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

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

[nongnu] elpa/nix-mode 6eb927f3c1 080/500: Add basic flychecking via nix


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 6eb927f3c1 080/500: Add basic flychecking via nix-instantiate
Date: Sat, 29 Jan 2022 08:26:37 -0500 (EST)

branch: elpa/nix-mode
commit 6eb927f3c177ebf23375b31c9a9950cfdb536b45
Author: Leon Isenberg <ljli@users.noreply.github.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>

    Add basic flychecking via nix-instantiate
---
 nix-mode.el | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 999bbdc100..309a5090af 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -15,6 +15,8 @@
 
 ;;; Code:
 
+(require 'flycheck)
+
 ;; Emacs 24.2 compatability
 (unless (fboundp 'setq-local)
   (defmacro setq-local (var val)
@@ -173,7 +175,43 @@ If a close brace `}' ends an antiquote, the next character 
begins a string."
      (0 (ignore (nix-syntax-propertize-close-brace)))))
    start end))
 
-;; Indentation
+;;; Flycheck
+
+(defconst nix-err-msg-re
+  "error: \\(.*\\) at \\(.*\\):\\([0-9]+\\):\\([0-9]+\\)")
+
+(defun nix--parse-errors (output checker buffer)
+  (with-temp-buffer
+    (insert output)
+    (goto-char (point-min))
+    (let ((errs '()))
+      (while (search-forward-regexp err-msg-re nil t 1)
+        (let* ((file (match-string 2))
+               (line (string-to-number (match-string 3)))
+               (col (string-to-number (match-string 4)))
+               (msg (match-string 1)))
+          (setq errs
+                (cons (flycheck-error-new-at
+                       line col 'error msg
+                       :filename (and (not (string= file "(string)")) file)
+                       :checker checker
+                       :buffer buffer)
+                      errs))))
+    errs)))
+
+(flycheck-def-args-var flycheck-nix-args (nix))
+
+(flycheck-define-checker nix
+  "A syntax and evaluation checker for Nix using nix-instantiate."
+  :command ("nix-instantiate" "--eval" "--strict" "--show-trace" (eval 
flycheck-nix-args) "-")
+  :standard-input t
+  :error-parser nix--parse-errors
+  :modes (nix-mode)
+  )
+
+(add-to-list 'flycheck-checkers 'nix)
+
+;;; Indentation
 
 (defun nix-indent-level-parens ()
   "Find indent level based on parens."
@@ -410,7 +448,11 @@ The hook `nix-mode-hook' is run when Nix mode is started.
   (setq-local paragraph-start "[ \t]*\\(#+[ \t]*\\)?$")
   (setq-local paragraph-separate paragraph-start)
 
-  (easy-menu-add nix-mode-menu nix-mode-map))
+  (easy-menu-add nix-mode-menu nix-mode-map)
+
+  ;; Flycheck
+  (flycheck-select-checker 'nix)
+  (flycheck-mode))
 
 ;;;###autoload
 (progn



reply via email to

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