diff options
| author | Agustín Martín | 2012-11-06 17:22:09 +0100 |
|---|---|---|
| committer | Agustín Martín | 2012-11-06 17:22:09 +0100 |
| commit | b159a1fd9ba32e72058beff12f185f7c2df55d70 (patch) | |
| tree | 30407576165e047c09f50f8d891b4ef5f2b5878a | |
| parent | f0704a9a28fcc441a8950c76b048001d11cdc1dd (diff) | |
| download | emacs-b159a1fd9ba32e72058beff12f185f7c2df55d70.tar.gz emacs-b159a1fd9ba32e72058beff12f185f7c2df55d70.zip | |
textmodes/ispell.el: Experimental support for support debugging.
* (ispell-create-debug-buffer): Create a `ispell-debug-buffer' debug
buffer for ispell.
* (ispell-print-if-debug): New function to print stuff to
`ispell-debug-buffer' if debugging is enabled.
* (ispell-region, ispell-process-line): Use `ispell-print-if-debug' to
show some debugging info.
* (ispell-buffer-with-debug): New function that creates a debugging
buffer and calls `ispell-buffer' with debugging enabled. This is also
en example of a possible way to use this system.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/textmodes/ispell.el | 98 |
2 files changed, 86 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1f1868745de..7470a0677b2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -3,6 +3,16 @@ | |||
| 3 | * textmodes/ispell.el (ispell-region): Standard re-indent for better | 3 | * textmodes/ispell.el (ispell-region): Standard re-indent for better |
| 4 | readability. | 4 | readability. |
| 5 | 5 | ||
| 6 | * textmodes/ispell.el: Experimental support for support debugging. | ||
| 7 | (ispell-create-debug-buffer): Create a `ispell-debug-buffer' debug | ||
| 8 | buffer for ispell. | ||
| 9 | (ispell-print-if-debug): New function to print stuff to | ||
| 10 | `ispell-debug-buffer' if debugging is enabled. | ||
| 11 | (ispell-region, ispell-process-line): Use `ispell-print-if-debug' to | ||
| 12 | show some debugging info. | ||
| 13 | (ispell-buffer-with-debug): New function that creates a debugging | ||
| 14 | buffer and calls `ispell-buffer' with debugging enabled. | ||
| 15 | |||
| 6 | 2012-11-06 Dmitry Antipov <dmantipov@yandex.ru> | 16 | 2012-11-06 Dmitry Antipov <dmantipov@yandex.ru> |
| 7 | 17 | ||
| 8 | * emacs-lisp/byte-opt.el (toplevel): Add compare-window-configurations, | 18 | * emacs-lisp/byte-opt.el (toplevel): Add compare-window-configurations, |
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el index 0af619ce773..424a83c1713 100644 --- a/lisp/textmodes/ispell.el +++ b/lisp/textmodes/ispell.el | |||
| @@ -907,6 +907,24 @@ Otherwise returns the library directory name, if that is defined." | |||
| 907 | (setq default-directory (expand-file-name "~/"))) | 907 | (setq default-directory (expand-file-name "~/"))) |
| 908 | (apply 'call-process-region args))) | 908 | (apply 'call-process-region args))) |
| 909 | 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)))) | ||
| 910 | 928 | ||
| 911 | 929 | ||
| 912 | ;; The preparation of the menu bar menu must be autoloaded | 930 | ;; The preparation of the menu bar menu must be autoloaded |
| @@ -2902,14 +2920,15 @@ amount for last line processed." | |||
| 2902 | (if (not recheckp) | 2920 | (if (not recheckp) |
| 2903 | (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc. | 2921 | (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc. |
| 2904 | (let ((skip-region-start (make-marker)) | 2922 | (let ((skip-region-start (make-marker)) |
| 2905 | (rstart (make-marker))) | 2923 | (rstart (make-marker)) |
| 2924 | (region-type (if (and (= reg-start (point-min)) (= reg-end (point-max))) | ||
| 2925 | (buffer-name) "region")) | ||
| 2926 | (program-basename (file-name-nondirectory ispell-program-name)) | ||
| 2927 | (dictionary (or ispell-current-dictionary "default"))) | ||
| 2906 | (unwind-protect | 2928 | (unwind-protect |
| 2907 | (save-excursion | 2929 | (save-excursion |
| 2908 | (message "Spell-checking %s using %s with %s dictionary..." | 2930 | (message "Spell-checking %s using %s with %s dictionary..." |
| 2909 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) | 2931 | region-type program-basename dictionary) |
| 2910 | (buffer-name) "region") | ||
| 2911 | (file-name-nondirectory ispell-program-name) | ||
| 2912 | (or ispell-current-dictionary "default")) | ||
| 2913 | ;; Returns cursor to original location. | 2932 | ;; Returns cursor to original location. |
| 2914 | (save-window-excursion | 2933 | (save-window-excursion |
| 2915 | (goto-char reg-start) | 2934 | (goto-char reg-start) |
| @@ -2917,18 +2936,30 @@ amount for last line processed." | |||
| 2917 | (case-fold-search case-fold-search) | 2936 | (case-fold-search case-fold-search) |
| 2918 | (query-fcc t) | 2937 | (query-fcc t) |
| 2919 | in-comment key) | 2938 | in-comment key) |
| 2920 | (let (message-log-max) | 2939 | (ispell-print-if-debug |
| 2921 | (message "searching for regions to skip")) | 2940 | (concat |
| 2941 | (format | ||
| 2942 | "ispell-region: (ispell-skip-region-list):\n%s\n" | ||
| 2943 | (ispell-skip-region-list)) | ||
| 2944 | (format | ||
| 2945 | "ispell-region: (ispell-begin-skip-region-regexp):\n%s\n" | ||
| 2946 | (ispell-begin-skip-region-regexp)) | ||
| 2947 | "ispell-region: Search for first region to skip after (ispell-begin-skip-region-regexp)\n")) | ||
| 2922 | (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t) | 2948 | (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t) |
| 2923 | (progn | 2949 | (progn |
| 2924 | (setq key (match-string-no-properties 0)) | 2950 | (setq key (match-string-no-properties 0)) |
| 2925 | (set-marker skip-region-start (- (point) (length key))) | 2951 | (set-marker skip-region-start (- (point) (length key))) |
| 2926 | (goto-char reg-start))) | 2952 | (goto-char reg-start) |
| 2927 | (let (message-log-max) | 2953 | (ispell-print-if-debug |
| 2928 | (message | 2954 | (format "ispell-region: First skip: %s at (pos,line,column): (%s,%s,%s).\n" |
| 2929 | "Continuing spelling check using %s with %s dictionary..." | 2955 | key |
| 2930 | (file-name-nondirectory ispell-program-name) | 2956 | (save-excursion (goto-char skip-region-start) (point)) |
| 2931 | (or ispell-current-dictionary "default"))) | 2957 | (line-number-at-pos skip-region-start) |
| 2958 | (save-excursion (goto-char skip-region-start) (current-column)))))) | ||
| 2959 | (ispell-print-if-debug | ||
| 2960 | (format | ||
| 2961 | "ispell-region: Continue spell-checking with %s and %s dictionary...\n" | ||
| 2962 | program-basename dictionary)) | ||
| 2932 | (set-marker rstart reg-start) | 2963 | (set-marker rstart reg-start) |
| 2933 | (set-marker ispell-region-end reg-end) | 2964 | (set-marker ispell-region-end reg-end) |
| 2934 | (while (and (not ispell-quit) | 2965 | (while (and (not ispell-quit) |
| @@ -2961,7 +2992,13 @@ amount for last line processed." | |||
| 2961 | (setq key (match-string-no-properties 0)) | 2992 | (setq key (match-string-no-properties 0)) |
| 2962 | (set-marker skip-region-start | 2993 | (set-marker skip-region-start |
| 2963 | (- (point) (length key))) | 2994 | (- (point) (length key))) |
| 2964 | (goto-char rstart)) | 2995 | (goto-char rstart) |
| 2996 | (ispell-print-if-debug | ||
| 2997 | (format "ispell-region: Next skip: %s at (pos,line,column): (%s,%s,%s).\n" | ||
| 2998 | key | ||
| 2999 | (save-excursion (goto-char skip-region-start) (point)) | ||
| 3000 | (line-number-at-pos skip-region-start) | ||
| 3001 | (save-excursion (goto-char skip-region-start) (current-column))))) | ||
| 2965 | (set-marker skip-region-start nil)))) | 3002 | (set-marker skip-region-start nil)))) |
| 2966 | (setq reg-end (max (point) | 3003 | (setq reg-end (max (point) |
| 2967 | (if (marker-position skip-region-start) | 3004 | (if (marker-position skip-region-start) |
| @@ -2971,6 +3008,10 @@ amount for last line processed." | |||
| 2971 | (ispell-end (min (point-at-eol) reg-end)) | 3008 | (ispell-end (min (point-at-eol) reg-end)) |
| 2972 | (string (ispell-get-line | 3009 | (string (ispell-get-line |
| 2973 | ispell-start ispell-end in-comment))) | 3010 | ispell-start ispell-end in-comment))) |
| 3011 | (ispell-print-if-debug | ||
| 3012 | (format | ||
| 3013 | "ispell-region: string pos (%s->%s), eol: %s, [in-comment]: [%s], [string]: [%s]\n" | ||
| 3014 | ispell-start ispell-end (point-at-eol) in-comment string)) | ||
| 2974 | (if in-comment ; account for comment chars added | 3015 | (if in-comment ; account for comment chars added |
| 2975 | (setq ispell-start (- ispell-start (length in-comment)) | 3016 | (setq ispell-start (- ispell-start (length in-comment)) |
| 2976 | in-comment nil)) | 3017 | in-comment nil)) |
| @@ -3006,10 +3047,7 @@ amount for last line processed." | |||
| 3006 | ;; Only save if successful exit. | 3047 | ;; Only save if successful exit. |
| 3007 | (ispell-pdict-save ispell-silently-savep) | 3048 | (ispell-pdict-save ispell-silently-savep) |
| 3008 | (message "Spell-checking %s using %s with %s dictionary...done" | 3049 | (message "Spell-checking %s using %s with %s dictionary...done" |
| 3009 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) | 3050 | region-type program-basename dictionary))))) |
| 3010 | (buffer-name) "region") | ||
| 3011 | (file-name-nondirectory ispell-program-name) | ||
| 3012 | (or ispell-current-dictionary "default")))))) | ||
| 3013 | 3051 | ||
| 3014 | 3052 | ||
| 3015 | (defun ispell-begin-skip-region-regexp () | 3053 | (defun ispell-begin-skip-region-regexp () |
| @@ -3256,10 +3294,19 @@ Returns the sum SHIFT due to changes in word replacements." | |||
| 3256 | ;; Alignment cannot be tracked and this error will occur when | 3294 | ;; Alignment cannot be tracked and this error will occur when |
| 3257 | ;; `query-replace' makes multiple corrections on the starting line. | 3295 | ;; `query-replace' makes multiple corrections on the starting line. |
| 3258 | (or (ispell-looking-at (car poss)) | 3296 | (or (ispell-looking-at (car poss)) |
| 3259 | ;; This occurs due to filter pipe problems | 3297 | ;; This error occurs due to filter pipe problems |
| 3260 | (error (concat "Ispell misalignment: word " | 3298 | (let* ((ispell-pipe-word (car poss)) |
| 3261 | "`%s' point %d; probably incompatible versions") | 3299 | (actual-point (marker-position word-start)) |
| 3262 | (car poss) (marker-position word-start))) | 3300 | (actual-line (line-number-at-pos actual-point)) |
| 3301 | (actual-column (save-excursion (goto-char actual-point) (current-column)))) | ||
| 3302 | (ispell-print-if-debug | ||
| 3303 | (concat | ||
| 3304 | "ispell-process-line: Ispell misalignment error:\n" | ||
| 3305 | (format " [Word from ispell pipe]: [%s], actual (point,line,column): (%s,%s,%s)\n" | ||
| 3306 | ispell-pipe-word actual-point actual-line actual-column))) | ||
| 3307 | (error (concat "Ispell misalignment: word " | ||
| 3308 | "`%s' point %d; probably incompatible versions") | ||
| 3309 | ispell-pipe-word actual-point))) | ||
| 3263 | ;; ispell-cmd-loop can go recursive & change buffer | 3310 | ;; ispell-cmd-loop can go recursive & change buffer |
| 3264 | (if ispell-keep-choices-win | 3311 | (if ispell-keep-choices-win |
| 3265 | (setq replace (ispell-command-loop | 3312 | (setq replace (ispell-command-loop |
| @@ -3393,6 +3440,13 @@ Returns the sum SHIFT due to changes in word replacements." | |||
| 3393 | (interactive) | 3440 | (interactive) |
| 3394 | (ispell-region (point-min) (point-max))) | 3441 | (ispell-region (point-min) (point-max))) |
| 3395 | 3442 | ||
| 3443 | ;;;###autoload | ||
| 3444 | (defun ispell-buffer-with-debug (&optional append) | ||
| 3445 | "`ispell-buffer' with some output sent to `ispell-debug-buffer' buffer. | ||
| 3446 | Use APPEND to append the info to previous buffer if exists." | ||
| 3447 | (interactive) | ||
| 3448 | (let ((ispell-debug-buffer (ispell-create-debug-buffer append))) | ||
| 3449 | (ispell-buffer))) | ||
| 3396 | 3450 | ||
| 3397 | ;;;###autoload | 3451 | ;;;###autoload |
| 3398 | (defun ispell-continue () | 3452 | (defun ispell-continue () |