summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-04-09 12:48:54 -0500
committerCase Duckworth2021-04-09 12:48:54 -0500
commitbac79657a5dac12776a5e0f2c2af8ae51dc618cd (patch)
tree707683fd93cfd163f2eecf8fd638fe7cefde835d /lisp
parentAdd `acdw/find-emacs-dotfiles' (diff)
downloademacs-bac79657a5dac12776a5e0f2c2af8ae51dc618cd.tar.gz
emacs-bac79657a5dac12776a5e0f2c2af8ae51dc618cd.zip
Change font loading logic to hopefully be more robust
Based heavily (basically copied) from
https://github.com/olivertaylor/olivertaylor.github.io/blob/master/notes/20210324_emacs-optical-font-adjustment.org
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-fonts.el117
1 files changed, 117 insertions, 0 deletions
diff --git a/lisp/acdw-fonts.el b/lisp/acdw-fonts.el new file mode 100644 index 0000000..c4f16e8 --- /dev/null +++ b/lisp/acdw-fonts.el
@@ -0,0 +1,117 @@
1;;; acdw-fonts.el -- font setup -*- lexical-binding: t; coding: utf-8-unix -*-
2
3;; Author: Case Duckworth <acdw@acdw.net>
4;; Created: Sometime during Covid-19, 2020
5;; Keywords: configuration
6;; URL: https://tildegit.org/acdw/emacs
7
8;; This file is NOT part of GNU Emacs.
9
10;; Everyone is permitted to do whatever with this software, without
11;; limitation. This software comes without any warranty whatsoever,
12;; but with two pieces of advice:
13;; - Don't hurt yourself.
14;; - Make good choices.
15
16;;; Commentary:
17;; This code is based heavily on (and in fact, until I am able to tweak it,
18;; will be a copy of) Oliver Taylor's code, available here:
19;; https://github.com/olivertaylor/olivertaylor.github.io
20;; /blob/master/notes/20210324_emacs-optical-font-adjustment.org
21
22;;; Code:
23
24
25;; Variables
26
27(defvar acdw-fonts/monospace nil
28 "Monospace font to be used for `default' and `fixed-pitch' faces.")
29
30(defvar acdw-fonts/variable nil
31 "Variable font to be used for the `variable-pitch' face.")
32
33(defvar acdw-fonts/monospace-size 11
34 "Font size, an integer, to be used for the `default' and `fixed-pitch' faces.
35
36This value is multiplied by 10, so 12 becomes 120, in order to
37comply with Emacs's `set-face-attribute' requirements.")
38
39(defvar acdw-fonts/variable-size 12
40 "Font size, an integer, to be used for the `variable-pitch' face.
41
42This value will be used to determine a relative (float) size
43based on the default size. So if your default size is 12 and
44your variable size is 14, the computed relative size will be
451.16.")
46
47
48;; Functions
49
50(defun acdw-fonts/set ()
51 "Set fonts according to `acdw-fonts' variables."
52 (interactive)
53 (set-face-attribute 'default nil
54 :family acdw-fonts/monospace
55 :height (* acdw-fonts/monospace-size 10))
56 (set-face-attribute 'fixed-pitch nil
57 :family acdw-fonts/monospace
58 :height 1.0)
59 (set-face-attribute 'variable-pitch nil
60 :family acdw-fonts/variable
61 :height 1.0))
62
63
64;;; Larger Variable Pitch Mode
65
66
67;; A minor mode to scale the variable-pitch face up to the height defined in
68;; `acdw-fonts/variable-size' and the fixed-pitch face down to the height
69;; defined in `acdw-fonts/monospace-size', buffer locally. This mode should
70;; be enabled wherever you want to adjust face sizes, perhaps with a hook.
71
72(make-variable-buffer-local
73 (defvar larger-variable-pitch-mode-status nil
74 "Status of the larger-variable-pitch-mode"))
75
76(make-variable-buffer-local
77 (defvar variable-pitch-remapping nil
78 "variable-pitch remapping cookie for larger-variable-pitch-mode."))
79
80(make-variable-buffer-local
81 (defvar fixed-pitch-remapping nil
82 "fixed-pitch remapping cookie for larger-variable-pitch-mode"))
83
84(defun larger-variable-pitch-mode-toggle ()
85 (setq larger-variable-pitch-mode-status
86 (not larger-variable-pitch-mode-status))
87 (if larger-variable-pitch-mode-status
88 (progn
89 (setq variable-pitch-remapping
90 (face-remap-add-relative
91 'variable-pitch :height (/ (float acdw-fonts/variable-size)
92 (float acdw-fonts/monospace-size))))
93 (setq fixed-pitch-remapping
94 (face-remap-add-relative
95 'fixed-pitch :height (/ (float acdw-fonts/monospace-size)
96 (float acdw-fonts/variable-size))))
97 (force-window-update (current-buffer)))
98 (progn
99 (face-remap-remove-relative variable-pitch-remapping)
100 (face-remap-remove-relative fixed-pitch-remapping))))
101
102(define-minor-mode larger-variable-pitch-mode
103 "Minor mode to scale the variable- and fixed-pitch faces up and down."
104 :init-value nil
105 :lighter " V+"
106 (larger-variable-pitch-mode-toggle))
107
108(defun acdw-fonts/buffer-face-hook ()
109 "Activate and deactivate larger-variable-pitch-mode minor mode."
110 (if buffer-face-mode
111 (larger-variable-pitch-mode 1)
112 (larger-variable-pitch-mode -1)))
113
114(add-hook 'buffer-face-mode-hook #'acdw-fonts/buffer-face-hook)
115
116(provide 'acdw-fonts)
117;;; acdw-fonts.el ends here