From dc2198971bbacab4093275b1c2f65afb3e1a0b21 Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Mon, 15 Jul 2019 00:22:51 +0200 Subject: [PATCH] org-agenda: Respect narrowing for agenda restricted to buffer * lisp/org-agenda.el (org-agenda): Add a condition to check if narrowing is in effect and in case set the agenda restriction markers. * etc/ORG-NEWS (Respect narrowing when agenda command is restricted to buffer): * doc/org-manual.org (The Agenda Dispatcher): Mention the behavior. --- doc/org-manual.org | 5 +++-- etc/ORG-NEWS | 2 ++ lisp/org-agenda.el | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 8411d9d9a..f216b45dc 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -8491,8 +8491,9 @@ commands: - {{{kbd(<)}}} :: #+kindex: < @r{(Agenda dispatcher)} - Restrict an agenda command to the current buffer[fn:91]. After - pressing {{{kbd(<)}}}, you still need to press the character + Restrict an agenda command to the current buffer[fn:91]. If + narrowing is in effect restrict to the narrowed part of the buffer. + After pressing {{{kbd(<)}}}, you still need to press the character selecting the command. - {{{kbd(< <)}}} :: diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 557b398e0..68fa9ad00 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -398,6 +398,8 @@ leave unfolded subtrees unfolded. I.e. treat the whole file as if it was a subtree. +*** Respect narrowing when agenda command is restricted to buffer + * Version 9.2 ** Incompatible changes *** Removal of OrgStruct mode mode and radio lists diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 633bbf308..3e992bb91 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2848,7 +2848,13 @@ Pressing `<' twice means to restrict to the current subtree or region (org-back-to-heading t) (move-marker org-agenda-restrict-begin (point)) (move-marker org-agenda-restrict-end - (progn (org-end-of-subtree t))))))) + (progn (org-end-of-subtree t))))) + ((and (eq restriction 'buffer) + (or (< 1 (point-min)) + (< (point-max) (1+ (buffer-size))))) + (setq org-agenda-restrict (current-buffer)) + (move-marker org-agenda-restrict-begin (point-min)) + (move-marker org-agenda-restrict-end (point-max))))) ;; For example the todo list should not need it (but does...) (cond