From dd51bdefb6fed6b89d34d8b195f4cc55c01a055f Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 21 Oct 2024 12:36:04 +0200 Subject: emacs: Improve modeline major-mode name generation --- .config/emacs/modules/mm-modeline.el | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.config/emacs/modules/mm-modeline.el b/.config/emacs/modules/mm-modeline.el index a3545cc..ce28d69 100644 --- a/.config/emacs/modules/mm-modeline.el +++ b/.config/emacs/modules/mm-modeline.el @@ -48,22 +48,31 @@ '("css" "csv" "gsp" "html" "json" "mhtml" "scss" "toml" "tsv") "TODO") +(defconst mm-modeline-remap-alist + '(("Js" . "JavaScript") + ("Ts Mode" . "Tree-Sitter Mode") + ("Gmake" . "GMake") + ("Imake" . "IMake") + ("Bsdmake" . "BSD Make")) + "TODO") + (mm-modeline--define-component mm-modeline-major-mode-name (propertize - (let ((string - (thread-last - major-mode - (symbol-name) - (capitalize) - (string-replace "-" " ") - ;; TODO: Make a remap alist - (replace-regexp-in-string "\\" "JavaScript") - (string-replace "Ts Mode" "Tree-Sitter Mode"))) - (case-fold-search t)) + (let ((string (thread-last + major-mode + (symbol-name) + (capitalize) + (string-replace "-" " "))) + (case-fold-search nil)) ;; TODO: Do I need ‘save-match-data’ (save-match-data - (if (string-match - (concat "\\<" (regexp-opt mm-modeline-mode-acronyms) "\\>") string) + (dolist (pair mm-modeline-remap-alist) + (setq string + (replace-regexp-in-string + (format "\\<%s\\>" (regexp-quote (car pair))) + (cdr pair) string))) + (setq case-fold-search t) + (if (string-match (regexp-opt mm-modeline-mode-acronyms 'words) string) (concat (substring string 0 (match-beginning 0)) (upcase (substring string (match-beginning 0) (match-end 0))) -- cgit v1.2.3