闲得没事,去修改了下 mode-line-format
,
- 参考
simple-modeline
的配置 - 参考 手动美化 mode-line 第二季
我的mode line 格式结构
- modified
- buffer name
- position
- input method
- major mode 配置代码
(defun chini/make-mouse-map (mouse function)
(let ((map (make-sparse-keymap)))
(define-key map (vector 'mode-line mouse) function)
map))
(defun chini/modified-modeline-format ()
"Displays a color-coded buffer modification/read-only indicator in the mode-line."
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
(let* ((read-only (and buffer-read-only (buffer-file-name)))
(modified (buffer-modified-p)))
(propertize
(if read-only " " (if modified " ●" " ○"))
'face 'font-lock-keyword-face
'help-echo (format
"Buffer is %s and %smodified\nmouse-1: Toggle read-only status."
(if read-only "read-only" "writable")
(if modified "" "not "))
'local-map (purecopy (chini/make-mouse-map
'mouse-1
(lambda (event)
(interactive "e")
(with-selected-window (posn-window (event-start event))
(read-only-mode 'toggle)))))
'mouse-face 'mode-line-highlight))))
(defun chini/buffername-modeline-format ()
"Displays the name of the current buffer in the mode-line."
(propertize " %b" 'face 'font-lock-keyword-face))
(defun chini/position-modeline-format ()
"Displays the current cursor position in the mode-line."
`((line-number-mode
((column-number-mode
(column-number-indicator-zero-based
(8 " %l:%c")
(8 " %l:%C"))
(5 " L%l")))
((column-number-mode
(column-number-indicator-zero-based
(5 " C%c")
(5 " C%C")))))
,(if (region-active-p)
(propertize (format "+%s"
(apply #'+ (mapcar
(lambda (pos)
(- (cdr pos)
(car pos)))
(region-bounds))))
'font-lock-face 'font-lock-variable-name-face))))
(defun chini/inputmethod-modeline-format ()
"Displays the input-method of the buffer in the mode-line."
`(""
(current-input-method
(:propertize (" " current-input-method-title)
help-echo (format
"Current input method: %s\nmouse-1: Describe current input method"
current-input-method)
mouse-face 'mode-line-highlight))))
(defun chini/majormode-modeline-format ()
"Displays the current major mode in the mode-line."
(propertize
(concat " "
(or (and (boundp 'delighted-modes)
(cadr (assq major-mode delighted-modes)))
(format-mode-line mode-name)))
'face 'font-lock-string-face))
设置 mode-line-format
(setq-default mode-line-format
(list
(chini/modified-modeline-format)
(chini/buffername-modeline-format)
(chini/position-modeline-format)
(chini/majormode-modeline-format)
(chini/inputmethod-modeline-format)
)
)
运行的时候有个问题
不管 buffer
是否修改,显示的状态都是 已修改
不知道错误在那里,会不会是我定义的函数返回类型不对,需要 (:eval ..)
这样的 ?
另外还有一些功能没有能力实现
- 在
modeline
中显示lsp
- 在
modeline
中显示flycheck