branch: elpa/helm
commit 829e109d411e1679f9f1bcd1ea4bda64a1adb88c
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Allow key substitution in actions titles
---
helm-core.el | 34 ++++++++++++++++++++++++----------
helm-source.el | 13 ++++++++++++-
2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/helm-core.el b/helm-core.el
index 5d3b65638b..09bf29ab4b 100644
--- a/helm-core.el
+++ b/helm-core.el
@@ -2586,25 +2586,39 @@ when you want the `display-to-real' function(s) to be
applied."
(helm-log "helm-get-selection" "selection = %S" selection)
selection)))))
+(defun helm-format-actions (actions map)
+ "Make key substitution in ACTIONS titles.
+When ACTIONS is a function return it inchanged (sole action)."
+ (if (functionp actions)
+ actions
+ (cl-loop for (str . fn) in actions
+ collect (cons (if (string-match "<%s>" str)
+ (substitute-command-keys (format str map))
+ str)
+ fn))))
+
(defun helm-get-actions-from-current-source (&optional source)
"Return the associated action for the selected candidate.
It is a function symbol (sole action) or list
of (action-display . function)."
(unless (helm-empty-buffer-p (helm-buffer-get))
(let* ((src (or source (helm-get-current-source)))
+ (map (helm-get-attr 'symbol-keymap src))
(marked (helm-marked-candidates))
(action-transformer (helm-get-attr 'action-transformer src))
(actions (helm-get-attr 'action src 'ignorefn)))
- (if action-transformer
- (helm-apply-functions-from-source
- src action-transformer actions
- ;; When there is marked candidates assume the set of
- ;; candidates user selected contains candidates of the same
- ;; type so that the actions added by transformer fit with
- ;; all marked (previously we were looping on each marked
- ;; but it is too costly for the benefit it brings).
- (car marked))
- actions))))
+ (helm-format-actions
+ (if action-transformer
+ (helm-apply-functions-from-source
+ src action-transformer actions
+ ;; When there is marked candidates assume the set of
+ ;; candidates user selected contains candidates of the same
+ ;; type so that the actions added by transformer fit with
+ ;; all marked (previously we were looping on each marked
+ ;; but it is too costly for the benefit it brings).
+ (car marked))
+ actions)
+ map))))
(defun helm-get-current-source ()
"Return the source for the current selection.
diff --git a/helm-source.el b/helm-source.el
index 2df9075d48..b69a98dab3 100644
--- a/helm-source.el
+++ b/helm-source.el
@@ -155,6 +155,15 @@
" Specific keymap for this source.
default value is `helm-map'.")
+ (symbol-keymap
+ :initarg :keymap
+ :initform 'helm-map
+ :type symbol
+ :documentation
+ " The keymap name for this source.
+ Contrarily to `keymap' it is not evaled.
+ default value is `helm-map'.")
+
(action
:initarg :action
:initform 'identity
@@ -1183,7 +1192,9 @@ The header line is based on one of `persistent-action-if',
(make-composed-keymap
must-match-map map)
map)))
- (setf (slot-value source 'keymap) loc-map)))
+ (setf (slot-value source 'keymap) loc-map)
+ (when (symbolp it)
+ (setf (slot-value source 'symbol-keymap) it))))
(helm-aif (slot-value source 'persistent-help)
(setf (slot-value source 'header-line)
(helm-source--persistent-help-string it source))