[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint 02c5dd2 13/23: Prepare for easier testability
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint 02c5dd2 13/23: Prepare for easier testability |
Date: |
Sun, 29 Sep 2019 15:34:53 -0400 (EDT) |
branch: externals/relint
commit 02c5dd2cde9d852c56bf1885d3185d909607c626
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Prepare for easier testability
Add relint--scan-buffer that takes explicit source and error buffer
arguments.
---
relint.el | 84 ++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 46 insertions(+), 38 deletions(-)
diff --git a/relint.el b/relint.el
index 1c33c8d..9d2d6e8 100644
--- a/relint.el
+++ b/relint.el
@@ -93,21 +93,23 @@
(require 'compile)
(require 'cl-lib)
-(defconst relint--error-buffer-name "*relint*")
-
-(defun relint--error-buffer ()
- (let ((buf (get-buffer relint--error-buffer-name)))
- (or buf
- (let ((buf (get-buffer-create relint--error-buffer-name)))
- (with-current-buffer buf
- (relint-mode))
- buf))))
-
+(defvar relint--error-buffer)
+(defvar relint--quiet)
(defvar relint--error-count)
(defvar relint--suppression-count)
+(defun relint--get-error-buffer ()
+ (let ((buf (get-buffer-create "*relint*")))
+ (with-current-buffer buf
+ (unless (eq major-mode 'relint-mode)
+ (relint-mode))
+ (let ((inhibit-read-only t))
+ (compilation-forget-errors)
+ (erase-buffer)))
+ buf))
+
(defun relint--add-to-error-buffer (string)
- (with-current-buffer (relint--error-buffer)
+ (with-current-buffer relint--error-buffer
(goto-char (point-max))
(let ((inhibit-read-only t))
(insert string))))
@@ -190,7 +192,7 @@ list of list indices to follow to target)."
matched)))
(defun relint--output-error (string)
- (if noninteractive
+ (if (and noninteractive (not relint--error-buffer))
(message "%s" string)
(relint--add-to-error-buffer (concat string "\n"))))
@@ -1412,9 +1414,9 @@ directly."
(setq index (1+ index)))))))
(defun relint--show-errors ()
- (unless noninteractive
+ (unless (or noninteractive relint--quiet)
(let ((pop-up-windows t))
- (display-buffer (relint--error-buffer))
+ (display-buffer relint--error-buffer)
(sit-for 0))))
(defun relint--read-buffer (file)
@@ -1474,21 +1476,20 @@ Return a list of (FORM . STARTING-POSITION)."
(defvar relint-last-target nil
"The last file, directory or buffer on which relint was run.")
-(defun relint--init (target base-dir)
+(defun relint--init (target base-dir error-buffer quiet)
+ (setq relint--quiet quiet)
+ (setq relint--error-count 0)
+ (setq relint--suppression-count 0)
(if noninteractive
- (progn
- (setq relint--error-count 0)
- (setq relint--suppression-count 0))
- (with-current-buffer (relint--error-buffer)
- (let ((inhibit-read-only t))
- (compilation-forget-errors)
- (erase-buffer)
- (insert (format "Relint results for %s\n" target))
- (relint--show-errors))
+ (setq relint--error-buffer error-buffer)
+ (setq relint--error-buffer (or error-buffer (relint--get-error-buffer)))
+ (with-current-buffer relint--error-buffer
+ (unless quiet
+ (let ((inhibit-read-only t))
+ (insert (format "Relint results for %s\n" target))
+ (relint--show-errors)))
(setq relint-last-target target)
- (setq default-directory base-dir)
- (setq relint--error-count 0)
- (setq relint--suppression-count 0))))
+ (setq default-directory base-dir))))
(defun relint--finish ()
(let* ((supp relint--suppression-count)
@@ -1498,9 +1499,10 @@ Return a list of (FORM . STARTING-POSITION)."
(if (zerop supp)
""
(format " (%s suppressed)" supp)))))
- (unless noninteractive
- (relint--add-to-error-buffer (format "\nFinished -- %s.\n" msg)))
- (message "relint: %s." msg)))
+ (unless relint--quiet
+ (unless noninteractive
+ (relint--add-to-error-buffer (format "\nFinished -- %s.\n" msg)))
+ (message "relint: %s." msg))))
(defun relint-again ()
"Re-run relint on the same file, directory or buffer as last time."
@@ -1528,7 +1530,7 @@ Return a list of (FORM . STARTING-POSITION)."
(setq-local relint-last-target nil))
(defun relint--scan-files (files target base-dir)
- (relint--init target base-dir)
+ (relint--init target base-dir nil nil)
(dolist (file files)
;;(relint--output-error (format "Scanning %s" file))
(relint--scan-file file base-dir))
@@ -1538,6 +1540,18 @@ Return a list of (FORM . STARTING-POSITION)."
(directory-files-recursively
dir (rx bos (not (any ".")) (* anything) ".el" eos)))
+(defun relint--scan-buffer (buffer error-buffer quiet)
+ "Scan BUFFER for regexp errors.
+Diagnostics to ERROR-BUFFER, or if nil to *relint*.
+If QUIET, don't emit messages."
+ (unless (eq (buffer-local-value 'major-mode buffer) 'emacs-lisp-mode)
+ (error "Relint: can only scan elisp code (use emacs-lisp-mode)"))
+ (relint--init buffer default-directory error-buffer quiet)
+ (with-current-buffer buffer
+ (save-excursion
+ (relint--scan-current-buffer (buffer-name))))
+ (relint--finish))
+
;;;###autoload
(defun relint-file (file)
@@ -1559,13 +1573,7 @@ Return a list of (FORM . STARTING-POSITION)."
"Scan the current buffer for regexp errors.
The buffer must be in emacs-lisp-mode."
(interactive)
- (unless (eq major-mode 'emacs-lisp-mode)
- (error "Relint: can only scan elisp code (use emacs-lisp-mode)"))
- (relint--init (current-buffer) default-directory)
- (save-excursion
- (relint--scan-current-buffer (buffer-name)))
- (relint--finish))
-
+ (relint--scan-buffer (current-buffer) nil nil))
(defun relint-batch ()
"Scan elisp source files for regexp-related errors.
- [elpa] externals/relint 956a15b 17/23: Fix defun parsing, (continued)
- [elpa] externals/relint 956a15b 17/23: Fix defun parsing, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 3a27cff 18/23: Handle mutation of local variables in evaluation, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint d2b7194 19/23: Evaluate `dolist' and `while', Mattias Engdegård, 2019/09/29
- [elpa] externals/relint b2a86b8 04/23: Fix typo in message description and clarify, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 1cb021a 03/23: Remove relint--eval-error, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 5137ec6 11/23: Evaluate keywords correctly, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 6a07508 10/23: Handle rx `eval' form correctly, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 3a7e82a 05/23: Track some mutation of local variables in phase 2, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint bc1b5a8 16/23: Add word-search-regexp to the list of regexp generating functions, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint b890b5a 15/23: Track mutation in push and lambda in phase 2, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 02c5dd2 13/23: Prepare for easier testability,
Mattias Engdegård <=
- [elpa] externals/relint 60d5627 21/23: Lazy evaluation of global variables, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint b0f0bee 23/23: Increment version to 1.11, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 501f87b 20/23: Evaluate `prog1' and `prog2', Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 6212b6f 22/23: Evaluate more functions and macros, Mattias Engdegård, 2019/09/29
- [elpa] externals/relint 7e6b8bf 14/23: Add tests, Mattias Engdegård, 2019/09/29