在我的.emacs
中,我有以下代码突出显示标签和尾随空格
(add-hook 'font-lock-mode-hook
(lambda ()
(setq font-lock-keywords
(append font-lock-keywords
'(("\t+" (0 'custom-tab-face t))
("[ \t]+$" (0 'custom-tab-face t)))))))
(custom-set-faces
'(custom-tab-face ((((class color)) (:background "#a0a0a0"))) t))
以上是全球性的设定。
我试图弄清楚如何在一个使用特定编程模式(golang)的缓冲区中禁用突出显示(我使其变白)。我尝试了下面的代码,但它当然会为所有缓冲区禁用它:
(add-hook 'go-mode-hook
(lambda ()
(custom-set-faces
'(custom-tab-face ((((class color)) (:background "#ffffff"))) t))))
请帮忙,我不太了解emacs。
答案 0 :(得分:1)
根据原始海报的要求,这是一个使用display-table
的示例,它在大缓冲区中运行良好,并且不会导致通常使用font-lock的速度减慢。我已将该功能附加到text-mode-hook
- 可以更改主模式挂钩以满足原始海报的需要。
(defgroup example nil
"Faces for highlighting display table entries."
:group 'example)
(defface ws-formfeed-face
'((t (:background "purple" :foreground "yellow" :weight bold)))
"Face for `ws-formfeed-face`."
:group 'example)
(defface ws-newline-face
'((t (:foreground "blue")))
"Face for `ws-newline-face`."
:group 'example)
(defface ws-space-face
'((t (:foreground "DarkRed")))
"Face for `ws-space-face`."
:group 'example)
(defface ws-tab-face
'((t (:foreground "cyan")))
"Face for `ws-tab-face`."
:group 'example)
(defun my-display-table-function ()
(let* (
(my-glyph-formfeed (make-glyph-code ?\U0001D4D5 'ws-formfeed-face))
(my-glyph-pilcrow (make-glyph-code ?\u00B6 'ws-newline-face))
(my-glyph-space (make-glyph-code ?\u00B7 'ws-space-face))
(my-glyph-tab
(cond
((eq system-type 'darwin)
(make-glyph-code ?\u203A 'ws-tab-face))
((eq system-type 'windows-nt)
(make-glyph-code ?\u00BB 'ws-tab-face)))) )
(when (not buffer-display-table)
(setq buffer-display-table (make-display-table)))
(aset buffer-display-table ?\n `[,my-glyph-pilcrow ?\n])
(aset buffer-display-table ?\014 `[,my-glyph-formfeed])
(aset buffer-display-table ?\ `[,my-glyph-space])
(aset buffer-display-table ?\t `[,my-glyph-tab ?\t])))
(add-hook 'text-mode-hook 'my-display-table-function)
(defun my-tab-function ()
(setq tab-stop-list (number-sequence 8 200 8))
(setq tab-width 8)
(setq indent-line-function 'insert-tab))
(add-hook 'text-mode-hook 'my-tab-function)