GNU bug report logs - #10368
24.0.92; wrong char-width by display table

Previous Next

Package: emacs;

Reported by: Kenichi Handa <handa <at> m17n.org>

Date: Mon, 26 Dec 2011 05:14:02 UTC

Severity: normal

Found in version 24.0.92

Fixed in version 23.4

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10368 in the body.
You can then email your comments to 10368 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Mon, 26 Dec 2011 05:14:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kenichi Handa <handa <at> m17n.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 26 Dec 2011 05:14:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kenichi Handa <handa <at> m17n.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.0.92; wrong char-width by display table
Date: Mon, 26 Dec 2011 14:10:52 +0900
I received the bug report about char-width used with display
table as this.

(progn
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?a [?エ ?イ])
  (char-width ?a))
=> 2

The attached is a patch to fix it.  As this bug exists in
Emacs 23.3 (so it is not a regression), I have not yet
installed it to the trunk.  What should I do?
  (1) commit it to emacs-23 branch now
  (2) commit it to trunk now
  (3) after the release of 24, commit it to trunk

---
Kenichi Handa
handa <at> m17n.org

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-12-25 09:06:42 +0000
+++ src/ChangeLog	2011-12-26 04:57:25 +0000
@@ -1,3 +1,8 @@
+2011-12-26  Kenichi Handa  <handa <at> m17n.org>
+
+	* character.c (char_width): New function.
+	(Fchar_width, c_string_width, lisp_string_width): Use char_width.
+
 2011-12-24  Andreas Schwab  <schwab <at> linux-m68k.org>
 
 	* callint.c (Fcall_interactively): Don't truncate prompt string.

=== modified file 'src/character.c'
--- src/character.c	2011-11-20 02:29:42 +0000
+++ src/character.c	2011-12-26 04:55:24 +0000
@@ -308,6 +308,31 @@
     }
 }
 
+
+/* Return width (columns) of C considering the buffer display table DP. */
+
+static int
+char_width (int c, struct Lisp_Char_Table *dp)
+{
+  int width = CHAR_WIDTH (c);
+
+  if (dp)
+    {
+      Lisp_Object disp = DISP_CHAR_VECTOR (dp, c), ch;
+      int i;
+
+      if (VECTORP (disp))
+	for (i = 0, width = 0; i < ASIZE (disp); i++)
+	  {
+	    ch = AREF (disp, i);
+	    if (CHARACTERP (ch))
+	      width += CHAR_WIDTH (XFASTINT (ch));
+	  }
+    }
+  return width;
+}
+
+
 DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0,
        doc: /* Return width of CHAR when displayed in the current buffer.
 The width is measured by how many columns it occupies on the screen.
@@ -315,21 +340,11 @@
 usage: (char-width CHAR)  */)
   (Lisp_Object ch)
 {
-  Lisp_Object disp;
   int c, width;
-  struct Lisp_Char_Table *dp = buffer_display_table ();
 
   CHECK_CHARACTER (ch);
   c = XINT (ch);
-
-  /* Get the way the display table would display it.  */
-  disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil;
-
-  if (VECTORP (disp))
-    width = sanitize_char_width (ASIZE (disp));
-  else
-    width = CHAR_WIDTH (c);
-
+  width = char_width (c, buffer_display_table ());
   return make_number (width);
 }
 
@@ -350,22 +365,9 @@
 
   while (i_byte < len)
     {
-      int bytes, thiswidth;
-      Lisp_Object val;
+      int bytes;
       int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
-
-      if (dp)
-	{
-	  val = DISP_CHAR_VECTOR (dp, c);
-	  if (VECTORP (val))
-	    thiswidth = sanitize_char_width (ASIZE (val));
-	  else
-	    thiswidth = CHAR_WIDTH (c);
-	}
-      else
-	{
-	  thiswidth = CHAR_WIDTH (c);
-	}
+      int thiswidth = char_width (c, dp);
 
       if (precision > 0
 	  && (width + thiswidth > precision))
@@ -447,18 +449,7 @@
 	  else
 	    c = str[i_byte], bytes = 1;
 	  chars = 1;
-	  if (dp)
-	    {
-	      val = DISP_CHAR_VECTOR (dp, c);
-	      if (VECTORP (val))
-		thiswidth = sanitize_char_width (ASIZE (val));
-	      else
-		thiswidth = CHAR_WIDTH (c);
-	    }
-	  else
-	    {
-	      thiswidth = CHAR_WIDTH (c);
-	    }
+	  thiswidth = char_width (c, dp);
 	}
 
       if (precision <= 0)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Tue, 27 Dec 2011 22:16:02 GMT) Full text and rfc822 format available.

