Skip to content

Commit e7c54bf

Browse files
committed
overlays: refactor
1 parent d668578 commit e7c54bf

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

haskell-load.el

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,25 +304,40 @@ actual Emacs buffer of the module being loaded."
304304
(with-current-buffer buffer
305305
(remove-overlays (point-min) (point-max) 'haskell-check t)))
306306

307+
(defun overlay-start> (o1 o2)
308+
(> (overlay-start o1) (overlay-start o2)))
309+
(defun overlay-start< (o1 o2)
310+
(< (overlay-start o1) (overlay-start o2)))
311+
312+
(defun first-overlay-in-if (test beg end)
313+
(let ((ovls (cl-remove-if-not test (overlays-in beg end))))
314+
(cl-first (sort (cl-copy-list ovls) 'overlay-start<))))
315+
316+
(defun last-overlay-in-if (test beg end)
317+
(let ((ovls (cl-remove-if-not test (overlays-in beg end))))
318+
(cl-first (sort (cl-copy-list ovls) 'overlay-start>))))
319+
320+
(defun haskell-goto-error-overlay (ovl)
321+
(cond (ovl
322+
(goto-char (overlay-start ovl)))
323+
(t
324+
(message "No further notes from Haskell compiler."))))
325+
307326
(defun haskell-goto-prev-error ()
308327
(interactive)
309-
(let* ((here (point))
310-
(ovls0 (haskell-check-filter-overlays (overlays-at here)))
311-
(end (if ovls0 (overlay-start (car ovls0)) here))
312-
(ovls1 (overlays-in (point-min) end))
313-
(ovls2 (haskell-check-filter-overlays ovls1))
314-
(pnts (mapcar 'overlay-start ovls2)))
315-
(if pnts (goto-char (apply 'max pnts)))))
328+
(haskell-goto-error-overlay
329+
(let ((ovl-at (cl-first (haskell-check-filter-overlays (overlays-at (point))))))
330+
(or (last-overlay-in-if 'haskell-check-overlay-p
331+
(point-min) (if ovl-at (overlay-start ovl-at) (point)))
332+
ovl-at))))
316333

317334
(defun haskell-goto-next-error ()
318335
(interactive)
319-
(let* ((here (point))
320-
(ovls0 (haskell-check-filter-overlays (overlays-at here)))
321-
(beg (if ovls0 (overlay-end (car ovls0)) here))
322-
(ovls1 (overlays-in beg (point-max)))
323-
(ovls2 (haskell-check-filter-overlays ovls1))
324-
(pnts (mapcar 'overlay-start ovls2)))
325-
(if pnts (goto-char (apply 'min pnts)))))
336+
(haskell-goto-error-overlay
337+
(let ((ovl-at (cl-first (haskell-check-filter-overlays (overlays-at (point))))))
338+
(or (first-overlay-in-if 'haskell-check-overlay-p
339+
(if ovl-at (overlay-end ovl-at) (point)) (point-max))
340+
ovl-at))))
326341

327342
(defun haskell-check-paint-overlay (buffer error-from-this-file-p line msg file err hole coln)
328343
(with-current-buffer buffer

0 commit comments

Comments
 (0)