Finally got litagures working on my Mac

Using a couple of hacks, but I'm keeping Mickey Peterson's project as
that seems like a better solution for the Linux system.
This commit is contained in:
Howard Abrams 2023-03-24 10:58:22 -07:00
parent b433f5d2e6
commit 1b81e2178a
4 changed files with 105 additions and 8 deletions

View file

@ -196,14 +196,16 @@ My /current/ favorite font is actually the top list of fonts that may be install
(or
(seq-first
(seq-filter (lambda (font) (when (x-list-fonts font) font))
'("Hack Nerd Font"
'("CaskaydiaCove Nerd Font" ; finally found it
"Cascadia Code PL" ; funky font with litagures and a dotted 0
"Hack Nerd Font" ; clean font, but no litagures!?
"FiraCode Nerd Font" ; has litagures
"Cousine Nerd Font"
"Iosevka Nerd Font"
"Iosevka"
"FantasqueSansMono Nerd Font"
"Monoid Nerd Font"
"Hasklig"
"Cascadia Code PL"
"Source Code Pro")))
"monospaced"))
"My fixed width font based on what I have installed.")
@ -216,8 +218,10 @@ I probably don't need to have such a ranking system, as chances are good I have
(or
(seq-first
(seq-filter (lambda (font) (when (x-list-fonts font) font))
'(; Interesting idea: "Iosevka Comfy Motion Duo"
'("Literata" ; Clean, readable with litagures
"XCharter" ; https://fontesk.com/xcharter-typeface/
"Charter"
; Interesting idea: "Iosevka Comfy Motion Duo"
"Serif")))
(warn "Cannot find a Serif Font. Install Source Sans Pro."))))
@ -367,7 +371,6 @@ Not use what I'm doing with the [[https://github.com/domtronn/all-the-icons.el][
#+end_src
*Note:* Install everything with the function, =all-the-icons-install-fonts=.
* Ligatures
Seems like getting ligatures to work in Emacs has been a Holy Grail. On Mac, I've used special builds that have hacks, but now with Emacs 27 and Harfbuzz, I should be able to get --> to look like it should.
#+begin_src emacs-lisp :tangle no
@ -377,9 +380,7 @@ Seems like getting ligatures to work in Emacs has been a Holy Grail. On Mac, I'v
(prettify-symbols-mode +1)
#+end_src
Note, in Doom, is appears we have a =ligatures= module.
We'll start using that instead, but changing it in [[file:general-programming.org][general-programming]] file.
We'll start using that instead, but setting this [[file:ha-programming.org::*Ligatures][over here]] in the programming section.
* Technical Artifacts :noexport:
Let's =provide= a name so we can =require= this file:

View file

