unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
@ 2013-06-13 11:45 E Sabof
  2013-06-13 13:02 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: E Sabof @ 2013-06-13 11:45 UTC (permalink / raw)
  To: 14604

[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

This works on 24.3, but on trunk all windows will be shown as "selected".

(setq-default
 mode-line-format
 '(:eval (if (eq (frame-selected-window)
                 (selected-window))
             "selected"
             "not-selected")))

I don't know which behavior is correct, but being able to find which is the
"really" selected window would be nice.

[-- Attachment #2: Type: text/html, Size: 760 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 11:45 bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window E Sabof
@ 2013-06-13 13:02 ` Eli Zaretskii
  2013-06-13 13:47   ` E Sabof
  2013-06-13 14:35 ` Stefan Monnier
  2022-02-13  9:21 ` Lars Ingebrigtsen
  2 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2013-06-13 13:02 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

> Date: Thu, 13 Jun 2013 12:45:54 +0100
> From: E Sabof <esabof@gmail.com>
> 
> 
> [1:text/plain Hide]
> 
> This works on 24.3, but on trunk all windows will be shown as "selected".
> 
> (setq-default
>  mode-line-format
>  '(:eval (if (eq (frame-selected-window)
>                  (selected-window))
>              "selected"
>              "not-selected")))
> 
> I don't know which behavior is correct, but being able to find which is the
> "really" selected window would be nice.

When the mode-line format is evaluated, Emacs makes its window the
selected window.  If it didn't, how could it show values for that
window in the mode line?





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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 13:02 ` Eli Zaretskii
@ 2013-06-13 13:47   ` E Sabof
  0 siblings, 0 replies; 13+ messages in thread
From: E Sabof @ 2013-06-13 13:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

On Thu, Jun 13, 2013 at 2:02 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Thu, 13 Jun 2013 12:45:54 +0100
> > From: E Sabof <esabof@gmail.com>
> >
> >
> > [1:text/plain Hide]
> >
> > This works on 24.3, but on trunk all windows will be shown as "selected".
> >
> > (setq-default
> >  mode-line-format
> >  '(:eval (if (eq (frame-selected-window)
> >                  (selected-window))
> >              "selected"
> >              "not-selected")))
> >
> > I don't know which behavior is correct, but being able to find which is
> the
> > "really" selected window would be nice.
>
> When the mode-line format is evaluated, Emacs makes its window the
> selected window.  If it didn't, how could it show values for that
> window in the mode line?
>

(frame-selected-window) used to remain bound to the window which the user
would consider selected, and only (selected-window) changed. I don't know
whether it was a bug, or intentional.

If it was a bug, I suppose I could get the desired results with command
hooks.

[-- Attachment #2: Type: text/html, Size: 1776 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 11:45 bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window E Sabof
  2013-06-13 13:02 ` Eli Zaretskii
@ 2013-06-13 14:35 ` Stefan Monnier
  2013-06-13 14:59   ` E Sabof
  2022-02-13  9:21 ` Lars Ingebrigtsen
  2 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2013-06-13 14:35 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

> This works on 24.3, but on trunk all windows will be shown as "selected".
> (setq-default
>  mode-line-format
>  '(:eval (if (eq (frame-selected-window)
>                  (selected-window))
>              "selected"
>              "not-selected")))

Indeed this doesn't work any more.  This was one of the very few places
where (eq (frame-selected-window) (selected-window)) was nil, and this
"invariant" is presumed at various places in the C code, so it was
a bug.

BTW, this worked in Emacs<24.3 if you wanted to highlight every frame's
selected-window, but not if you wanted to highlight "the one and only
selected-window".  For single-frame settings, there's no difference,
of course.

