0

In some cases, I often run the same command, say my-common-fun, which I call subsequently with M-x M-p RET, and occasionally run another command, such as my-occasional-fun. I want to call the latter interactively without adding it to the command-history, so that M-x M-p RET runs my-common-fun.

I tried this:

(defun my-occasional-fun ()
  (interactive)
  (insert "one occasional shortcut")
  (pop command-history))

This fails, probably because the function is added to the command history after it runs.

I tried with an advice:

(defadvice my-occasional-fun (after my-occasional-fun-after activate) (pop command-history))

and it also fails: I see the command my-occasional-fun in the history.

Can I call a function interactively without adding it to the command history?

1 Answer 1

1

Pop it from extended-command-history alongside command-history

(defun my-occasional-fun ()
  (interactive)
  (insert "one occasional shortcut")
  (pop extended-command-history)
  (pop command-history))
6
  • Indeed, for me too, (car command-history) shows epa-file-enable, but M-x M-p shows my-occasional-fun.
    – emonigma
    Commented Dec 8, 2023 at 12:25
  • 1
    Hmm.. looks like M-x M-p uses the minibuffer history, that's why it is not affected by command-history
    – Levinas
    Commented Dec 8, 2023 at 12:46
  • 1
    Why not try to adjust minibuffer-history instead of command-history?
    – Levinas
    Commented Dec 8, 2023 at 12:49
  • 2
    M-x uses extended-command-history.
    – Drew
    Commented Dec 8, 2023 at 15:49
  • 1
    @Drew Yes, that works, thanks!
    – emonigma
    Commented Dec 9, 2023 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.