emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: mis-alignment in org-tables with Tibetan characters
Date: Sun, 25 May 2014 13:14:06 +0800	[thread overview]
Message-ID: <87a9a6cue9.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 8738fzbim2.fsf@bzg.ath.cx

[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]

Bastien <bzg@gnu.org> writes:

> Hi Eric,
>
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> 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.
>
> I want to apply the patches on master -- can you give them a commit
> message with an Emacs changelog?  Also, the first one (0001-...) does
> not apply on master anymore.
>
> Thanks in advance!

The patch series that would not die!

I'm not a git wizard, but I think I was able to apply both these patches
to master with no problem: they're now sitting on top of 56b47fb and
nothing is going wrong (I think). Can you try again?

Here they are with better commit messages.

E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-string-width-in-table-field-justification.patch --]
[-- Type: text/x-diff, Size: 1468 bytes --]

From 3e6fd0e2790156a9bd68401bdabbf1b170408ba6 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Wed, 13 Feb 2013 11:56:18 +0800
Subject: [PATCH 1/2] Use string width in table field justification

lisp/org-table.el (org-table-justify-field-maybe): Use
org-string-width instead of length to calculate the visual width of
table cells -- helps with double-width charsets, etc.
---
 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 6a7935e..5e0177f 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -981,13 +981,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-no-properties
+				(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.9.3


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Improve-table-column-narrowing-with-variable-width-s.patch --]
[-- Type: text/x-diff, Size: 2143 bytes --]

From 7850f739a6ef21bcc92763150861a67798282f12 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Wed, 13 Feb 2013 16:46:33 +0800
Subject: [PATCH 2/2] Improve table column narrowing with variable-width
 strings

lisp/org-table.el (org-table-align): Use org-string-width to make a
better guess as to 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.
---
 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 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)
-- 
1.9.3


  reply	other threads:[~2014-05-25  5:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-03  3:29 mis-alignment in org-tables with Tibetan characters Steffan Iverson
2014-02-03  5:33 ` Steffan Iverson
2014-02-04 18:13   ` Michael Brand
2014-02-05  0:00     ` Steffan Iverson
2014-02-05  5:35       ` Michael Brand
2014-02-06 13:03         ` Michael Brand
2014-02-03  9:20 ` Bastien
2014-02-04 14:18   ` Eric Abrahamsen
2014-02-04 16:35     ` Bastien
2014-02-10  4:09       ` Eric Abrahamsen
2014-02-11  2:50         ` Steffan Iverson
2014-02-11  3:12           ` Eric Abrahamsen
2014-05-24 10:01         ` Bastien
2014-05-25  5:14           ` Eric Abrahamsen [this message]
2014-05-25  5:18             ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9a6cue9.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).