使用时如何排除or-marker-p(< =今天截止日期) [英] How to exclude or-marker-p when using (<= deadline today)
问题描述
截止日期
和今天
都是在另一个函数中定义的数值。我试图在类似于我最近的一个线程的函数中使用小于或等于或大于或等于:如何测试org-todo状态xyz截止日期不等于今天
deadline
and today
are both numeric values defined within another function. I'm trying to use less-than-or-equal-to, or greater-than-or-equal-to, within a function similar to a recent thread of mine: How to test for org-todo state "xyz" with deadline not equal to today
在这种特殊情况下,我的函数包含条件(< =截止日期)
,如果事先不意外设置任何标记,该功能可以正常工作。如果我无意中预先设置了一个标记(例如,在运行该函数之前到缓冲区的末尾),则会收到错误消息和:错误的类型参数:number-or-marker-p,零
。我试过插入函数(deactivate-mark)
with atq with setq and mark nil and transient-mark-mode -1
,但我无法解决这个错误。我没有找到一种方法来清除标记环中的所有标记。任何想法?
In this particular case, my function contains a condition of (<= deadline today)
and the function works properly if I don't unwittingly set any marks beforehand. If I unwittingly set a mark beforehand (e.g., by going to the end of the buffer before running the function), then I get an error message and: Wrong type argument: number-or-marker-p, nil
. I've tried inserting into the function (deactivate-mark)
with a t and with setq and mark nil and transient-mark-mode -1
, but I cannot get around that error. I haven't found a way to clear all markers from the mark-ring. Any ideas?
编辑:
(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文件。
Sample *.org file.
* 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 >
编辑 - 解决方案 - 特别感谢尼古拉斯Riley帮助解决问题。
EDIT -- SOLUTION -- special thanks to Nicholas Riley for helping to troubleshoot the issue.
(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)) )))
推荐答案
你的问题有点混乱。这将是最好的,如果你可以发布一个自包含的elisp的例子,触发你想要描述的问题。
Your question is a bit confusing. It would be best if you could post a self-contained example of elisp that triggers the problem you are trying to describe.
那就说,我会尽量回答:看起来像截止日期
或今天
是 nil
而不是无论你期待什么< =
期望它的两个参数都是一个数字或一个标记,因此为什么它确保使用 number-or-marker-p
。可能与设置标记相关的内容将 nil
写入其中一个变量。
That said, I'll try to answer: It looks like either deadline
or today
are nil
rather than whatever you're expecting. <=
expects both of its arguments to be either a number or a marker, hence why it's ensuring that with number-or-marker-p
. Probably something relating to setting the mark writes nil
to one of these variables.
目前还不清楚在另一个函数中定义的数值 - 定义变量的方式和位置( defvar
? let
?)他们写?如果您不明白Emacs的范围和动态绑定(和Emacs 24+中的词法绑定),您应该阅读它们。这些变量名称没有前缀,这取决于其范围是非常危险的。
It's unclear what you mean by "numeric values defined within another function" — how and where are the variables defined (defvar
? let
?) and where are they written? If you don't understand Emacs's scopes and dynamic binding (and lexical binding in Emacs 24+), you should read about them. Those variable names don't have a prefix, which is pretty dangerous depending on their scope.
这篇关于使用时如何排除or-marker-p(< =今天截止日期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!