summaryrefslogtreecommitdiff
path: root/helm-command.el
diff options
context:
space:
mode:
authorChunyang Xu <xuchunyang.me@gmail.com>2016-06-21 15:05:36 +0800
committerChunyang Xu <xuchunyang.me@gmail.com>2016-06-21 15:15:27 +0800
commita80ee6d6b36dde1f0005f62aab0c7f3ccad7ffdc (patch)
treec7977dd5da95b5a9a803981496429118e1c50e1a /helm-command.el
parentd53880f23efb5fd822de1c557bca43c87b676f18 (diff)
Add helm-M-x-allow-prefix-argument option
When the option is non-nil (defaults to nil), prefix argument is allowed before calling helm-M-x, but it will not be used if you specify prefix argument right before executing command, for example, M-3 helm-M-x foo RET => (foo 3) M-3 helm-M-x foo M-4 RET => (foo 4)
Diffstat (limited to 'helm-command.el')
-rw-r--r--helm-command.el27
1 files changed, 20 insertions, 7 deletions
diff --git a/helm-command.el b/helm-command.el
index 69beab24..fecbf11b 100644
--- a/helm-command.el
+++ b/helm-command.el
@@ -49,6 +49,11 @@ Show all candidates on startup when 0 (default)."
:group 'helm-command
:type 'boolean)
+(defcustom helm-M-x-allow-prefix-argument nil
+ "Allow specifying prefix argument before `helm-M-x' when non--nil."
+ :group 'helm-command
+ :type 'boolean)
+
;;; Faces
;;
@@ -65,6 +70,7 @@ Show all candidates on startup when 0 (default)."
(defvar helm-M-x-input-history nil)
+(defvar helm-M-x-prefix-argument nil "Prefix argument before calling `helm-M-x'.")
(cl-defun helm-M-x-get-major-mode-command-alist (mode-map)
@@ -188,12 +194,14 @@ than the default which is OBARRAY."
and collect c))
(unwind-protect
(let ((msg "Error: Specifying a prefix arg before calling `helm-M-x'"))
- (when current-prefix-arg
- (ding)
- (message "%s" msg)
- (while (not (sit-for 1))
- (discard-input))
- (user-error msg))
+ (if helm-M-x-allow-prefix-argument
+ (setq helm-M-x-prefix-argument current-prefix-arg)
+ (when current-prefix-arg
+ (ding)
+ (message "%s" msg)
+ (while (not (sit-for 1))
+ (discard-input))
+ (user-error msg)))
(setq current-prefix-arg nil)
(helm-comp-read
"M-x " (or collection obarray)
@@ -237,7 +245,12 @@ You can get help on each command by persistent action."
real-this-command sym-com)
;; If helm-M-x is called with regular emacs completion (kmacro)
;; use the value of arg otherwise use helm-current-prefix-arg.
- (let ((prefix-arg (or helm-current-prefix-arg arg)))
+ (let ((prefix-arg
+ (or helm-current-prefix-arg
+ (when helm-M-x-allow-prefix-argument
+ (prog1 helm-M-x-prefix-argument
+ (setq helm-M-x-prefix-argument nil)))
+ arg)))
;; This ugly construct is to save history even on error.
(unless helm-M-x-always-save-history
(command-execute sym-com 'record))