Mercurial > emacs
comparison lisp/textmodes/ispell.el @ 66343:b105e56fe1df
(ispell-local-dictionary-overridden): Fix the
make-variable-buffer-local call that was supposed to be for this variable.
(ispell-aspell-supports-utf8): Doc fix.
(ispell-find-aspell-dictionaries): Preserve elements of
ispell-dictionary-alist for dictionaries that aspell doesn't report.
(ispell-aspell-find-dictionary): Return nil on error.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 23 Oct 2005 18:22:06 +0000 |
parents | ce59f35f70f3 |
children | 64988dc86619 |
comparison
equal
deleted
inserted
replaced
66342:a4fe475f3c8b | 66343:b105e56fe1df |
---|---|
443 :type 'boolean | 443 :type 'boolean |
444 :group 'ispell) | 444 :group 'ispell) |
445 | 445 |
446 (defvar ispell-local-dictionary-overridden nil | 446 (defvar ispell-local-dictionary-overridden nil |
447 "Non-nil means the user has explicitly set this buffer's Ispell dictionary.") | 447 "Non-nil means the user has explicitly set this buffer's Ispell dictionary.") |
448 (make-variable-buffer-local 'ispell-local-dictionary) | 448 (make-variable-buffer-local 'ispell-local-dictionary-overridden) |
449 | 449 |
450 (defcustom ispell-local-dictionary nil | 450 (defcustom ispell-local-dictionary nil |
451 "If non-nil, the dictionary to be used for Ispell commands in this buffer. | 451 "If non-nil, the dictionary to be used for Ispell commands in this buffer. |
452 The value must be a string dictionary name, | 452 The value must be a string dictionary name, |
453 or nil, which means use the global setting in `ispell-dictionary'. | 453 or nil, which means use the global setting in `ispell-dictionary'. |
719 | 719 |
720 (defvar ispell-really-aspell nil) ; Non-nil if aspell extensions should be used | 720 (defvar ispell-really-aspell nil) ; Non-nil if aspell extensions should be used |
721 | 721 |
722 (defvar ispell-aspell-supports-utf8 nil | 722 (defvar ispell-aspell-supports-utf8 nil |
723 "Non-nil means to try to automatically find aspell dictionaries. | 723 "Non-nil means to try to automatically find aspell dictionaries. |
724 This is set to t in ispell-check-version for aspell >= 0.60. | 724 This is set to t in `ispell-check-version' for aspell >= 0.60. |
725 | 725 |
726 Earlier aspell versions do not consistently support UTF-8. Handling | 726 Earlier aspell versions do not consistently support UTF-8. Handling |
727 this would require some extra guessing in `ispell-aspell-find-dictionary'.") | 727 this would require some extra guessing in `ispell-aspell-find-dictionary'.") |
728 | 728 |
729 | 729 |
892 | 892 |
893 (defun ispell-find-aspell-dictionaries () | 893 (defun ispell-find-aspell-dictionaries () |
894 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'." | 894 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'." |
895 (unless ispell-really-aspell | 895 (unless ispell-really-aspell |
896 (error "This function only works with aspell")) | 896 (error "This function only works with aspell")) |
897 (let ((dictionaries | 897 (let* ((dictionaries |
898 (split-string | 898 (split-string |
899 (with-temp-buffer | 899 (with-temp-buffer |
900 (call-process ispell-program-name nil t nil "dicts") | 900 (call-process ispell-program-name nil t nil "dicts") |
901 (buffer-string))))) | 901 (buffer-string)))) |
902 (setq ispell-dictionary-alist | 902 ;; Search for the named dictionaries. |
903 (mapcar #'ispell-aspell-find-dictionary dictionaries)) | 903 (found |
904 (delq nil | |
905 (mapcar #'ispell-aspell-find-dictionary dictionaries)))) | |
906 ;; Merge into FOUND any elements from the standard ispell-dictionary-alist | |
907 ;; which have no element in FOUND at all. | |
908 (dolist (dict ispell-dictionary-alist) | |
909 (unless (assoc (car dict) found) | |
910 (setq found (nconc found (list dict))))) | |
911 (setq ispell-dictionary-alist found) | |
912 | |
904 (ispell-aspell-add-aliases) | 913 (ispell-aspell-add-aliases) |
905 ;; Add a default entry | 914 ;; Add a default entry |
906 (let* ((english-dict (assoc "en" ispell-dictionary-alist)) | 915 (let* ((english-dict (assoc "en" ispell-dictionary-alist)) |
907 (default-dict (cons nil (cdr english-dict)))) | 916 (default-dict (cons nil (cdr english-dict)))) |
908 (push default-dict ispell-dictionary-alist)) | 917 (push default-dict ispell-dictionary-alist)) |
920 (with-temp-buffer | 929 (with-temp-buffer |
921 (call-process ispell-program-name nil t nil "config" key) | 930 (call-process ispell-program-name nil t nil "config" key) |
922 (car (split-string (buffer-string))))) | 931 (car (split-string (buffer-string))))) |
923 | 932 |
924 (defun ispell-aspell-find-dictionary (dict-name) | 933 (defun ispell-aspell-find-dictionary (dict-name) |
934 ;; This returns nil if the data file does not exist. | |
935 ;; Can someone please explain the return value format when the | |
936 ;; file does exist -- rms? | |
925 (let* ((lang ;; Strip out region, variant, etc. | 937 (let* ((lang ;; Strip out region, variant, etc. |
926 (and (string-match "^[[:alpha:]]+" dict-name) | 938 (and (string-match "^[[:alpha:]]+" dict-name) |
927 (match-string 0 dict-name))) | 939 (match-string 0 dict-name))) |
928 (data-file | 940 (data-file |
929 (concat (or ispell-aspell-data-dir | 941 (concat (or ispell-aspell-data-dir |
930 (setq ispell-aspell-data-dir | 942 (setq ispell-aspell-data-dir |
931 (ispell-get-aspell-config-value "data-dir"))) | 943 (ispell-get-aspell-config-value "data-dir"))) |
932 "/" lang ".dat")) | 944 "/" lang ".dat")) |
933 otherchars) | 945 otherchars) |
934 ;; This file really should exist; there is no sensible recovery. | 946 (condition-case () |
935 (with-temp-buffer | 947 (with-temp-buffer |
936 (insert-file-contents data-file) | 948 (insert-file-contents data-file) |
937 ;; There is zero or one line with special characters declarations. | 949 ;; There is zero or one line with special characters declarations. |
938 (when (search-forward-regexp "^special" nil t) | 950 (when (search-forward-regexp "^special" nil t) |
939 (let ((specials (split-string | 951 (let ((specials (split-string |
940 (buffer-substring (point) | 952 (buffer-substring (point) |
941 (progn (end-of-line) (point)))))) | 953 (progn (end-of-line) (point)))))) |
942 ;; The line looks like: special ' -** - -** . -** : -*- | 954 ;; The line looks like: special ' -** - -** . -** : -*- |
943 ;; -** means that this character | 955 ;; -** means that this character |
944 ;; - doesn't appear at word start | 956 ;; - doesn't appear at word start |
945 ;; * may appear in the middle of a word | 957 ;; * may appear in the middle of a word |
946 ;; * may appear at word end | 958 ;; * may appear at word end |
947 ;; `otherchars' is about the middle case. | 959 ;; `otherchars' is about the middle case. |
948 (while specials | 960 (while specials |
949 (when (eq (aref (cadr specials) 1) ?*) | 961 (when (eq (aref (cadr specials) 1) ?*) |
950 (push (car specials) otherchars)) | 962 (push (car specials) otherchars)) |
951 (setq specials (cddr specials)))))) | 963 (setq specials (cddr specials))))) |
952 (list dict-name | 964 (list dict-name |
953 "[[:alpha:]]" | 965 "[[:alpha:]]" |
954 "[^[:alpha:]]" | 966 "[^[:alpha:]]" |
955 (regexp-opt otherchars) | 967 (regexp-opt otherchars) |
956 t ; We can't tell, so set this to t | 968 t ; We can't tell, so set this to t |
957 (list "-d" dict-name "--encoding=utf-8") | 969 (list "-d" dict-name "--encoding=utf-8") |
958 nil ; aspell doesn't support this | 970 nil ; aspell doesn't support this |
959 ;; Here we specify the encoding to use while communicating with | 971 ;; Here we specify the encoding to use while communicating with |
960 ;; aspell. This doesn't apply to command line arguments, so | 972 ;; aspell. This doesn't apply to command line arguments, so |
961 ;; just don't pass words to spellcheck as arguments... | 973 ;; just don't pass words to spellcheck as arguments... |
962 'utf-8))) | 974 'utf-8)) |
975 (file-error | |
976 nil)))) | |
963 | 977 |
964 (defun ispell-aspell-add-aliases () | 978 (defun ispell-aspell-add-aliases () |
965 "Find aspell's dictionary aliases and add them to `ispell-dictionary-alist'." | 979 "Find aspell's dictionary aliases and add them to `ispell-dictionary-alist'." |
966 (let ((aliases (file-expand-wildcards | 980 (let ((aliases (file-expand-wildcards |
967 (concat (or ispell-aspell-dict-dir | 981 (concat (or ispell-aspell-dict-dir |