Function: set-frame-font
set-frame-font is an interactive and byte-compiled function defined in
frame.el.gz.
Signature
(set-frame-font FONT &optional KEEP-SIZE FRAMES INHIBIT-CUSTOMIZE)
Documentation
Set the default font to FONT.
When called interactively, prompt for the name of a font, and use that font on the selected frame. When called from Lisp, FONT should be a font name (a string), a font object, font entity, or font spec.
If KEEP-SIZE is nil, keep the number of frame lines and columns fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try to keep the current frame size fixed (in pixels) by adjusting the number of lines and columns.
If FRAMES is nil, apply the font to the selected frame only.
If FRAMES is non-nil, it should be a list of frames to act upon,
or t meaning all existing graphical frames.
Also, if FRAMES is non-nil, alter the user's Customization settings
as though the font-related attributes of the default face had been
"set in this session", so that the font is applied to future frames.
If INHIBIT-CUSTOMIZE is non-nil, don't update the user's Customization settings.
Probably introduced at or before Emacs version 20.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/frame.el.gz
(defun set-frame-font (font &optional keep-size frames inhibit-customize)
"Set the default font to FONT.
When called interactively, prompt for the name of a font, and use
that font on the selected frame. When called from Lisp, FONT
should be a font name (a string), a font object, font entity, or
font spec.
If KEEP-SIZE is nil, keep the number of frame lines and columns
fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
to keep the current frame size fixed (in pixels) by adjusting the
number of lines and columns.
If FRAMES is nil, apply the font to the selected frame only.
If FRAMES is non-nil, it should be a list of frames to act upon,
or t meaning all existing graphical frames.
Also, if FRAMES is non-nil, alter the user's Customization settings
as though the font-related attributes of the `default' face had been
\"set in this session\", so that the font is applied to future frames.
If INHIBIT-CUSTOMIZE is non-nil, don't update the user's
Customization settings."
(interactive
(let* ((completion-ignore-case t)
(default (frame-parameter nil 'font))
(font (completing-read (format-prompt "Font name" default)
;; x-list-fonts will fail with an error
;; if this frame doesn't support fonts.
(x-list-fonts "*" nil (selected-frame))
nil nil nil nil default)))
(list font current-prefix-arg nil)))
(when (or (stringp font) (fontp font))
(let* ((this-frame (selected-frame))
;; FRAMES nil means affect the selected frame.
(frame-list (cond ((null frames)
(list this-frame))
((eq frames t)
(frame-list))
(t frames)))
height width)
(dolist (f frame-list)
(when (display-multi-font-p f)
(if keep-size
(setq height (* (frame-parameter f 'height)
(frame-char-height f))
width (* (frame-parameter f 'width)
(frame-char-width f))))
;; When set-face-attribute is called for :font, Emacs
;; guesses the best font according to other face attributes
;; (:width, :weight, etc.) so reset them too (Bug#2476).
(set-face-attribute 'default f
:width 'normal :weight 'normal
:slant 'normal :font font)
(if keep-size
(modify-frame-parameters
f
(list (cons 'height (round height (frame-char-height f)))
(cons 'width (round width (frame-char-width f))))))))
(when (and frames
(not inhibit-customize))
;; Alter the user's Custom setting of the `default' face, but
;; only for font-related attributes.
(let ((specs (cadr (assq 'user (get 'default 'theme-face))))
(attrs '(:family :foundry :slant :weight :height :width))
(new-specs nil))
(if (null specs) (setq specs '((t nil))))
(dolist (spec specs)
;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
(let ((display (nth 0 spec))
(plist (copy-tree (nth 1 spec))))
;; Alter only DISPLAY conditions matching this frame.
(when (or (memq display '(t default))
(face-spec-set-match-display display this-frame))
(dolist (attr attrs)
(setq plist (plist-put plist attr
(face-attribute 'default attr)))))
(push (list display plist) new-specs)))
(setq new-specs (nreverse new-specs))
(put 'default 'customized-face new-specs)
(custom-push-theme 'theme-face 'default 'user 'set new-specs)
(put 'default 'face-modified nil))))
(run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))