emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org 7a6bb0904d 3/3: org-table-justify-field-maybe: Do n


From: ELPA Syncer
Subject: [elpa] externals/org 7a6bb0904d 3/3: org-table-justify-field-maybe: Do not leak alignment data from other tables
Date: Sat, 3 Feb 2024 09:58:24 -0500 (EST)

branch: externals/org
commit 7a6bb0904d01b50680f9028f7c0f3cfc6ae3aa6e
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-table-justify-field-maybe: Do not leak alignment data from other tables
    
    * lisp/org-table.el (org-table-justify-field-maybe): Make sure that
    `org-table-last-alignment' and `org-table-last-column-widths' do not
    lea from another table that was re-aligned recently.
    
    Link: 
https://old.reddit.com/r/emacs/comments/10gegwa/recalculating_an_orgmode_table_causes/
---
 lisp/org-table.el | 80 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 41 insertions(+), 39 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6e08bfb935..c6e16c1fd7 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4474,46 +4474,48 @@ Optional argument NEW may specify text to replace the 
current field content."
   (cond
    ((and (not new) org-table-may-need-update)) ; Realignment will happen anyway
    ((org-at-table-hline-p))
-   ((and (not new)
-        (or (not (eq (marker-buffer org-table-aligned-begin-marker)
-                     (current-buffer)))
-            (< (point) org-table-aligned-begin-marker)
-            (>= (point) org-table-aligned-end-marker)))
-    ;; This is not the same table, force a full re-align.
-    (setq org-table-may-need-update t))
    (t
-    ;; Realign the current field, based on previous full realign.
-    (let ((pos (point))
-         (col (org-table-current-column)))
-      (when (> col 0)
-       (skip-chars-backward "^|")
-       (if (not (looking-at " *\\(?:\\([^|\n]*?\\) *\\(|\\)\\|\\([^|\n]+?\\) 
*\\($\\)\\)"))
-           (setq org-table-may-need-update t)
-         (let* ((align (nth (1- col) org-table-last-alignment))
-                (width (nth (1- col) org-table-last-column-widths))
-                (cell (match-string 0))
-                (field (match-string 1))
-                (properly-closed? (/= (match-beginning 2) (match-end 2)))
-                (new-cell
-                 (save-match-data
-                   (cond (org-table-may-need-update
-                          (format " %s |" (or new field)))
-                         ((not properly-closed?)
-                          (setq org-table-may-need-update t)
-                          (format " %s |" (or new field)))
-                         ((not new)
-                          (concat (org-table--align-field field width align)
-                                  "|"))
-                         ((and width (<= (org-string-width new nil 'org-table) 
width))
-                          (concat (org-table--align-field new width align)
-                                  "|"))
-                         (t
-                          (setq org-table-may-need-update t)
-                          (format " %s |" new))))))
-           (unless (equal new-cell cell)
-             (let (org-table-may-need-update)
-               (replace-match new-cell t t)))
-           (goto-char pos))))))))
+    (when (or (not (eq (marker-buffer org-table-aligned-begin-marker)
+                    (current-buffer)))
+             (< (point) org-table-aligned-begin-marker)
+             (>= (point) org-table-aligned-end-marker))
+      ;; This is not the same table, force a full re-align.
+      (setq org-table-may-need-update t
+            org-table-last-alignment nil
+            org-table-last-column-widths nil))
+    (when new
+      ;; Realign the current field, based on previous full realign.
+      (let ((pos (point))
+           (col (org-table-current-column)))
+        (when (> col 0)
+         (skip-chars-backward "^|")
+         (if (not (looking-at " *\\(?:\\([^|\n]*?\\) *\\(|\\)\\|\\([^|\n]+?\\) 
*\\($\\)\\)"))
+             (setq org-table-may-need-update t)
+           (let* ((align (nth (1- col) org-table-last-alignment))
+                  (width (nth (1- col) org-table-last-column-widths))
+                  (cell (match-string 0))
+                  (field (match-string 1))
+                  (properly-closed? (/= (match-beginning 2) (match-end 2)))
+                  (new-cell
+                   (save-match-data
+                     (cond (org-table-may-need-update
+                            (format " %s |" (or new field)))
+                           ((not properly-closed?)
+                            (setq org-table-may-need-update t)
+                            (format " %s |" (or new field)))
+                           ((not new)
+                            (concat (org-table--align-field field width align)
+                                    "|"))
+                           ((and width (<= (org-string-width new nil 
'org-table) width))
+                            (concat (org-table--align-field new width align)
+                                    "|"))
+                           (t
+                            (setq org-table-may-need-update t)
+                            (format " %s |" new))))))
+             (unless (equal new-cell cell)
+               (let (org-table-may-need-update)
+                 (replace-match new-cell t t)))
+             (goto-char pos)))))))))
 
 ;;;###autoload
 (defun org-table-sort-lines



reply via email to

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