emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Unindentation fixup for code blocks


From: Psionic K
Subject: [PATCH] Unindentation fixup for code blocks
Date: Wed, 10 Jan 2024 18:20:07 +0900

When cleaning up hard indentation, I found my source blocks remaining indented.

The way that org-do-remove-indentation is sensitive to invisible text.
This occurs for source blocks whenever using org-modern-mode, where it
makes the source blocks align left.

By swapping out the arithmetic and expressions that relied on
current-column, the behavior is fixed.

There are several behaviors I only just found, so I don't expect a lot
of precision in my fix, but the patch I came up with follows:

>From 858077f0d2a7f4cd8699948229c2965f0c6bb0a1 Mon Sep 17 00:00:00 2001
From: Psionik K <73710933+psionic-k@users.noreply.github.com>
Date: Wed, 10 Jan 2024 18:05:53 +0900
Subject: [PATCH] when removing indentation, take into account invisible text

org-current-text-indentation sets invisibility spec to nil
temporarily.

One behavioral difference is that the point is no longer moved
forward.  Therefore, arithmetic is used instead of (current-column)
based math.  (current-column) is inaccurate when moving the point
through invisible text.
---
 lisp/org-macs.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 8def5cbb..0512cc48 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -408,13 +408,13 @@ line.  Return nil if it fails."
     ;; 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 ((ind (org-current-text-indentation)))
         (cond ((< ind n)
-                   (if (eolp) (delete-region (line-beginning-position) (point))
+                   (if (eolp) (delete-region (line-beginning-position)
+                                             (line-end-position))
                      (throw :exit nil)))
           (t (delete-region (line-beginning-position)
-                                    (progn (move-to-column n t)
-                                           (point)))))
+                                    (+ (line-beginning-position) n))))
         (forward-line)))
     ;; Signal success.
     t))))
-- 
2.42.0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]