diff options
| -rw-r--r-- | README.md | 50 | ||||
| -rw-r--r-- | cursor-breathe-mode.el | 66 | ||||
| -rw-r--r-- | demo.gif | bin | 0 -> 84633 bytes |
3 files changed, 116 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee19aa8 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# CURSOR-BREATHE-MODE + +An Emacs minor mode that animates the cursor width in a slow breathing pattern, making it more visible without relying on blinking. + + + +## Why + +Because it's cool! And while a blinking cursor can be jarring, it is also more visible than a static one. This is both dynamic enough to catch the eye, yet static enough to always be visible. + +## Installation + +### straight.el + +```elisp +(use-package cursor-breathe-mode + :straight (cursor-breathe-mode + :type git + :repo "https://git.etenil.net/cursor-breathe-mode.el") + :config (cursor-breathe-mode 1)) +``` + +### Manual + +Copy `cursor-breathe-mode.el` somewhere on your `load-path`, then: + +```elisp +(require 'cursor-breathe-mode) +(cursor-breathe-mode 1) +``` + +## Usage + +Toggle with `M-x cursor-breathe-mode`. + +## Customisation + +All options are under `M-x customize-group cursor-breathe`. + +- `curbreathe/cursor-type`: shape to animate: `hbar` (horizontal bar, + default) or `bar` (vertical bar) +- `curbreathe/min-size`: minimum width in pixels (default `2`) +- `curbreathe/max-size`: maximum width in pixels (default `8`) +- `curbreathe/frame-rate`: animation steps per second (default `10`) + +## Caveats + +Emacs is complex and single-threaded, so sometimes the timer looks 'stuck', it is usually temporary and will defreeze when another command is run. + +Only `bar` and `hbar` cursor types are supported for the foreseeable future (depends on emacs cursor implementation.) diff --git a/cursor-breathe-mode.el b/cursor-breathe-mode.el new file mode 100644 index 0000000..06f2341 --- /dev/null +++ b/cursor-breathe-mode.el @@ -0,0 +1,66 @@ +;;; cursor-breathe-mode.el --- Animate cursor width to improve visibility -*- lexical-binding: t -*- + +;; Author: Gene Pasquet +;; Version: 0.1.0 +;; Keywords: convenience, cursor + +;;; Commentary: +;; A minor mode that animates the cursor width in a breathing pattern, +;; making it more visible without relying on blinking. + +;;; Code: + +(defgroup cursor-breathe nil + "Animated breathing cursor." + :group 'cursor + :prefix "curbreathe/") + +(defcustom curbreathe/frame-rate 10 + "Target frame-rate for the breathing cursor." + :type 'number + :group 'cursor-breathe) + +(defcustom curbreathe/max-size 8 + "Maximum cursor width in pixels." + :type 'integer + :group 'cursor-breathe) + +(defcustom curbreathe/min-size 2 + "Minimum cursor width in pixels." + :type 'integer + :group 'cursor-breathe) + +(defcustom curbreathe/cursor-type 'hbar + "Cursor type to animate. Only bar-like types support width animation." + :type '(choice (const :tag "Horizontal bar" hbar) + (const :tag "Vertical bar" bar)) + :group 'cursor-breathe) + +(defvar curbreathe/original-cursor-type nil + "The cursor type initially configured") + +(defvar curbreathe/increment +1 + "Direction of the animation") +(defvar curbreathe/timer nil + "Global variable holding the animation timer") + +(define-minor-mode cursor-breathe-mode + "Animate the cursor to make it more visible" + :global t + + (if cursor-breathe-mode + (progn + (setq curbreathe/original-cursor-type cursor-type) + (setq curbreathe/timer (run-with-timer 0 (/ 1.0 curbreathe/frame-rate) #'curbreathe/step))) + (progn + (cancel-timer curbreathe/timer) + (setq-default cursor-type curbreathe/original-cursor-type)))) + +(defun curbreathe/step () + (let ((new-value (+ curbreathe/increment (cdr cursor-type)))) + (cond ((>= new-value curbreathe/max-size) (setq curbreathe/increment -1)) + ((<= new-value curbreathe/min-size) (setq curbreathe/increment +1))) + (setq-default cursor-type (cons curbreathe/cursor-type new-value)))) + +(provide 'cursor-breathe-mode) +;;; cursor-breathe-mode.el ends here diff --git a/demo.gif b/demo.gif Binary files differnew file mode 100644 index 0000000..dc9174e --- /dev/null +++ b/demo.gif |
