GNU bug report logs - #24627
24.5; (thing-at-point 'list) may return a non-empty string without a list

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Thu, 6 Oct 2016 09:45:02 UTC

Severity: normal

Tags: confirmed

Merged with 13955

Found in versions 24.5, 25.0.94

Fixed in version 26.1

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 24627 <at> debbugs.gnu.org
Subject: bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list
Date: Tue, 11 Oct 2016 20:40:12 +0200

On 11.10.2016 18:29, Tino Calancha wrote:
> Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
>
>> With
>>
>> (defun foo ())
>>
>> at first open paren
>>
>> M-: (thing-at-point 'list t) RET
>>
>> returns the whole thing, right.
>>
>> But at second open paren returns the whole function too - where it
>> should return the empty arg-list
> Following patch do the right thing in my example and your example.
> Feel free to check it with some other examples that you may have:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>  From dc2703a43a7b5dae60f7e88805971472253d4600 Mon Sep 17 00:00:00 2001
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Wed, 12 Oct 2016 01:16:52 +0900
> Subject: [PATCH] (thing-at-point 'list) return nil if no list at point
>
> * lisp/thingatpt.el (thing-at-point-bounds-of-list-at-point):
> Check first if we are at the beginning of a top-level sexp (Bug#24627).
> Escape '[' and ']' in doc string.
> ---
>   lisp/thingatpt.el | 22 +++++++++-------------
>   1 file changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
> index 6d1014b..acacff2 100644
> --- a/lisp/thingatpt.el
> +++ b/lisp/thingatpt.el
> @@ -219,22 +219,18 @@ 'beginning-of-sexp
>   
>   (defun thing-at-point-bounds-of-list-at-point ()
>     "Return the bounds of the list at point.
> -[Internal function used by `bounds-of-thing-at-point'.]"
> +\[Internal function used by `bounds-of-thing-at-point'.\]"
>     (save-excursion
>       (let ((opoint (point))
> -	  (beg (ignore-errors
> -		 (up-list -1)
> -		 (point))))
> +          (beg (if (looking-at-p "(")
> +                   (point)
> +                 (ignore-errors
> +                   (up-list -1)
> +                   (point)))))
>         (ignore-errors
> -	(if beg
> -	    (progn (forward-sexp)
> -		   (cons beg (point)))
> -	  ;; Are we are at the beginning of a top-level sexp?
> -	  (forward-sexp)
> -	  (let ((end (point)))
> -	    (backward-sexp)
> -	    (if (>= opoint (point))
> -		(cons opoint end))))))))
> +        (when beg
> +          (forward-sexp)
> +          (cons beg (point)))))))
>   
>   ;; Defuns
>   

Hmm, what if cursor is inside a string or comment?

BTW "list" might be more universal if understood syntactically
What about writing

(eq 4 (car (syntax-after (point))))





This bug report was last modified 6 years and 337 days ago.

Previous Next


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