GNU bug report logs - #29499
25.3; bounds-of-thing-at-point for nested s-expressions?

Previous Next

Package: emacs;

Reported by: James Nguyen <jamesn <at> fastmail.com>

Date: Wed, 29 Nov 2017 07:55:01 UTC

Severity: minor

Tags: fixed

Found in version 25.3

Fixed in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: James Nguyen <jamesn <at> fastmail.com>
Cc: 29499 <at> debbugs.gnu.org
Subject: bug#29499: 25.3; bounds-of-thing-at-point for nested s-expressions?
Date: Sun, 14 Jul 2019 20:42:52 +0200
James Nguyen <jamesn <at> fastmail.com> writes:

> I’m curious if this is expected?
>
> ;; (bounds-of-thing-at-point ‘sexp)
>
> Cursor is after ending paren of line.
>
> (+ 1 1) ;; M-: (bounds-of-thing-at-point ‘sexp) -> returns (x . y)
>
> (+ 1 1
>    (+ 1 1) ;; M-: (bounds-of-thing-at-point ‘sexp) -> returns nil
>    )

The problem is that thingatpt wants to go to the end of the current
sexp, and uses forward-sexp for that.  The amusing thing about
forward-sexp is that it won't error if there's nothing to advance to
(like at the end of a buffer), but if it hits a ")" immediately, it
signals an error, making bounds-of-thing-at-point return nil.

The patch below fixes the problem, but I'm not very familiar with the
thingatpt code.  Does anybody think this makes sense?

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 60a20e2d18..319f4b2cf8 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -194,7 +194,9 @@ thing-at-point--end-of-sexp
     (if (or (eq char-syntax ?\))
 	    (and (eq char-syntax ?\") (nth 3 (syntax-ppss))))
 	(forward-char 1)
-      (forward-sexp 1))))
+      (condition-case _
+          (forward-sexp 1)
+        (scan-error nil)))))
 
 (define-obsolete-function-alias 'end-of-sexp
   'thing-at-point--end-of-sexp "25.1"


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 5 years and 301 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.