diff --git a/org_mode_samples/lesser_element/lesser_block/example/only_k.org b/org_mode_samples/lesser_element/lesser_block/example/only_k.org new file mode 100644 index 0000000..fbc3d87 --- /dev/null +++ b/org_mode_samples/lesser_element/lesser_block/example/only_k.org @@ -0,0 +1,3 @@ +#+begin_example foo -k +bar +#+end_example diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 5265a39..4ca5de1 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1626,7 +1626,7 @@ fn compare_example_block<'b, 's>( } // Compare retain-labels - // retain-labels is t by default, nil if -r is set, or a number if -k is set. + // retain-labels is t by default, nil if -r is set, or a number if -k and -r is set. let retain_labels = get_property_unquoted_atom(emacs, ":retain-labels")?; if let Some(retain_labels) = retain_labels { if retain_labels == "t" { @@ -1652,7 +1652,6 @@ fn compare_example_block<'b, 's>( )); } } - // foo } } else { match rust.retain_labels { diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 32a80c4..6305b7b 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -351,6 +351,7 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSwitc let mut retain_labels = RetainLabels::Yes; let mut use_labels = true; let mut label_format = None; + let mut saw_r = false; let (remaining, (source, (words, _))) = consumed(tuple((separated_list1(space1, switch_word), space0)))(input)?; @@ -366,6 +367,7 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSwitc state = SwitchState::ContinuedLineNumber; } (SwitchState::Normal, "-r") => { + saw_r = true; use_labels = false; match retain_labels { RetainLabels::Yes => { @@ -378,6 +380,7 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSwitc state = SwitchState::LabelFormat; } (SwitchState::Normal, "-k") => { + use_labels = false; 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) @@ -426,6 +429,11 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res, ExampleSwitc } } + let retain_labels = match retain_labels { + RetainLabels::Keep(_) if !saw_r => RetainLabels::Yes, + _ => retain_labels, + }; + Ok(( remaining, ExampleSwitches {