emacs目前不支持连字(在OSX上有一些支持,但在其他平台上不支持)。但是,emacs 24.4+支持prettify-symbols-mode
在某些方面比普通的连字支持更好。
该模式允许用任何字形替换显示任何正则表达式。我个人使用此代码片段获取Fira代码连字以在Linux上的emacs中工作。(编辑:不幸的是,链接现在已经死了,总是复制内联的stackoverflow策略显然是个好方法...)
我最初放置的链接已死,我不确定它包含的内容是什么,但我认为这些链接应该很好:https :
//github.com/tonsky/FiraCode/wiki/Emacs-instructions#using-prettify-symbols和https://github.com/tonsky/FiraCode/issues/312#issuecomment-262878734
考虑到无效链接的问题,这次我将代码插入内联:
(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)
我说过,从某种意义上说,这比普通的连字更好。.因为这是“点菜”。您可以混合搭配,仅使用自己喜欢的符号。您可以说,我要“ ;;” 连字,如果下一个字符再次为“;”则除外 在那种情况下,我不想要它...关于混合匹配...我使用的是'Fira Mono'字体和'Fira Code'连字。您不必购买整个字体。
它比纯连字更糟,因为它不能立即使用,并且需要以某种方式调整字体以使其可行。