[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pulsar 1535551ac0 27/28: Use post-command-hook instead
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pulsar 1535551ac0 27/28: Use post-command-hook instead of an advice |
Date: |
Tue, 22 Mar 2022 06:58:06 -0400 (EDT) |
branch: externals/pulsar
commit 1535551ac03212cd3437acae591fc1b0475d1898
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@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
- [elpa] externals/pulsar 98d970dcdf 09/28: Add minor rewording, (continued)
- [elpa] externals/pulsar 98d970dcdf 09/28: Add minor rewording, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar fca0e53815 15/28: Exert control over the pulse effect, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 486645f81b 16/28: Always ':extend t' the generic pulse face, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar dcc94662a9 07/28: Stop pulsing during pulsar-reveal-entry, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 82946880b5 14/28: Add missing function to sample package setup, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 42f8a03b8a 18/28: Fix typo, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar d654e552f0 19/28: Clarify doc strings of user options, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 4cfc18a009 22/28: Update to version 0.2.0, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar d2174307b0 23/28: Simple fix for highlight behavior on last line, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 2d666c7061 25/28: Update "Acknowledgements" in the manual, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 1535551ac0 27/28: Use post-command-hook instead of an advice,
ELPA Syncer <=
- [elpa] externals/pulsar 1b73a123f1 21/28: Reword Commentary and package description, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar b469abdd94 17/28: Abstract pulse effect; add pulsar-highlight-line, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 890d73e481 24/28: Merge branch 'fix-last-line' into 'main', ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 0891269ff8 26/28: Add pulsar-highlight-face user option, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar ebbe9486d1 20/28: Reword manual's description, ELPA Syncer, 2022/03/22
- [elpa] externals/pulsar 40b1aa8c48 28/28: Document pulsar package installation, ELPA Syncer, 2022/03/22