all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Detect window switches?
@ 2013-09-25  9:07 Joost Kremers
  2013-09-25  9:28 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 23+ messages in thread
From: Joost Kremers @ 2013-09-25  9:07 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

Is there a way in Emacs to detect a window switch? Basically, I'd like
to perform an action when a window showing a particular buffer gains or
loses focus. Is there a hook or something that exposes this to Elisp?

TIA

Joost



-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-25  9:07 Joost Kremers
@ 2013-09-25  9:28 ` Pascal J. Bourguignon
  2013-09-25 21:30   ` Joost Kremers
  0 siblings, 1 reply; 23+ messages in thread
From: Pascal J. Bourguignon @ 2013-09-25  9:28 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joostkremers@yahoo.com> writes:

> Is there a way in Emacs to detect a window switch? Basically, I'd like
> to perform an action when a window showing a particular buffer gains or
> loses focus. Is there a hook or something that exposes this to Elisp?

have a look at: window-configuration-change-hook
I guess you will have to filter the exact condition yourself.

-- 
__Pascal Bourguignon__
http://www.informatimago.com/


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-25  9:28 ` Pascal J. Bourguignon
@ 2013-09-25 21:30   ` Joost Kremers
  2013-09-25 21:44     ` Eli Zaretskii
       [not found]     ` <mailman.2884.1380145465.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-25 21:30 UTC (permalink / raw)
  To: help-gnu-emacs

Pascal J. Bourguignon wrote:
> Joost Kremers <joostkremers@yahoo.com> writes:
>
>> Is there a way in Emacs to detect a window switch? Basically, I'd like
>> to perform an action when a window showing a particular buffer gains or
>> loses focus. Is there a hook or something that exposes this to Elisp?
>
> have a look at: window-configuration-change-hook
> I guess you will have to filter the exact condition yourself.

Mmm, the documentation of that hook says that "[t]he buffer-local part
of this hook is run once for each window on the affected frame,
with the relevant window selected and its buffer current." That doesn't
seem to leave much room for determining if the relevant window has just
lost focus.


-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-25 21:30   ` Joost Kremers
@ 2013-09-25 21:44     ` Eli Zaretskii
       [not found]     ` <mailman.2884.1380145465.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-25 21:44 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Joost Kremers <joostkremers@yahoo.com>
> Date: 25 Sep 2013 21:30:37 GMT
> 
> Pascal J. Bourguignon wrote:
> > Joost Kremers <joostkremers@yahoo.com> writes:
> >
> >> Is there a way in Emacs to detect a window switch? Basically, I'd like
> >> to perform an action when a window showing a particular buffer gains or
> >> loses focus. Is there a hook or something that exposes this to Elisp?
> >
> > have a look at: window-configuration-change-hook
> > I guess you will have to filter the exact condition yourself.
> 
> Mmm, the documentation of that hook says that "[t]he buffer-local part
> of this hook is run once for each window on the affected frame,
> with the relevant window selected and its buffer current." That doesn't
> seem to leave much room for determining if the relevant window has just
> lost focus.

Instead of selecting a solution, all by yourself, to a problem you
don't describe, and asking details about that solution, I suggest to
step back one notch and describe the problem you are trying to solve.
It is quite possible that solutions other and better than "detect a
window switch" will be suggested.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]     ` <mailman.2884.1380145465.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26  2:50       ` Joost Kremers
  2013-09-26  6:45         ` Eli Zaretskii
       [not found]         ` <mailman.2899.1380177976.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-26  2:50 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:
> Instead of selecting a solution, all by yourself, to a problem you
> don't describe, and asking details about that solution, I suggest to
> step back one notch and describe the problem you are trying to solve.
> It is quite possible that solutions other and better than "detect a
> window switch" will be suggested.

What I'd like to do is remove a highlight from a buffer or change its
appearance when said buffer is not current, and restore it when it
becomes current again. Similar to what happens to the cursor in a window
that is not selected.

Since it's the visual effect I'm interested in, it's really only
relevant when the buffer is being displayed in a window, which is why I
asked the question this way.

I would be equally happy with a hook that is called when a buffer switch
takes place, but from what Google tells me, such a hook does not exist.

-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26  2:50       ` Joost Kremers
@ 2013-09-26  6:45         ` Eli Zaretskii
       [not found]         ` <mailman.2899.1380177976.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-26  6:45 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Joost Kremers <joostkremers@yahoo.com>