Message #8 received at 10368 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Kenichi Handa <handa <at> m17n.org>
Cc: 10368 <at> debbugs.gnu.org
Subject: Re: bug#10368: 24.0.92; wrong char-width by display table
Date: Mon, 26 Dec 2011 20:16:26 -0500
> The attached is a patch to fix it.  As this bug exists in
> Emacs 23.3 (so it is not a regression), I have not yet
> installed it to the trunk.  What should I do?
>   (1) commit it to emacs-23 branch now
>   (2) commit it to trunk now
>   (3) after the release of 24, commit it to trunk

Please commit it now to emacs-23 branch (and then merge into trunk).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Fri, 13 Jan 2012 02:45:01 GMT) Full text and rfc822 format available.

Message #11 received at 10368 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 10368 <at> debbugs.gnu.org, Kenichi Handa <handa <at> m17n.org>
Subject: Re: bug#10368: 24.0.92; wrong char-width by display table
Date: Thu, 12 Jan 2012 21:43:48 -0500
Stefan Monnier wrote:

> Please commit it now to emacs-23 branch (and then merge into trunk).

Better hurry if you want it to be in Emacs 23.4:

http://lists.gnu.org/archive/html/emacs-devel/2012-01/msg00387.html




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Fri, 13 Jan 2012 06:04:02 GMT) Full text and rfc822 format available.

Message #14 received at 10368 <at> debbugs.gnu.org (full text, mbox):

From: Kenichi Handa <handa <at> m17n.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: monnier <at> IRO.UMontreal.CA, 10368 <at> debbugs.gnu.org
Subject: Re: bug#10368: 24.0.92; wrong char-width by display table
Date: Fri, 13 Jan 2012 15:02:38 +0900
In article <cvipkgz5i3.fsf <at> fencepost.gnu.org>, Glenn Morris <rgm <at> gnu.org> writes:

> Stefan Monnier wrote:
> > Please commit it now to emacs-23 branch (and then merge into trunk).

> Better hurry if you want it to be in Emacs 23.4:

Thank you for the notice.  I somehow missed the above mail
from Stefan.  I've just committed the fix to emacs-23
branch.

But I have not yet merged it into trunk.  When I did the
merging last time, I had a problem (mainly because I didn't
understand bzr well).  So, I'd like to ask someone else who
is doing that kind of merging regularly.

---
Kenichi Handa
handa <at> m17n.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Fri, 13 Jan 2012 07:51:02 GMT) Full text and rfc822 format available.

Message #17 received at 10368 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Kenichi Handa <handa <at> m17n.org>
Cc: monnier <at> IRO.UMontreal.CA, 10368 <at> debbugs.gnu.org
Subject: Re: bug#10368: 24.0.92; wrong char-width by display table
Date: Fri, 13 Jan 2012 02:50:05 -0500
Kenichi Handa wrote:

> I've just committed the fix to emacs-23 branch.
>
> But I have not yet merged it into trunk.  When I did the
> merging last time, I had a problem (mainly because I didn't
> understand bzr well).  So, I'd like to ask someone else who
> is doing that kind of merging regularly.

It's generally pretty straightforward with bzrmerge.el.
However, in this case there is a merge conflict that I do not know how
to resolve. The code in the trunk has been changed to use
`sanitize_char_width'. If you can say what the diff against trunk should
look like, I could merge it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10368; Package emacs. (Sun, 15 Jan 2012 23:43:01 GMT) Full text and rfc822 format available.

Message #20 received at 10368 <at> debbugs.gnu.org (full text, mbox):

From: Kenichi Handa <handa <at> m17n.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: monnier <at> IRO.UMontreal.CA, 10368 <at> debbugs.gnu.org
Subject: Re: bug#10368: 24.0.92; wrong char-width by display table
Date: Mon, 16 Jan 2012 08:41:34 +0900
In article <l4nw0jb2q.fsf <at> fencepost.gnu.org>, Glenn Morris <rgm <at> gnu.org> writes:

> It's generally pretty straightforward with bzrmerge.el.

Ah, I didn't know about bzrmerge.el.

> However, in this case there is a merge conflict that I do not know how
> to resolve. The code in the trunk has been changed to use
> `sanitize_char_width'. If you can say what the diff against trunk should
> look like, I could merge it.

