Skip to content

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

Closed
DarwinAwardWinner wants to merge 5 commits intononsequitur:masterfrom
DarwinAwardWinner:patch-1
Closed

Update smex after function calls that are likely to define new commands.#4
DarwinAwardWinner wants to merge 5 commits intononsequitur:masterfrom
DarwinAwardWinner:patch-1

Conversation

@DarwinAwardWinner
Copy link
Contributor

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.

@DarwinAwardWinner
Copy link
Contributor Author

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

@DarwinAwardWinner
Copy link
Contributor Author

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.

@DarwinAwardWinner
Copy link
Contributor Author

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.

@DarwinAwardWinner
Copy link
Contributor Author

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

@nonsequitur
Copy link
Owner

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.

@DarwinAwardWinner
Copy link
Contributor Author

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.

* Add new function `smex-update-if-needed` and use it where
  appropriate

* 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.
Since this advice is attached to important emacs functions, it should
prefer to just do nothing rather than throw an error.
This is normally bound to "M-S-:".
@DarwinAwardWinner DarwinAwardWinner mentioned this pull request Mar 12, 2017
@DarwinAwardWinner
Copy link
Contributor Author

Closing in favor of #67.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants