-;;; spotlight.el --- Highlight the cursor whenever it moves long distances -*- lexical-binding: t; -*-
+;;; beacon.el --- Highlight the cursor whenever it moves long distances -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Artur Malabarba
;;; Commentary:
;; This is a global minor-mode. Turn it on everywhere with
-;; (spotlight-mode 1)
+;; (beacon-mode 1)
;;; Code:
(require 'cl-lib)
-(defgroup spotlight nil
- "Customization group for spotlight."
+(defgroup beacon nil
+ "Customization group for beacon."
:group 'emacs
- :prefix "spotlight-")
+ :prefix "beacon-")
-(defvar spotlight--timer nil)
+(defvar beacon--timer nil)
-(defcustom spotlight-minimum-distance 15
- "Minimum movement distance in lines to blink the spotlight."
+(defcustom beacon-minimum-distance 15
+ "Minimum movement distance in lines to blink the beacon."
:type 'integer)
-(defcustom spotlight-push-mark nil
+(defcustom beacon-push-mark nil
"Should the mark be pushed before long movements?"
:type 'boolean)
-(defcustom spotlight-blink-when-buffer-changes t
- "Should the spotlight blink when changing buffer?"
+(defcustom beacon-blink-when-buffer-changes t
+ "Should the beacon blink when changing buffer?"
:type 'boolean)
-(defcustom spotlight-blink-duration 0.3
+(defcustom beacon-blink-duration 0.3
"Time, in seconds, that the blink should last."
:type 'number)
-(defcustom spotlight-blink-delay 0.3
- "Time, in seconds, before starting to fade the spotlight."
+(defcustom beacon-blink-delay 0.3
+ "Time, in seconds, before starting to fade the beacon."
:type 'number)
-(defcustom spotlight-size 15
- "Size of the spotlight in characters."
+(defcustom beacon-size 30
+ "Size of the beacon in characters."
:type 'number)
-(defcustom spotlight-brightness 0.5
+(defcustom beacon-brightness 0.5
"Brightness as a float between 0 and 1."
:type 'number)
\f
;;; Overlays
-(defvar spotlight--ovs nil)
+(defvar beacon--ovs nil)
-(defun spotlight--colored-overlay (color)
+(defun beacon--colored-overlay (color)
"Put an overlay at point with background COLOR."
(let ((ov (make-overlay (point) (1+ (point)))))
(overlay-put ov 'face (list :background color))
- (overlay-put ov 'spotlight t)
- (push ov spotlight--ovs)))
+ (overlay-put ov 'beacon t)
+ (push ov beacon--ovs)))
-(defun spotlight--ov-at-point ()
- (car (cl-member-if (lambda (o) (overlay-get o 'spotlight))
+(defun beacon--ov-at-point ()
+ (car (cl-member-if (lambda (o) (overlay-get o 'beacon))
(overlays-at (point)))))
-(defun spotlight--vanish ()
- "Turn off the spotlight."
- (when (timerp spotlight--timer)
- (cancel-timer spotlight--timer))
- (mapc #'delete-overlay spotlight--ovs)
- (setq spotlight--ovs nil))
+(defun beacon--vanish ()
+ "Turn off the beacon."
+ (when (timerp beacon--timer)
+ (cancel-timer beacon--timer))
+ (mapc #'delete-overlay beacon--ovs)
+ (setq beacon--ovs nil))
\f
;;; Colors
-(defun spotlight--int-range (a b)
+(defun beacon--int-range (a b)
"Return a list of integers between A inclusive and B exclusive.
-Only returns `spotlight-size' elements."
- (let ((d (/ (- b a) spotlight-size))
+Only returns `beacon-size' elements."
+ (let ((d (/ (- b a) beacon-size))
(out (list a)))
- (dotimes (_ (1- spotlight-size))
+ (dotimes (_ (1- beacon-size))
(push (+ (car out) d) out))
(nreverse out)))
-(defun spotlight--color-range ()
- "Return a list of background colors for the spotlight."
+(defun beacon--color-range ()
+ "Return a list of background colors for the beacon."
(let ((bg (color-values (face-attribute 'default :background))))
(apply #'cl-mapcar (lambda (r g b) (format "#%04x%04x%04x" r g b))
(if (< (color-distance "black" bg)
(color-distance "white" bg))
- (mapcar (lambda (n) (butlast (spotlight--int-range (* spotlight-brightness 65535) n))) bg)
- (mapcar (lambda (n) (cdr (spotlight--int-range (* (- 1 spotlight-brightness) 65535) n))) bg)))))
+ (mapcar (lambda (n) (butlast (beacon--int-range (* beacon-brightness 65535) n))) bg)
+ (mapcar (lambda (n) (cdr (beacon--int-range (* (- 1 beacon-brightness) 65535) n))) bg)))))
\f
;;; Blinking
-(defun spotlight--shine ()
- "Shine a spotlight at point."
- (let ((colors (spotlight--color-range)))
+(defun beacon--shine ()
+ "Shine a beacon at point."
+ (let ((colors (beacon--color-range)))
(save-excursion
(while colors
(if (looking-at "$")
(progn
- ;; (spotlight--after-string)
+ ;; (beacon--after-string)
(setq colors nil))
- (spotlight--colored-overlay (pop colors))
+ (beacon--colored-overlay (pop colors))
(forward-char 1))))))
-(defun spotlight--dec ()
- "Decrease the spotlight brightness by one."
- (let ((o (spotlight--ov-at-point)))
+(defun beacon--dec ()
+ "Decrease the beacon brightness by one."
+ (let ((o (beacon--ov-at-point)))
(if (not o)
- (spotlight--vanish)
+ (beacon--vanish)
(delete-overlay o)
(save-excursion
(while (progn (forward-char 1)
- (setq o (spotlight--ov-at-point)))
+ (setq o (beacon--ov-at-point)))
(move-overlay o (1- (point)) (point)))))))
-(defun spotlight-blink ()
- "Blink the spotlight at the position of the cursor."
+(defun beacon-blink ()
+ "Blink the beacon at the position of the cursor."
(interactive)
- (spotlight--vanish)
- (spotlight--shine)
- (setq spotlight--timer
- (run-at-time spotlight-blink-delay
- (/ spotlight-blink-duration 1.0 (length spotlight--colors))
- #'spotlight--dec)))
+ (beacon--vanish)
+ (beacon--shine)
+ (setq beacon--timer
+ (run-at-time beacon-blink-delay
+ (/ beacon-blink-duration 1.0 (length beacon--colors))
+ #'beacon--dec)))
\f
;;; Movement detection
-(defvar spotlight--previous-place nil)
-(defvar spotlight--previous-mark-head nil)
+(defvar beacon--previous-place nil)
+(defvar beacon--previous-mark-head nil)
-(defun spotlight--maybe-push-mark ()
+(defun beacon--maybe-push-mark ()
"Push mark if it seems to be safe."
- (when (and spotlight-push-mark
+ (when (and beacon-push-mark
(not mark-active))
(let ((head (car mark-ring)))
- (when (and (eq spotlight--previous-mark-head head)
- (not (equal head spotlight--previous-place)))
- (push-mark spotlight--previous-place)))))
+ (when (and (eq beacon--previous-mark-head head)
+ (not (equal head beacon--previous-place)))
+ (push-mark beacon--previous-place)))))
-(defun spotlight--post-command ()
+(defun beacon--post-command ()
"Blink if point moved very far."
(cond
- ((not (markerp spotlight--previous-place))
- (spotlight--vanish))
+ ((not (markerp beacon--previous-place))
+ (beacon--vanish))
;; Blink because we changed buffer.
- ((not (equal (marker-buffer spotlight--previous-place)
+ ((not (equal (marker-buffer beacon--previous-place)
(current-buffer)))
- (when spotlight-blink-when-buffer-changes
+ (when beacon-blink-when-buffer-changes
(unless (window-minibuffer-p)
- (spotlight-blink))))
+ (beacon-blink))))
;; Blink for distance movement
- ((and (> (abs (- (point) spotlight--previous-place))
- spotlight-minimum-distance)
- (> (count-screen-lines (min (point) spotlight--previous-place)
- (max (point) spotlight--previous-place))
- spotlight-minimum-distance))
- (spotlight--maybe-push-mark)
- (spotlight-blink))
- ;; Even if we don't blink, vanish any previous spotlight.
- (t (spotlight--vanish)))
+ ((and (> (abs (- (point) beacon--previous-place))
+ beacon-minimum-distance)
+ (> (count-screen-lines (min (point) beacon--previous-place)
+ (max (point) beacon--previous-place))
+ beacon-minimum-distance))
+ (beacon--maybe-push-mark)
+ (beacon-blink))
+ ;; Even if we don't blink, vanish any previous beacon.
+ (t (beacon--vanish)))
(unless (window-minibuffer-p)
- (setq spotlight--previous-mark-head (car mark-ring))
- (setq spotlight--previous-place (point-marker))))
+ (setq beacon--previous-mark-head (car mark-ring))
+ (setq beacon--previous-place (point-marker))))
\f
;;; Minor-mode
-(defcustom spotlight-lighter (cond
+(defcustom beacon-lighter (cond
((char-displayable-p ?💡) "💡")
((char-displayable-p ?Λ) "Λ")
(t "*"))
:type 'string)
;;;###autoload
-(define-minor-mode spotlight-mode
- nil nil spotlight-lighter nil
+(define-minor-mode beacon-mode
+ nil nil beacon-lighter nil
:global t
- (if spotlight-mode
- (add-hook 'post-command-hook #'spotlight--post-command)
- (remove-hook 'post-command-hook #'spotlight--post-command)))
+ (if beacon-mode
+ (add-hook 'post-command-hook #'beacon--post-command)
+ (remove-hook 'post-command-hook #'beacon--post-command)))
-(provide 'spotlight)
-;;; spotlight.el ends here
+(provide 'beacon)
+;;; beacon.el ends here