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: [PATCHv2] textmodes/flyspell.el: Don't check pre-word if buffer was switched. Date: Wed, 27 Mar 2013 13:47:51 +0100 Organization: http://mina86.com/ Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1364388490 11935 80.91.229.3 (27 Mar 2013 12:48:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Mar 2013 12:48:10 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 27 13:48:37 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 1UKpmM-0007Zt-9U for ged-emacs-devel@m.gmane.org; Wed, 27 Mar 2013 13:48:34 +0100 Original-Received: from localhost ([::1]:58151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKply-000255-7t for ged-emacs-devel@m.gmane.org; Wed, 27 Mar 2013 08:48:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKplp-0001vh-8a for emacs-devel@gnu.org; Wed, 27 Mar 2013 08:48:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKplk-0003LS-3a for emacs-devel@gnu.org; Wed, 27 Mar 2013 08:48:01 -0400 Original-Received: from mail-ea0-x22f.google.com ([2a00:1450:4013:c01::22f]:56190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKplj-0003LF-QV for emacs-devel@gnu.org; Wed, 27 Mar 2013 08:47:56 -0400 Original-Received: by mail-ea0-f175.google.com with SMTP id r16so696738ead.20 for ; Wed, 27 Mar 2013 05:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:in-reply-to:organization :references:user-agent:x-face:face:x-pgp:x-pgp-fp:x-hashcash :x-hashcash:date:message-id:mime-version:content-type; bh=wvRyrHUxLTIq7/uP8PC8Otv/n19XrrrETS/ssKxSe7E=; b=jhQtNPgE4iS9JJ+I5K9iVb2jOgENmN6HGpfysnlm9J+/MQQiCA4lGMsWFosPeZ27VF r68zo4uQElNTVGySf2kfOUmqhL6ny0ztA9rA5jeSWAEzYGq1rILE3LcaAHZN/vD3VJE4 HdHme4B1ao6mchVbd1oPRkUGUpTxe3ueFrNQRGZaX3UJcrfr77WBaZptj97UkLrTYvUv VQoamQtXPwqptcnmAGqTsq+Wt+y84vipjCie+m0KZACT3934jy4rsfBE1N3kUs+WnEp2 F20kYCwt/MQP6jfHouq/77GWD36MV7ngtMP4ovn6beVBO+k3FVP4ZVeRr/Im54QGkgOE +Ldg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:in-reply-to:organization :references:user-agent:x-face:face:x-pgp:x-pgp-fp:x-hashcash :x-hashcash:date:message-id:mime-version:content-type :x-gm-message-state; bh=wvRyrHUxLTIq7/uP8PC8Otv/n19XrrrETS/ssKxSe7E=; b=ludyC8qA5sarR0v1WsF3u+GEvaSPtmfOABRxs6eMra9Y4+agyVUobGIwSw3bLKEF5S 4DTfNbI3UdIyX6Fo4qmdTofg4qdbG3iVCfWgbJJAUx2uiQNXV/gGZiLtMHYTBsbGi8kp hdp1uPK1w+niRpMx2d6pWhTGFRtXNaVhvShmWZuenbv0zGVCDAqiK/KX9y6IqQ23k18v yRHG2IoBYkIrbZEinILYda/NN1OUseXp5ey4KphVOpEX6l1+QqW+qrY+zZlTObSVk9tL PtPyl9LiEau1haO+O9nPg1weqFJDyFVhq+G7lC8AeonbY/JBKfR2Vjy6IO2ZIIxdLh21 H3kw== X-Received: by 10.14.173.196 with SMTP id v44mr55361737eel.29.1364388474598; Wed, 27 Mar 2013 05:47:54 -0700 (PDT) Original-Received: from mpn-glaptop (87-205-240-13.adsl.inetia.pl. [87.205.240.13]) by mx.google.com with ESMTPS id ca4sm31070713eeb.15.2013.03.27.05.47.52 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 27 Mar 2013 05:47:53 -0700 (PDT) In-Reply-To: User-Agent: Notmuch/0.15.2+55~geb6e9d8 (http://notmuchmail.org) Emacs/24.3.50.2 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR 4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:130327:monnier@iro.umontreal.ca::wo8VPoxoanK3yLqG:00000000000000000000000000000000000001kVg X-Hashcash: 1:20:130327:emacs-devel@gnu.org::FFET/e1q6xDXHiq3:0000000000000000000000000000000000000000004ZKs X-Gm-Message-State: ALoCoQmrC7jHCEl2DTEx9IyfvjzL5eiGRsfWVjrSgj0ht0RmmmwxETa9bPpOGvUrF6c+ms4+ZAeb/BcyXMJwPK8RRS8ycBqFRXT5rdZ1f22OgFQ9mEd8daV047UVUSAwcWgH/mGcE3J+8hKFvfxz/5lb2/Qr7UaSHSESzs982QKJ3X3+hFikWflPQ2gYGqrsArzgTrSN68d8TS6HIx2tJOj2/WzNWTRLPA== X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22f 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:158291 Archived-At: 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 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 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-03-27 Michal Nazarewicz + + * 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 + buffers + (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 * 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 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -738,7 +738,7 @@ before the current command." (let ((ispell-otherchars (ispell-get-otherchars))) (cond ((not (and (numberp flyspell-pre-point) - (buffer-live-p flyspell-pre-buffer))) + (eq flyspell-pre-buffer (current-buffer)))) nil) ((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. deactivate-mark) (if (flyspell-check-pre-word-p) - (with-current-buffer flyspell-pre-buffer + (save-excursion '(flyspell-debug-signal-pre-word-checked) - (save-excursion - (goto-char flyspell-pre-point) - (flyspell-word)))) + (goto-char flyspell-pre-point) + (flyspell-word))) (if (flyspell-check-word-p) (progn '(flyspell-debug-signal-word-checked) @@ -974,16 +973,14 @@ 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) + (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)) - (progn - (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))))