Skip to content

Commit d83b218

Browse files
Advice command-excute after helm session
otherwise command-execute is used inside helm session for e.g. next-line etc.. Don't reset helm-M-x-prefix-argument too early with FLAGS. Use directly helm-current-prefix-arg in advice instead of setting current-prefix arg after helm session. Set prefix-arg unconditionally in advice to either helm-M-x-prefix-argument or helm-current-prefix-arg.
1 parent 51798e5 commit d83b218

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

helm-mode.el

+15-6
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,6 @@ that use `helm-comp-read'. See `helm-M-x' for example."
10471047
(category . symbol-help)))
10481048
(command-help . (metadata
10491049
(prefix-arg . t)
1050-
(flags . (helm-M-x-prefix-argument))
10511050
(affixation-function . helm-symbol-completion-table-affixation)
10521051
(category . symbol-help)))
10531052
(eww-help . (metadata ;; Emacs-30 only
@@ -1550,10 +1549,13 @@ dynamically otherwise use `helm-completing-read-default-2'."
15501549
helm--mode-line-display-prefarg pref-arg)
15511550
(when pref-arg
15521551
(setq helm-M-x--timer (run-at-time 1 0.1 #'helm-M-x--notify-prefix-arg))
1552+
(add-hook 'helm-move-selection-after-hook
1553+
#'helm-M-x--move-selection-after-hook)
1554+
(add-hook 'helm-before-action-hook
1555+
#'helm-M-x--before-action-hook)
15531556
;; Notify C-u entered before Hitting M-[xX].
15541557
(setq helm-M-x-prefix-argument current-prefix-arg)
15551558
(setq current-prefix-arg nil)
1556-
(advice-add 'command-execute :around #'helm--advice-command-execute)
15571559
;; Remove command-execute advice when execute-extended-command exit.
15581560
(advice-add 'execute-extended-command :around #'helm--advice-execute-extended-command))
15591561
(unwind-protect
@@ -1602,13 +1604,20 @@ dynamically otherwise use `helm-completing-read-default-2'."
16021604
;; when init is added to history, it will be unquoted by
16031605
;; helm-comp-read.
16041606
:initial-input initial-input)
1605-
(when pref-arg (setq current-prefix-arg helm-current-prefix-arg)))
1606-
(when (timerp helm-M-x--timer)
1607-
(cancel-timer helm-M-x--timer) (setq helm-M-x--timer nil))
1607+
(when pref-arg
1608+
(advice-add 'command-execute :around #'helm--advice-command-execute)))
1609+
(helm-M-x--unwind-forms)
16081610
(dolist (f flags) (set f nil)))))
16091611

16101612
(defun helm--advice-command-execute (old--fn &rest args)
1611-
(unless prefix-arg (setq prefix-arg current-prefix-arg))
1613+
(helm-M-x--unwind-forms 'done)
1614+
;; `command-execute' is wrapped in a let with `prefix-arg' bound to the argument
1615+
;; PREFIXARG of `execute-extended-command' so set this let-bounded `prefix-arg'
1616+
;; to the value defined during helm completion. We use
1617+
;; helm-M-x-prefix-argument instead of initial PREFIXARG to allow changing the
1618+
;; initial prefix arg during helm completion e.g. C-u M-X foo C-u 2 foo, in
1619+
;; this case the initial C-u is replaced by C-u 2.
1620+
(setq prefix-arg (or helm-current-prefix-arg helm-M-x-prefix-argument))
16121621
(apply old--fn args))
16131622

16141623
(defun helm--advice-execute-extended-command (old--fn &rest args)

0 commit comments

Comments
 (0)