[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm 0f0bbf7550 2/3: Allow affixation functions to return
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm 0f0bbf7550 2/3: Allow affixation functions to return a function instead of a list |
Date: |
Fri, 4 Aug 2023 04:00:16 -0400 (EDT) |
branch: elpa/helm
commit 0f0bbf755098b49fdb7ccbfd349ce4a8c9d073f1
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Allow affixation functions to return a function instead of a list
Normally affixation functions use COMPLETIONS as arg, and return a list of
modified COMPLETIONS. Now we allow in Helm affixations functions to return a
function instead, just like annotation functions. The function should
return a
list of three elements like (comp prefix suffix). This increase
significantly
the speed avoiding one useless loop on complete list of candidates.
Speed is visible specially when using emacs as emacs style, with helm
styles it is already very fast so the difference is not really visible.
---
helm-mode.el | 81 ++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 49 insertions(+), 32 deletions(-)
diff --git a/helm-mode.el b/helm-mode.el
index cf8976dc57..b8e374ec5f 100644
--- a/helm-mode.el
+++ b/helm-mode.el
@@ -1830,40 +1830,49 @@ The `helm-find-files' history `helm-ff-history' is used
here."
(propertize str 'read-only t 'face 'helm-mode-prefix 'rear-nonsticky t)
str))
-(defun helm--advice-help--symbol-completion-table-affixation (completions)
+(defun helm--advice-help--symbol-completion-table-affixation (_completions)
"Override advice for `help--symbol-completion-table-affixation'.
+Normally affixation functions use COMPLETIONS as arg, and return a list of
+modified COMPLETIONS. Now we allow affixations functions to return a
+function instead, just like annotation functions. The function should return a
+list of three elements like (comp prefix suffix). This increase significantly
+the speed avoiding one useless loop on complete list of candidates.
+
This advice is used in helm completion by `helm-mode'.
+It returns a function and not a list of completions.
+It affects all describe-* functions.
It uses `helm-get-first-line-documentation' which allow providing documentation
-for `describe-variable' symbols."
- (require 'help-fns)
- (mapcar (lambda (c)
- (let* ((s (intern c))
- ;; When using in-buffer implementation we should have the
- ;; longest len to align documentation for free.
- ;; Check for style as well in case user switches to emacs
- ;; style and a candidate buffer remains (with its local vars
- ;; still available).
- (max-len (and (memq helm-completion-style '(helm
helm-fuzzy))
- (buffer-local-value
- 'helm-candidate-buffer-longest-len
- (get-buffer (or (helm-candidate-buffer)
- ;; Return 0 in this case and
don't
- ;; fail with a nil arg with
- ;; get-buffer.
- helm-buffer)))))
- (sep (if (or (null max-len) (zerop max-len))
- " --" ; Default separator.
- (make-string (- max-len (length c)) ? )))
- (doc (ignore-errors
- (helm-get-first-line-documentation s))))
- (list c (propertize
- (format "%-4s" (help--symbol-class s))
- 'face 'completions-annotations)
- (if doc (propertize (format "%s%s" sep doc)
- 'face 'completions-annotations)
- ""))))
- completions))
+for `describe-variable' symbols and align properly documentation when helm
style
+is used."
+ (lambda (c)
+ (require 'help-fns)
+ (let* ((s (intern c))
+ ;; When using in-buffer implementation we should have the
+ ;; longest len to align documentation for free.
+ ;; Check for style as well in case user switches to emacs
+ ;; style and a candidate buffer remains (with its local vars
+ ;; still available).
+ (max-len (and (memq helm-completion-style '(helm helm-fuzzy))
+ (buffer-local-value
+ 'helm-candidate-buffer-longest-len
+ (get-buffer (or (helm-candidate-buffer)
+ ;; Return 0 in this case and don't
+ ;; fail with a nil arg with
+ ;; get-buffer.
+ helm-buffer)))))
+ (sep (if (or (null max-len) (zerop max-len))
+ " --" ; Default separator.
+ (make-string (- max-len (length c)) ? )))
+ (doc (ignore-errors
+ (helm-get-first-line-documentation s))))
+ (list c
+ (propertize
+ (format "%-4s" (help--symbol-class s))
+ 'face 'completions-annotations)
+ (if doc (propertize (format "%s%s" sep doc)
+ 'face 'completions-annotations)
+ "")))))
(defun helm-completion--initial-filter (comps afun afix file-comp-p)
"Compute COMPS with function AFUN or AFIX unless FILE-COMP-P non nil.
@@ -1884,8 +1893,16 @@ When FILE-COMP-P is provided only filter out dot files."
(cl-loop for f in comps
unless (string-match "\\`\\.\\{1,2\\}/\\'" f)
collect f)
- (cond (afix (cl-loop for (comp prefix suffix) in (funcall afix comps)
- collect (cons (concat prefix comp suffix) comp)))
+ (cond (afix (let ((affixations (funcall afix comps)))
+ (if (functionp affixations)
+ (cl-loop for comp in comps
+ for cand = (funcall affixations comp)
+ collect (cons (concat (nth 1 cand) ;prefix
+ (nth 0 cand) ;comp
+ (nth 2 cand)) ;suffix
+ comp))
+ (cl-loop for (comp prefix suffix) in affixations
+ collect (cons (concat prefix comp suffix)
comp)))))
(afun
;; Add annotation at end of
;; candidate if needed, e.g. foo<f>, this happen when