From 2e92b9abb90420915d4055e34ec8e0753733705b Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Mon, 18 Mar 2019 17:01:16 +0100 Subject: [PATCH] org-habit: C-u K in agenda toggles display all/today habits * lisp/org-habit.el (org-habit-toggle-display-in-agenda): New command. --- doc/org-manual.org | 3 ++- etc/ORG-NEWS | 6 +++++- lisp/org-habit.el | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index cc6cf1419..071a7f97b 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -4187,7 +4187,8 @@ the way habits are displayed in the agenda. #+vindex: org-habit-show-habits-only-for-today If non-~nil~, only show habits in today's agenda view. The default - value is ~t~. + value is ~t~. Pressing {{{kbd(C-u K)}}} in the agenda toggles this + variable. Lastly, pressing {{{kbd(K)}}} in the agenda buffer causes habits to temporarily be disabled and do not appear at all. Press {{{kbd(K)}}} diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index da5edee9d..8e07da416 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -152,7 +152,10 @@ LaTeX font locking. negative value as a valid repeater to shift time stamps in backward in cloned subtrees. You can give, for example, ā€˜-3dā€™ to shift three days in the past. - +*** Toggle display of all vs. undone scheduled habits conveniently +== (~org-habit-toggle-display-in-agenda~) in an agenda toggles +the display of all habits to those which are undone and scheduled. +This is a function for convenience. ** New functions *** ~org-dynamic-block-insert-dblock~ @@ -164,6 +167,7 @@ dynamic block in ~org-dynamic-block-alist~. *** ~org-table-cell-down~ *** ~org-table-cell-left~ *** ~org-table-cell-right~ +*** ~org-habit-toggle-display-in-agenda~ ** Removed functions *** ~org-babel-set-current-result-hash~ diff --git a/lisp/org-habit.el b/lisp/org-habit.el index 2ef1b7af4..939d7eb78 100644 --- a/lisp/org-habit.el +++ b/lisp/org-habit.el @@ -449,7 +449,18 @@ current time." (message "Habits turned %s" (if org-habit-show-habits "on" "off"))) -(org-defkey org-agenda-mode-map "K" 'org-habit-toggle-habits) +(defun org-habit-toggle-display-in-agenda (arg) + "Toggle display of habits in agenda. +With ARG toggle display of all vs. undone scheduled habits. +See `org-habit-show-all-today'." + (interactive "P") + (if (not arg) + (org-habit-toggle-habits) + (org-agenda-check-type t 'agenda) + (setq org-habit-show-all-today (not org-habit-show-all-today)) + (when org-habit-show-habits (org-agenda-redo)))) + +(org-defkey org-agenda-mode-map "K" 'org-habit-toggle-display-in-agenda) (provide 'org-habit)