deadline
并且today
都是在另一个函数中定义的数值。我正在尝试在类似于我最近的线程的函数中使用小于或等于或大于或等于: 如何测试 org-todo 状态“xyz”截止日期不等于今天
(<= deadline today)
在这种特殊情况下,如果我没有事先设置任何标记,我的函数包含一个条件,并且该函数可以正常工作。如果我事先不经意地设置了一个标记(例如,在运行函数之前转到缓冲区的末尾),那么我会收到一条错误消息and: Wrong type argument: number-or-marker-p, nil
。(deactivate-mark)
我尝试使用 at 和 setq 并标记 nil and插入函数transient-mark-mode -1
,但我无法解决该错误。我还没有找到清除标记环上所有标记的方法。有任何想法吗?
编辑:
(defun carry-forward-uncompleted-todo (&optional from-state to-state)
"Carry forward uncompleted todo."
(interactive)
(let* (
(element (org-element-at-point))
(todo-state (org-element-property :todo-keyword element))
(deadline
(ignore-errors ;; avoids throwing error message if there is no deadline.
(time-to-days
(org-time-string-to-time
(org-element-property :deadline element) ))))
(today (time-to-days (current-time))) )
(goto-char (point-min))
(while
(re-search-forward "^\*\* Active" nil t)
(when (< deadline today) ;; condition -- past-due
(org-deadline nil ".") ;; make deadline today
)
)
)
)
示例 *.org 文件。
* TASKS
** Active [#A] First task due today. :lawlist:
DEADLINE: <2013-07-11 Thu >
** Active [#A] Second task due today. :lawlist:
DEADLINE: <2013-07-11 Thu >
** Next Action [#E] Test One -- make Active with deadline today. :lawlist:
DEADLINE: <2013-07-31 Wed >
** Next Action [#E] Test Two -- make Active with deadline today. :lawlist:
DEADLINE: <2013-07-31 Wed >
编辑——解决方案——特别感谢 Nicholas Riley 帮助解决问题。
(defvar from-state nil)
(defvar to-state nil)
(defun carry-forward-uncompleted-tasks ()
"Carry forward uncompleted tasks."
(interactive)
(goto-char (point-min))
(while (re-search-forward "^\*\* Active" nil t)
(unless (org-at-heading-p)
(org-back-to-heading))
(let* (
(element (org-element-at-point))
(todo-state (org-element-property :todo-keyword element))
(deadline
(ignore-errors ;; avoids throwing an error message if there is no deadline.
(time-to-days
(org-time-string-to-time
(org-element-property :deadline element) ))))
(today (time-to-days (current-time)))
(title (org-element-property :raw-value element)) )
(setq from-state "Active")
(setq to-state "Active")
(if (and
(> today deadline) ;; condition -- deadline is overdue
(string= todo-state from-state) ) ;; condition -- todo-state equals from-state
(progn ;; Process following list if conditions were met.
(message "\nMODIFIED => Active + Today: %s" title)
(org-deadline nil ".") )
(message "\nNO CHANGES: %s" title)) )))