123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- (require 'org)
- (defvar export-time-format "%Y%m%d%H%M"
- "format of timestamp appended to export file")
- (defvar export-function 'org-export-as-ascii
- "function used to prepare the export file for printing")
- (defun org-reset-checkbox-state-maybe ()
- "Reset all checkboxes in an entry if the `RESET_CHECK_BOXES' property is set"
- (interactive "*")
- (if (org-entry-get (point) "RESET_CHECK_BOXES")
- (save-restriction
- (save-excursion
- (org-narrow-to-subtree)
- (org-show-subtree)
- (goto-char (point-min))
- (let ((end (point-max)))
- (while (< (point) end)
- (when (org-at-item-checkbox-p)
- (replace-match "[ ]" t t))
- (beginning-of-line 2))))
- (org-update-checkbox-count-maybe))))
- (defun org-make-checklist-export ()
- "Produce a checklist containing all unchecked items from a list
- of checkbox items"
- (interactive "*")
- (if (org-entry-get (point) "LIST_EXPORT_BASENAME")
- (let* ((export-file (concat (org-entry-get (point) "LIST_EXPORT_BASENAME")
- "-" (format-time-string export-time-format)
- ".org"))
- exported-lines
- title)
- (save-restriction
- (save-excursion
- (org-narrow-to-subtree)
- (org-show-subtree)
- (goto-char (point-min))
- (if (looking-at org-complex-heading-regexp)
- (setq title (match-string 4)))
- (goto-char (point-min))
- (let ((end (point-max)))
- (while (< (point) end)
- (when (and (org-at-item-checkbox-p)
- (or (string= (match-string 0) "[ ]")
- (string= (match-string 0) "[-]")))
- (add-to-list 'exported-lines (thing-at-point 'line) t))
- (beginning-of-line 2)))
- (set-buffer (get-buffer-create export-file))
- (org-insert-heading)
- (insert (or title export-file) "\n")
- (dolist (entry exported-lines) (insert entry))
- (org-update-checkbox-count-maybe)
- (write-file export-file)
- (if (y-or-n-p "Print list? ")
- ((funcall export-function)
- (a2ps-buffer))))))))
- (defun org-checklist ()
- (if (member state org-done-keywords)
- (org-make-checklist-export))
- (org-reset-checkbox-state-maybe))
- (add-hook 'org-after-todo-state-change-hook 'org-checklist)
- (provide 'org-checklist)
|