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 (cdr (assoc major-mode
(seq-find (lambda (var) (and var (boundp var))) mood-line-segment-indentation-mode-offset-alist))))))
(cdr (assoc major-mode (propertize (concat (if indent-tabs-mode "TAB" "SPC")
mood-line-segment-indentation-mode-offset-alist)) (mood-line--get-glyph :count-separator)
nil))) (if mood-line-segment-indentation-always-show-offset
;; If we don't know the indent offset variable of this major mode, (format "%s:%d"
;; display a "-". (or mode-offset "?")
(if lookup-var tab-width)
;; Some major modes, for example lisp-mode, works better when (number-to-string (if indent-tabs-mode
;; lisp-indent-offset is nil, we use "-" for nil, too. tab-width
(if (not (null (symbol-value lookup-var))) (or mode-offset tab-width))))
(format "%d" (symbol-value lookup-var)) " ")
"-") 'face 'mood-line-unimportant)))
"-"))
tab-width))
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
;; ;;