Browse files

* helm.el (helm-add-action-to-source): Allow adding an action at INDEX.

  • Loading branch information...
1 parent 5123c94 commit 757bb86c96e9a48446c49ed5f6d949057742cc52 @thierryvolpiatto thierryvolpiatto committed Jun 20, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 helm.el
13 helm.el
@@ -576,18 +576,25 @@ If SRC is omitted, use current source."
(setcdr src (cons (cons attribute-name value) (cdr src))))
-(defun helm-add-action-to-source (name fn source)
+(defun helm-add-action-to-source (name fn source &optional index)
"Add new action NAME linked to function FN to SOURCE.
Function FN should be a valid function that take one arg i.e candidate,
-argument NAME is a string tha will appear in action menu
+argument NAME is a string that will appear in action menu
and SOURCE should be an existing helm source already loaded.
+If INDEX is specified, action is added in action list at INDEX,
+otherwise it is added at end.
This allow user to add a specific action to an existing source
without modifying source code."
(let ((actions (helm-attr 'action source))
(new-action (list (cons name fn))))
(when (symbolp actions)
(setq actions (list (cons "Default action" actions))))
- (helm-attrset 'action (append actions new-action) source)))
+ (helm-attrset 'action
+ (if index
+ (append (butlast actions (- (length actions) index))
+ (append new-action (nthcdr index actions)))
+ (append actions new-action))
+ source)))
(defun helm-set-source-filter (sources)
"Set the value of `helm-source-filter' to SOURCES and update.

0 comments on commit 757bb86

Please sign in to comment.