all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Narendra Joshi <narendraj9@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: spell-check buffer in background, display buffer only if user interaction is needed
Date: Sun, 25 Dec 2016 10:07:56 +0530	[thread overview]
Message-ID: <CAHCj4z6xd+AsFo6Si6xjc0w5J-wT-=7qNBZgnjxCQCWZi2+wJA@mail.gmail.com> (raw)
In-Reply-To: <20161224121651.xiodwfbe6akbvey7@doriath.local>

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.
>
>


      reply	other threads:[~2016-12-25  4:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHCj4z6xd+AsFo6Si6xjc0w5J-wT-=7qNBZgnjxCQCWZi2+wJA@mail.gmail.com' \
    --to=narendraj9@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.