From 93e1d35983796e44a68af67a62b7ee3aefec11b4 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 23 Aug 2011 02:35:21 -0300 Subject: [PATCH 1/2] Update smex after functions that are likely to define new commands --- smex.el | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/smex.el b/smex.el index 6d4a72b..40d848c 100644 --- a/smex.el +++ b/smex.el @@ -90,9 +90,7 @@ Set this to nil to disable fuzzy matching." (smex-initialize)) (if (smex-already-running) (smex-update-and-rerun) - (and smex-auto-update - (smex-detect-new-commands) - (smex-update)) + (and smex-auto-update (smex-update-if-needed)) (smex-read-and-run smex-ido-cache))) (defun smex-already-running () @@ -223,11 +221,13 @@ Set this to nil to disable fuzzy matching." (unless (= i smex-command-count) (setq smex-command-count i)))) +(defun smex-update-if-needed () + (if (smex-detect-new-commands) (smex-update))) + (defun smex-auto-update (&optional idle-time) "Update Smex when Emacs has been idle for IDLE-TIME." (unless idle-time (setq idle-time 60)) - (run-with-idle-timer idle-time t - '(lambda () (if (smex-detect-new-commands) (smex-update))))) + (run-with-idle-timer idle-time t 'smex-update-if-needed)) ;;;###autoload (defun smex-initialize () @@ -463,6 +463,25 @@ sorted by frequency of use." (set-buffer-modified-p nil) (goto-char (point-min)))) +(defmacro smex-auto-update-after (&rest functions) + "Advise each of FUNCTIONS to execute smex-update upon completion." + (cons + 'progn + (mapcar (lambda (fun) + `(defadvice ,fun (after smex-update activate) + "Run smex-update upon completion" + (ignore-errors + (when (bound-and-true-p smex-auto-update) + (smex-update-if-needed))))) + ;; Defining advice on `eval' causes infinite recursion, so + ;; don't allow that. + (delete-if (apply-partially 'equal 'eval) + functions)))) + +;; If you call `smex-update' after every invocation of just these few +;; functions, you almost never need any other updates. +(smex-auto-update-after load eval-last-sexp eval-buffer eval-region eval-expression) + ;; A copy of `ido-pp' that's compatible with lexical bindings (defun smex-pp* (list list-name) (let ((print-level nil) (eval-expression-print-level nil) From a7cf7ae7c6ce91164a84fda9f2244ba03887b8af Mon Sep 17 00:00:00 2001 From: "Ryan C. Thompson" Date: Sat, 11 Mar 2017 23:55:20 -0800 Subject: [PATCH 2/2] Only smart-update after smex is initialized --- smex.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smex.el b/smex.el index 40d848c..750fee0 100644 --- a/smex.el +++ b/smex.el @@ -471,7 +471,7 @@ sorted by frequency of use." `(defadvice ,fun (after smex-update activate) "Run smex-update upon completion" (ignore-errors - (when (bound-and-true-p smex-auto-update) + (when (and smex-initialized-p smex-auto-update) (smex-update-if-needed))))) ;; Defining advice on `eval' causes infinite recursion, so ;; don't allow that.