From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel 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 Message-ID: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1364321377 12658 80.91.229.3 (26 Mar 2013 18:09:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Mar 2013 18:09:37 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 26 19:10:03 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UKYJt-000502-Cs for ged-emacs-devel@m.gmane.org; Tue, 26 Mar 2013 19:10:01 +0100 Original-Received: from localhost ([::1]:58919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKYJV-0007dF-9k for ged-emacs-devel@m.gmane.org; Tue, 26 Mar 2013 14:09:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKYJP-0007Td-OW for emacs-devel@gnu.org; Tue, 26 Mar 2013 14:09:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKYJM-0003lx-Lv for emacs-devel@gnu.org; Tue, 26 Mar 2013 14:09:31 -0400 Original-Received: from mail-ea0-x22c.google.com ([2a00:1450:4013:c01::22c]:44348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKYJM-0003lp-DY for emacs-devel@gnu.org; Tue, 26 Mar 2013 14:09:28 -0400 Original-Received: by mail-ea0-f172.google.com with SMTP id z7so1355310eaf.31 for ; Tue, 26 Mar 2013 11:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=tAgrfcI+ZcxH8OnlsPYHnqIdE1dX7e8274AIQlbA/xY=; b=RjsaoCOgjul7IQRVh/xBU1+7HgG1iw8LpvUjzNpkvQ5TMFyVSX72ZbArIZ3ESMp8k7 jvTLwM2vwsuBlS0A68hORVsVOVfevWV2aQUFzOxt2w4LUuo06lRzO0GTElQ8uu4WlFUe M7/1ztvynmogOSrbdFf7oi4uiDdI/1rRRwctY56g+W7/SxIfu0WE6z9ppM0z4EHO/J2y 1KY0ZirrTcP78rS9aqlJkSegeGOenJgx1lRUvF89oEwKeUVQP0XPQMKbtXIDWn5EL3KS 9lZC0Iy3qnaCgpMMvUSbkhhNB0FxcbsoIFv3aXKIJtJdbvdbi3HPmU5ctZfhH/UP20d+ U8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=tAgrfcI+ZcxH8OnlsPYHnqIdE1dX7e8274AIQlbA/xY=; b=kt6mFFP1jZCt1qbgQa5FJt+IiS3jKYaeDrY3DuEHAPR6NlNjWfOp5RsbArLwHA38nb f/XD6IIDyLWIdmSQMi++tbPgWpqi8WJX/xP3L1F3jOeuc+/3PRgmJOZWVm2PQr/20lBQ w7hVvKGF0k9xaPX2orBgMnk1Yf85FBpdx7DIbPd6zTDn2Kodamzj1NVTVegEciN7G1rw 4/KyglJ1AgPhoBu2AmVcgYiuqTeEjvFbmIqFg7J3WKhxFm1ObofANPASrJq7SoySkVXt 3Dy5bZiFegGDpfUp2Y2d2HNxvcsZCIBtze07SDNyN00p7AF6SU9lQVYWx8d/cWf/lvg8 ricA== X-Received: by 10.14.173.67 with SMTP id u43mr47419771eel.22.1364321367225; Tue, 26 Mar 2013 11:09:27 -0700 (PDT) Original-Received: from mpn-glaptop.corp.google.com ([172.28.90.132]) by mx.google.com with ESMTPS id n2sm146473eeo.10.2013.03.26.11.09.24 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Mar 2013 11:09:25 -0700 (PDT) X-Mailer: git-send-email 1.8.1.3.718.g2a547ef X-Gm-Message-State: ALoCoQlM2DIUobMAUcAb0x8U4mZGH5LiTVh517bH5XHadP/MQqgBLvwFocyAi/WiR3H5ZW4b8VFvnQTLoEtDEeHnkpgM2oK/eU98SgBiXsVMpHG/WV6ryyYQ08dKt/3rD6gGj+T9uGBk643q+aE8CQf7tQjsr+SGiAmp9hLgwcKeQGh5GDIRJqR6a46MD/Tr860ndxuCpXF3 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158234 Archived-At: From: Michal Nazarewicz 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 + + * 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 * 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