From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Newsgroups: gmane.emacs.bugs Subject: bug#7381: 24.0.50; Provide a hook run when a window is selected Date: Fri, 12 Nov 2010 19:40:58 +0100 Message-ID: <87y68ye66d.fsf@gmail.com> References: <87k4kjfldo.fsf@gmail.com> <4CDCF7E0.40406@gmx.at> <87bp5ug4lz.fsf@gmail.com> <4CDD3B9B.8090309@gmx.at> <877hgifv9d.fsf@gmail.com> <4CDD6BDC.4010305@gmx.at> <8739r6foz3.fsf@gmail.com> <4CDD82E2.9070906@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1289587453 29053 80.91.229.12 (12 Nov 2010 18:44:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 12 Nov 2010 18:44:13 +0000 (UTC) Cc: 7381@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Nov 12 19:44:09 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PGybY-0005QK-53 for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Nov 2010 19:44:08 +0100 Original-Received: from localhost ([127.0.0.1]:34847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGybX-0007TE-Jb for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Nov 2010 13:44:07 -0500 Original-Received: from [140.186.70.92] (port=56506 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGybQ-0007QK-T3 for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:44:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGybP-00013w-FZ for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:44:00 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGybP-00013p-CI for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:43:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PGyVe-0007yx-55; Fri, 12 Nov 2010 13:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Nov 2010 18:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7381 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 7381-submit@debbugs.gnu.org id=B7381.128958707130676 (code B ref 7381); Fri, 12 Nov 2010 18:38:02 +0000 Original-Received: (at 7381) by debbugs.gnu.org; 12 Nov 2010 18:37:51 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGyVT-0007yj-Ad for submit@debbugs.gnu.org; Fri, 12 Nov 2010 13:37:51 -0500 Original-Received: from mail-fx0-f44.google.com ([209.85.161.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGyVR-0007ye-T6 for 7381@debbugs.gnu.org; Fri, 12 Nov 2010 13:37:50 -0500 Original-Received: by fxm3 with SMTP id 3so2554866fxm.3 for <7381@debbugs.gnu.org>; Fri, 12 Nov 2010 10:42:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject :in-reply-to:references:user-agent:date:message-id:mime-version :content-type:content-transfer-encoding; bh=roFYBfBbyBriB4LWmU12IcuYxRZ5yYUWLKPSwkAvmuc=; b=w/UBRSC+eMgAodCc6F4BMsqANbyel260jFYW4qJhYL5h4VmJLC2d4PFPfYpZJoNMkt RVxPvFBftrf7wdy/0d8JdhhxbONbmbUdmOBw3ppxP77WRQCg/M6pXzxNS9ETcN3mVKrF uaGjtR/3t8opEbpS1hkq2BQiKEUiy6v6BoDBg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type:content-transfer-encoding; b=qPv64YjCyraSZeQZA5hAGsyod/UjAgFBes9u+BfqtPHrXd15Xkmd5pMVGzx0Y8sdPZ lgjGzVPn0iYzlwiaXg7bwI+MBNL4ZPHMaJGEb6DpRzhTdZJ7dbzLP2FNhl1x4f8QVzC+ wTLG138DnBnbhoetImfD+3VRai4zXT1a4FH4k= Original-Received: by 10.223.100.4 with SMTP id w4mr1884786fan.26.1289587357912; Fri, 12 Nov 2010 10:42:37 -0800 (PST) Original-Received: from localhost (176.119.broadband10.iol.cz [90.177.119.176]) by mx.google.com with ESMTPS id 16sm136275fal.24.2010.11.12.10.42.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Nov 2010 10:42:36 -0800 (PST) In-Reply-To: <4CDD82E2.9070906@gmx.at> (martin rudalics's message of "Fri, 12 Nov 2010 19:09:38 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 12 Nov 2010 13:38:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:41528 Archived-At: martin rudalics writes: >>> Basically, we could keep the old window configuration around from one >>> "change" to the next but it's not clear whether we want to save the >>> configuration before the last command or before the last configuration >>> change. In the latter case, your code would hardly know whether it runs >>> within one and the same command or within different commands. >>> >>> Note in this context that a single command like setting up a GDB frame >>> may entail a couple of configuration changes and you would have to keep >>> track of all of them. And the hook would trigger within each and every >>> instance of `with-selected-window' or `save-window-excursion' no matter >>> how silly these macros are occasionally used. >> >> ...and these caveats seem only to confirm such doubts (although some of >> them would apply to lesser extent to the hypothetical >> `select-window'-specific hook as well). > > I'm afraid they would apply to the same extent. Hm. Would they? A lot of window configuration changes don't involve changing the selected window. >> What's wrong with a separate `window-selected-hook' or perhaps >> `select-window-hook'? > > Nothing but the fact that it might not help you very much. Your use > case was formulated in terms of commands > >> ... repeating the command would toggle between two windows ... > > and not in terms of window selections. So I don't think that Lennart's > proposal of using a `post-command-hook' here is unreasonable ;-) No, my use case is really about the previous selected window (on a given frame), not specific commands. `select-window' is not even a command. Checking after each and every command if by any chance we changed the selected window does seem rather unreasonable to me. I'd much rather have a `select-window-hook' and keep track of the two last selected windows. >> [On a related note, it would be nice if there were some clean and simple >> way to define custom hooks attached to arbitrary functions; that would >> solve problems similar to this one, preventing discussions whether adding >> yet another hook is worth it or not. Something like: >> >> (define-function-hook 'select-window) >> =3D> select-window-hook >> >> (add-hook 'select-window-hook ...) >> >> Dream on...] > > Hooks can be dangerous. It's very easy to crash Emacs by putting some > innocuously looking function on `window-configuration-change-hook'. Well, I don't find that very persuasive. It's not like Emacs lacks other ways to shoot yourself in the foot, and you can already achieve about the same (minus the "clean and simple" part) using advice. > BTW, I could give `get-mru-window' an additional argument like > > (defun get-mru-window (&optional all-frames avoid-selected) > (let (best-window best-time time) > (dolist (window (window-list-1 nil nil all-frames)) > (setq time (window-use-time window)) > (unless (and avoid-selected > (eq (window (selected-window)))) > (when (or (not best-time) (> time best-time)) > (setq best-time time) > (setq best-window window)))) > best-window)) > > which would return nil if the selected window is the only one on > ALL-FRAMES. That'd be great, yeah (and including it in the trunk). =C5=A0t=C4=9Bp=C3=A1n