[求助] 自己 customize 了一下 mode line format 有点错误不知道怎么改

闲得没事,去修改了下 mode-line-format

我的mode line 格式结构

  1. modified
  2. buffer name
  3. position
  4. input method
  5. 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)
	       )
	      )

运行的时候有个问题
2021-10-23 01-31-20 的屏幕截图
不管 buffer 是否修改,显示的状态都是 已修改

不知道错误在那里,会不会是我定义的函数返回类型不对,需要 (:eval ..) 这样的 ?


另外还有一些功能没有能力实现

  1. modeline 中显示 lsp
  2. modeline 中显示 flycheck

你这个是调整颜色吗,buffer修改了是红色,未修改是其它颜色;

修改mode-line要注意可能是本来已有的功能被自己改没了(显示lsp,显示flycheck),然后又去想怎么把被自己改没了的功能又改回来,我原来就把git状态的显示改没了,还来论坛 发贴问怎么改回来

这里写错了,初始化的时候就把 list 内容固定了,以后不再改变。

那具体的解决方法是?

(setq-default mode-line-format 
              '((:eval (concat
                        (chini/modified-modeline-format)
                        (chini/buffername-modeline-format)
                        (chini/position-modeline-format)
                        (chini/majormode-modeline-format)
                        (chini/inputmethod-modeline-format)))))