Eric Abrahamsen <e...@ericabrahamsen.net> writes: > Achim Gratz <strom...@nexgo.de> writes: > >> Eric Abrahamsen writes: >>> Yes, org-string-width eventually calls string-width, so that behaves >>> "correctly" as far as it goes, but unfortunately that's not where the >>> value in the text properties comes from... >>> >>> 《蛙》 >>> 123456 >>> >>> Doesn't that line up for you? Those bracket characters come with their >>> own "whitespace", maybe this is clearer: >>> >>> 正能量 >>> 123456 >>> >>> One Chinese character should definitely take up two screen columns.
[...] > On second thought I don't think it's a problem with text properties. > (add-text-properties 0 6 '() "正能量") gives an Args out of range error, > and it probably should, since all it cares about is the number of > characters in the string. Here's one provisional attempt to fix one instance of weirdness, inside `org-table-justify-field-maybe'. This handles re-justification of table fields when you hit TAB or S-TAB. It turns out this spot doesn't use text properties, but match-end/beginning locations. This patch Works For Me, though it's a little ugly and I have no idea if it may cause other repercussions. Could someone just glance over it? Thanks, Eric
>From 46a126e57494479db6b64035dfc43698963cffb5 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen <e...@ericabrahamsen.net> Date: Wed, 13 Feb 2013 10:11:37 +0800 Subject: [PATCH] Make table field justification respect string width --- lisp/org-table.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 204787f..6bbe732 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -977,14 +977,16 @@ Optional argument NEW may specify text to replace the current field content." (progn (setq s (match-string 1) o (match-string 0) - l (max 1 (- (match-end 0) (match-beginning 0) 3)) + l (max 1 + (- (org-string-width + (buffer-substring + (match-end 0) (match-beginning 0))) 3)) e (not (= (match-beginning 2) (match-end 2)))) (setq f (format (if num " %%%ds %s" " %%-%ds %s") l (if e "|" (setq org-table-may-need-update t) "")) n (format f s)) (if new - (if (<= (length new) l) ;; FIXME: length -> str-width? + (if (<= (org-string-width new) l) (setq n (format f new)) (setq n (concat new "|") org-table-may-need-update t))) (if (equal (string-to-char n) ?-) (setq n (concat " " n))) -- 1.8.1.3