diff options
author | Case Duckworth | 2021-01-08 23:31:40 -0600 |
---|---|---|
committer | Case Duckworth | 2021-01-08 23:31:40 -0600 |
commit | 6e7ad60257c632ad004b1ccb7c6646175d543518 (patch) | |
tree | f0f4036f2e3a7f5877f4793f07d52896768e5fc5 | |
parent | Update README (diff) | |
download | emacs-6e7ad60257c632ad004b1ccb7c6646175d543518.tar.gz emacs-6e7ad60257c632ad004b1ccb7c6646175d543518.zip |
Fix font-changing functions
-rw-r--r-- | config.org | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/config.org b/config.org index c945012..1a17b2f 100644 --- a/config.org +++ b/config.org | |||
@@ -472,15 +472,14 @@ Commented for now because I really need to figure out the keybindings I want to | |||
472 | **** Define fonts | 472 | **** Define fonts |
473 | 473 | ||
474 | #+BEGIN_SRC emacs-lisp | 474 | #+BEGIN_SRC emacs-lisp |
475 | (defun set-face-from-alternatives (face fonts) | 475 | (defun set-face-from-alternatives (face frame &rest fontspecs) |
476 | "Set FACE on FRAME from first available spec from FONTSPECS. | ||
477 | FACE and FRAME work the same as with `set-face-attribute.'" | ||
476 | (catch :return | 478 | (catch :return |
477 | (dolist (font fonts) | 479 | (dolist (spec fontspecs) |
478 | (when (find-font (font-spec :family (car font))) | 480 | (when-let ((found (find-font (apply #'font-spec spec)))) |
479 | (apply #'set-face-attribute `(,face | 481 | (set-face-attribute face frame :font found) |
480 | nil | 482 | (throw :return found))))) |
481 | :family (car font) | ||
482 | ,@(cdr font))) | ||
483 | (throw :return font))))) | ||
484 | 483 | ||
485 | (defun acdw/setup-fonts () | 484 | (defun acdw/setup-fonts () |
486 | "Setup fonts. This has to happen after the frame is setup for | 485 | "Setup fonts. This has to happen after the frame is setup for |
@@ -488,24 +487,27 @@ Commented for now because I really need to figure out the keybindings I want to | |||
488 | removes itself from that hook." | 487 | removes itself from that hook." |
489 | (interactive) | 488 | (interactive) |
490 | (when (display-graphic-p) | 489 | (when (display-graphic-p) |
491 | (set-face-from-alternatives 'default | 490 | (dolist (face '(default fixed-pitch)) |
492 | '(("Input Mono" | 491 | ;; fixed-pitch /is/ the default |
493 | :height 105) | 492 | (set-face-from-alternatives face nil |
494 | ("Go Mono" | 493 | '(:family "Input Mono" |
495 | :height 100) | 494 | :weight normal |
496 | ("Consolas" | 495 | :height 110) |
497 | :height 100))) | 496 | '(:family "Go Mono" |
498 | 497 | :weight normal | |
499 | (set-face-from-alternatives 'fixed-pitch | 498 | :height 100) |
500 | '(("Input Mono") | 499 | '(:family "Consolas" |
501 | ("Go Mono") | 500 | :weight normal |
502 | ("Consolas"))) | 501 | :height 100))) |
503 | 502 | ;; variable-pitch is different | |
504 | (set-face-from-alternatives 'variable-pitch | 503 | (set-face-from-alternatives 'variable-pitch nil |
505 | '(("Input Serif") | 504 | '(:family "Input Sans" |
506 | ("Georgia"))) | 505 | :weight normal) |
507 | 506 | '(:family "Georgia" | |
508 | (remove-function after-focus-change-function #'acdw/setup-fonts))) | 507 | :weight normal))) |
508 | |||
509 | ;; remove myself from the hook | ||
510 | (remove-function after-focus-change-function #'acdw/setup-fonts)) | ||
509 | 511 | ||
510 | (add-function :before after-focus-change-function #'acdw/setup-fonts) | 512 | (add-function :before after-focus-change-function #'acdw/setup-fonts) |
511 | #+END_SRC | 513 | #+END_SRC |