From a8aa91a257796695d0fbbf471e90bd4ea74c70a8 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 18 Jun 2026 20:56:18 -0500 Subject: refactor(ui): remove buffer-state coloring of the buffer name The modeline colored the buffer name by write and modification state (red read-only, green modified, gold overwrite) through a classifier in user-constants.el. I removed it, the same way the matching cursor coloring was removed earlier for being more confusing than useful. The classifier had no other live user, so it and its two test files go with it. The buffer name now renders in the normal mode-line color. --- modules/modeline-config.el | 8 +- modules/ui-config.el | 7 +- modules/user-constants.el | 41 ----------- tests/test-modeline-config-string-cut-middle.el | 8 -- tests/test-modeline-config-string-truncate-p.el | 8 -- tests/test-ui-buffer-status-colors.el | 98 ------------------------- tests/test-ui-config--buffer-cursor-state.el | 74 ------------------- 7 files changed, 5 insertions(+), 239 deletions(-) delete mode 100644 tests/test-ui-buffer-status-colors.el delete mode 100644 tests/test-ui-config--buffer-cursor-state.el diff --git a/modules/modeline-config.el b/modules/modeline-config.el index f6b8ef4eb..d669425d3 100644 --- a/modules/modeline-config.el +++ b/modules/modeline-config.el @@ -15,7 +15,6 @@ ;; No external packages = no buffer issues, no native-comp errors. ;; Features: -;; - Buffer status (modified, read-only) ;; - Buffer name ;; - Major mode ;; - Version control status @@ -75,11 +74,9 @@ Example: `my-very-long-name.el' → `my-ver...me.el'" ;; -------------------------- Modeline Segments -------------------------------- (defvar-local cj/modeline-buffer-name - '(:eval (let* ((color (cj/buffer-status-color (cj/buffer-status-state))) - (name (buffer-name)) + '(:eval (let* ((name (buffer-name)) (truncated-name (cj/modeline-string-cut-middle name))) (propertize truncated-name - 'face `(:foreground ,color) 'mouse-face 'mode-line-highlight 'help-echo (concat name "\n" @@ -89,8 +86,7 @@ Example: `my-very-long-name.el' → `my-ver...me.el'" (define-key map [mode-line mouse-1] 'previous-buffer) (define-key map [mode-line mouse-3] 'next-buffer) map)))) - "Buffer name colored by modification and read-only status. -White = unmodified, Green = modified, Red = read-only, Gold = overwrite. + "Buffer name in the mode line. Truncates in narrow windows. Click to switch buffers.") (defvar-local cj/modeline-position diff --git a/modules/ui-config.el b/modules/ui-config.el index 05448b3c5..32bd393f5 100644 --- a/modules/ui-config.el +++ b/modules/ui-config.el @@ -94,10 +94,9 @@ When `cj/enable-transparency' is nil, reset alpha to fully opaque." (if cj/enable-transparency "enabled" "disabled"))) ;; ----------------------------------- Cursor ---------------------------------- -;; The cursor uses the theme's cursor face. Buffer-state cursor coloring was -;; removed -- a cursor that changed color by buffer state was confusing. The -;; cj/buffer-status-state / cj/buffer-status-color classifier stays in -;; user-constants.el; the modeline buffer-name indicator still uses it. +;; The cursor uses the theme's cursor face. Buffer-state coloring (both the +;; cursor and the modeline buffer-name) was removed -- changing color by buffer +;; write state was more confusing than useful. ;; Don’t show a cursor in non-selected windows: (setq cursor-in-non-selected-windows nil) diff --git a/modules/user-constants.el b/modules/user-constants.el index 1ee8ecda3..dab12dcbe 100644 --- a/modules/user-constants.el +++ b/modules/user-constants.el @@ -53,47 +53,6 @@ mail, chime, etc." (defvar user-mail-address "c@cjennings.net" "The user's email address.") -;; ---------------------------- Buffer Status Colors --------------------------- - -(defconst cj/buffer-status-faces - '((read-only . error) ; can't edit - (overwrite . warning) ; overwrite mode - (modified . warning) ; writeable, with unsaved changes - (unmodified . success)) ; clean and writeable - "Alist mapping a buffer state to the theme face whose foreground colors it. -Shared by the cursor color (ui-config.el) and the modeline buffer-status -indicator (modeline-config.el) so the two stay in sync and follow the active -theme, rather than hard-coding hex colors.") - -(defun cj/buffer-status-state () - "Return the buffer-state symbol for the current buffer. -One of `read-only', `overwrite', `modified', or `unmodified' -- the keys of -`cj/buffer-status-faces'. - -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 it is -writeable and the read-only state 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'." - (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/buffer-status-color (state) - "Return the foreground color of the theme face mapped to buffer STATE. -Resolves STATE through `cj/buffer-status-faces' against the active theme. Nil -when the state is unknown or its face has no concrete foreground (face-attribute -returns the symbol `unspecified' there), so callers can skip cleanly." - (when-let* ((face (alist-get state cj/buffer-status-faces)) - (fg (face-attribute face :foreground nil t))) - (and (stringp fg) fg))) - ;; --------------------------- Media File Extensions --------------------------- (defvar cj/audio-file-extensions diff --git a/tests/test-modeline-config-string-cut-middle.el b/tests/test-modeline-config-string-cut-middle.el index 40cc0bccc..d68431b49 100644 --- a/tests/test-modeline-config-string-cut-middle.el +++ b/tests/test-modeline-config-string-cut-middle.el @@ -17,14 +17,6 @@ ;; Add modules directory to load path (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -;; Stub dependencies before loading the module -(unless (boundp 'cj/buffer-status-colors) - (defvar cj/buffer-status-colors - '((unmodified . "#FFFFFF") - (modified . "#00FF00") - (read-only . "#FF0000") - (overwrite . "#FFD700")))) - (require 'modeline-config) ;;; Test Helpers diff --git a/tests/test-modeline-config-string-truncate-p.el b/tests/test-modeline-config-string-truncate-p.el index 09378b0d1..94ea74171 100644 --- a/tests/test-modeline-config-string-truncate-p.el +++ b/tests/test-modeline-config-string-truncate-p.el @@ -19,14 +19,6 @@ ;; Add modules directory to load path (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -;; Stub dependencies before loading the module -(unless (boundp 'cj/buffer-status-colors) - (defvar cj/buffer-status-colors - '((unmodified . "#FFFFFF") - (modified . "#00FF00") - (read-only . "#FF0000") - (overwrite . "#FFD700")))) - (require 'modeline-config) ;;; Test Helpers diff --git a/tests/test-ui-buffer-status-colors.el b/tests/test-ui-buffer-status-colors.el deleted file mode 100644 index 06e466b85..000000000 --- a/tests/test-ui-buffer-status-colors.el +++ /dev/null @@ -1,98 +0,0 @@ -;;; test-ui-buffer-status-colors.el --- Tests for buffer-status faces -*- lexical-binding: t; -*- - -;;; Commentary: -;; The buffer-status state classifier (`cj/buffer-status-state'), the state->face -;; map (`cj/buffer-status-faces'), and the resolver (`cj/buffer-status-color') -;; drive both the cursor color and the modeline buffer-name color, kept in sync. -;; Theme faces (error / warning / success) replace the old hard-coded hexes so -;; the colors follow whatever theme is loaded. - -;;; Code: - -(require 'ert) -(require 'user-constants) -(require 'ui-config) -(require 'modeline-config) - -;;; State -> face map - -(ert-deftest test-buffer-status-faces-has-all-states () - "Normal: every buffer state is mapped to a face." - (dolist (state '(read-only overwrite modified unmodified)) - (should (alist-get state cj/buffer-status-faces)))) - -(ert-deftest test-buffer-status-faces-values-are-real-faces () - "Normal: every mapped value is an existing face." - (dolist (entry cj/buffer-status-faces) - (should (facep (cdr entry))))) - -(ert-deftest test-buffer-status-faces-mapping () - "Normal: read-only->error, overwrite/modified->warning, unmodified->success." - (should (eq (alist-get 'read-only cj/buffer-status-faces) 'error)) - (should (eq (alist-get 'overwrite cj/buffer-status-faces) 'warning)) - (should (eq (alist-get 'modified cj/buffer-status-faces) 'warning)) - (should (eq (alist-get 'unmodified cj/buffer-status-faces) 'success))) - -;;; State classifier (the shared function, exercised directly) - -(ert-deftest test-buffer-status-state-read-only () - "Normal: a read-only buffer reports `read-only'." - (with-temp-buffer - (setq buffer-read-only t) - (should (eq (cj/buffer-status-state) 'read-only)))) - -(ert-deftest test-buffer-status-state-overwrite-wins-over-modified () - "Boundary: overwrite-mode takes priority over the modified state." - (with-temp-buffer - (insert "x") - (overwrite-mode 1) - (should (eq (cj/buffer-status-state) 'overwrite)))) - -(ert-deftest test-buffer-status-state-modified () - "Normal: a writeable buffer with unsaved changes reports `modified'." - (with-temp-buffer - (insert "x") - (should (eq (cj/buffer-status-state) 'modified)))) - -(ert-deftest test-buffer-status-state-unmodified () - "Normal: a clean writeable buffer reports `unmodified'." - (with-temp-buffer - (set-buffer-modified-p nil) - (should (eq (cj/buffer-status-state) 'unmodified)))) - -(ert-deftest test-buffer-status-state-read-only-wins-over-modified () - "Boundary: read-only takes priority over modified." - (with-temp-buffer - (insert "x") - (set-buffer-modified-p t) - (setq buffer-read-only t) - (should (eq (cj/buffer-status-state) 'read-only)))) - -;;; Resolver - -(ert-deftest test-buffer-status-color-resolves-through-the-face () - "Normal: the color is the mapped face's foreground." - (let ((orig (face-attribute 'error :foreground nil t))) - (unwind-protect - (progn - (set-face-foreground 'error "#abcdef") - (should (equal (cj/buffer-status-color 'read-only) "#abcdef"))) - (when (stringp orig) (set-face-foreground 'error orig))))) - -(ert-deftest test-buffer-status-color-nil-for-unknown-state () - "Error: an unknown state has no face, so no color." - (should-not (cj/buffer-status-color 'nonexistent))) - -;;; Modeline integration - -(ert-deftest test-modeline-buffer-name-variable-exists () - "Normal: the modeline buffer-name construct is defined." - (should (boundp 'cj/modeline-buffer-name))) - -(ert-deftest test-modeline-buffer-name-is-mode-line-construct () - "Normal: it is an :eval mode-line construct." - (should (listp cj/modeline-buffer-name)) - (should (eq (car cj/modeline-buffer-name) :eval))) - -(provide 'test-ui-buffer-status-colors) -;;; test-ui-buffer-status-colors.el ends here diff --git a/tests/test-ui-config--buffer-cursor-state.el b/tests/test-ui-config--buffer-cursor-state.el deleted file mode 100644 index 99cfc4b9d..000000000 --- a/tests/test-ui-config--buffer-cursor-state.el +++ /dev/null @@ -1,74 +0,0 @@ -;;; test-ui-config--buffer-cursor-state.el --- Tests for cursor-state classification -*- lexical-binding: t; -*- - -;;; Commentary: -;; `cj/buffer-status-state' picks the buffer-state symbol the modeline -;; buffer-name indicator maps to a face via `cj/buffer-status-color'. The -;; subtle case: a live ghostel terminal is -;; technically `buffer-read-only' but the user types into it -- keystrokes go -;; to the terminal process -- so it must report a writeable state, not -;; `read-only'. ghostel's `copy' / `emacs' input modes are the exception: -;; there the buffer really is a read-only Emacs buffer the user navigates, so -;; `read-only' (the orange cursor) is correct and kept. - -;;; Code: - -(require 'ert) -(require 'cl-lib) - -(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) -(setq load-prefer-newer t) -(defvar ghostel--input-mode nil) -(require 'ui-config) -(require 'testutil-ghostel-buffers) - -(ert-deftest test-ui-config-buffer-cursor-state-readwrite-unmodified () - "Normal: a clean writeable buffer reports `unmodified'." - (with-temp-buffer - (set-buffer-modified-p nil) - (should (eq (cj/buffer-status-state) 'unmodified)))) - -(ert-deftest test-ui-config-buffer-cursor-state-readwrite-modified () - "Normal: a writeable buffer with unsaved changes reports `modified'." - (with-temp-buffer - (insert "x") - (should (eq (cj/buffer-status-state) 'modified)))) - -(ert-deftest test-ui-config-buffer-cursor-state-read-only () - "Normal: a plain read-only buffer reports `read-only'." - (with-temp-buffer - (setq buffer-read-only t) - (should (eq (cj/buffer-status-state) 'read-only)))) - -(ert-deftest test-ui-config-buffer-cursor-state-overwrite () - "Boundary: `overwrite-mode' wins over the modified/unmodified split." - (with-temp-buffer - (insert "x") - (overwrite-mode 1) - (should (eq (cj/buffer-status-state) 'overwrite)))) - -(ert-deftest test-ui-config-buffer-cursor-state-live-ghostel-is-writeable () - "Boundary: a live ghostel buffer is `buffer-read-only' but reports a -writeable state -- the user types into the terminal process there, so the -read-only (orange) cursor would be misleading." - (let ((buf (cj/test--make-fake-ghostel-buffer "*test-ghostel-cursor-state*"))) - (unwind-protect - (with-current-buffer buf - (setq buffer-read-only t) ; ghostel keeps the buffer read-only - (setq-local ghostel--input-mode 'semi-char) - (should-not (eq (cj/buffer-status-state) 'read-only))) - (when (buffer-live-p buf) (kill-buffer buf))))) - -(ert-deftest test-ui-config-buffer-cursor-state-ghostel-copy-mode-is-read-only () - "Boundary: in ghostel `copy' mode the buffer is a read-only Emacs buffer -the user navigates, so `read-only' (orange) is kept." - (let ((buf (cj/test--make-fake-ghostel-buffer "*test-ghostel-cursor-state-copy*"))) - (unwind-protect - (with-current-buffer buf - (setq buffer-read-only t) - (setq-local ghostel--input-mode 'copy) - (should (eq (cj/buffer-status-state) 'read-only))) - (when (buffer-live-p buf) (kill-buffer buf))))) - -(provide 'test-ui-config--buffer-cursor-state) -;;; test-ui-config--buffer-cursor-state.el ends here -- cgit v1.2.3