Use regexp-opt instead of manual regexes

This helps maintainability tremendously. Thanks wasamasa for the snippet
This commit is contained in:
Gerry Agbobada 2020-04-26 12:17:43 +02:00 committed by Gerry Agbobada
parent 8a2f8bf260
commit a897492b99
No known key found for this signature in database
GPG key ID: BE26DBAFD866BE34

View file

@ -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'