我想在任何模式下,将数字的颜色与文本字符的颜色不同。我该如何修改 .emacs 文件以实现此目的?我希望我的数字始终显示为粉红色。
Gvim 似乎已经内置了此功能。
答案1
用法——激活或停用本地和: M-x smilingbuddha-mode
启用smilingbuddha-mode
全球,取消注释(global-smilingbuddha-mode)
并重新启动;或者,输入M-x global-smilingbuddha-mode
(该命令将一直有效,直到您重新启动)。
请随意修改正则表达式以满足您的个人需要。
(define-minor-mode smilingbuddha-mode
"Minor mode for highlighting numbers."
:group 'smilingbuddha
:lighter " :)"
(cond
(smilingbuddha-mode
(when (not (or font-lock-mode global-font-lock-mode))
(font-lock-mode 1))
(font-lock-add-keywords nil
(list (list "\\([0-9]+\\)" '(0 'smilingbuddha-pink-face t)) ))
(message "Turned ON `smilingbuddha-mode`."))
((not smilingbuddha-mode)
(font-lock-remove-keywords nil
(list (list "\\([0-9]+\\)" '(0 'smilingbuddha-pink-face t)) ))
(font-lock-fontify-buffer)
(message "Turned OFF `smilingbuddha-mode`."))))
(defgroup smilingbuddha nil
"Highlight numbers."
:version "0.1"
:group 'smilingbuddha)
(defface smilingbuddha-pink-face
'((t (:foreground "black" :background "pink")))
"Face for `smilingbuddha-pink-face`."
:group 'smilingbuddha)
(defun turn-on-smilingbuddha-mode ()
(interactive)
(smilingbuddha-mode 1))
(defun turn-off-smilingbuddha-mode ()
(interactive)
(smilingbuddha-mode -1))
(define-globalized-minor-mode global-smilingbuddha-mode
smilingbuddha-mode turn-on-smilingbuddha-mode)
;; (global-smilingbuddha-mode)