gpt4 book ai didi

emacs - 如何在 Emacs 组织模式中自动触发 TODO 状态的更改

转载 作者:行者123 更新时间:2023-12-01 01:07:28 26 4
gpt4 key购买 nike

使用 Emacs 组织模式,我经常有一个我希望一次激活一个的 TODO 项目列表,按顺序排列。例如,当列表中的项目 A 标记为“完成”时,我希望项目 B 自动标记为“待办事项”。我该如何做到这一点?这不应该是任何类型的一般行为,它应该只发生在我选择的特定对或项目列表中。

最佳答案

;; init-org-lawlist.el
;;
;; QUESTION @Brian Z -- stackoverflow.com: "How to automatically trigger a change in TODO state in Emacs org-mode."
;;
;; "I often have a list of TODO items that I want to have active one at a time, in sequence. For example when the
;; Item A in a list is marked "DONE", then I want Item B to be automatically be marked "TODO". How do I make this
;; happen? This should not be any kind of general behavior, it should only happen with specific pairs or lists of
;; items that I chose."
;;
;;
;; ANSWER @lawlist -- stackoverflow.com -- This script provides two (2) possible options:
;;
;; 1. Navigate to a ** TODO heading (must have at least one todo subtree underneath) and enter: M-x lawlist-done
;; OR
;; 2. Within a ** TODO heading (must have at least one todo subtree underneath), Shift-Right or Shift-Left and cycle
;; to the option ** DONE and then confirm yes or no.
;;
;; NOTE # A: This configuration script assumes the `org-archive-location` will use the SAME lawlist.org file for everything.
;; In this example, the script uses: (setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
;;
;; NOTE # B: Whenever using setq . . ., there is a likelihood that other settings with the same variable will be trumped.
;; So, after testing this script, it would be best to mix and match portions you like with your own configuration for org-mode.
;; You may need to temporarily disable your other configurations that use the same setq variables so as not to conflict while
;; testing this script.
;;
;; NOTE # C: Author to consider adding a check for the existence of at least one subsequent todo subtree as a condition precedent.
;;
;; NOTE # D: Author to consider adding a check that the user is on a second level tier (i.e., a todo) as a condition precedent.
;;
;;
;;
;;
;; SAMPLE lawlist.org CONFIGURATION FILE
;;
;;
;; * TASKS
;;
;; ** TODO [#A] First, figure out this new feature request. :lawlist:
;; DEADLINE: <2013-07-09 Tue>
;; :PROPERTIES:
;; :lawlist-drawer: ACTIVE
;; :END:
;;
;; ** NEXT [#B] Second, If at first you don't succeed, then try again. :lawlist:
;; :PROPERTIES:
;; :lawlist-drawer: PENDING
;; :END:
;;
;; ** WAITING [#C] Third, try again to figure out this new feature request. :lawlist: :WAITING:
;; :PROPERTIES:
;; :lawlist-drawer: DORMANT
;; :END:
;;
;; ** HOLD [#D] Fourth, try, try again to figure out this new feature request. :lawlist: :WAITING:HOLD:
;; :PROPERTIES:
;; :lawlist-drawer: DORMANT
;; :END:
;;
;;
;; * ARCHIVES
;;
;; ** DONE [#E] This task is a done deal. :lawlist:
;; :PROPERTIES:
;; :lawlist-drawer: COMPLETED
;; :END:


(require 'org)
(setq org-startup-folded 'showeverything) ;; overview | content | all | showeverything
(setq org-tags-column 0)
(setq org-startup-indented nil)
(setq org-indent-mode nil)
(setq org-support-shift-select t) ;; 'always to disable; or, t to use shift-select only when cursor is within a special context.
(setq org-cycle-separator-lines 1)
(setq org-insert-heading-respect-content t)
(setq org-blank-before-new-entry '((heading . t) (plain-list-item . nil)))
(setq org-enable-priority-commands t)
(setq org-highest-priority ?A)
(setq org-lowest-priority ?E)
(setq org-default-priority ?A)
(setq org-ellipsis " \u25bc" )


;; '!' (for a timestamp) or '@' (for a note with timestamp)
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "NEXT(n)" "WAITING(w)" "HOLD(h)" "|" "DONE(d)" "CANCELED(c)") )))

(setq org-global-properties '(("lawlist-drawer_ALL". "ACTIVE PENDING DORMANT COMPLETED")))
(setq org-default-properties (cons "lawlist-drawer" org-default-properties))

(setq org-todo-state-tags-triggers
(quote (("CANCELED" ("CANCELED" . t))
("WAITING" ("WAITING" . t))
("HOLD" ("WAITING" . t) ("HOLD" . t))
(done ("WAITING") ("HOLD"))
("TODO" ("WAITING") ("CANCELED") ("HOLD"))
("NEXT" ("WAITING") ("CANCELED") ("HOLD"))
("DONE" ("WAITING") ("CANCELED") ("HOLD")))))

(setq org-tag-alist (quote ((:startgroup)
("john-doe" . ?j)
("jane-doe" . ?J)
(:endgroup)
("lawlist" . ?0))))

(add-hook 'org-after-todo-state-change-hook 'lawlist-hook)
(defun lawlist-hook (&optional default-heading)
(let ((lawlist-item default-heading)
result)
(unless lawlist-item
(condition-case nil
(progn
(org-back-to-heading t)
(setq lawlist-item (elt (org-heading-components) 4)))
)
)
(when (string-equal org-state "DONE")
(if (string-equal org-state "DONE")
(or (yes-or-no-p (format "%s -- process?" org-state))
(error "You changed your mind.")))
(org-forward-heading-same-level 1)
(org-todo "TODO")
(org-priority ?A)
(org-deadline nil "<%<%Y-%m-%d %a>>")
(org-set-property "lawlist-drawer" "ACTIVE")
(org-backward-heading-same-level 1)
(org-priority ?E)
(org-deadline 'remove)
(org-set-property "lawlist-drawer" "COMPLETED")
;; (setq org-archive-save-context-info nil) ;; Set to nil if user doesn't want archive info.
;; NOTE: User must set the correct path to his / her lawlist.org file.
(setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
(org-archive-subtree)
(goto-char (point-min))
(re-search-forward "^\* ARCHIVES" nil t)
(org-sort-entries t ?a)
;; (org-sort-entries t ?d) additional sorting criteria if deadline is not removed.
(lawlist-org-cleanup)
(goto-char (point-min))
(re-search-forward lawlist-item nil t)
(beginning-of-line)
(message "Please take a moment to visually verify your completed tasks has been refiled correctly, then press any key.")
(read-event) )))


(defun delete-trailing-blank-lines-at-end-of-file ()
"Deletes all blank lines at the end of the file, even the last one"
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(delete-blank-lines)
(let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
(if (> trailnewlines 0)
(progn
(delete-char trailnewlines)))))))

(defun lawlist-org-cleanup ()
(interactive)
(save-excursion
(replace-regexp "\n+\\*\\* " "\n\n** " nil (point-min) (point-max))
(replace-regexp "\n+\\* " "\n\n\n* " nil (point-min) (point-max))
(replace-regexp "\n\t\s*" "\n " nil (point-min) (point-max)) )
(delete-trailing-blank-lines-at-end-of-file) )


(defun lawlist-done (&optional default-heading)
(interactive)
(remove-hook 'org-after-todo-state-change-hook 'lawlist-hook)
(let ((lawlist-item default-heading)
result)
(unless lawlist-item
(condition-case nil
(progn
(org-back-to-heading t)
(setq lawlist-item (elt (org-heading-components) 4)))
)
)
(org-forward-heading-same-level 1)
(org-todo "TODO")
(org-priority ?A)
(org-deadline nil "<%<%Y-%m-%d %a>>")
(org-set-property "lawlist-drawer" "ACTIVE")
(org-backward-heading-same-level 1)
(org-todo "DONE")
(org-priority ?E)
(org-deadline 'remove)
(org-set-property "lawlist-drawer" "COMPLETED")
;; (setq org-archive-save-context-info nil) ;; Set to nil if user doesn't want archive info.
;; NOTE: User must set the correct path to his / her lawlist.org file.
(setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
(org-archive-subtree)
(goto-char (point-min))
(re-search-forward "^\* ARCHIVES" nil t)
(org-sort-entries t ?a)
;; (org-sort-entries t ?d) additional sorting criteria if deadline is not removed.
(lawlist-org-cleanup)
(goto-char (point-min))
(re-search-forward lawlist-item nil t)
(beginning-of-line))
(add-hook 'org-after-todo-state-change-hook 'lawlist-hook) )

(provide 'init-org-lawlist)
lawlist.org用于测试脚本的示例文件应该看起来是 exactly像这样:
* TASKS

** TODO [#A] First, figure out this new feature request. :lawlist:
DEADLINE: <2013-07-09 Tue>
:PROPERTIES:
:lawlist-drawer: ACTIVE
:END:

** NEXT [#B] Second, If at first you don't succeed, then try again. :lawlist:
:PROPERTIES:
:lawlist-drawer: PENDING
:END:

** WAITING [#C] Third, try again to figure out this new feature request. :lawlist: :WAITING:
:PROPERTIES:
:lawlist-drawer: DORMANT
:END:

** HOLD [#D] Fourth, try, try again to figure out this new feature request. :lawlist: :WAITING:HOLD:
:PROPERTIES:
:lawlist-drawer: DORMANT
:END:


* ARCHIVES

** DONE [#E] This task is a done deal. :lawlist:
:PROPERTIES:
:lawlist-drawer: COMPLETED
:END:

关于emacs - 如何在 Emacs 组织模式中自动触发 TODO 状态的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17559662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com