3

I am using tex-mode in Aquamacs and would like to temporarily change the font for the current buffer. What is the way to do it? I tried:

(set-face-attribute "American Typewriter" nil :height 150)

which gives the error:

eval: Wrong type argument: symbolp, "American Typewriter"

even though "American Typewriter" is in (font-family-list). When I try:

(set-face-attribute "American Typewriter" nil :height 150)

it only affects the font of the minibuffer, not the current buffer I have open.

3 Answers3

3

Try buffer-face-set, which accepts either a face name like (buffer-face-set "error") or a property list of face attributes and values like (buffer-face-set :weight 'bold :height 150).

I think your specific example would be something like (buffer-face-set :font-family "American Typewriter" :height 150).

You can M-: and at the "Eval:" prompt enter one of those Emacs Lisp expressions. (When I tried, it set the font in the buffer from which I issued the command, as you want -- not the minibuffer.)


buffer-face-set is also usable as interactive command: M-x buffer-face-set. The prompt only seems to accept a face name -- not a property list. So, maybe you could use defface in your Emacs init file to define a face with the desired properties, to be able to enter that face name.

Greg Hendershott
  • 1,483
  • 12
  • 17
3

With respect to what you tried using set-face-attribute:

The error message tells you that the first argument needs to be a symbol. At that point you should use C-h f set-face-attribute, which tells you that the first argument needs to be a face.

Here's an example of its use.

(set-face-attribute 'default nil ':font "American Typewriter" ':height 150)

That changes the default font (the font for face default) for all existing and future frames (second arg nil), which is not what you want. set-face-attribute is face-specific, not buffer-specific. The answer for what you want is to use functionbuffer-face-set`, as others have indicated.

Drew
  • 75,699
  • 9
  • 109
  • 225
2

I use it as buffer local by

# Local Variables:
# eval: (setq buffer-face-mode-face '(:family "American typewriter" :height 150))
# eval: (buffer-face-mode t)
# End:

Change :height to what you want.