mirror of
https://github.com/tonsky/FiraCode.git
synced 2024-10-04 00:31:49 +03:00
Restructure the page so the best options are at the top of the document
parent
cf23655cef
commit
370d788c78
@ -1,4 +1,101 @@
|
||||
Put this lisp in your `.emacs` (thanks [Sean Farley](https://github.com/seanfarley) for putting this together; extended by [Jason Blevins](https://github.com/jrblevin)):
|
||||
There are a few options when it comes down to using ligatures in
|
||||
Emacs. They are listed in order of preferred to less-preferred. Pick one!
|
||||
|
||||
- [Using composition mode in Emacs Mac port](#using-composition-mode-in-emacs-mac-port)
|
||||
- [Using prettify-symbols](#using-prettify-symbols)
|
||||
- [Using composition char table](#using-composition-char-table)
|
||||
- [Using font-lock keywords](#using-font-lock-keywords)
|
||||
|
||||
### Using composition mode in Emacs Mac port
|
||||
|
||||
If you're using the latest [Mac port](https://bitbucket.org/mituharu/emacs-mac)
|
||||
of Emacs (by Mitsuharu Yamamoto) for macOS, you can use:
|
||||
|
||||
```elisp
|
||||
(mac-auto-operator-composition-mode)
|
||||
```
|
||||
|
||||
This is generally the easiest solution, but can only be used on macOS.
|
||||
|
||||
### Using prettify-symbols
|
||||
|
||||
These instructions are pieced together by [@Triavanicus](https://github.com/Triavanicus),
|
||||
taking some pieces from: [Hasklig-Mode](https://github.com/minad/hasklig-mode).
|
||||
|
||||
This method requires you to install the Fira Code Symbol font, made by [@siegebell](https://github.com/siegebell):
|
||||
https://github.com/tonsky/FiraCode/issues/211#issuecomment-239058632
|
||||
|
||||
```elisp
|
||||
(defun fira-code-mode--make-alist (list)
|
||||
"Generate prettify-symbols alist from LIST."
|
||||
(let ((idx -1))
|
||||
(mapcar
|
||||
(lambda (s)
|
||||
(setq idx (1+ idx))
|
||||
(let* ((code (+ #Xe100 idx))
|
||||
(width (string-width s))
|
||||
(prefix ())
|
||||
(suffix '(?\s (Br . Br)))
|
||||
(n 1))
|
||||
(while (< n width)
|
||||
(setq prefix (append prefix '(?\s (Br . Bl))))
|
||||
(setq n (1+ n)))
|
||||
(cons s (append prefix suffix (list (decode-char 'ucs code))))))
|
||||
list)))
|
||||
|
||||
(defconst fira-code-mode--ligatures
|
||||
'("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\"
|
||||
"{-" "[]" "::" ":::" ":=" "!!" "!=" "!==" "-}"
|
||||
"--" "---" "-->" "->" "->>" "-<" "-<<" "-~"
|
||||
"#{" "#[" "##" "###" "####" "#(" "#?" "#_" "#_("
|
||||
".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*"
|
||||
"/**" "/=" "/==" "/>" "//" "///" "&&" "||" "||="
|
||||
"|=" "|>" "^=" "$>" "++" "+++" "+>" "=:=" "=="
|
||||
"===" "==>" "=>" "=>>" "<=" "=<<" "=/=" ">-" ">="
|
||||
">=>" ">>" ">>-" ">>=" ">>>" "<*" "<*>" "<|" "<|>"
|
||||
"<$" "<$>" "<!--" "<-" "<--" "<->" "<+" "<+>" "<="
|
||||
"<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" "<~"
|
||||
"<~~" "</" "</>" "~@" "~-" "~=" "~>" "~~" "~~>" "%%"
|
||||
"x" ":" "+" "+" "*"))
|
||||
|
||||
(defvar fira-code-mode--old-prettify-alist)
|
||||
|
||||
(defun fira-code-mode--enable ()
|
||||
"Enable Fira Code ligatures in current buffer."
|
||||
(setq-local fira-code-mode--old-prettify-alist prettify-symbols-alist)
|
||||
(setq-local prettify-symbols-alist (append (fira-code-mode--make-alist fira-code-mode--ligatures) fira-code-mode--old-prettify-alist))
|
||||
(prettify-symbols-mode t))
|
||||
|
||||
(defun fira-code-mode--disable ()
|
||||
"Disable Fira Code ligatures in current buffer."
|
||||
(setq-local prettify-symbols-alist fira-code-mode--old-prettify-alist)
|
||||
(prettify-symbols-mode -1))
|
||||
|
||||
(define-minor-mode fira-code-mode
|
||||
"Fira Code ligatures minor mode"
|
||||
:lighter " Fira Code"
|
||||
(setq-local prettify-symbols-unprettify-at-point 'right-edge)
|
||||
(if fira-code-mode
|
||||
(fira-code-mode--enable)
|
||||
(fira-code-mode--disable)))
|
||||
|
||||
(defun fira-code-mode--setup ()
|
||||
"Setup Fira Code Symbols"
|
||||
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol"))
|
||||
|
||||
(provide 'fira-code-mode)
|
||||
```
|
||||
|
||||
#### Alternative instructions
|
||||
|
||||
https://github.com/Profpatsch/blog/blob/master/posts/ligature-emulation-in-emacs/post.md#appendix-b-update-1-firacode-integration
|
||||
|
||||
### Using composition char table
|
||||
|
||||
Put this lisp in your `.emacs`.
|
||||
|
||||
Thanks to [Sean Farley](https://github.com/seanfarley) for putting this together; extended by [Jason Blevins](https://github.com/jrblevin).
|
||||
|
||||
```elisp
|
||||
(when (window-system)
|
||||
(set-frame-font "Fira Code"))
|
||||
@ -33,13 +130,16 @@ Put this lisp in your `.emacs` (thanks [Sean Farley](https://github.com/seanfarl
|
||||
`([,(cdr char-regexp) 0 font-shape-gstring]))))
|
||||
```
|
||||
|
||||
Note! If you get `error in process filter: Attempt to shape unibyte text`, check out [this issue](https://github.com/tonsky/FiraCode/issues/42). [Emacs Cider](https://github.com/clojure-emacs/cider) users may avoid this issue by commenting the following line from the above config:
|
||||
**Note!** If you get `error in process filter: Attempt to shape unibyte text`,
|
||||
check out [this issue](https://github.com/tonsky/FiraCode/issues/42).
|
||||
[Emacs Cider](https://github.com/clojure-emacs/cider)
|
||||
users may avoid this issue by commenting the following line from the above config:
|
||||
|
||||
```elisp
|
||||
;; (46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)")
|
||||
```
|
||||
|
||||
Char 45 is also known to have issues in OSX Mojave.
|
||||
Char `45` is also known to have issues in macOS Mojave.
|
||||
|
||||
If you are having problems with helm you can disable ligatures in helm:
|
||||
|
||||
@ -47,16 +147,14 @@ If you are having problems with helm you can disable ligatures in helm:
|
||||
(add-hook 'helm-major-mode-hook
|
||||
(lambda ()
|
||||
(setq auto-composition-mode nil)))
|
||||
|
||||
```
|
||||
|
||||
If you're using the latest [Mac port](https://bitbucket.org/mituharu/emacs-mac) of Emacs (by Mitsuharu Yamamoto), you can instead use:
|
||||
### Using font-lock keywords
|
||||
|
||||
```elisp
|
||||
(mac-auto-operator-composition-mode)
|
||||
```
|
||||
If none of the above worked, you can try this method.
|
||||
|
||||
None of the above worked for me for emacs 24.5.1 on Debian Linux. So, after @siegebell made Fira Code Symbol font due to https://github.com/tonsky/FiraCode/issues/211 I spent several hours putting the following together which works for me:
|
||||
This method requires you to install the Fira Code Symbol font, made by [@siegebell](https://github.com/siegebell):
|
||||
https://github.com/tonsky/FiraCode/issues/211#issuecomment-239058632
|
||||
|
||||
```elisp
|
||||
;;; Fira code
|
||||
@ -73,7 +171,7 @@ None of the above worked for me for emacs 24.5.1 on Debian Linux. So, after @sie
|
||||
(compose-region (match-beginning 1)
|
||||
(match-end 1)
|
||||
;; The first argument to concat is a string containing a literal tab
|
||||
,(concat " " (list (decode-char 'ucs (cadr regex-char-pair)))))))))
|
||||
,(concat " " (list (decode-char 'ucs (cadr regex-char-pair)))))))))
|
||||
'(("\\(www\\)" #Xe100)
|
||||
("[^/]\\(\\*\\*\\)[^/]" #Xe101)
|
||||
("\\(\\*\\*\\*\\)" #Xe102)
|
||||
@ -199,66 +297,3 @@ On some systems, `==` will appear incorrectly as a blank space in certain modes
|
||||
(set-language-environment "UTF-8")
|
||||
(set-default-coding-systems 'utf-8)
|
||||
```
|
||||
|
||||
After piecing together a few things (namely [Hasklig-Mode](https://github.com/minad/hasklig-mode)) I managed to come up with this:
|
||||
|
||||
```elisp
|
||||
(defun fira-code-mode--make-alist (list)
|
||||
"Generate prettify-symbols alist from LIST."
|
||||
(let ((idx -1))
|
||||
(mapcar
|
||||
(lambda (s)
|
||||
(setq idx (1+ idx))
|
||||
(let* ((code (+ #Xe100 idx))
|
||||
(width (string-width s))
|
||||
(prefix ())
|
||||
(suffix '(?\s (Br . Br)))
|
||||
(n 1))
|
||||
(while (< n width)
|
||||
(setq prefix (append prefix '(?\s (Br . Bl))))
|
||||
(setq n (1+ n)))
|
||||
(cons s (append prefix suffix (list (decode-char 'ucs code))))))
|
||||
list)))
|
||||
|
||||
(defconst fira-code-mode--ligatures
|
||||
'("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\"
|
||||
"{-" "[]" "::" ":::" ":=" "!!" "!=" "!==" "-}"
|
||||
"--" "---" "-->" "->" "->>" "-<" "-<<" "-~"
|
||||
"#{" "#[" "##" "###" "####" "#(" "#?" "#_" "#_("
|
||||
".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*"
|
||||
"/**" "/=" "/==" "/>" "//" "///" "&&" "||" "||="
|
||||
"|=" "|>" "^=" "$>" "++" "+++" "+>" "=:=" "=="
|
||||
"===" "==>" "=>" "=>>" "<=" "=<<" "=/=" ">-" ">="
|
||||
">=>" ">>" ">>-" ">>=" ">>>" "<*" "<*>" "<|" "<|>"
|
||||
"<$" "<$>" "<!--" "<-" "<--" "<->" "<+" "<+>" "<="
|
||||
"<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" "<~"
|
||||
"<~~" "</" "</>" "~@" "~-" "~=" "~>" "~~" "~~>" "%%"
|
||||
"x" ":" "+" "+" "*"))
|
||||
|
||||
(defvar fira-code-mode--old-prettify-alist)
|
||||
|
||||
(defun fira-code-mode--enable ()
|
||||
"Enable Fira Code ligatures in current buffer."
|
||||
(setq-local fira-code-mode--old-prettify-alist prettify-symbols-alist)
|
||||
(setq-local prettify-symbols-alist (append (fira-code-mode--make-alist fira-code-mode--ligatures) fira-code-mode--old-prettify-alist))
|
||||
(prettify-symbols-mode t))
|
||||
|
||||
(defun fira-code-mode--disable ()
|
||||
"Disable Fira Code ligatures in current buffer."
|
||||
(setq-local prettify-symbols-alist fira-code-mode--old-prettify-alist)
|
||||
(prettify-symbols-mode -1))
|
||||
|
||||
(define-minor-mode fira-code-mode
|
||||
"Fira Code ligatures minor mode"
|
||||
:lighter " Fira Code"
|
||||
(setq-local prettify-symbols-unprettify-at-point 'right-edge)
|
||||
(if fira-code-mode
|
||||
(fira-code-mode--enable)
|
||||
(fira-code-mode--disable)))
|
||||
|
||||
(provide 'fira-code-mode)
|
||||
```
|
||||
|
||||
# Alternative instruction
|
||||
|
||||
https://github.com/Profpatsch/blog/blob/master/posts/ligature-emulation-in-emacs/post.md#appendix-b-update-1-firacode-integration
|
Loading…
Reference in New Issue
Block a user