[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint 4a8b0ef 14/15: Return position of both expressio
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint 4a8b0ef 14/15: Return position of both expression and error from relint-buffer |
Date: |
Sat, 29 Feb 2020 17:22:31 -0500 (EST) |
branch: externals/relint
commit 4a8b0ef1572ce9c2346eb2872937cbbbc2d6f093
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Return position of both expression and error from relint-buffer
This way, the caller can itself decide whether to show the
flawed regexp when the precise error position is available.
---
relint-test.el | 8 +++++---
relint.el | 48 ++++++++++++++++++++++++++++--------------------
2 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/relint-test.el b/relint-test.el
index 05bb8a4..fae38a9 100644
--- a/relint-test.el
+++ b/relint-test.el
@@ -132,12 +132,14 @@ and a path."
(with-current-buffer buf
(emacs-lisp-mode)
(insert ";hello\n(looking-at \"broken**regexp\")\n")
+ (insert "(looking-at (make-string 2 ?^))\n")
(insert "(looking-at (concat \"ab\" \"cdef\" \"[gg]\"))\n"))
(should (equal
(relint-buffer buf)
- '(("In call to looking-at: Repetition of repetition" 28
+ '(("In call to looking-at: Repetition of repetition" 20 28
"broken**regexp" 7)
+ ("In call to looking-at: Unescaped literal `^'" 50 nil
+ "^^" 1)
("In call to looking-at: Duplicated `g' inside character
alternative"
- 73
- "abcdef[gg]" 8)))))
+ 82 105 "abcdef[gg]" 8)))))
(kill-buffer buf))))
diff --git a/relint.el b/relint.el
index 2171a75..186ffa9 100644
--- a/relint.el
+++ b/relint.el
@@ -225,31 +225,32 @@ or nil if no position could be determined."
(message "%s" string)
(relint--add-to-error-buffer (concat string "\n"))))
-(defun relint--output-report (file pos message str str-pos)
- (let ((line (line-number-at-pos pos t))
- (col (save-excursion
- (goto-char pos)
- (1+ (current-column)))))
+(defun relint--output-report (file expr-pos error-pos message str str-idx)
+ (let* ((pos (or error-pos expr-pos))
+ (line (line-number-at-pos pos t))
+ (col (save-excursion
+ (goto-char pos)
+ (1+ (current-column)))))
(relint--output-message
(concat
(format "%s:%d:%d: %s" file line col message)
- (and str-pos (format " (pos %d)" str-pos))
+ (and str-idx (format " (pos %d)" str-idx))
(and str
(format "\n %s\n %s"
(relint--quote-string str)
- (relint--caret-string str str-pos)))))))
+ (relint--caret-string str str-idx)))))))
(defvar relint--report-function #'relint--output-report
"Function accepting a found complaint, taking the arguments
-(FILE POS MESSAGE STRING STRING-IDX).")
+(FILE EXPR-POS ERROR-POS MESSAGE STRING STRING-IDX).")
-(defun relint--report (file start-pos path message &optional str str-pos)
- (let* ((base-pos (relint--pos-from-start-pos-path start-pos path))
- (pos (or (and str-pos (relint--string-pos base-pos str-pos))
- base-pos)))
- (if (relint--suppression pos message)
+(defun relint--report (file start-pos path message &optional str str-idx)
+ (let* ((expr-pos (relint--pos-from-start-pos-path start-pos path))
+ (error-pos (and str-idx (relint--string-pos expr-pos str-idx))))
+ (if (relint--suppression expr-pos message)
(setq relint--suppression-count (1+ relint--suppression-count))
- (funcall relint--report-function file pos message str str-pos)))
+ (funcall relint--report-function file expr-pos error-pos message
+ str str-idx)))
(setq relint--error-count (1+ relint--error-count)))
(defun relint--escape-string (str escape-printable)
@@ -1892,14 +1893,21 @@ The buffer must be in emacs-lisp-mode."
;;;###autoload
(defun relint-buffer (buffer)
"Scan BUFFER for regexp errors. Return list of diagnostics.
-Each element in the returned list is (MESSAGE POS STRING STRING-IDX),
-where MESSAGE is the message string, POS the buffer location,
-STRING is nil or a string to which the message pertains, and
-STRING-IDX is nil or an index into STRING."
+Each element in the returned list has the form
+
+ (MESSAGE EXPR-POS ERROR-POS STRING STRING-IDX),
+
+where MESSAGE is the message string, EXPR-POS the location of the
+flawed expression, ERROR-POS the exact position of the error or
+nil if unavailable, STRING is nil or a string to which the
+message pertains, and STRING-IDX is nil or an index into STRING.
+The intent is that ERROR-POS is the position in the buffer that
+corresponds to STRING at STRING-IDX, if such a location can be
+determined."
(let* ((complaints nil)
(relint--report-function
- (lambda (_file pos message str str-pos)
- (push (list message pos str str-pos) complaints))))
+ (lambda (_file expr-pos error-pos message str str-idx)
+ (push (list message expr-pos error-pos str str-idx) complaints))))
(relint--scan-buffer buffer nil t)
(nreverse complaints)))
- [elpa] externals/relint b46ee8b 04/15: Update copyright year to 2020, (continued)
- [elpa] externals/relint b46ee8b 04/15: Update copyright year to 2020, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint bb7d8a1 10/15: Fix mistake in previous commit, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 1741e2c 09/15: Locate error position in 'concat' forms, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 8cc1017 12/15: Rename relint--pos-from-toplevel-pos-path, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 9de65a6 11/15: Remove package description in relint.el, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint c33b893 06/15: Refactor error reporting, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 803579c 01/15: More font-lock-keywords detection, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 47490f3 08/15: Add relint-buffer for easier use of relint as a library, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 159a210 13/15: Simplify line/column computation and reindent, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint c2d3f3b 15/15: Increment version to 1.14, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 4a8b0ef 14/15: Return position of both expression and error from relint-buffer,
Mattias Engdegård <=
- [elpa] externals/relint 7b93662 07/15: Report error position inside string literals, Mattias Engdegård, 2020/02/29