Mercurial > emacs
comparison lisp/textmodes/ispell.el @ 100616:d97232b983fb
* textmodes/ispell.el (ispell-check-minver): New function.
(ispell-check-version): Rewrite spellchecker and version checking.
Use (ispell-check-minver). Handle hunspell versions.
author | Agustin Martin <agustin.martin@hispalinux.es> |
---|---|
date | Sat, 20 Dec 2008 18:34:41 +0000 |
parents | e7cd485b79ff |
children | a9dc0e7c3f2b |
comparison
equal
deleted
inserted
replaced
100615:95d9ce85cf2b | 100616:d97232b983fb |
---|---|
194 ;; Improved skipping support for SGML. | 194 ;; Improved skipping support for SGML. |
195 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'. | 195 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'. |
196 ;; Improved message reference matching in `ispell-message'. | 196 ;; Improved message reference matching in `ispell-message'. |
197 ;; Fixed bug in returning to nroff mode from tex mode. | 197 ;; Fixed bug in returning to nroff mode from tex mode. |
198 | 198 |
199 ;;; Compatibility code for xemacs and (not too) older emacsen: | |
200 | |
201 (if (fboundp 'version<=) | |
202 (defalias 'ispell-check-minver 'version<=) | |
203 (defun ispell-check-minver (minver version) | |
204 "Check if string VERSION is at least string MINVER. | |
205 Both must be in [0-9]+.[0-9]+... format. This is a fallback | |
206 compatibility function in case version<= is not available." | |
207 (let ((pending t) | |
208 (return t) | |
209 start-ver start-mver) | |
210 ;; Loop until an absolute greater or smaller condition is reached | |
211 ;; or until no elements are left in any of version and minver. In | |
212 ;; this case version is exactly the minimal, so return OK. | |
213 (while pending | |
214 (let (ver mver) | |
215 (if (string-match "[0-9]+" version start-ver) | |
216 (setq start-ver (match-end 0) | |
217 ver (string-to-int (substring version (match-beginning 0) (match-end 0))))) | |
218 (if (string-match "[0-9]+" minver start-mver) | |
219 (setq start-mver (match-end 0) | |
220 mver (string-to-int (substring minver (match-beginning 0) (match-end 0))))) | |
221 | |
222 (if (or ver mver) | |
223 (progn | |
224 (or ver (setq ver 0)) | |
225 (or mver (setq mver 0)) | |
226 ;; If none of below conditions match, this element is the | |
227 ;; same. Go checking next element. | |
228 (if (> ver mver) | |
229 (setq pending nil) | |
230 (if (< ver mver) | |
231 (setq pending nil | |
232 return nil)))) | |
233 (setq pending nil)))) | |
234 return))) | |
199 | 235 |
200 ;;; Code: | 236 ;;; Code: |
201 | 237 |
202 (defvar mail-yank-prefix) | 238 (defvar mail-yank-prefix) |
203 | 239 |
712 ;; avoid bugs when syntax of `.' changes in various default modes | 748 ;; avoid bugs when syntax of `.' changes in various default modes |
713 (default-major-mode 'fundamental-mode) | 749 (default-major-mode 'fundamental-mode) |
714 (default-directory (or (and (boundp 'temporary-file-directory) | 750 (default-directory (or (and (boundp 'temporary-file-directory) |
715 temporary-file-directory) | 751 temporary-file-directory) |
716 default-directory)) | 752 default-directory)) |
717 result status) | 753 result status ispell-program-version) |
718 (save-excursion | 754 (save-excursion |
719 (let ((buf (get-buffer " *ispell-tmp*"))) | 755 (let ((buf (get-buffer " *ispell-tmp*"))) |
720 (if buf (kill-buffer buf))) | 756 (if buf (kill-buffer buf))) |
721 (set-buffer (get-buffer-create " *ispell-tmp*")) | 757 (set-buffer (get-buffer-create " *ispell-tmp*")) |
722 (erase-buffer) | 758 (erase-buffer) |
744 (setq result (buffer-substring (match-beginning 1) (match-end 1))))) | 780 (setq result (buffer-substring (match-beginning 1) (match-end 1))))) |
745 (goto-char (point-min)) | 781 (goto-char (point-min)) |
746 (if (not (memq status '(0 nil))) | 782 (if (not (memq status '(0 nil))) |
747 (error "%s exited with %s %s" ispell-program-name | 783 (error "%s exited with %s %s" ispell-program-name |
748 (if (stringp status) "signal" "code") status)) | 784 (if (stringp status) "signal" "code") status)) |
749 (setq case-fold-search t | 785 |
750 status (re-search-forward | 786 ;; Get relevant version strings. Only xx.yy.... format works well |
751 (concat "\\<\\(" | 787 (let (case-fold-search) |
752 (format "%d" (car ispell-required-version)) | 788 (setq ispell-program-version |
753 "\\)\\.\\([0-9]*\\)\\.\\([0-9]*\\)\\>") | 789 (and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t) |
754 nil t) | 790 (match-string 1))) |
755 case-fold-search case-fold-search-val) | 791 |
756 (if (or (not status) ; major version mismatch | 792 ;; Make sure these variables are (re-)initialized to the default value |
757 (< (car (read-from-string (match-string-no-properties 2))) | 793 (setq ispell-really-aspell nil |
758 (car (cdr ispell-required-version)))) ; minor version mismatch | 794 ispell-aspell-supports-utf8 nil |
759 (error "%s version 3 release %d.%d.%d or greater is required" | 795 ispell-really-hunspell nil) |
760 ispell-program-name (car ispell-required-version) | 796 |
761 (car (cdr ispell-required-version)) | 797 (goto-char (point-min)) |
762 (car (cdr (cdr ispell-required-version)))) | 798 (or (setq ispell-really-aspell |
763 | 799 (and (search-forward-regexp |
764 ;; check that it is the correct version. | 800 "(but really Aspell \\([0-9]+\\.[0-9\\.]+\\)?)" nil t) |
765 (if (and (= (car (read-from-string (match-string-no-properties 2))) | 801 (match-string 1))) |
766 (car (cdr ispell-required-version))) | 802 (setq ispell-really-hunspell |
767 (< (car (read-from-string (match-string-no-properties 3))) | 803 (and (search-forward-regexp |
768 (car (cdr (cdr ispell-required-version))))) | 804 "(but really Hunspell \\([0-9]+\\.[0-9\\.]+\\)?)" nil t) |
769 (setq ispell-offset 0)) | 805 (match-string 1))))) |
770 | 806 |
771 ;; Check to see if it's really aspell or hunspell. | 807 (let ((aspell-minver "0.50") |
772 (goto-char (point-min)) | 808 (aspell8-minver "0.60") |
773 (let (case-fold-search) | 809 (ispell0-minver "3.1.0") |
774 (or | 810 (ispell-minver "3.1.12") |
775 (setq ispell-really-aspell | 811 (hunspell8-minver "1.1.6")) |
776 (and (search-forward-regexp | 812 |
777 "(but really Aspell \\(.*?\\)\\(-[0-9]+\\)?)" nil t) | 813 (if (ispell-check-minver ispell0-minver ispell-program-version) |
778 (progn | 814 (or (ispell-check-minver ispell-minver ispell-program-version) |
779 (setq ispell-aspell-supports-utf8 | 815 (setq ispell-offset 0)) |
780 (not (version< (match-string 1) "0.60"))) | 816 (error "%s release %s or greater is required" |
781 t))) | 817 ispell-program-name |
782 (setq ispell-really-hunspell | 818 ispell-minver)) |
783 (search-forward-regexp | 819 |
784 "(but really Hunspell \\(.*?\\)\\(-[0-9]+\\)?)" nil t)) | 820 (cond |
785 ))) | 821 (ispell-really-aspell |
822 (if (ispell-check-minver aspell-minver ispell-really-aspell) | |
823 (if (ispell-check-minver aspell8-minver ispell-really-aspell) | |
824 (setq ispell-aspell-supports-utf8 t)) | |
825 (setq ispell-really-aspell nil))) | |
826 (ispell-really-hunspell | |
827 (or (ispell-check-minver hunspell8-minver ispell-really-hunspell) | |
828 (setq ispell-really-hunspell nil))))) | |
829 | |
786 (kill-buffer (current-buffer))) | 830 (kill-buffer (current-buffer))) |
787 result)) | 831 result)) |
788 | 832 |
789 (defun ispell-call-process (&rest args) | 833 (defun ispell-call-process (&rest args) |
790 "Like `call-process' but defend against bad `default-directory'." | 834 "Like `call-process' but defend against bad `default-directory'." |