Tweak formatting of indentation segment

This commit is contained in:
Jessie Hildebrandt 2022-12-29 09:00:52 -05:00
parent cff8cc6032
commit 9233fdce74

View File

@ -29,6 +29,18 @@
;;; Code: ;;; Code:
;; -------------------------------------------------------------------------- ;;
;;
;; Byte-compiler declarations
;;
;; -------------------------------------------------------------------------- ;;
;; ---------------------------------- ;;
;; External function decls
;; ---------------------------------- ;;
(declare-function mood-line--get-glyph "mood-line" (glyph))
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
;; ;;
;; Custom definitions ;; Custom definitions
@ -39,6 +51,20 @@
;; Variable definitions ;; Variable definitions
;; ---------------------------------- ;; ;; ---------------------------------- ;;
(defcustom mood-line-segment-indentation-always-show-offset nil
"When non-nil, always show the indentation offset of the current mode.
Default behavior of the indentation segment is to display the indentation offset
of the current mode when `indent-tabs-mode' is non-nil and an offset value can
be found for the current mode. Otherwise, `tab-wdith' will be shown.
When `mood-line-segment-indentation-always-show-offset' is set to non-nil, the
indentation offset will always be shown alongside `tab-width'. If an offset
value cannot be found for the current mode, a \"?\" character will be displayed
alongside `tab-width'."
:group 'mood-line
:type 'boolean)
;; Assembled from `editorconfig-indentation-alist' and `doom-modeline-indent-alist': ;; Assembled from `editorconfig-indentation-alist' and `doom-modeline-indent-alist':
;; https://github.com/editorconfig/editorconfig-emacs/blob/b8043702f3d977db0e030c6c64ee4a810cad5f45/editorconfig.el#L175 ;; https://github.com/editorconfig/editorconfig-emacs/blob/b8043702f3d977db0e030c6c64ee4a810cad5f45/editorconfig.el#L175
;; https://github.com/seagle0128/doom-modeline/blob/fe9ee5a2a950f9ded10261a05a12adc577ae9e36/doom-modeline-core.el#L284 ;; https://github.com/seagle0128/doom-modeline/blob/fe9ee5a2a950f9ded10261a05a12adc577ae9e36/doom-modeline-core.el#L284
@ -164,23 +190,21 @@ order provided)."
(defun mood-line-segment-indentation--segment () (defun mood-line-segment-indentation--segment ()
"Display the indentation style of the current buffer." "Display the indentation style of the current buffer."
(format "%s %s %d " (let* ((mode-offset (symbol-value
(if indent-tabs-mode "TAB" "SPC") (seq-some #'identity
(let ((lookup-var
(seq-find (lambda (var) (and var (boundp var)))
(cdr (assoc major-mode (cdr (assoc major-mode
mood-line-segment-indentation-mode-offset-alist)) mood-line-segment-indentation-mode-offset-alist))))))
nil))) (propertize (concat (if indent-tabs-mode "TAB" "SPC")
;; If we don't know the indent offset variable of this major mode, (mood-line--get-glyph :count-separator)
;; display a "-". (if mood-line-segment-indentation-always-show-offset
(if lookup-var (format "%s:%d"
;; Some major modes, for example lisp-mode, works better when (or mode-offset "?")
;; lisp-indent-offset is nil, we use "-" for nil, too. tab-width)
(if (not (null (symbol-value lookup-var))) (number-to-string (if indent-tabs-mode
(format "%d" (symbol-value lookup-var)) tab-width
"-") (or mode-offset tab-width))))
"-")) " ")
tab-width)) 'face 'mood-line-unimportant)))
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
;; ;;