diff options
| author | Martin Rudalics | 2014-12-18 18:53:48 +0100 |
|---|---|---|
| committer | Martin Rudalics | 2014-12-18 18:53:48 +0100 |
| commit | 655a6f35dfae775de53daff99ce0b1c802f4b4b7 (patch) | |
| tree | 7d2e96b1a1f8d0f11e4009896f61e21514a706c8 | |
| parent | 47f730e3b6a36d6b3e22b91caac576ec2ac4bd7c (diff) | |
| download | emacs-655a6f35dfae775de53daff99ce0b1c802f4b4b7.tar.gz emacs-655a6f35dfae775de53daff99ce0b1c802f4b4b7.zip | |
Fix ispell window handling.
* textmodes/ispell.el (ispell-command-loop): Suppress horizontal
scroll bar on ispell's windows. Don't count window lines and
don't deal with dedicated windows.
(ispell-show-choices, ispell-help): Let `ispell-display-buffer'
do the window handling.
(ispell-adjusted-window-height, ispell-overlay-window): Remove.
(ispell-display-buffer): New function to reuse, create and fit
window to ispell's buffers. (Bug#3413)
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/textmodes/ispell.el | 177 |
2 files changed, 68 insertions, 117 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 46c87180411..6027cd12bc2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -38,6 +38,14 @@ | |||
| 38 | (display-buffer): Mention `preserve-size' alist member in | 38 | (display-buffer): Mention `preserve-size' alist member in |
| 39 | doc-string. | 39 | doc-string. |
| 40 | (fit-window-to-buffer): New argument PRESERVE-SIZE. | 40 | (fit-window-to-buffer): New argument PRESERVE-SIZE. |
| 41 | * textmodes/ispell.el (ispell-command-loop): Suppress horizontal | ||
| 42 | scroll bar on ispell's windows. Don't count window lines and | ||
| 43 | don't deal with dedicated windows. | ||
| 44 | (ispell-show-choices, ispell-help): Let `ispell-display-buffer' | ||
| 45 | do the window handling. | ||
| 46 | (ispell-adjusted-window-height, ispell-overlay-window): Remove. | ||
| 47 | (ispell-display-buffer): New function to reuse, create and fit | ||
| 48 | window to ispell's buffers. (Bug#3413) | ||
| 41 | 49 | ||
| 42 | 2014-12-18 Dmitry Gutov <dgutov@yandex.ru> | 50 | 2014-12-18 Dmitry Gutov <dgutov@yandex.ru> |
| 43 | 51 | ||
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el index 0fc6b4a9995..ea2eaba6b9e 100644 --- a/lisp/textmodes/ispell.el +++ b/lisp/textmodes/ispell.el | |||
| @@ -2209,16 +2209,12 @@ indicates whether the dictionary has been modified when option `a' | |||
| 2209 | or `i' is used. | 2209 | or `i' is used. |
| 2210 | Global `ispell-quit' set to start location to continue spell session." | 2210 | Global `ispell-quit' set to start location to continue spell session." |
| 2211 | (let ((count ?0) | 2211 | (let ((count ?0) |
| 2212 | (line ispell-choices-win-default-height) | ||
| 2213 | ;; ensure 4 context lines. | ||
| 2214 | (max-lines (- (ispell-adjusted-window-height) 4)) | ||
| 2215 | (choices miss) | 2212 | (choices miss) |
| 2216 | (window-min-height (min window-min-height | 2213 | (window-min-height (min window-min-height |
| 2217 | ispell-choices-win-default-height)) | 2214 | ispell-choices-win-default-height)) |
| 2218 | (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m )) | 2215 | (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m )) |
| 2219 | (dedicated (window-dedicated-p)) | ||
| 2220 | (skipped 0) | 2216 | (skipped 0) |
| 2221 | char num result textwin dedicated-win) | 2217 | char num result textwin) |
| 2222 | 2218 | ||
| 2223 | ;; setup the *Choices* buffer with valid data. | 2219 | ;; setup the *Choices* buffer with valid data. |
| 2224 | (with-current-buffer (get-buffer-create ispell-choices-buffer) | 2220 | (with-current-buffer (get-buffer-create ispell-choices-buffer) |
| @@ -2233,30 +2229,27 @@ Global `ispell-quit' set to start location to continue spell session." | |||
| 2233 | (boundp 'horizontal-scrollbar-visible-p) | 2229 | (boundp 'horizontal-scrollbar-visible-p) |
| 2234 | (set-specifier horizontal-scrollbar-visible-p nil | 2230 | (set-specifier horizontal-scrollbar-visible-p nil |
| 2235 | (cons (current-buffer) nil)))) | 2231 | (cons (current-buffer) nil)))) |
| 2232 | (ispell-with-no-warnings | ||
| 2233 | (and (boundp 'horizontal-scroll-bar) | ||
| 2234 | (setq horizontal-scroll-bar nil))) | ||
| 2236 | (erase-buffer) | 2235 | (erase-buffer) |
| 2237 | (if guess | 2236 | (if guess |
| 2238 | (progn | 2237 | (progn |
| 2239 | (insert "Affix rules generate and capitalize " | 2238 | (insert "Affix rules generate and capitalize " |
| 2240 | "this word as shown below:\n\t") | 2239 | "this word as shown below:\n\t") |
| 2241 | (while guess | 2240 | (while guess |
| 2242 | (if (> (+ 4 (current-column) (length (car guess))) | 2241 | (when (> (+ 4 (current-column) (length (car guess))) |
| 2243 | (window-width)) | 2242 | (window-width)) |
| 2244 | (progn | 2243 | (insert "\n\t")) |
| 2245 | (insert "\n\t") | ||
| 2246 | (setq line (1+ line)))) | ||
| 2247 | (insert (car guess) " ") | 2244 | (insert (car guess) " ") |
| 2248 | (setq guess (cdr guess))) | 2245 | (setq guess (cdr guess))) |
| 2249 | (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n") | 2246 | (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n"))) |
| 2250 | (setq line (+ line (if choices 3 2))))) | 2247 | (while choices |
| 2251 | (while (and choices | 2248 | (when (> (+ 7 (current-column) |
| 2252 | (< (if (> (+ 7 (current-column) (length (car choices)) | 2249 | (length (car choices)) |
| 2253 | (if (> count ?~) 3 0)) | 2250 | (if (> count ?~) 3 0)) |
| 2254 | (window-width)) | 2251 | (window-width)) |
| 2255 | (progn | 2252 | (insert "\n")) |
| 2256 | (insert "\n") | ||
| 2257 | (setq line (1+ line))) | ||
| 2258 | line) | ||
| 2259 | max-lines)) | ||
| 2260 | ;; not so good if there are over 20 or 30 options, but then, if | 2253 | ;; not so good if there are over 20 or 30 options, but then, if |
| 2261 | ;; there are that many you don't want to scan them all anyway... | 2254 | ;; there are that many you don't want to scan them all anyway... |
| 2262 | (while (memq count command-characters) ; skip command characters. | 2255 | (while (memq count command-characters) ; skip command characters. |
| @@ -2271,14 +2264,8 @@ Global `ispell-quit' set to start location to continue spell session." | |||
| 2271 | (if (not (pos-visible-in-window-p end)) | 2264 | (if (not (pos-visible-in-window-p end)) |
| 2272 | (sit-for 0)) | 2265 | (sit-for 0)) |
| 2273 | 2266 | ||
| 2274 | ;; allow temporary split of dedicated windows... | ||
| 2275 | (if dedicated | ||
| 2276 | (progn | ||
| 2277 | (setq dedicated-win (selected-window)) | ||
| 2278 | (set-window-dedicated-p dedicated-win nil))) | ||
| 2279 | |||
| 2280 | ;; Display choices for misspelled word. | 2267 | ;; Display choices for misspelled word. |
| 2281 | (ispell-show-choices line end) | 2268 | (ispell-show-choices) |
| 2282 | (select-window (setq textwin (next-window))) | 2269 | (select-window (setq textwin (next-window))) |
| 2283 | 2270 | ||
| 2284 | ;; highlight word, protecting current buffer status | 2271 | ;; highlight word, protecting current buffer status |
| @@ -2406,18 +2393,13 @@ Global `ispell-quit' set to start location to continue spell session." | |||
| 2406 | (or ispell-complete-word-dict | 2393 | (or ispell-complete-word-dict |
| 2407 | ispell-alternate-dictionary)) | 2394 | ispell-alternate-dictionary)) |
| 2408 | miss (ispell-lookup-words new-word) | 2395 | miss (ispell-lookup-words new-word) |
| 2409 | choices miss | 2396 | choices miss) |
| 2410 | line ispell-choices-win-default-height) | 2397 | (while choices |
| 2411 | (while (and choices ; adjust choices window. | 2398 | (when (> (+ 7 (current-column) |
| 2412 | (< (if (> (+ 7 (current-column) | 2399 | (length (car choices)) |
| 2413 | (length (car choices)) | 2400 | (if (> count ?~) 3 0)) |
| 2414 | (if (> count ?~) 3 0)) | 2401 | (window-width)) |
| 2415 | (window-width)) | 2402 | (insert "\n")) |
| 2416 | (progn | ||
| 2417 | (insert "\n") | ||
| 2418 | (setq line (1+ line))) | ||
| 2419 | line) | ||
| 2420 | max-lines)) | ||
| 2421 | (while (memq count command-characters) | 2403 | (while (memq count command-characters) |
| 2422 | (setq count (ispell-int-char (1+ count)) | 2404 | (setq count (ispell-int-char (1+ count)) |
| 2423 | skipped (1+ skipped))) | 2405 | skipped (1+ skipped))) |
| @@ -2426,7 +2408,7 @@ Global `ispell-quit' set to start location to continue spell session." | |||
| 2426 | count (ispell-int-char (1+ count)))) | 2408 | count (ispell-int-char (1+ count)))) |
| 2427 | (setq count (ispell-int-char | 2409 | (setq count (ispell-int-char |
| 2428 | (- count ?0 skipped)))) | 2410 | (- count ?0 skipped)))) |
| 2429 | (ispell-show-choices line end) | 2411 | (ispell-show-choices) |
| 2430 | (select-window (next-window))))) | 2412 | (select-window (next-window))))) |
| 2431 | (and (eq 'block ispell-highlight-p) | 2413 | (and (eq 'block ispell-highlight-p) |
| 2432 | (ispell-highlight-spelling-error start end nil | 2414 | (ispell-highlight-spelling-error start end nil |
| @@ -2487,44 +2469,19 @@ Global `ispell-quit' set to start location to continue spell session." | |||
| 2487 | (and ispell-highlight-p ; unhighlight | 2469 | (and ispell-highlight-p ; unhighlight |
| 2488 | (save-window-excursion | 2470 | (save-window-excursion |
| 2489 | (select-window textwin) | 2471 | (select-window textwin) |
| 2490 | (ispell-highlight-spelling-error start end))) | 2472 | (ispell-highlight-spelling-error start end)))))) |
| 2491 | (if dedicated | ||
| 2492 | (set-window-dedicated-p dedicated-win t))))) | ||
| 2493 | 2473 | ||
| 2494 | 2474 | ||
| 2495 | 2475 | ||
| 2496 | (defun ispell-show-choices (line end) | 2476 | (defun ispell-show-choices () |
| 2497 | "Show the choices in another buffer or frame." | 2477 | "Show the choices in another buffer or frame." |
| 2498 | (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer)) | 2478 | (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer)) |
| 2499 | (progn | 2479 | (progn |
| 2500 | (framepop-display-buffer (get-buffer ispell-choices-buffer)) | 2480 | (framepop-display-buffer (get-buffer ispell-choices-buffer)) |
| 2501 | ;; (get-buffer-window ispell-choices-buffer t) | 2481 | ;; (get-buffer-window ispell-choices-buffer t) |
| 2502 | (select-window (previous-window))) ; *Choices* window | 2482 | (select-window (previous-window))) ; *Choices* window |
| 2503 | ;; standard selection by splitting a small buffer out of this window. | 2483 | ;; Display choices above selected window. |
| 2504 | (let ((choices-window (get-buffer-window ispell-choices-buffer))) | 2484 | (ispell-display-buffer (get-buffer-create ispell-choices-buffer)))) |
| 2505 | (if choices-window | ||
| 2506 | (if (= line (ispell-adjusted-window-height choices-window)) | ||
| 2507 | (select-window choices-window) | ||
| 2508 | ;; *Choices* window changed size. Adjust the choices window | ||
| 2509 | ;; without scrolling the spelled window when possible | ||
| 2510 | (let ((window-line | ||
| 2511 | (- line (ispell-adjusted-window-height choices-window))) | ||
| 2512 | (visible (progn (vertical-motion -1) (point)))) | ||
| 2513 | (if (< line ispell-choices-win-default-height) | ||
| 2514 | (setq window-line (+ window-line | ||
| 2515 | (- ispell-choices-win-default-height | ||
| 2516 | line)))) | ||
| 2517 | (move-to-window-line 0) | ||
| 2518 | (vertical-motion window-line) | ||
| 2519 | (set-window-start (selected-window) | ||
| 2520 | (if (> (point) visible) visible (point))) | ||
| 2521 | (goto-char end) | ||
| 2522 | (select-window choices-window) | ||
| 2523 | (enlarge-window window-line))) | ||
| 2524 | ;; Overlay *Choices* window when it isn't showing | ||
| 2525 | (ispell-overlay-window (max line ispell-choices-win-default-height))) | ||
| 2526 | (switch-to-buffer ispell-choices-buffer) | ||
| 2527 | (goto-char (point-min))))) | ||
| 2528 | 2485 | ||
| 2529 | 2486 | ||
| 2530 | ;;;###autoload | 2487 | ;;;###autoload |
| @@ -2594,10 +2551,10 @@ SPC: Accept word this time. | |||
| 2594 | "Type 'x C-h f ispell-help' for more help"))) | 2551 | "Type 'x C-h f ispell-help' for more help"))) |
| 2595 | (save-window-excursion | 2552 | (save-window-excursion |
| 2596 | (if ispell-help-in-bufferp | 2553 | (if ispell-help-in-bufferp |
| 2597 | (progn | 2554 | (let ((buffer (get-buffer-create "*Ispell Help*"))) |
| 2598 | (ispell-overlay-window 4) | 2555 | (with-current-buffer buffer |
| 2599 | (switch-to-buffer (get-buffer-create "*Ispell Help*")) | 2556 | (insert (concat help-1 "\n" help-2 "\n" help-3))) |
| 2600 | (insert (concat help-1 "\n" help-2 "\n" help-3)) | 2557 | (ispell-display-buffer buffer) |
| 2601 | (sit-for 5) | 2558 | (sit-for 5) |
| 2602 | (kill-buffer "*Ispell Help*")) | 2559 | (kill-buffer "*Ispell Help*")) |
| 2603 | (unwind-protect | 2560 | (unwind-protect |
| @@ -2816,49 +2773,35 @@ The variable `ispell-highlight-face' selects the face to use for highlighting." | |||
| 2816 | (ispell-highlight-spelling-error-overlay start end highlight)) | 2773 | (ispell-highlight-spelling-error-overlay start end highlight)) |
| 2817 | (t (ispell-highlight-spelling-error-generic start end highlight refresh)))) | 2774 | (t (ispell-highlight-spelling-error-generic start end highlight refresh)))) |
| 2818 | 2775 | ||
| 2819 | (defun ispell-adjusted-window-height (&optional window) | 2776 | (defun ispell-display-buffer (buffer) |
| 2820 | "Like `window-height', adjusted to correct for the effect of tall mode-lines. | 2777 | "Show BUFFER in new window above selected one. |
| 2821 | The value returned is actually the nominal number of text-lines in the | 2778 | Also position fit window to BUFFER and select it." |
| 2822 | window plus 1. On a terminal, this is the same value returned by | 2779 | (let* ((unsplittable |
| 2823 | `window-height', but if the window has a mode-line is taller than a normal | 2780 | (cdr (assq 'unsplittable (frame-parameters (selected-frame))))) |
| 2824 | text line, the returned value may be smaller than that from | 2781 | (window |
| 2825 | `window-height'." | 2782 | (or (get-buffer-window buffer) |
| 2826 | (cond ((fboundp 'window-text-height) | 2783 | (and unsplittable |
| 2827 | (1+ (window-text-height window))) | 2784 | ;; If frame is unsplittable, temporarily disable that... |
| 2828 | ((or (and (fboundp 'display-graphic-p) (display-graphic-p)) | 2785 | (let ((frame (selected-frame))) |
| 2829 | (and (featurep 'xemacs) window-system)) | 2786 | (modify-frame-parameters frame '((unsplittable . nil))) |
| 2830 | (1- (window-height window))) | 2787 | (prog1 |
| 2831 | (t | 2788 | (condition-case nil |
| 2832 | (window-height window)))) | 2789 | (split-window |
| 2833 | 2790 | nil (- ispell-choices-win-default-height) 'above) | |
| 2834 | (defun ispell-overlay-window (height) | 2791 | (error nil)) |
| 2835 | "Create a window covering the top HEIGHT lines of the current window. | 2792 | (modify-frame-parameters frame '((unsplittable . t)))))) |
| 2836 | Ensure that the line above point is still visible but otherwise avoid | 2793 | (and (not unsplittable) |
| 2837 | scrolling the current window. Leave the new window selected." | 2794 | (condition-case nil |
| 2838 | (save-excursion | 2795 | (split-window |
| 2839 | (let ((oldot (save-excursion (vertical-motion -1) (point))) | 2796 | nil (- ispell-choices-win-default-height) 'above) |
| 2840 | (top (save-excursion (move-to-window-line height) (point)))) | 2797 | (error nil))) |
| 2841 | ;; If line above old point (line starting at oldot) would be | 2798 | (display-buffer buffer)))) |
| 2842 | ;; hidden by new window, scroll it to just below new win | 2799 | (if (not window) |
| 2843 | ;; otherwise set top line of other win so it doesn't scroll. | 2800 | (error "Couldn't make window for *Choices*") |
| 2844 | (if (< oldot top) (setq top oldot)) | 2801 | (select-window window) |
| 2845 | ;; if frame is unsplittable, temporarily disable that... | 2802 | (set-window-buffer window buffer) |
| 2846 | (if (cdr (assq 'unsplittable (frame-parameters (selected-frame)))) | 2803 | (set-window-point window (point-min)) |
| 2847 | (let ((frame (selected-frame))) | 2804 | (fit-window-to-buffer window nil nil nil nil t)))) |
| 2848 | (modify-frame-parameters frame '((unsplittable . nil))) | ||
| 2849 | (split-window nil height) | ||
| 2850 | (modify-frame-parameters frame '((unsplittable . t)))) | ||
| 2851 | (split-window nil height)) | ||
| 2852 | (let ((deficit (- height (ispell-adjusted-window-height)))) | ||
| 2853 | (when (> deficit 0) | ||
| 2854 | ;; Number of lines the window is still too short. We ensure that | ||
| 2855 | ;; there are at least (1- HEIGHT) lines visible in the window. | ||
| 2856 | (enlarge-window deficit) | ||
| 2857 | (goto-char top) | ||
| 2858 | (vertical-motion deficit) | ||
| 2859 | (setq top (min (point) oldot)))) | ||
| 2860 | (set-window-start (next-window) top)))) | ||
| 2861 | |||
| 2862 | 2805 | ||
| 2863 | ;; Should we add a compound word match return value? | 2806 | ;; Should we add a compound word match return value? |
| 2864 | (defun ispell-parse-output (output &optional accept-list shift) | 2807 | (defun ispell-parse-output (output &optional accept-list shift) |