emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Re: double-width characters in tables
Date: Wed, 13 Feb 2013 10:23:32 +0800	[thread overview]
Message-ID: <87621x3qaj.fsf_-_@ericabrahamsen.net> (raw)
In-Reply-To: 87a9r93s0o.fsf@ericabrahamsen.net

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

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Achim Gratz <Stromeko@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


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

From 46a126e57494479db6b64035dfc43698963cffb5 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@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


  reply	other threads:[~2013-02-13  2:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12 10:56 double-width characters in tables Eric Abrahamsen
2013-02-12 11:02 ` Jambunathan K
2013-02-12 11:22   ` Bastien
2013-02-12 11:16 ` Bastien
2013-02-12 15:43   ` Eric Abrahamsen
2013-02-12 15:50     ` Nick Dokos
2013-02-12 15:55     ` Bastien
2013-02-12 17:55       ` Takaaki ISHIKAWA
2013-02-12 18:43     ` Achim Gratz
2013-02-13  1:46       ` Eric Abrahamsen
2013-02-13  2:23         ` Eric Abrahamsen [this message]
2013-02-13 11:42           ` [PATCH] " Bastien
2013-02-13 13:18             ` Eric Abrahamsen
2013-02-13  8:50         ` Eric Abrahamsen
2013-02-13 11:31         ` 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=87621x3qaj.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).