Ihor Radchenko <yanta...@posteo.net> writes:

> Thanks! This patch does apply.
> I am not yet sure if I like this patch or the previous one more. I am
> thinking about combining them and implementing something like
> `org-move-to-text-column'.

I do not see immediate use of `org-move-to-text-column', so let's keep
things simple.

I am attaching an amended patch with modified commit message and
docstring describing the invisible text is accounted as visible.
I also added TINYCHANGE cookie as you do not appear to have FSF
copyright assignment.

Let me know if you want to make any changes to the new version of the
patch.

>From b7eb76647395eac256602bdecaab4aea3ffbe68c Mon Sep 17 00:00:00 2001
Message-ID: <b7eb76647395eac256602bdecaab4aea3ffbe68c.1705838536.git.yanta...@posteo.net>
From: Psionik K <73710933+psioni...@users.noreply.github.com>
Date: Wed, 10 Jan 2024 22:37:28 +0900
Subject: [PATCH v2] org-do-remove-indentation: Ignore invisible text

* lisp/org-macs.el (org-do-remove-indentation): Set
`buffer-invisibility-spec' to nil before detecting the column or
moving to a column.

This fixes src_block indentation removal for org-modern-mode but will
also correct other cases of hidden indentation.

TINYCHANGE
---
 lisp/org-macs.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 8def5cbb2..fc4fd7975 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -388,6 +388,8 @@ (defmacro org-current-text-indentation ()
 
 (defun org-do-remove-indentation (&optional n skip-fl)
   "Remove the maximum common indentation from the buffer.
+Do not consider invisible text when calculating indentation.
+
 When optional argument N is a positive integer, remove exactly
 that much characters from indentation, if possible.  When
 optional argument SKIP-FL is non-nil, skip the first
@@ -408,7 +410,8 @@ (defun org-do-remove-indentation (&optional n skip-fl)
 	;; Remove exactly N indentation, but give up if not possible.
         (when skip-fl (forward-line))
 	(while (not (eobp))
-	  (let ((ind (progn (skip-chars-forward " \t") (current-column))))
+	  (let* ((buffer-invisibility-spec nil) ; do not treat invisible text specially
+                 (ind (progn (skip-chars-forward " \t") (current-column))))
 	    (cond ((< ind n)
                    (if (eolp) (delete-region (line-beginning-position) (point))
                      (throw :exit nil)))
-- 
2.43.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to