Commits

Aidan Kehoe committed 8593e61

Avoid signalling args-out-of-range errors, #'truncate-string-to-width

lisp/ChangeLog addition:

Avoid args-out-of-range errors, this function is regularly called
from menu code and with debug-on-signal non-nil, this can be very
irritating.
Don't bind ellipsis-len, we don't use it.

  • Participants
  • Parent commits 00fd55d

Comments (0)

Files changed (2)

File lisp/ChangeLog

 	* subr.el:
 	* subr.el (truncate-string-to-width):
 	Sync with GNU's version, use its test suite in mule-tests.el.
+	Avoid args-out-of-range errors, this function is regularly called
+	from menu code and with debug-on-signal non-nil, this can be very
+	irritating.
+	Don't bind ellipsis-len, we don't use it.
 
 2012-05-12  Aidan Kehoe  <kehoea@parhasard.net>
 

File lisp/subr.el

     (setq ellipsis "..."))
   (let ((str-len (length str))
 	(str-width (string-width str))
-	(ellipsis-len (if ellipsis (length ellipsis) 0))
 	(ellipsis-width (if ellipsis (string-width ellipsis) 0))
 	(idx 0)
 	(column 0)
 	(head-padding "") (tail-padding "")
 	ch last-column last-idx from-idx)
-    (condition-case nil
-	(while (< column start-column)
-	  (setq ch (aref str idx)
-		column (+ column (char-width ch))
-		idx (1+ idx)))
-      (args-out-of-range (setq idx str-len)))
+    (while (and (< column start-column) (< idx str-len))
+      (setq ch (aref str idx)
+            column (+ column (char-width ch))
+            idx (1+ idx)))
     (if (< column start-column)
 	(if padding (make-string end-column padding) "")
       (when (and padding (> column start-column))
 		 (> str-width ellipsis-width))
 	    (setq end-column (- end-column ellipsis-width))
 	  (setq ellipsis ""))
-	(condition-case nil
-	    (while (< column end-column)
-	      (setq last-column column
-		    last-idx idx
-		    ch (aref str idx)
-		    column (+ column (char-width ch))
-		    idx (1+ idx)))
-	  (args-out-of-range (setq idx str-len)))
+        (while (and (< column end-column) (< idx str-len))
+          (setq last-column column
+                last-idx idx
+                ch (aref str idx)
+                column (+ column (char-width ch))
+                idx (1+ idx)))
 	(when (> column end-column)
 	  (setq column last-column
 		idx last-idx))