branch: elpa/helm
commit 7da871b82360a86aa5b70d01cade6fd9a27ae943
Author: Thierry Volpiatto <thie...@posteo.net>
Commit: Thierry Volpiatto <thie...@posteo.net>

    Store max length of candidates in a local var at candidate buffer init
    
    Allow not recomputing max len in transformers.
---
 helm-command.el |  3 ++-
 helm-core.el    | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/helm-command.el b/helm-command.el
index 1859b33c03..a794c4465d 100644
--- a/helm-command.el
+++ b/helm-command.el
@@ -138,7 +138,8 @@ fuzzy matching is running its own sort function with a 
different
 algorithm."
   (with-helm-current-buffer
     (cl-loop with max-len = (when helm-M-x-show-short-doc
-                              (cl-loop for i in candidates maximize (length 
i)))
+                              (buffer-local-value 
'helm-candidate-buffer-longest-len
+                                                  (helm-candidate-buffer)))
              with local-map = (helm-M-x-current-mode-map-alist)
              for cand in candidates
              for local-key  = (car (rassq cand local-map))
diff --git a/helm-core.el b/helm-core.el
index 4402b7a9a6..4f66fe5dac 100644
--- a/helm-core.el
+++ b/helm-core.el
@@ -6641,6 +6641,13 @@ before running again the init function."
                       (buffer-live-p (get-buffer it))
                       it)))))
 
+(defvar helm-candidate-buffer-longest-len 0
+  "May store the longest length of candidates in a in-buffer source.
+It is a local variable set from `helm-init-candidates-in-buffer' in
+`helm-candidate-buffer'.
+Allow getting the longest length of initial candidates in transformers
+without looping again through the whole list.")
+
 (defun helm-init-candidates-in-buffer (buffer-spec data)
   "Register BUFFER-SPEC with DATA for a helm candidates-in-buffer session.
 
@@ -6666,9 +6673,13 @@ when initializing a source with `helm-source-in-buffer' 
class."
         (erase-buffer)
         (cond ((listp data)
                (insert (mapconcat (lambda (i)
-                                    (cond ((symbolp i) (symbol-name i))
-                                          ((numberp i) (number-to-string i))
-                                          (t i)))
+                                    (let ((cand (cond ((symbolp i) 
(symbol-name i))
+                                                      ((numberp i) 
(number-to-string i))
+                                                      (t i))))
+                                      (setq-local 
helm-candidate-buffer-longest-len
+                                                  (max 
helm-candidate-buffer-longest-len
+                                                       (length cand)))
+                                      cand))
                                   data "\n")))
               ((stringp data) (insert data))))
       buf)))

Reply via email to