2

特定の todo 状態と、今日とは異なる期限の存在をテストする最善の方法は何ですか?

org-state「TODOアイテムの状態が変更された後に実行される[h]ook」です。したがって、実際に todo の状態を変更しない限り、使用できないと思います(string-equal org-state "Next Action")string-equal以下にリストされているコードの 各行は拒否されます:Symbol's value as variable is void: org-todoorg-deadline. 締め切りは、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

         )

    )

)

サンプル *.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 >

編集: 以下は、Jonathan Leech-Pepin が下の回答で提案した関数の変更です。回答の最初のドラフトでは、問題が原因でnil変数からしか取得できませんでした-その参照を完全に削除すると、問題が修正されたようです。何が起こっているのかをよりよく理解できるように、途中でメッセージを設定しました。条件が満たされていないにもかかわらず関数が正しく機能していることを知らせるメッセージが欲しかったので、代わりに使用しました。型関数にラップするなど、いくつかのテストを実行しましたが、非常にうまく機能します-ラップされた関数はいくつかの方法で実行できますが、それはこのスレッドの範囲を超えています-たとえば、deadline(org-element-timestamp-interpreter . . . nil)ifunlesselsere-search-forward(&optional from-state to-state)そして(interactive)さらに(setq . . .)下へ。または(from-state to-state)および(interactive (list (setq . . .)

(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."))
  ))
4

1 に答える 1