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 16:50:29 +0800 Message-ID: <87k3qcbnsa.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]:35047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5b9y-00085B-UN for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 07:10:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5b9r-0000Ta-MY for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 07:09:58 -0500 Received: from plane.gmane.org ([80.91.229.3]:52649) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5b9r-0000TV-Be for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 07:09:51 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1U5bA9-0003q1-Cq for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 13:10:09 +0100 Received: from 114.250.110.218 ([114.250.110.218]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 13:10:09 +0100 Received: from eric by 114.250.110.218 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 13:10:09 +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 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 [...] And more, this time to prevent errors when using column-narrowing cookies on columns containing peculiar-width strings. It's still going to look weird, often as not, but this will at least prevent blowups. I'm providing two possible patches. One is a one-liner that does the trick but produces ugly results. The other goes a wee bit overboard, but looks a little better. I offer either, or neither, for consideration. Eric --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-table-column-narrowing-play-nice-with-variable-.patch >From ccf294f9dad0b81240b8f1a0051cecfddd47d1c4 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 13 Feb 2013 16:46:33 +0800 Subject: [PATCH] Make table column narrowing play nice with variable-width strings --- lisp/org-table.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 3f276f8..d79b650 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 @@ -850,10 +850,19 @@ When nil, simply write \"#ERROR\" in corrupted fields.") (unless (> f1 1) (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) -- 1.8.1.3 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Prevent-errors-with-table-column-narrowing-and-varia.patch >From 319931ba76fc3ce5b8157f131d7c71c18f4c5d60 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 13 Feb 2013 15:07:59 +0800 Subject: [PATCH] Prevent errors with table column narrowing and variable-width strings --- lisp/org-table.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/org-table.el b/lisp/org-table.el index 3f276f8..6fbff7a 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -850,6 +850,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.") (unless (> f1 1) (error "Cannot narrow field starting with wide link \"%s\"" (match-string 0 xx))) + (setq f1 (round (* (/ (float (length xx)) (org-string-width xx)) f1))) (add-text-properties f1 (length xx) (list 'org-cwidth t) xx) (add-text-properties (- f1 2) f1 (list 'display org-narrow-column-arrow) -- 1.8.1.3 --=-=-=--