help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: spell-check buffer in background, display buffer only if user intera


From: Narendra Joshi
Subject: Re: spell-check buffer in background, display buffer only if user interaction is needed
Date: Sun, 25 Dec 2016 10:07:56 +0530

Why aren't you popping to buffer right inside the hook function?

Narendra Joshi
On 24 Dec 2016 17:47, "Ernest Adrogué" <address@hidden> wrote:

> Hello,
>
> Suppose that a function creates a temporary buffer for editing parts a
> file and switches to it.  For the purpose of testing, I'm using the
> following function instead of the real one
>
> (defun create-test-buffer-and-go (text)
>   (pop-to-buffer "*test-buffer*")
>   (erase-buffer)
>   (insert text)
>   (goto-char (point-min)))
>
> I'm trying to write a function that will spell-check the temporary
> buffer in the background and will only display the buffer if user
> interaction is required, that is, if the buffer contains misspelled
> words and the user has to choose among a list of corrections.
>
> One possibility is to use save-window-excursion and add a hook to
> ispell-update-post-hook which is run by ispell before creating the
> *Choices* buffer.
>
> (defun ispell-test-buffer ()
>   (set-buffer "*test-buffer*")
>   (add-hook 'ispell-update-post-hook
>             (lambda () (pop-to-buffer "*test-buffer*"))
>             t t)
>   (ispell-buffer))
>
> So, using an English dictionary
>
> (save-window-excursion (create-test-buffer-and-go "hello"))
> (ispell-test-buffer)
>
> shouldn't display the buffer at all, but passing the string "helloz"
> should, which it does.  The problem is the window is not left open, not
> sure why.  In order to fix this the only thing that occurs to me is have
> the hook function set a flag, and afterwards display the buffer if the
> flag is set
>
> (defun ispell-test-buffer ()
>   (let (required-interaction)
>     (set-buffer "*test-buffer*")
>     (add-hook 'ispell-update-post-hook
>               (lambda ()
>                 (pop-to-buffer "*test-buffer*")
>                 (setq required-interaction t))
>               t t)
>     (ispell-buffer)
>     (when required-interaction
>       (pop-to-buffer "*test-buffer*"))))
>
> but I'm not sure that this approach is right, so I'd like to hear
> suggestions if somebody has any.
>
> Cheers.
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]