forked from mirrors/org-mode
table: Avoid unnecessary consing
* lisp/org-table.el (org-table-align): Avoid unnecessary consing.
This commit is contained in:
parent
ba7bf12b44
commit
e39365e32f
|
@ -4346,8 +4346,7 @@ FIELD is a string. WIDTH is a number. ALIGN is either \"c\",
|
||||||
(move-marker org-table-aligned-end-marker end)
|
(move-marker org-table-aligned-end-marker end)
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(org-table-with-shrunk-columns
|
(org-table-with-shrunk-columns
|
||||||
(let* ((indent (progn (looking-at "[ \t]*") (match-string 0)))
|
(let* ((table (org-table-to-lisp))
|
||||||
(table (org-table-to-lisp))
|
|
||||||
(rows (remq 'hline table))
|
(rows (remq 'hline table))
|
||||||
;; Compute number of columns.
|
;; Compute number of columns.
|
||||||
(columns-number (apply #'max (mapcar #'length rows)))
|
(columns-number (apply #'max (mapcar #'length rows)))
|
||||||
|
@ -4384,30 +4383,32 @@ FIELD is a string. WIDTH is a number. ALIGN is either \"c\",
|
||||||
(setq org-table-last-column-widths widths)
|
(setq org-table-last-column-widths widths)
|
||||||
;; Build new table rows. Only replace rows that actually
|
;; Build new table rows. Only replace rows that actually
|
||||||
;; changed.
|
;; changed.
|
||||||
(dolist (row table)
|
(let ((rule (and (memq 'hline table)
|
||||||
(let ((previous (buffer-substring (point) (line-end-position)))
|
(mapconcat (lambda (w) (make-string (+ 2 w) ?-))
|
||||||
(new
|
widths
|
||||||
(format "%s|%s|"
|
"+")))
|
||||||
indent
|
(indent (progn (looking-at "[ \t]*|") (match-string 0))))
|
||||||
(if (eq row 'hline) ;horizontal rule
|
(dolist (row table)
|
||||||
(mapconcat (lambda (w) (make-string (+ 2 w) ?-))
|
(let ((previous (buffer-substring (point) (line-end-position)))
|
||||||
widths
|
(new
|
||||||
"+")
|
(concat indent
|
||||||
(let ((cells ;add missing fields
|
(if (eq row 'hline) rule
|
||||||
(append row
|
(let* ((offset (- columns-number (length row)))
|
||||||
(make-list (- columns-number
|
(fields (if (= 0 offset) row
|
||||||
(length row))
|
;; Add missing fields.
|
||||||
""))))
|
(append row
|
||||||
(mapconcat #'identity
|
(make-list offset "")))))
|
||||||
(cl-mapcar #'org-table--align-field
|
(mapconcat #'identity
|
||||||
cells
|
(cl-mapcar #'org-table--align-field
|
||||||
widths
|
fields
|
||||||
alignments)
|
widths
|
||||||
"|"))))))
|
alignments)
|
||||||
(if (equal new previous)
|
"|")))
|
||||||
(forward-line)
|
"|")))
|
||||||
(insert new "\n")
|
(if (equal new previous)
|
||||||
(delete-region (point) (line-beginning-position 2)))))
|
(forward-line)
|
||||||
|
(insert new "\n")
|
||||||
|
(delete-region (point) (line-beginning-position 2))))))
|
||||||
(set-marker end nil)
|
(set-marker end nil)
|
||||||
(when org-table-overlay-coordinates (org-table-overlay-coordinates))
|
(when org-table-overlay-coordinates (org-table-overlay-coordinates))
|
||||||
(setq org-table-may-need-update nil))))))
|
(setq org-table-may-need-update nil))))))
|
||||||
|
|
Loading…
Reference in New Issue