Is there a way to prevent font-locking from changing the font family (and change color only)?
Asked Answered
D

1

7

Admittedly, this is something of a first world problem, but I'm sort of picky about the appearance of the display, and I find it really annoying when some mode sets a new font size, family, bold/italic, etc. What I'd like to do is put (set-frame-font "Menlo-10") near the top of my .emacs, and then force emacs to never change any aspect from that default font except for color.

I can sort of get the effect I want by doing something like this:

(mapc (lambda (face) 
    (set-face-attribute face nil
                        :family "Menlo"
                        ;; something like (cdr (assoc 'font (frame-parameters)) would be better
                        ;; for the :family, but it didn't immediately work
                        :width 'normal
                        :height 1.0
                        :weight 'normal 
                        :underline nil
                        :slant 'normal))
    (remove 'default (face-list)))

but that only works after I've loaded a new buffer that has created font-lock faces to be changed, and it's a dreadful hack regardless. I suspect there just isn't really in facility in font-locking for ignoring some parts of what a mode requests, but I thought I'd ask.

Also, AUCTeX is by far the worst offender here, so if there's alternately just an AUCTeX setting somewhere to prevent it from requesting changes in family, size, etc. in the first place, that would at least make the problem less annoying.

I'm currently using a recent Emacs 24 pulled from HEAD.

Den answered 22/10, 2011 at 15:24 Comment(2)
thats odd. my custom font set to deja-vu. atleast font family never got changed by any mode including auctex with emacs 24.Lynsey
Hmm. Maybe I should dig through 15 years of accrued elisp cruft. To be clear, the default font in AUCTeX stays the same, but if I have \section{Foo}, the "Foo" part is typeset in what looks like Helvetica at about 18 point.Den
D
5

Running customize-face with your cursor on the face you are interested in will allow you to see how that face is defined (and change it). Doing this on the section title gives me font-latex-sectioning-1-face. This inherits from font-latex-sectioning-2-face etc. down to font-latex-sectioning-5-face which in turn inherits form variable-pitch (which is what changes the font family). The documentation also mentions that it's best to change the base face font-latex-sectioning-5-face, or the variable font-latex-fontify-sectioning. You can set this last to 'color which will do what you want (I think). Alternately, you can customize font-latex-sectioning-5-face to not inherit from variable-pitch, or change variable-pitch to not be variable pitch.

Disarmament answered 23/10, 2011 at 12:18 Comment(1)
I think setting the right handful of top-level faces (e.g., variable-pitch) probably does what I want. I always hated the customize interface, but I should have thought of using it to look up the inheritance chain. The font-latex-fontify-sectioning tip works in AUCTeX (although, oddly, it uses a different color). Presumably there are several such settings controlling other things such as the smaller fonts used in superscripts and subscripts in math mode, but I haven't started looking around yet.Den

© 2022 - 2024 — McMap. All rights reserved.