branch: externals/pulsar commit 1535551ac03212cd3437acae591fc1b0475d1898 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Use post-command-hook instead of an advice Thanks to Daniel Mendler for proposing this approach in issue 6: <https://gitlab.com/protesilaos/pulsar/-/issues/6>. --- README.org | 12 +++++++----- pulsar.el | 34 +++++++++------------------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/README.org b/README.org index c42a16b309..b6d1c7a73e 100644 --- a/README.org +++ b/README.org @@ -64,12 +64,14 @@ modify this GNU manual.” :END: #+vindex: pulse-pulse-functions -#+vindex: pulse-after-function-hook This is a small package that temporarily highlights the current line after a given function is invoked. The affected functions are defined -in the user option ~pulsar-pulse-functions~. What Pulsar does is set up -an advice so that those functions run a hook after they are called. The -pulse effect is added there (~pulsar-after-function-hook~). +in the user option ~pulsar-pulse-functions~. + +[ NOTE 2022-03-20 07:26 +0200: The ~pulse-after-function-hook~ has been + removed as part of {{{development-version}}}. Pulsar no longer uses + the advice mechanism. Instead, it does its work by leveraging the + ~post-command-hook~. ] #+findex: pulsar-setup To remove the advice and disable Pulsar altogether, evaluate this form: @@ -254,7 +256,7 @@ Pulsar is meant to be a collective effort. Every bit of help matters. + Author/maintainer :: Protesilaos Stavrou. -+ Contributions to the code or manual :: JD Smith. ++ Contributions to the code or manual :: Daniel Mendler, JD Smith. + Ideas and user feedback :: Mark Barton, Petter Storvik, and user kb. diff --git a/pulsar.el b/pulsar.el index 3c2e0c6137..d369ecf929 100644 --- a/pulsar.el +++ b/pulsar.el @@ -28,9 +28,6 @@ ;; This is a small package that temporarily highlights the current line ;; either on demand or after a given function is invoked. The affected ;; functions are defined in the user option `pulsar-pulse-functions'. -;; What Pulsar does is set up an advice so that those functions run a -;; hook after they are called. The pulse effect is added there -;; (`pulsar-after-function-hook'). ;; ;; The duration of the highlight is determined by `pulsar-delay'. The ;; steps of the pulse effect are controlled by `pulsar-iterations'. @@ -296,31 +293,18 @@ default)." ;;;; Advice setup -(defvar pulsar-after-function-hook nil - "Hook that runs after any function in `pulsar-pulse-functions'.") - -(defun pulsar--add-hook (&rest _) - "Run `pulsar-after-function-hook'." - (run-hooks 'pulsar-after-function-hook)) +(defun pulsar--post-command-pulse () + "Run `pulsar-pulse-line' for `pulsar-pulse-functions'." + (when (memq this-command pulsar-pulse-functions) + (pulsar-pulse-line))) ;;;###autoload (defun pulsar-setup (&optional reverse) - "Set up pulsar for select functions. -This adds the `pulsar-after-function-hook' to every command listed -in the `pulsar-pulse-functions'. If the list is updated, this -command needs to be invoked again. - -With optional non-nil REVERSE argument, remove the advice that -sets up the aforementioned hook." - (cond - (reverse - (dolist (fn pulsar-pulse-functions) - (advice-remove fn #'pulsar--add-hook)) - (remove-hook 'pulsar-after-function-hook #'pulsar-pulse-line)) - (t - (dolist (fn pulsar-pulse-functions) - (advice-add fn :after #'pulsar--add-hook)) - (add-hook 'pulsar-after-function-hook #'pulsar-pulse-line)))) + "Set up pulsar for each function in `pulsar-pulse-functions'. +With optional non-nil REVERSE argument, remove the effect." + (if reverse + (remove-hook 'post-command-hook #'pulsar--post-command-pulse) + (add-hook 'post-command-hook #'pulsar--post-command-pulse))) ;;;; Recentering commands