Browse Source

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.
Marco Wahl 1 month ago
parent
commit
dc2198971b
3 changed files with 12 additions and 3 deletions
  1. 3 2
      doc/org-manual.org
  2. 2 0
      etc/ORG-NEWS
  3. 7 1
      lisp/org-agenda.el

+ 3 - 2
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(< <)}}} ::

+ 2 - 0
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

+ 7 - 1
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