all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Run `window-configuration-change-hook` in Lisp code?
@ 2024-11-06 19:40 Joost Kremers
  2024-11-07  4:47 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2024-11-06 19:40 UTC (permalink / raw)
  To: gnu-emacs-help

Hi list,

Something that just came up: is it OK to run
`window-configuration-change-hook` in Lisp code? The doc string says
"Functions called during redisplay when window configuration has changed",
which gives me the impression that it's *only* meant to be run during
redisplay, i.e., not during Lisp code.

Is that a correct assumption? TIA

-- 
Joost Kremers
Life has its moments



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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-06 19:40 Run `window-configuration-change-hook` in Lisp code? Joost Kremers
@ 2024-11-07  4:47 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-11-07  5:35   ` James Cherti
  2024-11-07  7:24   ` Eli Zaretskii
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-11-07  4:47 UTC (permalink / raw)
  To: help-gnu-emacs

> Something that just came up: is it OK to run
> `window-configuration-change-hook` in Lisp code? The doc string says
> "Functions called during redisplay when window configuration has changed",
> which gives me the impression that it's *only* meant to be run during
> redisplay, i.e., not during Lisp code.

That description describes when the C code runs this hook.
Do you want to run this hook yourself manually at other times?
If so, why?


        Stefan




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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-07  4:47 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-11-07  5:35   ` James Cherti
  2024-11-08 14:12     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-11-07  7:24   ` Eli Zaretskii
  1 sibling, 1 reply; 10+ messages in thread
From: James Cherti @ 2024-11-07  5:35 UTC (permalink / raw)
  To: help-gnu-emacs

Hello Stefan,

Here is a summary of an email I sent to emacs-devel (Subject: Should 
text-scale trigger hooks?): I have identified an issue that affects 
Emacs packages such as eat (terminal) and visual-fill-column. Functions 
like `text-scale-increase`, `text-scale-decrease`, and `text-scale-set` 
do not trigger hooks like `window-configuration-change-hook`. As a 
result, the eat package does not immediately update the window when the 
text scale is changed, and visual-fill-column does not update the margin 
right away (it updates only after the window is resized).

