2012-04-20 20 views
5

Tôi thường để hl-line lấy bóng tối hơn một chút so với nền hiện tại. Điều này hoạt động tốt trong việc chỉnh sửa bộ đệm. Tuy nhiên, trong một số bộ đệm, chẳng hạn như Org chương trình nghị sự và bộ đệm nhóm Gnus, tôi muốn sử dụng một màu sắc spiffy hơn (thay cho con trỏ).Emacs hl-line: đổi màu cục bộ

Để cụ thể tôi muốn thay đổi màu sắc của hl-line trong gnus-hl-line mà không ảnh hưởng đến màu sắc của hl-line trong bộ đệm khác.

(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)) 

Cảm ơn,

giải pháp cuối cùng sử dụng đề nghị Phil. Nó sử dụng một dòng hl trung lập hầu hết thời gian, nhưng đôi khi một dòng hl đậm được đánh giá cao, ví dụ: trong Gnus và Org chương trình nghị sự

;; 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

Bạn có thể giải thích vị trí trong mã có thể đặt cường độ * và * màu cho tổ chức chương trình, nhóm gnus-summary và gnus tương ứng không? Cảm ơn! –

Trả lời

4

hl-line-face là một biến chứa khuôn mặt để sử dụng cho hl-line-mode, vì vậy chúng tôi có thể làm cho rằng biến đệm cục bộ ở các chế độ này, và gán cho nó một khuôn mặt tùy chỉnh mới.

Bạn có thể tạo một khuôn mặt mới như thế này:

(defface gnus-hl-line 
    '((t :inherit hl-line)) 
    "Face for highlighting the current line with `gnus-hl-line'." 
    :group 'hl-line) 

và tùy chỉnh nó với Mxcustomize-faceRETgnus-hl-lineRET

Sau đó thêm này trong chức năng gnus-hl-line của bạn (trước khi gọi hl-line-mode có vẻ hợp lý nhất).

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

Thật vậy. Cảm ơn! – Rasmus

Các vấn đề liên quan