> Date: 26 Sep 2013 02:50:53 GMT
> 
> What I'd like to do is remove a highlight from a buffer or change its
> appearance when said buffer is not current, and restore it when it
> becomes current again. Similar to what happens to the cursor in a window
> that is not selected.

OK, but the requirements are still not clear.  First, what do you mean
by "remove a highlight from a buffer", and what "change in its
appearance" did you have in mind?  And second, what if the same buffer
is displayed in more than one window?  Finally, why the differences in
the mode-line appearance are not already what you want?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]         ` <mailman.2899.1380177976.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 10:23           ` Joost Kremers
  0 siblings, 0 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-26 10:23 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:
>> From: Joost Kremers <joostkremers@yahoo.com>
>> Date: 26 Sep 2013 02:50:53 GMT
>> 
>> What I'd like to do is remove a highlight from a buffer or change its
>> appearance when said buffer is not current, and restore it when it
>> becomes current again. Similar to what happens to the cursor in a window
>> that is not selected.
>
> OK, but the requirements are still not clear.  First, what do you mean
> by "remove a highlight from a buffer", and what "change in its
> appearance" did you have in mind?

Sorry, I meant an overlay. So that would be (delete-overlay <overlay>)
or changing the face property of an overlay.

>  And second, what if the same buffer
> is displayed in more than one window?

In this particular case, that shouldn't happen and won't happen, unless
a user explicitly sets out to do so. If that happens, I'm confident that
Emacs won't crash. :-)

Long story long: I'm talking about a BibTeX database manager I maintain:

<http://ebib.sourceforge.net>

Best to look at the screen shot:

<http://ebib.sourceforge.net/images/Main-view.png>

I'm using two buffers, one to list all the entry keys in the database
and one to list the fields of the current entry. I use two overlays, one
in each buffer, to indicate which entry and which field is active. In
the screen shot, the top (index) buffer is active (look at the cursor
shape), and what I'd like to do is change or hide the overlay of the
bottom (entry) buffer in that case.

There are keys to switch from the index to the entry buffer and back
(`e' and `q', respectively), so a user normally doesn't use the standard
buffer switching commands to switch between them. In fact, if the kind
of hook I'm asking about doesn't exist, I'll use the commands to which
`e' and `q' are bound to change the overlay, I just thought that a hook
would be a bit more robust.[1]

>  Finally, why the differences in
> the mode-line appearance are not already what you want?

Well, as you can see in the screen shot, there are colour themes that
don't distinguish very clearly between the selected window and
non-selected ones. (This particular theme is zenburn, I think, which I'm
not using anymore, but my current theme, anti-zenburn, isn't much better
in this respect.) 

Joost



[1] In fact, these commands do a bit more than just switching to the
index/entry buffer, so a user really *shouldn't* be using the normal
buffer switching commands. If a buffer switch hook or a window select
hook would exist, I'd move the extra stuff to the hook functions as
well, so that normal buffer switching commands work properly.

-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
@ 2013-09-26 12:52 martin rudalics
  0 siblings, 0 replies; 23+ messages in thread
From: martin rudalics @ 2013-09-26 12:52 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: joostkremers

 > Mmm, the documentation of that hook says that "[t]he buffer-local part
 > of this hook is run once for each window on the affected frame,
 > with the relevant window selected and its buffer current." That doesn't
 > seem to leave much room for determining if the relevant window has just
 > lost focus.

Did you try the "global" part?  If it doesn't work, please report a bug.

Thanks, martin



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found] <mailman.2910.1380199959.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 16:54 ` Joost Kremers
  2013-09-26 17:49   ` Eli Zaretskii
       [not found]   ` <mailman.2942.1380217810.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-26 16:54 UTC (permalink / raw)
  To: help-gnu-emacs

martin rudalics wrote:
> > Mmm, the documentation of that hook says that "[t]he buffer-local part
> > of this hook is run once for each window on the affected frame,
> > with the relevant window selected and its buffer current." That doesn't
> > seem to leave much room for determining if the relevant window has just
> > lost focus.
>
> Did you try the "global" part?  If it doesn't work, please report a bug.

A quick test I just did suggests that window-configuration-change-hook
isn't even called when switching from one window to another, e.g., with
`other-window' or one of the `windmove-*' commands.

