From 3f1b25b580bf45f92c4ee4750771a987e5524299 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Agust=C3=ADn=20Mart=C3=ADn?= Date: Fri, 18 May 2012 09:04:04 +0200 Subject: [PATCH] textmodes/flyspell.el: Protect delay handling for otherchars against empty otherchars. (flyspell-check-pre-word-p, flyspell-check-word-p,flyspell-debug-signal-word-checked) --- lisp/ChangeLog | 6 ++ lisp/textmodes/flyspell.el | 142 ++++++++++++++++++++----------------- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e22b3d07985..774ea476fb3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-05-18 Agustín Martín Domingo + + * flyspell.el (flyspell-check-pre-word-p, flyspell-check-word-p) + (flyspell-debug-signal-word-checked): Protect delay handling for + otherchars against empty otherchars. + 2012-05-18 Stefan Monnier * emacs-lisp/lisp-mode.el (doc-string-elt): Move those properties to diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 156a7e532e8..89134a1d355 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -730,45 +730,50 @@ not the very same deplacement command." "Return non-nil if we should check the word before point. More precisely, it applies to the word that was before point before the current command." - (cond - ((or (not (numberp flyspell-pre-point)) - (not (bufferp flyspell-pre-buffer)) - (not (buffer-live-p flyspell-pre-buffer))) - nil) - ((and (eq flyspell-pre-pre-point flyspell-pre-point) - (eq flyspell-pre-pre-buffer flyspell-pre-buffer)) - nil) - ((or (and (= flyspell-pre-point (- (point) 1)) - (or (eq (char-syntax (char-after flyspell-pre-point)) ?w) - (string-match-p (ispell-get-otherchars) - (buffer-substring-no-properties - flyspell-pre-point (1+ flyspell-pre-point))))) - (= flyspell-pre-point (point)) - (= flyspell-pre-point (+ (point) 1))) - nil) - ((and (symbolp this-command) - (not executing-kbd-macro) - (or (get this-command 'flyspell-delayed) - (and (get this-command 'flyspell-deplacement) - (eq flyspell-previous-command this-command))) - (or (= (current-column) 0) - (= (current-column) flyspell-pre-column) - ;; If other post-command-hooks change the buffer, - ;; flyspell-pre-point can lie past eob (bug#468). - (null (char-after flyspell-pre-point)) - (or (eq (char-syntax (char-after flyspell-pre-point)) ?w) - (string-match-p (ispell-get-otherchars) - (buffer-substring-no-properties - flyspell-pre-point (1+ flyspell-pre-point)))))) - nil) - ((not (eq (current-buffer) flyspell-pre-buffer)) - t) - ((not (and (numberp flyspell-word-cache-start) - (numberp flyspell-word-cache-end))) - t) - (t - (or (< flyspell-pre-point flyspell-word-cache-start) - (> flyspell-pre-point flyspell-word-cache-end))))) + (let ((ispell-otherchars (ispell-get-otherchars))) + (cond + ((or (not (numberp flyspell-pre-point)) + (not (bufferp flyspell-pre-buffer)) + (not (buffer-live-p flyspell-pre-buffer))) + nil) + ((and (eq flyspell-pre-pre-point flyspell-pre-point) + (eq flyspell-pre-pre-buffer flyspell-pre-buffer)) + nil) + ((or (and (= flyspell-pre-point (- (point) 1)) + (or (eq (char-syntax (char-after flyspell-pre-point)) ?w) + (and (not (string= "" ispell-otherchars)) + (string-match-p + ispell-otherchars + (buffer-substring-no-properties + flyspell-pre-point (1+ flyspell-pre-point)))))) + (= flyspell-pre-point (point)) + (= flyspell-pre-point (+ (point) 1))) + nil) + ((and (symbolp this-command) + (not executing-kbd-macro) + (or (get this-command 'flyspell-delayed) + (and (get this-command 'flyspell-deplacement) + (eq flyspell-previous-command this-command))) + (or (= (current-column) 0) + (= (current-column) flyspell-pre-column) + ;; If other post-command-hooks change the buffer, + ;; flyspell-pre-point can lie past eob (bug#468). + (null (char-after flyspell-pre-point)) + (or (eq (char-syntax (char-after flyspell-pre-point)) ?w) + (and (not (string= "" ispell-otherchars)) + (string-match-p + ispell-otherchars + (buffer-substring-no-properties + flyspell-pre-point (1+ flyspell-pre-point))))))) + nil) + ((not (eq (current-buffer) flyspell-pre-buffer)) + t) + ((not (and (numberp flyspell-word-cache-start) + (numberp flyspell-word-cache-end))) + t) + (t + (or (< flyspell-pre-point flyspell-word-cache-start) + (> flyspell-pre-point flyspell-word-cache-end)))))) ;;*---------------------------------------------------------------------*/ ;;* The flyspell after-change-hook, store the change position. In */ @@ -812,31 +817,33 @@ Mostly we check word delimiters." "Return t when the word at `point' has to be checked. The answer depends of several criteria. Mostly we check word delimiters." - (cond - ((<= (- (point-max) 1) (point-min)) - ;; the buffer is not filled enough - nil) - ((and (and (> (current-column) 0) - (not (eq (current-column) flyspell-pre-column))) - (save-excursion - (backward-char 1) - (and (looking-at (flyspell-get-not-casechars)) - (not (looking-at (ispell-get-otherchars))) - (or flyspell-consider-dash-as-word-delimiter-flag - (not (looking-at "-")))))) - ;; yes because we have reached or typed a word delimiter. - t) - ((symbolp this-command) + (let ((ispell-otherchars (ispell-get-otherchars))) (cond - ((get this-command 'flyspell-deplacement) - (not (eq flyspell-previous-command this-command))) - ((get this-command 'flyspell-delayed) - ;; the current command is not delayed, that - ;; is that we must check the word now - (and (not unread-command-events) - (sit-for flyspell-delay))) - (t t))) - (t t))) + ((<= (- (point-max) 1) (point-min)) + ;; the buffer is not filled enough + nil) + ((and (and (> (current-column) 0) + (not (eq (current-column) flyspell-pre-column))) + (save-excursion + (backward-char 1) + (and (looking-at (flyspell-get-not-casechars)) + (or (string= "" ispell-otherchars) + (not (looking-at (ispell-get-otherchars)))) + (or flyspell-consider-dash-as-word-delimiter-flag + (not (looking-at "-")))))) + ;; yes because we have reached or typed a word delimiter. + t) + ((symbolp this-command) + (cond + ((get this-command 'flyspell-deplacement) + (not (eq flyspell-previous-command this-command))) + ((get this-command 'flyspell-delayed) + ;; the current command is not delayed, that + ;; is that we must check the word now + (and (not unread-command-events) + (sit-for flyspell-delay))) + (t t))) + (t t)))) ;;*---------------------------------------------------------------------*/ ;;* flyspell-debug-signal-no-check ... */ @@ -866,7 +873,8 @@ Mostly we check word delimiters." ;;*---------------------------------------------------------------------*/ (defun flyspell-debug-signal-word-checked () (setq debug-on-error t) - (let ((oldbuf (current-buffer)) + (let ((ispell-otherchars (ispell-get-otherchars)) + (oldbuf (current-buffer)) (point (point))) (with-current-buffer (get-buffer-create "*flyspell-debug*") (insert "WORD:\n") @@ -887,7 +895,8 @@ Mostly we check word delimiters." (save-excursion (backward-char 1) (and (and (looking-at (flyspell-get-not-casechars)) 1) - (not (looking-at (ispell-get-otherchars))) + (or (string= "" ispell-otherchars) + (not (looking-at (ispell-get-otherchars)))) (and (or flyspell-consider-dash-as-word-delimiter-flag (not (looking-at "\\-"))) 2)))))) c)))) @@ -903,7 +912,8 @@ Mostly we check word delimiters." (save-excursion (backward-char 1) (and (looking-at (flyspell-get-not-casechars)) - (not (looking-at (ispell-get-otherchars))) + (or (string= "" ispell-otherchars) + (not (looking-at (ispell-get-otherchars)))) (or flyspell-consider-dash-as-word-delimiter-flag (not (looking-at "\\-")))))))) c)) -- 2.39.2