branch: master
commit dbeb5b1c7f883ce75da39b56d0fdb18074a6dbbc
Author: Wilfred Hughes <[email protected]>
Commit: Oleh Krehel <[email protected]>

    Ensure counsel-M-x preserves last-command
    
    Fixes #891.
    Fixes #893.
---
 counsel.el | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/counsel.el b/counsel.el
index adc46d8..d7bc5bc 100644
--- a/counsel.el
+++ b/counsel.el
@@ -699,6 +699,12 @@ Optional INITIAL-INPUT is the initial input in the 
minibuffer."
       (setq cands smex-ido-cache)
       (setq pred nil)
       (setq sort nil))
+    ;; When `counsel-M-x' returns, `last-command' would be set to
+    ;; `counsel-M-x' because :action hasn't been invoked yet.
+    ;; Instead, preserve the old value of `this-command'.
+    (setq this-command last-command)
+    (setq real-this-command real-last-command)
+
     (ivy-read (counsel--M-x-prompt) cands
               :predicate pred
               :require-match t

Reply via email to