From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasushi SHOJI Subject: [PATCH] org: Fix tag width calculation for multi-column chars Date: Tue, 31 May 2016 16:25:42 +0900 Message-ID: <87wpmar7b4.wl@dns1.atmark-techno.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7eVw-0004dS-QL for emacs-orgmode@gnu.org; Tue, 31 May 2016 03:55:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7eVq-00062s-Nk for emacs-orgmode@gnu.org; Tue, 31 May 2016 03:54:59 -0400 Received: from p654789.hkidff01.ap.so-net.ne.jp ([121.101.71.137]:57701 helo=gw.atmark-techno.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7eVq-00062J-FA for emacs-orgmode@gnu.org; Tue, 31 May 2016 03:54:54 -0400 Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by gw.atmark-techno.com (Postfix) with ESMTPS id 4EA0220103 for ; Tue, 31 May 2016 16:54:51 +0900 (JST) Received: by mail-pa0-f70.google.com with SMTP id x1so306681121pav.3 for ; Tue, 31 May 2016 00:54:51 -0700 (PDT) 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" To: emacs-orgmode@gnu.org 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" (funcall list-visible-lines 'canonical nil))))) + +;;; 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