Compare todo-type on headlines.
This commit is contained in:
parent
7c471ab32e
commit
12cbb89861
@ -60,6 +60,7 @@ use crate::types::TableCell;
|
||||
use crate::types::TableRow;
|
||||
use crate::types::Target;
|
||||
use crate::types::Timestamp;
|
||||
use crate::types::TodoKeywordType;
|
||||
use crate::types::Underline;
|
||||
use crate::types::Verbatim;
|
||||
use crate::types::VerseBlock;
|
||||
@ -510,9 +511,9 @@ fn compare_heading<'s>(
|
||||
.map(Token::as_atom)
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.unwrap_or("nil");
|
||||
match (todo_keyword, rust.todo_keyword, unquote(todo_keyword)) {
|
||||
match (todo_keyword, &rust.todo_keyword, unquote(todo_keyword)) {
|
||||
("nil", None, _) => {}
|
||||
(_, Some(rust_todo), Ok(emacs_todo)) if emacs_todo == rust_todo => {}
|
||||
(_, Some((_rust_todo_type, rust_todo)), Ok(emacs_todo)) if emacs_todo == *rust_todo => {}
|
||||
(emacs_todo, rust_todo, _) => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
@ -521,6 +522,24 @@ fn compare_heading<'s>(
|
||||
));
|
||||
}
|
||||
};
|
||||
// Compare todo-type
|
||||
let todo_type = get_property(emacs, ":todo-type")?
|
||||
.map(Token::as_atom)
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.unwrap_or("nil");
|
||||
// todo-type is an unquoted string either todo, done, or nil
|
||||
match (todo_type, &rust.todo_keyword) {
|
||||
("nil", None) => {}
|
||||
("todo", Some((TodoKeywordType::Todo, _))) => {}
|
||||
("done", Some((TodoKeywordType::Done, _))) => {}
|
||||
(emacs_todo, rust_todo) => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"(emacs != rust) {:?} != {:?}",
|
||||
emacs_todo, rust_todo
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// Compare title
|
||||
let title = get_property(emacs, ":title")?.ok_or("Missing :title attribute.")?;
|
||||
@ -532,7 +551,7 @@ fn compare_heading<'s>(
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
child_status.push(artificial_diff_scope("title".to_owned(), title_status)?);
|
||||
|
||||
// TODO: Compare todo-type, priority, :footnote-section-p, :archivedp, :commentedp
|
||||
// TODO: Compare priority, :footnote-section-p, :archivedp, :commentedp
|
||||
|
||||
// Compare section
|
||||
let section_status = children
|
||||
|
@ -51,6 +51,7 @@ use crate::types::Element;
|
||||
use crate::types::Heading;
|
||||
use crate::types::Object;
|
||||
use crate::types::Section;
|
||||
use crate::types::TodoKeywordType;
|
||||
|
||||
/// Parse a full org-mode document.
|
||||
///
|
||||
@ -346,8 +347,9 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
Heading {
|
||||
source: source.into(),
|
||||
stars: star_count,
|
||||
todo_keyword: maybe_todo_keyword
|
||||
.map(|(todo_keyword, _ws)| Into::<&str>::into(todo_keyword)),
|
||||
todo_keyword: maybe_todo_keyword.map(|((todo_keyword_type, todo_keyword), _ws)| {
|
||||
(todo_keyword_type, Into::<&str>::into(todo_keyword))
|
||||
}),
|
||||
title,
|
||||
tags: heading_tags,
|
||||
children,
|
||||
@ -371,7 +373,7 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
(
|
||||
usize,
|
||||
OrgSource<'s>,
|
||||
Option<(OrgSource<'s>, OrgSource<'s>)>,
|
||||
Option<((TodoKeywordType, OrgSource<'s>), OrgSource<'s>)>,
|
||||
Vec<Object<'s>>,
|
||||
Vec<&'s str>,
|
||||
),
|
||||
@ -447,23 +449,38 @@ fn single_tag<'r, 's>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
|
||||
fn heading_keyword<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
) -> Res<OrgSource<'s>, (TodoKeywordType, OrgSource<'s>)> {
|
||||
let global_settings = context.get_global_settings();
|
||||
if global_settings.in_progress_todo_keywords.is_empty()
|
||||
&& global_settings.complete_todo_keywords.is_empty()
|
||||
{
|
||||
alt((tag("TODO"), tag("DONE")))(input)
|
||||
alt((
|
||||
map(tag("TODO"), |capture| (TodoKeywordType::Todo, capture)),
|
||||
map(tag("DONE"), |capture| (TodoKeywordType::Done, capture)),
|
||||
))(input)
|
||||
} else {
|
||||
for todo_keyword in global_settings
|
||||
.in_progress_todo_keywords
|
||||
.iter()
|
||||
.chain(global_settings.complete_todo_keywords.iter())
|
||||
.map(String::as_str)
|
||||
{
|
||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
||||
match result {
|
||||
Ok((remaining, ent)) => {
|
||||
return Ok((remaining, ent));
|
||||
return Ok((remaining, (TodoKeywordType::Todo, ent)));
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
for todo_keyword in global_settings
|
||||
.complete_todo_keywords
|
||||
.iter()
|
||||
.map(String::as_str)
|
||||
{
|
||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
||||
match result {
|
||||
Ok((remaining, ent)) => {
|
||||
return Ok((remaining, (TodoKeywordType::Done, ent)));
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub struct Document<'s> {
|
||||
pub struct Heading<'s> {
|
||||
pub source: &'s str,
|
||||
pub stars: usize,
|
||||
pub todo_keyword: Option<&'s str>,
|
||||
pub todo_keyword: Option<(TodoKeywordType, &'s str)>,
|
||||
// TODO: add todo-type enum
|
||||
pub title: Vec<Object<'s>>,
|
||||
pub tags: Vec<&'s str>,
|
||||
@ -32,6 +32,12 @@ pub enum DocumentElement<'s> {
|
||||
Section(Section<'s>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TodoKeywordType {
|
||||
Todo,
|
||||
Done,
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Document<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
|
@ -8,6 +8,7 @@ pub use document::Document;
|
||||
pub use document::DocumentElement;
|
||||
pub use document::Heading;
|
||||
pub use document::Section;
|
||||
pub use document::TodoKeywordType;
|
||||
pub use element::Element;
|
||||
pub use greater_element::Drawer;
|
||||
pub use greater_element::DynamicBlock;
|
||||
|
Loading…
Reference in New Issue
Block a user