emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Psionic K <psionik@positron.solutions>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Unindentation fixup for code blocks
Date: Wed, 10 Jan 2024 18:20:07 +0900	[thread overview]
Message-ID: <CADQMGASvOR3VvLFEe_5VDFP3=hC_xpvoLPubN5eC1YNtOZWKZQ@mail.gmail.com> (raw)

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	other threads:[~2024-01-10  9:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10  9:20 Psionic K [this message]
2024-01-10 12:28 ` [PATCH] Unindentation fixup for code blocks 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADQMGASvOR3VvLFEe_5VDFP3=hC_xpvoLPubN5eC1YNtOZWKZQ@mail.gmail.com' \
    --to=psionik@positron.solutions \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).