aboutsummaryrefslogtreecommitdiff
path: root/modules/ui-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-14 17:23:37 -0500
committerCraig Jennings <c@cjennings.net>2026-06-14 17:23:37 -0500
commit7ccc3f5c0d688914eff0f8501f85d3f40ab8601d (patch)
tree96c1669768a87345747a441fa3effd265d5a74b3 /modules/ui-config.el
parentabaf96f1b4b9efc296161e2315549f55377740b4 (diff)
downloaddotemacs-7ccc3f5c0d688914eff0f8501f85d3f40ab8601d.tar.gz
dotemacs-7ccc3f5c0d688914eff0f8501f85d3f40ab8601d.zip
refactor(ui): color the cursor and modeline from theme faces, in sync
The cursor color and the modeline buffer-name indicator both hard-coded hex colors through cj/buffer-status-colors. Replaced that constant with cj/buffer-status-faces, mapping each buffer state to a theme face: read-only to error, overwrite and modified to warning, unmodified to success. A shared classifier (cj/buffer-status-state) and resolver (cj/buffer-status-color) in user-constants now drive both consumers, so the cursor and the modeline resolve their color from the active theme at use time and stay in sync, including the ghostel-terminal case the cursor already special-cased. Tests cover the map, the classifier, the resolver, and both integration paths.
Diffstat (limited to 'modules/ui-config.el')
-rw-r--r--modules/ui-config.el57
1 files changed, 18 insertions, 39 deletions
diff --git a/modules/ui-config.el b/modules/ui-config.el
index 7afe528b2..86670b29d 100644
--- a/modules/ui-config.el
+++ b/modules/ui-config.el
@@ -94,53 +94,32 @@ When `cj/enable-transparency' is nil, reset alpha to fully opaque."
(if cj/enable-transparency "enabled" "disabled")))
;; ----------------------------------- Cursor ----------------------------------
-;; set cursor color according to mode
-;;
-;; #f06a3f indicates a read-only document
-;; #c48702 indicates overwrite mode
-;; #64aa0f indicates insert and read/write mode
+;; Set the cursor color from the active theme's faces according to buffer state.
+;; The state classifier and the state->face map live in user-constants.el
+;; (cj/buffer-status-state / cj/buffer-status-faces, colored via the theme's
+;; error / warning / success faces) and are shared with the modeline buffer-name
+;; indicator, so the cursor and the modeline stay in sync.
(defvar cj/-cursor-last-color nil
"Last color applied by `cj/set-cursor-color-according-to-mode'.")
(defvar cj/-cursor-last-buffer nil
"Last buffer name where cursor color was applied.")
-(defun cj/--buffer-cursor-state ()
- "Return the buffer-state symbol used to choose the cursor color.
-
-One of `read-only', `overwrite', `modified', or `unmodified' — keys
-of `cj/buffer-status-colors'.
-
-A live ghostel terminal (in `ghostel-mode' and an input mode that
-forwards keys — semi-char / char / line) reports `unmodified' even
-though the buffer is read-only: keystrokes go to the terminal process,
-so from the user's side the buffer is writeable and the read-only
-(orange) cursor would be misleading. ghostel's `copy' and `emacs'
-input modes are the exception — there the buffer really is a read-only
-Emacs buffer the user navigates, so it falls through to `read-only'
-and keeps the orange cursor."
- (cond
- ((and (eq major-mode 'ghostel-mode)
- (not (memq (bound-and-true-p ghostel--input-mode) '(copy emacs))))
- 'unmodified)
- (buffer-read-only 'read-only)
- (overwrite-mode 'overwrite)
- ((buffer-modified-p) 'modified)
- (t 'unmodified)))
-
(defun cj/set-cursor-color-according-to-mode ()
- "Change cursor color according to buffer state (modified, read-only, overwrite).
-Only updates for real user buffers, not internal/temporary buffers.
-A no-op on non-graphical frames -- TTY/batch sessions have no cursor color
-to set."
+ "Set the cursor color from the active theme according to buffer state.
+The state and its theme face come from `cj/buffer-status-state' and
+`cj/buffer-status-color' (shared with the modeline), so the color follows the
+loaded theme. Only updates real user buffers, not internal/temporary ones; a
+no-op on non-graphical frames -- TTY/batch sessions have no cursor color to set."
(when (display-graphic-p)
- ;; Only update cursor for real buffers (not internal ones like *temp*, *Echo Area*, etc.)
- (unless (string-prefix-p " " (buffer-name)) ; Internal buffers start with space
- (let ((color (alist-get (cj/--buffer-cursor-state) cj/buffer-status-colors)))
- ;; Only skip if BOTH color AND buffer are the same (optimization)
- ;; This allows color to update when buffer state changes
- (unless (and (string= color cj/-cursor-last-color)
- (string= (buffer-name) cj/-cursor-last-buffer))
+ ;; Only update cursor for real buffers (not internal ones like *temp*, *Echo Area*).
+ (unless (string-prefix-p " " (buffer-name)) ; internal buffers start with a space
+ (let ((color (cj/buffer-status-color (cj/buffer-status-state))))
+ ;; Skip only when BOTH color and buffer are unchanged (so the color still
+ ;; updates when the buffer state changes).
+ (when (and color
+ (not (and (equal color cj/-cursor-last-color)
+ (equal (buffer-name) cj/-cursor-last-buffer))))
(set-cursor-color color)
(setq cj/-cursor-last-color color
cj/-cursor-last-buffer (buffer-name)))))))