我通常让hl-line采用稍暗的当前背景.这在编辑缓冲区时效果很好.但是,在某些缓冲区中,例如Org议程和Gnus组缓冲区,我想使用更漂亮的颜色(代替光标).
具体而言,我想改变gnus-hl-line 中hl-line的颜色而不影响其他缓冲区中hl-line的颜色.
(add-hook 'gnus-summary-mode-hook 'gnus-hl-line)
(add-hook 'gnus-group-mode-hook 'gnus-hl-line)
(defun gnus-hl-line ()
(hl-line-mode 1)
(set (make-local-variable 'line-move-visual) nil)
(setq cursor-type nil))
Run Code Online (Sandbox Code Playgroud)
谢谢,
使用Phil的建议的最终解决方案.它大部分时间使用中性线,但有时候大胆的线条很明显,例如在Gnus和Org议程中
;; From emacs-wiki:
(defun shade-color (intensity)
"print the #rgb color of the background, dimmed according to intensity"
(interactive "nIntensity of the shade : ")
(apply 'format "#%02x%02x%02x"
(mapcar (lambda (x)
(if (> (lsh x -8) intensity)
(- (lsh x -8) intensity)
0))
(color-values (cdr (assoc 'background-color (frame-parameters)))))))
;; Default hl
(global-hl-line-mode t)
(make-variable-buffer-local 'global-hl-line-mode)
(set-face-background hl-line-face (shade-color 08))
(defface hl-line-highlight-face
'((t :inherit highlight))
"Face for highlighting the current line with `hl-line-fancy-highlight'."
:group 'hl-line)
(defun hl-line-fancy-highlight ()
(set (make-local-variable 'hl-line-face) 'hl-line-highlight-face)
;; (set (make-local-variable 'line-move-visual) nil)
;; (set (make-local-variable 'cursor-type) nil)
(setq global-hl-line-mode nil)
(hl-line-mode))
(add-hook 'org-agenda-mode-hook 'hl-line-fancy-highlight)
(add-hook 'gnus-summary-mode-hook 'hl-line-fancy-highlight)
(add-hook 'gnus-group-mode-hook 'hl-line-fancy-highlight)
Run Code Online (Sandbox Code Playgroud)
hl-line-face是一个包含要用于 的人脸的变量hl-line-mode,因此我们可以在这些模式下将该变量设为缓冲区本地,并为其分配一个新的自定义人脸。
您可以像这样创建一个新面孔:
(defface gnus-hl-line
'((t :inherit hl-line))
"Face for highlighting the current line with `gnus-hl-line'."
:group 'hl-line)
Run Code Online (Sandbox Code Playgroud)
并定制它 M-x customize-face RET gnus-hl-line RET
然后将其添加到您的gnus-hl-line函数中(在调用hl-line-mode之前似乎是最明智的)。
(set (make-local-variable 'hl-line-face) 'gnus-hl-line)
Run Code Online (Sandbox Code Playgroud)