unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10368: 24.0.92; wrong char-width by display table
@ 2011-12-26  5:10 Kenichi Handa
  2011-12-27  1:16 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Kenichi Handa @ 2011-12-26  5:10 UTC (permalink / raw)
  To: 10368

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@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@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@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)






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

* bug#10368: 24.0.92; wrong char-width by display table
  2011-12-26  5:10 bug#10368: 24.0.92; wrong char-width by display table Kenichi Handa
@ 2011-12-27  1:16 ` Stefan Monnier
  2012-01-13  2:43   ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-12-27  1:16 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: 10368

> 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





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

* bug#10368: 24.0.92; wrong char-width by display table
  2011-12-27  1:16 ` Stefan Monnier
@ 2012-01-13  2:43   ` Glenn Morris
  2012-01-13  6:02     ` Kenichi Handa
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2012-01-13  2:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10368

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





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

* bug#10368: 24.0.92; wrong char-width by display table
  2012-01-13  2:43   ` Glenn Morris
@ 2012-01-13  6:02     ` Kenichi Handa
  2012-01-13  7:50       ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Kenichi Handa @ 2012-01-13  6:02 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10368

In article <cvipkgz5i3.fsf@fencepost.gnu.org>, Glenn Morris <rgm@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@m17n.org





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

* bug#10368: 24.0.92; wrong char-width by display table
  2012-01-13  6:02     ` Kenichi Handa
@ 2012-01-13  7:50       ` Glenn Morris
  2012-01-15 23:41         ` Kenichi Handa
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2012-01-13  7:50 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: 10368

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.





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

* bug#10368: 24.0.92; wrong char-width by display table
  2012-01-13  7:50       ` Glenn Morris
@ 2012-01-15 23:41         ` Kenichi Handa
  0 siblings, 0 replies; 6+ messages in thread
From: Kenichi Handa @ 2012-01-15 23:41 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10368

In article <l4nw0jb2q.fsf@fencepost.gnu.org>, Glenn Morris <rgm@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@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@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@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)






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

end of thread, other threads:[~2012-01-15 23:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-26  5:10 bug#10368: 24.0.92; wrong char-width by display table Kenichi Handa
2011-12-27  1:16 ` Stefan Monnier
2012-01-13  2:43   ` Glenn Morris
2012-01-13  6:02     ` Kenichi Handa
2012-01-13  7:50       ` Glenn Morris
2012-01-15 23:41         ` Kenichi Handa

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).