all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
@ 2023-07-19 18:51 Philip Kaludercic
  2023-07-19 19:06 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-19 18:51 UTC (permalink / raw)
  To: 64733

[-- Attachment #1: Type: text/plain, Size: 3767 bytes --]

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'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-string-at-point-at-end-of-buffer-gracefully.patch --]
[-- Type: text/patch, Size: 1051 bytes --]

From fb5da3b4a4785938d82c8ce4ea59215a8905ddd7 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Wed, 19 Jul 2023 20:49:30 +0200
Subject: [PATCH] ; Handle string-at-point at end of buffer gracefully

* lisp/thingatpt.el (thing-at-point-bounds-of-string-at-point): Check
if 'char-after' returns non-nil before passing it to 'char-syntax'.
---
 lisp/thingatpt.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 9363a474cb5..46e700c2091 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -250,7 +250,7 @@ thing-at-point-bounds-of-string-at-point
             (goto-char (nth 8 ppss))
             (cons (point) (progn (forward-sexp) (point))))
         ;; At the beginning of the string
-        (if (eq (char-syntax (char-after)) ?\")
+        (if (and (char-after) (eq (char-syntax (char-after)) ?\"))
             (let ((bound (bounds-of-thing-at-point 'sexp)))
 	      (and bound
 	           (<= (car bound) (point)) (< (point) (cdr bound))
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-19 18:51 bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully Philip Kaludercic
@ 2023-07-19 19:06 ` Eli Zaretskii
  2023-07-19 19:17   ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-07-19 19:06 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 64733

> From: Philip Kaludercic <philipk@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?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-19 19:06 ` Eli Zaretskii
@ 2023-07-19 19:17   ` Philip Kaludercic
  2023-07-20  4:40     ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-19 19:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64733

[-- Attachment #1: Type: text/plain, Size: 125 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

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

Sure,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-string-at-point-at-end-of-buffer-gracefully.patch --]
[-- Type: text/x-diff, Size: 1106 bytes --]

From 6fe6b91970a50c5609e81567c4b486b02e4f1a66 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Wed, 19 Jul 2023 21:14:40 +0200
Subject: [PATCH] ; Handle string-at-point at end of buffer gracefully

* lisp/thingatpt.el (thing-at-point-bounds-of-string-at-point): Check
if 'char-after' returns non-nil before passing it to
'char-syntax'.  (Bug#64733)
---
 lisp/thingatpt.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 46e700c2091..22a356efa83 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -250,7 +250,8 @@ thing-at-point-bounds-of-string-at-point
             (goto-char (nth 8 ppss))
             (cons (point) (progn (forward-sexp) (point))))
         ;; At the beginning of the string
-        (if (and (char-after) (eq (char-syntax (char-after)) ?\"))
+        (if (let ((ca (char-after)))
+              (and ca (eq (char-syntax ca) ?\")))
             (let ((bound (bounds-of-thing-at-point 'sexp)))
 	      (and bound
 	           (<= (car bound) (point)) (< (point) (cdr bound))
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-19 19:17   ` Philip Kaludercic
@ 2023-07-20  4:40     ` Eli Zaretskii
  2023-07-20  6:57       ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-07-20  4:40 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 64733

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 64733@debbugs.gnu.org
> Date: Wed, 19 Jul 2023 19:17:07 +0000
> 
> Eli Zaretskii <eliz@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?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-20  4:40     ` Eli Zaretskii
@ 2023-07-20  6:57       ` Philip Kaludercic
  2023-07-20  7:38         ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-20  6:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64733

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 64733@debbugs.gnu.org
>> Date: Wed, 19 Jul 2023 19:17:07 +0000
>> 
>> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-20  6:57       ` Philip Kaludercic
@ 2023-07-20  7:38         ` Eli Zaretskii
  2023-07-20  8:42           ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-07-20  7:38 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 64733

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 64733@debbugs.gnu.org
> Date: Thu, 20 Jul 2023 06:57:17 +0000
> 
> Eli Zaretskii <eliz@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?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-20  7:38         ` Eli Zaretskii
@ 2023-07-20  8:42           ` Philip Kaludercic
  2023-07-20 10:21             ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-20  8:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64733

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 64733@debbugs.gnu.org
>> Date: Thu, 20 Jul 2023 06:57:17 +0000
>> 
>> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-20  8:42           ` Philip Kaludercic
@ 2023-07-20 10:21             ` Eli Zaretskii
  2023-07-21 14:53               ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-07-20 10:21 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 64733

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 64733@debbugs.gnu.org
> Date: Thu, 20 Jul 2023 08:42:15 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Philip Kaludercic <philipk@posteo.net>
> >> Cc: 64733@debbugs.gnu.org
> >> Date: Thu, 20 Jul 2023 06:57:17 +0000
> >> 
> >> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-20 10:21             ` Eli Zaretskii
@ 2023-07-21 14:53               ` Philip Kaludercic
  2023-07-21 15:13                 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-21 14:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64733

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 64733@debbugs.gnu.org
>> Date: Thu, 20 Jul 2023 08:42:15 +0000
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> From: Philip Kaludercic <philipk@posteo.net>
>> >> Cc: 64733@debbugs.gnu.org
>> >> Date: Thu, 20 Jul 2023 06:57:17 +0000
>> >> 
>> >> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-21 14:53               ` Philip Kaludercic
@ 2023-07-21 15:13                 ` Eli Zaretskii
  2023-07-22  7:21                   ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-07-21 15:13 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 64733

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 64733@debbugs.gnu.org
> Date: Fri, 21 Jul 2023 14:53:14 +0000
> 
> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully
  2023-07-21 15:13                 ` Eli Zaretskii
@ 2023-07-22  7:21                   ` Philip Kaludercic
  0 siblings, 0 replies; 11+ messages in thread
From: Philip Kaludercic @ 2023-07-22  7:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64733-done

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 64733@debbugs.gnu.org
>> Date: Fri, 21 Jul 2023 14:53:14 +0000
>> 
>> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-07-22  7:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 18:51 bug#64733: [PATCH] ; Handle string-at-point at end of buffer gracefully Philip Kaludercic
2023-07-19 19:06 ` Eli Zaretskii
2023-07-19 19:17   ` Philip Kaludercic
2023-07-20  4:40     ` Eli Zaretskii
2023-07-20  6:57       ` Philip Kaludercic
2023-07-20  7:38         ` Eli Zaretskii
2023-07-20  8:42           ` Philip Kaludercic
2023-07-20 10:21             ` Eli Zaretskii
2023-07-21 14:53               ` Philip Kaludercic
2023-07-21 15:13                 ` Eli Zaretskii
2023-07-22  7:21                   ` Philip Kaludercic

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.