]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Flymake's treatment of region-specific reports
authorJoão Távora <joaotavora@gmail.com>
Wed, 3 Jul 2019 23:27:08 +0000 (00:27 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 3 Jul 2019 23:38:01 +0000 (00:38 +0100)
We're supposed to delete intersecting diagnostics in that situation,
but the intersection logic was way off.

* lisp/progmodes/flymake.el (version): Bump to 1.0.7.
(flymake--intersects-p): New helper.
(flymake--handle-report): Fix handling of :region.

lisp/progmodes/flymake.el

index 6f3d2d59b5c25b14972b1868e1124026c4553f7c..d662aaf4257e8ecb92df7150a764b22651debb04 100644 (file)
@@ -4,7 +4,7 @@
 
 ;; Author: Pavel Kobyakov <pk_at_work@yahoo.com>
 ;; Maintainer: João Távora <joaotavora@gmail.com>
-;; Version: 1.0.6
+;; Version: 1.0.7
 ;; Package-Requires: ((emacs "26.1"))
 ;; Keywords: c languages tools
 
@@ -697,6 +697,14 @@ backend is operating normally.")
   "Tell if Flymake has running backends in this buffer"
   (flymake-running-backends))
 
+;; FIXME: clone of `isearch-intesects-p'! Make this an util.
+(defun flymake--intersects-p (start0 end0 start1 end1)
+  "Return t if regions START0..END0 and START1..END1 intersect."
+  (or (and (>= start0 start1) (<  start0 end1))
+      (and (>  end0 start1)   (<= end0 end1))
+      (and (>= start1 start0) (<  start1 end0))
+      (and (>  end1 start0)   (<= end1 end0))))
+
 (cl-defun flymake--handle-report (backend token report-action
                                           &key explanation force region
                                           &allow-other-keys)
@@ -744,9 +752,12 @@ report applies to that region."
           (cond
            (region
             (cl-loop for diag in (flymake--backend-state-diags state)
-                     if (or (> (flymake--diag-end diag) (car region))
-                            (< (flymake--diag-beg diag) (cdr region)))
-                     do (delete-overlay (flymake--diag-overlay diag))
+                     for ov = (flymake--diag-overlay diag)
+                     if (or (not (overlay-buffer ov))
+                            (flymake--intersects-p
+                             (overlay-start ov) (overlay-end ov)
+                             (car region) (cdr region)))
+                     do (delete-overlay ov)
                      else collect diag into surviving
                      finally (setf (flymake--backend-state-diags state)
                                    surviving)))