From a74ea730f4d7e802e3f05bbb1fb8cb1d473facbd Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Sep 2023 22:31:15 -0400 Subject: [PATCH] Read the odd startup option from org-mode files. --- src/context/global_settings.rs | 12 ++++++++++++ src/context/mod.rs | 1 + src/parser/in_buffer_settings.rs | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs index 88eadde..e91c93a 100644 --- a/src/context/global_settings.rs +++ b/src/context/global_settings.rs @@ -22,6 +22,11 @@ pub struct GlobalSettings<'g, 's> { /// /// Corresponds to the tab-width elisp variable. pub tab_width: IndentationLevel, + + /// Whether to only allow odd headline levels. + /// + /// Corresponds to org-odd-levels-only elisp variable. + pub odd_levels_only: HeadlineLevelFilter, } impl<'g, 's> GlobalSettings<'g, 's> { @@ -35,6 +40,7 @@ impl<'g, 's> GlobalSettings<'g, 's> { complete_todo_keywords: BTreeSet::new(), org_list_allow_alphabetical: false, tab_width: 8, + odd_levels_only: HeadlineLevelFilter::OddEven, } } } @@ -44,3 +50,9 @@ impl<'g, 's> Default for GlobalSettings<'g, 's> { GlobalSettings::new() } } + +#[derive(Debug, Clone)] +pub enum HeadlineLevelFilter { + Odd, + OddEven, +} diff --git a/src/context/mod.rs b/src/context/mod.rs index a396cd3..c2d4a0e 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -25,5 +25,6 @@ pub(crate) use exiting::ExitClass; pub use file_access_interface::FileAccessInterface; pub use file_access_interface::LocalFileAccessInterface; pub use global_settings::GlobalSettings; +pub use global_settings::HeadlineLevelFilter; pub(crate) use list::List; pub(crate) use parser_with_context::parser_with_context; diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index da93d08..626e397 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -1,13 +1,17 @@ use nom::branch::alt; +use nom::bytes::complete::is_not; use nom::bytes::complete::tag_no_case; use nom::character::complete::anychar; +use nom::character::complete::space1; use nom::combinator::map; use nom::multi::many0; use nom::multi::many_till; +use nom::multi::separated_list0; use super::keyword::filtered_keyword; use super::keyword_todo::todo_keywords; use super::OrgSource; +use crate::context::HeadlineLevelFilter; use crate::error::Res; use crate::types::Keyword; use crate::GlobalSettings; @@ -50,6 +54,7 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( ) -> Result, String> { let mut new_settings = original_settings.clone(); + // Todo Keywords for kw in keywords.iter().filter(|kw| { kw.key.eq_ignore_ascii_case("todo") || kw.key.eq_ignore_ascii_case("seq_todo") @@ -65,5 +70,18 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( .extend(complete_words.into_iter().map(str::to_string)); } + // Startup settings + for kw in keywords + .iter() + .filter(|kw| kw.key.eq_ignore_ascii_case("startup")) + { + let (_remaining, settings) = + separated_list0(space1::<&str, nom::error::Error<_>>, is_not(" \t"))(kw.value) + .map_err(|err: nom::Err<_>| err.to_string())?; + if settings.contains(&"odd") { + new_settings.odd_levels_only = HeadlineLevelFilter::Odd; + } + } + Ok(new_settings) }