4

I work with a lot of tabular data files and use stripe-buffer.el make them easier to read. But I also work with more than one, so I'd like to make it easier to distinguish among them as well and want to change the stripe colors per buffer.

I can change the face globally using:

(modify-face 'stripe-highlight "black" "#cce7ff")

Is there a way to do this locally to a single buffer?

10

As noted by @phils in the comment below, the Emacs manual suggests not modifying the face-remapping-alist directly due to possible unintended side effects: . . .to avoid trampling on remappings applied elsewhere. Thus, (setq-local face-remapping-alist '((stripe-highlight (:background "white" :foreground "black")))) is not considered to be the preferred method. Instead, the Emacs manual suggests using a function such as face-remap-add-relative:

(face-remap-add-relative 'stripe-highlight '(:foreground "black" :background "yellow"))

Here is a link to additional Emacs documentation on this issue: http://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Remapping.html

  • Nice; the variable docstring even mentions the buffer-local scenario as a use-case for this. – phils Jan 11 '15 at 22:40
  • C-h i g (elisp) Face Remapping documents API functions intended for buffer-local modifications, and indicates that they are preferable to manipulating the alist directly. You'll be able to improve your answer that way. – phils Jan 11 '15 at 22:53
  • @phils -- thank you for suggesting the use of face-remap-add-relative as a means of modifying the face-remapping-alist. I have edited the answer accordingly. – lawlist Jan 11 '15 at 23:50
  • One more example: (face-remap-add-relative 'default '(:family "Arial")). – Adobe Jan 12 '15 at 10:15
  • 1
    @Hi-Angel -- remove the single quote in front of the word bold and try again. :) – lawlist Sep 7 '17 at 5:46
1

(edit: lawlist has a much better answer, but I'll leave this answer in case the information is useful to anyone.)

Face specs are properties in the face symbol's plist -- e.g. (get 'stripe-highlight 'face-defface-spec) -- and I don't believe the notion of buffer-local symbol properties exists. That's a special feature of the value slot (i.e. values of variables).

What some libraries do is assign their faces to variables, and then use the variable everywhere that the face is needed.

You can then create buffer-local values for those variables, which has the same effect that you're looking for.

This requires the code using the face to have been written that way, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.