Skip to content

Instantly share code, notes, and snippets.

@abo-abo
Created July 20, 2013 11:35
Show Gist options
  • Save abo-abo/6044729 to your computer and use it in GitHub Desktop.
Save abo-abo/6044729 to your computer and use it in GitHub Desktop.
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."
(interactive)
(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))
1)
(t (1+ lawlist-month))))
(?k (cond
((null lawlist-month) 1)
((= 1 lawlist-month)
(setq year (decf lawlist-year))
12)
(t (1- lawlist-month))))
(?h
(setq year (incf lawlist-year))
(or lawlist-month 1))
(?l
(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")
(org-agenda-month-view
(read (format "%d%02d" year month)))
(calendar)
(calendar-other-month month year)
(lawlist-org-agenda-view-mode-dispatch))))
@lawlist
Copy link

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