From 3022997debed25c5975e396e82cd090632d9569c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 14 Oct 2015 00:51:28 +0100 Subject: [PATCH] Rename to beacon --- Readme.org | 18 +++--- spotlight.el | 174 +++++++++++++++++++++++++-------------------------- 2 files changed, 96 insertions(+), 96 deletions(-) diff --git a/Readme.org b/Readme.org index 6587e1228..621d259d0 100644 --- a/Readme.org +++ b/Readme.org @@ -1,20 +1,20 @@ -#+TITLE: Spotlight --- Never lose your cursor again +#+TITLE: Beacon --- Never lose your cursor again This is a global minor-mode. Turn it on everywhere with: #+BEGIN_SRC emacs-lisp -(spotlight-mode 1) +(beacon-mode 1) #+END_SRC Whenever point moves a long distance (as defined by -~spotlight-minimum-distance~) a light will shine on top of your cursor +~beacon-minimum-distance~) a light will shine on top of your cursor to make sure you see where it is. -- To customize the appearance of the spotlight, configure - ~spotlight-size~ and ~spotlight-brightness~. +- To customize the appearance of the beacon, configure + ~beacon-size~ and ~beacon-brightness~. -- To customize how long it lasts, configure ~spotlight-blink-duration~ - and ~spotlight-blink-delay~. +- To customize how long it lasts, configure ~beacon-blink-duration~ + and ~beacon-blink-delay~. - To customize when it is used at all, configure - ~spotlight-minimum-distance~ and - ~spotlight-blink-when-buffer-changes~. + ~beacon-minimum-distance~ and + ~beacon-blink-when-buffer-changes~. diff --git a/spotlight.el b/spotlight.el index 5bc13a5f5..a652e6701 100644 --- a/spotlight.el +++ b/spotlight.el @@ -1,4 +1,4 @@ -;;; 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 @@ -23,166 +23,166 @@ ;;; 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) ;;; 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)) ;;; 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))))) ;;; 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))) ;;; 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)))) ;;; Minor-mode -(defcustom spotlight-lighter (cond +(defcustom beacon-lighter (cond ((char-displayable-p ?💡) "💡") ((char-displayable-p ?Λ) "Λ") (t "*")) @@ -190,12 +190,12 @@ Only returns `spotlight-size' elements." :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 -- 2.39.2