Skip to content

Commit 8f634a2

Browse files
committed
Fix: Warn about files with too-long lines
Fixes #63. Or works around it. There's only so much we can do. These tend to be e.g. minified JavaScript files, which shouldn't be scanned, and the user will have to exclude them.
1 parent 60ba734 commit 8f634a2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

README.org

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no
131131
*Added*
132132
+ Commands =helm-magit-todos= and =ivy-magit-todos=, which display items with Helm and Ivy. (Note that Helm and Ivy are not required, nor does this package depend on them; they are only used if present.)
133133

134+
*Fixed*
135+
+ Warn about files containing lines too long for Emacs's regexp matcher to handle, rather than aborting the scan ([[https://github.com/alphapapa/magit-todos/issues/63][#63]]).
136+
134137
*Updated*
135138
+ Use =magit-setup-buffer= instead of =magit-mode-setup=.
136139

magit-todos.el

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,22 @@ Match items are a list of `magit-todos-item' found in PROCESS's buffer for RESUL
517517

518518
(defun magit-todos--buffer-items (results-regexp)
519519
"Return list of `magit-todos-item' found in current buffer for RESULTS-REGEXP."
520-
(save-excursion
521-
(goto-char (point-min))
522-
(cl-loop for item = (magit-todos--line-item results-regexp)
523-
while item
524-
collect item
525-
do (forward-line 1))))
520+
(let ((items))
521+
(save-excursion
522+
(goto-char (point-min))
523+
(while (not (eobp))
524+
(--when-let (condition-case err
525+
(magit-todos--line-item results-regexp)
526+
;; Files with very, very long lines may cause Emacs's regexp matcher to overflow.
527+
;; Rather than abort the whole scan and raise an error, try to handle it gracefully.
528+
;; FIXME: This may raise multiple warnings per file.
529+
(error (if (string= "Stack overflow in regexp matcher" (error-message-string err))
530+
(let ((filename (buffer-substring (point) (1- (re-search-forward ":")))))
531+
(display-warning 'magit-todos (concat "File has lines too long for Emacs to search. Consider excluding it from scans: " filename)))
532+
(signal (car err) (cdr err)))))
533+
(push it items))
534+
(forward-line 1)))
535+
(nreverse items)))
526536

527537
(cl-defun magit-todos--git-diff-callback (&key magit-status-buffer results-regexp search-regexp-elisp process heading
528538
&allow-other-keys)

0 commit comments

Comments
 (0)