From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus? Date: Sun, 15 Nov 2015 21:45:24 +0200 Message-ID: <83k2pjcai3.fsf@gnu.org> References: <87fv09o9p5.fsf@mbork.pl> <83twopdmz4.fsf@gnu.org> <83d1vcexdp.fsf@gnu.org> <871tbsbw01.fsf@mbork.pl> <831tbsem1g.fsf@gnu.org> <876113wvv3.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1447704445 12492 80.91.229.3 (16 Nov 2015 20:07:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Nov 2015 20:07:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 16 21:07:18 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 1ZyQ3Z-000574-9g for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 21:07:17 +0100 Original-Received: from localhost ([::1]:48547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyQ3Y-0005ws-Nn for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 15:07:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zy3F2-0007ao-0e for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 14:45:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zy3Ex-0000xu-RB for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 14:45:35 -0500 Original-Received: from mtaout29.012.net.il ([80.179.55.185]:34445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zy3Ex-0000xq-FN for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 14:45:31 -0500 Original-Received: from conversion-daemon.mtaout29.012.net.il by mtaout29.012.net.il (HyperSendmail v2007.08) id <0NXV00M00G4LUA00@mtaout29.012.net.il> for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 21:44:49 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([84.94.185.246]) by mtaout29.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NXV00CBPG6PUH90@mtaout29.012.net.il> for help-gnu-emacs@gnu.org; Sun, 15 Nov 2015 21:44:49 +0200 (IST) In-reply-to: <876113wvv3.fsf@mbork.pl> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.179.55.185 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:108089 Archived-At: > From: Marcin Borkowski > Cc: help-gnu-emacs@gnu.org > Date: Sun, 15 Nov 2015 08:45:03 +0100 > > >> 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. In any case, I see no way for Emacs to provide this information, except by tracking these focus events. So doing it in an application will not lose anything, I think. > >> 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. At least wrt to being in the minibuffer, Emacs already does what you want, otherwise "M-: (current-buffer) RET" would not do what you expect.