all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] org: Fix tag width calculation for multi-column chars
@ 2016-05-31  7:25 Yasushi SHOJI
  2016-05-31 20:02 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Yasushi SHOJI @ 2016-05-31  7:25 UTC (permalink / raw)
  To: emacs-orgmode

Some characters have multiple column width.  Calculating string width
with points gives a wrong value than actual display width.  Use
`string-width' instead.

Here is an ECM for this problem.  `M-x org-update-statistics-cookies` or
`C-c #` on bar moves the tag on the headline.

* foo [0/0]								:abc:
** child
* bar [0/0]							     :日本語:
** child
12345678901234567890123456789012345678901234567890123456789012345678901234567890
         1         2         3         4         5         6         7         8

Simple test case is also included.
---

Hello,

While using Japanese as a tag, it seems to move the position of it
when `org-align-tags-here' is called.

If Japanese characters are allowed for tags, please merge it.

Let me know if I miss something.

Thanks,
            yashi


 lisp/org.el              |  2 +-
 testing/lisp/test-org.el | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index e4edcf4..d34163f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14922,7 +14922,7 @@ If ONOFF is `on' or `off', don't toggle but set to this state."
     (if	(and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
 	     (< pos (match-beginning 2)))
 	(progn
-	  (setq tags-l (- (match-end 2) (match-beginning 2)))
+	  (setq tags-l (string-width (match-string 2)))
 	  (goto-char (match-beginning 1))
 	  (insert " ")
 	  (delete-region (point) (1+ (match-beginning 2)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 73245b4..7de0fa0 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -4406,6 +4406,29 @@ Paragraph<point>"
 		   (funcall list-visible-lines 'canonical nil)))))
 
 
+\f
+;;; Tags
+
+(ert-deftest test-org/tag-align ()
+  "Test `org-align-tags-here' with different display width."
+  (should
+   ;;      12345678901234567890
+   (equal "* Test         :abc:"
+	  (org-test-with-temp-text "* Test :abc:"
+	    (let ((org-tags-column -20)
+		  (indent-tabs-mode nil))
+	     (org-fix-tags-on-the-fly))
+	    (buffer-string))))
+  (should
+   ;;      12345678901234567890
+   (equal "* Test      :日本語:"
+	  (org-test-with-temp-text "* Test :日本語:"
+	    (let ((org-tags-column -20)
+		  (indent-tabs-mode nil))
+	     (org-fix-tags-on-the-fly))
+	    (buffer-string)))))
+
+
 (provide 'test-org)
 
 ;;; test-org.el ends here
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-06-02 11:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-31  7:25 [PATCH] org: Fix tag width calculation for multi-column chars Yasushi SHOJI
2016-05-31 20:02 ` Nicolas Goaziou
2016-05-31 21:06   ` Samuel Wales
2016-06-01  5:57     ` Georgiy Tugai
2016-06-02 11:29       ` Yasushi SHOJI
2016-06-01 13:00     ` [PATCH] " Yasushi SHOJI
2016-06-01 14:27     ` Rasmus
2016-06-01 12:52   ` Yasushi SHOJI
2016-06-01 17:34     ` Nicolas Goaziou
2016-06-02 11:13       ` Yasushi SHOJI
2016-06-02 11:34         ` Nicolas Goaziou

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.