Skip to content

Commit

Permalink
refactor(fonts): move font & script settings to me-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Dec 29, 2023
1 parent cba686f commit aa4de70
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 178 deletions.
10 changes: 5 additions & 5 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ When MAIL-MODE-P is non-nil, treat INFILE as a mail.

Save URL into OUT-FILE as a standalone HTML file.

#### `(+github-latest-release REPO &optional FALLBACK-RELEASE)`

Get the latest release of REPO. Strips the "v" at left.
Fallback to FALLBACK-RELEASE when it can't get the last one.

#### `(+lockedp NAME)`

Return non-nil if the resource NAME is locked.
Expand Down Expand Up @@ -992,11 +997,6 @@ is a pre-release.
This command stashes the current workspace before bumping the version, and
restores it after that.

#### `(+github-latest-release USER REPO &optional FALLBACK-RELEASE)`

Get the latest release of USER/REPO. Strips the "v" at left.
Fallback to FALLBACK-RELEASE when it can't get the last one.

#### `(eglot-ltex-workspace-config-fn &optional SERVER)`

A function to use as a value of `eglot-workspace-configuration`.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ make-readme-markdown.el:
wget -q -O $@ https://raw.github.com/mgalgs/make-readme-markdown/master/make-readme-markdown.el

combined.el:
cat init.el early-init.el core/me-{vars,lib,builtin,fonts,gc,compat,core-ui}.el modules/me-*.el modules/extras/me-*.el >combined.el
cat init.el early-init.el core/me-{vars,lib,builtin,gc,compat,core-ui}.el modules/me-*.el modules/extras/me-*.el >combined.el

docs: combined.el make-readme-markdown.el
emacs --script make-readme-markdown.el <combined.el >DOCS.md 2>/dev/null
Expand Down
164 changes: 0 additions & 164 deletions core/me-fonts.el

This file was deleted.

155 changes: 155 additions & 0 deletions core/me-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,161 @@ If prefix ARG, delete all persistent scratches."



;;; Font and script settings

(defcustom minemacs-fonts-plist
'(:default
((:family "Iosevka Fixed Curly Slab" :height 130)
(:family "Iosevka Comfy Fixed" :height 130)
(:family "Iosevka Fixed Curly" :height 130)
(:family "Iosevka Comfy Motion Fixed" :height 130)
(:family "Iosevka" :height 130)
(:family "Iosevka Comfy" :height 130)
(:family "Cascadia Code" :height 130)
(:family "Fira Code" :height 130)
(:family "Jetbrains Mono" :height 110)
(:family "Hack" :height 130)
(:family "Roboto Mono" :height 120)
(:family "SF Mono" :height 130)
(:family "Source Code Pro" :height 130)
(:family "Menlo" :height 130)
(:family "Monaco" :height 130)
(:family "Ubuntu Mono" :height 130)
(:family "DejaVu Sans Mono" :height 130)
(:family "Consolas" :height 130))
:fixed-pitch
((:inherit default))
:fixed-pitch-serif
((:inherit default))
:variable-pitch
("Lato"
"Roboto"
"Inter"
"San Francisco"
"Helvetica Neue"
"Helvetica"
"Ubuntu"
"Liberation Sans"
"Segoe UI")
:symbol
((:family "Segoe UI Symbol" :prepend t)
(:family "Symbola" :prepend t)
(:family "Symbol" :prepend t))
:emoji
((:family "Noto Color Emoji" :prepend t)
(:family "Apple Color Emoji" :prepent t)
(:family "Segoe UI Emoji" :prepend t)
(:family "Quivira" :prepend t))
;; Arabic script
:arabic
("Amiri Typewriter"
"KacstOne"
"Greta Arabic"
"Scheherazade"
"Koodak"
(:family "Amiri" :scale 0.9))
;; Chinese script
:han
((:family "LXGW Neo Xihei" :scale 1.3)
(:family "WenQuanYi Micro Hei Mono" :scale 1.3)
(:family "LXGW WenKai Screen" :scale 1.3)
(:family "LXGW WenKai Mono" :scale 1.3)
(:family "PingFang SC" :scale 1.3)
(:family "Microsoft Yahei UI" :scale 1.3)
(:family "Simhei" :scale 1.3)))
"MinEmacs fonts used by `+setup-fonts'.
The function checks and enables the first available font from these defined in
this plist. This variable can be customized to set font specs for specific Emacs
faces or to enable some language-specific fonts. The plist keywords are either
face names or script names expressed as keywords (with the \":\" prefix).
For example to set `default' face, use `:default', to set the `mode-line' face,
use `:mode-line', and so on. The parameters for each font in these cases (ie.
for face names) are used in the `custom-theme-set-faces' function, so you can
pass any specs (key value pairs) supported by `custom-theme-set-faces' (like
`:weight', `:slant', `:foreground', ...). A list of supported keywords are
available in the variable `+face-attributes'.
You can also setup some language-specific fonts. All scripts supported by Emacs
can be found in `+known-scripts'. The keyword in this plist will be the script
name expressed as a keyword, for example, for `latin' use `:latin', for `arabic'
use `:arabic', for `emoji' use `:emoji', and so on. In this case, the parameters
are used with `set-fontset-font', so you can send any key value pair supported
by `set-fontset-font'. A list of supported keywords in this case is available in
`+font-spec-keywords'.
The value of the extra `:prepend' keyword is passed the last argument to
`set-fontset-font'. The value of the extra `:scale' keyword can be used to set a
scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
`+setup-fonts' implementation for more details."
:group 'minemacs-ui
:type 'plist)

(defconst +known-scripts (mapcar #'car script-representative-chars)
"Supported scripts, like `latin', `arabic', `han', and so on.")

(defconst +face-attributes
'(:family :foundry :width :height :weight :slant :foreground
:distant-foreground :background :underline :overline :strike-through :box
:inverse-video :stipple :font :inherit :extend)
"Arguments accepted by the `set-face-attribute' function.")

(defconst +font-spec-keywords
'(:family :foundry :width :weight :slant :adstyle :registry :dpi :size
:spacing :avgwidth :name :script :lang :otf)
"Arguments accepted by the `font-spec' function.")

