]> code.delx.au - gnu-emacs/commitdiff
calendar-insert-at-column small fix for bug#10978
authorGlenn Morris <rgm@gnu.org>
Fri, 16 Mar 2012 01:10:46 +0000 (21:10 -0400)
committerGlenn Morris <rgm@gnu.org>
Fri, 16 Mar 2012 01:10:46 +0000 (21:10 -0400)
* lisp/calendar/calendar.el (calendar-insert-at-column):
Handle non-unit-width characters a bit better.

lisp/ChangeLog
lisp/calendar/calendar.el

index 427d7d87979d051d25181a99c0cfc27560f98c8d..1e1f02f2cd79852361500c99bcc46953ed52843e 100644 (file)
@@ -1,3 +1,8 @@
+2012-03-16  Glenn Morris  <rgm@gnu.org>
+
+       * calendar/calendar.el (calendar-insert-at-column):
+       Handle non-unit-width characters a bit better.  (Bug#10978)
+
 2012-03-15  Chong Yidong  <cyd@gnu.org>
 
        * emacs-lisp/ring.el (ring-extend): New function.
index b09167ea49be20f34b33492f0320e66e25190820..d9ec27b4f88f4502024dd46c57e1f98647406805 100644 (file)
@@ -1424,16 +1424,24 @@ Optional integers MON and YR are used instead of today's date."
   "Move to column INDENT, adding spaces as needed.
 Inserts STRING so that it ends at INDENT.  STRING is either a
 literal string, or a sexp to evaluate to return such.  Truncates
-STRING to length TRUNCATE, ensure a trailing space."
+STRING to length TRUNCATE, and ensures a trailing space."
   (if (not (ignore-errors (stringp (setq string (eval string)))))
       (calendar-move-to-column indent)
-    (if (> (length string) truncate)
-        (setq string (substring string 0 truncate)))
+    (if (> (string-width string) truncate)
+        (setq string (truncate-string-to-width string truncate)))
     (or (string-match " $" string)
-        (if (= (length string) truncate)
-            (aset string (1- truncate) ?\s)
-          (setq string (concat string " "))))
-    (calendar-move-to-column (- indent (length string)))
+        (setq string (concat (if (= (string-width string) truncate)
+                                 (substring string 0 -1)
+                               string)
+                             ;; Avoid inserting text properties unless
+                             ;; we have to (ie, non-unit-width chars).
+                             ;; This is by no means essential.
+                             (if (= (string-width string) (length string))
+                                 " "
+                               ;; Cribbed from buff-menu.el.
+                               (propertize
+                                " " 'display `(space :align-to ,indent))))))
+    (calendar-move-to-column (- indent (string-width string)))
     (insert string)))
 
 (defun calendar-generate-month (month year indent)