Use regexp-opt instead of manual regexes
This helps maintainability tremendously. Thanks wasamasa for the snippet
This commit is contained in:
parent
8a2f8bf260
commit
a897492b99
1 changed files with 26 additions and 29 deletions
|
@ -100,35 +100,32 @@ Otherwise it builds `prettify-code-symbols-alist' according to
|
|||
|
||||
;;; Automatic font-specific ligatures
|
||||
(defvar +prog-ligatures-alist
|
||||
'((?! . "!\\(?:\\(==\\|[!=]\\)[!=]?\\)")
|
||||
(?# . "#\\(?:\\(###?\\|_(\\|[(:=?[_{]\\)[#(:=?[_{]?\\)")
|
||||
(?$ . "$\\(?:\\(>\\)>?\\)")
|
||||
(?% . "%\\(?:\\(%\\)%?\\)")
|
||||
(?& . "&\\(?:\\(&\\)&?\\)")
|
||||
(?* . "*\\(?:\\(\\*\\*\\|[*>]\\)[*>]?\\)")
|
||||
;; (?* . "*\\(?:\\(\\*\\*\\|[*/>]\\).?\\)")
|
||||
(?+ . "+\\(?:\\([>]\\)>?\\)")
|
||||
;; (?+ . "+\\(?:\\(\\+\\+\\|[+>]\\).?\\)")
|
||||
(?- . "-\\(?:\\(-[->]\\|<<\\|>>\\|[-<>|~]\\)[-<>|~]?\\)")
|
||||
;; (?. . "\\.\\(?:\\(\\.[.<]\\|[-.=]\\)[-.<=]?\\)")
|
||||
(?. . "\\.\\(?:\\(\\.<\\|[-=]\\)[-<=]?\\)")
|
||||
(?/ . "/\\(?:\\(//\\|==\\|[=>]\\)[/=>]?\\)")
|
||||
;; (?/ . "/\\(?:\\(//\\|==\\|[*/=>]\\).?\\)")
|
||||
(?0 . "0\\(?:\\(x[a-fA-F0-9]\\).?\\)")
|
||||
(?: . ":\\(?:\\(::\\|[:<=>]\\)[:<=>]?\\)")
|
||||
(59 . ";\\(?:\\(;\\);?\\)") ;; 59 is ;
|
||||
(?< . "<\\(?:\\(!--\\|\\$>\\|\\*>\\|\\+>\\|-[-<>|]\\|/>\\|<[-<=]\\|=[<>|]\\|==>?\\||>\\||||?\\|~[>~]\\|[$*+/:<=>|~-]\\)[$*+/:<=>|~-]?\\)")
|
||||
(?= . "=\\(?:\\(!=\\|/=\\|:=\\|<<\\|=[=>]\\|>>\\|[=>]\\)[=<>]?\\)")
|
||||
(?> . ">\\(?:\\(->\\|=>\\|>[-=>]\\|[-:=>]\\)[-:=>]?\\)")
|
||||
(?? . "?\\(?:\\([.:=?]\\)[.:=?]?\\)")
|
||||
(91 . "\\[\\(?:\\(|\\)[]|]?\\)") ;; 91 is [
|
||||
;; (?\ . "\\\\\\(?:\\([\\n]\\)[\\]?\\)")
|
||||
(?^ . "^\\(?:\\(=\\)=?\\)")
|
||||
(?_ . "_\\(?:\\(|_\\|[_]\\)_?\\)")
|
||||
(?w . "w\\(?:\\(ww\\)w?\\)")
|
||||
(?{ . "{\\(?:\\(|\\)[|}]?\\)")
|
||||
(?| . "|\\(?:\\(->\\|=>\\||[-=>]\\||||*>\\|[]=>|}-]\\).?\\)")
|
||||
(?~ . "~\\(?:\\(~>\\|[-=>@~]\\)[-=>@~]?\\)"))
|
||||
`((?! . ,(regexp-opt '("!!" "!=" "!==")))
|
||||
(?# . ,(regexp-opt '("##" "###" "####" "#(" "#:" "#=" "#?" "#[" "#_" "#_(" "#{")))
|
||||
(?$ . ,(regexp-opt '("$>" "$>>")))
|
||||
(?% . ,(regexp-opt '("%%" "%%%")))
|
||||
(?& . ,(regexp-opt '("&&" "&&&")))
|
||||
(?* . ,(regexp-opt '("*" "**" "***" "**/" "*/" "*>")))
|
||||
(?+ . ,(regexp-opt '("+" "++" "+++" "+>")))
|
||||
(?- . ,(regexp-opt '("--" "---" "-->" "-<" "-<<" "->" "->>" "-}" "-~")))
|
||||
(?. . ,(regexp-opt '(".-" ".." "..." "..<" ".=")))
|
||||
(?/ . ,(regexp-opt '("/*" "/**" "//" "///" "/=" "/==" "/>")))
|
||||
(?: . ,(regexp-opt '(":" "::" ":::" ":=" ":<" ":=" ":>")))
|
||||
(?0 . "0\\(?:\\(x[a-fA-F0-9]\\).?\\)") ; Tries to match the x in 0xDEADBEEF
|
||||
;; (?x . ,(regexp-opt '("x"))) ; Also tries to match the x in 0xDEADBEEF
|
||||
(?\; . ,(regexp-opt '(";;")))
|
||||
(?< . ,(regexp-opt '("<!--" "<$" "<$>" "<*" "<*>" "<+" "<+>" "<-" "<--" "<->" "</" "</>" "<<" "<<-" "<<<" "<<=" "<=" "<=" "<=<" "<==" "<=>" "<>" "<|" "<|>" "<~" "<~~")))
|
||||
(?= . ,(regexp-opt '("=/=" "=:=" "=<<" "==" "===" "==>" "=>" "=>>")))
|
||||
(?> . ,(regexp-opt '(">-" ">->" ">:" ">=" ">=>" ">>" ">>-" ">>=" ">>>")))
|
||||
(?? . ,(regexp-opt '("??" "?." "?:" "?=")))
|
||||
(?\[ . ,(regexp-opt '("[]" "[|]" "[|")))
|
||||
(?\\ . ,(regexp-opt '("\\\\" "\\\\\\" "\\\\n")))
|
||||
(?^ . ,(regexp-opt '("^=" "^==")))
|
||||
(?w . ,(regexp-opt '("www" "wwww")))
|
||||
(?{ . ,(regexp-opt '("{-" "{|" "{||" "{|}" "{||}")))
|
||||
(?| . ,(regexp-opt '("|=" "|>" "||" "||=" "|->" "|=>" "|]" "|}")))
|
||||
(?_ . ,(regexp-opt '("_|_" "__")))
|
||||
(?~ . ,(regexp-opt '("~-" "~=" "~>" "~@" "~~" "~~>"))))
|
||||
"An alist containing all the ligatures used when in a `+prog-ligatures-modes' mode.
|
||||
|
||||
The car is the character ASCII number, cdr is a regex which will call `font-shape-gstring'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue