GNU bug report logs - #64733
[PATCH] ; Handle string-at-point at end of buffer gracefully

Previous Next

Package: emacs;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Wed, 19 Jul 2023 18:52:02 UTC

Severity: normal

Tags: patch

Done: Philip Kaludercic <philipk <at> posteo.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 64733 in the body.
You can then email your comments to 64733 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Wed, 19 Jul 2023 18:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Kaludercic <philipk <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 19 Jul 2023 18:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] ; Handle string-at-point at end of buffer gracefully
Date: Wed, 19 Jul 2023 18:51:05 +0000
[Message part 1 (text/plain, inline)]
Tags: patch


Evaluating (thing-at-point 'string) at the end of a buffer raises an
error:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument characterp nil)
  char-syntax(nil)
  (eq (char-syntax (char-after)) 34)
  (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound)))
  (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound))))
  (let ((ppss (syntax-ppss))) (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound)))))
  (save-excursion (let ((ppss (syntax-ppss))) (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point ...))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound))))))
  thing-at-point-bounds-of-string-at-point()
  funcall(thing-at-point-bounds-of-string-at-point)
  (cond ((get thing 'bounds-of-thing-at-point) (funcall (get thing 'bounds-of-thing-at-point))) ((and (not (eq thing 'whitespace)) (save-excursion (goto-char (point-min)) (not (re-search-forward "[^\11\n ]" nil t)))) nil) (t (let ((orig (point))) (condition-case nil (progn (save-excursion (funcall (or ... ...)) (funcall (or ... ...)) (let (...) (if ... ... ... ... ... ...)))) (error nil)))))
  bounds-of-thing-at-point(string)
  (let ((bounds (bounds-of-thing-at-point thing))) (if bounds (progn (buffer-substring (car bounds) (cdr bounds)))))
  (cond ((let* ((--cl-var-- thing-at-point-provider-alist) #'nil (pthing nil) (result nil) (--cl-var-- t) (--cl-var-- t) --cl-var--) (while (and (consp --cl-var--) (progn (progn (setq function ...) (setq pthing ...)) (if (eq pthing thing) (progn ...)) (if result (progn ... ...) t))) (setq --cl-var-- (cdr --cl-var--)) (setq --cl-var-- nil)) --cl-var--)) ((get thing 'thing-at-point) (funcall (get thing 'thing-at-point))) (t (let ((bounds (bounds-of-thing-at-point thing))) (if bounds (progn (buffer-substring (car bounds) (cdr bounds)))))))
  (let ((text (cond ((let* ((--cl-var-- thing-at-point-provider-alist) #'nil (pthing nil) (result nil) (--cl-var-- t) (--cl-var-- t) --cl-var--) (while (and ... ...) (setq --cl-var-- ...) (setq --cl-var-- nil)) --cl-var--)) ((get thing 'thing-at-point) (funcall (get thing 'thing-at-point))) (t (let ((bounds ...)) (if bounds (progn ...))))))) (if (and text no-properties (sequencep text)) (progn (set-text-properties 0 (length text) nil text))) text)
  thing-at-point(string)
  eval-expression((thing-at-point 'string) nil nil 127)
  funcall-interactively(eval-expression (thing-at-point 'string) nil nil 127)
  command-execute(eval-expression)
--8<---------------cut here---------------end--------------->8---

In this case it is easy to avoid it, with the below patch, by ensuring
that `char-syntax' is not passed a nil.


In GNU Emacs 29.0.92 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.37, cairo version 1.16.0) of 2023-07-16 built on quetzal
Repository revision: fcde115d5748880ad7ebbf43a10753fb7014a6e1
Repository branch: emacs-29
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-pgtk --with-native-compilation --with-imagemagick
 --with-tree-sitter'

[0001-Handle-string-at-point-at-end-of-buffer-gracefully.patch (text/patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Wed, 19 Jul 2023 19:07:01 GMT) Full text and rfc822 format available.

Message #8 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ;
 Handle string-at-point at end of buffer gracefully
Date: Wed, 19 Jul 2023 22:06:48 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Date: Wed, 19 Jul 2023 18:51:05 +0000
> 
> Evaluating (thing-at-point 'string) at the end of a buffer raises an
> error:
> 
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument characterp nil)
>   char-syntax(nil)
>   (eq (char-syntax (char-after)) 34)
>   (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound)))
>   (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound))))
>   (let ((ppss (syntax-ppss))) (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point 'sexp))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound)))))
>   (save-excursion (let ((ppss (syntax-ppss))) (if (nth 3 ppss) (condition-case nil (progn (goto-char (nth 8 ppss)) (cons (point) (progn (forward-sexp) (point)))) (error nil)) (if (eq (char-syntax (char-after)) 34) (let ((bound (bounds-of-thing-at-point ...))) (and bound (<= (car bound) (point)) (< (point) (cdr bound)) bound))))))
>   thing-at-point-bounds-of-string-at-point()
>   funcall(thing-at-point-bounds-of-string-at-point)
>   (cond ((get thing 'bounds-of-thing-at-point) (funcall (get thing 'bounds-of-thing-at-point))) ((and (not (eq thing 'whitespace)) (save-excursion (goto-char (point-min)) (not (re-search-forward "[^\11\n ]" nil t)))) nil) (t (let ((orig (point))) (condition-case nil (progn (save-excursion (funcall (or ... ...)) (funcall (or ... ...)) (let (...) (if ... ... ... ... ... ...)))) (error nil)))))
>   bounds-of-thing-at-point(string)
>   (let ((bounds (bounds-of-thing-at-point thing))) (if bounds (progn (buffer-substring (car bounds) (cdr bounds)))))
>   (cond ((let* ((--cl-var-- thing-at-point-provider-alist) #'nil (pthing nil) (result nil) (--cl-var-- t) (--cl-var-- t) --cl-var--) (while (and (consp --cl-var--) (progn (progn (setq function ...) (setq pthing ...)) (if (eq pthing thing) (progn ...)) (if result (progn ... ...) t))) (setq --cl-var-- (cdr --cl-var--)) (setq --cl-var-- nil)) --cl-var--)) ((get thing 'thing-at-point) (funcall (get thing 'thing-at-point))) (t (let ((bounds (bounds-of-thing-at-point thing))) (if bounds (progn (buffer-substring (car bounds) (cdr bounds)))))))
>   (let ((text (cond ((let* ((--cl-var-- thing-at-point-provider-alist) #'nil (pthing nil) (result nil) (--cl-var-- t) (--cl-var-- t) --cl-var--) (while (and ... ...) (setq --cl-var-- ...) (setq --cl-var-- nil)) --cl-var--)) ((get thing 'thing-at-point) (funcall (get thing 'thing-at-point))) (t (let ((bounds ...)) (if bounds (progn ...))))))) (if (and text no-properties (sequencep text)) (progn (set-text-properties 0 (length text) nil text))) text)
>   thing-at-point(string)
>   eval-expression((thing-at-point 'string) nil nil 127)
>   funcall-interactively(eval-expression (thing-at-point 'string) nil nil 127)
>   command-execute(eval-expression)
> --8<---------------cut here---------------end--------------->8---
> 
> In this case it is easy to avoid it, with the below patch, by ensuring
> that `char-syntax' is not passed a nil.

Thanks, but could you rewrite so as not to call char-after more than
once?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Wed, 19 Jul 2023 19:18:01 GMT) Full text and rfc822 format available.

Message #11 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Wed, 19 Jul 2023 19:17:07 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

> Thanks, but could you rewrite so as not to call char-after more than
> once?

Sure,

[0001-Handle-string-at-point-at-end-of-buffer-gracefully.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Thu, 20 Jul 2023 04:41:01 GMT) Full text and rfc822 format available.

Message #14 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Thu, 20 Jul 2023 07:40:35 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: 64733 <at> debbugs.gnu.org
> Date: Wed, 19 Jul 2023 19:17:07 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Thanks, but could you rewrite so as not to call char-after more than
> > once?
> 
> Sure,

Thanks, this LGTM, but please wait for a couple of days to let others
comment.

This is for master, right?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Thu, 20 Jul 2023 06:58:01 GMT) Full text and rfc822 format available.

Message #17 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Thu, 20 Jul 2023 06:57:17 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: 64733 <at> debbugs.gnu.org
>> Date: Wed, 19 Jul 2023 19:17:07 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> > Thanks, but could you rewrite so as not to call char-after more than
>> > once?
>> 
>> Sure,
>
> Thanks, this LGTM, but please wait for a couple of days to let others
> comment.

OK,

> This is for master, right?

I actually had indented for this and bug#64664 to be applied onto
emacs-29.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Thu, 20 Jul 2023 07:38:02 GMT) Full text and rfc822 format available.

Message #20 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Thu, 20 Jul 2023 10:38:06 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: 64733 <at> debbugs.gnu.org
> Date: Thu, 20 Jul 2023 06:57:17 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > This is for master, right?
> 
> I actually had indented for this and bug#64664 to be applied onto
> emacs-29.

Why are these important enough to install on the release branch?  Did
the behavior change in Emacs 29?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Thu, 20 Jul 2023 08:43:02 GMT) Full text and rfc822 format available.

Message #23 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Thu, 20 Jul 2023 08:42:15 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: 64733 <at> debbugs.gnu.org
>> Date: Thu, 20 Jul 2023 06:57:17 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> > This is for master, right?
>> 
>> I actually had indented for this and bug#64664 to be applied onto
>> emacs-29.
>
> Why are these important enough to install on the release branch?  Did
> the behavior change in Emacs 29?

I assumed so, but on checking both of these issues exist since Emacs 28.
That being said, the fact that (thing-at-point 'string) raises an
(avoidable) error seems to be something that shouldn't be the case, but
I don't know if that warrants applying this patch at this late stage.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Thu, 20 Jul 2023 10:21:02 GMT) Full text and rfc822 format available.

Message #26 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Thu, 20 Jul 2023 13:21:07 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: 64733 <at> debbugs.gnu.org
> Date: Thu, 20 Jul 2023 08:42:15 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> From: Philip Kaludercic <philipk <at> posteo.net>
> >> Cc: 64733 <at> debbugs.gnu.org
> >> Date: Thu, 20 Jul 2023 06:57:17 +0000
> >> 
> >> Eli Zaretskii <eliz <at> gnu.org> writes:
> >> 
> >> > This is for master, right?
> >> 
> >> I actually had indented for this and bug#64664 to be applied onto
> >> emacs-29.
> >
> > Why are these important enough to install on the release branch?  Did
> > the behavior change in Emacs 29?
> 
> I assumed so, but on checking both of these issues exist since Emacs 28.
> That being said, the fact that (thing-at-point 'string) raises an
> (avoidable) error seems to be something that shouldn't be the case, but
> I don't know if that warrants applying this patch at this late stage.

Let's install these on master, and maybe consider backporting then
after Emacs 29.1 is released.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Fri, 21 Jul 2023 14:54:02 GMT) Full text and rfc822 format available.

Message #29 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Fri, 21 Jul 2023 14:53:14 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: 64733 <at> debbugs.gnu.org
>> Date: Thu, 20 Jul 2023 08:42:15 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> >> From: Philip Kaludercic <philipk <at> posteo.net>
>> >> Cc: 64733 <at> debbugs.gnu.org
>> >> Date: Thu, 20 Jul 2023 06:57:17 +0000
>> >> 
>> >> Eli Zaretskii <eliz <at> gnu.org> writes:
>> >> 
>> >> > This is for master, right?
>> >> 
>> >> I actually had indented for this and bug#64664 to be applied onto
>> >> emacs-29.
>> >
>> > Why are these important enough to install on the release branch?  Did
>> > the behavior change in Emacs 29?
>> 
>> I assumed so, but on checking both of these issues exist since Emacs 28.
>> That being said, the fact that (thing-at-point 'string) raises an
>> (avoidable) error seems to be something that shouldn't be the case, but
>> I don't know if that warrants applying this patch at this late stage.
>
> Let's install these on master, and maybe consider backporting then
> after Emacs 29.1 is released.

Wasn't the plan to wait for others to comment.  Or has enough time passed?

> Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64733; Package emacs. (Fri, 21 Jul 2023 15:13:02 GMT) Full text and rfc822 format available.

Message #32 received at 64733 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 64733 <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Fri, 21 Jul 2023 18:13:09 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: 64733 <at> debbugs.gnu.org
> Date: Fri, 21 Jul 2023 14:53:14 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Let's install these on master, and maybe consider backporting then
> > after Emacs 29.1 is released.
> 
> Wasn't the plan to wait for others to comment.

Yes.  I just wanted to make sure we are on the same page regarding
the branch where to install this.




Reply sent to Philip Kaludercic <philipk <at> posteo.net>:
You have taken responsibility. (Sat, 22 Jul 2023 07:22:01 GMT) Full text and rfc822 format available.

Notification sent to Philip Kaludercic <philipk <at> posteo.net>:
bug acknowledged by developer. (Sat, 22 Jul 2023 07:22:01 GMT) Full text and rfc822 format available.

Message #37 received at 64733-done <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64733-done <at> debbugs.gnu.org
Subject: Re: bug#64733: [PATCH] ; Handle string-at-point at end of buffer
 gracefully
Date: Sat, 22 Jul 2023 07:21:42 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: 64733 <at> debbugs.gnu.org
>> Date: Fri, 21 Jul 2023 14:53:14 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> > Let's install these on master, and maybe consider backporting then
>> > after Emacs 29.1 is released.
>> 
>> Wasn't the plan to wait for others to comment.
>
> Yes.  I just wanted to make sure we are on the same page regarding
> the branch where to install this.

OK, I've pushed the patches.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 19 Aug 2023 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 304 days ago.

Previous Next


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