]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/flyspell.el
Message format spec fixes (2)
[gnu-emacs] / lisp / textmodes / flyspell.el
index 8bd6c731e3cdb08c6f1e8d91312b6f3a043d849d..e46b8533fc4ad6686a2d6cc213f9b82b5a8ab31e 100644 (file)
@@ -1,6 +1,7 @@
 ;;; 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
@@ -20,8 +21,8 @@
 
 ;; 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 ...                                           */
 ;*---------------------------------------------------------------------*/
@@ -80,7 +77,9 @@ Non-nil means use highlight, nil means use minibuffer messages."
   :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)
 
@@ -94,7 +93,7 @@ Non-nil means use highlight, nil means use minibuffer messages."
   "*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."
@@ -172,7 +171,7 @@ command was not the very same command."
   "*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."
@@ -228,7 +227,6 @@ http://strw.leidenuniv.nl/~dominik/Tools"
   :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."
@@ -242,10 +240,13 @@ If the region is smaller than this number of characters,
 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."
@@ -404,38 +405,22 @@ property of the major mode name.")
 ;*---------------------------------------------------------------------*/
 ;*    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
@@ -449,26 +434,31 @@ property of the major mode name.")
 ;*---------------------------------------------------------------------*/
 ;*    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
-(defun flyspell-mode (&optional arg)
+(define-minor-mode flyspell-mode
   "Minor mode performing on-the-fly spelling checking.
 This spawns a single Ispell process and checks each word.
 The default flyspell behavior is to highlight incorrect words.
@@ -496,28 +486,12 @@ in your .emacs file.
 
 \\[flyspell-region] checks all words inside a region.
 \\[flyspell-buffer] checks the whole buffer."
-  (interactive "P")
-  (let ((old-flyspell-mode flyspell-mode))
-    ;; Mark the mode as on or off.
-    (setq flyspell-mode (not (or (and (null arg) flyspell-mode)
-                                (<= (prefix-numeric-value arg) 0))))
-    ;; Do the real work.
-    (unless (eq flyspell-mode old-flyspell-mode)
-      (if flyspell-mode
-         (flyspell-mode-on)
-       (flyspell-mode-off))
-      ;; Force modeline redisplay.
-      (set-buffer-modified-p (buffer-modified-p)))))
-
-;*---------------------------------------------------------------------*/
-;*    Autoloading                                                      */
-;*---------------------------------------------------------------------*/
-;;;###autoload
-(add-minor-mode 'flyspell-mode
-               'flyspell-mode-line-string
-               flyspell-mode-map
-               nil
-               'flyspell-mode)
+  :lighter flyspell-mode-line-string
+  :keymap flyspell-mode-map
+  :group 'flyspell
+  (if flyspell-mode
+      (flyspell-mode-on)
+    (flyspell-mode-off)))
 
 ;*---------------------------------------------------------------------*/
 ;*    flyspell-buffers ...                                             */
@@ -561,7 +535,7 @@ in your .emacs file.
 ;*---------------------------------------------------------------------*/
 (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
@@ -586,29 +560,13 @@ in your .emacs file.
   (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))
@@ -984,7 +942,7 @@ Mostly we check word delimiters."
                            (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 ...                                */
@@ -999,7 +957,7 @@ Mostly we check word delimiters."
              (setq r p)
            (goto-char p))))
       r)))
-         
+
 ;*---------------------------------------------------------------------*/
 ;*    flyspell-word-search-forward ...                                 */
 ;*---------------------------------------------------------------------*/
@@ -1013,7 +971,7 @@ Mostly we check word delimiters."
              (setq r p)
            (goto-char (1+ p)))))
       r)))
-         
+
 ;*---------------------------------------------------------------------*/
 ;*    flyspell-word ...                                                */
 ;*---------------------------------------------------------------------*/
@@ -1043,7 +1001,7 @@ Mostly we check word delimiters."
                 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))))))
@@ -1132,7 +1090,7 @@ Mostly we check word delimiters."
                              (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)
@@ -1143,7 +1101,7 @@ Mostly we check word delimiters."
                                (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))))))))
 
@@ -1587,11 +1545,8 @@ for the overlay."
     (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))
@@ -1631,7 +1586,7 @@ for the overlay."
            ;; 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 ...                          */
@@ -1657,7 +1612,7 @@ for the overlay."
            ;; now we can use a new overlay
            (setq flyspell-overlay
                  (make-flyspell-overlay beg end
-                                        'flyspell-duplicate-face
+                                        'flyspell-duplicate
                                         'highlight)))))))
 
 ;*---------------------------------------------------------------------*/
@@ -1719,13 +1674,12 @@ misspelled words backwards."
       (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 ...                                        */
@@ -1857,7 +1811,7 @@ This command proposes various successive corrections for the current word."
 (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)))
@@ -1865,7 +1819,7 @@ Sets `flyspell-auto-correct-previous-pos' to 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")
@@ -1881,29 +1835,29 @@ But don't look beyond what's visible on the screen."
        (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
@@ -2152,9 +2106,9 @@ Ispell, after transposing two adjacent characters, correct the text,
 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))
@@ -2182,9 +2136,9 @@ Ispell, after removing a pair of doubled characters, correct the text,
 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))