I apologise if my initial description was too unclear. What I'd like to
know is if it's possible to detect when a window goes from being
selected to being not selected and vice versa. Or, alternatively, when a
buffer goes from being current to not current and vice versa. From what
I've been able to find on the internet, this isn't possible.

TIA


-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 16:54 ` Detect window switches? Joost Kremers
@ 2013-09-26 17:49   ` Eli Zaretskii
       [not found]   ` <mailman.2942.1380217810.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-26 17:49 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Joost Kremers <joostkremers@yahoo.com>
> Date: 26 Sep 2013 16:54:34 GMT
> 
> What I'd like to know is if it's possible to detect when a window
> goes from being selected to being not selected and vice versa. Or,
> alternatively, when a buffer goes from being current to not current
> and vice versa.

There's always post-command-hook, where you can test whether the
current-buffer is one of yours, and act accordingly.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]   ` <mailman.2942.1380217810.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 18:22     ` Dan Espen
  2013-09-26 18:37       ` Eli Zaretskii
       [not found]       ` <mailman.2950.1380220732.10748.help-gnu-emacs@gnu.org>
  2013-09-26 20:51     ` Joost Kremers
  1 sibling, 2 replies; 23+ messages in thread
From: Dan Espen @ 2013-09-26 18:22 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Joost Kremers <joostkremers@yahoo.com>
>> Date: 26 Sep 2013 16:54:34 GMT
>> 
>> What I'd like to know is if it's possible to detect when a window
>> goes from being selected to being not selected and vice versa. Or,
>> alternatively, when a buffer goes from being current to not current
>> and vice versa.
>
> There's always post-command-hook, where you can test whether the
> current-buffer is one of yours, and act accordingly.

My mode line changes color when a buffer changes from active/inactive.
Isn't that what the OP is looking for?

-- 
Dan Espen


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 18:22     ` Dan Espen
@ 2013-09-26 18:37       ` Eli Zaretskii
       [not found]       ` <mailman.2950.1380220732.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-26 18:37 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Dan Espen <despen@verizon.net>
> Date: Thu, 26 Sep 2013 14:22:15 -0400
> 
> My mode line changes color when a buffer changes from active/inactive.
> Isn't that what the OP is looking for?

That's done on the C level, and Lisp programs cannot hook into this.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]       ` <mailman.2950.1380220732.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 19:22         ` Dan Espen
  2013-09-26 19:48           ` Eli Zaretskii
                             ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Dan Espen @ 2013-09-26 19:22 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Dan Espen <despen@verizon.net>
>> Date: Thu, 26 Sep 2013 14:22:15 -0400
>> 
>> My mode line changes color when a buffer changes from active/inactive.
>> Isn't that what the OP is looking for?
>
> That's done on the C level, and Lisp programs cannot hook into this.

Hmm, starting to sound like a bug.
Here's an event that Emacs acts on but doesn't make the
event visible to ELisp.

