branch: elpa/nix-mode
commit 6534f146eb56568cbccd39f0d317910766c4eb3d
Author: Matthew Bauer <[email protected]>
Commit: Matthew Bauer <[email protected]>
Formatting
---
nix-mode.el | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index bc253f7185..bb19472a2e 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -21,6 +21,8 @@
"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
@@ -95,11 +97,13 @@
(context (save-excursion (save-match-data (syntax-ppss start))))
(string-type (nth 3 context)))
(pcase string-type
+
(`t
;; inside a multiline string
;; ending multi-line string delimiter
(put-text-property (1- end) end
'syntax-table (string-to-syntax "|")))
+
(`nil
;; beginning multi-line string delimiter
(put-text-property start (1+ start)
@@ -111,8 +115,7 @@
(context (save-excursion (save-match-data (syntax-ppss start))))
(string-type (nth 3 context)))
- ;; only add antiquote when we're already in a string
- (when string-type
+ (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 (+ start 2)
@@ -125,6 +128,7 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(end (match-end 0))
(context (save-excursion (save-match-data (syntax-ppss start))))
(open (nth 1 context)))
+
(when open ;; a corresponding open-brace was found
(let* ((antiquote (get-text-property open 'nix-syntax-antiquote)))
(when antiquote
@@ -150,6 +154,8 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(0 (ignore (nix-syntax-propertize-close-brace)))))
start end))
+;; Indentation
+
(defun nix-indent-level-parens ()
"Find indent level based on parens."
(setq n 0)
@@ -179,6 +185,7 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(setq lets 0)
(setq ins 0)
(beginning-of-line)
+
(while (not (eq (point) (point-min)))
(forward-line -1)
(cond
@@ -268,6 +275,8 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(t
(indent-line-to (nix-indent-level)))))
+;; Visit file
+
(defun nix-visit-file ()
"Go to file under cursor."
(interactive)
@@ -277,6 +286,8 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(if (looking-at nix-re-file-path)
(find-file (match-string-no-properties 0)))))
+;; Formatting
+
(defcustom nix-nixfmt-bin "nixfmt"
"Path to nixfmt executable."
:group 'nix
@@ -302,6 +313,8 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(nix--format-call (current-buffer))
(message "Formatted buffer with rustfmt."))
+;; Key maps
+
(defvar nix-mode-menu (make-sparse-keymap "Nix")
"Menu for Nix mode.")