Thank you.  Here's the diff against trunk.

---
Kenichi Handa
handa <at> m17n.org

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-12-25 09:06:42 +0000
+++ src/ChangeLog	2011-12-26 04:57:25 +0000
@@ -1,3 +1,8 @@
+2011-12-26  Kenichi Handa  <handa <at> m17n.org>
+
+	* character.c (char_width): New function.
+	(Fchar_width, c_string_width, lisp_string_width): Use char_width.
+
 2011-12-24  Andreas Schwab  <schwab <at> linux-m68k.org>
 
 	* callint.c (Fcall_interactively): Don't truncate prompt string.

=== modified file 'src/character.c'
--- src/character.c	2011-11-20 02:29:42 +0000
+++ src/character.c	2011-12-26 04:55:24 +0000
@@ -308,6 +308,31 @@
     }
 }
 
+
+/* Return width (columns) of C considering the buffer display table DP. */
+
+static int
+char_width (int c, struct Lisp_Char_Table *dp)
+{
+  int width = CHAR_WIDTH (c);
+
+  if (dp)
+    {
+      Lisp_Object disp = DISP_CHAR_VECTOR (dp, c), ch;
+      int i;
+
+      if (VECTORP (disp))
+	for (i = 0, width = 0; i < ASIZE (disp); i++)
+	  {
+	    ch = AREF (disp, i);
+	    if (CHARACTERP (ch))
+	      width += CHAR_WIDTH (XFASTINT (ch));
+	  }
+    }
+  return width;
+}
+
+
 DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0,
        doc: /* Return width of CHAR when displayed in the current buffer.
 The width is measured by how many columns it occupies on the screen.
@@ -315,21 +340,11 @@
 usage: (char-width CHAR)  */)
   (Lisp_Object ch)
 {
-  Lisp_Object disp;
   int c, width;
-  struct Lisp_Char_Table *dp = buffer_display_table ();
 
   CHECK_CHARACTER (ch);
   c = XINT (ch);
-
-  /* Get the way the display table would display it.  */
-  disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil;
-
-  if (VECTORP (disp))
-    width = sanitize_char_width (ASIZE (disp));
-  else
-    width = CHAR_WIDTH (c);
-
+  width = char_width (c, buffer_display_table ());
   return make_number (width);
 }
 
@@ -350,22 +365,9 @@
 
   while (i_byte < len)
     {
-      int bytes, thiswidth;
-      Lisp_Object val;
+      int bytes;
       int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
-
-      if (dp)
-	{
-	  val = DISP_CHAR_VECTOR (dp, c);
-	  if (VECTORP (val))
-	    thiswidth = sanitize_char_width (ASIZE (val));
-	  else
-	    thiswidth = CHAR_WIDTH (c);
-	}
-      else
-	{
-	  thiswidth = CHAR_WIDTH (c);
-	}
+      int thiswidth = char_width (c, dp);
 
       if (precision > 0
 	  && (width + thiswidth > precision))
@@ -447,18 +449,7 @@
 	  else
 	    c = str[i_byte], bytes = 1;
 	  chars = 1;
-	  if (dp)
-	    {
-	      val = DISP_CHAR_VECTOR (dp, c);
-	      if (VECTORP (val))
-		thiswidth = sanitize_char_width (ASIZE (val));
-	      else
-		thiswidth = CHAR_WIDTH (c);
-	    }
-	  else
-	    {
-	      thiswidth = CHAR_WIDTH (c);
-	    }
+	  thiswidth = char_width (c, dp);
 	}
 
       if (precision <= 0)





bug marked as fixed in version 23.4, send any further explanations to 10368 <at> debbugs.gnu.org and Kenichi Handa <handa <at> m17n.org> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 19 Jan 2012 07:26:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 16 Feb 2012 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 127 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.