2023-10-06 20:34:13 -04:00
|
|
|
use std::collections::BTreeMap;
|
2023-09-06 11:00:19 -04:00
|
|
|
use std::collections::BTreeSet;
|
|
|
|
|
2023-10-08 18:01:42 -04:00
|
|
|
use super::constants::DEFAULT_ORG_ENTITIES;
|
|
|
|
use super::constants::DEFAULT_ORG_LINK_PARAMETERS;
|
2023-09-04 16:29:41 -04:00
|
|
|
use super::FileAccessInterface;
|
|
|
|
use super::LocalFileAccessInterface;
|
2023-10-11 12:06:05 -04:00
|
|
|
use crate::context::constants::DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS;
|
|
|
|
use crate::context::constants::DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS;
|
|
|
|
use crate::context::constants::DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST;
|
2023-10-11 10:07:12 -04:00
|
|
|
use crate::context::constants::DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS;
|
2023-09-15 21:52:42 -04:00
|
|
|
use crate::types::IndentationLevel;
|
2023-09-04 12:28:33 -04:00
|
|
|
use crate::types::Object;
|
|
|
|
|
2023-09-04 12:31:43 -04:00
|
|
|
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
|
|
|
|
|
2023-09-04 12:28:33 -04:00
|
|
|
#[derive(Debug, Clone)]
|
2023-09-11 13:13:28 -04:00
|
|
|
pub struct GlobalSettings<'g, 's> {
|
|
|
|
pub radio_targets: Vec<&'g Vec<Object<'s>>>,
|
|
|
|
pub file_access: &'g dyn FileAccessInterface,
|
|
|
|
pub in_progress_todo_keywords: BTreeSet<String>,
|
|
|
|
pub complete_todo_keywords: BTreeSet<String>,
|
2023-09-14 00:27:54 -04:00
|
|
|
/// Set to true to allow for plain lists using single letters as the bullet in the same way that numbers are used.
|
|
|
|
///
|
|
|
|
/// Corresponds to the org-list-allow-alphabetical elisp variable.
|
2023-09-29 14:33:52 -04:00
|
|
|
pub list_allow_alphabetical: bool,
|
2023-09-15 21:52:42 -04:00
|
|
|
|
|
|
|
/// How many spaces a tab should be equal to.
|
|
|
|
///
|
|
|
|
/// Corresponds to the tab-width elisp variable.
|
|
|
|
pub tab_width: IndentationLevel,
|
2023-09-15 22:31:15 -04:00
|
|
|
|
|
|
|
/// Whether to only allow odd headline levels.
|
|
|
|
///
|
|
|
|
/// Corresponds to org-odd-levels-only elisp variable.
|
|
|
|
pub odd_levels_only: HeadlineLevelFilter,
|
2023-10-02 10:48:34 -04:00
|
|
|
|
|
|
|
/// If a headline title matches this string exactly, then that section will become a "footnote section".
|
|
|
|
///
|
|
|
|
/// Corresponds to org-footnote-section elisp variable.
|
|
|
|
pub footnote_section: &'g str,
|
2023-10-04 15:48:57 -04:00
|
|
|
|
2023-10-06 19:14:11 -04:00
|
|
|
/// The allowed protocols for links (for example, the "https" in "https://foo.bar/").
|
|
|
|
///
|
2023-10-06 19:18:58 -04:00
|
|
|
/// Corresponds to org-link-parameters elisp variable.
|
|
|
|
pub link_parameters: &'g [&'g str],
|
2023-10-06 20:34:13 -04:00
|
|
|
|
|
|
|
/// Link templates where the key is the document text and the value is the replacement.
|
|
|
|
///
|
|
|
|
/// For example, `"foo": "bar%s"` will replace `[[foo::baz]]` with `[[barbaz]]`
|
|
|
|
///
|
|
|
|
/// This is set by including #+LINK in the org-mode document.
|
2023-10-06 22:08:26 -04:00
|
|
|
pub link_templates: BTreeMap<String, String>,
|
2023-10-08 18:01:42 -04:00
|
|
|
|
|
|
|
/// The special characters that can be written in org-mode like \infin for the infinity symbol.
|
|
|
|
///
|
2023-10-08 23:31:19 -04:00
|
|
|
/// MUST be sorted with the largest names first. Otherwise the parser may match a shorter substring of a longer entity.
|
|
|
|
///
|
2023-10-08 18:01:42 -04:00
|
|
|
/// Corresponds to org-entities elisp variable.
|
2023-10-08 18:06:56 -04:00
|
|
|
pub entities: &'g [EntityDefinition<'s>],
|
2023-10-11 10:07:12 -04:00
|
|
|
|
|
|
|
/// Keywords that contain the standard set of objects (excluding footnote references).
|
|
|
|
///
|
|
|
|
/// Corresponds to org-element-parsed-keywords elisp variable.
|
2023-10-11 12:06:05 -04:00
|
|
|
pub element_parsed_keywords: &'g [&'s str],
|
|
|
|
|
|
|
|
/// Keywords that can have a secondary value in square brackets.
|
|
|
|
///
|
|
|
|
/// Corresponds to org-element-dual-keywords elisp variable.
|
|
|
|
pub element_dual_keywords: &'g [&'s str],
|
|
|
|
|
|
|
|
/// Keywords that can be affiliated with an element.
|
|
|
|
///
|
|
|
|
/// Corresponds to org-element-affiliated-keywords elisp variable.
|
|
|
|
pub element_affiliated_keywords: &'g [&'s str],
|
|
|
|
|
|
|
|
/// Mapping of keyword names.
|
|
|
|
///
|
|
|
|
/// Corresponds to org-element-keyword-translation-alist elisp variable.
|
|
|
|
pub element_keyword_translation_alist: &'g [(&'s str, &'s str)],
|
2023-09-02 20:46:17 -04:00
|
|
|
}
|
|
|
|
|
2023-09-29 16:37:22 -04:00
|
|
|
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
|
|
|
|
|
2023-10-08 18:01:42 -04:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct EntityDefinition<'a> {
|
|
|
|
pub name: &'a str,
|
|
|
|
pub latex_math_mode: bool,
|
|
|
|
pub latex: &'a str,
|
|
|
|
pub html: &'a str,
|
|
|
|
pub ascii: &'a str,
|
|
|
|
// Skipping latin1 because it is detrimental to the future. If anyone out there is using latin1, take a long look in the mirror and change your ways.
|
|
|
|
pub utf8: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-09-04 12:28:33 -04:00
|
|
|
impl<'g, 's> GlobalSettings<'g, 's> {
|
2023-09-11 13:13:28 -04:00
|
|
|
fn new() -> GlobalSettings<'g, 's> {
|
2023-10-11 09:24:20 -04:00
|
|
|
debug_assert!(DEFAULT_ORG_ENTITIES.is_sorted_by(|a, b| b.name.len().partial_cmp(&a.name.len())));
|
2023-09-04 12:28:33 -04:00
|
|
|
GlobalSettings {
|
|
|
|
radio_targets: Vec::new(),
|
2023-09-04 21:46:40 -04:00
|
|
|
file_access: &LocalFileAccessInterface {
|
|
|
|
working_directory: None,
|
|
|
|
},
|
2023-09-06 11:00:19 -04:00
|
|
|
in_progress_todo_keywords: BTreeSet::new(),
|
2023-09-06 11:48:24 -04:00
|
|
|
complete_todo_keywords: BTreeSet::new(),
|
2023-09-29 14:33:52 -04:00
|
|
|
list_allow_alphabetical: false,
|
2023-09-29 16:37:22 -04:00
|
|
|
tab_width: DEFAULT_TAB_WIDTH,
|
|
|
|
odd_levels_only: HeadlineLevelFilter::default(),
|
2023-10-02 10:48:34 -04:00
|
|
|
footnote_section: "Footnotes",
|
2023-10-06 20:34:13 -04:00
|
|
|
link_parameters: &DEFAULT_ORG_LINK_PARAMETERS,
|
|
|
|
link_templates: BTreeMap::new(),
|
2023-10-08 18:01:42 -04:00
|
|
|
entities: &DEFAULT_ORG_ENTITIES,
|
2023-10-11 10:07:12 -04:00
|
|
|
element_parsed_keywords: &DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS,
|
2023-10-11 12:06:05 -04:00
|
|
|
element_dual_keywords: &DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS,
|
|
|
|
element_affiliated_keywords: &DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS,
|
|
|
|
element_keyword_translation_alist: &DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST,
|
2023-09-04 12:28:33 -04:00
|
|
|
}
|
2023-09-02 20:46:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-04 12:28:33 -04:00
|
|
|
impl<'g, 's> Default for GlobalSettings<'g, 's> {
|
2023-09-04 16:29:41 -04:00
|
|
|
fn default() -> GlobalSettings<'g, 's> {
|
2023-09-02 20:46:17 -04:00
|
|
|
GlobalSettings::new()
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 22:31:15 -04:00
|
|
|
|
2023-09-29 16:37:22 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2023-09-15 22:31:15 -04:00
|
|
|
pub enum HeadlineLevelFilter {
|
|
|
|
Odd,
|
|
|
|
OddEven,
|
|
|
|
}
|
2023-09-29 16:37:22 -04:00
|
|
|
|
|
|
|
impl Default for HeadlineLevelFilter {
|
|
|
|
fn default() -> Self {
|
|
|
|
HeadlineLevelFilter::OddEven
|
|
|
|
}
|
|
|
|
}
|