使用时如何排除or-marker-p(< =今天截止日期)

时间:2013-07-14 19:32:23

标签: emacs

deadlinetoday都是在另一个函数中定义的数值。我尝试在类似于我最近的线程的函数中使用小于或等于或大于或等于:How to test for org-todo state "xyz" with deadline not equal to today

在这种特殊情况下,我的函数包含(<= deadline today)的条件,如果我事先没有在不知情的情况下设置任何标记,则该函数可以正常工作。如果我事先无意中设置了一个标记(例如,在运行该函数之前到达缓冲区的末尾),那么我会收到一条错误消息and: Wrong type argument: number-or-marker-p, nil。我尝试使用t和setq以及标记nil和(deactivate-mark)插入函数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)) )))

1 个答案:

答案 0 :(得分:2)

你的问题有点令人困惑。如果你能发布一个自包含的elisp示例来触发你想要描述的问题,那将是最好的。

那就是说,我会尝试回答:看起来deadlinetoday都是nil,而不是你所期待的。 <=期望它的两个参数都是数字或标记,因此它确保使用number-or-marker-p。可能与设置标记相关的内容会将nil写入其中一个变量。

目前还不清楚“另一个函数中定义的数值”是什么意思 - 变量定义的方式和位置(defvarlet?)以及它们在哪里编写?如果您不了解Emacs的范围和动态绑定(以及Emacs 24+中的词法绑定),您应该阅读它们。这些变量名称没有前缀,这取决于它们的范围,这非常危险。