132 lines
4.4 KiB
EmacsLisp
132 lines
4.4 KiB
EmacsLisp
;;; acdw-fonts.el -- font setup -*- lexical-binding: t; coding: utf-8-unix -*-
|
||
|
||
;; Author: Case Duckworth <acdw@acdw.net>
|
||
;; Created: Sometime during Covid-19, 2020
|
||
;; Keywords: configuration
|
||
;; URL: https://tildegit.org/acdw/emacs
|
||
|
||
;; This file is NOT part of GNU Emacs.
|
||
|
||
;; Everyone is permitted to do whatever with this software, without
|
||
;; limitation. This software comes without any warranty whatsoever,
|
||
;; but with two pieces of advice:
|
||
;; - Don't hurt yourself.
|
||
;; - Make good choices.
|
||
|
||
;;; Commentary:
|
||
;; This code is based heavily on (and in fact, until I am able to tweak it,
|
||
;; will be a copy of) Oliver Taylor's code, available here:
|
||
;; https://github.com/olivertaylor/olivertaylor.github.io
|
||
;; /blob/master/notes/20210324_emacs-optical-font-adjustment.org
|
||
|
||
;;; Code:
|
||
|
||
|
||
;; Variables
|
||
|
||
(defvar acdw-fonts/monospace nil
|
||
"Monospace font to be used for `default' and `fixed-pitch' faces.")
|
||
|
||
(defvar acdw-fonts/variable nil
|
||
"Variable font to be used for the `variable-pitch' face.")
|
||
|
||
(defvar acdw-fonts/monospace-size 11
|
||
"Font size, an integer, to be used for the `default' and `fixed-pitch' faces.
|
||
|
||
This value is multiplied by 10, so 12 becomes 120, in order to
|
||
comply with Emacs's `set-face-attribute' requirements.")
|
||
|
||
(defvar acdw-fonts/variable-size 12
|
||
"Font size, an integer, to be used for the `variable-pitch' face.
|
||
|
||
This value will be used to determine a relative (float) size
|
||
based on the default size. So if your default size is 12 and
|
||
your variable size is 14, the computed relative size will be
|
||
1.16.")
|
||
|
||
|
||
;; Functions
|
||
|
||
(defun acdw-fonts/set ()
|
||
"Set fonts according to `acdw-fonts' variables."
|
||
(interactive)
|
||
(set-face-attribute 'default nil
|
||
:family acdw-fonts/monospace
|
||
:height (* acdw-fonts/monospace-size 10))
|
||
(set-face-attribute 'fixed-pitch nil
|
||
:family acdw-fonts/monospace
|
||
:height 1.0)
|
||
(set-face-attribute 'variable-pitch nil
|
||
:family acdw-fonts/variable
|
||
:height 1.0))
|
||
|
||
|
||
;;; Larger Variable Pitch Mode
|
||
|
||
|
||
;; A minor mode to scale the variable-pitch face up to the height defined in
|
||
;; `acdw-fonts/variable-size' and the fixed-pitch face down to the height
|
||
;; defined in `acdw-fonts/monospace-size', buffer locally. This mode should
|
||
;; be enabled wherever you want to adjust face sizes, perhaps with a hook.
|
||
|
||
(make-variable-buffer-local
|
||
(defvar larger-variable-pitch-mode-status nil
|
||
"Status of the larger-variable-pitch-mode"))
|
||
|
||
(make-variable-buffer-local
|
||
(defvar variable-pitch-remapping nil
|
||
"variable-pitch remapping cookie for larger-variable-pitch-mode."))
|
||
|
||
(make-variable-buffer-local
|
||
(defvar fixed-pitch-remapping nil
|
||
"fixed-pitch remapping cookie for larger-variable-pitch-mode"))
|
||
|
||
(defun larger-variable-pitch-mode-toggle ()
|
||
(setq larger-variable-pitch-mode-status
|
||
(not larger-variable-pitch-mode-status))
|
||
(if larger-variable-pitch-mode-status
|
||
(progn
|
||
(setq variable-pitch-remapping
|
||
(face-remap-add-relative
|
||
'variable-pitch :height (/ (float acdw-fonts/variable-size)
|
||
(float acdw-fonts/monospace-size))))
|
||
(setq fixed-pitch-remapping
|
||
(face-remap-add-relative
|
||
'fixed-pitch :height (/ (float acdw-fonts/monospace-size)
|
||
(float acdw-fonts/variable-size))))
|
||
(force-window-update (current-buffer)))
|
||
(progn
|
||
(face-remap-remove-relative variable-pitch-remapping)
|
||
(face-remap-remove-relative fixed-pitch-remapping))))
|
||
|
||
(define-minor-mode larger-variable-pitch-mode
|
||
"Minor mode to scale the variable- and fixed-pitch faces up and down."
|
||
:init-value nil
|
||
:lighter " V+"
|
||
(larger-variable-pitch-mode-toggle))
|
||
|
||
(defun acdw-fonts/buffer-face-hook ()
|
||
"Activate and deactivate larger-variable-pitch-mode minor mode."
|
||
(if buffer-face-mode
|
||
(larger-variable-pitch-mode 1)
|
||
(larger-variable-pitch-mode -1)))
|
||
|
||
(add-hook 'buffer-face-mode-hook #'acdw-fonts/buffer-face-hook)
|
||
|
||
|
||
;;; Emoji fonts
|
||
;; from https://old.reddit.com/r/emacs/comments/mvlid5/
|
||
|
||
(defun acdw-fonts/setup-emoji-fonts (&rest emoji-fonts)
|
||
"For all EMOJI-FONTS that exist, add them to the symbol fontset.
|
||
|
||
This is for emoji fonts."
|
||
(let ((ffl (font-family-list)))
|
||
(dolist (font emoji-fonts)
|
||
(when (member font ffl)
|
||
(set-fontset-font t 'symbol
|
||
(font-spec :family font) nil 'append)))))
|
||
|
||
(provide 'acdw-fonts)
|
||
;;; acdw-fonts.el ends here
|