bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Lars Ingebrigtsen
Subject: bug#29499: 25.3; bounds-of-thing-at-point for nested s-expressions?
Date: Sun, 14 Jul 2019 20:42:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

James Nguyen <address@hidden> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]