-- 
Dan Espen


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 19:22         ` Dan Espen
@ 2013-09-26 19:48           ` Eli Zaretskii
  2013-09-26 20:27             ` Stefan Monnier
       [not found]           ` <mailman.2957.1380224960.10748.help-gnu-emacs@gnu.org>
  2013-09-26 20:54           ` Joost Kremers
  2 siblings, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-26 19:48 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Dan Espen <despen@verizon.net>
> Date: Thu, 26 Sep 2013 15:22:58 -0400
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Dan Espen <despen@verizon.net>
> >> Date: Thu, 26 Sep 2013 14:22:15 -0400
> >> 
> >> My mode line changes color when a buffer changes from active/inactive.
> >> Isn't that what the OP is looking for?
> >
> > That's done on the C level, and Lisp programs cannot hook into this.
> 
> Hmm, starting to sound like a bug.
> Here's an event that Emacs acts on but doesn't make the
> event visible to ELisp.

No, Emacs doesn't act on this as an event.  What happens is that the
next redisplay after a window switch redraws the mode line in a
different face.  The redisplay isn't triggered by an event (because
there is no such event), it is triggered by other means, mostly
because Emacs becomes idle.  That could happen many seconds after the
switch, if Emacs becomes busy calculating something, for example.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]           ` <mailman.2957.1380224960.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 20:15             ` Dan Espen
  2013-09-27  5:57               ` Eli Zaretskii
       [not found]               ` <mailman.2973.1380261467.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 23+ messages in thread
From: Dan Espen @ 2013-09-26 20:15 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Dan Espen <despen@verizon.net>
>> Date: Thu, 26 Sep 2013 15:22:58 -0400
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> From: Dan Espen <despen@verizon.net>
>> >> Date: Thu, 26 Sep 2013 14:22:15 -0400
>> >> 
>> >> My mode line changes color when a buffer changes from active/inactive.
>> >> Isn't that what the OP is looking for?
>> >
>> > That's done on the C level, and Lisp programs cannot hook into this.
>> 
>> Hmm, starting to sound like a bug.
>> Here's an event that Emacs acts on but doesn't make the
>> event visible to ELisp.
>
> No, Emacs doesn't act on this as an event.  What happens is that the
> next redisplay after a window switch redraws the mode line in a
> different face.  The redisplay isn't triggered by an event (because
> there is no such event), it is triggered by other means, mostly
> because Emacs becomes idle.  That could happen many seconds after the
> switch, if Emacs becomes busy calculating something, for example.

I only meant event with the meaning that something happens.

Here Emacs sees a buffer become active or inactive and thinks it's
an important enough event that it provides a visual mode line change.

Well, it also changes the physical appearance of the keyboard cursor.
Mine goes from 3 pixels wide to 1.

-- 
Dan Espen


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 19:48           ` Eli Zaretskii
@ 2013-09-26 20:27             ` Stefan Monnier
  2013-09-27  6:01               ` Eli Zaretskii
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2013-09-26 20:27 UTC (permalink / raw)
  To: help-gnu-emacs

>> Hmm, starting to sound like a bug.  Here's an event that Emacs acts
>> on but doesn't make the event visible to ELisp.
> No, Emacs doesn't act on this as an event.  What happens is that the
> next redisplay after a window switch redraws the mode line in a
> different face.  The redisplay isn't triggered by an event (because
> there is no such event), it is triggered by other means, mostly
> because Emacs becomes idle.  That could happen many seconds after the
> switch, if Emacs becomes busy calculating something, for example.

Well the event is `redisplay', and indeed if we had
a before-redisplay-hook, we could use it to do that in Lisp (although
we'd bump into another problem: faces can't be set per-window.
Tho maybe with a redisplay-window-hook we could trick the display into
using different face settings for different windows).


        Stefan




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]   ` <mailman.2942.1380217810.10748.help-gnu-emacs@gnu.org>
  2013-09-26 18:22     ` Dan Espen
@ 2013-09-26 20:51     ` Joost Kremers
  1 sibling, 0 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-26 20:51 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:
>> From: Joost Kremers <joostkremers@yahoo.com>
>> Date: 26 Sep 2013 16:54:34 GMT
>> 
>> What I'd like to know is if it's possible to detect when a window
>> goes from being selected to being not selected and vice versa. Or,
>> alternatively, when a buffer goes from being current to not current
>> and vice versa.
>
> There's always post-command-hook, where you can test whether the
> current-buffer is one of yours, and act accordingly.

That's something to consider, thanks.


-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 19:22         ` Dan Espen
  2013-09-26 19:48           ` Eli Zaretskii
       [not found]           ` <mailman.2957.1380224960.10748.help-gnu-emacs@gnu.org>
@ 2013-09-26 20:54           ` Joost Kremers
  2 siblings, 0 replies; 23+ messages in thread
From: Joost Kremers @ 2013-09-26 20:54 UTC (permalink / raw)
  To: help-gnu-emacs

Dan Espen wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Dan Espen <despen@verizon.net>
>>> Date: Thu, 26 Sep 2013 14:22:15 -0400
>>> 
>>> My mode line changes color when a buffer changes from active/inactive.
>>> Isn't that what the OP is looking for?

Yup. The mode line and also the cursor. I'd like to create a similar
effect with overlays.

>> That's done on the C level, and Lisp programs cannot hook into this.
>
> Hmm, starting to sound like a bug.
> Here's an event that Emacs acts on but doesn't make the
> event visible to ELisp.

I don't know if I'd call it a bug, but I am surprised that it's not
exposed to Elisp.


-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
@ 2013-09-27  5:48 martin rudalics
  0 siblings, 0 replies; 23+ messages in thread
