summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-06-28 15:45:31 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-06-28 16:21:45 +0200
commit6d60138260d54bf8403b9c87155682447808335e (patch)
tree4b16d4e9ebdbfc3355630900036c528920ef77c4
parent03eb88661b7b270b19c00597ffc70a59f53f3a10 (diff)
downloadorg-mode-6d60138260d54bf8403b9c87155682447808335e.tar.gz
org-table: Do not modify buffer needlessly when aligning table
* lisp/org-table.el (org-table-align): Compare new table with old one before replacing it. Only replace modified lines.
-rw-r--r--lisp/org-table.el23
1 files changed, 11 insertions, 12 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 7b7d5f5..32dc777 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -723,7 +723,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(colpos (org-table-current-column))
(winstart (window-start))
(winstartline (org-current-line (min winstart (1- (point-max)))))
- lines (new "") lengths l typenums ty fields maxfields i
+ lines lengths l typenums ty fields maxfields i
column
(indent "") cnt frac
rfmt hfmt
@@ -796,7 +796,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(setq emptystrings (make-list maxfields ""))
;; Check for special formatting.
(setq i -1)
- (while (< (setq i (1+ i)) maxfields) ;; Loop over all columns
+ (while (< (setq i (1+ i)) maxfields) ;; Loop over all columns
(setq column (mapcar (lambda (x) (or (nth i x) "")) fields))
;; Check if there is an explicit width specified
(setq fmax nil)
@@ -820,7 +820,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(setq f1 (min fmax (or (string-match org-bracket-link-regexp xx) fmax)))
(unless (> f1 1)
(user-error "Cannot narrow field starting with wide link \"%s\""
- (match-string 0 xx)))
+ (match-string 0 xx)))
(setq f2 (length xx))
(if (= (org-string-width xx)
f2)
@@ -882,16 +882,15 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(setq rfmt (concat rfmt "\n")
hfmt (concat (substring hfmt 0 -1) "|\n"))
- (setq new (mapconcat
- (lambda (l)
- (if l (apply 'format rfmt
- (append (pop fields) emptystrings))
- hfmt))
- lines ""))
(move-marker org-table-aligned-begin-marker (point))
- (insert new)
- ;; Replace the old one
- (delete-region (point) end)
+ ;; Replace modified lines only.
+ (dolist (l lines)
+ (let ((line (if l (apply #'format rfmt (append (pop fields) emptystrings))
+ hfmt)))
+ (if (equal (buffer-substring (point) (line-beginning-position 2)) line)
+ (forward-line)
+ (insert line)
+ (delete-region (point) (line-beginning-position 2)))))
(move-marker end nil)
(move-marker org-table-aligned-end-marker (point))
(when (and orgtbl-mode (not (derived-mode-p 'org-mode)))