diff options
| author | João Távora <joaotavora@gmail.com> | 2026-05-03 11:16:08 +0100 |
|---|---|---|
| committer | João Távora <joaotavora@gmail.com> | 2026-05-03 11:16:08 +0100 |
| commit | 04c50e32e8f32afd68242e4dc28da02e8a45e237 (patch) | |
| tree | ff953e4cf7a5d338b6c4225e17c5ebcdfaeffdcc | |
| parent | 495b5117521beb6192b95da959c36007bca5b6cb (diff) | |
Per #27: Add opinionated mode-line entry pointsexternals/breadcrumb
* breadcrumb.el (breadcrumb-opinionated-mlf): New defcustom.
(breadcrumb-opinionated-diminished-modes): New defcustom.
(bc--saved-mlf, bc--saved-lighters): New variables.
(bc--diminish): New function.
(breadcrumb-opinionated-mode): New global minor mode.
* README.md: Fix "is a global mode" grammar. Add "An opinionated
mode line" section.
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | breadcrumb.el | 71 |
2 files changed, 86 insertions, 2 deletions
@@ -9,7 +9,7 @@ Breadcrumbs are sequences of short strings indicating where you are in some big tree-like maze that is probably your code. Hopefully the screenshot above clears it up. -* `M-x breadcrumb-mode` is global mode. Will try to turn itself on +* `M-x breadcrumb-mode` is a global mode. Will try to turn itself on conservatively and only if there's a project. * `M-x breadcrumb-local-mode` is a buffer-local minor mode, if you @@ -38,11 +38,24 @@ and ```lisp (:eval (breadcrumb-project-crumbs)) -``` +``` in your settings of the `mode-line-format` or `header-line-format` variables. +## An opinionated mode line + +If you had trouble understanding the previous section and just want to +get breadcrumbs on the mode-line, you can call `M-x +breadcrumb-opinionated-mode`. Looks like this: + + + +Call it again to turn it off. Also, you probably want to check how +the variable `breadcrumb-opinionated-mlf` is built so you can +adjust/customize it. Or just steal ideas from it into your own +`mode-line-format` `header-line-format` customizations. + ## Tweaks The shape and size of each breadcrumb groups may be tweaked via diff --git a/breadcrumb.el b/breadcrumb.el index efde47f..f14e1a2 100644 --- a/breadcrumb.el +++ b/breadcrumb.el @@ -451,6 +451,77 @@ propertized crumbs." (push-mark) (bc--goto (selected-window) choice)))) + +;;;; Opinionated mode line +;; + +;;;###autoload +(defcustom breadcrumb-opinionated-mlf + '("%e" + mode-line-modified + (:eval (bc-project-crumbs)) + " " + (:propertize " " face default) + " " + (:eval (bc-imenu-crumbs)) + " " + mode-line-format-right-align + (vc-mode vc-mode) + " " + mode-line-modes + mode-line-misc-info + " %p% %l:%c" + (:eval (format-time-string " %H:%M"))) + "A `mode-line-format' with breadcrumb project and imenu crumbs. +Replaces `mode-line-buffer-identification' with the output of +`breadcrumb-project-crumbs' and `breadcrumb-imenu-crumbs'." + :type '(repeat sexp)) + +(defcustom bc-opinionated-diminished-modes + '(yas-minor-mode eldoc-mode company-mode whitespace-mode + which-key-mode) + "Minor modes whose lighters are hidden by `breadcrumb-opinionated-mode'." + :type '(repeat symbol)) + +(defvar bc--saved-mlf) +(defvar bc--saved-lighters nil) + +(defun bc--diminish (mode) + (when-let* ((cell (assq mode minor-mode-alist))) + (push (cons mode (cadr cell)) bc--saved-lighters) + (setcar (cdr cell) ""))) + +;;;###autoload +(define-minor-mode breadcrumb-opinionated-mode + "Global minor mode installing an opinionated breadcrumb mode line. +On activation, saves the current `mode-line-format' default and replaces +it with `breadcrumb-opinionated-mlf'." + :global t + (cond + (bc-opinionated-mode + (unless (boundp 'bc--saved-mlf) (setq bc--saved-mlf (default-value 'mode-line-format))) + (setq-default mode-line-format bc-opinionated-mlf) + (mapc #'bc--diminish bc-opinionated-diminished-modes) + (advice-add 'add-minor-mode :after + (lambda (toggle &rest _) + (when (memq toggle bc-opinionated-diminished-modes) + (bc--diminish toggle))) + '((name . bc--do-diminish-advice)))) + (t + (setq-default mode-line-format bc--saved-mlf) + (advice-remove 'add-minor-mode 'bc--do-diminish-advice) + (dolist (saved bc--saved-lighters) + (when-let* ((cell (assq (car saved) minor-mode-alist))) + (setcar (cdr cell) (cdr saved)))) + (setq bc--saved-lighters nil) + (makunbound 'bc--saved-mlf)))) + +(advice-add 'mode--line-format-right-align :filter-return + (lambda (r) + (when bc-opinionated-mode + (propertize r 'face 'default))) + '((name . bc-opinionated-mlf))) + (provide 'breadcrumb) ;;;###autoload (register-definition-prefixes "breadcrumb" '("breadcrumb-")) |
