diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 22:04:33 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-16 22:04:33 +0200 |
commit | 0ee7fa9c382ae30295f0b8d88457f7856c7ff800 (patch) | |
tree | 6b5a0cf01fa0bfa4d01b0134b268f5d993055c0b /.config/emacs/modules/mm-modeline.el | |
parent | d452ae1347b3711bc0a7ac80cfa2c37d9d63836e (diff) |
emacs: Overhaul configuration completely
Diffstat (limited to '.config/emacs/modules/mm-modeline.el')
-rw-r--r-- | .config/emacs/modules/mm-modeline.el | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/.config/emacs/modules/mm-modeline.el b/.config/emacs/modules/mm-modeline.el new file mode 100644 index 0000000..cd9af3e --- /dev/null +++ b/.config/emacs/modules/mm-modeline.el @@ -0,0 +1,115 @@ +;;; mm-modeline.el --- Pluggable modeline components -*- lexical-binding: t; -*- + +(defmacro mm-modeline--define-component (name &rest forms) + (declare (indent 1)) + `(progn + (defvar-local ,name '(:eval (or ,(macroexp-progn forms) ""))) + (put ',name 'risky-local-variable t))) + + +;;; Faces + +(defface mm-modeline-narrow-face + '((t :foreground "#C5C8C6" ; From ‘mango-theme’ + :background "dark red" + :box "dark red" + :weight bold)) + "Face for the `mm-modeline-narrow' modeline component.") + + +;;; Support Icons + +(use-package all-the-icons + :ensure t + :init + (defvar mm-all-the-icons-cookie + (expand-file-name ".all-the-icons-installed-p" mm-cache-directory)) + (unless (file-exists-p mm-all-the-icons-cookie) + (all-the-icons-install-fonts) + (make-empty-file mm-all-the-icons-cookie :parents)) + (set-char-table-range char-width-table #xE907 2)) + + +;;; Modeline Components + +(mm-modeline--define-component mm-modeline-readonly + (when buffer-read-only + (propertize " READONLY" 'face 'bold))) + +(mm-modeline--define-component mm-modeline-buffer-name + (propertize "%b" 'face 'font-lock-constant-face)) + +(mm-modeline--define-component mm-modeline-buffer-modified + (when (and (buffer-modified-p) + (buffer-file-name)) + (propertize " (modified)" 'face 'shadow))) + +(mm-modeline--define-component mm-modeline-major-mode-name + (propertize + (thread-last + major-mode + (symbol-name) + (capitalize) + (string-replace "-" " ") + (string-replace "Ts Mode" "Tree-Sitter Mode") + ;; Casing doesn’t work for abbreviations, so fix it manually + (replace-regexp-in-string "\\<\\(M\\)?html\\>" "\\1HTML") + (replace-regexp-in-string "\\<\\(S\\)?css\\>" "\\1CSS") + (replace-regexp-in-string "\\<toml\\>" "TOML") + (replace-regexp-in-string "\\<gsp\\>" "GSP")) + 'face 'bold)) + +(mm-modeline--define-component mm-modeline-major-mode-symbol + (propertize + (cond + ((derived-mode-p 'prog-mode) "λ ") + ((derived-mode-p '(text-mode conf-mode)) "§ ") + ((derived-mode-p 'comint-mode) ">_ ") + (t "")) + 'face 'shadow)) + +(mm-modeline--define-component mm-modeline-narrow + (when (buffer-narrowed-p) + (propertize + " Narrow " + 'face 'mm-modeline-narrow-face))) + +(mm-modeline--define-component mm-modeline-git-branch + (when-let ((branch (car (and (featurep 'vc-git) + (vc-git-branches))))) + (concat + (propertize "\uE907" 'display '(raise 0)) + " " + (propertize branch 'face 'font-lock-constant-face) + " │ "))) + + +;;; Padding Between Left and Right + +(mm-modeline--define-component mm-modeline-left-right-padding + (let ((length (string-width (format-mode-line mm-modeline-right)))) + (propertize " " 'display `(space :align-to (- right ,length))))) + + +;;; Configure Modeline + +(setopt mode-line-format-right-align 'right-margin) + +(setq + mm-modeline-left (list mm-modeline-narrow + mm-modeline-readonly + " " + mm-modeline-buffer-name + mm-modeline-buffer-modified + " │ " + mm-modeline-major-mode-symbol + mm-modeline-major-mode-name + mm-modeline-left-right-padding + mode-line-end-spaces) + mm-modeline-right (list mm-modeline-git-branch + "%l:%c ")) + +(setq-default + mode-line-format + (list mm-modeline-left mm-modeline-left-right-padding mm-modeline-right)) +(provide 'mm-modeline) |