unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35967: [PATCH] avoid flyspell error if point is at bob
@ 2019-05-28 20:43 Alex Branham
  2019-05-29 16:08 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Alex Branham @ 2019-05-28 20:43 UTC (permalink / raw)
  To: 35967

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

Hello -

The attached patch avoids an args-out-of-range error (from
`get-text-property') if `flyspell-prog-mode' is on and point is in a
comment at the beginning of the buffer.

Thanks,
Alex


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Avoid-a-flyspell-error-if-point-is-at-beginning-of-b.patch --]
[-- Type: text/x-patch, Size: 1288 bytes --]

From e130dfcb542af667fbef6e6eb867c46eee6d9746 Mon Sep 17 00:00:00 2001
From: Alex Branham <alex.branham@gmail.com>
Date: Tue, 28 May 2019 15:40:26 -0500
Subject: [PATCH] Avoid a flyspell error if point is at beginning of buffer

* lisp/textmodes/flyspell.el (flyspell-generic-progmode-verify):
Check if point is at bob.  This prevents an error when e.g.
'flyspell-auto-correct-word' gets called with point at the
beginning of the buffer.
---
 lisp/textmodes/flyspell.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index d18916dfd0..e711fe72b2 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -424,8 +424,9 @@ like <img alt=\"Some thing.\">."
 (defun flyspell-generic-progmode-verify ()
   "Used for `flyspell-generic-check-word-predicate' in programming modes."
   ;; (point) is next char after the word. Must check one char before.
-  (let ((f (get-text-property (- (point) 1) 'face)))
-    (memq f flyspell-prog-text-faces)))
+  (unless (bobp)
+    (let ((f (get-text-property (- (point) 1) 'face)))
+      (memq f flyspell-prog-text-faces))))
 
 ;; Records the binding of M-TAB in effect before flyspell was activated.
 (defvar flyspell--prev-meta-tab-binding)
-- 
2.21.0


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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-05-28 20:43 bug#35967: [PATCH] avoid flyspell error if point is at bob Alex Branham
@ 2019-05-29 16:08 ` Eli Zaretskii
  2019-05-30 11:58   ` Basil L. Contovounesios
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Eli Zaretskii @ 2019-05-29 16:08 UTC (permalink / raw)
  To: Alex Branham; +Cc: 35967

> From: Alex Branham <alex.branham@gmail.com>
> Date: Tue, 28 May 2019 15:43:53 -0500
> 
> >From e130dfcb542af667fbef6e6eb867c46eee6d9746 Mon Sep 17 00:00:00 2001
> From: Alex Branham <alex.branham@gmail.com>
> Date: Tue, 28 May 2019 15:40:26 -0500
> Subject: [PATCH] Avoid a flyspell error if point is at beginning of buffer
> 
> * lisp/textmodes/flyspell.el (flyspell-generic-progmode-verify):
> Check if point is at bob.  This prevents an error when e.g.
> 'flyspell-auto-correct-word' gets called with point at the
> beginning of the buffer.
> ---
>  lisp/textmodes/flyspell.el | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
> index d18916dfd0..e711fe72b2 100644
> --- a/lisp/textmodes/flyspell.el
> +++ b/lisp/textmodes/flyspell.el
> @@ -424,8 +424,9 @@ like <img alt=\"Some thing.\">."
>  (defun flyspell-generic-progmode-verify ()
>    "Used for `flyspell-generic-check-word-predicate' in programming modes."
>    ;; (point) is next char after the word. Must check one char before.
> -  (let ((f (get-text-property (- (point) 1) 'face)))
> -    (memq f flyspell-prog-text-faces)))
> +  (unless (bobp)
> +    (let ((f (get-text-property (- (point) 1) 'face)))
> +      (memq f flyspell-prog-text-faces))))

Thanks.

Maybe it's just me, but whenever I see bobp, I always have to consult
the docs regarding what happens in a narrowed buffer.  For that
reason, I prefer comparison with point-min instead.

Am I the only one troubled by that?





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-05-29 16:08 ` Eli Zaretskii
@ 2019-05-30 11:58   ` Basil L. Contovounesios
  2019-06-11 14:12   ` npostavs
  2019-06-18 12:18   ` Stefan Monnier
  2 siblings, 0 replies; 11+ messages in thread
From: Basil L. Contovounesios @ 2019-05-30 11:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alex Branham, 35967

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex Branham <alex.branham@gmail.com>
>> Date: Tue, 28 May 2019 15:43:53 -0500
>> 
>> >From e130dfcb542af667fbef6e6eb867c46eee6d9746 Mon Sep 17 00:00:00 2001
>> From: Alex Branham <alex.branham@gmail.com>
>> Date: Tue, 28 May 2019 15:40:26 -0500
>> Subject: [PATCH] Avoid a flyspell error if point is at beginning of buffer
>> 
>> * lisp/textmodes/flyspell.el (flyspell-generic-progmode-verify):
>> Check if point is at bob.  This prevents an error when e.g.
>> 'flyspell-auto-correct-word' gets called with point at the
>> beginning of the buffer.
>> ---
>>  lisp/textmodes/flyspell.el | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>> 
>> diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
>> index d18916dfd0..e711fe72b2 100644
>> --- a/lisp/textmodes/flyspell.el
>> +++ b/lisp/textmodes/flyspell.el
>> @@ -424,8 +424,9 @@ like <img alt=\"Some thing.\">."
>>  (defun flyspell-generic-progmode-verify ()
>>    "Used for `flyspell-generic-check-word-predicate' in programming modes."
>>    ;; (point) is next char after the word. Must check one char before.
>> -  (let ((f (get-text-property (- (point) 1) 'face)))
>> -    (memq f flyspell-prog-text-faces)))
>> +  (unless (bobp)
>> +    (let ((f (get-text-property (- (point) 1) 'face)))
>> +      (memq f flyspell-prog-text-faces))))
>
> Maybe it's just me, but whenever I see bobp, I always have to consult
> the docs regarding what happens in a narrowed buffer.  For that
> reason, I prefer comparison with point-min instead.
>
> Am I the only one troubled by that?

I wouldn't say I'm troubled by what bobp does in a narrowed buffer
(I would expect it to heed buffer restrictions).

Rather, bobp conveys only some property of current state, whereas
explicit comparisons to point-min such as (> (point) (point-min)) or
(max (point-min) (1- (point))) additionally suggest that subsequent
buffer position operations are being guarded from out-of-bounds errors.

But that's just my reading into the distinction, so it probably comes
down to taste and habits.

-- 
Basil





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-05-29 16:08 ` Eli Zaretskii
  2019-05-30 11:58   ` Basil L. Contovounesios
@ 2019-06-11 14:12   ` npostavs
  2019-06-11 14:39     ` Eli Zaretskii
  2019-06-18 12:18   ` Stefan Monnier
  2 siblings, 1 reply; 11+ messages in thread
From: npostavs @ 2019-06-11 14:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alex Branham, 35967

Eli Zaretskii <eliz@gnu.org> writes:

>> +  (unless (bobp)
>> +    (let ((f (get-text-property (- (point) 1) 'face)))
>> +      (memq f flyspell-prog-text-faces))))
>
> Thanks.
>
> Maybe it's just me, but whenever I see bobp, I always have to consult
> the docs regarding what happens in a narrowed buffer.  For that
> reason, I prefer comparison with point-min instead.
>
> Am I the only one troubled by that?

It doesn't take too long to check the docstring, does it?  And it seems
fairly easy to remember that bobp should treat a narrowed buffer the
same way that beginning-of-buffer will.

My only complaint about bobp is that it's abbreviated perhaps a little
too far, to the point of obscurity.  As in, who is "bob" and why are we
asking about him?





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-11 14:12   ` npostavs
@ 2019-06-11 14:39     ` Eli Zaretskii
  2019-06-14 18:17       ` Alex Branham
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2019-06-11 14:39 UTC (permalink / raw)
  To: npostavs; +Cc: alex.branham, 35967

> From: npostavs@gmail.com
> Cc: Alex Branham <alex.branham@gmail.com>,  35967@debbugs.gnu.org
> Date: Tue, 11 Jun 2019 10:12:12 -0400
> 
> it seems fairly easy to remember that bobp should treat a narrowed
> buffer the same way that beginning-of-buffer will.

Not for this old curmudgeon, evidently.

> My only complaint about bobp is that it's abbreviated perhaps a little
> too far, to the point of obscurity.  As in, who is "bob" and why are we
> asking about him?

That question has a known answer: Bob's your uncle.





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-11 14:39     ` Eli Zaretskii
@ 2019-06-14 18:17       ` Alex Branham
  2019-06-14 18:31         ` npostavs
  0 siblings, 1 reply; 11+ messages in thread
From: Alex Branham @ 2019-06-14 18:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35967, npostavs

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


On Tue 11 Jun 2019 at 09:39, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: npostavs@gmail.com
>> Cc: Alex Branham <alex.branham@gmail.com>,  35967@debbugs.gnu.org
>> Date: Tue, 11 Jun 2019 10:12:12 -0400
>>
>> it seems fairly easy to remember that bobp should treat a narrowed
>> buffer the same way that beginning-of-buffer will.
>
> Not for this old curmudgeon, evidently.

Here's a new patch that checks for (equal (point) 1) rather than using
bobp. OK to push to master?

Alex


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Avoid-a-flyspell-error-if-point-is-at-beginning-of-b.patch --]
[-- Type: text/x-patch, Size: 1391 bytes --]

From c7d7ccaf5b94a1146e4664ec21564f982686fcab Mon Sep 17 00:00:00 2001
From: Alex Branham <alex.branham@gmail.com>
Date: Fri, 14 Jun 2019 13:15:36 -0500
Subject: [PATCH] Avoid a flyspell error if point is at beginning of buffer

* lisp/textmodes/flyspell.el (flyspell-generic-progmode-verify): Check
if point is at the beginning of the buffer.  This prevents an error
when e.g. 'flyspell-auto-correct-word' gets called with point at the
beginning of the buffer.
---
 lisp/textmodes/flyspell.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index d18916dfd0..7237a0f8ab 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -423,9 +423,10 @@ flyspell-prog-text-faces
 
 (defun flyspell-generic-progmode-verify ()
   "Used for `flyspell-generic-check-word-predicate' in programming modes."
-  ;; (point) is next char after the word. Must check one char before.
-  (let ((f (get-text-property (- (point) 1) 'face)))
-    (memq f flyspell-prog-text-faces)))
+  (unless (eql (point) 1)
+    ;; (point) is next char after the word. Must check one char before.
+    (let ((f (get-text-property (- (point) 1) 'face)))
+      (memq f flyspell-prog-text-faces))))
 
 ;; Records the binding of M-TAB in effect before flyspell was activated.
 (defvar flyspell--prev-meta-tab-binding)
-- 
2.21.0


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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-14 18:17       ` Alex Branham
@ 2019-06-14 18:31         ` npostavs
  2019-06-14 18:41           ` Alex Branham
  0 siblings, 1 reply; 11+ messages in thread
From: npostavs @ 2019-06-14 18:31 UTC (permalink / raw)
  To: Alex Branham; +Cc: 35967, npostavs

Alex Branham <alex.branham@gmail.com> writes:

> Here's a new patch that checks for (equal (point) 1) rather than using
> bobp. OK to push to master?

> +  (unless (eql (point) 1)
> +    ;; (point) is next char after the word. Must check one char before.
> +    (let ((f (get-text-property (- (point) 1) 'face)))

This will do the wrong thing when point is at the beginning of a
narrowed buffer.  Score one point for bobp?





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-14 18:31         ` npostavs
@ 2019-06-14 18:41           ` Alex Branham
  2019-06-14 19:14             ` Andreas Schwab
  0 siblings, 1 reply; 11+ messages in thread
From: Alex Branham @ 2019-06-14 18:41 UTC (permalink / raw)
  To: npostavs; +Cc: 35967

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


On Fri 14 Jun 2019 at 13:31, npostavs@gmail.com wrote:

> Alex Branham <alex.branham@gmail.com> writes:
>
>> Here's a new patch that checks for (equal (point) 1) rather than using
>> bobp. OK to push to master?
>
>> +  (unless (eql (point) 1)
>> +    ;; (point) is next char after the word. Must check one char before.
>> +    (let ((f (get-text-property (- (point) 1) 'face)))
>
> This will do the wrong thing when point is at the beginning of a
> narrowed buffer.  Score one point for bobp?

Oh, of course. Here it is with (point-min), which should work I think.

Alex


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Avoid-a-flyspell-error-if-point-is-at-beginning-of-b.patch --]
[-- Type: text/x-patch, Size: 1401 bytes --]

From f4ecc0a1657e736173f6daeabbe870dae4e8a7f1 Mon Sep 17 00:00:00 2001
From: Alex Branham <alex.branham@gmail.com>
Date: Fri, 14 Jun 2019 13:15:36 -0500
Subject: [PATCH] Avoid a flyspell error if point is at beginning of buffer

* lisp/textmodes/flyspell.el (flyspell-generic-progmode-verify): Check
if point is at the beginning of the buffer.  This prevents an error
when e.g. 'flyspell-auto-correct-word' gets called with point at the
beginning of the buffer.
---
 lisp/textmodes/flyspell.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index d18916dfd0..22f9db4363 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -423,9 +423,10 @@ flyspell-prog-text-faces
 
 (defun flyspell-generic-progmode-verify ()
   "Used for `flyspell-generic-check-word-predicate' in programming modes."
-  ;; (point) is next char after the word. Must check one char before.
-  (let ((f (get-text-property (- (point) 1) 'face)))
-    (memq f flyspell-prog-text-faces)))
+  (unless (eql (point) (point-min))
+    ;; (point) is next char after the word. Must check one char before.
+    (let ((f (get-text-property (- (point) 1) 'face)))
+      (memq f flyspell-prog-text-faces))))
 
 ;; Records the binding of M-TAB in effect before flyspell was activated.
 (defvar flyspell--prev-meta-tab-binding)
-- 
2.21.0


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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-14 18:41           ` Alex Branham
@ 2019-06-14 19:14             ` Andreas Schwab
  2019-06-17 19:04               ` Alex Branham
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Schwab @ 2019-06-14 19:14 UTC (permalink / raw)
  To: Alex Branham; +Cc: 35967, npostavs

On Jun 14 2019, Alex Branham <alex.branham@gmail.com> wrote:

> diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
> index d18916dfd0..22f9db4363 100644
> --- a/lisp/textmodes/flyspell.el
> +++ b/lisp/textmodes/flyspell.el
> @@ -423,9 +423,10 @@ flyspell-prog-text-faces
>  
>  (defun flyspell-generic-progmode-verify ()
>    "Used for `flyspell-generic-check-word-predicate' in programming modes."
> -  ;; (point) is next char after the word. Must check one char before.
> -  (let ((f (get-text-property (- (point) 1) 'face)))
> -    (memq f flyspell-prog-text-faces)))
> +  (unless (eql (point) (point-min))
> +    ;; (point) is next char after the word. Must check one char before.
> +    (let ((f (get-text-property (- (point) 1) 'face)))

Perhaps change this to (1- (point)).

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-06-14 19:14             ` Andreas Schwab
@ 2019-06-17 19:04               ` Alex Branham
  0 siblings, 0 replies; 11+ messages in thread
From: Alex Branham @ 2019-06-17 19:04 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: npostavs, 35967-done


On Fri 14 Jun 2019 at 14:14, Andreas Schwab <schwab@linux-m68k.org> wrote:

>> +    (let ((f (get-text-property (- (point) 1) 'face)))
>
> Perhaps change this to (1- (point)).

Thanks, I made that change and pushed as 1942f4ccba52896e3e97789dc6b51926ad74c591 on the master branch.

Alex





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

* bug#35967: [PATCH] avoid flyspell error if point is at bob
  2019-05-29 16:08 ` Eli Zaretskii
  2019-05-30 11:58   ` Basil L. Contovounesios
  2019-06-11 14:12   ` npostavs
@ 2019-06-18 12:18   ` Stefan Monnier
  2 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2019-06-18 12:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alex Branham, 35967

> Am I the only one troubled by that?

I find it a lot more clear than (eq (point) (point-min)).
But if we start avoiding `bobp`, we should then tweak the byte-compiler to
turn (eq (point) (point-min)) into `bobp` for us.


        Stefan






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

end of thread, other threads:[~2019-06-18 12:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 20:43 bug#35967: [PATCH] avoid flyspell error if point is at bob Alex Branham
2019-05-29 16:08 ` Eli Zaretskii
2019-05-30 11:58   ` Basil L. Contovounesios
2019-06-11 14:12   ` npostavs
2019-06-11 14:39     ` Eli Zaretskii
2019-06-14 18:17       ` Alex Branham
2019-06-14 18:31         ` npostavs
2019-06-14 18:41           ` Alex Branham
2019-06-14 19:14             ` Andreas Schwab
2019-06-17 19:04               ` Alex Branham
2019-06-18 12:18   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).