emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/nix-mode ae68b456f8 022/500: Refactor font lock


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode ae68b456f8 022/500: Refactor font lock
Date: Sat, 29 Jan 2022 08:26:32 -0500 (EST)

branch: elpa/nix-mode
commit ae68b456f8eae0d45221100d7f7ab0ca9ffc3922
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>

    Refactor font lock
---
 nix-mode.el | 60 +++++++++++++++++++++++++++---------------------------------
 1 file changed, 27 insertions(+), 33 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 3a5604f189..4f6ed2298b 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -36,39 +36,32 @@
         (set-match-data (list pos (point)))
         t))))
 
+(defconst nix-keywords
+  '("if" "then"
+    "else" "with"
+    "let" "in"
+    "rec" "inherit"
+    "or"
+    ))
+
+(defconst nix-builtins
+  '("builtins" "baseNameOf"
+    "derivation" "dirOf"
+    "false" "fetchTarball"
+    "import" "isNull"
+    "map" "removeAttrs"
+    "toString" "true"))
+
+(defconst nix-warning-keywords
+  '("assert" "abort" "throw"))
+
 (defconst nix-font-lock-keywords
-  '(
-    ;; keywords
-    ("\\_<if\\_>" . font-lock-keyword-face)
-    ("\\_<then\\_>" . font-lock-keyword-face)
-    ("\\_<else\\_>" . font-lock-keyword-face)
-    ("\\_<with\\_>" . font-lock-keyword-face)
-    ("\\_<let\\_>" . font-lock-keyword-face)
-    ("\\_<in\\_>" . font-lock-keyword-face)
-    ("\\_<rec\\_>" . font-lock-keyword-face)
-    ("\\_<inherit\\_>" . font-lock-keyword-face)
-    ("\\_<or\\_>" . font-lock-keyword-face)
-
-    ;; builtin functions
-    ;; taken from http://nixos.org/nix/manual/#ssec-builtins
-    ("\\_<builtins\\(\.[a-zA-Z]+\\)?\\_>" . font-lock-builtin-face)
-    ("\\_<baseNameOf\\_>" . font-lock-builtin-face)
-    ("\\_<derivation\\_>" . font-lock-builtin-face)
-    ("\\_<dirOf\\_>" . font-lock-builtin-face)
-    ("\\_<false\\_>" . font-lock-builtin-face)
-    ("\\_<fetchTarball\\_>" . font-lock-builtin-face)
-    ("\\_<import\\_>" . font-lock-builtin-face)
-    ("\\_<isNull\\_>" . font-lock-builtin-face)
-    ("\\_<map\\_>" . font-lock-builtin-face)
-    ("\\_<null\\_>" . font-lock-builtin-face)
-    ("\\_<removeAttrs\\_>" . font-lock-builtin-face)
-    ("\\_<toString\\_>" . font-lock-builtin-face)
-    ("\\_<true\\_>" . font-lock-builtin-face)
-
-    ;; warnings
-    ("\\_<assert\\_>" . font-lock-warning-face)
-    ("\\_<abort\\_>" . font-lock-warning-face)
-    ("\\_<throw\\_>" . font-lock-warning-face)
+  `(
+    (,(regexp-opt nix-keywords 'symbols) . font-lock-keyword-face)
+
+    (,(regexp-opt nix-warning-keywords 'symbols) . font-lock-warning-face)
+
+    (,(regexp-opt nix-builtins 'symbols) . font-lock-builtin-face)
 
     ("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
      . font-lock-constant-face)
@@ -78,7 +71,8 @@
      . font-lock-constant-face)
     ("[a-zA-Z0-9._\\+-]*\\(/[a-zA-Z0-9._\\+-]+\\)+"
      . font-lock-constant-face)
-    (nix-syntax-match-antiquote 0 font-lock-preprocessor-face t))
+    (nix-syntax-match-antiquote 0 font-lock-preprocessor-face t)
+  )
   "Font lock keywords for nix.")
 
 (defvar nix-mode-syntax-table



reply via email to

[Prev in Thread] Current Thread [Next in Thread]