Retain labels stays a boolean without -r.

This commit is contained in:
Tom Alexander 2023-10-04 16:21:37 -04:00
parent da5dcd4c1b
commit 13163f2468
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1,3 @@
#+begin_example foo -k
bar
#+end_example

View File

@ -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 {

View File

@ -351,6 +351,7 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, 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<OrgSource<'s>, 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<OrgSource<'s>, 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<OrgSource<'s>, ExampleSwitc
}
}
let retain_labels = match retain_labels {
RetainLabels::Keep(_) if !saw_r => RetainLabels::Yes,
_ => retain_labels,
};
Ok((
remaining,
ExampleSwitches {