From 32959ca977b7b05bcbeef14c559de85ba7838243 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:37:57 -0500 Subject: Add variable-pitch-mode in Org and Info --- init.el | 12 +++++++++++- lisp/acdw-fonts.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index d20e1ac..a6e29a4 100644 --- a/init.el +++ b/init.el @@ -365,6 +365,9 @@ (setup imenu (:option imenu-auto-rescan t)) +(setup Info + (:hook variable-pitch-mode)) + (setup isearch (:option search-default-mode t)) @@ -578,6 +581,9 @@ uniquify-after-kill-buffer-p t uniquify-ignore-buffers-re "^\\*")) +(setup variable-pitch-mode + (:hook acdw-fonts/adapt-variable-pitch)) + (setup view (:option view-read-only t) @@ -936,7 +942,11 @@ if ripgrep is installed, otherwise `consult-grep'." (:bind "RET" acdw-org/return-dwim "" acdw-org/org-table-copy-down) - (add-hook 'before-save-hook #'acdw-org/fix-blank-lines-in-buffer) + (defun acdw/org-fix-lines-before-save () + (add-hook 'before-save-hook #'acdw-org/fix-blank-lines-in-buffer 0 :local)) + + (:hook variable-pitch-mode + acdw/org-fix-lines-before-save) (advice-add 'org-delete-backward-char :override #'acdw-org/delete-backward-char)) diff --git a/lisp/acdw-fonts.el b/lisp/acdw-fonts.el index 6c0cb8d..1b73af7 100644 --- a/lisp/acdw-fonts.el +++ b/lisp/acdw-fonts.el @@ -127,5 +127,50 @@ This is for emoji fonts." (set-fontset-font t 'symbol (font-spec :family font) nil 'append))))) + +;;; Variable-pitch +;; from https://github.com/turbana/emacs-config#variable-pitch + +(defcustom acdw-fonts/fixed-pitch-faces '(linum + org-block + org-block-begin-line + org-block-end-line + org-checkbox + org-code + org-date + org-document-info-keyword + org-hide + org-indent + org-link + org-meta-line + org-special-keyword + org-table + whitespace-space) + "Faces to keep fixed-pitch in `acdw/variable-pitch-mode'." + :type 'sexp + :group 'faces) + +(defun acdw-fonts//variable-pitch-add-inherit (attrs parent) + "Add `:inherit PARENT' to ATTRS unless already present. +Handles cases where `:inherit' is already specified." + (let ((current-parent (plist-get attrs :inherit))) + (unless (or (eq parent current-parent) + (and (listp current-parent) + (member parent current-parent))) + (plist-put attrs :inherit (if current-parent + (list current-parent parent) + parent))))) + +(defun acdw-fonts/adapt-variable-pitch () + "Adapt `variable-pitch-mode' to keep some fonts fixed-pitch." + (when variable-pitch-mode + (mapc (lambda (face) + (when (facep face) + (apply #'set-face-attribute + face nil (acdw-fonts//variable-pitch-add-inherit + (face-attr-construct face) + 'fixed-pitch)))) + acdw-fonts/fixed-pitch-faces))) + (provide 'acdw-fonts) ;;; acdw-fonts.el ends here -- cgit 1.4.1-21-gabe81