There is no alternative, yet.  We should probably provide some ad-hoc
primitives (call them maybe display-selected-window and
display-frame-selected-window) which return something like "the window
that was selected when we entered redisplay".


        Stefan





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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 14:35 ` Stefan Monnier
@ 2013-06-13 14:59   ` E Sabof
  2013-06-13 16:04     ` Eli Zaretskii
  2013-10-30 17:50     ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: E Sabof @ 2013-06-13 14:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]

On Thu, Jun 13, 2013 at 3:35 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> > This works on 24.3, but on trunk all windows will be shown as "selected".
> > (setq-default
> >  mode-line-format
> >  '(:eval (if (eq (frame-selected-window)
> >                  (selected-window))
> >              "selected"
> >              "not-selected")))
>
> Indeed this doesn't work any more.  This was one of the very few places
> where (eq (frame-selected-window) (selected-window)) was nil, and this
> "invariant" is presumed at various places in the C code, so it was
> a bug.
>
> BTW, this worked in Emacs<24.3 if you wanted to highlight every frame's
> selected-window, but not if you wanted to highlight "the one and only
> selected-window".  For single-frame settings, there's no difference,
> of course.
>
> There is no alternative, yet.  We should probably provide some ad-hoc
> primitives (call them maybe display-selected-window and
> display-frame-selected-window) which return something like "the window
> that was selected when we entered redisplay".
>
>
>         Stefan
>

FWIW, the below seems to be working, although it still feels like an
omission.

Evgeni

(defvar user-selected-window nil)
(defun register-user-location ()
  (setq user-selected-window (selected-window)))
(add-hook 'post-command-hook 'register-user-location)

(setq-default
  mode-line-format
  '(:eval (if (eq user-selected-window (selected-window))
              "selected"
              "not-selected")))

[-- Attachment #2: Type: text/html, Size: 2853 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 14:59   ` E Sabof
@ 2013-06-13 16:04     ` Eli Zaretskii
  2013-06-13 16:16       ` E Sabof
  2013-10-30 17:50     ` Stefan Monnier
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2013-06-13 16:04 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

> Date: Thu, 13 Jun 2013 15:59:11 +0100
> From: E Sabof <esabof@gmail.com>
> Cc: 14604@debbugs.gnu.org
> 
> (defvar user-selected-window nil)
> (defun register-user-location ()
>   (setq user-selected-window (selected-window)))
> (add-hook 'post-command-hook 'register-user-location)
> 
> (setq-default
>   mode-line-format
>   '(:eval (if (eq user-selected-window (selected-window))
>               "selected"
>               "not-selected")))

Does this work with mouse-autoselect-window?





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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 16:04     ` Eli Zaretskii
@ 2013-06-13 16:16       ` E Sabof
  0 siblings, 0 replies; 13+ messages in thread
From: E Sabof @ 2013-06-13 16:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 597 bytes --]

On Thu, Jun 13, 2013 at 5:04 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Thu, 13 Jun 2013 15:59:11 +0100
> > From: E Sabof <esabof@gmail.com>
> > Cc: 14604@debbugs.gnu.org
> >
> > (defvar user-selected-window nil)
> > (defun register-user-location ()
> >   (setq user-selected-window (selected-window)))
> > (add-hook 'post-command-hook 'register-user-location)
> >
> > (setq-default
> >   mode-line-format
> >   '(:eval (if (eq user-selected-window (selected-window))
> >               "selected"
> >               "not-selected")))
>
> Does this work with mouse-autoselect-window?
>

Yes

[-- Attachment #2: Type: text/html, Size: 1143 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 14:59   ` E Sabof
  2013-06-13 16:04     ` Eli Zaretskii
@ 2013-10-30 17:50     ` Stefan Monnier
  2013-10-30 19:23       ` E Sabof
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2013-10-30 17:50 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

> (defvar user-selected-window nil)
> (defun register-user-location ()
>   (setq user-selected-window (selected-window)))
> (add-hook 'post-command-hook 'register-user-location)

> (setq-default
>   mode-line-format
>   '(:eval (if (eq user-selected-window (selected-window))
>               "selected"
>               "not-selected")))

That will usually work, except for corner-cases where redisplay happens
in the middle of a command, or when the selected window is modified
between commands (e.g. from a process sentinel).

You can make it reliable with the use of the new
`pre-redisplay-function' hook (instead of post-command-hook), which
I just added yesterday.

Of course, making it reliable doesn't mean it's not an omission.
I tend to agree that it would be good to provide access to that info
more directly.


        Stefan





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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-10-30 17:50     ` Stefan Monnier
@ 2013-10-30 19:23       ` E Sabof
  2013-10-30 22:40         ` E Sabof
  0 siblings, 1 reply; 13+ messages in thread
From: E Sabof @ 2013-10-30 19:23 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

Thanks!

Evgeni


On Wed, Oct 30, 2013 at 5:50 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> > (defvar user-selected-window nil)
> > (defun register-user-location ()
> >   (setq user-selected-window (selected-window)))
> > (add-hook 'post-command-hook 'register-user-location)
>
> > (setq-default
> >   mode-line-format
> >   '(:eval (if (eq user-selected-window (selected-window))
> >               "selected"
> >               "not-selected")))
>
> That will usually work, except for corner-cases where redisplay happens
> in the middle of a command, or when the selected window is modified
> between commands (e.g. from a process sentinel).
>
> You can make it reliable with the use of the new
> `pre-redisplay-function' hook (instead of post-command-hook), which
> I just added yesterday.
>
> Of course, making it reliable doesn't mean it's not an omission.
> I tend to agree that it would be good to provide access to that info
> more directly.
>
>
>         Stefan
>

