org-table: Small refactoring
* lisp/org-table.el (org-table-align): Small refactoring.
This commit is contained in:
parent
0aee6f76b3
commit
66bbe54a75
|
@ -825,10 +825,6 @@ FIELD is a string. WIDTH is a number. ALIGN is either \"c\",
|
||||||
(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* ((indent (progn (looking-at "[ \t]*") (match-string 0)))
|
||||||
(align-cookie?
|
|
||||||
(save-excursion
|
|
||||||
(re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*\\(?:|\\|$\\)"
|
|
||||||
end t)))
|
|
||||||
;; Table's rows as lists of fields. Rules are replaced
|
;; Table's rows as lists of fields. Rules are replaced
|
||||||
;; by nil. Trailing spaces are removed.
|
;; by nil. Trailing spaces are removed.
|
||||||
(fields (mapcar
|
(fields (mapcar
|
||||||
|
@ -847,31 +843,25 @@ FIELD is a string. WIDTH is a number. ALIGN is either \"c\",
|
||||||
(alignments nil))
|
(alignments nil))
|
||||||
;; Compute alignment and width for each column.
|
;; Compute alignment and width for each column.
|
||||||
(dotimes (i columns-number)
|
(dotimes (i columns-number)
|
||||||
(let* ((column (mapcar (lambda (x) (or (nth i x) ""))
|
(let* ((max-width 1)
|
||||||
fields))
|
(fixed-align? nil)
|
||||||
(width (apply #'max 1 (mapcar #'org-string-width column))))
|
(numbers 0)
|
||||||
;; Store the maximum width for the column.
|
|
||||||
(push width widths)
|
|
||||||
;; If there is no alignment cookie get the fraction of
|
|
||||||
;; numbers among non-empty cells to decide about alignment
|
|
||||||
;; of the column.
|
|
||||||
(push (cond
|
|
||||||
((= width 1) "r") ;doesn't matter
|
|
||||||
((and align-cookie?
|
|
||||||
(cl-some
|
|
||||||
(lambda (f)
|
|
||||||
(and (string-match "\\`<\\([lrc]\\)[0-9]*>\\'" f)
|
|
||||||
(match-string-no-properties 1 f)))
|
|
||||||
column)))
|
|
||||||
((let ((numbers 0)
|
|
||||||
(non-empty 0))
|
(non-empty 0))
|
||||||
(dolist (field column)
|
(dolist (row fields)
|
||||||
(unless (equal "" field)
|
(let ((cell (or (nth i row) "")))
|
||||||
|
(setq max-width (max max-width (org-string-width cell)))
|
||||||
|
(cond (fixed-align? nil)
|
||||||
|
((equal cell "") nil)
|
||||||
|
((string-match "\\`<\\([lrc]\\)[0-9]*>\\'" cell)
|
||||||
|
(setq fixed-align? (match-string 1 cell)))
|
||||||
|
(t
|
||||||
(cl-incf non-empty)
|
(cl-incf non-empty)
|
||||||
(when (string-match-p org-table-number-regexp field)
|
(when (string-match-p org-table-number-regexp cell)
|
||||||
(cl-incf numbers))))
|
(cl-incf numbers))))))
|
||||||
(>= numbers (* org-table-number-fraction non-empty)))
|
(push max-width widths)
|
||||||
"r")
|
(push (cond
|
||||||
|
(fixed-align?)
|
||||||
|
((>= numbers (* org-table-number-fraction non-empty)) "r")
|
||||||
(t "l"))
|
(t "l"))
|
||||||
alignments)))
|
alignments)))
|
||||||
(setq widths (nreverse widths))
|
(setq widths (nreverse widths))
|
||||||
|
|
Loading…
Reference in New Issue