-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FiraCode “Ligature” integration #6972
Comments
Is there a reason why prettify-symbols-mode is not being used for this? |
Probably not, no. But it looks awesome. |
I'm not sure if that's the right solution here, as it looks like prettify-symbols-mode alters the number of characters per row, while the ligature rendering preserves that property. For instance, using FiraCode in Konsole would make "->" become an arrow but still take up two characters. Similarly, "::", ">>=", et al. conserve that many characters, keeping the spacing correct. However, if prettify-symbols-mode can keep the character count, then that works too. |
So to install and use Fira code with spacemacs, does one follow the instructions for emacs from the fira code project site [1], or there is already some mechanism in spacemacs that can use fira code so that the user only needs to "helm xselect font" the Fira Code Retina? I would very much like to use Fira Code in Spacemacs, but am trying not to break anything. I am just coming from Vim, and know almost nothing about Lisp except what is taught in Wikipedia. I tried putting the first snippet provided in that page to my .spacemacs file within the user-config() function, but after restarting, when I restart spacemacs and type "=>", nothing changes (I do not see a ligature). [1] https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs |
I haven’t yet looked at it any further, maybe the regex-method works, but I suspect it to severely slow down every kind of text display. (It’s essentially running a couple dozen matches on every substring in each buffer…) |
News! It seems to work with firacode now. If anyone wants to take a look: go for it! |
Another update: Hasklig seems to have moved to the FiraCode mechanism with 1.0 as well. So getting this to work would give us two fonts to choose from. |
Unfortunately that method still does not allow multiple blocks to be taken up by a single ligature (from the website @Profpatsch linked to). This is problematic for coding:
|
Oh no. Maybe it can be patched? |
I think that prettify would have to support adding in the lost space. |
Well, these fonts make the ligatures exactly as wide as the normal combinations, so it must support multi-width characters as well. |
Hi I wrote the blog on pretty-mode linked earlier. The options as I see it are:
I took a shot at the hook:
This works in all cases that The glaring flaws are the sleep and that save-file cannot tell anymore when your file hasn't changed, especially annoying with eg magit. Number 6 is the only true solution I see to this problem but it seems quite involved. Any other thoughts on how spacing could be handled? |
I implemented the visual spacing solution: I only afterwards noticed that it’s not perfect, but it works fine for me right now with Hasklig. My idea would be to switch back to non-visual and tag every symbol with the number of spaces it occupies, then prefix them with spaces accordingly. I think I’m gonna try that next. |
When I use Fira Code in Spacemacs even without ligature support sometimes the character alignment is off, specifically where line 1 uses bold for some characters, and line 2 doesn't have bold, then they don't line up vertically. What could be causing this? |
@Profpatsch did you considered making a MELPA package from your code? |
@root42 No, not really. But if you want one, go ahead. You have my blessing. :) It’s MIT-licensed anyway. |
@Profpatsch How can I plug that into my |
@honza Just copy the code verbatim, then |
Putting this code: (defun my-correct-symbol-bounds (pretty-alist)
"Prepend a TAB character to each symbol in this alist,
this way compose-region called by prettify-symbols-mode
will use the correct width of the symbols
instead of the width measured by char-width."
(mapcar (lambda (el)
(setcdr el (string ?\t (cdr el)))
el)
pretty-alist))
(defun my-ligature-list (ligatures codepoint-start)
"Create an alist of strings to replace with
codepoints starting from codepoint-start."
(let ((codepoints (-iterate '1+ codepoint-start (length ligatures))))
(-zip-pair ligatures codepoints)))
(setq my-fira-code-ligatures
(let* ((ligs '("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\"
"{-" "[]" "::" ":::" ":=" "!!" "!=" "!==" "-}"
"--" "---" "-->" "->" "->>" "-<" "-<<" "-~"
"#{" "#[" "##" "###" "####" "#(" "#?" "#_" "#_("
".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*"
"/**" "/=" "/==" "/>" "//" "///" "&&" "||" "||="
"|=" "|>" "^=" "$>" "++" "+++" "+>" "=:=" "=="
"===" "==>" "=>" "=>>" "<=" "=<<" "=/=" ">-" ">="
">=>" ">>" ">>-" ">>=" ">>>" "<*" "<*>" "<|" "<|>"
"<$" "<$>" "<!--" "<-" "<--" "<->" "<+" "<+>" "<="
"<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" "<~"
"<~~" "</" "</>" "~@" "~-" "~=" "~>" "~~" "~~>" "%%"
"x" ":" "+" "+" "*")))
(my-correct-symbol-bounds (my-ligature-list ligs #Xe100)))) to the |
You forgot the code that adds it to the hooks that are called when you enable a mode. ;; nice glyphs for haskell with hasklig
(defun my-set-hasklig-ligatures ()
"Add hasklig ligatures for use with prettify-symbols-mode."
(setq prettify-symbols-alist
(append my-hasklig-ligatures prettify-symbols-alist))
(prettify-symbols-mode))
(add-hook 'haskell-mode-hook 'my-set-hasklig-ligatures) For FiraCode change accordingly. |
@Profpatsch Ah, thanks! I was hoping to enable it globally. |
I can confirm that works wonderfully. Thanks @Profpatsch <3 |
Afaik inherits every mode from |
I've developed a proof of concept fix to ligature indentation that you all might find interesting: http://www.modernemacs.com/post/lig-spacing/ |
Fixed! Thanks @gustavAR 👍 Btw now my themes are displaying correctly, and is faster than before! |
This issue is quite long and there are many comments, some specific to macOS and some not. As a debian spacemacs user, is there a known solution/workaround to make FiraCode work in (spac)emacs with ligatures not affecting line length? |
@abeluck Have you tried this and followed the conversation for a few messages from this timestamp? |
@gustavAR As far as I know, |
I made a ticket about this, i.e. a specific implementation already exists #11639 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid! |
@github-actions this issue is still open and awaits action from the devs to support in the @Profpatsch not sure which one is more convenient/easy to do: writing up a layer for spacemacs, or publishing a melpa package? |
I don’t know, I have never created a melpa package |
We should keep this issue open. |
Another solution is to use homebrew to install the cask of emacs-mac instead of building from a recipe. It trails the version available via recipe sometimes, but otherwise it's solid and it installs |
You can also use the development version of Emacs (28) which has ligature support. emacs-plus@28 on homebrew. https://github.com/d12frosted/homebrew-emacs-plus |
@barischrooneyj care to share your set up for the ligature support in Emacs 28? There was HarfBuzz support there but seemed it seeded some configuration [1,2]. [1] https://www.reddit.com/r/emacs/comments/byddvm/emacsdevel_harfbuzz_is_now_available_on_master/ |
I think even Emacs 27 has the support too. microsoft/cascadia-code#153 (comment). Use the config from it, I have tested with JetBrainsMono FiraCode. |
Copied from microsoft/cascadia-code#153 (comment) for convenience here: (use-package composite
:defer t
:init
(defvar composition-ligature-table (make-char-table nil))
:hook
(((prog-mode conf-mode nxml-mode markdown-mode help-mode)
. (lambda () (setq-local composition-function-table composition-ligature-table))))
:config
;; support ligatures, some toned down to prevent hang
(when (version<= "27.0" emacs-version)
(let ((alist
'((33 . ".\\(?:\\(==\\|[!=]\\)[!=]?\\)")
(35 . ".\\(?:\\(###?\\|_(\\|[(:=?[_{]\\)[#(:=?[_{]?\\)")
(36 . ".\\(?:\\(>\\)>?\\)")
(37 . ".\\(?:\\(%\\)%?\\)")
(38 . ".\\(?:\\(&\\)&?\\)")
(42 . ".\\(?:\\(\\*\\*\\|[*>]\\)[*>]?\\)")
;; (42 . ".\\(?:\\(\\*\\*\\|[*/>]\\).?\\)")
(43 . ".\\(?:\\([>]\\)>?\\)")
;; (43 . ".\\(?:\\(\\+\\+\\|[+>]\\).?\\)")
(45 . ".\\(?:\\(-[->]\\|<<\\|>>\\|[-<>|~]\\)[-<>|~]?\\)")
;; (46 . ".\\(?:\\(\\.[.<]\\|[-.=]\\)[-.<=]?\\)")
(46 . ".\\(?:\\(\\.<\\|[-=]\\)[-<=]?\\)")
(47 . ".\\(?:\\(//\\|==\\|[=>]\\)[/=>]?\\)")
;; (47 . ".\\(?:\\(//\\|==\\|[*/=>]\\).?\\)")
(48 . ".\\(?:\\(x[a-fA-F0-9]\\).?\\)")
(58 . ".\\(?:\\(::\\|[:<=>]\\)[:<=>]?\\)")
(59 . ".\\(?:\\(;\\);?\\)")
(60 . ".\\(?:\\(!--\\|\\$>\\|\\*>\\|\\+>\\|-[-<>|]\\|/>\\|<[-<=]\\|=[<>|]\\|==>?\\||>\\||||?\\|~[>~]\\|[$*+/:<=>|~-]\\)[$*+/:<=>|~-]?\\)")
(61 . ".\\(?:\\(!=\\|/=\\|:=\\|<<\\|=[=>]\\|>>\\|[=>]\\)[=<>]?\\)")
(62 . ".\\(?:\\(->\\|=>\\|>[-=>]\\|[-:=>]\\)[-:=>]?\\)")
(63 . ".\\(?:\\([.:=?]\\)[.:=?]?\\)")
(91 . ".\\(?:\\(|\\)[]|]?\\)")
;; (92 . ".\\(?:\\([\\n]\\)[\\]?\\)")
(94 . ".\\(?:\\(=\\)=?\\)")
(95 . ".\\(?:\\(|_\\|[_]\\)_?\\)")
(119 . ".\\(?:\\(ww\\)w?\\)")
(123 . ".\\(?:\\(|\\)[|}]?\\)")
(124 . ".\\(?:\\(->\\|=>\\||[-=>]\\||||*>\\|[]=>|}-]\\).?\\)")
(126 . ".\\(?:\\(~>\\|[-=>@~]\\)[-=>@~]?\\)"))))
(dolist (char-regexp alist)
(set-char-table-range composition-ligature-table (car char-regexp)
`([,(cdr char-regexp) 0 font-shape-gstring]))))
(set-char-table-parent composition-ligature-table composition-function-table))
) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid! |
👾 👾 👾 activityyyyy |
There will be no ligature for any specific font. But ligature in general is already supported with unicode-fonts layer. The only issue is currently it won't work with Emacs 27. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid! |
FiraCode is a nice derivation from Fira Mono that adds many ligatures for a nice code look. It uses Unicode ligatures, but Emacs sadly doesn’t support them (yet). I’d like to add a layer to Spacemacs to support that.
There is a page about integration into Emacs via font-lock, and the second example is also how Hasklig can be made to work with Emacs. I noticed integrating too many ligatures that way makes font rendering very slow.
The text was updated successfully, but these errors were encountered: