branch: elpa/nix-mode
commit 9043a8d6870367294bc37beb18debe438bfbc1d5
Merge: 32b013cd62 1ebfda9810
Author: Matthew Bauer <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #98 from j-piecuch/94-fix
Improve symbol tokenization.
---
nix-mode.el | 29 ++++++++++++++++++++++-------
tests/nix-mode-tests.el | 2 +-
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index 31c8efa1b1..887424c085 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -418,11 +418,12 @@ STRING-TYPE type of string based off of Emacs syntax
table types"
(right " -bseqskip- ")
(left " -fseqskip- "))))))
-(defconst nix-smie--symbol-chars "[:->|&=!</-+*?,;!]")
+(defconst nix-smie--2char-symbols
+ '("->" "||" "&&" "==" "!=" "<=" ">=" "++" "//"))
(defconst nix-smie--infix-symbols-re
- (regexp-opt '(":" "->" "||" "&&" "==" "!=" "<" "<=" ">" ">="
- "//" "-" "+" "*" "/" "++" "?")))
+ (regexp-opt (append '(":" "<" ">" "-" "+" "*" "/" "?")
+ nix-smie--2char-symbols)))
(defconst nix-smie-indent-tokens-re
(regexp-opt '("{" "(" "[" "=" "let" "if" "then" "else")))
@@ -564,6 +565,22 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
sub
(ignore (goto-char start))))))
+;; Returns non-nil if it successfully skipped a symbol.
+(defun nix-smie--skip-symbol (how)
+ (let* ((start (point))
+ (nskip (pcase-exhaustive how
+ ('backward (skip-syntax-backward "._"))
+ ('forward (skip-syntax-forward "._"))))
+ (abs-skip (abs nskip)))
+ (or (= 1 abs-skip)
+ (and (= 2 abs-skip)
+ (member (buffer-substring-no-properties (point) start)
+ nix-smie--2char-symbols))
+ (if (< 0 abs-skip)
+ (goto-char (+ start (if (< 0 nskip) 1 -1)))
+ (goto-char start)
+ nil))))
+
(defun nix-smie--forward-token-1 ()
"Move forward one token."
(forward-comment (point-max))
@@ -573,8 +590,7 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
(point)
(progn
(or (/= 0 (skip-syntax-forward "'w_"))
- (when (looking-at nix-smie--symbol-chars) (forward-char) t)
- (skip-syntax-forward "'"))
+ (nix-smie--skip-symbol 'forward))
(point)))))
(defun nix-smie--forward-token ()
@@ -595,8 +611,7 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
(point)
(progn
(or (/= 0 (skip-syntax-backward "'w_"))
- (when (looking-back nix-smie--symbol-chars) (backward-char) t)
- (skip-syntax-backward "'"))
+ (nix-smie--skip-symbol 'backward))
(point)))))
(defun nix-smie--backward-token ()
diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el
index 6f41199a27..106ad3ba13 100644
--- a/tests/nix-mode-tests.el
+++ b/tests/nix-mode-tests.el
@@ -231,7 +231,7 @@ Related issue: https://github.com/NixOS/nix-mode/issues/72"
"Proper indentation of attrsets inside of lists inside of attrsets.
Related issue: https://github.com/NixOS/nix-mode/issues/94"
- (with-nix-mode-test ("issue-60.1.nix" :indent 'smie-indent-line)))
+ (with-nix-mode-test ("issue-94.nix" :indent 'smie-indent-line)))
(ert-deftest nix-mode-test-indent-lambdas-smie ()
"Proper indentation of function bodies."