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

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

[nongnu] elpa/nix-mode 0fd152e118 119/500: Merge pull request #22 from l


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 0fd152e118 119/500: Merge pull request #22 from ljli/various
Date: Sat, 29 Jan 2022 08:26:46 -0500 (EST)

branch: elpa/nix-mode
commit 0fd152e11836b4cd8e9d8968e99510ca34de4c07
Merge: 2f3dfd90df 1a4c98fcf7
Author: Matthew Justin Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #22 from ljli/various
    
    Small stuff
---
 nix-mode.el | 124 ++++++++++++++++++++++++++++--------------------------------
 1 file changed, 57 insertions(+), 67 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 5535a899a1..18a22d8267 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -16,8 +16,6 @@
 
 ;;; Code:
 
-(require 'cl)
-
 ;; Emacs 24.2 compatability
 (unless (fboundp 'setq-local)
   (defmacro setq-local (var val)
@@ -28,32 +26,12 @@
 
 ;;; Syntax coloring
 
-(defun nix-syntax-match-antiquote (limit)
-  "Find antiquote within a Nix expression up to LIMIT."
-  (let ((pos (next-single-char-property-change (point) 'nix-syntax-antiquote
-                                               nil limit)))
-    (when (and pos (> pos (point)) (< pos (point-max)))
-      (goto-char pos)
-      (let ((char (char-after pos)))
-        (pcase char
-          (`?{
-           (forward-char 1)
-           (set-match-data (list (1- pos) (point)))
-           t)
-          (`?}
-           (forward-char 1)
-           (set-match-data (list pos (point)))
-           t))
-        )
-      )))
-
 (defconst nix-keywords
   '("if" "then"
     "else" "with"
     "let" "in"
     "rec" "inherit"
-    "or"
-    ))
+    "or"))
 
 (defconst nix-builtins
   '("builtins" "baseNameOf"
@@ -87,10 +65,12 @@
     (,nix-re-file-path . font-lock-constant-face)
     (,nix-re-variable-assign 1 font-lock-variable-name-face)
     (,nix-re-bracket-path . 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.")
 
+(defconst nix--variable-char "[a-zA-Z0-9_'\-]")
+
 (makunbound 'nix-mode-syntax-table)
 
 (defvar nix-mode-syntax-table
@@ -106,14 +86,35 @@
     table)
   "Syntax table for Nix mode.")
 
+(defun nix--syntax-match-antiquote (limit)
+  "Find antiquote within a Nix expression up to LIMIT."
+  (unless (> (point) limit)
+    (if (get-text-property (point) 'nix-syntax-antiquote)
+        (progn
+          (set-match-data (list (point) (1+ (point))))
+          (forward-char 1)
+          t)
+      (let ((pos (next-single-char-property-change (point) 
'nix-syntax-antiquote
+                                                   nil limit)))
+        (when (and pos (not (> pos limit)))
+          (goto-char pos)
+          (let ((char (char-after pos)))
+            (pcase char
+              (`?{
+               (forward-char 1)
+               (set-match-data (list (1- pos) (point)))
+               t)
+              (`?}
+               (forward-char 1)
+               (set-match-data (list pos (point)))
+               t))))))))
+
 (defun nix--mark-string (pos string-type)
   (put-text-property pos (1+ pos)
                      'syntax-table (string-to-syntax "|"))
   (put-text-property pos (1+ pos)
                      'nix-string-type string-type))
 
-(defconst nix--variable-char "[a-zA-Z0-9_'\-]")
-
 (defun nix--get-parse-state (pos)
   (save-excursion (save-match-data (syntax-ppss pos))))
 
@@ -146,7 +147,7 @@
         (let ((str-peek (buffer-substring end (min (point-max) (+ 2 end)))))
           (if (member str-peek '("${" "\\n" "\\r" "\\t"))
               (goto-char (+ 2 end))
-              (nix--mark-string (1- end) ?\')))))))
+            (nix--mark-string (1- end) ?\')))))))
 
 (defun nix--escaped-antiquote-dq-style ()
   (let* ((start (match-beginning 0))
@@ -196,45 +197,33 @@
     (unless (nix--get-string-type ps)
       (let ((string-type (nix--open-brace-string-type ps)))
         (when string-type
-          (put-text-property start (+ 2 start)
+          (put-text-property start (1+ start)
                              'nix-string-type string-type)
           (put-text-property start (1+ start)
                              'nix-syntax-antiquote t)
           (let ((ahead (buffer-substring (1+ start) (min (point-max) (+ 5 
start)))))
-            (case string-type
-              (?\" (cond
-                    ((string-match-p "^\\\\\"" ahead)
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 3 start)))
-                    ((string-match-p "^\\\\\\${" ahead)
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 4 start)))
-                    ((string-match-p "^\"" ahead)
-                     (goto-char (+ 2 start)))
-                    (t
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 2 start)))))
-              (?\' (cond
-                    ((string-match-p "^'''" ahead)
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 4 start)))
-                    ((string-match-p "^''\\${" ahead)
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 5 start)))
-                    ((string-match-p "^''\\\\[nrt]" ahead)
-                     (put-text-property (1+ start) (+ 2 start)
-                                        'syntax-table (string-to-syntax "|"))
-                     (goto-char (+ 5 start)))
-                    ((string-match-p "^''" ahead)
-                     (goto-char (+ 3 start)))
-                    (t (put-text-property (1+ start) (+ 2 start)
-                                          'syntax-table (string-to-syntax "|"))
-                       (goto-char (+ 2 start))))))))))))
+            (pcase string-type
+              (`?\" (cond
+                     ((or (string-match "^\\\\\"" ahead)
+                          (string-match "^\\\\\\${" ahead))
+                      (nix--mark-string (1+ start) string-type)
+                      (goto-char (match-end 0)))
+                     ((string-match-p "^\"" ahead)
+                      (goto-char (+ 2 start)))
+                     ((< (1+ start) (point-max))
+                      (nix--mark-string (1+ start) string-type)
+                      (goto-char (+ 2 start)))))
+              (`?\' (cond
+                     ((or (string-match "^'''" ahead)
+                          (string-match "^''\\${" ahead)
+                          (string-match "^''\\\\[nrt]" ahead))
+                      (nix--mark-string (1+ start) string-type)
+                      (goto-char (match-end 0)))
+                     ((string-match-p "^''" ahead)
+                      (goto-char (+ 3 start)))
+                     ((< (1+ start) (point-max))
+                      (nix--mark-string (1+ start) string-type)
+                      (goto-char (+ 2 start))))))))))))
 
 (defun nix-syntax-propertize (start end)
   "Special syntax properties for Nix from START to END."
@@ -247,8 +236,10 @@
      (0 nil))
     ("\\\\\""
      (0 nil))
-    ("\\\\\\${" (0 (ignore (nix--escaped-antiquote-dq-style))))
-    ("'\\{2,\\}" (0 (ignore (nix--single-quotes))))
+    ("\\\\\\${"
+     (0 (ignore (nix--escaped-antiquote-dq-style))))
+    ("'\\{2,\\}"
+     (0 (ignore (nix--single-quotes))))
     ("}\\${"
      (0 (ignore (nix--antiquote-close-open))))
     ("\\${"
@@ -256,8 +247,7 @@
     ("}"
      (0 (ignore (nix--antiquote-close))))
     ("\""
-     (0 (ignore (nix--double-quotes))))
-    )
+     (0 (ignore (nix--double-quotes)))))
    start end))
 
 ;;; Indentation
@@ -454,7 +444,7 @@ The hook `nix-mode-hook' is run when Nix mode is started.
   (setq-local tab-width 2)
 
   ;; Font lock support.
-  (setq-local font-lock-defaults '(nix-font-lock-keywords nil nil nil nil))
+  (setq-local font-lock-defaults '(nix-font-lock-keywords))
 
   ;; Special syntax properties for Nix
   (setq-local syntax-propertize-function 'nix-syntax-propertize)



reply via email to

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