手动美化mode-line

因为种种原因没有使用 spaceline,但是 mode-line 默认的样式实在是不好看,尤其是窗口太小时显示不全,自己美化了下 mode-line,先放效果图

(setq evil-normal-state-tag   (propertize "[Normal]" 'face '((:background "green" :foreground "black")))
      evil-emacs-state-tag    (propertize "[Emacs]" 'face '((:background "orange" :foreground "black")))
      evil-insert-state-tag   (propertize "[Insert]" 'face '((:background "red") :foreground "white"))
      evil-motion-state-tag   (propertize "[Motion]" 'face '((:background "blue") :foreground "white"))
      evil-visual-state-tag   (propertize "[Visual]" 'face '((:background "grey80" :foreground "black")))
      evil-operator-state-tag (propertize "[Operator]" 'face '((:background "purple"))))

;; 简化 major-mode 的名字,替换表中没有的显示原名

(defun codefalling//simplify-major-mode-name ()
  "Return simplifyed major mode name"
  (let* ((major-name (format-mode-line "%m"))
         (replace-table '(Emacs-Lisp "𝝀"
                                     Spacemacs\ buffer "𝓢"
                                     Python "𝝅"
                                     Shell ">"
                                     Makrdown "𝓜"
                                     GFM "𝓜"
                                     Org "𝒪"
                                     Text "𝓣"
                                     Fundamental "ℱ"
                                     ))
         (replace-name (plist-get replace-table (intern major-name))))
    (if replace-name replace-name major-name
        )))

(setq-default
 mode-line-format
 (list
  ;; the buffer name; the file name as a tool tip
  " "
  '(:eval (propertize "%b " 'face 'font-lock-keyword-face
                      'help-echo (buffer-file-name)))

  ;; line and column
  "(" ;; '%02' to set to 2 chars at least; prevents flickering
  (propertize "%02l" 'face 'font-lock-type-face) ","
  (propertize "%02c" 'face 'font-lock-type-face)
  ") "

  ;; relative position, size of file
  "["
  (propertize "%p" 'face 'font-lock-constant-face) ;; % above top
  "/"
  (propertize "%I" 'face 'font-lock-constant-face) ;; size
  "] "

  ;; the current major mode for the buffer.
  "["

  '(:eval (propertize (codefalling//simplify-major-mode-name) 'face 'font-lock-string-face
                      'help-echo buffer-file-coding-system))
  "] "


  "[" ;; insert vs overwrite mode, input-method in a tooltip
  '(:eval (propertize (if overwrite-mode "Ovr" "Ins")
                      'face 'font-lock-preprocessor-face
                      'help-echo (concat "Buffer is in "
                                         (if overwrite-mode "overwrite" "insert") " mode")))

  ;; was this buffer modified since the last save?
  '(:eval (when (buffer-modified-p)
            (concat ","  (propertize "Mod"
                                     'face 'font-lock-warning-face
                                     'help-echo "Buffer has been modified"))))

  ;; is this buffer read-only?
  '(:eval (when buffer-read-only
            (concat ","  (propertize "RO"
                                     'face 'font-lock-type-face
                                     'help-echo "Buffer is read-only"))))
  "] "

  ;; evil state
  '(:eval (evil-generate-mode-line-tag evil-state))

  " "
  ;; add the time, with the date and the emacs uptime in the tooltip
  '(:eval (propertize (format-time-string "%H:%M")
                      'help-echo
                      (concat (format-time-string "%c; ")
                              (emacs-uptime "Uptime:%hh"))))
  " --"
  ;; i don't want to see minor-modes; but if you want, uncomment this:
  ;; minor-mode-alist  ;; list of minor modes
  "%-" ;; fill with '-'
  ))

有什么问题或者要补充的可以去 Mode line · CodeFalling/wiki Wiki

参考自 emacs-fu: customizing the mode-line

9 个赞

感谢分享。

现在用 Spacemacs 自带的 mode-line,感觉还不错。

太棒了!正好需要。我在 Win10上不得不去掉 Spaceline ,不然太卡了

用了这个代码以后 我的 nyan-mode 那只猫没有了 请问怎么可以兼容一下

好的好的,看到你的nyan nyan了01

我用了这段代码 nyan-mode久失效了

你好,请问mode line的高度如何设置呢?在不改变字体大小的情况下

:height这个face attribute吧,然后mode line高度会按最高的那个字符来。不知道是不是符合你的需求。

(propertize "❌" 'face '(:family "Apple Color Emoji" :height 0.7))

...

(all-the-icons-icon-for-mode major-mode :height 0.8 :v-adjust 0)

你好,是这样的,我modeline中文字体和英文字体高度不一样,导致两个窗口并排时,modeline高度不一致

在末尾加一个高度与中文字等同的空格,这样纯英文的mode line就和带中文的等高了

3 个赞

在保证性能的情况下,modeline 进化成这样了。关闭 icon 显示会更快。

1 个赞

请问开头那个“1”和“98k“: 这个1是指什么,文件大小”98k“怎么打开这个功能?谢谢

我默认的doom-modeline是这样子的:

那个1是window number,打开显示文件大小的话:

(size-indication-mode t)
1 个赞

谢谢!那 那个window number又是什么minor mode提供的呢,如果也一样是别的mode支持?我默认的是没有。还是doom-modeline某个设置?github主页看了一遍也没发现。谢啦!

window-numbering?(我google时看到一个选择) 看起来怪怪的不像啊

应该是这个:

1 个赞

上面有人回复了,文件大小是size-indication-mode.

Window Number支持三个包

感谢感谢!又发现了一些很不错的包~