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 ;;; Automatic font-specific ligatures
(defvar +prog-ligatures-alist (defvar +prog-ligatures-alist
'((?! . "!\\(?:\\(==\\|[!=]\\)[!=]?\\)") `((?! . ,(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 '(";;")))
(?0 . "0\\(?:\\(x[a-fA-F0-9]\\).?\\)") (?< . ,(regexp-opt '("<!--" "<$" "<$>" "<*" "<*>" "<+" "<+>" "<-" "<--" "<->" "</" "</>" "<<" "<<-" "<<<" "<<=" "<=" "<=" "<=<" "<==" "<=>" "<>" "<|" "<|>" "<~" "<~~")))
(?: . ":\\(?:\\(::\\|[:<=>]\\)[:<=>]?\\)") (?= . ,(regexp-opt '("=/=" "=:=" "=<<" "==" "===" "==>" "=>" "=>>")))
(59 . ";\\(?:\\(;\\);?\\)") ;; 59 is ; (?> . ,(regexp-opt '(">-" ">->" ">:" ">=" ">=>" ">>" ">>-" ">>=" ">>>")))
(?< . "<\\(?:\\(!--\\|\\$>\\|\\*>\\|\\+>\\|-[-<>|]\\|/>\\|<[-<=]\\|=[<>|]\\|==>?\\||>\\||||?\\|~[>~]\\|[$*+/:<=>|~-]\\)[$*+/:<=>|~-]?\\)") (?? . ,(regexp-opt '("??" "?." "?:" "?=")))
(?= . "=\\(?:\\(!=\\|/=\\|:=\\|<<\\|=[=>]\\|>>\\|[=>]\\)[=<>]?\\)") (?\[ . ,(regexp-opt '("[]" "[|]" "[|")))
(?> . ">\\(?:\\(->\\|=>\\|>[-=>]\\|[-:=>]\\)[-:=>]?\\)") (?\\ . ,(regexp-opt '("\\\\" "\\\\\\" "\\\\n")))
(?? . "?\\(?:\\([.:=?]\\)[.:=?]?\\)") (?^ . ,(regexp-opt '("^=" "^==")))
(91 . "\\[\\(?:\\(|\\)[]|]?\\)") ;; 91 is [ (?w . ,(regexp-opt '("www" "wwww")))
;; (?\ . "\\\\\\(?:\\([\\n]\\)[\\]?\\)") (?{ . ,(regexp-opt '("{-" "{|" "{||" "{|}" "{||}")))
(?^ . "^\\(?:\\(=\\)=?\\)") (?| . ,(regexp-opt '("|=" "|>" "||" "||=" "|->" "|=>" "|]" "|}")))
(?_ . "_\\(?:\\(|_\\|[_]\\)_?\\)") (?_ . ,(regexp-opt '("_|_" "__")))
(?w . "w\\(?:\\(ww\\)w?\\)") (?~ . ,(regexp-opt '("~-" "~=" "~>" "~@" "~~" "~~>"))))
(?{ . "{\\(?:\\(|\\)[|}]?\\)")
(?| . "|\\(?:\\(->\\|=>\\||[-=>]\\||||*>\\|[]=>|}-]\\).?\\)")
(?~ . "~\\(?:\\(~>\\|[-=>@~]\\)[-=>@~]?\\)"))
"An alist containing all the ligatures used when in a `+prog-ligatures-modes' mode. "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' The car is the character ASCII number, cdr is a regex which will call `font-shape-gstring'