From: martin rudalics @ 2013-09-27  5:48 UTC (permalink / raw)
  To: joostkremers; +Cc: help-gnu-emacs

 > What I'd like to
 > know is if it's possible to detect when a window goes from being
 > selected to being not selected and vice versa.
[...]
 > From what
 > I've been able to find on the internet, this isn't possible.

On current trunk try

(add-hook 'buffer-list-update-hook 'ding)

martin



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 20:15             ` Dan Espen
@ 2013-09-27  5:57               ` Eli Zaretskii
       [not found]               ` <mailman.2973.1380261467.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-27  5:57 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Dan Espen <despen@verizon.net>
> Date: Thu, 26 Sep 2013 16:15:52 -0400
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Dan Espen <despen@verizon.net>
> >> Date: Thu, 26 Sep 2013 15:22:58 -0400
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> >> From: Dan Espen <despen@verizon.net>
> >> >> Date: Thu, 26 Sep 2013 14:22:15 -0400
> >> >> 
> >> >> My mode line changes color when a buffer changes from active/inactive.
> >> >> Isn't that what the OP is looking for?
> >> >
> >> > That's done on the C level, and Lisp programs cannot hook into this.
> >> 
> >> Hmm, starting to sound like a bug.
> >> Here's an event that Emacs acts on but doesn't make the
> >> event visible to ELisp.
> >
> > No, Emacs doesn't act on this as an event.  What happens is that the
> > next redisplay after a window switch redraws the mode line in a
> > different face.  The redisplay isn't triggered by an event (because
> > there is no such event), it is triggered by other means, mostly
> > because Emacs becomes idle.  That could happen many seconds after the
> > switch, if Emacs becomes busy calculating something, for example.
> 
> I only meant event with the meaning that something happens.

But that's just it: nothing happened, as far as Emacs is concerned.
As part of routine redisplay, Emacs displays the mode line of the
selected window differently than it does with other windows.  It
doesn't track whether a particular window was selected earlier and
became non-selected now, so it doesn't know that "something's
happened".  It just reflects the current state of affairs on the
screen.

> Here Emacs sees a buffer become active or inactive

No, it doesn't know a buffer _became_ active, it just _finds_ it to be
current or not current.

> Well, it also changes the physical appearance of the keyboard cursor.
> Mine goes from 3 pixels wide to 1.

More of the same.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-26 20:27             ` Stefan Monnier
@ 2013-09-27  6:01               ` Eli Zaretskii
  2013-09-27 13:13                 ` Stefan Monnier
  0 siblings, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2013-09-27  6:01 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Thu, 26 Sep 2013 16:27:04 -0400
> 
> Well the event is `redisplay', and indeed if we had
> a before-redisplay-hook, we could use it to do that in Lisp (although
> we'd bump into another problem: faces can't be set per-window.

The way to do that is with face remapping, although that is per
buffer, not per window.  But I don't think this is relevant to the
issue at hand, as the OP has an overlay to handle that.  He just wants
to know when to put the overlay and when to remove it.

> Tho maybe with a redisplay-window-hook we could trick the display into
> using different face settings for different windows).

I don't think redisplay-window-hook would help in this case, but if it
will, so will an idle timer, since the code that runs off that hook
will simply sample the situation at more or less regular intervals.
Doing that from a timer is probably an approximation that is "good
enough".



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
  2013-09-27  6:01               ` Eli Zaretskii
@ 2013-09-27 13:13                 ` Stefan Monnier
  0 siblings, 0 replies; 23+ messages in thread
From: Stefan Monnier @ 2013-09-27 13:13 UTC (permalink / raw)
  To: help-gnu-emacs

> I don't think redisplay-window-hook would help in this case, but if it
> will, so will an idle timer, since the code that runs off that hook
> will simply sample the situation at more or less regular intervals.
> Doing that from a timer is probably an approximation that is "good
> enough".

There are plenty of "good enough" solutions (e.g. post-command-hook).
But a `before-redisplay-hook' would make it possible to write a reliable
solution, rather than just a "good enough" one.


        Stefan




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Detect window switches?
       [not found]               ` <mailman.2973.1380261467.10748.help-gnu-emacs@gnu.org>
@ 2013-09-27 15:27                 ` Dan Espen
  0 siblings, 0 replies; 23+ messages in thread
