emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Unindentation fixup for code blocks
@ 2024-01-10  9:20 Psionic K
  2024-01-10 12:28 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Psionic K @ 2024-01-10  9:20 UTC (permalink / raw)
  To: emacs-orgmode

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-12 12:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10  9:20 [PATCH] Unindentation fixup for code blocks Psionic K
2024-01-10 12:28 ` Ihor Radchenko
2024-01-10 13:55   ` Psionic K
2024-01-10 15:45     ` Ihor Radchenko
2024-01-21 12:04       ` Ihor Radchenko
2024-03-12 12:26         ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).