From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Narendra Joshi Newsgroups: gmane.emacs.help Subject: Re: spell-check buffer in background, display buffer only if user interaction is needed Date: Sun, 25 Dec 2016 10:07:56 +0530 Message-ID: References: <20161224121651.xiodwfbe6akbvey7@doriath.local> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1482640713 20121 195.159.176.226 (25 Dec 2016 04:38:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 25 Dec 2016 04:38:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 25 05:38:26 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cL0Zh-0003kd-HL for geh-help-gnu-emacs@m.gmane.org; Sun, 25 Dec 2016 05:38:21 +0100 Original-Received: from localhost ([::1]:45695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cL0Zm-0005dR-8E for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Dec 2016 23:38:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cL0ZL-0005dB-Is for help-gnu-emacs@gnu.org; Sat, 24 Dec 2016 23:38:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cL0ZK-0004Rx-H9 for help-gnu-emacs@gnu.org; Sat, 24 Dec 2016 23:37:59 -0500 Original-Received: from mail-ua0-x22d.google.com ([2607:f8b0:400c:c08::22d]:35607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cL0ZK-0004Rq-BY for help-gnu-emacs@gnu.org; Sat, 24 Dec 2016 23:37:58 -0500 Original-Received: by mail-ua0-x22d.google.com with SMTP id 2so164910438uax.2 for ; Sat, 24 Dec 2016 20:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=Rlv+pibLk15AzdfYikXaM0ZCbrAB2UdQzA/JFkPElMg=; b=KMn2is6spQ0ulbbmFCIDsf/KyJddIWHbaDNZsrso8CuHJ/y8cKzz/xPe/nRV1vTyNi Ju9h/akD3OAOwtpyLzb/WMycopPsJy4lBHXvfruqj9BcswDMcO4PEwYGbSsiaU9zAuar b1uEsLW+arWttVFtnyT0iSVmbzyRcE0p8c0ZoHT9iEZ8mta6n7ElMGNW3nHbZA0Z31lL 5N6gfH6Acv6nU8NyvePD7iIUA4QkUVcuJaQVbCS3DzZ/ZYq4JqCG1NHk3GJiC+kPygQB KZx+N7EjcMUN3NaVUWiS88hCPAEnAf06/rPZ4sONCSVTAEuHvQhIumw8D+AKjQZP+X7g 9uGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Rlv+pibLk15AzdfYikXaM0ZCbrAB2UdQzA/JFkPElMg=; b=VJ6DWPcAOfpvxJ9ZlU//RM6QdU8wyoJ0S/BgE69+Z6/KqEusr25XsKEV9dMH4JyimR Bcu+/l5gPoPJ73ju3RxxgHkf59dTo7mhEkioIseBwlqwA7pCTmtSwJ5vQgQXMT7vT78N 1qjnY+aeEKLfAMi8Ef+3PfOZmmXl+JkDGyzo16tL5EGxdBu0iULK1FaAHGA80QkZCYTw +67JS9VakhB13KT5RqEURVGbMMDIzhc2bV1jj5hM6qMOulXsAmcY3nkNkve0PweeM5zD GrYt/p6Q6ItUflWGU52HGn9j3l7hktIkICOo/c38ykg8aI/v/YBtFDYwTnSUT660VaHC Jt9Q== X-Gm-Message-State: AIkVDXL9qN5Rpw1d/482sOHRMhRD6hSRoBiyddrnpl1L4UfCSccSmyP3ccaWh1XYvFMVpaZvhzu19eym46apRw== X-Received: by 10.176.16.87 with SMTP id g23mr13948848uab.54.1482640677346; Sat, 24 Dec 2016 20:37:57 -0800 (PST) Original-Received: by 10.31.201.196 with HTTP; Sat, 24 Dec 2016 20:37:56 -0800 (PST) Original-Received: by 10.31.201.196 with HTTP; Sat, 24 Dec 2016 20:37:56 -0800 (PST) In-Reply-To: <20161224121651.xiodwfbe6akbvey7@doriath.local> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400c:c08::22d X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111998 Archived-At: Why aren't you popping to buffer right inside the hook function? Narendra Joshi On 24 Dec 2016 17:47, "Ernest Adrogu=C3=A9" 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. > >