From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: [PATCH] Re: double-width characters in tables Date: Wed, 13 Feb 2013 10:23:32 +0800 Message-ID: <87621x3qaj.fsf_-_@ericabrahamsen.net> References: <878v6tdcmm.fsf@ericabrahamsen.net> <87vc9xixze.fsf@bzg.ath.cx> <87vc9x4jwq.fsf@ericabrahamsen.net> <877gmdcqzd.fsf@Rainer.invalid> <87a9r93s0o.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5Rvd-0006co-OW for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 21:18:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5Rvb-0007Ce-9u for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 21:18:33 -0500 Received: from plane.gmane.org ([80.91.229.3]:51045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5Rvb-0007CU-2w for emacs-orgmode@gnu.org; Tue, 12 Feb 2013 21:18:31 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1U5Rvq-0002sI-W3 for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 03:18:46 +0100 Received: from 222.95.4.58 ([222.95.4.58]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 03:18:46 +0100 Received: from eric by 222.95.4.58 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 03:18:46 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Eric Abrahamsen writes: > Achim Gratz 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-table-field-justification-respect-string-width.patch >From 46a126e57494479db6b64035dfc43698963cffb5 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen 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 --=-=-=--