elispflycheck

Guarantee that flycheck-mode appears in first position in the mode line


When coding in not too wide buffer flycheck errors tally that should be visible in line-mode gets truncated. How do I guarantee that flycheck mode tally comes first in the order of major/minor modes in line-mode?


Solution

  • The minor modes are displayed in the order of minor-mode-alist. By default this simply reflects the load order (hence the kind-of-workaround you noted, but noting that the workaround would fail once additional minor modes were loaded).

    Manipulating the list after libraries are loaded lets you maintain a desired display order on an ongoing basis.

    (defun my-promote-flycheck (&optional _file)
      "Give `flycheck-mode' priority position in `minor-mode-alist'.
    
    Called via `after-load-functions', as well as `after-init-hook'."
      (unless (eq (caar minor-mode-alist) 'flycheck-mode)
        (let ((found (assq 'flycheck-mode minor-mode-alist)))
          (when found
            (assq-delete-all 'flycheck-mode minor-mode-alist)
            (push found minor-mode-alist)))))
    
    (add-hook 'after-load-functions 'my-promote-flycheck)
    (add-hook 'after-init-hook 'my-promote-flycheck)