Emacs “如何测试组织待办事项状态”;xyz";截止日期不等于今天

Emacs “如何测试组织待办事项状态”;xyz";截止日期不等于今天,emacs,org-mode,Emacs,Org Mode,请问,测试特定待办事项状态和不等于今天的截止日期是否存在的最佳方法是什么 org state是一个“[h]ook,在TODO项目的状态更改后运行”。因此,除非我真的在更改todo的状态,否则我认为我不能使用(字符串等于组织状态“下一个操作”)。下面列出的我的string equal行代码都被拒绝:符号作为变量的值无效:组织todo和组织截止日期。截止日期是出现在todo状态下的一条线,因此在测试这两种情况是否存在时,这也可能会造成问题 (defun if-next-action-not-toda

请问,测试特定待办事项状态和不等于今天的截止日期是否存在的最佳方法是什么

org state
是一个“[h]ook,在TODO项目的状态更改后运行”。因此,除非我真的在更改todo的状态,否则我认为我不能使用
(字符串等于组织状态“下一个操作”)
。下面列出的我的
string equal
行代码都被拒绝:
符号作为变量的值无效:
组织todo
组织截止日期
。截止日期是出现在todo状态下的一条线,因此在测试这两种情况是否存在时,这也可能会造成问题

(defun if-next-action-not-today-then-promote ()

(interactive)

    (goto-char (point-min))

    (while

    (re-search-forward "^\*\* Next Action" nil t)

        (when (and (string-equal org-todo "Next Action") (not (string-equal org-deadline "<%<%Y-%m-%d %a>>")) )

        (message "You have satisfied the two conditions . . . proceeding.")

        (org-todo "Active")  ;; change state to active

        (org-deadline nil "<%<%Y-%m-%d %a>>") ;; change deadline to today

         )

    )

)

只要您使用的是
ORG7.9.2
或更高版本,以下内容就可以使用。通过调整截止日期和待办事项状态,我尽可能地测试了它

(defun zin/org测试截止日期(各州之间)
“如果截止日期为,则将标题从一个州改为另一个州
还没有定到今天。”
(交互式“从状态更改为状态:\n更改为状态:”)
(除非(org-at-heading-p)
(组织返回标题)
(let*((元素(点处的组织元素))
(todo状态(组织元素属性:todo关键字)
元素)
如果没有最后期限,不要出错
(截止日期(忽略错误)
(时间到天)
(组织时间字符串到时间)
(org)元素时间戳解释器
(组织元素属性:截止日期)
元素)无(()()))
(今天(时间到天(当前时间)))
(除非(或
有最后期限吗
(不是截止日期)
今天是截止日期吗
(eq今日截止日期)
待办事项陈述是错误的吗
(非(字符串=从状态到todo状态)))
(组织todo到状态)
(组织截止日期为零“))

然后,您可以将其绑定或封装在一个函数中,该函数定义了从状态到状态的
和从状态到状态的
。如果以交互方式调用,它还将提示输入这两种状态。

Awesome!!!非常感谢你。今晚晚些时候,我将有机会试用您的函数,我将向您报告任何问题和/或接受另一个感谢您的复选标记。我已为此函数中定义的变量设置了一些消息,例如,
(消息“this is the deadline variable:%s”deadline)
截止日期
变量始终打印
nil的消息,即使todo有截止日期。如果我们删除
(组织元素时间戳解释器
nil)
,那么截止日期变量的功能是否正确--我想?我对你的函数做了一些修改,并在我的初始问题下面发布了建议的修改函数,并对所述修改做了一些解释。如果您有任何其他建议,请让我知道。我已经做了更多的测试,我将接受这个答案,并在我的初始问题下方以
编辑
的形式发布建议修订。我现在可以每天自动更新日历了——所有截止日期为今天的事情都会从下一个动作变为活动。当然,还有无数其他的可能性。感谢您发明此功能--非常感谢
* 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 >
(defun zin/org-test-deadline (from-state to-state)

"Change headline from FROM-STATE to TO-STATE if the deadline is not already set to today."

  (interactive "sChange from state: \nsChange to state: ")

    (unless (org-at-heading-p)
      (org-back-to-heading))

    (let* (

      (element (org-element-at-point))

      (todo-state (org-element-property :todo-keyword element))

      ;; "ignore-errors" avoids throwing an error message if there is no deadline.
      (deadline
        (ignore-errors
        (time-to-days
        (org-time-string-to-time
        (org-element-property :deadline element) ))))

      (today (time-to-days (current-time))) )

    (message "This is the element variable:  %s" element)

    (message "This is the today variable:  %s" today)

    (message "This is the deadline variable:  %s" deadline)

    (message "This is the todo-state variable:  %s" todo-state)

    (message "This is the from-state variable:  %s" from-state)

    (message "This is the to-state variable:  %s" to-state)

    (if (not (eq today deadline))
      (message "The deadline is not today.")
      (message "Today is the deadline."))

    (if (and
      (not (eq today deadline)) ;; condition -- deadline not equal to today
      (string= todo-state from-state) ) ;; condition -- todo-state equals from-state
        (progn ;; Process following list if conditions were met.
          (org-todo to-state)
          (org-deadline nil ".")
          (message "The conditions were met, so we did everything that was required.") )
      (message "The conditions were not met, so nothing has been done."))
  ))