[-- Attachment #2: Type: text/html, Size: 1540 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-10-30 19:23       ` E Sabof
@ 2013-10-30 22:40         ` E Sabof
  2013-10-30 23:30           ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: E Sabof @ 2013-10-30 22:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 1240 bytes --]

Seemed to work during my brief test. Am I right in assuming that it's going
to become `pre-redisplay-functions' if it goes into production?

Evgeni


On Wed, Oct 30, 2013 at 7:23 PM, E Sabof <esabof@gmail.com> wrote:

> Thanks!
>
> Evgeni
>
>
> On Wed, Oct 30, 2013 at 5:50 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:
>
>> > (defvar user-selected-window nil)
>> > (defun register-user-location ()
>> >   (setq user-selected-window (selected-window)))
>> > (add-hook 'post-command-hook 'register-user-location)
>>
>> > (setq-default
>> >   mode-line-format
>> >   '(:eval (if (eq user-selected-window (selected-window))
>> >               "selected"
>> >               "not-selected")))
>>
>> That will usually work, except for corner-cases where redisplay happens
>> in the middle of a command, or when the selected window is modified
>> between commands (e.g. from a process sentinel).
>>
>> You can make it reliable with the use of the new
>> `pre-redisplay-function' hook (instead of post-command-hook), which
>> I just added yesterday.
>>
>> Of course, making it reliable doesn't mean it's not an omission.
>> I tend to agree that it would be good to provide access to that info
>> more directly.
>>
>>
>>         Stefan
>>
>
>

[-- Attachment #2: Type: text/html, Size: 2177 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-10-30 22:40         ` E Sabof
@ 2013-10-30 23:30           ` Stefan Monnier
  2013-11-01 21:13             ` E Sabof
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2013-10-30 23:30 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

> Seemed to work during my brief test. Am I right in assuming that it's going
> to become `pre-redisplay-functions' if it goes into production?

No: use add-function to modify it.


        Stefan





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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-10-30 23:30           ` Stefan Monnier
@ 2013-11-01 21:13             ` E Sabof
  0 siblings, 0 replies; 13+ messages in thread
From: E Sabof @ 2013-11-01 21:13 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14604

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

FWIW, I do like the new mechnsim. At the same time I think it offers little
utility for of 90% cases, while introducing complexity and opaqueness. I
wouldn't want it to become default for hooks.

Evgeni


On Wed, Oct 30, 2013 at 11:30 PM, Stefan Monnier
<monnier@iro.umontreal.ca>wrote:

> > Seemed to work during my brief test. Am I right in assuming that it's
> going
> > to become `pre-redisplay-functions' if it goes into production?
>
> No: use add-function to modify it.
>
>
>         Stefan
>

[-- Attachment #2: Type: text/html, Size: 948 bytes --]

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

* bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window
  2013-06-13 11:45 bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window E Sabof
  2013-06-13 13:02 ` Eli Zaretskii
  2013-06-13 14:35 ` Stefan Monnier
@ 2022-02-13  9:21 ` Lars Ingebrigtsen
  2 siblings, 0 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-13  9:21 UTC (permalink / raw)
  To: E Sabof; +Cc: 14604

E Sabof <esabof@gmail.com> writes:

> This works on 24.3, but on trunk all windows will be shown as "selected".
>
> (setq-default 
>  mode-line-format
>  '(:eval (if (eq (frame-selected-window)
>                  (selected-window))
>              "selected"
>              "not-selected")))
>
> I don't know which behavior is correct, but being able to find which is the "really"
> selected window would be nice.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

In Emacs 29, we've introduced a new function
`mode-line-window-selected-p' for this use case (i.e., determining if
we're rendering the mode line for the currently selected window).  So
I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2022-02-13  9:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-13 11:45 bug#14604: 24.3.50.1; Possibly incorrect behaviour of frame-selected-window E Sabof
2013-06-13 13:02 ` Eli Zaretskii
2013-06-13 13:47   ` E Sabof
2013-06-13 14:35 ` Stefan Monnier
2013-06-13 14:59   ` E Sabof
2013-06-13 16:04     ` Eli Zaretskii
2013-06-13 16:16       ` E Sabof
2013-10-30 17:50     ` Stefan Monnier
2013-10-30 19:23       ` E Sabof
2013-10-30 22:40         ` E Sabof
2013-10-30 23:30           ` Stefan Monnier
2013-11-01 21:13             ` E Sabof
2022-02-13  9:21 ` Lars Ingebrigtsen

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).