2012-04-20 58 views
5

我通常會讓hl-line採用當前背景稍暗的陰影。這在編輯緩衝區很好。但是,在一些緩衝區中,例如Org議程和Gnus組緩衝區,我想使用更漂亮的顏色(代替光標)。Emacs hl-line:在本地更改顏色

具體而言,我想更改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)) 

感謝,

用菲爾的建議,最終的解決方案。它大部分時間使用中立的hl線,但有時一個粗體的hl線是可觀的,例如,在和Gnus的議程組織

;; 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) 
+0

請問您可以在代碼中分別介紹org-agenda,gnus-summary和gnus-group的強度*和*顏色。謝謝! – 2016-06-28 19:28:47

回答

4

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) 

定製的Mxcustomize-faceRETgnus-hl-lineRET

然後在你的gnus-hl-line功能添加這個(調用hl-line-mode前看起來最明智)。

(set (make-local-variable 'hl-line-face) 'gnus-hl-line) 
+0

確實。謝謝! – Rasmus 2012-04-20 12:12:19