[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCHv2] textmodes/flyspell.el: Don't check pre-word if buffer was swit
[PATCHv2] textmodes/flyspell.el: Don't check pre-word if buffer was switched.
Wed, 27 Mar 2013 13:47:51 +0100
Notmuch/0.15.2+55~geb6e9d8 (http://notmuchmail.org) Emacs/126.96.36.199 (x86_64-unknown-linux-gnu)
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.
To avoid the problem, change flyspell-check-pre-word-p so that it does
not allow checking of pre-word if command changed buffer
(ie. `flyspell-pre-buffer' is not current buffer).
lisp/ChangeLog | 11 +++++++++++
lisp/textmodes/flyspell.el | 25 +++++++++++--------------
2 files changed, 22 insertions(+), 14 deletions(-)
On Wed, Mar 27 2013, Stefan Monnier <address@hidden> wrote:
> Can't we just say that if current-buffer is different from the previous
> one, then don't do anything?
Sure. I don't mind either way.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5b24164..e310e35 100644
@@ -1,3 +1,14 @@
+2013-03-27 Michal Nazarewicz <address@hidden>
+ * textmodes/flyspell.el (flyspell-check-pre-word-p): Return nil if
+ command changed buffer (ie. `flyspell-pre-buffer' is not current
+ buffer), which prevents making decisions based on invalid value of
+ `flyspell-pre-point' in the wrong buffer. Most notably, this used to
+ cause an error when `flyspell-pre-point' was nil after switching
+ (flyspell-post-command-hook): No longer needs to change buffers when
+ checking pre-word. While at it remove unnecessary progn.
2013-03-26 Stefan Monnier <address@hidden>
* desktop.el (desktop--v2s): Rename from desktop-internal-v2s.
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 6ab3e3d..81f17c8 100644
@@ -738,7 +738,7 @@ before the current command."
(let ((ispell-otherchars (ispell-get-otherchars)))
((not (and (numberp flyspell-pre-point)
- (buffer-live-p flyspell-pre-buffer)))
+ (eq flyspell-pre-buffer (current-buffer))))
((and (eq flyspell-pre-pre-point flyspell-pre-point)
(eq flyspell-pre-pre-buffer flyspell-pre-buffer))
@@ -956,11 +956,10 @@ Mostly we check word delimiters."
;; Prevent anything we do from affecting the mark.
- (with-current-buffer flyspell-pre-buffer
- (goto-char flyspell-pre-point)
+ (goto-char flyspell-pre-point)
@@ -974,16 +973,14 @@ Mostly we check word delimiters."
(setq flyspell-pre-pre-buffer (current-buffer))
(setq flyspell-pre-pre-point (point)))
- (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)
+ (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.
+ (when (and (symbolp this-command)
(get this-command 'flyspell-delayed))
- (setq flyspell-word-cache-end -1)
- (setq flyspell-word-cache-result '_)))))
+ (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))))