How to set a buffer locally face attribute for a particular buffer?
Asked Answered
B

2

9

I want to change the face attribute in Org-Agenda buffer only. So I need to change Org-Agenda face attribute buffer locally.

Here is my code: (which is globally)

(defun my-org-agenda-hl-line ()
  (hl-line-mode)
  (set-face-attribute 'hl-line nil
                  :box '(:color "deep pink" :line-width 2))
)
(add-hook 'org-agenda-mode-hook 'my-org-agenda-hl-line)

Please to help me make this buffer locally. Thanks

Barbey answered 13/7, 2013 at 9:48 Comment(0)
C
13

Here is what you need to do:

;; First create new face which is a copy of hl-line-face
(copy-face 'hl-line 'hl-line-agenda-face)

;; Change what you want in this new face 
(set-face-attribute 'hl-line-agenda-face nil
                    :box '(:color "deep pink" :line-width 2))

;; The function to use the new face
(defun my-org-agenda-hl-line ()
  (set (make-local-variable 'hl-line-face) ; This is how to make it local
       'hl-line-agenda-face)
    (hl-line-mode))

;; Finally, the hook
(add-hook 'org-agenda-mode-hook 'my-org-agenda-hl-line)
Carpospore answered 13/7, 2013 at 14:1 Comment(1)
Since Emacs 23.1, the other answer by Wenpin CHOU is the recommended way, namely use face-remap-add-relative. // This is a nice answer that I should upvote. Once CHOU's answer gets enough votes, I'd upvote this one, too. ;-pRhoden
S
4

try face-remap-add-relative.

(add-hook 'org-agenda-mode-hook
          (lambda ()
            (hl-line-mode)
            (face-remap-add-relative 'hl-line :box '(:color "deep pink" :line-width 2))))

also, see How to modify-face for a specific buffer

Stambaugh answered 16/7, 2020 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.