unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* spell-check buffer in background, display buffer only if user interaction is needed
@ 2016-12-24 12:16 Ernest Adrogué
  2016-12-25  4:37 ` Narendra Joshi
  0 siblings, 1 reply; 2+ messages in thread
From: Ernest Adrogué @ 2016-12-24 12:16 UTC (permalink / raw)
  To: help-gnu-emacs

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.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: spell-check buffer in background, display buffer only if user interaction is needed
  2016-12-24 12:16 spell-check buffer in background, display buffer only if user interaction is needed Ernest Adrogué
@ 2016-12-25  4:37 ` Narendra Joshi
  0 siblings, 0 replies; 2+ messages in thread
From: Narendra Joshi @ 2016-12-25  4:37 UTC (permalink / raw)
  To: help-gnu-emacs

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

Narendra Joshi
On 24 Dec 2016 17:47, "Ernest Adrogué" <nfdisco@gmail.com> 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.
>
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-25  4:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-24 12:16 spell-check buffer in background, display buffer only if user interaction is needed Ernest Adrogué
2016-12-25  4:37 ` Narendra Joshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).