Subject: bug#29193: 26.0.90; Using (thing-at-point 'sexp) in flymake-diag-region might be suboptimal

From: João Távora <[email-masked]>
Date: Sun, 13 Dec 2020 13:19:08 +0000

Lars Ingebrigtsen <[email-masked]> writes:

> OK, adding João to the Cc's.

Not sure why 'symbol and 'sexp don't reference the same "thing", or at
least stuff consistent in terms of nesting.  In my testing
(thing-at-point 'sexp) at the "e" got me nothing, but at the "n" or "d"
got me the whole sexp.  Similar strange situation with "begin".  "b"
sees the whole sexp, any of "egin" doesn't.  This seems to resist
different indentations.

In the end flymake-diag-region tries its best to guess a region from
limited line/col stuff and asks thingatpt.el for help, which in turn
will probably ask the major-mode for syntactic navigation.

So I wouldn't say the problem is in flymake.el, but in whom is
untimately providing the (broken) goods.  Then again maybe this untested
patch would work and not break much stuff for other backends...

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index efa7b2ffbf..6c3e0a1981 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -437,7 +437,8 @@ flymake-diag-region
               (if (and col (cl-plusp col))
                   (let* ((beg (progn (forward-char (1- col))
                                      (point)))
-                         (sexp-end (ignore-errors (end-of-thing 'sexp)))
+                         (sexp-end (or (ignore-errors (end-of-thing 'sexp))
+                                       (ignore-errors (end-of-thing 'symbol))))
                          (end (or (and sexp-end
                                        (not (= sexp-end beg))
                                        sexp-end)

Other than that, I don't have much to add.  I don't have the resources
to debug ruby-mode and/or install rubocop right now.  Good luck.

João