From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus? Date: Sun, 15 Nov 2015 08:45:03 +0100 Message-ID: <876113wvv3.fsf@mbork.pl> References: <87fv09o9p5.fsf@mbork.pl> <83twopdmz4.fsf@gnu.org> <83d1vcexdp.fsf@gnu.org> <871tbsbw01.fsf@mbork.pl> <831tbsem1g.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1447657425 17275 80.91.229.3 (16 Nov 2015 07:03:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Nov 2015 07:03:45 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 16 08:03:40 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZyDpD-000677-Hk for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 08:03:39 +0100 Original-Received: from localhost ([::1]:46270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyDpD-00040x-4r for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 02:03:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zxs00-0002lU-8f for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 02:45:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zxrzy-0003v5-N7 for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 02:45:20 -0500 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:49992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zxrzu-0003ut-O4; Sun, 15 Nov 2015 02:45:14 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 7F2D06F2003; Sun, 15 Nov 2015 08:45:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YvI7vwsywRHv; Sun, 15 Nov 2015 08:45:10 +0100 (CET) Original-Received: from localhost (unknown [109.232.24.28]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 7C3146F2002; Sun, 15 Nov 2015 08:45:10 +0100 (CET) User-agent: mu4e 0.9.15; emacs 25.0.50.1 In-reply-to: <831tbsem1g.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108087 Archived-At: On 2015-11-14, at 14:40, Eli Zaretskii wrote: >> From: Marcin Borkowski >> Cc: help-gnu-emacs@gnu.org >> Date: Sat, 14 Nov 2015 13:34:06 +0100 >> >> > Then I don't understand why the solution of focus-in/out-hook was >> > rejected as "hackish". These hooks are there precisely for situations >> > like these, AFAIK. IMO, there's nothing hackish about that. >> >> AFAIU, these hooks are best suited to situations like "run LaTeX on >> switching to a pdf viewer". That does not require global variables; my >> use case does. > > Sorry, I still don't understand: why cannot the hook modify values of > global variables, and thus serve your needs in this context? Well, you're probably right, I'm just overthinking it. >> Would it be possible to introduce a function like (emacs-has-focus-p) >> for that? Would it make sense? > > What would that function do except test the value of some global > variable, set by the focus-in and focus-out hooks? Well, it could do it without using those hooks, if it were in C. But you're probably right (again), there's no need to add that to the core. >> For starters, I only want to know whether it is Emacs which has focus or >> not. Then, I would like to know e.g. the mode of the current buffer; in >> that case, I'm not sure what I should do when the current buffer is the >> minibuffer or something. But this is less important for me now. > > There's only one current buffer in the entire Emacs session, and it > doesn't change when Emacs loses focus. Its value is returned by the > function current-buffer, as I'm sure you know. Of course. However, what I really mean is not exactly (current-buffer), but "the buffer I'm working in now". This means that if e.g. current-buffer is the minibuffer (as might be the case during search or M-x or whatever), I would prefer /the buffer I'll get back to when I finish doing whatever I'm doing in the minibuffer/, or /the buffer I was in when I switched to the minibuffer/ (these two need not coincide, of course, e.g. in case of C-x b - in such a case I'm fine with whichever one). This might be the other-buffer, I'm not sure - I'll have to study the docs a bit more. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University