[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 4ce19a966b 095/500: Merge branch 'ljli-fonticatio
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 4ce19a966b 095/500: Merge branch 'ljli-fontication' |
Date: |
Sat, 29 Jan 2022 08:26:39 -0500 (EST) |
branch: elpa/nix-mode
commit 4ce19a966b1591e7e9bc60eda7e37b44da4b736e
Merge: 836e14fdd4 ea23a301d7
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Merge branch 'ljli-fontication'
---
nix-mode.el | 218 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 134 insertions(+), 84 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index 36a1791cb1..425060b517 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -22,22 +22,7 @@
"Set variable VAR to value VAL in current buffer."
`(set (make-local-variable ',var) ,val)))
-;; 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 2))
- (`?}
- (forward-char 1)))
- (set-match-data (list pos (point)))
- t))))
+;;; Syntax coloring
(defconst nix-keywords
'("if" "then"
@@ -78,8 +63,7 @@
(,nix-re-url . font-lock-constant-face)
(,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-re-bracket-path . font-lock-constant-face))
"Font lock keywords for nix.")
(defvar nix-mode-syntax-table
@@ -88,89 +72,153 @@
(modify-syntax-entry ?* ". 23" table)
(modify-syntax-entry ?# "< b" table)
(modify-syntax-entry ?\n "> b" table)
+ ;; We handle strings
+ (modify-syntax-entry ?\" "." table)
+ ;; We handle escapes
+ (modify-syntax-entry ?\\ "." table)
table)
"Syntax table for Nix mode.")
-(defun nix-syntax-propertize-multiline-string ()
- "Set syntax properies for multiline string delimiters."
- (let* ((start (match-beginning 0))
- (context (save-excursion (save-match-data (syntax-ppss start))))
- (string-type (nth 3 context)))
+(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))))
- (pcase string-type
+(defun nix--get-string-type (parse-state)
+ (let ((string-start (nth 8 parse-state)))
+ (and string-start (get-text-property string-start 'nix-string-type))))
- (`t
- ;; inside a multiline string
- ;; ending multi-line string delimiter
- (put-text-property (1+ start) (+ 2 start)
- 'syntax-table (string-to-syntax "|")))
+(defun nix--open-brace-string-type (parse-state)
+ (let ((open-brace (nth 1 parse-state)))
+ (and open-brace (get-text-property open-brace 'nix-string-type))))
- (`nil
- ;; beginning multi-line string delimiter
- (put-text-property start (1+ start)
- 'syntax-table (string-to-syntax "|"))))))
+(defun nix--open-brace-antiquote-p (parse-state)
+ (let ((open-brace (nth 1 parse-state)))
+ (and open-brace (get-text-property open-brace 'nix-syntax-antiquote))))
-(defun nix-syntax-propertize-antiquote ()
- "Set syntax properties for an antiquote mark."
+(defun nix--single-quotes ()
(let* ((start (match-beginning 0))
- (context (save-excursion (save-match-data (syntax-ppss start))))
- (string-type (nth 3 context)))
-
- (when string-type ;; only add antiquote when we're already in a string
- (put-text-property start (1+ start)
- 'syntax-table (string-to-syntax "|"))
- (put-text-property start (+ 2 start)
- 'nix-syntax-antiquote t))))
-
-(defun nix-syntax-propertize-close-brace ()
- "Set syntax properties for close braces.
-If a close brace `}' ends an antiquote, the next character begins a string."
+ (end (match-end 0))
+ (context (nix--get-parse-state start))
+ (string-type (nix--get-string-type context)))
+ (unless (or (equal string-type ?\")
+ (and (equal string-type nil)
+ (string-match-p nix--variable-char
+ (buffer-substring (1- start) start))))
+ (when (equal string-type nil)
+ (nix--mark-string start ?\')
+ (setq start (+ 2 start)))
+ (when (equal (mod (- end start) 3) 2)
+ (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) ?\')))))))
+
+(defun nix--escaped-antiquote-dq-style ()
(let* ((start (match-beginning 0))
- (context (save-excursion (save-match-data (syntax-ppss start))))
- (open (nth 1 context)))
-
- (when open ;; a corresponding open-brace was found
- (when (get-text-property open 'nix-syntax-antiquote)
- (put-text-property start (1+ start)
- 'syntax-table (string-to-syntax "|"))
- (put-text-property start (1+ start)
- 'nix-syntax-antiquote t)))))
-
-(defun nix-syntax-propertize-escaped-antiquote ()
- "Set syntax properties for escaped antiquote."
+ (ps (nix--get-parse-state start))
+ (string-type (nix--get-string-type ps)))
+ (when (equal string-type ?\')
+ (nix--antiquote-open-at (1+ start) ?\'))))
+
+(defun nix--double-quotes ()
+ (let* ((pos (match-beginning 0))
+ (ps (nix--get-parse-state pos))
+ (string-type (nix--get-string-type ps)))
+ (unless (equal string-type ?\')
+ (nix--mark-string pos ?\"))))
+
+(defun nix--antiquote-open-at (pos string-type)
+ (put-text-property pos (1+ pos)
+ 'syntax-table (string-to-syntax "|"))
+ (put-text-property pos (+ 2 pos)
+ 'nix-string-type string-type)
+ (put-text-property (1+ pos) (+ 2 pos)
+ 'nix-syntax-antiquote t))
+
+(defun nix--antiquote-open ()
(let* ((start (match-beginning 0))
- (context (save-excursion (save-match-data (syntax-ppss start))))
- (string-type (nth 3 context)))
-
- ;; treat like multiline when not already in string
- ;; else ignore
- (when (not string-type)
- (put-text-property start (1+ start)
- 'syntax-table (string-to-syntax "|"))
-
- (when (string= (buffer-substring (+ 2 start) (+ 4 start)) "${")
- (put-text-property (+ 2 start) (+ 3 start)
- 'syntax-table (string-to-syntax "|"))
- (put-text-property (+ 2 start) (+ 4 start)
- 'nix-syntax-antiquote t))
- )
- ))
+ (ps (nix--get-parse-state start))
+ (string-type (nix--get-string-type ps)))
+ (when string-type
+ (nix--antiquote-open-at start string-type))))
+
+(defun nix--antiquote-close-open ()
+ (let* ((start (match-beginning 0))
+ (ps (nix--get-parse-state start)))
+ (when (and (not (nix--get-string-type ps))
+ (nix--open-brace-antiquote-p ps))
+ (let ((string-type (nix--open-brace-string-type ps)))
+ (put-text-property start (+ 3 start)
+ 'nix-string-type string-type)
+ (put-text-property start (1+ start)
+ 'nix-syntax-antiquote t)
+ (put-text-property (+ 2 start) (+ 3 start)
+ 'nix-syntax-antiquote t)))))
+
+(defun nix--antiquote-close ()
+ (let* ((start (match-beginning 0))
+ (ps (nix--get-parse-state start)))
+ (unless (nix--get-string-type ps)
+ (let ((string-type (nix--open-brace-string-type ps)))
+ (when string-type
+ (put-text-property start (+ 2 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
+ (?\" (unless (string-match-p "^\"" ahead)
+ (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))))))))))))
(defun nix-syntax-propertize (start end)
"Special syntax properties for Nix from START to END."
- ;; search for multi-line string delimiters
(goto-char start)
- (remove-text-properties start end '(syntax-table nil nix-syntax-antiquote
nil))
+ (remove-text-properties start end
+ '(syntax-table nil nix-string-type nil
nix-syntax-antiquote nil))
(funcall
(syntax-propertize-rules
- ("''['\\$\]" ;; ignore ''* characters
- (0 (ignore (nix-syntax-propertize-escaped-antiquote))))
- ("''"
- (0 (ignore (nix-syntax-propertize-multiline-string))))
+ ("\\\\\\\\"
+ (0 nil))
+ ("\\\\\""
+ (0 nil))
+ ("\\\\\\${" (0 (ignore (nix--escaped-antiquote-dq-style))))
+ ("'\\{2,\\}" (0 (ignore (nix--single-quotes))))
+ ("}\\${"
+ (0 (ignore (nix--antiquote-close-open))))
("\\${"
- (0 (ignore (nix-syntax-propertize-antiquote))))
+ (0 (ignore (nix--antiquote-open))))
("}"
- (0 (ignore (nix-syntax-propertize-close-brace)))))
+ (0 (ignore (nix--antiquote-close))))
+ ("\""
+ (0 (ignore (nix--double-quotes))))
+ )
start end))
@@ -519,7 +567,9 @@ The hook `nix-mode-hook' is run when Nix mode is started.
\\{nix-mode-map}
"
- (set-syntax-table nix-mode-syntax-table)
+ :syntax-table nix-mode-syntax-table
+
+ (setq-local case-fold-search nil)
;; Disable hard tabs and set tab to 2 spaces
;; Recommended by nixpkgs manual:
https://nixos.org/nixpkgs/manual/#sec-syntax
- [nongnu] elpa/nix-mode f3b4215166 004/500: Update metadata, (continued)
- [nongnu] elpa/nix-mode f3b4215166 004/500: Update metadata, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 69c7c87caa 017/500: Sert comment-multi-line., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 83229f0d4c 041/500: Fix flycheck errors., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 76ad5882f0 046/500: format, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3ef4647aa2 052/500: Fixup lets/ins counting., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0ad464e25a 058/500: Add ']' to match closing parens., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 376cbff828 054/500: More let fixes., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1a1ce340af 070/500: Fix indentation case when '{' at beginning., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode dc705bb4df 057/500: Disable generic hanging indent., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 2be81fe55b 074/500: Get rid of match-end., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 4ce19a966b 095/500: Merge branch 'ljli-fontication',
ELPA Syncer <=
- [nongnu] elpa/nix-mode 1e58da56ac 083/500: Fix var name nix-err-msg-re, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b1078c6add 092/500: Add case sensitive searching, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6eb927f3c1 080/500: Add basic flychecking via nix-instantiate, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode afb1629922 085/500: Fix nix--antiquote-open, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1ebbd318d2 089/500: Add some comments to nix-flycheck.el., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0f12887ea7 082/500: Add basic company completions via nix-repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5b63478bcb 109/500: Make nix-flycheck optional., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 4076a86333 114/500: Merge pull request #17 from matthewbauer/separate-files, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 2f3dfd90df 115/500: Make nix-format.el optional in nix-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode da7e6de79a 139/500: Move some unpolished elisp to "misc" folder., ELPA Syncer, 2022/01/29