0

I have a checklist to do when adding new tasks for myself in org-mode. I would like to see it when capturing a task via org-capture, but I don't want it to be among the text I am adding because I would have to erase it every time. How can I do this?

1

Your question is quite vague. For an instance you do not say anything about the location of your checklist. I assume here that your checklist is stored in a separate file and you just want to view the contents of this file in a separate window as long as org-capture is running.

If you put the following lisp code into your [[][init file]] and re-start emacs the command org-capture displays the checklist given by the customization option org-checklist-file when the property list of the TODO entry is shown.

The checklist disappears when you hit C-c C-c.

(require 'subr-x) ;; for `when-let'
(defcustom org-checklist-file "~/checklist.org"
  "Checklist for adding org agenda items."
  :type 'file
  :group 'org-agenda)

(defvar org-capture-checklist-window nil
  "Where `org-capture-with-checklist' saves the created window.
So that it can be deleted in `org-capture-after-finalize-hook'.")

(defun org-capture-checklist-window ()
  "Just do `org-capture' but show the contents of `org-checklist-file' therewhile."
  (interactive "P")
  (when-let ((buf (find-file-noselect org-checklist-file))
         (window (display-buffer buf nil)))
    (set-window-dedicated-p window t)))

(defun org-capture-delete-checklist-window ()
  "Delete window from `org-capture-checklist-window' if it is alive."
  (when (window-live-p org-capture-checklist-window)
    (delete-window org-capture-checklist-window)))

(add-hook 'org-capture-mode-hook #'org-capture-checklist-window)
(add-hook 'org-capture-after-finalize-hook #'org-capture-delete-checklist-window)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defcustom org-checklist-file "~/checklist.org"
  "Checklist for adding org agenda items."
  :type 'file
  :group 'org-agenda)

(defun org-capture-with-checklist (&rest _)
  "Like `org-capture' but also displays the checklist from `org-checklist-file'
when the property drawer is shown."
  (cl-assert (file-readable-p org-checklist-file)
         "Org checklist file \"%s\" not readable." org-checklist-file)
  (let (window)
    (unwind-protect
    (let ((buffer (find-file-noselect org-checklist-file)))
      (when (buffer-live-p buffer)
        (setq window (display-buffer buffer)))
      (call-interactively #'org-capture))
      (when (window-live-p window)
    (delete-window window)))
    ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.