bug-recutils
[Top][All Lists]
Advanced

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

Flymake recfix linter


From: Ivan Sokolov
Subject: Flymake recfix linter
Date: Tue, 01 Dec 2020 16:27:27 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hello!

I wrote recfix based Flymake backend for .rec files.

I know there are few comments, but this is my first experience with
submitting patches to GNU projects, so I would like to receive feedback
as soon as possible.

>From f9cddb03a102ef5d355421dddea918a60dbe27a1 Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Tue, 1 Dec 2020 16:03:18 +0300
Subject: [PATCH] Add flymake-recfix.el

---
Range-diff:
-:  ------- > 1:  f9cddb0 Add flymake-recfix.el

 flymake-recfix.el | 88 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 flymake-recfix.el

diff --git a/flymake-recfix.el b/flymake-recfix.el
new file mode 100644
index 0000000..08dc462
--- /dev/null
+++ b/flymake-recfix.el
@@ -0,0 +1,88 @@
+;;; flymake-recfix.el --- Recutils flymake linter -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;; Author: Ivan Sokolov <ivan-p-sokolov@ya.ru>
+;; Package-Requires: ()
+;; Version: 0.1.0
+
+;;; Commentary:
+
+;;; Code:
+
+(defvar-local flymake-recfix--proc nil)
+
+(defconst flymake-recfix--error-regexp
+  (rx bol "stdin: " (group (+ digit)) ": error: " (group (+ any)) eol))
+
+(defun flymake-recfix--make-process (report-fn source-buffer)
+  "Create linter process for `flymake-recfix'.
+REPORT-FN -- Flymake callback.
+SOURCE-BUFFER -- buffer, for which linter was started."
+  (make-process
+   :name "flymake-recfix"
+   :noquery t
+   :connection-type 'pipe
+   :buffer (generate-new-buffer " *flymake-recfix*")
+   :command '("recfix" "--check")
+   :sentinel
+   (lambda (proc _event)
+     (when (eq 'exit (process-status proc))
+       (unwind-protect
+           (if (with-current-buffer source-buffer
+                 (not (eq proc flymake-recfix--proc)))
+               (flymake-log :warning "Canceling obsolete check %s" proc)
+             (with-current-buffer (process-buffer proc)
+               (goto-char (point-min))
+               (let (diagnostics)
+                 (while (search-forward-regexp flymake-recfix--error-regexp 
nil t)
+                   (let* ((line (string-to-number (match-string 1)))
+                          (region (flymake-diag-region source-buffer line)))
+                     (push (flymake-make-diagnostic source-buffer
+                                                    (car region)
+                                                    (cdr region)
+                                                    :error
+                                                    (match-string 2))
+                           diagnostics)))
+                 (funcall report-fn diagnostics))))
+         ;; Clean up
+         (kill-buffer (process-buffer proc)))))))
+
+;;;###autoload
+(defun flymake-recfix (report-fn &rest _args)
+  "Flymake backend for recfix.
+REPORT-FN -- Flymake callback."
+  (unless (executable-find "recfix")
+    (error "Cannot find recfix executable"))
+
+  (when (process-live-p flymake-recfix--proc)
+    (kill-process flymake-recfix--proc))
+
+  (let ((source-buffer (current-buffer)))
+    (save-restriction
+      (widen)
+      (setq flymake-recfix--proc
+            (flymake-recfix--make-process report-fn source-buffer))
+      (process-send-region flymake-recfix--proc (point-min) (point-max))
+      (process-send-eof flymake-recfix--proc))))
+
+;;;###autoload
+(defun flymake-recfix-enable ()
+  "Enable `flymake-recfix' backend."
+  (add-hook 'flymake-diagnostic-functions #'flymake-recfix nil t))
+
+(provide 'flymake-recfix)
+;;; flymake-recfix.el ends here
-- 
2.29.2


reply via email to

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