Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
org-mode agenda quick month/year selection with hjkl and 0-9.
(defvar lawlist-month)
(defvar lawlist-year nil)
(defun lawlist-org-agenda-view-mode-dispatch ()
"Select the month in agenda view."
(message "View: [1-9] [o]CT [n]OV [d]EC, j(next), k(prev).")
(let* ((a (read-char-exclusive))
(year (or lawlist-year
(setq lawlist-year
(nth 5 (decode-time (current-time))))))
(month (case a
(?j (cond
((null lawlist-month) 1)
((= 12 lawlist-month)
(setq year (incf lawlist-year))
(t (1+ lawlist-month))))
(?k (cond
((null lawlist-month) 1)
((= 1 lawlist-month)
(setq year (decf lawlist-year))
(t (1- lawlist-month))))
(setq year (incf lawlist-year))
(or lawlist-month 1))
(setq year (decf lawlist-year))
(or lawlist-month 1))
(?o 10)
(?n 11)
(?d 12)
(t (and (> a ?0) (<= a ?9) (- a ?0))))))
(if (not (setq lawlist-month month))
(progn (setq lawlist-year)
(message "Aborted"))
(org-agenda nil "a")
(read (format "%d%02d" year month)))
(calendar-other-month month year)

This comment has been minimized.

Copy link

@lawlist lawlist commented Jul 21, 2013

Excellent! Thank you very much. The only suggestion I have would be to add a short description to the initial message to include the new features you have written -- i.e., for options "h" (next year) and "l" (previous year) . This is such a useful function, I'm certain other Emacs users are going to find it on the net and want to use it on a daily basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.