0

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)) )))
4

1 回答 1

2

你的问题有点令人困惑。如果您可以发布一个独立的 elisp 示例来触发您试图描述的问题,那将是最好的。

也就是说,我会试着回答:它看起来像deadline不是你所期望的 today。期望它的两个参数都是数字或标记,因此它为什么要确保 with . 可能与设置标记有关的内容写入这些变量之一。nil<=number-or-marker-pnil

不清楚您所说的“在另一个函数中定义的数值”是什么意思——变量是如何以及在哪里定义的(defvar??let)以及它们是在哪里写的?如果您不了解 Emacs 的作用域和动态绑定(以及 Emacs 24+ 中的词法绑定),您应该阅读它们。这些变量名没有前缀,这取决于它们的范围是非常危险的。

于 2013-07-14T20:28:42.150 回答