GNU bug report logs - #10978
`calendar-string-spread' loses with double-width characters

Previous Next

Package: emacs;

Reported by: Štěpán Němec <stepnem <at> gmail.com>

Date: Fri, 9 Mar 2012 11:59:02 UTC

Severity: normal

Fixed in version 24.0.95

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 10978 in the body.
You can then email your comments to 10978 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#10978; Package emacs. (Fri, 09 Mar 2012 11:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Štěpán Němec <stepnem <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 09 Mar 2012 11:59:03 GMT) Full text and rfc822 format available.

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

From: Štěpán Němec <stepnem <at> gmail.com>
To: bug-gnu-emacs <bug-gnu-emacs <at> gnu.org>
Subject: `calendar-string-spread' loses with double-width characters
Date: Fri, 09 Mar 2012 12:57:30 +0100
The algorithm used obviously works using `length', but for every
double-width character the resulting string is one char too long when
actually displayed, defeating its purpose when formatting the calendar
mode line (`calendar-update-mode-line' et al.).

Ex.:

(calendar-string-spread '("a" "b" "c") ?\s 10)
;=> "a   b    c" ; OK

(calendar-string-spread '("矢" "b" "c") ?\s 10)
;=> "矢   b    c" ; not OK

-- 
Štěpán




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Fri, 09 Mar 2012 12:35:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Štěpán Němec <stepnem <at> gmail.com>
Cc: 10978 <at> debbugs.gnu.org
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Fri, 09 Mar 2012 14:33:05 +0200
> From: Štěpán Němec
> 	<stepnem <at> gmail.com>
> Date: Fri, 09 Mar 2012 12:57:30 +0100
> 
> The algorithm used obviously works using `length', but for every
> double-width character the resulting string is one char too long when
> actually displayed, defeating its purpose when formatting the calendar
> mode line (`calendar-update-mode-line' et al.).

It should use `string-width' instead of `length'.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Fri, 09 Mar 2012 14:07:02 GMT) Full text and rfc822 format available.

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

From: "Drew Adams" <drew.adams <at> oracle.com>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>,
	"'Štepán Nemec'" <stepnem <at> gmail.com>
Cc: 10978 <at> debbugs.gnu.org
Subject: RE: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Fri, 9 Mar 2012 06:05:24 -0800
> It should use `string-width' instead of `length'.

The Elisp manual has a section on `Strings and Characters', which is one of the
sections about Lisp data types. It has details about lots of string- and
character-related functions.

Perhaps some node in that section (maybe `Text Comparison'?) should at least
mention function `string-width' and cross-reference the node `Width' in the
`Display' part of the manual.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Sat, 10 Mar 2012 02:57:01 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 10978 <at> debbugs.gnu.org,
	Štěpán Němec <stepnem <at> gmail.com>
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Fri, 09 Mar 2012 21:27:08 -0500
Eli Zaretskii wrote:

> It should use `string-width' instead of `length'.

Like so?

*** lisp/calendar/calendar.el	2012-03-06 02:18:29 +0000
--- lisp/calendar/calendar.el	2012-03-10 02:16:16 +0000
***************
*** 1756,1762 ****
                            (if (< (length strings) 2)
                                (append (list "") strings (list ""))
                              strings)))
!          (n (- length (length (apply 'concat strings))))
           (m (1- (length strings)))
           (s (car strings))
           (strings (cdr strings))
--- 1756,1762 ----
                            (if (< (length strings) 2)
                                (append (list "") strings (list ""))
                              strings)))
!          (n (- length (string-width (apply 'concat strings))))
           (m (1- (length strings)))
           (s (car strings))
           (strings (cdr strings))
***************
*** 1766,1772 ****
                        (make-string (max 0 (/ (+ n i) m)) char)
                        string)
              i (1+ i)))
!     (substring s 0 length)))
  
  (defun calendar-update-mode-line ()
    "Update the calendar mode line with the current date and date style."
--- 1766,1772 ----
                        (make-string (max 0 (/ (+ n i) m)) char)
                        string)
              i (1+ i)))
