aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-04-23 20:39:10 +0000
committerStefan Monnier2008-04-23 20:39:10 +0000
commitcaea54f833d135985fbaddd0b74a0dff4684e263 (patch)
tree48e27668976d8bb2d6be94e42f2e521f7908d213
parent2f65ac9e19dc2fd01d949f752bdc85b95c656725 (diff)
downloademacs-caea54f833d135985fbaddd0b74a0dff4684e263.tar.gz
emacs-caea54f833d135985fbaddd0b74a0dff4684e263.zip
* ispell.el (ispell-set-spellchecker-params): New function to make sure
right params and dictionary alists are used after spellchecker changes. (ispell-aspell-dictionary-alist, ispell-last-program-name) (ispell-initialize-spellchecker-hook): New variables and hook. (ispell-find-aspell-dictionaries): Use ispell-aspell-dictionary-alist. (ispell-maybe-find-aspell-dictionaries): Remove. Calls replaced by (ispell-set-spellchecker-params) calls. (ispell-have-aspell-dictionaries): Remove. * flyspell.el: Replace ispell-maybe-find-aspell-dictionaries by ispell-set-spellchecker-params.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/textmodes/flyspell.el6
-rw-r--r--lisp/textmodes/ispell.el93
3 files changed, 90 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 11355da864c..7238fe9aad6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12008-04-23 Agustin Martin <agustin.martin@hispalinux.es>
2
3 * ispell.el (ispell-set-spellchecker-params): New function to make sure
4 right params and dictionary alists are used after spellchecker changes.
5 (ispell-aspell-dictionary-alist, ispell-last-program-name)
6 (ispell-initialize-spellchecker-hook): New variables and hook.
7 (ispell-find-aspell-dictionaries): Use ispell-aspell-dictionary-alist.
8 (ispell-maybe-find-aspell-dictionaries): Remove.
9 Calls replaced by (ispell-set-spellchecker-params) calls.
10 (ispell-have-aspell-dictionaries): Remove.
11 * flyspell.el: Replace ispell-maybe-find-aspell-dictionaries by
12 ispell-set-spellchecker-params.
13
12008-04-23 Stefan Monnier <monnier@iro.umontreal.ca> 142008-04-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 15
3 * complete.el (PC-do-completion): Be more robust in the presence of 16 * complete.el (PC-do-completion): Be more robust in the presence of
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 33e245c4bf6..ef7d91b3471 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -579,7 +579,7 @@ in your .emacs file.
579;;*---------------------------------------------------------------------*/ 579;;*---------------------------------------------------------------------*/
580(defun flyspell-mode-on () 580(defun flyspell-mode-on ()
581 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." 581 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
582 (ispell-maybe-find-aspell-dictionaries) 582 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
583 (setq ispell-highlight-face 'flyspell-incorrect) 583 (setq ispell-highlight-face 'flyspell-incorrect)
584 ;; local dictionaries setup 584 ;; local dictionaries setup
585 (or ispell-local-dictionary ispell-dictionary 585 (or ispell-local-dictionary ispell-dictionary
@@ -1017,6 +1017,7 @@ Mostly we check word delimiters."
1017(defun flyspell-word (&optional following) 1017(defun flyspell-word (&optional following)
1018 "Spell check a word." 1018 "Spell check a word."
1019 (interactive (list ispell-following-word)) 1019 (interactive (list ispell-following-word))
1020 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1020 (save-excursion 1021 (save-excursion
1021 ;; use the correct dictionary 1022 ;; use the correct dictionary
1022 (flyspell-accept-buffer-local-defs) 1023 (flyspell-accept-buffer-local-defs)
@@ -1532,7 +1533,7 @@ The buffer to mark them in is `flyspell-large-region-buffer'."
1532 ;; this is done, we can start checking... 1533 ;; this is done, we can start checking...
1533 (if flyspell-issue-message-flag (message "Checking region...")) 1534 (if flyspell-issue-message-flag (message "Checking region..."))
1534 (set-buffer curbuf) 1535 (set-buffer curbuf)
1535 (ispell-check-version) 1536 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1536 ;; Local dictionary becomes the global dictionary in use. 1537 ;; Local dictionary becomes the global dictionary in use.
1537 (setq ispell-current-dictionary 1538 (setq ispell-current-dictionary
1538 (or ispell-local-dictionary ispell-dictionary)) 1539 (or ispell-local-dictionary ispell-dictionary))
@@ -1591,6 +1592,7 @@ The buffer to mark them in is `flyspell-large-region-buffer'."
1591(defun flyspell-region (beg end) 1592(defun flyspell-region (beg end)
1592 "Flyspell text between BEG and END." 1593 "Flyspell text between BEG and END."
1593 (interactive "r") 1594 (interactive "r")
1595 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1594 (if (= beg end) 1596 (if (= beg end)
1595 () 1597 ()
1596 (save-excursion 1598 (save-excursion
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 5eb74e49c8f..bca165d0a4d 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -881,18 +881,9 @@ and added as a submenu of the \"Edit\" menu.")
881 881
882;; Make ispell.el work better with aspell. 882;; Make ispell.el work better with aspell.
883 883
884(defvar ispell-have-aspell-dictionaries nil 884(defvar ispell-aspell-dictionary-alist nil
885 "Non-nil if we have queried Aspell for dictionaries at least once.") 885 "An alist of parsed aspell dicts and associated parameters.
886 886Internal use.")
887(defun ispell-maybe-find-aspell-dictionaries ()
888 "Find Aspell's dictionaries, unless already done."
889 (when (and (not ispell-have-aspell-dictionaries)
890 (condition-case ()
891 (progn (ispell-check-version) t)
892 (error nil))
893 ispell-really-aspell
894 ispell-aspell-supports-utf8)
895 (ispell-find-aspell-dictionaries)))
896 887
897(defun ispell-find-aspell-dictionaries () 888(defun ispell-find-aspell-dictionaries ()
898 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'." 889 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
@@ -915,14 +906,13 @@ and added as a submenu of the \"Edit\" menu.")
915 (dolist (dict ispell-dictionary-alist) 906 (dolist (dict ispell-dictionary-alist)
916 (unless (assoc (car dict) found) 907 (unless (assoc (car dict) found)
917 (setq found (nconc found (list dict))))) 908 (setq found (nconc found (list dict)))))
918 (setq ispell-dictionary-alist found) 909 (setq ispell-aspell-dictionary-alist found)
919 ;; Add a default entry 910 ;; Add a default entry
920 (let* ((english-dict (assoc "en" ispell-dictionary-alist)) 911 (let* ((english-dict (assoc "en" ispell-dictionary-alist))
921 (default-dict 912 (default-dict
922 (cons nil (or (cdr english-dict) 913 (cons nil (or (cdr english-dict)
923 (cdr (car ispell-dictionary-alist-1)))))) 914 (cdr (car ispell-dictionary-alist-1))))))
924 (push default-dict ispell-dictionary-alist)) 915 (push default-dict ispell-aspell-dictionary-alist))))
925 (setq ispell-have-aspell-dictionaries t)))
926 916
927(defvar ispell-aspell-data-dir nil 917(defvar ispell-aspell-data-dir nil
928 "Data directory of Aspell.") 918 "Data directory of Aspell.")
@@ -1004,11 +994,74 @@ Return the new dictionary alist."
1004 (push (cons aliasname (cdr realdict)) alist)))))) 994 (push (cons aliasname (cdr realdict)) alist))))))
1005 alist)) 995 alist))
1006 996
997;; Set params according to the selected spellchecker
998
999(defvar ispell-last-program-name nil
1000 "Last value of ispell-program name. Internal use.")
1001
1002(defvar ispell-initialize-spellchecker-hook nil
1003 "Actions to be taken on spellchecker initialization.
1004This hook is run when an spellchecker is used for the first
1005time, before ``ispell-dictionary-alist'' is set. Is intended for
1006sysadmins to override entries in the ispell.el base dictionary-alist
1007by putting those overrides in a ``ispell-base-dicts-override-alist''
1008alist with same format as ``ispell-dictionary-alist''. This alist
1009will not override the auto-detected values if a recent aspell is
1010used along with emacs.")
1011
1012(defun ispell-set-spellchecker-params ()
1013 "Initialize some spellchecker parameters when changed or first used."
1014 (unless (eq ispell-last-program-name ispell-program-name)
1015 (setq ispell-last-program-name ispell-program-name)
1016 (ispell-kill-ispell t)
1017 (if (and (condition-case ()
1018 (progn
1019 (setq ispell-library-directory (ispell-check-version))
1020 t)
1021 (error nil))
1022 ispell-really-aspell
1023 ispell-aspell-supports-utf8
1024 ;; xemacs does not like [:alpha:] regexps
1025 (string-match "^[[:alpha:]]+$" "abcde"))
1026 (unless ispell-aspell-dictionary-alist
1027 (ispell-find-aspell-dictionaries)))
1028
1029 ;; Substitute ispell-dictionary-alist with the list of dictionaries
1030 ;; corresponding to the given spellchecker. If a recent aspell, use
1031 ;; the list of really installed dictionaries and add to it elements
1032 ;; of the original list that are not present there. Allow distro info.
1033 (let ((base-dicts-alist
1034 (append ispell-dictionary-alist-1 ispell-dictionary-alist-2
1035 ispell-dictionary-alist-3 ispell-dictionary-alist-4
1036 ispell-dictionary-alist-5 ispell-dictionary-alist-6))
1037 (found-dicts-alist
1038 (if (and ispell-really-aspell
1039 ispell-aspell-supports-utf8)
1040 ispell-aspell-dictionary-alist
1041 nil))
1042 ispell-base-dicts-override-alist ; Override only base-dicts-alist
1043 all-dicts-alist)
1044
1045 (run-hooks 'ispell-initialize-spellchecker-hook)
1046
1047 ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
1048 (dolist (dict (append found-dicts-alist
1049 ispell-base-dicts-override-alist
1050 base-dicts-alist))
1051 (unless (assoc (car dict) all-dicts-alist)
1052 (add-to-list 'all-dicts-alist dict)))
1053 (setq ispell-dictionary-alist all-dicts-alist))))
1054
1055
1007(defun ispell-valid-dictionary-list () 1056(defun ispell-valid-dictionary-list ()
1008 "Returns a list of valid dictionaries. 1057 "Returns a list of valid dictionaries.
1009The variable `ispell-library-directory' defines the library location." 1058The variable `ispell-library-directory' defines the library location."
1010 ;; If Ispell is really Aspell, query it for the dictionary list. 1059 ;; Initialize variables and dictionaries alists for desired spellchecker.
1011 (ispell-maybe-find-aspell-dictionaries) 1060 ;; Make sure ispell.el is loaded to avoid some autoload loops in xemacs
1061 ;; (and may be others)
1062 (if (featurep 'ispell)
1063 (ispell-set-spellchecker-params))
1064
1012 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist)) 1065 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist))
1013 (dict-list (cons "default" nil)) 1066 (dict-list (cons "default" nil))
1014 name load-dict) 1067 name load-dict)
@@ -1566,7 +1619,7 @@ quit spell session exited."
1566 (ispell-region (region-beginning) (region-end))) 1619 (ispell-region (region-beginning) (region-end)))
1567 (continue (ispell-continue)) 1620 (continue (ispell-continue))
1568 (t 1621 (t
1569 (ispell-maybe-find-aspell-dictionaries) 1622 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1570 (ispell-accept-buffer-local-defs) ; use the correct dictionary 1623 (ispell-accept-buffer-local-defs) ; use the correct dictionary
1571 (let ((cursor-location (point)) ; retain cursor location 1624 (let ((cursor-location (point)) ; retain cursor location
1572 (word (ispell-get-word following)) 1625 (word (ispell-get-word following))
@@ -2602,7 +2655,7 @@ By just answering RET you can find out what the current dictionary is."
2602 (mapcar 'list (ispell-valid-dictionary-list))) 2655 (mapcar 'list (ispell-valid-dictionary-list)))
2603 nil t) 2656 nil t)
2604 current-prefix-arg)) 2657 current-prefix-arg))
2605 (ispell-maybe-find-aspell-dictionaries) 2658 (ispell-set-spellchecker-params) ; Initilize variables and dicts alists
2606 (unless arg (ispell-buffer-local-dict 'no-reload)) 2659 (unless arg (ispell-buffer-local-dict 'no-reload))
2607 (if (equal dict "default") (setq dict nil)) 2660 (if (equal dict "default") (setq dict nil))
2608 ;; This relies on completing-read's bug of returning "" for no match 2661 ;; This relies on completing-read's bug of returning "" for no match
@@ -2653,7 +2706,7 @@ a new one will be started when needed."
2653Return nil if spell session is quit, 2706Return nil if spell session is quit,
2654 otherwise returns shift offset amount for last line processed." 2707 otherwise returns shift offset amount for last line processed."
2655 (interactive "r") ; Don't flag errors on read-only bufs. 2708 (interactive "r") ; Don't flag errors on read-only bufs.
2656 (ispell-maybe-find-aspell-dictionaries) 2709 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2657 (if (not recheckp) 2710 (if (not recheckp)
2658 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc. 2711 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
2659 (let ((skip-region-start (make-marker)) 2712 (let ((skip-region-start (make-marker))