unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mpn@google.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: [PATCH] textmodes/flyspell.el (flyspell-post-command-hook): Decided whether to check previous word while in correct buffer.
Date: Tue, 26 Mar 2013 19:09:05 +0100	[thread overview]
Message-ID: <ed66319a42c3c8e4ab3f4041ec0b78b26461529c.1364320939.git.mina86@mina86.com> (raw)

From: Michal Nazarewicz <mina86@mina86.com>

If command changed the buffer, the decision may be made based on the
current buffer even though it should based on the previous one.  This
may lead to false positives and more importantly to errors since
`flyspell-pre-point' is buffer local so it may have unsanitised value
(such as nil) in previous buffer.

To be honest, I'm not sure how this can happen since
`flyspell-pre-point' is set in previous buffer, but nonetheless, I've
been encountering the error for quite some time and finally decided to
fix it.  Interestingly, line making `flyspell-pre-point'
a buffer-local variable has a very revealing "Why?? --Stef" comment.

While at it, remove uneccessary (progn ...).
---
 lisp/ChangeLog             | 14 ++++++++++++++
 lisp/textmodes/flyspell.el | 27 +++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5b24164..ccd4c13 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
+2013-03-26  Michal Nazarewicz  <mina86@mina86.com>
+
+	* textmodes/flyspell.el (flyspell-post-command-hook): Decided whether
+	to check previous word while in correct buffer.  If command changed
+	the buffer, the decision may be made based on the current buffer even
+	though it should based on the previous one.  This may lead to false
+	positives and more importantly to errors since `flyspell-pre-point' is
+	buffer local so it may have unsanitised value (such as nil) in
+	previous buffer.  To be honest, I'm not sure how this can happen since
+	`flyspell-pre-point' is set in previous buffer, but nonetheless, I've
+	been encountering the error for quite some time and finally decided to
+	fix it.  Interestingly, line making `flyspell-pre-point'
+	a buffer-local variable has a very revealing "Why?? --Stef" comment.
+
 2013-03-26  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* desktop.el (desktop--v2s): Rename from desktop-internal-v2s.
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 6ab3e3d..698dac0 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -955,12 +955,12 @@ Mostly we check word delimiters."
       (let ((command this-command)
             ;; Prevent anything we do from affecting the mark.
             deactivate-mark)
-        (if (flyspell-check-pre-word-p)
-            (with-current-buffer flyspell-pre-buffer
-              '(flyspell-debug-signal-pre-word-checked)
+        (when (buffer-live-p flyspell-pre-buffer)
+          (with-current-buffer flyspell-pre-buffer
+            (when (flyspell-check-pre-word-p)
               (save-excursion
                 (goto-char flyspell-pre-point)
-                (flyspell-word))))
+                (flyspell-word)))))
         (if (flyspell-check-word-p)
             (progn
               '(flyspell-debug-signal-word-checked)
@@ -974,16 +974,15 @@ Mostly we check word delimiters."
               ;; FLYSPELL-CHECK-PRE-WORD-P
               (setq flyspell-pre-pre-buffer (current-buffer))
               (setq flyspell-pre-pre-point  (point)))
-          (progn
-            (setq flyspell-pre-pre-buffer nil)
-            (setq flyspell-pre-pre-point  nil)
-            ;; when a word is not checked because of a delayed command
-            ;; we do not disable the ispell cache.
-            (if (and (symbolp this-command)
-                     (get this-command 'flyspell-delayed))
-                (progn
-                  (setq flyspell-word-cache-end -1)
-                  (setq flyspell-word-cache-result '_)))))
+          (setq flyspell-pre-pre-buffer nil)
+          (setq flyspell-pre-pre-point  nil)
+          ;; when a word is not checked because of a delayed command
+          ;; we do not disable the ispell cache.
+          (if (and (symbolp this-command)
+                   (get this-command 'flyspell-delayed))
+              (progn
+                (setq flyspell-word-cache-end -1)
+                (setq flyspell-word-cache-result '_))))
         (while (and (not (input-pending-p)) (consp flyspell-changes))
           (let ((start (car (car flyspell-changes)))
                 (stop  (cdr (car flyspell-changes))))
-- 
1.8.1.3.718.g2a547ef




             reply	other threads:[~2013-03-26 18:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-26 18:09 Michal Nazarewicz [this message]
2013-03-27  1:09 ` [PATCH] textmodes/flyspell.el (flyspell-post-command-hook): Decided whether to check previous word while in correct buffer Stefan Monnier
2013-03-27 12:47   ` [PATCHv2] textmodes/flyspell.el: Don't check pre-word if buffer was switched Michal Nazarewicz
2013-04-20  4:53     ` Agustin Martin
2013-04-20 15:46       ` Michal Nazarewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed66319a42c3c8e4ab3f4041ec0b78b26461529c.1364320939.git.mina86@mina86.com \
    --to=mpn@google.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).