emacs 29.1 中,如何获取 mode-line 上显示的 elisp (.el)的 major-name ?

当前 buffer 为 .el 文件,mode-line 上显示的内容为 ELisp/d,但执行

(format-mode-line "%m")

后返回了空字串 “”

如果想用 nerd-font 替换 mode-line 上显示的 major-mode name 字符,应该如何获取到 ELisp/d ?

目前使用了以下方式,其它格式的文件都能替换成功,唯独 elisp 没成功!请问有没有做过类似设置的道友,知道正确的方法?

(defun blove/re-major-mode-name ()
  "Return simplifyed major mode name"
  (let* ((major-name (format-mode-line "%m"))
         (replace-table '(
                          Python "  "
						  C++//l " ﭱ  "
						  C/*l "  "
                          Org "   "
                          Fundamental "  "
						  Messages "  "
						  Debugger "   "
                          Shell-script "  "
						  ELisp/d " չ-Lisp "
						  Lisp\ Interaction "  "
                          ;; Makrdown "  "
                          Text "  "
                          ))
         (replace-name (plist-get replace-table (intern major-name))))
    (if replace-name
		replace-name
	  major-name))
  )
;;;
;;; rep
;;;
(defun blove/mode-line-major-mode ()
  "Displays the current major mode in the mode-line."
  (propertize 
   (concat " ["
		   (or (and (boundp 'delighted-modes)
					(cadr (assq major-mode delighted-modes)))
			   (blove/re-major-mode-name)
			   (format-mode-line mode-name)
			   )
		   "]")
   'face '(:bold t))
  )

直接用变量 mode-name

1 个赞

好的👌🏻感谢!