From: Dan Espen @ 2013-09-27 15:27 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Dan Espen <despen@verizon.net>
>> Date: Thu, 26 Sep 2013 16:15:52 -0400
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> From: Dan Espen <despen@verizon.net>
>> >> Date: Thu, 26 Sep 2013 15:22:58 -0400
>> >> 
>> >> Eli Zaretskii <eliz@gnu.org> writes:
>> >> 
>> >> >> From: Dan Espen <despen@verizon.net>
>> >> >> Date: Thu, 26 Sep 2013 14:22:15 -0400
>> >> >> 
>> >> >> My mode line changes color when a buffer changes from active/inactive.
>> >> >> Isn't that what the OP is looking for?
>> >> >
>> >> > That's done on the C level, and Lisp programs cannot hook into this.
>> >> 
>> >> Hmm, starting to sound like a bug.
>> >> Here's an event that Emacs acts on but doesn't make the
>> >> event visible to ELisp.
>> >
>> > No, Emacs doesn't act on this as an event.  What happens is that the
>> > next redisplay after a window switch redraws the mode line in a
>> > different face.  The redisplay isn't triggered by an event (because
>> > there is no such event), it is triggered by other means, mostly
>> > because Emacs becomes idle.  That could happen many seconds after the
>> > switch, if Emacs becomes busy calculating something, for example.
>> 
>> I only meant event with the meaning that something happens.
>
> But that's just it: nothing happened, as far as Emacs is concerned.
> As part of routine redisplay, Emacs displays the mode line of the
> selected window differently than it does with other windows.  It
> doesn't track whether a particular window was selected earlier and
> became non-selected now, so it doesn't know that "something's
> happened".  It just reflects the current state of affairs on the
> screen.
>
>> Here Emacs sees a buffer become active or inactive
>
> No, it doesn't know a buffer _became_ active, it just _finds_ it to be
> current or not current.
>
>> Well, it also changes the physical appearance of the keyboard cursor.
>> Mine goes from 3 pixels wide to 1.
>
> More of the same.

I think I understand.

Switching buffers tells Emacs to redraw everything.
Something else set the state flag to active or inactive
and the redraw routines just see the new flag.

So the place the hook is needed is where that state flag
is set.  And Emacs may need to add a test while setting
that state flag to see if it's a change in state so it
could run the new hook.

-- 
Dan Espen


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2013-09-27 15:27 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2910.1380199959.10748.help-gnu-emacs@gnu.org>
2013-09-26 16:54 ` Detect window switches? Joost Kremers
2013-09-26 17:49   ` Eli Zaretskii
     [not found]   ` <mailman.2942.1380217810.10748.help-gnu-emacs@gnu.org>
2013-09-26 18:22     ` Dan Espen
2013-09-26 18:37       ` Eli Zaretskii
     [not found]       ` <mailman.2950.1380220732.10748.help-gnu-emacs@gnu.org>
2013-09-26 19:22         ` Dan Espen
2013-09-26 19:48           ` Eli Zaretskii
2013-09-26 20:27             ` Stefan Monnier
2013-09-27  6:01               ` Eli Zaretskii
2013-09-27 13:13                 ` Stefan Monnier
     [not found]           ` <mailman.2957.1380224960.10748.help-gnu-emacs@gnu.org>
2013-09-26 20:15             ` Dan Espen
2013-09-27  5:57               ` Eli Zaretskii
     [not found]               ` <mailman.2973.1380261467.10748.help-gnu-emacs@gnu.org>
2013-09-27 15:27                 ` Dan Espen
2013-09-26 20:54           ` Joost Kremers
2013-09-26 20:51     ` Joost Kremers
2013-09-27  5:48 martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2013-09-26 12:52 martin rudalics
2013-09-25  9:07 Joost Kremers
2013-09-25  9:28 ` Pascal J. Bourguignon
2013-09-25 21:30   ` Joost Kremers
2013-09-25 21:44     ` Eli Zaretskii
     [not found]     ` <mailman.2884.1380145465.10748.help-gnu-emacs@gnu.org>
2013-09-26  2:50       ` Joost Kremers
2013-09-26  6:45         ` Eli Zaretskii
     [not found]         ` <mailman.2899.1380177976.10748.help-gnu-emacs@gnu.org>
2013-09-26 10:23           ` Joost Kremers

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.