Compare footnote section.

This commit is contained in:
Tom Alexander 2023-10-02 10:48:34 -04:00
parent d78ce10a0b
commit 178894680b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 46 additions and 3 deletions

View File

@ -0,0 +1,3 @@
* Foo
* Footnotes
* Footnotes and stuff

View File

@ -9,6 +9,7 @@ use super::sexp::unquote;
use super::sexp::Token; use super::sexp::Token;
use super::util::compare_standard_properties; use super::util::compare_standard_properties;
use super::util::get_property; use super::util::get_property;
use super::util::get_property_boolean;
use super::util::get_property_quoted_string; use super::util::get_property_quoted_string;
use super::util::get_property_unquoted_atom; use super::util::get_property_unquoted_atom;
use crate::types::AngleLink; use crate::types::AngleLink;
@ -726,7 +727,17 @@ fn compare_heading<'s>(
)); ));
} }
// TODO: Compare :pre-blank :footnote-section-p :scheduled :closed // Compare footnote-section-p
let footnote_section = get_property_boolean(emacs, ":footnote-section-p")?;
if footnote_section != rust.is_footnote_section {
this_status = DiffStatus::Bad;
message = Some(format!(
"footnote section mismatch (emacs != rust) {:?} != {:?}",
footnote_section, rust.is_footnote_section
));
}
// TODO: Compare :pre-blank :scheduled :closed
// //
// :scheduled and :closed seem to only appear when the headline has a planning // :scheduled and :closed seem to only appear when the headline has a planning

View File

@ -217,3 +217,19 @@ pub(crate) fn get_property_quoted_string<'s, 'x>(
.map(unquote) .map(unquote)
.map_or(Ok(None), |r| r.map(Some))?) .map_or(Ok(None), |r| r.map(Some))?)
} }
/// Get a named property containing a boolean value.
///
/// This uses the elisp convention of nil == false, non-nil == true.
///
/// Returns false if key is not found.
pub(crate) fn get_property_boolean<'s, 'x>(
emacs: &'s Token<'s>,
key: &'x str,
) -> Result<bool, Box<dyn std::error::Error>> {
Ok(get_property(emacs, key)?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil")
!= "nil")
}

View File

@ -27,6 +27,11 @@ pub struct GlobalSettings<'g, 's> {
/// ///
/// Corresponds to org-odd-levels-only elisp variable. /// Corresponds to org-odd-levels-only elisp variable.
pub odd_levels_only: HeadlineLevelFilter, pub odd_levels_only: HeadlineLevelFilter,
/// If a headline title matches this string exactly, then that section will become a "footnote section".
///
/// Corresponds to org-footnote-section elisp variable.
pub footnote_section: &'g str,
} }
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8; pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
@ -43,6 +48,7 @@ impl<'g, 's> GlobalSettings<'g, 's> {
list_allow_alphabetical: false, list_allow_alphabetical: false,
tab_width: DEFAULT_TAB_WIDTH, tab_width: DEFAULT_TAB_WIDTH,
odd_levels_only: HeadlineLevelFilter::default(), odd_levels_only: HeadlineLevelFilter::default(),
footnote_section: "Footnotes",
} }
} }
} }

View File

@ -4,6 +4,7 @@ use nom::bytes::complete::tag;
use nom::character::complete::anychar; use nom::character::complete::anychar;
use nom::character::complete::space0; use nom::character::complete::space0;
use nom::character::complete::space1; use nom::character::complete::space1;
use nom::combinator::consumed;
use nom::combinator::map; use nom::combinator::map;
use nom::combinator::not; use nom::combinator::not;
use nom::combinator::opt; use nom::combinator::opt;
@ -101,6 +102,7 @@ fn _heading<'b, 'g, 'r, 's>(
children, children,
is_comment: maybe_comment.is_some(), is_comment: maybe_comment.is_some(),
is_archived, is_archived,
is_footnote_section: false, // TODO
}, },
)) ))
} }
@ -159,7 +161,9 @@ fn headline<'b, 'g, 'r, 's>(
let (remaining, maybe_title) = opt(tuple(( let (remaining, maybe_title) = opt(tuple((
space1, space1,
many1(parser_with_context!(standard_set_object)(&parser_context)), consumed(many1(parser_with_context!(standard_set_object)(
&parser_context,
))),
)))(remaining)?; )))(remaining)?;
let (remaining, maybe_tags) = opt(tuple((space0, tags)))(remaining)?; let (remaining, maybe_tags) = opt(tuple((space0, tags)))(remaining)?;
@ -174,7 +178,9 @@ fn headline<'b, 'g, 'r, 's>(
maybe_todo_keyword.map(|(_, todo, _)| todo), maybe_todo_keyword.map(|(_, todo, _)| todo),
maybe_priority, maybe_priority,
maybe_comment.map(|(_, comment, _)| comment), maybe_comment.map(|(_, comment, _)| comment),
maybe_title.map(|(_, title)| title).unwrap_or(Vec::new()), maybe_title
.map(|(_, (_, title))| title)
.unwrap_or(Vec::new()),
maybe_tags maybe_tags
.map(|(_ws, tags)| { .map(|(_ws, tags)| {
tags.into_iter() tags.into_iter()

View File

@ -28,6 +28,7 @@ pub struct Heading<'s> {
pub children: Vec<DocumentElement<'s>>, pub children: Vec<DocumentElement<'s>>,
pub is_comment: bool, pub is_comment: bool,
pub is_archived: bool, pub is_archived: bool,
pub is_footnote_section: bool,
} }
#[derive(Debug)] #[derive(Debug)]