From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics 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:09:38 +0100 Message-ID: <4CDD82E2.9070906@gmx.at> 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> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1289585652 17614 80.91.229.12 (12 Nov 2010 18:14:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 12 Nov 2010 18:14:12 +0000 (UTC) Cc: 7381@debbugs.gnu.org To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Nov 12 19:14:08 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 1PGy8U-0002WU-Dq for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Nov 2010 19:14:06 +0100 Original-Received: from localhost ([127.0.0.1]:35885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGy8T-0004pY-LA for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Nov 2010 13:14:05 -0500 Original-Received: from [140.186.70.92] (port=60291 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGy8N-0004gl-Pz for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:14:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGy8M-00022c-Nx for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:13:59 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGy8M-00022P-Kv for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2010 13:13:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PGxzi-0007k0-Ep; Fri, 12 Nov 2010 13:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: martin rudalics 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:05: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.128958509629750 (code B ref 7381); Fri, 12 Nov 2010 18:05:02 +0000 Original-Received: (at 7381) by debbugs.gnu.org; 12 Nov 2010 18:04:56 +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 1PGxzb-0007jn-G9 for submit@debbugs.gnu.org; Fri, 12 Nov 2010 13:04:55 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23] helo=mail.gmx.net) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1PGxzY-0007jg-Lu for 7381@debbugs.gnu.org; Fri, 12 Nov 2010 13:04:54 -0500 Original-Received: (qmail invoked by alias); 12 Nov 2010 18:09:40 -0000 Original-Received: from 62-47-37-164.adsl.highway.telekom.at (EHLO [62.47.37.164]) [62.47.37.164] by mail.gmx.net (mp031) with SMTP; 12 Nov 2010 19:09:40 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18V7a4IEyMVleq2sdxwav/qtxP+VKqgA5i7yfDILn mrQ4xOg8EXyQz6 User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <8739r6foz3.fsf@gmail.com> X-Y-GMX-Trusted: 0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 12 Nov 2010 13:05: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:41527 Archived-At: > But I really don't think extending `w-c-c-hook' is the right > solution. I don't see why just selecting another window should be > considered a window configuration change... Agreed. >> 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. > 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 ;-) > [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) > => 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'. 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. martin