Last active
March 21, 2016 10:46
-
-
Save alphapapa/99a759f535fea1915fe3 to your computer and use it in GitHub Desktop.
Emacs: Display org-agenda for current subtree or region
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun org-agenda-subtree-or-region (prefix) | |
| "Display an agenda view for the current subtree or region. | |
| With prefix, display only TODO-keyword items." | |
| (interactive "p") | |
| (let (header) | |
| (if (use-region-p) | |
| (progn | |
| (setq header "Region") | |
| (put 'org-agenda-files 'org-restrict (list (buffer-file-name (current-buffer)))) | |
| (setq org-agenda-restrict (current-buffer)) | |
| (move-marker org-agenda-restrict-begin (region-beginning)) | |
| (move-marker org-agenda-restrict-end | |
| (save-excursion | |
| (goto-char (1+ (region-end))) ; If point is at pos 0, include heading on that line | |
| (org-end-of-subtree)))) | |
| (progn | |
| ;; No region; restrict to subtree | |
| (setq header "Subtree") | |
| (org-agenda-set-restriction-lock 'subtree))) | |
| ;; sorting doesn't seem to be working, but the header is | |
| (let ((org-agenda-sorting-strategy '(priority-down timestamp-up)) | |
| (org-agenda-overriding-header header)) | |
| (org-search-view (if (>= prefix 4) t nil) "*")) | |
| (org-agenda-remove-restriction-lock t) | |
| (message nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment