From fd1a5d308e730bad2936adb2384897bb620458be Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 14 Nov 2025 01:53:30 -0600 Subject: feat(ui): Add buffer modification state to color indicators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change modeline filename and cursor colors to indicate buffer modification status, not just read-only/overwrite state. Color scheme changes: - White (#ffffff): Unmodified writeable buffer - Green (#64aa0f): Modified writeable buffer (unsaved changes) - Red (#f06a3f): Read-only buffer - Gold (#c48702): Overwrite mode active Previously: All writeable buffers were green regardless of modification Now: White when clean, green when dirty (better visual feedback) Implementation: - Updated cj/buffer-status-colors in user-constants.el: - Changed 'normal' → 'unmodified' (white) - Added new 'modified' state (green) - Updated state detection in modeline-config.el: - Now checks (buffer-modified-p) before defaulting to unmodified - Updated cursor color logic in ui-config.el: - Same state detection as modeline for consistency - Added after-change-functions hook for real-time updates - Added after-save-hook to update on save Priority order (highest to lowest): 1. Read-only (red) - takes precedence over everything 2. Overwrite mode (gold) - takes precedence over modified state 3. Modified (green) - buffer has unsaved changes 4. Unmodified (white) - default for clean writeable buffers Tests: - 18 comprehensive tests in test-ui-buffer-status-colors.el - Tests state detection logic and priority order - Tests color constant definitions and mappings - Tests integration with cursor and modeline - All tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- modules/ui-config.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'modules/ui-config.el') diff --git a/modules/ui-config.el b/modules/ui-config.el index 3922ce2a..3e065370 100644 --- a/modules/ui-config.el +++ b/modules/ui-config.el @@ -97,11 +97,12 @@ When `cj/enable-transparency' is nil, reset alpha to fully opaque." "Last buffer name where cursor color was applied.") (defun cj/set-cursor-color-according-to-mode () - "Change cursor color according to \\='buffer-read-only or \\='overwrite state." + "Change cursor color according to buffer state (modified, read-only, overwrite)." (let* ((state (cond - (buffer-read-only 'read-only) - (overwrite-mode 'overwrite) - (t 'normal))) + (buffer-read-only 'read-only) + (overwrite-mode 'overwrite) + ((buffer-modified-p) 'modified) + (t 'unmodified))) (color (alist-get state cj/buffer-status-colors))) (unless (and (string= color cj/-cursor-last-color) (string= (buffer-name) cj/-cursor-last-buffer)) @@ -114,6 +115,10 @@ When `cj/enable-transparency' is nil, reset alpha to fully opaque." (lambda (_window) (cj/set-cursor-color-according-to-mode))) (add-hook 'read-only-mode-hook #'cj/set-cursor-color-according-to-mode) (add-hook 'overwrite-mode-hook #'cj/set-cursor-color-according-to-mode) +;; Add hook to update cursor color when buffer is modified/saved +(add-hook 'after-change-functions + (lambda (&rest _) (cj/set-cursor-color-according-to-mode))) +(add-hook 'after-save-hook #'cj/set-cursor-color-according-to-mode) ;; Don’t show a cursor in non-selected windows: (setq cursor-in-non-selected-windows nil) -- cgit v1.2.3