diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 451943d..3d8c553 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1618,11 +1618,14 @@ fn compare_example_block<'b, 's>( }; // Compare preserve-indent - let preserve_indent = get_property_boolean(emacs, ":preserve-indent")?; - if preserve_indent { - // I don't know what :preserve-indent is for, but it seems to always be nil. This is here to alert me to value being non-nil so I can investigate. + let preserve_indent: Option = + get_property_numeric(emacs, ":preserve-indent")?; + if preserve_indent != rust.preserve_indent { this_status = DiffStatus::Bad; - message = Some(format!("Non-nil :preserve-indent {:?}", preserve_indent)); + message = Some(format!( + "Prserve indent mismatch (emacs != rust) {:?} != {:?}", + preserve_indent, rust.preserve_indent + )); } // Compare retain-labels @@ -1731,8 +1734,6 @@ fn compare_src_block<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; - // TODO: Compare :parameters - // Compare language let language = get_property_quoted_string(emacs, ":language")?; if language.as_ref().map(String::as_str) != rust.language { @@ -1771,7 +1772,7 @@ fn compare_src_block<'b, 's>( } } - // Compare switches + // Compare parameters let parameters = get_property_quoted_string(emacs, ":parameters")?; match (parameters.as_ref().map(String::as_str), rust.parameters) { (None, None) => {} @@ -1830,11 +1831,14 @@ fn compare_src_block<'b, 's>( }; // Compare preserve-indent - let preserve_indent = get_property_boolean(emacs, ":preserve-indent")?; - if preserve_indent { - // I don't know what :preserve-indent is for, but it seems to always be nil. This is here to alert me to value being non-nil so I can investigate. + let preserve_indent: Option = + get_property_numeric(emacs, ":preserve-indent")?; + if preserve_indent != rust.preserve_indent { this_status = DiffStatus::Bad; - message = Some(format!("Non-nil :preserve-indent {:?}", preserve_indent)); + message = Some(format!( + "Prserve indent mismatch (emacs != rust) {:?} != {:?}", + preserve_indent, rust.preserve_indent + )); } // Compare retain-labels diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index a43d8c5..17b239c 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -160,7 +160,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>( let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?; let source = get_consumed(input, remaining); - let (switches, number_lines, retain_labels, use_labels, label_format) = { + let (switches, number_lines, preserve_indent, retain_labels, use_labels, label_format) = { if let Some(parameters) = parameters { ( if parameters.source.len() == 0 { @@ -169,12 +169,13 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>( Some(parameters.source) }, parameters.number_lines, + parameters.preserve_indent, parameters.retain_labels, parameters.use_labels, parameters.label_format, ) } else { - (None, None, RetainLabels::Yes, true, None) + (None, None, None, RetainLabels::Yes, true, None) } }; Ok(( @@ -183,6 +184,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>( source: source.into(), switches, number_lines, + preserve_indent, retain_labels, use_labels, label_format, @@ -242,8 +244,7 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>( let (remaining, language) = opt(map(tuple((space1, switch_word(true))), |(_, language)| { language }))(remaining)?; - let (remaining, switches) = - opt(map(tuple((space1, src_switches)), |(_, switches)| switches))(remaining)?; + let (remaining, switches) = opt(src_switches)(remaining)?; let (remaining, parameters) = opt(map(tuple((space1, src_parameters)), |(_, parameters)| { parameters }))(remaining)?; @@ -264,7 +265,7 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>( let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?; let source = get_consumed(input, remaining); - let (switches, number_lines, retain_labels, use_labels, label_format) = { + let (switches, number_lines, preserve_indent, retain_labels, use_labels, label_format) = { if let Some(switches) = switches { ( if switches.source.len() == 0 { @@ -273,12 +274,13 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>( Some(switches.source) }, switches.number_lines, + switches.preserve_indent, switches.retain_labels, switches.use_labels, switches.label_format, ) } else { - (None, None, RetainLabels::Yes, true, None) + (None, None, None, RetainLabels::Yes, true, None) } }; Ok(( @@ -289,6 +291,7 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>( switches, parameters: parameters.map(Into::<&str>::into), number_lines, + preserve_indent, retain_labels, use_labels, label_format, @@ -361,6 +364,7 @@ struct ExampleSrcSwitches<'s> { source: &'s str, number_lines: Option, retain_labels: RetainLabels, + preserve_indent: Option, use_labels: bool, label_format: Option<&'s str>, } @@ -380,28 +384,35 @@ fn src_parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn src_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSrcSwitches<'s>> { - example_src_switches(true)(input) + let (remaining, leading_spaces) = space1(input)?; + let offset = Into::<&str>::into(leading_spaces).chars().count(); + let offset = CharOffsetInLine::try_from(offset) + .expect("Character offset should fit in CharOffsetInLine"); + example_src_switches(true, offset)(remaining) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn example_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSrcSwitches<'s>> { - let (remaining, switches) = example_src_switches(false)(input)?; + let (remaining, switches) = example_src_switches(false, 0)(input)?; Ok((remaining, switches)) } fn example_src_switches( stop_at_parameters: bool, + additional_char_offset: CharOffsetInLine, ) -> impl for<'s> Fn(OrgSource<'s>) -> Res, ExampleSrcSwitches<'s>> { - move |input| _example_src_switches(input, stop_at_parameters) + move |input| _example_src_switches(input, stop_at_parameters, additional_char_offset) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _example_src_switches<'s>( input: OrgSource<'s>, stop_at_parameters: bool, + additional_char_offset: CharOffsetInLine, ) -> Res, ExampleSrcSwitches<'s>> { let mut number_lines = None; let mut retain_labels = RetainLabels::Yes; + let mut preserve_indent = None; let mut use_labels = true; let mut label_format = None; let mut saw_r = false; @@ -440,7 +451,14 @@ fn _example_src_switches<'s>( let character_offset = Into::<&str>::into(text_until_flag).chars().count(); let character_offset = CharOffsetInLine::try_from(character_offset) .expect("Character offset should fit in CharOffsetInLine"); - retain_labels = RetainLabels::Keep(character_offset); + retain_labels = RetainLabels::Keep(character_offset + additional_char_offset); + } + (SwitchState::Normal, "-i") => { + let text_until_flag = input.get_until(word); + let character_offset = Into::<&str>::into(text_until_flag).chars().count(); + let character_offset = CharOffsetInLine::try_from(character_offset) + .expect("Character offset should fit in CharOffsetInLine"); + preserve_indent = Some(character_offset + additional_char_offset); } (SwitchState::NewLineNumber, _) => { let val = normalized_word.parse::(); @@ -507,6 +525,7 @@ fn _example_src_switches<'s>( source: Into::<&str>::into(source), number_lines, retain_labels, + preserve_indent, use_labels, label_format, }, diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 572626e..eed5082 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -50,6 +50,7 @@ pub struct ExampleBlock<'s> { pub source: &'s str, pub switches: Option<&'s str>, pub number_lines: Option, + pub preserve_indent: Option, pub retain_labels: RetainLabels, pub use_labels: bool, pub label_format: Option<&'s str>, @@ -71,6 +72,7 @@ pub struct SrcBlock<'s> { pub switches: Option<&'s str>, pub parameters: Option<&'s str>, pub number_lines: Option, + pub preserve_indent: Option, pub retain_labels: RetainLabels, pub use_labels: bool, pub label_format: Option<&'s str>,