emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] fix point position shifting in some org-src instances
@ 2021-04-28 10:33 Timothy
  2021-04-30  7:19 ` Bastien
  2021-05-01  9:58 ` Bastien
  0 siblings, 2 replies; 3+ messages in thread
From: Timothy @ 2021-04-28 10:33 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]

Hi All,

I've noticed for a while that if you have a block with
overlays/invisible characters that editing it with `org-edit-special'
moves the point around.

For example, with Org pretty entities enabled, and █ indicating the
cursor, if I call org-edit-special on a LaTeX fragment like:
  \( \alpha +█\beta \)
which is displayed as \( α +█β \)
The point is moved on creation of the org-src buffer
  \( \alpha + \beta █\)
Then if I move it back to after the "+", on calling `org-edit-src-exit'
the point is moved to
  \(█ \alpha + \beta \)
In the original buffer.

This may seem quite minor, but if you're editing a lot of LaTeX
fragments having the point constantly jumping around can be quite a
pain.

After investigating this, I tried shifting org-src--{goto-}coordinates
to a point-based approach from a column-based approach, and it seems to
have fixed the problem.

I have tested a few other situations (e.g. LaTeX environments, example
blocks, src blocks), and it seems to work well.

--
Timothy


[-- Attachment #2: 0001-org-src-Use-point-instead-of-column-for-coords.patch --]
[-- Type: text/x-patch, Size: 1882 bytes --]

From 8e8faf389d6d5c0769b5f95775ec7883820b10b3 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 28 Apr 2021 18:17:00 +0800
Subject: [PATCH] org-src: Use point instead of column for coords
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-src.el (org-src--coordinates, org-src--goto-coordinates):
Using a column-based approach fails to account for invisible regions
or display overlays that change the number of columns: for example,
showing a LaTeX \alpha as α.  In src edits which involve such
structures, this causes the point to be shifted undesirably.
By using a point-based approach this issue does not occur.
---
 lisp/org-src.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index cabedecb6..a694e5595 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -327,8 +327,7 @@ (defun org-src--coordinates (pos beg end)
      (cons (count-lines beg (line-beginning-position))
 	   ;; Column is relative to the end of line to avoid problems of
 	   ;; comma escaping or colons appended in front of the line.
-	   (- (current-column)
-	      (progn (end-of-line) (current-column)))))))
+	   (- (point) (min end (line-end-position)))))))
 
 (defun org-src--goto-coordinates (coord beg end)
   "Move to coordinates COORD relatively to BEG and END.
@@ -341,9 +340,9 @@ (defun org-src--goto-coordinates (coord beg end)
      (org-with-wide-buffer
       (goto-char beg)
       (forward-line (car coord))
-      (end-of-line)
-      (org-move-to-column (max (+ (current-column) (cdr coord)) 0))
-      (point)))))
+      (max (point)
+           (+ (min end (line-end-position))
+              (cdr coord)))))))
 
 (defun org-src--contents-area (datum)
   "Return contents boundaries of DATUM.
-- 
2.31.1


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

end of thread, other threads:[~2021-05-01  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-28 10:33 [PATCH] fix point position shifting in some org-src instances Timothy
2021-04-30  7:19 ` Bastien
2021-05-01  9:58 ` Bastien

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).