Update smex after function calls that are likely to define new commands. #4

wants to merge 5 commits into


None yet

2 participants


I got tired of periodic smex auto updates, especially since every time I loaded a file or defined a new function, I would have to manually update smex anyway, since I immediately wanted access to the new functions that I just loaded. So I figured out which functions are involved in the definitions of vast majority of commands, and I wrapped them in advice that updates smex immediately after them. Now when you load a file or press C-j in scratch, your new stuff is available with no waiting.


For general consumption, it might be best to refactor this into a modifiable custom variable.


Do you have any interest in merging this? I've been using it for a long time (at least a year), and it has completely eliminated the need for periodic auto-updates.


By the way, the two commits in this pull request are completely independent. I probably should have submitted them separately. So feel free to cherry-pick just one or the other.


I just fixed a missing paren on this pull request and rebased on top of your latest master branch.


Thanks! In the early stages, I did some experiments using exact same approach.
It turned out to not work reliably enough for me. For example, commands defined via fset won't get caught; and fset can't be advised.
I'll leave this open - quickly capturing new commands is still an unsolved problem.


With the code in this pull request, I've never run into a case where a new command was defined and smex didn't immediately pick it up. Yes, calls fset (and defun, and defmacro, etc.) will be missed, but that doesn't matter because it's nearly impossible to call any of those without using one of the functions listed in:

(smex-auto-update-after load eval-last-sexp eval-buffer eval-region eval-expression)

(Yes, I just added eval-expression to that list two seconds ago.) So in practice the only time any new functions will be missed is if you were deliberately trying to evade the auto-updating by using some obscure method of evaluating elisp.

Can you provide a method of defining a function that doesn't use one of the five functions listed above? I can't think of any.

@DarwinAwardWinner @DarwinAwardWinner DarwinAwardWinner Update smex after function calls that are likely to define new commands. aa7dd29
@DarwinAwardWinner DarwinAwardWinner Code cleanups
* Add new function `smex-update-if-needed` and use it where

* Rename `update-smex-after` to `smex-auto-update-after`

* Advice defined by `smex-auto-update-after` now only works when
  `smex-auto-update' is set to t.

* Other minor cleanups

These are all in one commit because they all affect overlapping lines,
so separating them out would have been quite difficult.
@DarwinAwardWinner DarwinAwardWinner Update smex after "eval-region" 655bece
@DarwinAwardWinner DarwinAwardWinner Ensure that advice never gives errors
Since this advice is attached to important emacs functions, it should
prefer to just do nothing rather than throw an error.
@DarwinAwardWinner DarwinAwardWinner Update smex after "eval-expression"
This is normally bound to "M-S-:".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment