[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode bb602e160f 286/500: Cleanups
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode bb602e160f 286/500: Cleanups |
Date: |
Sat, 29 Jan 2022 08:27:14 -0500 (EST) |
branch: elpa/nix-mode
commit bb602e160fa5bb8ae15b113ebf308f0fb30b3aa9
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Cleanups
Get rid of extra customs
---
nix-mode.el | 107 ++++++++++++++++++++----------------------------------------
1 file changed, 36 insertions(+), 71 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index 05ba967388..bb8f1c2f67 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -37,30 +37,6 @@ Valid functions for this are:
:group 'nix-mode
:type 'function)
-(defcustom nix-mode-caps
- '(" =[ \n]" "\(" "\{" "\\[" "\\bwith\\b" "\\blet\\b" "\\binherit\\b")
- "Regular expressions to consider expression caps."
- :group 'nix-mode
- :type '(repeat string))
-
-(defcustom nix-mode-ends
- '(";" "\)" "\\]" "\}" "\\bin\\b")
- "Regular expressions to consider expression ends."
- :group 'nix-mode
- :type '(repeat string))
-
-(defcustom nix-mode-quotes
- '("''" "\"")
- "Regular expressions to consider expression quotes."
- :group 'nix-mode
- :type '(repeat string))
-
-(defcustom nix-mode-comments
- '("#" "/\\*" "\\*/")
- "Regular expressions to consider comment codes."
- :group 'nix-mode
- :type '(repeat string))
-
(defgroup nix-faces nil
"Nix faces."
:group 'nix-mode
@@ -96,12 +72,12 @@ Valid functions for this are:
"Face used to highlight Nix antiquotes."
:group 'nix-faces)
-(defvar nix-system-types
+;;; Constants
+
+(defconst nix-system-types
'("x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin")
"List of supported systems.")
-;;; Syntax coloring
-
(defconst nix-keywords
'("if" "then"
"else" "with"
@@ -120,6 +96,8 @@ Valid functions for this are:
(defconst nix-warning-keywords
'("assert" "abort" "throw"))
+;;; Regexps
+
(defconst nix-re-file-path
"[a-zA-Z0-9._\\+-]*\\(/[a-zA-Z0-9._\\+-]+\\)+")
@@ -132,6 +110,15 @@ Valid functions for this are:
(defconst nix-re-variable-assign
"\\<\\([a-zA-Z_][a-zA-Z0-9_'\-\.]*\\)[ \t]*=[^=]")
+(defconst nix-re-caps
+ " =[ \n]\\|\(\\|\{\\|\\[\\|\\bwith\\b\\|\\blet\\b\\|\\binherit\\b")
+
+(defconst nix-re-ends ";\\|\)\\|\\]\\|\}\\|\\bin\\b")
+
+(defconst nix-re-quotes "''\\|\"")
+
+(defconst nix-re-comments "#\\|/\\*\\|\\*/")
+
(defconst nix-font-lock-keywords
`((,(regexp-opt nix-keywords 'symbols) 0 'nix-keyword-face)
(,(regexp-opt nix-warning-keywords 'symbols) 0 'nix-keyword-warning-face)
@@ -149,8 +136,6 @@ Valid functions for this are:
(make-abbrev-table)
"Abbrev table for Nix mode.")
-(makunbound 'nix-mode-syntax-table)
-
(defvar nix-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?/ ". 14" table)
@@ -348,11 +333,6 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
;;; Indentation
-(defun nix--inside-string-or-comment ()
- "Determine whether we are inside of a string or comment."
- (or (nix--get-string-type (nix--get-parse-state (point)))
- (nth 4 (syntax-ppss))))
-
(defun nix-find-backward-matching-token ()
"Find the previous Nix token."
(cond
@@ -360,7 +340,8 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
(let ((counter 1))
(while (and (> counter 0)
(re-search-backward "\\b\\(let\\|in\\)\\b" nil t))
- (unless (nix--inside-string-or-comment)
+ (unless (or (nix--get-string-type (nix--get-parse-state (point)))
+ (nix-is-comment-p))
(setq counter (cond ((looking-at "let") (- counter 1))
((looking-at "in") (+ counter 1))))))
counter ))
@@ -413,37 +394,12 @@ STRING-TYPE type of string based off of Emacs syntax
table types"
(+ 2 (current-indentation))))))))
(when matching-indentation (indent-line-to matching-indentation) t)))
-(defun nix-mode-make-regexp (parts)
- "Combine the regexps into a single or-delimited regexp.
-PARTS a list of regexps"
- (declare (indent defun))
- (string-join parts "\\|"))
-
-(defun nix-mode-caps-regexp ()
- "Return regexp for matching expression caps."
- (nix-mode-make-regexp nix-mode-caps))
-
-(defun nix-mode-ends-regexp ()
- "Return regexp for matching expression ends."
- (nix-mode-make-regexp nix-mode-ends))
-
-(defun nix-mode-quotes-regexp ()
- "Return regexp for matching string quotes."
- (nix-mode-make-regexp nix-mode-quotes))
-
-(defun nix-mode-comments-regexp ()
- "Return regexp for matching comments."
- (nix-mode-make-regexp nix-mode-comments))
-
-(defun nix-mode-combined-regexp ()
- "Return combined regexp for matching items of interest."
- (nix-mode-make-regexp (append nix-mode-caps
- nix-mode-ends
- nix-mode-quotes)))
-
(defun nix-mode-search-backward ()
"Search backward for items of interest regarding indentation."
- (re-search-backward (nix-mode-combined-regexp) nil t))
+ (re-search-backward nix-re-ends nil t)
+ (re-search-backward nix-re-quotes nil t)
+ (re-search-backward nix-re-comments nil t)
+ (re-search-backward nix-re-caps nil t))
(defun nix-indent-expression-start ()
"Indent the start of a nix expression."
@@ -460,17 +416,17 @@ PARTS a list of regexps"
;; end is found
(while (and (not done) (nix-mode-search-backward))
(cond
- ((looking-at (nix-mode-quotes-regexp))
+ ((looking-at nix-re-quotes)
;; skip over strings entirely
- (re-search-backward (nix-mode-quotes-regexp) nil t))
- ((looking-at (nix-mode-comments-regexp))
+ (re-search-backward nix-re-quotes nil t))
+ ((looking-at nix-re-comments)
;; skip over comments entirely
- (re-search-backward (nix-mode-comments-regexp) nil t))
- ((looking-at (nix-mode-ends-regexp))
+ (re-search-backward nix-re-comments nil t))
+ ((looking-at nix-re-ends)
;; count the matched end
;; this means we expect to find at least one more cap
(setq ends (+ ends 1)))
- ((looking-at (nix-mode-caps-regexp))
+ ((looking-at nix-re-caps)
;; we found at least one cap
;; this means our function will return true
;; this signals to the caller we handled the indentation
@@ -525,7 +481,7 @@ PARTS a list of regexps"
;; comment
((save-excursion
(beginning-of-line)
- (nth 4 (syntax-ppss)))
+ (nix-is-comment-p))
(indent-line-to (nix-indent-prev-level)))
;; string
@@ -562,6 +518,15 @@ PARTS a list of regexps"
(point))))
(when (> end-of-indentation (point)) (goto-char end-of-indentation))))
+(defun nix-is-comment-p ()
+ "Whether we are in a comment."
+ (nth 3 (syntax-ppss)))
+
+(defun nix-is-string-p ()
+ "Whether we are in a string."
+ (or (looking-at nix-re-quotes)
+ (nix--get-string-type (nix--get-parse-state (point)))))
+
;;;###autoload
(defun nix-mode-ffap-nixpkgs-path (str)
"Support `ffap' for <nixpkgs> declarations.
- [nongnu] elpa/nix-mode 097b7bb992 257/500: Add nix-build.el, (continued)
- [nongnu] elpa/nix-mode 097b7bb992 257/500: Add nix-build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a6571fa877 260/500: Add nix-log.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0c2807f037 262/500: Cleanup nix-build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b62c395b65 264/500: Remove nix-shell-haskell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1dd112e5cf 267/500: Fix function used as variable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f1973ceb4b 269/500: Add .nix to auto-mode-alist, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1389a6b25a 275/500: Fix flycheck warnings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 95ef285e74 277/500: Update .nix script, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1ade7b76bd 282/500: ert/indent: Add testcase for contents of lists, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 02b59d9bcf 283/500: ert/indent: Add testcases for issues reported in #60, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode bb602e160f 286/500: Cleanups,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 7526a43ea0 292/500: tests: Rename test for consistency with the rest, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aa47e0c5ae 302/500: Fix indentation of lambdas starting at bol., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e744c602fd 304/500: Replace regex operations with faster alternatives in the lexer., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8721f63650 310/500: Merge pull request #79 from j-piecuch/smie, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5fcdd667de 312/500: Make smie-indent-line the default indent function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b902e15c1f 003/500: Create nix-mode.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1e74e5021a 002/500: Create LICENSE, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 616c368898 007/500: Add two spaces after period., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7292d8971c 021/500: Refactor indenting, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7f69c71f8d 019/500: Fixup mode map., ELPA Syncer, 2022/01/29