* Advicing select-windows, shr rendering, and per-buffer-theme package
@ 2016-03-18 11:04 Iñigo Serna
2016-03-18 13:38 ` Clément Pit--Claudel
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Iñigo Serna @ 2016-03-18 11:04 UTC (permalink / raw)
To: emacs-devel
Hi,
I'm the author of “per-buffer-theme”, a simple package available in
MELPA [1], which changes emacs theme when switching to a buffer according to
some configured rules (f.e. use a dark theme when coding, light theme
for email or web navigation). It advices `select-window', checks buffer
name or major-mode, and changes theme.
It worked correctly and fast with emacs 24.5, but now with emacs 25.x it
produces additional “flickering” when switching buffers, especially for
eww/shr buffers, where it makes package useless.
I think problem comes that, when switching to a eww/shr buffer, shr
rendering uses many temporal buffers, so theme changes many times
producing that "flickering" effect. But I'm not sure as my elisp skills
and emacs internals knowledge is quite limited.
I don't know how to solve it… I've tested with before/after variations
to `advice-add' but results are similar. First versions used
`window-configuration-change-hook' but add-advice to select-window was
much better option then. Any ideas?
Thanks in advance,
Iñigo Serna
[1] http://melpa.org/#/per-buffer-theme
https://bitbucket.org/inigoserna/per-buffer-theme.el
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 11:04 Advicing select-windows, shr rendering, and per-buffer-theme package Iñigo Serna
@ 2016-03-18 13:38 ` Clément Pit--Claudel
2016-03-18 13:40 ` Clément Pit--Claudel
2016-03-18 13:55 ` raman
2 siblings, 0 replies; 14+ messages in thread
From: Clément Pit--Claudel @ 2016-03-18 13:38 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 469 bytes --]
On 03/18/2016 07:04 AM, Iñigo Serna wrote:
> I think problem comes that, when switching to a eww/shr buffer, shr
> rendering uses many temporal buffers, so theme changes many times
> producing that "flickering" effect. But I'm not sure as my elisp skills
> and emacs internals knowledge is quite limited.
Do you need to change theme for temporary buffers? Usually these have a name that starts with a space; did you make sure to blacklist them?
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 11:04 Advicing select-windows, shr rendering, and per-buffer-theme package Iñigo Serna
2016-03-18 13:38 ` Clément Pit--Claudel
@ 2016-03-18 13:40 ` Clément Pit--Claudel
2016-03-18 16:45 ` Iñigo Serna
2016-03-18 13:55 ` raman
2 siblings, 1 reply; 14+ messages in thread
From: Clément Pit--Claudel @ 2016-03-18 13:40 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1510 bytes --]
Another idea; do you need to change the theme per buffer, or per buffer displayed in a window? If the latter, then you could ensure that buffer themes are only changed if a buffer is actually shown on screen.
On 03/18/2016 07:04 AM, Iñigo Serna wrote:
> Hi,
>
> I'm the author of “per-buffer-theme”, a simple package available in
> MELPA [1], which changes emacs theme when switching to a buffer according to
> some configured rules (f.e. use a dark theme when coding, light theme
> for email or web navigation). It advices `select-window', checks buffer
> name or major-mode, and changes theme.
>
> It worked correctly and fast with emacs 24.5, but now with emacs 25.x it
> produces additional “flickering” when switching buffers, especially for
> eww/shr buffers, where it makes package useless.
>
> I think problem comes that, when switching to a eww/shr buffer, shr
> rendering uses many temporal buffers, so theme changes many times
> producing that "flickering" effect. But I'm not sure as my elisp skills
> and emacs internals knowledge is quite limited.
>
> I don't know how to solve it… I've tested with before/after variations
> to `advice-add' but results are similar. First versions used
> `window-configuration-change-hook' but add-advice to select-window was
> much better option then. Any ideas?
>
> Thanks in advance,
> Iñigo Serna
>
> [1] http://melpa.org/#/per-buffer-theme
> https://bitbucket.org/inigoserna/per-buffer-theme.el
>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 13:40 ` Clément Pit--Claudel
@ 2016-03-18 16:45 ` Iñigo Serna
2016-03-18 17:45 ` Clément Pit--Claudel
0 siblings, 1 reply; 14+ messages in thread
From: Iñigo Serna @ 2016-03-18 16:45 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: emacs-devel
Hi,
Clément Pit--Claudel <clement.pit@gmail.com> writes:
> Do you need to change theme for temporary buffers? Usually these have a name that starts with a space; did you make sure to blacklist them?
I think I checked for them, but not, the regular expression I used didn't
include temporary buffers.
Checking for them before changing theme helps a lot!
> Another idea; do you need to change the theme per buffer, or per buffer displayed in a window? If the latter, then you could ensure that buffer themes are only changed if a buffer is actually shown on screen.
This is useful too.
Finally, combining both suggestions solve the problem. There are some
flickering in some rare cases but most of them have disappeared.
(when (and (not (string-prefix-p " " (buffer-name buffer)))
(get-buffer-window buffer))
...)
Thanks,
Iñigo Serna
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 16:45 ` Iñigo Serna
@ 2016-03-18 17:45 ` Clément Pit--Claudel
2016-03-18 20:17 ` Iñigo Serna
0 siblings, 1 reply; 14+ messages in thread
From: Clément Pit--Claudel @ 2016-03-18 17:45 UTC (permalink / raw)
To: Iñigo Serna; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 226 bytes --]
On 03/18/2016 12:45 PM, Iñigo Serna wrote:
> ...
> Finally, combining both suggestions solve the problem. There are some
> flickering in some rare cases but most of them have disappeared.
Great, glad I could help :)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 17:45 ` Clément Pit--Claudel
@ 2016-03-18 20:17 ` Iñigo Serna
2016-03-18 22:07 ` raman
0 siblings, 1 reply; 14+ messages in thread
From: Iñigo Serna @ 2016-03-18 20:17 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: emacs-devel
Clément Pit--Claudel <clement.pit@gmail.com> writes:
> Great, glad I could help :)
In my case, problem is aggravated as I use "perspective" package and
persp-mode activates each buffer when switching perspective.
As I see, it happens in `persp-reactivate-buffers' function to put
the buffers in current perspective on top of visited list.
But this should not occur with plain emacs.
Anyway, as the solution is not perfect and I'm learning I will look at
Raman's & Stefan's suggestion of using an idle timer. Sounds ugly but…
Thanks again,
Iñigo Serna
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 20:17 ` Iñigo Serna
@ 2016-03-18 22:07 ` raman
0 siblings, 0 replies; 14+ messages in thread
From: raman @ 2016-03-18 22:07 UTC (permalink / raw)
To: Iñigo Serna; +Cc: Clément Pit--Claudel, emacs-devel
Iñigo Serna <inigoserna@gmail.com> writes:
Like you I too asserted that the idle-timer solution was "ugly" before I
swallowed my pride and implemented it --- then got surprized that it
worked well. You should be able to clone the code I pointed you at in
the soundscapes.el module -- look at function soundscape-update.> Clément Pit--Claudel <clement.pit@gmail.com> writes:
>
>> Great, glad I could help :)
>
> In my case, problem is aggravated as I use "perspective" package and
> persp-mode activates each buffer when switching perspective.
> As I see, it happens in `persp-reactivate-buffers' function to put
> the buffers in current perspective on top of visited list.
>
> But this should not occur with plain emacs.
>
> Anyway, as the solution is not perfect and I'm learning I will look at
> Raman's & Stefan's suggestion of using an idle timer. Sounds ugly but…
>
> Thanks again,
> Iñigo Serna
>
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 11:04 Advicing select-windows, shr rendering, and per-buffer-theme package Iñigo Serna
2016-03-18 13:38 ` Clément Pit--Claudel
2016-03-18 13:40 ` Clément Pit--Claudel
@ 2016-03-18 13:55 ` raman
2016-03-18 15:21 ` Stefan Monnier
2 siblings, 1 reply; 14+ messages in thread
From: raman @ 2016-03-18 13:55 UTC (permalink / raw)
To: Iñigo Serna; +Cc: emacs-devel
See thread I had on this list re hooking sound themes based on current
mode -- I ran into this issue as well. As far as I know, it's more than
just shr/eww that triggers this: if you look, select-window gets called
way more often than you'd expect.
After suggestions from folks like John, I ended up implementing my
solution via an idle timer, you can see the relevant code here:
https://github.com/tvraman/emacspeak/blob/master/lisp/soundscape.el#L191
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 13:55 ` raman
@ 2016-03-18 15:21 ` Stefan Monnier
2016-03-18 16:28 ` raman
2016-03-18 17:04 ` Iñigo Serna
0 siblings, 2 replies; 14+ messages in thread
From: Stefan Monnier @ 2016-03-18 15:21 UTC (permalink / raw)
To: emacs-devel
> See thread I had on this list re hooking sound themes based on current
> mode -- I ran into this issue as well. As far as I know, it's more than
> just shr/eww that triggers this: if you look, select-window gets called
> way more often than you'd expect.
Indeed, `current-buffer' and `selected-window' don't correspond really
to the user's perception, because they can be changed temporarily
without the user even noticing (and it's not just a theoretical
possibility but is something that happens often enough).
> After suggestions from folks like John, I ended up implementing my
> solution via an idle timer, you can see the relevant code here:
Sounds like a better option, indeed.
Stefan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 15:21 ` Stefan Monnier
@ 2016-03-18 16:28 ` raman
2016-03-18 16:47 ` Stefan Monnier
2016-03-18 22:13 ` Iñigo Serna
2016-03-18 17:04 ` Iñigo Serna
1 sibling, 2 replies; 14+ messages in thread
From: raman @ 2016-03-18 16:28 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Hi Stefan,
Yes, the idle-timer solution worked surprisingly well which at least to
me was counter-intuitive --- guess I dont understand Emacs' internals
well enough. So what is it that led folk like yourself and John to
intuitively suggest idle timers for this case?
Incidentally the documentation for
buffer-list-update-hook is fairly misleading. I originally tried using
that hook and saw it firing way too often; then adviced select-window
and observed that that fired almost as often which was still too often.
Places where the afore-mentioned hook fires where you wouldn't expect it
to bsed on the doc-string:
A. While transitioning through the minibuffer
B. When you have completions come and go as you interact with the
minibuffer
C. shr/eww as the earlier poster pointed out
D. and many more cases that will fit this margin.
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 16:28 ` raman
@ 2016-03-18 16:47 ` Stefan Monnier
2016-03-18 22:13 ` Iñigo Serna
1 sibling, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2016-03-18 16:47 UTC (permalink / raw)
To: raman; +Cc: emacs-devel
> well enough. So what is it that led folk like yourself and John to
> intuitively suggest idle timers for this case?
Actually, I would have suggested post-command-hook, but if you want to
do it a bit more lazily (e.g. not react to changes within
a keyboard-macro, for example), then an idle hook is the next
logical step.
The main issue is that you want to deal with "the user-perceived
changes", rather than actual detailed changes, and the user only
perceives changes when a redisplay occurs or between commands.
Stefan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 16:28 ` raman
2016-03-18 16:47 ` Stefan Monnier
@ 2016-03-18 22:13 ` Iñigo Serna
2016-03-18 22:48 ` raman
1 sibling, 1 reply; 14+ messages in thread
From: Iñigo Serna @ 2016-03-18 22:13 UTC (permalink / raw)
To: raman; +Cc: Stefan Monnier, emacs-devel
Hello,
raman <raman@google.com> writes:
> Yes, the idle-timer solution worked surprisingly well which at least to
> me was counter-intuitive --- guess I dont understand Emacs' internals
> well enough. So what is it that led folk like yourself and John to
> intuitively suggest idle timers for this case?
I've been experimenting with idle-timer and I must agree, it is very
easy to implement and works *surprisingly* well.
Even so, that I've left it as the default method to check buffer and
theme in my package.
> Places where the afore-mentioned hook fires where you wouldn't expect it
> to bsed on the doc-string:
>
> A. While transitioning through the minibuffer
>
> B. When you have completions come and go as you interact with the
> minibuffer
>
> C. shr/eww as the earlier poster pointed out
>
> D. and many more cases that will fit this margin.
In my case, C was the main headache when switching to eww/shr-based
buffers. Looks like 25.x shr use lots of temporary buffers for its
rendering tasks.
Then A and B (using helm here) causes some "flickering" with
select-window advicing method too.
As I've mentioned in other email, perspective package also aggravated
what I saw.
Thanks again to all for your help and suggestions,
Iñigo Serna
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 22:13 ` Iñigo Serna
@ 2016-03-18 22:48 ` raman
0 siblings, 0 replies; 14+ messages in thread
From: raman @ 2016-03-18 22:48 UTC (permalink / raw)
To: Iñigo Serna; +Cc: Stefan Monnier, emacs-devel
Iñigo Serna <inigoserna@gmail.com> writes:
In emacs 25, EWW renders buffers asynchronously so that emacs doesn't
lock up while a web page is opening. That necessarily causes a lot of
context switches.> Hello,
>
> raman <raman@google.com> writes:
>
>> Yes, the idle-timer solution worked surprisingly well which at least to
>> me was counter-intuitive --- guess I dont understand Emacs' internals
>> well enough. So what is it that led folk like yourself and John to
>> intuitively suggest idle timers for this case?
>
> I've been experimenting with idle-timer and I must agree, it is very
> easy to implement and works *surprisingly* well.
> Even so, that I've left it as the default method to check buffer and
> theme in my package.
>
>> Places where the afore-mentioned hook fires where you wouldn't expect it
>> to bsed on the doc-string:
>>
>> A. While transitioning through the minibuffer
>>
>> B. When you have completions come and go as you interact with the
>> minibuffer
>>
>> C. shr/eww as the earlier poster pointed out
>>
>> D. and many more cases that will fit this margin.
>
> In my case, C was the main headache when switching to eww/shr-based
> buffers. Looks like 25.x shr use lots of temporary buffers for its
> rendering tasks.
>
> Then A and B (using helm here) causes some "flickering" with
> select-window advicing method too.
> As I've mentioned in other email, perspective package also aggravated
> what I saw.
>
> Thanks again to all for your help and suggestions,
> Iñigo Serna
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Advicing select-windows, shr rendering, and per-buffer-theme package
2016-03-18 15:21 ` Stefan Monnier
2016-03-18 16:28 ` raman
@ 2016-03-18 17:04 ` Iñigo Serna
1 sibling, 0 replies; 14+ messages in thread
From: Iñigo Serna @ 2016-03-18 17:04 UTC (permalink / raw)
To: Stefan Monnier, raman; +Cc: emacs-devel
Hi,
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Indeed, `current-buffer' and `selected-window' don't correspond really
> to the user's perception, because they can be changed temporarily
> without the user even noticing (and it's not just a theoretical
> possibility but is something that happens often enough).
I noticed this when I started writing this package and was investigating
the best way to achieve it, experimenting with different alternatives
(hooks, advice, etc).
raman <raman@google.com> writes:
> See thread I had on this list re hooking sound themes based on current
> mode -- I ran into this issue as well. As far as I know, it's more than
> just shr/eww that triggers this: if you look, select-window gets called
> way more often than you'd expect.
>
> After suggestions from folks like John, I ended up implementing my
> solution via an idle timer, you can see the relevant code here:
> https://github.com/tvraman/emacspeak/blob/master/lisp/soundscape.el#L191
The ideas Clément provided where enough to solve the problems I
have. Not perfect but good enough for my case.
Anyway, I'll search for that thread you mention and read it to look for
better ideas.
Thanks for the suggestions,
Iñigo Serna
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2016-03-18 22:48 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 11:04 Advicing select-windows, shr rendering, and per-buffer-theme package Iñigo Serna
2016-03-18 13:38 ` Clément Pit--Claudel
2016-03-18 13:40 ` Clément Pit--Claudel
2016-03-18 16:45 ` Iñigo Serna
2016-03-18 17:45 ` Clément Pit--Claudel
2016-03-18 20:17 ` Iñigo Serna
2016-03-18 22:07 ` raman
2016-03-18 13:55 ` raman
2016-03-18 15:21 ` Stefan Monnier
2016-03-18 16:28 ` raman
2016-03-18 16:47 ` Stefan Monnier
2016-03-18 22:13 ` Iñigo Serna
2016-03-18 22:48 ` raman
2016-03-18 17:04 ` Iñigo Serna
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).