;;; flyspell.el --- on-the-fly spell checker
-;; Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000, 2002, 2003, 2004,
+;; 2005 Free Software Foundation, Inc.
;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr>
;; Maintainer: FSF
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
'emacs))
"The type of Emacs we are currently running.")
-(defvar flyspell-use-local-map
- (or (eq flyspell-emacs 'xemacs)
- (not (string< emacs-version "20"))))
-
;*---------------------------------------------------------------------*/
;* User configuration ... */
;*---------------------------------------------------------------------*/
:type 'boolean)
(defcustom flyspell-mark-duplications-flag t
- "*Non-nil means Flyspell reports a repeated word as an error."
+ "*Non-nil means Flyspell reports a repeated word as an error.
+Detection of repeated words is not implemented in
+\"large\" regions; see `flyspell-large-region'."
:group 'flyspell
:type 'boolean)
"*The maximum distance for finding duplicates of unrecognized words.
This applies to the feature that when a word is not found in the dictionary,
if the same spelling occurs elsewhere in the buffer,
-Flyspell uses a different face (`flyspell-duplicate-face') to highlight it.
+Flyspell uses a different face (`flyspell-duplicate') to highlight it.
This variable specifies how far to search to find such a duplicate.
-1 means no limit (search the whole buffer).
0 means do not search for duplicate unrecognized spellings."
"*List of functions to be called when incorrect words are encountered.
Each function is given three arguments: the beginning and the end
of the incorrect region. The third is either the symbol 'doublon' or the list
-of possible corrections as returned by 'ispell-parse-output'.
+of possible corrections as returned by `ispell-parse-output'.
If any of the functions return non-Nil, the word is not highlighted as
incorrect."
:version "21.1"
:type 'boolean)
-;;;###autoload
(defcustom flyspell-mode-line-string " Fly"
"*String displayed on the modeline when flyspell is active.
Set this to nil if you don't want a modeline indicator."
flyspell methods. Else, if the region is large, a new Ispell process is
spawned for speed.
+Doubled words are not detected in a large region, because Ispell
+does not check for them.
+
If `flyspell-large-region' is nil, all regions are treated as small."
:group 'flyspell
:version "21.1"
- :type '(choice number boolean))
+ :type '(choice number (const :tag "All small" nil)))
(defcustom flyspell-insert-function (function insert)
"*Function for inserting word by flyspell upon correction."
;*---------------------------------------------------------------------*/
;* The minor mode declaration. */
;*---------------------------------------------------------------------*/
-(eval-when-compile (defvar flyspell-local-mouse-map))
-
-;;;###autoload
-(defvar flyspell-mode nil)
-(make-variable-buffer-local 'flyspell-mode)
-
(defvar flyspell-mouse-map
(let ((map (make-sparse-keymap)))
- (if flyspell-use-meta-tab
- (define-key map "\M-\t" #'flyspell-auto-correct-word))
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2])
#'flyspell-correct-word)
- (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
- (define-key map [(control \,)] 'flyspell-goto-next-error)
- (define-key map [(control \.)] 'flyspell-auto-correct-word)
- map))
+ map)
+ "Keymap for Flyspell to put on erroneous words.")
(defvar flyspell-mode-map
(let ((map (make-sparse-keymap)))
- ;; mouse, keyboard bindings and misc definition
(if flyspell-use-meta-tab
(define-key map "\M-\t" 'flyspell-auto-correct-word))
- (cond
- ;; I don't understand this test, so I left it as is. --Stef
- ((or (featurep 'xemacs) flyspell-use-local-map)
- (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
- (define-key map [(control ?\,)] 'flyspell-goto-next-error)
- (define-key map [(control ?\.)] 'flyspell-auto-correct-word)))
- map))
-
-;; the name of the overlay property that defines the keymap
-(defvar flyspell-overlay-keymap-property-name 'keymap)
+ (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
+ (define-key map [(control ?\,)] 'flyspell-goto-next-error)
+ (define-key map [(control ?\.)] 'flyspell-auto-correct-word)
+ map)
+ "Minor mode keymap for Flyspell mode--for the whole buffer.")
;; dash character machinery
(defvar flyspell-consider-dash-as-word-delimiter-flag nil
;*---------------------------------------------------------------------*/
;* Highlighting */
;*---------------------------------------------------------------------*/
-(defface flyspell-incorrect-face
+(defface flyspell-incorrect
'((((class color)) (:foreground "OrangeRed" :bold t :underline t))
(t (:bold t)))
"Face used for marking a misspelled word in Flyspell."
:group 'flyspell)
+;; backward-compatibility alias
+(put 'flyspell-incorrect-face 'face-alias 'flyspell-incorrect)
-(defface flyspell-duplicate-face
+(defface flyspell-duplicate
'((((class color)) (:foreground "Gold3" :bold t :underline t))
(t (:bold t)))
"Face used for marking a misspelled word that appears twice in the buffer.
See also `flyspell-duplicate-distance'."
:group 'flyspell)
+;; backward-compatibility alias
+(put 'flyspell-duplicate-face 'face-alias 'flyspell-duplicate)
(defvar flyspell-overlay nil)
;*---------------------------------------------------------------------*/
;* flyspell-mode ... */
;*---------------------------------------------------------------------*/
+;;;###autoload(defvar flyspell-mode nil)
;;;###autoload
(define-minor-mode flyspell-mode
"Minor mode performing on-the-fly spelling checking.
;*---------------------------------------------------------------------*/
(defun flyspell-mode-on ()
"Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
- (setq ispell-highlight-face 'flyspell-incorrect-face)
+ (setq ispell-highlight-face 'flyspell-incorrect)
;; local dictionaries setup
(or ispell-local-dictionary ispell-dictionary
(if flyspell-default-dictionary
(let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
(if mode-predicate
(setq flyspell-generic-check-word-p mode-predicate)))
- ;; work around the fact that the `local-map' text-property replaces the
- ;; buffer's local map rather than shadowing it.
- (set (make-local-variable 'flyspell-mouse-map)
- (let ((map (copy-keymap flyspell-mouse-map)))
- (set-keymap-parent map (current-local-map))
- (if (and (eq flyspell-emacs 'emacs)
- (not (string< emacs-version "20")))
- (define-key map '[tool-bar] nil))
- map))
- (set (make-local-variable 'flyspell-mode-map)
- (let ((map (copy-keymap flyspell-mode-map)))
- (set-keymap-parent map (current-local-map))
- (if (and (eq flyspell-emacs 'emacs)
- (not (string< emacs-version "20")))
- (define-key map '[tool-bar] nil))
- map))
;; the welcome message
(if (and flyspell-issue-message-flag
flyspell-issue-welcome-flag
(interactive-p))
(let ((binding (where-is-internal 'flyspell-auto-correct-word
nil 'non-ascii)))
- (message
+ (message "%s"
(if binding
(format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
(key-description binding))
(sort (car (cdr (cdr poss))) 'string<)
(car (cdr (cdr poss)))))))
(if flyspell-issue-message-flag
- (message (format "mispelling `%s' %S" word replacements)))))
+ (message "mispelling `%s' %S" word replacements))))
;*---------------------------------------------------------------------*/
;* flyspell-word-search-backward ... */
(setq r p)
(goto-char p))))
r)))
-
+
;*---------------------------------------------------------------------*/
;* flyspell-word-search-forward ... */
;*---------------------------------------------------------------------*/
(setq r p)
(goto-char (1+ p)))))
r)))
-
+
;*---------------------------------------------------------------------*/
;* flyspell-word ... */
;*---------------------------------------------------------------------*/
flyspell-mark-duplications-flag
(save-excursion
(goto-char (1- start))
- (let ((p (flyspell-word-search-backward
+ (let ((p (flyspell-word-search-backward
word
(- start (1+ (- end start))))))
(and p (/= p (1- start))))))
(if flyspell-highlight-flag
(flyspell-highlight-duplicate-region
start end poss)
- (message (format "duplicate `%s'" word)))
+ (message "duplicate `%s'" word))
nil)
(t
(setq flyspell-word-cache-result nil)
(flyspell-notify-misspell start end word poss))
nil))))
;; return to original location
- (goto-char cursor-location)
+ (goto-char cursor-location)
(if ispell-quit (setq ispell-quit nil))
res))))))))
(overlay-put flyspell-overlay 'flyspell-overlay t)
(overlay-put flyspell-overlay 'evaporate t)
(overlay-put flyspell-overlay 'help-echo "mouse-2: correct word at point")
- (if flyspell-use-local-map
- (overlay-put flyspell-overlay
- flyspell-overlay-keymap-property-name
- flyspell-mouse-map))
- (when (eq face 'flyspell-incorrect-face)
+ (overlay-put flyspell-overlay 'keymap flyspell-mouse-map)
+ (when (eq face 'flyspell-incorrect)
(and (stringp flyspell-before-incorrect-word-string)
(overlay-put flyspell-overlay 'before-string
flyspell-before-incorrect-word-string))
;; now we can use a new overlay
(setq flyspell-overlay
(make-flyspell-overlay
- beg end 'flyspell-incorrect-face 'highlight)))))))
+ beg end 'flyspell-incorrect 'highlight)))))))
;*---------------------------------------------------------------------*/
;* flyspell-highlight-duplicate-region ... */
;; now we can use a new overlay
(setq flyspell-overlay
(make-flyspell-overlay beg end
- 'flyspell-duplicate-face
+ 'flyspell-duplicate
'highlight)))))))
;*---------------------------------------------------------------------*/
(let ((num (car pos)))
(put-text-property num
(+ num (length flyspell-auto-correct-word))
- 'face
- 'flyspell-incorrect-face
+ 'face 'flyspell-incorrect
string))
(setq pos (cdr pos)))
(if (fboundp 'display-message)
(display-message 'no-log string)
- (message string))))
+ (message "%s" string))))
;*---------------------------------------------------------------------*/
;* flyspell-abbrev-table ... */
(defun flyspell-auto-correct-previous-hook ()
"Hook to track successive calls to `flyspell-auto-correct-previous-word'.
Sets `flyspell-auto-correct-previous-pos' to nil"
- (interactive)
+ (interactive)
(remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
(unless (eq this-command (function flyspell-auto-correct-previous-word))
(setq flyspell-auto-correct-previous-pos nil)))
;*---------------------------------------------------------------------*/
;* flyspell-auto-correct-previous-word ... */
;*---------------------------------------------------------------------*/
-(defun flyspell-auto-correct-previous-word (position)
+(defun flyspell-auto-correct-previous-word (position)
"*Auto correct the first mispelled word that occurs before point.
But don't look beyond what's visible on the screen."
(interactive "d")
(narrow-to-region top bot)
(overlay-recenter (point))
- (add-hook 'pre-command-hook
+ (add-hook 'pre-command-hook
(function flyspell-auto-correct-previous-hook) t t)
(unless flyspell-auto-correct-previous-pos
;; only reset if a new overlay exists
(setq flyspell-auto-correct-previous-pos nil)
-
+
(let ((overlay-list (overlays-in (point-min) position))
(new-overlay 'dummy-value))
-
+
;; search for previous (new) flyspell overlay
(while (and new-overlay
(or (not (flyspell-overlay-p new-overlay))
;; check if its face has changed
- (not (eq (get-char-property
- (overlay-start new-overlay) 'face)
- 'flyspell-incorrect-face))))
+ (not (eq (get-char-property
+ (overlay-start new-overlay) 'face)
+ 'flyspell-incorrect))))
(setq new-overlay (car-safe overlay-list))
(setq overlay-list (cdr-safe overlay-list)))
-
+
;; if nothing new exits new-overlay should be nil
(if new-overlay ;; the length of the word may change so go to the start
- (setq flyspell-auto-correct-previous-pos
+ (setq flyspell-auto-correct-previous-pos
(overlay-start new-overlay)))))
(when flyspell-auto-correct-previous-pos
and return t.
The third arg POSS is either the symbol 'doublon' or a list of
-possible corrections as returned by 'ispell-parse-output'.
+possible corrections as returned by `ispell-parse-output'.
-This function is meant to be added to 'flyspell-incorrect-hook'."
+This function is meant to be added to `flyspell-incorrect-hook'."
(when (consp poss)
(catch 'done
(let ((str (buffer-substring beg end))
and return t.
The third arg POSS is either the symbol 'doublon' or a list of
-possible corrections as returned by 'ispell-parse-output'.
+possible corrections as returned by `ispell-parse-output'.
-This function is meant to be added to 'flyspell-incorrect-hook'."
+This function is meant to be added to `flyspell-incorrect-hook'."
(when (consp poss)
(catch 'done
(let ((str (buffer-substring beg end))