org-narrow-to-subtree: Fix when current narrowing intersects subtree

* lisp/org.el (org-narrow-to-subtree): Fix error when current
narrowing intersects the current subtree.  When intersection happens,
behave historically, like the previous version of the command (that
did not use org-element).
This commit is contained in:
Ihor Radchenko 2024-02-18 17:47:18 +01:00
parent 7360c6b427
commit d314882301
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 12 additions and 4 deletions

View File

@ -7375,11 +7375,19 @@ With optional argument ELEMENT narrow to subtree around ELEMENT."
(org-element-lineage (org-element-lineage
(or element (org-element-at-point)) (or element (org-element-at-point))
'headline 'with-self)) 'headline 'with-self))
(begin (org-element-begin heading))
(end (org-element-end heading))) (end (org-element-end heading)))
(if (and heading end) (if (and heading end
(narrow-to-region (org-element-begin heading) ;; Preserve historical behavior throwing an error when
(if (= end (point-max)) ;; current heading starts before active narrowing.
end (1- end))) (<= (point-min) begin))
(narrow-to-region
begin
;; Preserve historical behavior not extending the active
;; narrowing when the subtree extends beyond it.
(min (point-max)
(if (= end (point-max))
end (1- end))))
(signal 'outline-before-first-heading nil)))) (signal 'outline-before-first-heading nil))))
(defun org-toggle-narrow-to-subtree () (defun org-toggle-narrow-to-subtree ()