@ -200,6 +200,19 @@ After reading [[https://www.punctuationmatters.com/en-dash-em-dash-hyphen][this
(define-key org-mode-map "-" #'ha-insert-long-dash)
#+end_src
The /issue/ is how do we deal with orgs dashed bullets? In this case, we want to insert an actual dash, but elsewhere, we /visually/ display the dash as a more emphasized glyph.
** Ligatures
Well, using the =composition-function-table=, we can finally get some ligatures to improve readability without Harfbuzz.
#+begin_src emacs-lisp
(defun ha-textual-litagures ()
"Non-programming litagures for readable and text-derived modes."
(set-char-table-range composition-function-table
?f '(["\\(?:ff?[fijlt]\\)" 0 font-shape-gstring]))
(set-char-table-range composition-function-table
?T '(["\\(?:Th\\)" 0 font-shape-gstring])))
(add-hook 'text-mode-hook #'ha-textual-litagures)
#+end_src
This is now fine and ffantastic!
* Org Beautify
I really want to use the Org Beautify package, but it overrides my darker themes (and all I really want is headlines to behave).

View file

@ -612,8 +612,10 @@ Splitting out HTML snippets is often a way that I can transfer org-formatted con
#+begin_src emacs-lisp
(setq org-html-head-extra
(string-join '( "<style>"
"@import url('https://fonts.googleapis.com/css2?family=Literata:ital,wght@0,300;0,600;1,300;1,600&display=swap');"
"@import url('https://fonts.googleapis.com/css2?family=Overpass:ital,wght@0,300;0,600;1,300;1,600&display=swap');"
"html { font-family: 'Overpass', sans-serif; color: #333; }"
"html { font-family: 'Literata', sans-serif; color: #333; }"
"h1,h2,h3,h4,h5 { font-family: 'Overpass', sans-serif; color: #333; }"
"pre.src { background-color: #eee; }"
;; "@importmedia (prefers-color-scheme: dark) {"
" html { background-color: #1d1f21; color: white; }"

View file

@ -455,7 +455,88 @@ The idea of using math symbols for a programming languages keywords is /cute/, b
(add-hook 'prog-mode-hook 'ha-prettify-prog)
#+end_src
Hopefully I can follow [[https://www.masteringemacs.org/article/unicode-ligatures-color-emoji][Mickey Petersen's essay]] on getting full ligatures working, but right now, they dont work on the Mac, and that is my current workhorse.
#+begin_src emacs-lisp
(use-package ligature
:config
;; Enable the "www" ligature in every possible major mode
(ligature-set-ligatures 't '("www"))
;; Enable traditional ligature support in eww-mode, if the
;; `variable-pitch' face supports it
(ligature-set-ligatures '(org-mode eww-mode) '("ff" "fi" "ffi"))
(ligature-set-ligatures '(html-mode nxml-mode web-mode)
'("<!--" "-->" "</>" "</" "/>" "://"))
;; Create a new ligature:
(ligature-set-ligatures 'markdown-mode '(("=" (rx (+ "=") (? (| ">" "<"))))
("-" (rx (+ "-")))))
;; Enable all Cascadia Code ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
"<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
"##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
"?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
"\\\\" "://"))
;; Enables ligature checks globally in all buffers. You can also do it
;; per mode with `ligature-mode'.
(global-ligature-mode t))
#+end_src
Until I can get [[https://github.com/d12frosted/homebrew-emacs-plus/issues/222][Harfbuzz support]] on my Emacs-Plus build of Mac, the following work-around seems to mostly work:
#+begin_src emacs-lisp
(defun ha-mac-litagure-workaround ()
"Implement an old work-around for ligature support.
This kludge seems to only need to be set for my Mac version of
Emacs, since I can't build it with Harfuzz support."
(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
(35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)")
(36 . ".\\(?:>\\)")
(37 . ".\\(?:\\(?:%%\\)\\|%\\)")
(38 . ".\\(?:\\(?:&&\\)\\|&\\)")
(42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)")
(43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
(45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
(46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)")
(47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
(48 . ".\\(?:x[a-zA-Z]\\)")
(58 . ".\\(?:::\\|[:=]\\)")
(59 . ".\\(?:;;\\|;\\)")
(60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)")
(61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
(62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
(63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)")
(91 . ".\\(?:]\\)")
(92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
(94 . ".\\(?:=\\)")
(119 . ".\\(?:ww\\)")
(123 . ".\\(?:-\\)")
(124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
(126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)"))))
(dolist (char-regexp alist)
(set-char-table-range composition-function-table (car char-regexp)
`([,(cdr char-regexp) 0 font-shape-gstring])))))
(unless (s-contains? "HARFBUZZ" system-configuration-features)
(add-hook 'prog-mode-hook #'ha-mac-ligature-workaround))
#+end_src
The unicode-fonts package rejigs the internal tables Emacs uses to pick better fonts for unicode codepoint ranges.
#+begin_src emacs-lisp
(use-package unicode-fonts
:config
(unicode-fonts-setup))
#+end_src
** Compiling
The [[help:compile][compile]] function lets me enter a command to run, or I can search the history for a previous run. What it doesnt give me, is a project-specific list of commands. Perhaps, for each project, I define in =.dir-locals.el= a variable, =compile-command-list=, like:
#+begin_src emacs-lisp :tangle no