From b739c13005817cfd628535d96e8e51bde230da6c Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Thu, 14 Mar 2024 10:49:05 +0100 Subject: [PATCH] Clean up the face setting section; font scaling does not work well --- README.org | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/README.org b/README.org index 32f4ff1..2dd9e19 100644 --- a/README.org +++ b/README.org @@ -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 scaling). 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 -proper initialization of all face heights. To adjust the font size in the -current or future frames, invoke src_emacs-lisp{(set-default-face-height)}. To -adjust the font size in the current buffer, type: +Listing [[lst:face-setting-functions]] shows that font scaling is easy in case of +proper initialization of all face heights in a frame. To adjust the font size +in windows, invoke src_emacs-lisp{(set-default-face-height)}. To adjust the +font size in the current buffer, type: 1. {{{kbd(s-=)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust +1)}. 2. {{{kbd(s--)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust -1)}. 3. {{{kbd(s-0)}}} to invoke src_emacs-lisp[:results silent]{(text-scale-adjust 0)}. -Listing [[lst:fix-gtk-color-for-invert-default-face]], -[[lst:shadow-org-font-lock-faces]], and [[lst:shadow-emacs-font-lock-faces]] show a -tweaks to improve visibility without theming: +Listing [[lst:face-setting-functions]], [[lst:shadow-org-font-lock-faces]], and +[[lst:shadow-emacs-font-lock-faces]] show tweaks to improve visibility without +theming: 1. Fixing the =gtk= background color of the already loaded =region= face. 2. Toggling between a dark and light background by means of 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")))) #+end_src -#+caption[Implement =set-default-face-height=]: -#+caption: Implement =set-default-face-height=. -#+name: lst:set-default-face-height +#+caption[Implement =face= setting functions]: +#+caption: Implement =face= setting functions. +#+name: lst:face-setting-functions #+begin_src emacs-lisp -n :results silent (with-eval-after-load 'emacs + ;; Neither `set-default-face-height' nor `text-scale-adjust' work well. (defun set-default-face-height () "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 (completing-read prompt choices nil 'require-match)))) (message "Setting the height of the default face to %s" 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"))))))) + (set-face-attribute 'default nil :height height))) (defun invert-default-face () "Invert the default face." (interactive) - (invert-face 'default) - (fix-gtk-region-face-background-color)) - - (fix-gtk-region-face-background-color)) + (invert-face 'default))) #+end_src #+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 () "Set a variable width (proportional) font in current buffer." (interactive) - (setq buffer-face-mode-face 'variable-pitch) - (buffer-face-mode)) + (let ((buffer-face-mode-face 'variable-pitch)) + (buffer-face-mode))) ;; Use monospaced font faces in current buffer (defun set-buffer-fixed-pitch-face () "Set a fixed width (monospace) font in current buffer." (interactive) - (setq buffer-face-mode-face 'fixed-pitch) - (buffer-face-mode)) + (let ((buffer-face-mode-face 'fixed-pitch)) + (buffer-face-mode))) (add-hook 'magit-mode-hook #'set-buffer-fixed-pitch-face) (add-hook 'prog-mode-hook #'set-buffer-fixed-pitch-face)