Clean up the face setting section; font scaling does not work well

This commit is contained in:
Gerard Vermeulen 2024-03-14 10:49:05 +01:00
parent f875f8a4ef
commit b739c13005
1 changed files with 17 additions and 33 deletions

View File

@ -483,19 +483,19 @@ Emacs]] for how to setup fonts properly. It boils down to two rules:
with respect to the height of the face (those heights default to 1.0 for no with respect to the height of the face (those heights default to 1.0 for no
scaling). scaling).
The code in listing [[lst:configure-face-attributes]] implements those rules. The code in listing [[lst:configure-face-attributes]] implements those rules.
Listing [[lst:set-default-face-height]] shows that font scaling is easy in case of Listing [[lst:face-setting-functions]] shows that font scaling is easy in case of
proper initialization of all face heights. To adjust the font size in the proper initialization of all face heights in a frame. To adjust the font size
current or future frames, invoke src_emacs-lisp{(set-default-face-height)}. To in windows, invoke src_emacs-lisp{(set-default-face-height)}. To adjust the
adjust the font size in the current buffer, type: font size in the current buffer, type:
1. {{{kbd(s-=)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust 1. {{{kbd(s-=)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust
+1)}. +1)}.
2. {{{kbd(s--)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust 2. {{{kbd(s--)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust
-1)}. -1)}.
3. {{{kbd(s-0)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust 3. {{{kbd(s-0)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust
0)}. 0)}.
Listing [[lst:fix-gtk-color-for-invert-default-face]], Listing [[lst:face-setting-functions]], [[lst:shadow-org-font-lock-faces]], and
[[lst:shadow-org-font-lock-faces]], and [[lst:shadow-emacs-font-lock-faces]] show a [[lst:shadow-emacs-font-lock-faces]] show tweaks to improve visibility without
tweaks to improve visibility without theming: theming:
1. Fixing the =gtk= background color of the already loaded =region= face. 1. Fixing the =gtk= background color of the already loaded =region= face.
2. Toggling between a dark and light background by means of 2. Toggling between a dark and light background by means of
src_emacs-lisp{(invert-default-face)}. src_emacs-lisp{(invert-default-face)}.
@ -526,11 +526,12 @@ selects a fixed pitch face for =magit-mode= and =progmode= buffers.
(set-face-attribute 'variable-pitch nil :family "DejaVu Sans")))) (set-face-attribute 'variable-pitch nil :family "DejaVu Sans"))))
#+end_src #+end_src
#+caption[Implement =set-default-face-height=]: #+caption[Implement =face= setting functions]:
#+caption: Implement =set-default-face-height=. #+caption: Implement =face= setting functions.
#+name: lst:set-default-face-height #+name: lst:face-setting-functions
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs (with-eval-after-load 'emacs
;; Neither `set-default-face-height' nor `text-scale-adjust' work well.
(defun set-default-face-height () (defun set-default-face-height ()
"Set the default face height in all current and future frames. "Set the default face height in all current and future frames.
@ -543,29 +544,12 @@ Scale all other faces with a height that is a real number."
(height (string-to-number (height (string-to-number
(completing-read prompt choices nil 'require-match)))) (completing-read prompt choices nil 'require-match))))
(message "Setting the height of the default face to %s" height) (message "Setting the height of the default face to %s" height)
(set-face-attribute 'default nil :height height)))) (set-face-attribute 'default nil :height height)))
#+end_src
#+caption[Fix a `gtk' color and implement =invert-default-face=]:
#+caption: Fix a `gtk' color and implement =invert-default-face=.
#+name: lst:fix-gtk-color-for-invert-default-face
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs
(defun fix-gtk-region-face-background-color ()
(when (featurep 'gtk)
(set-face-attribute
'region nil
:background (cdr (assoc (face-attribute 'default :background)
'(("white" . "LightGoldenrod2")
("black" . "blue3")))))))
(defun invert-default-face () (defun invert-default-face ()
"Invert the default face." "Invert the default face."
(interactive) (interactive)
(invert-face 'default) (invert-face 'default)))
(fix-gtk-region-face-background-color))
(fix-gtk-region-face-background-color))
#+end_src #+end_src
#+caption[Shadow Org font-lock faces to improve the readability]: #+caption[Shadow Org font-lock faces to improve the readability]:
@ -638,15 +622,15 @@ verse and quote blocks are fontified using the `org-verse' and
(defun set-buffer-variable-pitch-face () (defun set-buffer-variable-pitch-face ()
"Set a variable width (proportional) font in current buffer." "Set a variable width (proportional) font in current buffer."
(interactive) (interactive)
(setq buffer-face-mode-face 'variable-pitch) (let ((buffer-face-mode-face 'variable-pitch))
(buffer-face-mode)) (buffer-face-mode)))
;; Use monospaced font faces in current buffer ;; Use monospaced font faces in current buffer
(defun set-buffer-fixed-pitch-face () (defun set-buffer-fixed-pitch-face ()
"Set a fixed width (monospace) font in current buffer." "Set a fixed width (monospace) font in current buffer."
(interactive) (interactive)
(setq buffer-face-mode-face 'fixed-pitch) (let ((buffer-face-mode-face 'fixed-pitch))
(buffer-face-mode)) (buffer-face-mode)))
(add-hook 'magit-mode-hook #'set-buffer-fixed-pitch-face) (add-hook 'magit-mode-hook #'set-buffer-fixed-pitch-face)
(add-hook 'prog-mode-hook #'set-buffer-fixed-pitch-face) (add-hook 'prog-mode-hook #'set-buffer-fixed-pitch-face)