The workaround to fix this issue is to call the following after the text 
scale is changed:
(run-hooks 'window-configuration-change-hook)

OP wants to know whether it is good practice or bad practice to run the 
`window-configuration-change-hook` hooks from a third-party package in 
this situation, as a workaround to resolve the issue described above. 
(Check: https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ).

--
James Cherti
https://www.jamescherti.com/

On 2024-11-06 23:47, Stefan Monnier via Users list for the GNU Emacs 
text editor wrote:
>> Something that just came up: is it OK to run
>> `window-configuration-change-hook` in Lisp code? The doc string says
>> "Functions called during redisplay when window configuration has changed",
>> which gives me the impression that it's *only* meant to be run during
>> redisplay, i.e., not during Lisp code.
> 
> That description describes when the C code runs this hook.
> Do you want to run this hook yourself manually at other times?
> If so, why?
> 
> 
>          Stefan
> 
> 



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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-07  4:47 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-11-07  5:35   ` James Cherti
@ 2024-11-07  7:24   ` Eli Zaretskii
  2024-11-07  8:01     ` Joost Kremers
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-11-07  7:24 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 06 Nov 2024 23:47:02 -0500
> From:  Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> > Something that just came up: is it OK to run
> > `window-configuration-change-hook` in Lisp code? The doc string says
> > "Functions called during redisplay when window configuration has changed",
> > which gives me the impression that it's *only* meant to be run during
> > redisplay, i.e., not during Lisp code.
> 
> That description describes when the C code runs this hook.
> Do you want to run this hook yourself manually at other times?
> If so, why?

Indeed, the idea is that whatever a Lisp program does, it eventually
causes the display engine to make changes which trigger calls to this
hook.  So if that doesn't happen for some Lisp program, we need to
understand what that program does, and why it expects this hook to be
called.



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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-07  7:24   ` Eli Zaretskii
@ 2024-11-07  8:01     ` Joost Kremers
  0 siblings, 0 replies; 10+ messages in thread
From: Joost Kremers @ 2024-11-07  8:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Hi Stefan & Eli,

On Thu, Nov 07 2024, Eli Zaretskii wrote:
>> Date: Wed, 06 Nov 2024 23:47:02 -0500
>> From: Stefan Monnier via Users list for the GNU Emacs text editor
>> <help-gnu-emacs@gnu.org>
>> 
>> > Something that just came up: is it OK to run
>> > `window-configuration-change-hook` in Lisp code? The doc string says
>> > "Functions called during redisplay when window configuration has
>> > changed",
>> > which gives me the impression that it's *only* meant to be run during
>> > redisplay, i.e., not during Lisp code.
>> 
>> That description describes when the C code runs this hook.
>> Do you want to run this hook yourself manually at other times?
>> If so, why?
>
> Indeed, the idea is that whatever a Lisp program does, it eventually
> causes the display engine to make changes which trigger calls to this
> hook.  So if that doesn't happen for some Lisp program, we need to
> understand what that program does, and why it expects this hook to be
> called.

I asked this question in relation to the issue that James Cherti posted
about on emacs-devel
<https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00208.html>.
Perhaps we should continue the discussion there.

-- 
Joost Kremers
Life has its moments



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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-07  5:35   ` James Cherti
@ 2024-11-08 14:12     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-11-08 14:55       ` Joost Kremers
  2024-11-08 15:51       ` James Cherti
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-11-08 14:12 UTC (permalink / raw)
  To: help-gnu-emacs

> The workaround to fix this issue is to call the following after the text
> scale is changed (run-hooks 'window-configuration-change-hook)

From where?

The way I see it, another workaround is for those packages which depend
strongly on such single-size monospace text to add the relevant function
to `text-scale-mode-hook`.

> OP wants to know whether it is good practice or bad practice to run the
> `window-configuration-change-hook` hooks from a third-party package in this
> situation, as a workaround to resolve the issue described above. (Check:
> https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ).

I'd put it in the bad practice column (especially since that hook
is documented to be run in a fairly special way which `run-hooks`
doesn't follow).

Then again, looking at that patch I can't understand why it would work.
Does it work?  If so how?  That code is run only when `visual-fill-mode`
is enabled, AFAICT, so whether it runs
`window-configuration-change-hook` won't make any difference when
text-scale is used.


        Stefan




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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-08 14:12     ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-11-08 14:55       ` Joost Kremers
  2024-11-08 17:55         ` Stefan Monnier
  2024-11-08 15:51       ` James Cherti
  1 sibling, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2024-11-08 14:55 UTC (permalink / raw)
  To: Stefan Monnier via Users list for the GNU Emacs text editor
  Cc: Stefan Monnier

On Fri, Nov 08 2024, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> Then again, looking at that patch I can't understand why it would work.
> Does it work?  If so how?  That code is run only when `visual-fill-mode`
> is enabled, AFAICT,

Yes, but that's the point. When `visual-fill-column-mode` is active, a
change in text size should trigger a recalculation of the window margins by
`visual-fill-column-mode`.

Eli made two suggestions (`text-scale-mode-hook` and `add-variable-watcher`
on `face-remap-alist`). I'll give them a try as soon as I find some time.

-- 
Joost Kremers
Life has its moments



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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-08 14:12     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-11-08 14:55       ` Joost Kremers
@ 2024-11-08 15:51       ` James Cherti
  2024-11-08 17:47         ` [External] : " Drew Adams
  1 sibling, 1 reply; 10+ messages in thread
From: James Cherti @ 2024-11-08 15:51 UTC (permalink / raw)
  To: help-gnu-emacs

Thank you for confirming that you would place it in the
'bad practices' column.

Yes, the patch works; however, I closed the pull request as
it was too specific to another package I'm using, which restores
persisted text scale through a hook in
`window-configuration-change-hook`.

In the general case, however, the need to run
window-configuration-change-hook during text-scale-mode-hook
is not particularly important.

--
James Cherti
https://www.jamescherti.com/

On 2024-11-08 09:12, Stefan Monnier via Users list for the GNU Emacs 
text editor wrote:
>> The workaround to fix this issue is to call the following after the text
>> scale is changed (run-hooks 'window-configuration-change-hook)
> 
>>From where?
> 
> The way I see it, another workaround is for those packages which depend
> strongly on such single-size monospace text to add the relevant function
> to `text-scale-mode-hook`.
> 
>> OP wants to know whether it is good practice or bad practice to run the
>> `window-configuration-change-hook` hooks from a third-party package in this
>> situation, as a workaround to resolve the issue described above. (Check:
>> https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ).
> 
> I'd put it in the bad practice column (especially since that hook
> is documented to be run in a fairly special way which `run-hooks`
> doesn't follow).
> 
> Then again, looking at that patch I can't understand why it would work.
> Does it work?  If so how?  That code is run only when `visual-fill-mode`
> is enabled, AFAICT, so whether it runs
> `window-configuration-change-hook` won't make any difference when
> text-scale is used.
> 
> 
>          Stefan
> 
> 



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

* RE: [External] : Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-08 15:51       ` James Cherti
@ 2024-11-08 17:47         ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2024-11-08 17:47 UTC (permalink / raw)
  To: James Cherti, help-gnu-emacs@gnu.org

Coming late to this thread, and with nothing
special to say about the specific trigger/hook
question.

But with something to offer perhaps for the
original/underlying request of allowing a buffer
in `visual-line-mode' to have its window change
size to accommodate text scaling, i.e., keep the
same visual-fill position.

IOW, maybe think of the current discussion as
possibly an X-Y question: you have an idea of
what a solution to your original question might
be, so you ask a question about that (trigger).

If I've misunderstood something, then please
ignore...
___

I brought up the original question decades ago,
as soon as text-scaling was added to Emacs.
Not wrt visual-line-mode, in particular (that
didn't exist back then), but generally.

I suggested that users should be able to
choose whether the window gets automatically
scaled in conjunction with text scaling, i.e.,
as an optional behavior.

For one thing, this saves horizontal screen
space when text is shrunk - wasted blank window
space at line ends.

This was roundly rejected by Eli at the time,
IIRC, saying that no one would ever want such
behavior.

So I implemented it in a little library,
`face-remap+.el' (back in 2009).  I wouldn't
be without it.

It works with and without `visual-line-mode'.
It really has _nothing to do with
`visual-line-mode'_: the question/request is
only about keeping the relation between the
text size and the window size.  It just so
happens that with `visual-line-mode' lines
are visually fit to the window width.


The behavior is controlled by option
`text-scale-resize-window':

text-scale-resize-window is a variable defined in `face-remap+.el’.

Non-nil means text scaling resizes the window or frame accordingly.
For example, if you use ‘C-x C--’ (‘text-scale-decrease’)’ to make the
text smaller, then the window or frame is made smaller by a similar
factor.
___

You can choose to resize the window horizontally
only, vertically only, both, or neither (off).

(There's also a global minor mode,
`text-scale-keep-mode', which when on keeps the
same text-scaling when a buffer changes major mode.
If off, you get the vanilla Emacs behavior that
text-scaling is lost when the major mode changes.)
___

Apologetically, `face-remap+.el' redefines vanilla
function `text-scale-increase', to respect option
`text-scale-resize-window'.

I'd still suggest that such an option be added to
vanilla Emacs, FWIW.  (Better late than never...)
___

https://www.emacswiki.org/emacs/download/face-remap%2b.el


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

* Re: Run `window-configuration-change-hook` in Lisp code?
  2024-11-08 14:55       ` Joost Kremers
@ 2024-11-08 17:55         ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2024-11-08 17:55 UTC (permalink / raw)
  To: Joost Kremers; +Cc: Stefan Monnier via Users list for the GNU Emacs text editor

>> Then again, looking at that patch I can't understand why it would work.
>> Does it work?  If so how?  That code is run only when `visual-fill-mode`
>> is enabled, AFAICT,
> Yes, but that's the point. When `visual-fill-column-mode` is active, a
> change in text size should trigger a recalculation of the window margins by
> `visual-fill-column-mode`.

But the code is not run when the mode is active but when the mode is
being activated.  So I don't see how the patch helps: the previous code
already called the relevant function in that case, AFAICT the new code
just runs it N times redundantly (by running the N hooks on which we
register that same function).


        Stefan




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

end of thread, other threads:[~2024-11-08 17:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 19:40 Run `window-configuration-change-hook` in Lisp code? Joost Kremers
2024-11-07  4:47 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-11-07  5:35   ` James Cherti
2024-11-08 14:12     ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-11-08 14:55       ` Joost Kremers
2024-11-08 17:55         ` Stefan Monnier
2024-11-08 15:51       ` James Cherti
2024-11-08 17:47         ` [External] : " Drew Adams
2024-11-07  7:24   ` Eli Zaretskii
2024-11-07  8:01     ` 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.