diff options
author | Eric Abrahamsen <eric@ericabrahamsen.net> | 2013-02-13 16:46:33 +0800 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2014-05-25 07:18:12 +0200 |
commit | 62950827eccedbb7deb11684c2ad6995213cf67d (patch) | |
tree | 11b18052b59a607820c8612bf89ccd16d0d8c76c | |
parent | 4af31090b4420978067bc24512467bcc9a78a7f1 (diff) | |
download | org-mode-62950827eccedbb7deb11684c2ad6995213cf67d.tar.gz |
Improve table column narrowing with variable-width strings
org-table.el (org-table-align): Use `org-string-width'.
This aims at better guessing how wide a narrowed table column should
actually be. This won't work perfectly with variable-width scripts,
as it still only narrows in full-column increments, but it's better
than before.
-rw-r--r-- | lisp/org-table.el | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index 5e0177f..d1f9686 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -765,7 +765,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.") (hfmt1 (concat (make-string sp2 ?-) "%s" (make-string sp1 ?-) "+")) emptystrings links dates emph raise narrow - falign falign1 fmax f1 len c e space) + falign falign1 fmax f1 f2 len c e space) (untabify beg end) (remove-text-properties beg end '(org-cwidth t org-dwidth t display t)) ;; Check if we have links or dates @@ -851,10 +851,19 @@ When nil, simply write \"#ERROR\" in corrupted fields.") (unless (> f1 1) (user-error "Cannot narrow field starting with wide link \"%s\"" (match-string 0 xx))) - (add-text-properties f1 (length xx) (list 'org-cwidth t) xx) - (add-text-properties (- f1 2) f1 - (list 'display org-narrow-column-arrow) - xx))))) + (setq f2 (length xx)) + (if (= (org-string-width xx) + f2) + (setq f2 f1) + (setq f2 1) + (while (< (org-string-width (substring xx 0 f2)) + f1) + (setq f2 (1+ f2)))) + (add-text-properties f2 (length xx) (list 'org-cwidth t) xx) + (add-text-properties (if (>= (string-width (substring xx (1- f2) f2)) 2) + (1- f2) (- f2 2)) f2 + (list 'display org-narrow-column-arrow) + xx))))) ;; Get the maximum width for each column (push (apply 'max (or fmax 1) 1 (mapcar 'org-string-width column)) lengths) |