unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10978: `calendar-string-spread' loses with double-width characters
@ 2012-03-09 11:57 Štěpán Němec
  2012-03-09 12:33 ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Štěpán Němec @ 2012-03-09 11:57 UTC (permalink / raw)
  To: 10978

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





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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-09 11:57 bug#10978: `calendar-string-spread' loses with double-width characters Štěpán Němec
@ 2012-03-09 12:33 ` Eli Zaretskii
  2012-03-09 14:05   ` Drew Adams
  2012-03-10  2:27   ` Glenn Morris
  0 siblings, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2012-03-09 12:33 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: 10978

> From: Štěpán Němec
> 	<stepnem@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'.






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-09 12:33 ` Eli Zaretskii
@ 2012-03-09 14:05   ` Drew Adams
  2012-03-10  9:57     ` Eli Zaretskii
  2012-03-10  2:27   ` Glenn Morris
  1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2012-03-09 14:05 UTC (permalink / raw)
  To: 'Eli Zaretskii', 'Štepán Nemec'; +Cc: 10978

> 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.






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-09 12:33 ` Eli Zaretskii
  2012-03-09 14:05   ` Drew Adams
@ 2012-03-10  2:27   ` Glenn Morris
  2012-03-10  2:32     ` Glenn Morris
  2012-03-10  7:32     ` Eli Zaretskii
  1 sibling, 2 replies; 10+ messages in thread
From: Glenn Morris @ 2012-03-10  2:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 10978, Štěpán Němec

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."






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-10  2:27   ` Glenn Morris
@ 2012-03-10  2:32     ` Glenn Morris
  2012-03-10 10:02       ` Eli Zaretskii
  2012-03-10  7:32     ` Eli Zaretskii
  1 sibling, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-03-10  2:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 10978, Štěpán Němec


PS it goes quite wrong for CHAR != single-width, but that case has no
relevance for the calendar, which only uses CHAR = ?\s or ?-.





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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-10  2:27   ` Glenn Morris
  2012-03-10  2:32     ` Glenn Morris
@ 2012-03-10  7:32     ` Eli Zaretskii
  1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2012-03-10  7:32 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10978, stepnem

> From: Glenn Morris <rgm@gnu.org>
> Cc: Štěpán Němec <stepnem@gmail.com>,
>   10978@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.






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-09 14:05   ` Drew Adams
@ 2012-03-10  9:57     ` Eli Zaretskii
  0 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2012-03-10  9:57 UTC (permalink / raw)
  To: Drew Adams; +Cc: 10978, stepnem

> From: "Drew Adams" <drew.adams@oracle.com>
> Cc: <10978@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".





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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-10  2:32     ` Glenn Morris
@ 2012-03-10 10:02       ` Eli Zaretskii
  2012-03-12 20:26         ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2012-03-10 10:02 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10978, stepnem

> From: Glenn Morris <rgm@gnu.org>
> Cc: 10978@debbugs.gnu.org,  Štěpán Němec
>  <stepnem@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?






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-10 10:02       ` Eli Zaretskii
@ 2012-03-12 20:26         ` Glenn Morris
  2012-03-16  1:12           ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-03-12 20:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 10978, stepnem

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."






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

* bug#10978: `calendar-string-spread' loses with double-width characters
  2012-03-12 20:26         ` Glenn Morris
@ 2012-03-16  1:12           ` Glenn Morris
  0 siblings, 0 replies; 10+ messages in thread
From: Glenn Morris @ 2012-03-16  1:12 UTC (permalink / raw)
  To: 10978-done

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.





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

end of thread, other threads:[~2012-03-16  1:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-09 11:57 bug#10978: `calendar-string-spread' loses with double-width characters Štěpán Němec
2012-03-09 12:33 ` Eli Zaretskii
2012-03-09 14:05   ` Drew Adams
2012-03-10  9:57     ` Eli Zaretskii
2012-03-10  2:27   ` Glenn Morris
2012-03-10  2:32     ` Glenn Morris
2012-03-10 10:02       ` Eli Zaretskii
2012-03-12 20:26         ` Glenn Morris
2012-03-16  1:12           ` Glenn Morris
2012-03-10  7:32     ` Eli Zaretskii

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