When `org-loop-over-headlines-in-active-region' is 'start-level, the
command should loop only over the headings having the same level as the
first one, but it loops over all headings in the region. This patch fixes
the issue.
From 289d6bdcb8328554c6dd4136d38f1220d239940e Mon Sep 17 00:00:00 2001
From: alexgiorev <alex.gio...@gmail.com>
Date: Wed, 9 Feb 2022 16:22:09 +0200
Subject: [PATCH] lisp/org.el: Fix org-set-tags-command active region bug

* lisp/org.el (org-set-tags-command): When called with an active
region and `org-loop-over-headlines-in-active-region` having a value
`start-level', it is supposed to loop only over the headings at the
same level as the first one, but without this fix it loops over all
headings in the region.
---
 lisp/org.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index ef8d460e1..b2091a4fe 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -12183,11 +12183,12 @@ in Lisp code use `org-set-tags' instead."
     (cond
      ((equal '(4) arg) (org-align-tags t))
      ((and (org-region-active-p) org-loop-over-headlines-in-active-region)
-      (let (org-loop-over-headlines-in-active-region) ;  hint: infinite recursion.
+      (let ((original org-loop-over-headlines-in-active-region)
+            (org-loop-over-headlines-in-active-region nil)) ;  hint: infinite recursion.
 	(org-map-entries
 	 #'org-set-tags-command
 	 nil
-	 (if (eq org-loop-over-headlines-in-active-region 'start-level)
+	 (if (eq original 'start-level)
 	     'region-start-level
 	   'region)
 	 (lambda () (when (org-invisible-p) (org-end-of-subtree nil t))))))
-- 
2.25.1

Reply via email to