(defun +font--get-valid-args (script-or-face font)
(if (stringp font)
`(:family ,font)
(apply
#'append
(mapcar (lambda (a) (list a (plist-get font a)))
(cl-intersection (+plist-keys font)
(if (memq script-or-face +known-scripts)
+font-spec-keywords
+face-attributes))))))

(defun +font-installed-p (font-family)
"Check if FONT-FAMILY is installed on the system."
(and font-family (member font-family (font-family-list)) t))

(defun +apply-font-or-script (script-or-face)
"Set font for SCRIPT-OR-FACE from `minemacs-fonts-plist'."
(catch 'done
(dolist (font (plist-get minemacs-fonts-plist (intern (format ":%s" script-or-face))))
(let* ((spec (+font--get-valid-args script-or-face font))
(scale (and (plistp font) (plist-get font :scale)))
(prependp (and (plistp font) (plist-get font :family)))
(family (plist-get spec :family))
(scriptp (memq script-or-face +known-scripts)))
(when (or (not family) (+font-installed-p family))
(if scriptp
(set-fontset-font t script-or-face (apply #'font-spec spec) nil prependp)
(custom-theme-set-faces 'user `(,script-or-face ((t ,spec)))))
(when (and scale family)
(add-to-list 'face-font-rescale-alist (cons family scale)))
(+log! "Settinng %s `%s' to `%s'" (if scriptp "script" "face") script-or-face spec)
(throw 'done spec))))))

;; Inspired by: github.com/seagle0128/.emacs.d/blob/master/custom-example.el
;;;###autoload
(defun +setup-fonts ()
"Setup fonts."
(interactive)
(mapc #'+apply-font-or-script
(reverse
(mapcar (lambda (k) (intern (substring (symbol-name k) 1)))
(+plist-keys minemacs-fonts-plist))))
;; Run hooks
(run-hooks 'minemacs-after-setup-fonts-hook))

(+add-hook! (window-setup server-after-make-frame) #'+setup-fonts)




(provide 'me-lib)

;;; me-lib.el ends here
11 changes: 3 additions & 8 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ restores it after that.
(put 'eglot-ltex-language 'safe-local-variable 'stringp)
(register-definition-prefixes "../modules/extras/me-eglot-ltex" '("eglot-ltex-"))


;;; Generated autoloads from me-fonts.el

(autoload '+setup-fonts "me-fonts" "\
Setup fonts." t)
(register-definition-prefixes "me-fonts" '("+apply-font-or-script" "+f" "+known-scripts" "minemacs-fonts-plist"))


;;; Generated autoloads from ../modules/extras/me-gdb.el

Expand All @@ -68,7 +61,9 @@ Get the latest release of REPO. Strips the \"v\" at left.
Fallback to FALLBACK-RELEASE when it can't get the last one.
(fn REPO &optional FALLBACK-RELEASE)")
(register-definition-prefixes "me-lib" '("+a" "+binary-" "+c" "+d" "+e" "+f" "+h" "+i" "+kill-" "+l" "+m" "+n" "+omap!" "+p" "+quoted-p" "+r" "+s" "+t" "+un" "+v" "+w" "+yank-this-file-name" "minemacs-" "objdump-disassemble-mode"))
(autoload '+setup-fonts "me-lib" "\
Setup fonts." t)
(register-definition-prefixes "me-lib" '("+a" "+binary-" "+c" "+d" "+e" "+f" "+h" "+i" "+k" "+l" "+m" "+n" "+omap!" "+p" "+quoted-p" "+r" "+s" "+t" "+un" "+v" "+w" "+yank-this-file-name" "minemacs-" "objdump-disassemble-mode"))


;;; Generated autoloads from me-modules.el
Expand Down

0 comments on commit aa4de70

Please sign in to comment.