!     (truncate-string-to-width s length)))
  
  (defun calendar-update-mode-line ()
    "Update the calendar mode line with the current date and date style."





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Sat, 10 Mar 2012 03:03:02 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 10978 <at> debbugs.gnu.org,
	Štěpán Němec <stepnem <at> gmail.com>
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Fri, 09 Mar 2012 21:32:32 -0500
PS it goes quite wrong for CHAR != single-width, but that case has no
relevance for the calendar, which only uses CHAR = ?\s or ?-.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Sat, 10 Mar 2012 08:03:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 10978 <at> debbugs.gnu.org, stepnem <at> gmail.com
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Sat, 10 Mar 2012 09:32:15 +0200
> From: Glenn Morris <rgm <at> gnu.org>
> Cc: Štěpán Němec <stepnem <at> gmail.com>,
>   10978 <at> debbugs.gnu.org
> Date: Fri, 09 Mar 2012 21:27:08 -0500
> 
> Eli Zaretskii wrote:
> 
> > It should use `string-width' instead of `length'.
> 
> Like so?

Yes, I think this is right.

But it looks like calendar-insert-at-column and calendar-string-spread
also need similar changes.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Sat, 10 Mar 2012 10:28:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 10978 <at> debbugs.gnu.org, stepnem <at> gmail.com
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Sat, 10 Mar 2012 11:57:37 +0200
> From: "Drew Adams" <drew.adams <at> oracle.com>
> Cc: <10978 <at> debbugs.gnu.org>
> Date: Fri, 9 Mar 2012 06:05:24 -0800
> 
> > It should use `string-width' instead of `length'.
> 
> The Elisp manual has a section on `Strings and Characters', which is one of the
> sections about Lisp data types. It has details about lots of string- and
> character-related functions.
> 
> Perhaps some node in that section (maybe `Text Comparison'?) should at least
> mention function `string-width' and cross-reference the node `Width' in the
> `Display' part of the manual.

I added such cross-references to "String Basics" and also to "Sequence
Functions".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Sat, 10 Mar 2012 10:33:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 10978 <at> debbugs.gnu.org, stepnem <at> gmail.com
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Sat, 10 Mar 2012 12:02:28 +0200
> From: Glenn Morris <rgm <at> gnu.org>
> Cc: 10978 <at> debbugs.gnu.org,  Štěpán Němec
>  <stepnem <at> gmail.com>
> Date: Fri, 09 Mar 2012 21:32:32 -0500
> 
> 
> PS it goes quite wrong for CHAR != single-width, but that case has no
> relevance for the calendar, which only uses CHAR = ?\s or ?-.

Sorry, I don't follow.  Could you elaborate on what you had in mind?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10978; Package emacs. (Mon, 12 Mar 2012 20:57:02 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 10978 <at> debbugs.gnu.org, stepnem <at> gmail.com
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Mon, 12 Mar 2012 16:26:26 -0400
Eli Zaretskii wrote:

> But it looks like calendar-insert-at-column and calendar-string-spread
> also need similar changes.

ACK on calendar-insert-at-column, but calendar-string-spread is the
function already being discussed - was there a third?

> Sorry, I don't follow.  Could you elaborate on what you had in mind?

I meant, don't do this:

(calendar-string-spread '("a" "b" "c") ?矢 10)

 ie, a restriction similar to that of truncate-string-to-width:

   The optional 4th arg PADDING, if non-nil, specifies a padding
   character (which should have a display width of 1)

But, it can be handled a bit better with:

*** lisp/calendar/calendar.el	2012-03-06 02:18:29 +0000
--- lisp/calendar/calendar.el	2012-03-12 20:23:23 +0000
***************
*** 1756,1763 ****
                            (if (< (length strings) 2)
                                (append (list "") strings (list ""))
                              strings)))
!          (n (- length (length (apply 'concat strings))))
!          (m (1- (length strings)))
           (s (car strings))
           (strings (cdr strings))
           (i 0))
--- 1756,1763 ----
                            (if (< (length strings) 2)
                                (append (list "") strings (list ""))
                              strings)))
!          (n (- length (string-width (apply 'concat strings))))
!          (m (* (1- (length strings)) (char-width char)))
           (s (car strings))
           (strings (cdr strings))
           (i 0))
***************
*** 1766,1772 ****
                        (make-string (max 0 (/ (+ n i) m)) char)
                        string)
              i (1+ i)))
!     (substring s 0 length)))
  
  (defun calendar-update-mode-line ()
    "Update the calendar mode line with the current date and date style."
--- 1766,1772 ----
                        (make-string (max 0 (/ (+ n i) m)) char)
                        string)
              i (1+ i)))
!     (truncate-string-to-width s length)))
  
  (defun calendar-update-mode-line ()
    "Update the calendar mode line with the current date and date style."





Reply sent to Glenn Morris <rgm <at> gnu.org>:
You have taken responsibility. (Fri, 16 Mar 2012 01:43:02 GMT) Full text and rfc822 format available.

Notification sent to Štěpán Němec <stepnem <at> gmail.com>:
bug acknowledged by developer. (Fri, 16 Mar 2012 01:43:03 GMT) Full text and rfc822 format available.

Message #34 received at 10978-done <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 10978-done <at> debbugs.gnu.org
Subject: Re: bug#10978: `calendar-string-spread' loses with double-width
	characters
Date: Thu, 15 Mar 2012 21:12:06 -0400
Version: 24.0.95

> Eli Zaretskii wrote:
>
>> But it looks like calendar-insert-at-column and calendar-string-spread
>> also need similar changes.

Both hopefully fixed.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 13 Apr 2012 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 39 days ago.

Previous Next


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