Skip to content

Commit

Permalink
ivy.el (ivy-make-magic-action): Add docstring to the generated lambda
Browse files Browse the repository at this point in the history
Fixes #1956
  • Loading branch information
abo-abo committed Mar 8, 2019
1 parent 0a4ad42 commit 4e07e6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion counsel.el
Expand Up @@ -1757,7 +1757,7 @@ currently checked out."
(define-key map (kbd "C-DEL") 'counsel-up-directory)
(define-key map (kbd "C-<backspace>") 'counsel-up-directory)
(define-key map (kbd "C-M-y") 'counsel-yank-directory)
(define-key map (kbd "`") (ivy-make-magic-action "b"))
(define-key map (kbd "`") (ivy-make-magic-action 'counsel-find-file "b"))
map))

(defun counsel-yank-directory ()
Expand Down
23 changes: 16 additions & 7 deletions ivy.el
Expand Up @@ -2855,17 +2855,26 @@ Possible choices are 'ivy-magic-slash-non-match-cd-selected,
(ivy--cd-maybe))
(insert last-input-event)))

(defun ivy-make-magic-action (key)
(defun ivy-make-magic-action (caller key)
"Return a command that does the equivalent of `ivy-read-action' and KEY.
This happens only when the input is empty.
The intention is to bind the result to keys that are typically
bound to `self-insert-command'."
(lambda (&optional arg)
(interactive "p")
(if (string= "" ivy-text)
(execute-kbd-macro
(kbd (concat "M-o " key)))
(self-insert-command arg))))
(let ((alist (assoc key
(plist-get
ivy--actions-list
caller)))
(action (nth 1 alist))
(doc (concat (nth 2 alist)
"\n\n"
(documentation action))))
`(lambda (&optional arg)
,doc
(interactive "p")
(if (string= "" ivy-text)
(execute-kbd-macro
(kbd (concat "M-o " key)))
(self-insert-command arg)))))

(defcustom ivy-magic-tilde t
"When non-nil, ~ will move home when selecting files.
Expand Down

0 comments on commit 4e07e6f

Please sign in to comment.