From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: mis-alignment in org-tables with Tibetan characters Date: Mon, 10 Feb 2014 12:09:20 +0800 Message-ID: <87d2ivpq1b.fsf@ericabrahamsen.net> References: <87a9e8y2ky.fsf@bzg.ath.cx> <8738jzc66w.fsf@ericabrahamsen.net> <87zjm6n8dh.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCiBU-0007pW-MO for emacs-orgmode@gnu.org; Sun, 09 Feb 2014 23:09:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCiBN-0007zB-Tn for emacs-orgmode@gnu.org; Sun, 09 Feb 2014 23:09:28 -0500 Received: from mail-pb0-f46.google.com ([209.85.160.46]:39932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCiBN-0007z2-Kl for emacs-orgmode@gnu.org; Sun, 09 Feb 2014 23:09:21 -0500 Received: by mail-pb0-f46.google.com with SMTP id um1so5684232pbc.19 for ; Sun, 09 Feb 2014 20:09:20 -0800 (PST) In-Reply-To: <87zjm6n8dh.fsf@bzg.ath.cx> (Bastien's message of "Tue, 04 Feb 2014 17:35:38 +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: Bastien Cc: Steffan Iverson , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Bastien writes: > Eric Abrahamsen writes: > >> I've been using that patch or something like it for nearly a year now, >> with no adverse effects. I'm on the road right now, give me a day and >> I'll take a closer look at what I've got... > > Great -- thanks in advance! I'll then wait before releasing a new > minor version and merging it into Emacs for Emacs 24.4. > > To other core maintainers: if you see important issues that needs to > be fixed in maint, let me know. Sorry this took a while to get to... I think it was a little simpler than I thought -- at least I hope that's true, and I'm not missing something really obvious. There are two patches attached, a simple one that handles re-justification of table fields during field movement, and another that allows for narrowing of columns with double-width strings. The second patch is uglier, and doesn't work 100% well (you get misalignment if you try to narrow a double-wide to an odd number of single-width characters), but it's better than nothing. Please test! Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-table-field-justification-respect-string-width.patch >From f03f4755b2d3e62d9f88845d93390a364805c131 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 13 Feb 2013 11:56:18 +0800 Subject: [PATCH 1/9] 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 520ac8a..33ae63e 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -973,14 +973,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.5.4 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Make-table-column-narrowing-play-nice-with-variable-.patch >From 85aee797a97194d9c29d7baac6415555f3849f7f Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 13 Feb 2013 16:46:33 +0800 Subject: [PATCH 2/9] 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 33ae63e..32dd025 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -758,7 +758,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 @@ -843,10 +843,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) -- 1.8.5.4 --=-=-=--