added bulk delete and org agenda execution macro

This commit is contained in:
ndwarshuis 2018-12-06 22:54:48 -05:00
parent aaf734f89c
commit 470b491888
1 changed files with 53 additions and 31 deletions

View File

@ -733,11 +733,33 @@ and reverts all todo keywords to TODO."
(delete-region (region-beginning) (region-end)) (delete-region (region-beginning) (region-end))
(org-remove-empty-drawer-at (point))))) (org-remove-empty-drawer-at (point)))))
(defun nd/org-agenda-toggle-checkbox () (defun nd/org-insert-todo-heading-inactive-timestamp ()
"Toggle checkboxes in org agenda view using `org-toggle-checkbox'." "Insert a todo heading but also insert inactive timestamp set to now."
(interactive) (interactive)
(org-agenda-check-no-diary) ;; a bit redundant and hacky, with the advantage of being effective
(let* ((hdmarker (or (org-get-at-bol 'org-hd-marker) (when (not (org-insert-item 'checkbox))
(call-interactively 'org-insert-todo-heading)
(insert "\n")
(funcall-interactively 'org-time-stamp-inactive '(16))
(previous-line)))
(defun nd/org-delete-subtree ()
"Delete the entire subtree under the current heading without sending to kill ring."
(interactive)
(org-back-to-heading t)
(delete-region (point) (+ 1 (save-excursion (org-end-of-subtree)))))
#+END_SRC
*** interactive agenda commands
These are executed directly from agenda views and affect their source org buffers. The trick is that all of them must somehow go back to the heading to which they alude, execute, then update the agenda view with whatever changes have been made.
#+BEGIN_SRC emacs-lisp
(defmacro nd/org-agenda-cmd-wrapper (get-head &rest body)
"Wraps commands in BODY in necessary code to allow commands to be
called from the agenda buffer. Particularly, this wrapper will
navigate to the original header, execute BODY, then update the agenda
buffer."
'(org-agenda-check-no-diary)
`(let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
(org-agenda-error))) (org-agenda-error)))
(buffer (marker-buffer hdmarker)) (buffer (marker-buffer hdmarker))
(pos (marker-position hdmarker)) (pos (marker-position hdmarker))
@ -748,41 +770,35 @@ and reverts all todo keywords to TODO."
(widen) (widen)
(goto-char pos) (goto-char pos)
(org-show-context 'agenda) (org-show-context 'agenda)
(call-interactively #'org-toggle-checkbox) ,@body
(end-of-line 1) (when ,get-head (setq newhead (org-get-heading))))
(setq newhead (org-get-heading))) (if ,get-head
(org-agenda-change-all-lines newhead hdmarker) (org-agenda-change-all-lines newhead hdmarker)
(org-agenda-redo))
(beginning-of-line 1)))) (beginning-of-line 1))))
;; TODO, use a macro here...this is a common idiom (defun nd/org-agenda-toggle-checkbox ()
"Toggle checkboxes in org agenda view using `org-toggle-checkbox'."
(interactive)
(nd/org-agenda-cmd-wrapper
t
(call-interactively #'org-toggle-checkbox)))
(defun nd/org-agenda-clone-subtree-with-time-shift () (defun nd/org-agenda-clone-subtree-with-time-shift ()
"Apply `nd/org-clone-subtree-with-time-shift' to an agenda entry. "Apply `nd/org-clone-subtree-with-time-shift' to an agenda entry.
It will clone the last entry in the selected subtree." It will clone the last entry in the selected subtree."
(interactive) (interactive)
(org-agenda-check-no-diary) (nd/org-agenda-cmd-wrapper
(let* ((hdmarker (or (org-get-at-bol 'org-hd-marker) nil
(org-agenda-error)))
(buffer (marker-buffer hdmarker))
(pos (marker-position hdmarker))
(inhibit-read-only t)
newhead)
(org-with-remote-undo buffer
(with-current-buffer buffer
(widen)
(goto-char pos)
(org-show-context 'agenda)
(org-end-of-subtree) (org-end-of-subtree)
(call-interactively #'nd/org-clone-subtree-with-time-shift)) (call-interactively #'nd/org-clone-subtree-with-time-shift)))
(beginning-of-line 1)
(org-agenda-redo))))
(defun nd/org-insert-todo-heading-inactive-timestamp () (defun nd/org-agenda-delete-subtree ()
"Insert a todo heading but also insert inactive timestamp set to now." "Apply `nd/org-delete-subtree' to an agenda entry."
(interactive) (interactive)
(call-interactively 'org-insert-todo-heading) (nd/org-agenda-cmd-wrapper
(insert "\n") nil
(funcall-interactively 'org-time-stamp-inactive '(16)) (call-interactively #'nd/org-delete-subtree)))
(previous-line))
#+END_SRC #+END_SRC
** column view ** column view
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
@ -1533,6 +1549,12 @@ H is a string like +prop or -prop"
(lambda () (when org-agenda-hasprop-filter (lambda () (when org-agenda-hasprop-filter
(nd/org-agenda-filter-show-all-hasprop)))) (nd/org-agenda-filter-show-all-hasprop))))
#+END_SRC #+END_SRC
**** bulk actions
These add to the existing bulk actions in the agenda view.
#+BEGIN_SRC emacs-lisp
(setq org-agenda-bulk-custom-functions
'((?D nd/org-agenda-delete-subtree)))
#+END_SRC
**** holidays and birthdays **** holidays and birthdays
If I don't include this, I actually forget about major holidays. If I don't include this, I actually forget about major holidays.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp