branch: externals/pulsar
commit de9d0adf75335133a8ca8481e3c0cbced14df54f
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Make Pulsar also work in frames that normally do not pulse
I am doing this in response to issue 33:
<https://github.com/protesilaos/pulsar/issues/33>.
Thanks to the participation of Sébastien Delafond who provided
feedback about their Emacs environment and helped me test the
snippets I had provided.
---
README.org | 3 ++-
pulsar.el | 50 +++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/README.org b/README.org
index 5617138430..33f92214a0 100644
--- a/README.org
+++ b/README.org
@@ -412,7 +412,8 @@ Pulsar is meant to be a collective effort. Every bit of
help matters.
+ Ideas and user feedback :: Anwesh Gangula, Diego Alvarez, Duy
Nguyen, Koloszár Gergely, Matthias Meulien, Mark Barton, Mehrad
Mahmoudian, Nikolaos Bezirgiannis, Petter Storvik, Ronny Randen,
- Rudolf Adamkovič, Toon Claes, and users djl, hammerandtongs, kb.
+ Rudolf Adamkovič, Sébastien Delafond, Toon Claes, and users djl,
+ hammerandtongs, kb.
* GNU Free Documentation License
:PROPERTIES:
diff --git a/pulsar.el b/pulsar.el
index 822576b19e..33b2748342 100644
--- a/pulsar.el
+++ b/pulsar.el
@@ -39,6 +39,7 @@
;;; Code:
(require 'pulse)
+(eval-when-compile (require 'cl-lib))
(defgroup pulsar ()
"Pulse highlight line on demand or after running select functions.
@@ -385,16 +386,51 @@ extended to the edge of the window."
(pulsar--get-region-boundaries)
(pulsar--get-line-boundaries)))
+(defvar pulsar-tty-color "red"
+ "Named color used in non-graphical frames.")
+
+;; NOTE 2026-02-25: The `cl-letf' in `pulsar--create-pulse' is to make
+;; Pulsar work in frames that normally do not produce a pulse, per
`pulse-available-p'.
+;;
+;; The complete thread is here:
<https://github.com/protesilaos/pulsar/issues/33>.
+;;
+;; Below is what I wrote with regard to the choice of `pulsar-tty-color':
+;;
+;;
+;; For completeness, my rationale with the choice of colour is this:
+;;
+;; - We are in an environment which does not guarantee accurate colour
reproduction.
+;; - It is almost a given that the frame supports at least 8 colours.
+;; - Of those 8 colours we have black, red, green, yellow, blue, magenta,
cyan, white.
+;; - Excluding black and white, the colour that contrasts best against
both black and white is red.
+;; - Picking red means we do not need to know the background-mode of the
frame, which saves us the extra computations.
+;;
+;; The contrast table for the six colours, using Org, where Λ is an alias
for modus-themes-contrast:
+;;
+;; | | #000000 | #ffffff |
+;; |---------+---------+---------|
+;; | #ff0000 | 5.25 | 4.00 |
+;; | #00ff00 | 15.30 | 1.37 |
+;; | #0000ff | 2.44 | 8.59 |
+;; | #ffff00 | 19.56 | 1.07 |
+;; | #ff00ff | 6.70 | 3.14 |
+;; | #00ffff | 16.75 | 1.25 |
+;; #+TBLFM: $2='(Λ $1 @1$2);%.2f :: $3='(Λ $1 @1$3);%.2f
(defun pulsar--create-pulse (locus face)
"Create a pulse spanning the LOCUS using FACE.
LOCUS is a cons cell with two buffer positions."
- (let ((pulse-flag t)
- (pulse-delay pulsar-delay)
- (pulse-iterations pulsar-iterations)
- (overlay (make-overlay (car locus) (cdr locus))))
- (overlay-put overlay 'pulse-delete t)
- (overlay-put overlay 'window (frame-selected-window))
- (pulse-momentary-highlight-overlay overlay face)))
+ (let ((common-fn (lambda (locus face)
+ (let ((pulse-flag t)
+ (pulse-delay pulsar-delay)
+ (pulse-iterations pulsar-iterations)
+ (overlay (make-overlay (car locus) (cdr locus))))
+ (overlay-put overlay 'pulse-delete t)
+ (overlay-put overlay 'window (frame-selected-window))
+ (pulse-momentary-highlight-overlay overlay face)))))
+ (if (display-graphic-p)
+ (funcall common-fn locus face)
+ (cl-letf (((symbol-function 'face-background) (lambda (&rest _)
pulsar-tty-color)))
+ (funcall common-fn locus face)))))
(define-obsolete-function-alias
'pulsar-pulse-region