unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Štěpán Němec" <stepnem@gmail.com>
To: martin rudalics <rudalics@gmx.at>
Cc: 7381@debbugs.gnu.org
Subject: bug#7381: 24.0.50; Provide a hook run when a window is selected
Date: Fri, 12 Nov 2010 12:31:52 +0100	[thread overview]
Message-ID: <87bp5ug4lz.fsf@gmail.com> (raw)
In-Reply-To: <4CDCF7E0.40406@gmx.at> (martin rudalics's message of "Fri, 12 Nov 2010 09:16:32 +0100")

martin rudalics <rudalics@gmx.at> writes:

>> Use case: I wanted to make myself a command to select the last selected
>> window (i.e., repeating the command would toggle between two windows).
>>
>> After some head-scratching, the best I could come up with is this:
>>
>> (defun .goto-mru-window ()
>>   (interactive)
>>   (select-window (frame-parameter nil '.last-selected-window)))
>>
>> (defadvice select-window (before .save-selected-window activate)
>>   (set-frame-parameter nil '.last-selected-window (selected-window)))
>>
>> ...which seems to work most of the time, but using an advice doesn't
>> feel that great, esp. with C functions.
>
> You might want to have a look at my window-pub branch.  It has
>
> window-use-time is a built-in function in `window.c'.
>
> (window-use-time &optional WINDOW)
>
> Return WINDOW's use time.
> WINDOW defaults to the selected window.  The window with the highest use
> time is the most recently selected one.  The window with the lowest use
> time is the least recently selected one.
>
> and
>
> get-mru-window is a compiled Lisp function in `window.el'.
>
> (get-mru-window &optional ALL-FRAMES)
>
> Return the most recently used window on frames specified by ALL-FRAMES.
> Do not return a minibuffer window.
>
> The following non-nil values of the optional argument ALL-FRAMES
> have special meanings:
>
> - t means consider all windows on all existing frames.
>
> - `visible' means consider all windows on all visible frames.
>
> - 0 (the number zero) means consider all windows on all visible
>     and iconified frames.
>
> - A frame means consider all windows on that frame only.
>
> Any other value of ALL-FRAMES means consider all windows on the
> selected frame and no others.

This is great, thank you! I'll have a look.

Any reason not to have `get-mru-window' in the trunk (I actually
searched for exactly that before resorting to the advice hack)?

(And I guess the hook proposal still stands as well, or are there any
arguments against that? One might want to do other things triggered by
window selection.)

  Štěpán





  reply	other threads:[~2010-11-12 11:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12  0:14 bug#7381: 24.0.50; Provide a hook run when a window is selected Štěpán Němec
2010-11-12  0:53 ` Lennart Borgman
2010-11-12 11:26   ` Štěpán Němec
2010-11-12  8:16 ` martin rudalics
2010-11-12 11:31   ` Štěpán Němec [this message]
2010-11-12 13:05     ` martin rudalics
2010-11-12 14:53       ` Štěpán Němec
2010-11-12 16:31         ` martin rudalics
2010-11-12 17:09           ` Štěpán Němec
2010-11-12 18:09             ` martin rudalics
2010-11-12 18:40               ` Štěpán Němec
2010-11-13  8:32                 ` martin rudalics
2010-11-13 12:13                   ` Štěpán Němec
2010-11-13 13:57                     ` martin rudalics
2010-11-13 15:23                       ` Štěpán Němec
2010-11-13 16:02                         ` martin rudalics
2010-11-13 16:03                         ` martin rudalics
2010-11-13 18:49                           ` Chong Yidong
2010-12-23 17:07                             ` Štěpán Němec
2010-12-24  9:31                               ` martin rudalics
2010-12-29 11:21                               ` Chong Yidong
2010-12-30 16:06                                 ` Richard Stallman
2010-11-12 20:55 ` Stefan Monnier
2019-01-12  9:15 ` martin rudalics
2019-01-12 11:46   ` Štěpán Němec
2019-01-12 14:12     ` martin rudalics
2019-01-12 14:58       ` Štěpán Němec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bp5ug4lz.fsf@gmail.com \
    --to=stepnem@gmail.com \
    --cc=7381@debbugs.gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).