Add real handling for preserve indent.
Now that I know which flag changes this setting, we can handle it properly.
This commit is contained in:
parent
e1e4ac75e4
commit
87ac18e6b2
@ -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<CharOffsetInLine> =
|
||||
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<CharOffsetInLine> =
|
||||
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
|
||||
|
@ -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<SwitchNumberLines>,
|
||||
retain_labels: RetainLabels,
|
||||
preserve_indent: Option<CharOffsetInLine>,
|
||||
use_labels: bool,
|
||||
label_format: Option<&'s str>,
|
||||
}
|
||||
@ -380,28 +384,35 @@ fn src_parameters<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn src_switches<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, 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<OrgSource<'s>, 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<OrgSource<'s>, 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<OrgSource<'s>, 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::<LineNumber>();
|
||||
@ -507,6 +525,7 @@ fn _example_src_switches<'s>(
|
||||
source: Into::<&str>::into(source),
|
||||
number_lines,
|
||||
retain_labels,
|
||||
preserve_indent,
|
||||
use_labels,
|
||||
label_format,
|
||||
},
|
||||
|
@ -50,6 +50,7 @@ pub struct ExampleBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub switches: Option<&'s str>,
|
||||
pub number_lines: Option<SwitchNumberLines>,
|
||||
pub preserve_indent: Option<CharOffsetInLine>,
|
||||
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<SwitchNumberLines>,
|
||||
pub preserve_indent: Option<CharOffsetInLine>,
|
||||
pub retain_labels: RetainLabels,
|
||||
pub use_labels: bool,
|
||||
pub label_format: Option<&'s str>,
|
||||
|
Loading…
Reference in New Issue
Block a user