organic/src/context/global_settings.rs

120 lines
3.4 KiB
Rust
Raw Normal View History

use std::collections::BTreeMap;
2023-09-06 11:00:19 -04:00
use std::collections::BTreeSet;
use super::FileAccessInterface;
use super::LocalFileAccessInterface;
use crate::types::IndentationLevel;
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
#[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>,
/// 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.
pub list_allow_alphabetical: bool,
/// How many spaces a tab should be equal to.
///
/// 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,
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,
/// The label format for references inside src/example blocks.
///
/// Corresponds to org-coderef-label-format elisp variable.
pub coderef_label_format: &'g str,
/// The allowed protocols for links (for example, the "https" in "https://foo.bar/").
///
/// Corresponds to org-link-parameters elisp variable.
pub link_parameters: &'g [&'g str],
/// 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.
pub link_templates: BTreeMap<&'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;
impl<'g, 's> GlobalSettings<'g, 's> {
2023-09-11 13:13:28 -04:00
fn new() -> GlobalSettings<'g, 's> {
GlobalSettings {
radio_targets: Vec::new(),
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(),
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",
coderef_label_format: "(ref:%s)",
link_parameters: &DEFAULT_ORG_LINK_PARAMETERS,
link_templates: BTreeMap::new(),
}
2023-09-02 20:46:17 -04:00
}
}
impl<'g, 's> Default for GlobalSettings<'g, 's> {
fn default() -> GlobalSettings<'g, 's> {
2023-09-02 20:46:17 -04:00
GlobalSettings::new()
}
}
2023-09-29 16:37:22 -04:00
#[derive(Debug, Clone, PartialEq)]
pub enum HeadlineLevelFilter {
Odd,
OddEven,
}
2023-09-29 16:37:22 -04:00
impl Default for HeadlineLevelFilter {
fn default() -> Self {
HeadlineLevelFilter::OddEven
}
}
const DEFAULT_ORG_LINK_PARAMETERS: [&'static str; 23] = [
"id",
"eww",
"rmail",
"mhe",
"irc",
"info",
"gnus",
"docview",
"bibtex",
"bbdb",
"w3m",
"doi",
"file+sys",
"file+emacs",
"shell",
"news",
"mailto",
"https",
"http",
"ftp",
"help",
"file",
"elisp",
];