Permalink
Browse files

* helm-bookmark.el: Fix truncation of multibyte bookmark names.

* helm-utils.el (helm-substring-by-width): New optional arg.
  • Loading branch information...
thierryvolpiatto committed Apr 9, 2013
1 parent c7ba2d1 commit db7dc7c3275f71675d6b6f4d03bedd65f42e973a
Showing with 6 additions and 6 deletions.
  1. +4 −4 helm-bookmark.el
  2. +2 −2 helm-utils.el
View
@@ -94,9 +94,9 @@
(defun helm-bookmark-transformer (candidates source)
(loop for i in candidates
for loc = (bookmark-location i)
- for len = (length i)
+ for len = (string-width i)
for trunc = (if (> len bookmark-bmenu-file-column)
- (substring i 0 bookmark-bmenu-file-column)
+ (helm-substring-by-width i bookmark-bmenu-file-column "")
i)
for sep = (make-string (- (+ bookmark-bmenu-file-column 2)
(length trunc)) ? )
@@ -196,10 +196,10 @@ Work both with standard Emacs bookmarks and bookmark-extensions.el."
for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
for isinfo = (eq handlerp 'Info-bookmark-jump)
for loc = (bookmark-location i)
- for len = (length i)
+ for len = (string-width i)
for trunc = (if (and helm-bookmark-show-location
(> len bookmark-bmenu-file-column))
- (substring i 0 bookmark-bmenu-file-column)
+ (helm-substring-by-width i bookmark-bmenu-file-column "")
i)
;; Add a * if bookmark have annotation
if (and isannotation (not (string-equal isannotation "")))
View
@@ -231,7 +231,7 @@ Handle multibyte characters by moving by columns."
(delete-region (point) (point-max))
(buffer-string)))
-(defun helm-substring-by-width (str width)
+(defun* helm-substring-by-width (str width &optional (endstr "..."))
"Truncate string STR to end at column WIDTH.
Similar to `truncate-string-to-width'.
Add \"...\" at end of truncated STR.
@@ -240,7 +240,7 @@ Add spaces at end if needed to reach WIDTH."
then (substring ini-str 0 (1- (length ini-str)))
for sw = (string-width ini-str)
when (<= sw width) return
- (concat ini-str "..." (make-string (- width sw) ? ))))
+ (concat ini-str endstr (make-string (- width sw) ? ))))
(defun helm-string-multibyte-p (str)
"Check if string STR contains multibyte characters."

0 comments on commit db7dc7c

Please sign in to comment.