diff options
| author | Eli Zaretskii | 2012-11-13 16:17:18 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-11-13 16:17:18 +0200 |
| commit | 3c4ca7155293ffc2d04708007131bcbc882d8913 (patch) | |
| tree | 61787be8cd43b6fb3d5159852fbd186eea404de7 /lisp/textmodes | |
| parent | 5ade42a5114255c43117065494b96d480c1e1588 (diff) | |
| parent | c708524567662c8911c5ab2695acc7bda0383705 (diff) | |
| download | emacs-3c4ca7155293ffc2d04708007131bcbc882d8913.tar.gz emacs-3c4ca7155293ffc2d04708007131bcbc882d8913.zip | |
Merge from trunk.
Diffstat (limited to 'lisp/textmodes')
| -rw-r--r-- | lisp/textmodes/ispell.el | 288 |
1 files changed, 177 insertions, 111 deletions
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el index d591dc5fa85..f667525397c 100644 --- a/lisp/textmodes/ispell.el +++ b/lisp/textmodes/ispell.el | |||
| @@ -357,6 +357,10 @@ Must be greater than 1." | |||
| 357 | "ispell") | 357 | "ispell") |
| 358 | "Program invoked by \\[ispell-word] and \\[ispell-region] commands." | 358 | "Program invoked by \\[ispell-word] and \\[ispell-region] commands." |
| 359 | :type 'string | 359 | :type 'string |
| 360 | :set (lambda (symbol value) | ||
| 361 | (set-default symbol value) | ||
| 362 | (if (featurep 'ispell) | ||
| 363 | (ispell-set-spellchecker-params))) | ||
| 360 | :group 'ispell) | 364 | :group 'ispell) |
| 361 | 365 | ||
| 362 | (defcustom ispell-alternate-dictionary | 366 | (defcustom ispell-alternate-dictionary |
| @@ -903,6 +907,24 @@ Otherwise returns the library directory name, if that is defined." | |||
| 903 | (setq default-directory (expand-file-name "~/"))) | 907 | (setq default-directory (expand-file-name "~/"))) |
| 904 | (apply 'call-process-region args))) | 908 | (apply 'call-process-region args))) |
| 905 | 909 | ||
| 910 | (defun ispell-create-debug-buffer (&optional append) | ||
| 911 | "Create an ispell debug buffer for debugging output. | ||
| 912 | Use APPEND to append the info to previous buffer if exists, | ||
| 913 | otherwise is reset. Returns name of ispell debug buffer. | ||
| 914 | See `ispell-buffer-with-debug' for an example of use." | ||
| 915 | (let ((ispell-debug-buffer (get-buffer-create "*ispell-debug*"))) | ||
| 916 | (with-current-buffer ispell-debug-buffer | ||
| 917 | (if append | ||
| 918 | (insert | ||
| 919 | (format "-----------------------------------------------\n")) | ||
| 920 | (erase-buffer))) | ||
| 921 | ispell-debug-buffer)) | ||
| 922 | |||
| 923 | (defsubst ispell-print-if-debug (string) | ||
| 924 | "Print STRING to `ispell-debug-buffer' buffer if enabled." | ||
| 925 | (if (boundp 'ispell-debug-buffer) | ||
| 926 | (with-current-buffer ispell-debug-buffer | ||
| 927 | (insert string)))) | ||
| 906 | 928 | ||
| 907 | 929 | ||
| 908 | ;; The preparation of the menu bar menu must be autoloaded | 930 | ;; The preparation of the menu bar menu must be autoloaded |
| @@ -2898,114 +2920,142 @@ amount for last line processed." | |||
| 2898 | (if (not recheckp) | 2920 | (if (not recheckp) |
| 2899 | (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc. | 2921 | (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc. |
| 2900 | (let ((skip-region-start (make-marker)) | 2922 | (let ((skip-region-start (make-marker)) |
| 2901 | (rstart (make-marker))) | 2923 | (rstart (make-marker)) |
| 2902 | (unwind-protect | 2924 | (region-type (if (and (= reg-start (point-min)) (= reg-end (point-max))) |
| 2903 | (save-excursion | 2925 | (buffer-name) "region")) |
| 2904 | (message "Spell-checking %s using %s with %s dictionary..." | 2926 | (program-basename (file-name-nondirectory ispell-program-name)) |
| 2905 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) | 2927 | (dictionary (or ispell-current-dictionary "default"))) |
| 2906 | (buffer-name) "region") | 2928 | (unwind-protect |
| 2907 | (file-name-nondirectory ispell-program-name) | 2929 | (save-excursion |
| 2908 | (or ispell-current-dictionary "default")) | 2930 | (message "Spell-checking %s using %s with %s dictionary..." |
| 2909 | ;; Returns cursor to original location. | 2931 | region-type program-basename dictionary) |
| 2910 | (save-window-excursion | 2932 | ;; Returns cursor to original location. |
| 2911 | (goto-char reg-start) | 2933 | (save-window-excursion |
| 2912 | (let ((transient-mark-mode) | 2934 | (goto-char reg-start) |
| 2913 | (case-fold-search case-fold-search) | 2935 | (let ((transient-mark-mode) |
| 2914 | (query-fcc t) | 2936 | (case-fold-search case-fold-search) |
| 2915 | in-comment key) | 2937 | (query-fcc t) |
| 2916 | (let (message-log-max) | 2938 | in-comment key) |
| 2917 | (message "searching for regions to skip")) | 2939 | (ispell-print-if-debug |
| 2918 | (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t) | 2940 | (concat |
| 2919 | (progn | 2941 | (format |
| 2920 | (setq key (match-string-no-properties 0)) | 2942 | "ispell-region: (ispell-skip-region-list):\n%s\n" |
| 2921 | (set-marker skip-region-start (- (point) (length key))) | 2943 | (ispell-skip-region-list)) |
| 2922 | (goto-char reg-start))) | 2944 | (format |
| 2923 | (let (message-log-max) | 2945 | "ispell-region: (ispell-begin-skip-region-regexp):\n%s\n" |
| 2924 | (message | 2946 | (ispell-begin-skip-region-regexp)) |
| 2925 | "Continuing spelling check using %s with %s dictionary..." | 2947 | "ispell-region: Search for first region to skip after (ispell-begin-skip-region-regexp)\n")) |
| 2926 | (file-name-nondirectory ispell-program-name) | 2948 | (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t) |
| 2927 | (or ispell-current-dictionary "default"))) | ||
| 2928 | (set-marker rstart reg-start) | ||
| 2929 | (set-marker ispell-region-end reg-end) | ||
| 2930 | (while (and (not ispell-quit) | ||
| 2931 | (< (point) ispell-region-end)) | ||
| 2932 | ;; spell-check region with skipping | ||
| 2933 | (if (and (marker-position skip-region-start) | ||
| 2934 | (<= skip-region-start (point))) | ||
| 2935 | (progn | 2949 | (progn |
| 2936 | ;; If region inside line comment, must keep comment start. | 2950 | (setq key (match-string-no-properties 0)) |
| 2937 | (setq in-comment (point) | 2951 | (set-marker skip-region-start (- (point) (length key))) |
| 2938 | in-comment | 2952 | (goto-char reg-start) |
| 2939 | (and comment-start | 2953 | (ispell-print-if-debug |
| 2940 | (or (null comment-end) (string= "" comment-end)) | 2954 | (format "ispell-region: First skip: %s at (pos,line,column): (%s,%s,%s).\n" |
| 2941 | (save-excursion | 2955 | key |
| 2942 | (beginning-of-line) | 2956 | (save-excursion (goto-char skip-region-start) (point)) |
| 2943 | (re-search-forward comment-start in-comment t)) | 2957 | (line-number-at-pos skip-region-start) |
| 2944 | comment-start)) | 2958 | (save-excursion (goto-char skip-region-start) (current-column)))))) |
| 2945 | ;; Can change skip-regexps (in ispell-message) | 2959 | (ispell-print-if-debug |
| 2946 | (ispell-skip-region key) ; moves pt past region. | 2960 | (format |
| 2947 | (set-marker rstart (point)) | 2961 | "ispell-region: Continue spell-checking with %s and %s dictionary...\n" |
| 2948 | ;; check for saving large attachments... | 2962 | program-basename dictionary)) |
| 2949 | (setq query-fcc (and query-fcc | 2963 | (set-marker rstart reg-start) |
| 2950 | (ispell-ignore-fcc skip-region-start | 2964 | (set-marker ispell-region-end reg-end) |
| 2951 | rstart))) | 2965 | (while (and (not ispell-quit) |
| 2952 | (if (and (< rstart ispell-region-end) | 2966 | (< (point) ispell-region-end)) |
| 2953 | (re-search-forward | 2967 | ;; spell-check region with skipping |
| 2954 | (ispell-begin-skip-region-regexp) | 2968 | (if (and (marker-position skip-region-start) |
| 2955 | ispell-region-end t)) | 2969 | (<= skip-region-start (point))) |
| 2956 | (progn | 2970 | (progn |
| 2957 | (setq key (match-string-no-properties 0)) | 2971 | ;; If region inside line comment, must keep comment start. |
| 2958 | (set-marker skip-region-start | 2972 | (setq in-comment (point) |
| 2959 | (- (point) (length key))) | 2973 | in-comment |
| 2960 | (goto-char rstart)) | 2974 | (and comment-start |
| 2961 | (set-marker skip-region-start nil)))) | 2975 | (or (null comment-end) (string= "" comment-end)) |
| 2962 | (setq reg-end (max (point) | 2976 | (save-excursion |
| 2963 | (if (marker-position skip-region-start) | 2977 | (beginning-of-line) |
| 2964 | (min skip-region-start ispell-region-end) | 2978 | (re-search-forward comment-start in-comment t)) |
| 2965 | (marker-position ispell-region-end)))) | 2979 | comment-start)) |
| 2966 | (let* ((ispell-start (point)) | 2980 | ;; Can change skip-regexps (in ispell-message) |
| 2967 | (ispell-end (min (point-at-eol) reg-end)) | 2981 | (ispell-skip-region key) ; moves pt past region. |
| 2968 | (string (ispell-get-line | 2982 | (set-marker rstart (point)) |
| 2969 | ispell-start ispell-end in-comment))) | 2983 | ;; check for saving large attachments... |
| 2970 | (if in-comment ; account for comment chars added | 2984 | (setq query-fcc (and query-fcc |
| 2971 | (setq ispell-start (- ispell-start (length in-comment)) | 2985 | (ispell-ignore-fcc skip-region-start |
| 2972 | in-comment nil)) | 2986 | rstart))) |
| 2973 | (setq ispell-end (point)) ; "end" tracks region retrieved. | 2987 | (if (and (< rstart ispell-region-end) |
| 2974 | (if string ; there is something to spell check! | 2988 | (re-search-forward |
| 2975 | ;; (special start end) | 2989 | (ispell-begin-skip-region-regexp) |
| 2976 | (setq shift (ispell-process-line string | 2990 | ispell-region-end t)) |
| 2977 | (and recheckp shift)))) | 2991 | (progn |
| 2978 | (goto-char ispell-end))))) | 2992 | (setq key (match-string-no-properties 0)) |
| 2979 | (if ispell-quit | 2993 | (set-marker skip-region-start |
| 2980 | nil | 2994 | (- (point) (length key))) |
| 2981 | (or shift 0))) | 2995 | (goto-char rstart) |
| 2982 | ;; protected | 2996 | (ispell-print-if-debug |
| 2983 | (if (and (not (and recheckp ispell-keep-choices-win)) | 2997 | (format "ispell-region: Next skip: %s at (pos,line,column): (%s,%s,%s).\n" |
| 2984 | (get-buffer ispell-choices-buffer)) | 2998 | key |
| 2985 | (kill-buffer ispell-choices-buffer)) | 2999 | (save-excursion (goto-char skip-region-start) (point)) |
| 2986 | (set-marker skip-region-start nil) | 3000 | (line-number-at-pos skip-region-start) |
| 2987 | (set-marker rstart nil) | 3001 | (save-excursion (goto-char skip-region-start) (current-column))))) |
| 2988 | (if ispell-quit | 3002 | (set-marker skip-region-start nil)))) |
| 2989 | (progn | 3003 | (setq reg-end (max (point) |
| 2990 | ;; preserve or clear the region for ispell-continue. | 3004 | (if (marker-position skip-region-start) |
| 2991 | (if (not (numberp ispell-quit)) | 3005 | (min skip-region-start ispell-region-end) |
| 2992 | (set-marker ispell-region-end nil) | 3006 | (marker-position ispell-region-end)))) |
| 2993 | ;; Ispell-continue enabled - ispell-region-end is set. | 3007 | (let* ((ispell-start (point)) |
| 2994 | (goto-char ispell-quit)) | 3008 | (ispell-end (min (point-at-eol) reg-end)) |
| 2995 | ;; Check for aborting | 3009 | ;; See if line must be prefixed by comment string to let ispell know this is |
| 2996 | (if (and ispell-checking-message (numberp ispell-quit)) | 3010 | ;; part of a comment string. This is only supported in some modes. |
| 2997 | (progn | 3011 | ;; In particular, this is not supported in autoconf mode where adding the |
| 2998 | (setq ispell-quit nil) | 3012 | ;; comment string messes everything up because ispell tries to spellcheck the |
| 2999 | (error "Message send aborted"))) | 3013 | ;; `dnl' string header causing misalignments in some cases (debbugs.gnu.org: #12768). |
| 3000 | (if (not recheckp) (setq ispell-quit nil))) | 3014 | (add-comment (and in-comment |
| 3001 | (if (not recheckp) (set-marker ispell-region-end nil)) | 3015 | (not (string= in-comment "dnl ")) |
| 3002 | ;; Only save if successful exit. | 3016 | in-comment)) |
| 3003 | (ispell-pdict-save ispell-silently-savep) | 3017 | (string (ispell-get-line |
| 3004 | (message "Spell-checking %s using %s with %s dictionary...done" | 3018 | ispell-start ispell-end add-comment))) |
| 3005 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) | 3019 | (ispell-print-if-debug |
| 3006 | (buffer-name) "region") | 3020 | (format |
| 3007 | (file-name-nondirectory ispell-program-name) | 3021 | "ispell-region: string pos (%s->%s), eol: %s, [in-comment]: [%s], [add-comment]: [%s], [string]: [%s]\n" |
| 3008 | (or ispell-current-dictionary "default")))))) | 3022 | ispell-start ispell-end (point-at-eol) in-comment add-comment string)) |
| 3023 | (if add-comment ; account for comment chars added | ||
| 3024 | (setq ispell-start (- ispell-start (length add-comment)) | ||
| 3025 | add-comment nil)) | ||
| 3026 | (setq ispell-end (point)) ; "end" tracks region retrieved. | ||
| 3027 | (if string ; there is something to spell check! | ||
| 3028 | ;; (special start end) | ||
| 3029 | (setq shift (ispell-process-line string | ||
| 3030 | (and recheckp shift)))) | ||
| 3031 | (goto-char ispell-end))))) | ||
| 3032 | (if ispell-quit | ||
| 3033 | nil | ||
| 3034 | (or shift 0))) | ||
| 3035 | ;; protected | ||
| 3036 | (if (and (not (and recheckp ispell-keep-choices-win)) | ||
| 3037 | (get-buffer ispell-choices-buffer)) | ||
| 3038 | (kill-buffer ispell-choices-buffer)) | ||
| 3039 | (set-marker skip-region-start nil) | ||
| 3040 | (set-marker rstart nil) | ||
| 3041 | (if ispell-quit | ||
| 3042 | (progn | ||
| 3043 | ;; preserve or clear the region for ispell-continue. | ||
| 3044 | (if (not (numberp ispell-quit)) | ||
| 3045 | (set-marker ispell-region-end nil) | ||
| 3046 | ;; Ispell-continue enabled - ispell-region-end is set. | ||
| 3047 | (goto-char ispell-quit)) | ||
| 3048 | ;; Check for aborting | ||
| 3049 | (if (and ispell-checking-message (numberp ispell-quit)) | ||
| 3050 | (progn | ||
| 3051 | (setq ispell-quit nil) | ||
| 3052 | (error "Message send aborted"))) | ||
| 3053 | (if (not recheckp) (setq ispell-quit nil))) | ||
| 3054 | (if (not recheckp) (set-marker ispell-region-end nil)) | ||
| 3055 | ;; Only save if successful exit. | ||
| 3056 | (ispell-pdict-save ispell-silently-savep) | ||
| 3057 | (message "Spell-checking %s using %s with %s dictionary...done" | ||
| 3058 | region-type program-basename dictionary))))) | ||
| 3009 | 3059 | ||
| 3010 | 3060 | ||
| 3011 | (defun ispell-begin-skip-region-regexp () | 3061 | (defun ispell-begin-skip-region-regexp () |
| @@ -3252,10 +3302,19 @@ Returns the sum SHIFT due to changes in word replacements." | |||
| 3252 | ;; Alignment cannot be tracked and this error will occur when | 3302 | ;; Alignment cannot be tracked and this error will occur when |
| 3253 | ;; `query-replace' makes multiple corrections on the starting line. | 3303 | ;; `query-replace' makes multiple corrections on the starting line. |
| 3254 | (or (ispell-looking-at (car poss)) | 3304 | (or (ispell-looking-at (car poss)) |
| 3255 | ;; This occurs due to filter pipe problems | 3305 | ;; This error occurs due to filter pipe problems |
| 3256 | (error (concat "Ispell misalignment: word " | 3306 | (let* ((ispell-pipe-word (car poss)) |
| 3257 | "`%s' point %d; probably incompatible versions") | 3307 | (actual-point (marker-position word-start)) |
| 3258 | (car poss) (marker-position word-start))) | 3308 | (actual-line (line-number-at-pos actual-point)) |
| 3309 | (actual-column (save-excursion (goto-char actual-point) (current-column)))) | ||
| 3310 | (ispell-print-if-debug | ||
| 3311 | (concat | ||
| 3312 | "ispell-process-line: Ispell misalignment error:\n" | ||
| 3313 | (format " [Word from ispell pipe]: [%s], actual (point,line,column): (%s,%s,%s)\n" | ||
| 3314 | ispell-pipe-word actual-point actual-line actual-column))) | ||
| 3315 | (error (concat "Ispell misalignment: word " | ||
| 3316 | "`%s' point %d; probably incompatible versions") | ||
| 3317 | ispell-pipe-word actual-point))) | ||
| 3259 | ;; ispell-cmd-loop can go recursive & change buffer | 3318 | ;; ispell-cmd-loop can go recursive & change buffer |
| 3260 | (if ispell-keep-choices-win | 3319 | (if ispell-keep-choices-win |
| 3261 | (setq replace (ispell-command-loop | 3320 | (setq replace (ispell-command-loop |
| @@ -3389,6 +3448,13 @@ Returns the sum SHIFT due to changes in word replacements." | |||
| 3389 | (interactive) | 3448 | (interactive) |
| 3390 | (ispell-region (point-min) (point-max))) | 3449 | (ispell-region (point-min) (point-max))) |
| 3391 | 3450 | ||
| 3451 | ;;;###autoload | ||
| 3452 | (defun ispell-buffer-with-debug (&optional append) | ||
| 3453 | "`ispell-buffer' with some output sent to `ispell-debug-buffer' buffer. | ||
| 3454 | Use APPEND to append the info to previous buffer if exists." | ||
| 3455 | (interactive) | ||
| 3456 | (let ((ispell-debug-buffer (ispell-create-debug-buffer append))) | ||
| 3457 | (ispell-buffer))) | ||
| 3392 | 3458 | ||
| 3393 | ;;;###autoload | 3459 | ;;;###autoload |
| 3394 | (defun ispell-continue () | 3460 | (defun ispell-continue () |