From adca2736e2e3ef1eef1aaf62542aa2189a560463 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 16 May 2026 02:12:56 -0500 Subject: feat(modeline): surface flycheck status in the custom modeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The custom modeline builds `mode-line-format` from explicit segments and skips `minor-mode-alist`, so flycheck's lighter never appears. That hid error and warning counts even in buffers where flycheck was auto-enabling (every emacs-lisp and sh buffer). The fix is Option 4 from the design doc: customize the flycheck modeline variables, then add a single guarded `(:eval ...)` form to `mode-line-format`. Five new lines total, two-file change. `modules/flycheck-config.el` :custom block gets: (flycheck-mode-line-prefix "🐛") (flycheck-mode-success-indicator " ✓") `flycheck-mode-line-color` stays default-t so error / warning counts pick up their faces automatically. `modules/modeline-config.el` `mode-line-format` gets an `(:eval ...)` between the recording indicator and `cj/modeline-vc-branch`: (:eval (when (and (mode-line-window-selected-p) (bound-and-true-p flycheck-mode)) (flycheck-mode-line-status-text))) The `mode-line-window-selected-p` guard mirrors `cj/modeline-vc-branch` and `cj/modeline-misc-info` -- segments hide in inactive windows. The `bound-and-true-p flycheck-mode` guard keeps the form silent in buffers where flycheck hasn't loaded or isn't enabled, which is safer than referencing `flycheck-mode` directly. The `(:eval ...)` is inline rather than a named `defvar-local`, so no addition to the risky-local-variable list is needed. `tests/test-modeline-config-flycheck-segment.el` -- 3 smoke tests asserting the segment is present and both guards are in place. All existing tests stay green. Manual verification (per the design doc) is the user's call -- the emoji prefix and the colored count behavior need a running GUI Emacs to observe. --- modules/flycheck-config.el | 5 ++++ modules/modeline-config.el | 7 +++++ tests/test-modeline-config-flycheck-segment.el | 36 ++++++++++++++++++++++++++ todo.org | 25 ++++++++++++------ 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 tests/test-modeline-config-flycheck-segment.el diff --git a/modules/flycheck-config.el b/modules/flycheck-config.el index 8c3e2a7b..e6dfb25e 100644 --- a/modules/flycheck-config.el +++ b/modules/flycheck-config.el @@ -56,6 +56,11 @@ (checkdoc-arguments '(("sentence-end-double-space" nil) ("warn-escape" nil))) + ;; Modeline customization (rendered via mode-line-format in modeline-config.el). + ;; The count portion picks up `error' / `warning' faces because + ;; `flycheck-mode-line-color' stays t (the default). + (flycheck-mode-line-prefix "🐛") + (flycheck-mode-success-indicator " ✓") :config ;; use the load-path of the currently running Emacs instance diff --git a/modules/modeline-config.el b/modules/modeline-config.el index 7fc75594..771d960f 100644 --- a/modules/modeline-config.el +++ b/modules/modeline-config.el @@ -231,6 +231,13 @@ Shows only in active window.") mode-line-format-right-align (:eval (when (fboundp 'cj/recording-modeline-indicator) (cj/recording-modeline-indicator))) + ;; Flycheck status: prefix + counts (or success indicator). Gated + ;; to the active window, and to buffers where flycheck has loaded + ;; and turned on, so the call is safe even before flycheck loads. + (:eval (when (and (mode-line-window-selected-p) + (bound-and-true-p flycheck-mode)) + (flycheck-mode-line-status-text))) + " " cj/modeline-vc-branch " " cj/modeline-misc-info diff --git a/tests/test-modeline-config-flycheck-segment.el b/tests/test-modeline-config-flycheck-segment.el new file mode 100644 index 00000000..208deaa7 --- /dev/null +++ b/tests/test-modeline-config-flycheck-segment.el @@ -0,0 +1,36 @@ +;;; test-modeline-config-flycheck-segment.el --- Flycheck segment in modeline -*- lexical-binding: t; -*- + +;;; Commentary: +;; Smoke test that the custom modeline's `mode-line-format' includes +;; a guarded reference to `flycheck-mode-line-status-text', and that +;; the guard requires both `mode-line-window-selected-p' and +;; `bound-and-true-p flycheck-mode'. See +;; docs/design/flycheck-modeline-customization.org for the design. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) + +(require 'modeline-config) + +(ert-deftest test-modeline-config-flycheck-segment-present () + "`mode-line-format' contains an :eval form invoking flycheck-mode-line-status-text." + (let ((printed (format "%S" (default-value 'mode-line-format)))) + (should (string-match-p "flycheck-mode-line-status-text" printed)))) + +(ert-deftest test-modeline-config-flycheck-segment-guarded-by-active-window () + "Flycheck segment gates on `mode-line-window-selected-p'." + (let ((printed (format "%S" (default-value 'mode-line-format)))) + (should (string-match-p "mode-line-window-selected-p" printed)))) + +(ert-deftest test-modeline-config-flycheck-segment-guarded-by-flycheck-mode () + "Flycheck segment gates on `bound-and-true-p flycheck-mode'. +The `bound-and-true-p' guard makes the form safe in buffers where +flycheck never loaded." + (let ((printed (format "%S" (default-value 'mode-line-format)))) + (should (string-match-p "bound-and-true-p flycheck-mode" printed)))) + +(provide 'test-modeline-config-flycheck-segment) +;;; test-modeline-config-flycheck-segment.el ends here diff --git a/todo.org b/todo.org index 14777f27..e69c45c3 100644 --- a/todo.org +++ b/todo.org @@ -2548,16 +2548,25 @@ Test the new REST API client integration in a running Emacs session. - C-; R s should replace :skyfi-key = PLACEHOLDER with real key - Key should NOT be written to disk (verify file still shows PLACEHOLDER) -** TODO [#C] Implement flycheck modeline customization :feature: +** DONE [#C] Implement flycheck modeline customization :feature: +CLOSED: [2026-05-16 Sat] + +Spec: [[file:docs/design/flycheck-modeline-customization.org][docs/design/flycheck-modeline-customization.org]] (Option 4 / hybrid). + +=modules/flycheck-config.el= got two new =:custom= lines: +=flycheck-mode-line-prefix= → "🐛", =flycheck-mode-success-indicator= → +" ✓". =flycheck-mode-line-color= stays default-t so counts pick up +=error= / =warning= faces automatically. -Spec: [[file:docs/design/flycheck-modeline-customization.org][docs/design/flycheck-modeline-customization.org]] +=modules/modeline-config.el= got one new =(:eval ...)= form in +=mode-line-format=, placed between the recording indicator and +=cj/modeline-vc-branch=. Two guards: =(mode-line-window-selected-p)= +gates to the active window; =(bound-and-true-p flycheck-mode)= prevents +the call from firing in buffers where flycheck hasn't loaded. -Custom modeline (=modules/modeline-config.el=) omits =minor-mode-alist=, -so flycheck's error/warning lighter is invisible. Fix is a two-line -=:custom= block in =flycheck-config.el= (prefix + success indicator) plus -one guarded =(:eval ...)= form in =mode-line-format=. See spec for the -active-window-gating decision, risky-local-variable note, emoji -candidates, and the manual verification walk. +=tests/test-modeline-config-flycheck-segment.el= -- 3 smoke tests +asserting the segment is present and both guards are in place. The +existing modeline tests stay green. ** TODO [#C] Migrate from Company to Corfu (with prescient integration) :feature: -- cgit v1.2.3