Skip to content

Commit

Permalink
Correct and more efficient calculation of column width.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmalsburg committed Dec 26, 2014
1 parent 6fc8c62 commit 0606621
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions helm-dictionary.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,26 @@ browser in `helm-browse-url-default-browser-alist'"
(easy-menu-add-item nil '("Tools" "Helm" "Tools") ["Dictionary" helm-dictionary t])


;; The function `window-width' does not necessarily report the correct
;; number of characters that fit on a line. This is a
;; work-around. See also this bug report:
;; http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19395
(defun helm-dictionary-window-width ()
(if (and (not (featurep 'xemacs))
(display-graphic-p)
overflow-newline-into-fringe
(/= (frame-parameter nil 'left-fringe) 0)
(/= (frame-parameter nil 'right-fringe) 0))
(window-body-width)
(1- (window-body-width))))

(defun helm-dictionary-transformer (candidates)
"Formats entries retrieved from the data base."
(cl-loop for i in candidates
with entry and l1terms and l2terms
and width = (with-helm-window (window-width))
and width = (with-helm-window (helm-dictionary-window-width))
with left-col-width = (1- (/ width 2))
with right-col-width = (- width (/ width 2))
unless (or (string-match "\\`#" i)
(not (string-match " :: ?" i)))
do (progn (setq entry (split-string i " :: ?"))
Expand All @@ -204,9 +219,9 @@ browser in `helm-browse-url-default-browser-alist'"
collect
(cons
(concat
(truncate-string-to-width l1term (- (/ width 2) 1) 0 ?\s)
(truncate-string-to-width l1term left-col-width 0 ?\s)
" "
(truncate-string-to-width l2term (- (/ width 2) 1) 0 ?\s))
(truncate-string-to-width l2term right-col-width 0 ?\s))
(cons l1term l2term)))))


Expand Down

0 comments on commit 0606621

Please sign in to comment.