* Should text-scale trigger hooks? @ 2024-11-07 1:17 James Cherti 2024-11-07 1:52 ` James Cherti ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: James Cherti @ 2024-11-07 1:17 UTC (permalink / raw) To: emacs-devel I've identified an issue that affects Emacs packages like eat (terminal) and visual-fill-column. The core problem is that functions such as text-scale-increase, text-scale-decrease, and text-scale-set do not trigger hooks such as window-configuration-change-hook. Because of that, eat does not instantly update the window when the text scale is changed and visual-fill-column does not update the margin until we resize the window. Currently, I've implemented workarounds for the eat package: (defun persist-text-scale-adjust-eat (&rest args) "Adjust the text scale of all eat buffers." (when (derived-mode-p 'eat-mode) (run-hooks 'window-configuration-change-hook))) (advice-add 'text-scale-increase :after #'persist-text-scale-adjust-eat) (advice-add 'text-scale-decrease :after #'persist-text-scale-adjust-eat) I've implemented a similar solution for visual-fill-column (see https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ), but the visual-fill-column maintainer thinks this is probably not the right solution to this problem. I tend to agree with him. While these workarounds work, I believe a more robust solution would be to have text-scale functions automatically trigger hooks such as window-configuration-change-hook, or perhaps introduce a dedicated hook for text scale that other plugins could utilize. This would provide a more maintainable solution and prevent the need for individual package-specific workarounds. -- James Cherti https://www.jamescherti.com/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 1:17 Should text-scale trigger hooks? James Cherti @ 2024-11-07 1:52 ` James Cherti 2024-11-07 6:55 ` Eli Zaretskii 2024-11-07 8:10 ` Joost Kremers 2 siblings, 0 replies; 9+ messages in thread From: James Cherti @ 2024-11-07 1:52 UTC (permalink / raw) To: emacs-devel Update: I just realized that text-scale-mode-hook can be utilized instead of advice because text-scale-* functions call text-scale-mode each time the text scale is changed. (defun persist-text-scale-adjust-eat () "Adjust the text scale of all ediff buffers." (when (derived-mode-p 'eat-mode) (run-hooks 'window-configuration-change-hook))) (defun persist-text-scale-adjust-visual-fill-column () "Adjust the text scale of all ediff buffers." (when (bound-and-true-p visual-fill-column-mode) (run-hooks 'window-configuration-change-hook))) (add-hook 'text-scale-mode-hook #'persist-text-scale-adjust-eat) (add-hook 'text-scale-mode-hook #'persist-text-scale-adjust-visual-fill-column) -- James Cherti https://www.jamescherti.com/ On 2024-11-06 20:17, James Cherti wrote: > I've identified an issue that affects Emacs packages like eat (terminal) > and visual-fill-column. > > The core problem is that functions such as text-scale-increase, > text-scale-decrease, and text-scale-set do not trigger hooks such as > window-configuration-change-hook. Because of that, eat does not > instantly update the window when the text scale is changed and > visual-fill-column does not update the margin until we resize the window. > > Currently, I've implemented workarounds for the eat package: > (defun persist-text-scale-adjust-eat (&rest args) > "Adjust the text scale of all eat buffers." > (when (derived-mode-p 'eat-mode) > (run-hooks 'window-configuration-change-hook))) > (advice-add 'text-scale-increase :after #'persist-text-scale-adjust-eat) > (advice-add 'text-scale-decrease :after #'persist-text-scale-adjust-eat) > > I've implemented a similar solution for visual-fill-column (see > https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ), but the > visual-fill-column maintainer thinks this is probably not the right > solution to this problem. I tend to agree with him. > > While these workarounds work, I believe a more robust solution would be > to have text-scale functions automatically trigger hooks such as > window-configuration-change-hook, or perhaps introduce a dedicated hook > for text scale that other plugins could utilize. > > This would provide a more maintainable solution and prevent the need for > individual package-specific workarounds. > > -- > James Cherti > https://www.jamescherti.com/ > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 1:17 Should text-scale trigger hooks? James Cherti 2024-11-07 1:52 ` James Cherti @ 2024-11-07 6:55 ` Eli Zaretskii 2024-11-07 8:21 ` Joost Kremers 2024-11-07 8:10 ` Joost Kremers 2 siblings, 1 reply; 9+ messages in thread From: Eli Zaretskii @ 2024-11-07 6:55 UTC (permalink / raw) To: James Cherti; +Cc: emacs-devel > Date: Wed, 6 Nov 2024 20:17:50 -0500 > From: James Cherti <contact@jamescherti.com> > > I've identified an issue that affects Emacs packages like eat (terminal) > and visual-fill-column. > > The core problem is that functions such as text-scale-increase, > text-scale-decrease, and text-scale-set do not trigger hooks such as > window-configuration-change-hook. Because of that, eat does not > instantly update the window when the text scale is changed and > visual-fill-column does not update the margin until we resize the window. There's a huge gape between invocation of text-scale-increase and our need that window-configuration-change-hook should be run. I cannot cross that gap, so please explain the relation between these two, and in particular why you need that hook to run and not some other mechanism. The functions which manipulate face-remapping-alist force redisplay of the buffer in which the alist was changed, and from Emacs display POV this is the only thing that should happen to make sure the affected buffer's display is redrawn. Please explain why buffer's redisplay is not enough for the packages you mention to do their job. OTOH, window-configuration-change-hook is for specific events, documented thusly: -- Variable: window-configuration-change-hook This variable specifies functions called during redisplay when either the buffer or the size of a window has changed. text-scale-increase/decrease don't fit this description, so expecting that hook to be called in those cases is wrong, and asking Emacs to run that hook is against the documented behavior of the hook. So if redisplaying a buffer somehow cannot allow these packages to do their job (but please explain in detail why), we will have to think about some different mechanism of doing that; window-configuration-change-hook doesn't sound like the right tool for this. > While these workarounds work, I believe a more robust solution would be > to have text-scale functions automatically trigger hooks such as > window-configuration-change-hook, or perhaps introduce a dedicated hook > for text scale that other plugins could utilize. As you have discovered, there's already such a hook. Does it mean that your problems are solved? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 6:55 ` Eli Zaretskii @ 2024-11-07 8:21 ` Joost Kremers 2024-11-07 8:58 ` Eli Zaretskii 0 siblings, 1 reply; 9+ messages in thread From: Joost Kremers @ 2024-11-07 8:21 UTC (permalink / raw) To: Eli Zaretskii; +Cc: James Cherti, emacs-devel On Thu, Nov 07 2024, Eli Zaretskii wrote: > The functions which manipulate face-remapping-alist force redisplay of > the buffer in which the alist was changed, and from Emacs display POV > this is the only thing that should happen to make sure the affected > buffer's display is redrawn. Please explain why buffer's redisplay is > not enough for the packages you mention to do their job. Speaking for `visual-fill-column`: it's a package that adjusts the text margins in wide windows. The goal is to have buffers that use visual-line-mode wrap text at `fill-column`, not at the window's edge. If the window configuration or size changes, the width of the margins needs to be recalculated, so the package puts a function on the relevant hooks to do that. If the text size is changed, the window margins also need to be recalculated, but this does not happen automatically. The README of `visual-fill-column` suggests to advise the function `text-scale-adjust` to solve this (see https://codeberg.org/joostkremers/visual-fill-column#adjusting-text-size), but it's an ad hoc solution, of course. -- Joost Kremers Life has its moments ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 8:21 ` Joost Kremers @ 2024-11-07 8:58 ` Eli Zaretskii 2024-11-07 9:42 ` Joost Kremers 0 siblings, 1 reply; 9+ messages in thread From: Eli Zaretskii @ 2024-11-07 8:58 UTC (permalink / raw) To: Joost Kremers; +Cc: contact, emacs-devel > From: Joost Kremers <joostkremers@fastmail.fm> > Cc: James Cherti <contact@jamescherti.com>, emacs-devel@gnu.org > Date: Thu, 07 Nov 2024 09:21:01 +0100 > > On Thu, Nov 07 2024, Eli Zaretskii wrote: > > The functions which manipulate face-remapping-alist force redisplay of > > the buffer in which the alist was changed, and from Emacs display POV > > this is the only thing that should happen to make sure the affected > > buffer's display is redrawn. Please explain why buffer's redisplay is > > not enough for the packages you mention to do their job. > > Speaking for `visual-fill-column`: it's a package that adjusts the text > margins in wide windows. The goal is to have buffers that use > visual-line-mode wrap text at `fill-column`, not at the window's edge. If > the window configuration or size changes, the width of the margins needs to > be recalculated, so the package puts a function on the relevant hooks to do > that. The need for adjusting the margins in this case is specific to how the visual-fill-column package uses the margins, it is not a general need. In general, whether the margins need to be adjusted according to text scale depends on what are margins used for; they can be used for more than just showing text of the same default face. This is why Emacs doesn't automatically resize the margins in this case. > If the text size is changed, the window margins also need to be > recalculated, but this does not happen automatically. The README of > `visual-fill-column` suggests to advise the function > `text-scale-adjust` to solve this (see > https://codeberg.org/joostkremers/visual-fill-column#adjusting-text-size), > but it's an ad hoc solution, of course. What are the problems of using text-scale-mode-hook? Or even using add-variable-watcher to cause Emacs call your function when face-remapping-alist changes? IOW, why do you think this is a core Emacs issue, not an issue with how visual-fill-column is implemented? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 8:58 ` Eli Zaretskii @ 2024-11-07 9:42 ` Joost Kremers 2024-11-07 14:16 ` James Cherti 0 siblings, 1 reply; 9+ messages in thread From: Joost Kremers @ 2024-11-07 9:42 UTC (permalink / raw) To: Eli Zaretskii; +Cc: contact, emacs-devel On Thu, Nov 07 2024, Eli Zaretskii wrote: > The need for adjusting the margins in this case is specific to how the > visual-fill-column package uses the margins, it is not a general need. Yes, true. > What are the problems of using text-scale-mode-hook? Or even using > add-variable-watcher to cause Emacs call your function when > face-remapping-alist changes? I haven't actually tried those methods, since I rarely use text-scale-adjust and James's is the first user request I received about it in a long time. > IOW, why do you think this is a core Emacs issue, not an issue with > how visual-fill-column is implemented? Reading your message, I'm not sure that it is. But I guess this is also a question for James. -- Joost Kremers Life has its moments ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 9:42 ` Joost Kremers @ 2024-11-07 14:16 ` James Cherti 2024-11-08 17:47 ` [External] : " Drew Adams 0 siblings, 1 reply; 9+ messages in thread From: James Cherti @ 2024-11-07 14:16 UTC (permalink / raw) To: Joost Kremers, Eli Zaretskii; +Cc: emacs-devel I tested adding a function to `text-scale-mode-hook` that executes: (run-hooks 'window-configuration-change-hook) And it solved the issue in both packages (`eat` and `visual-fill-column`). After further consideration, I believe that this is not an Emacs core issue, but rather a problem caused by the implementation of those packages. It doesn't make sense for text scaling to run the window-configuration-change-hook functions. -- James Cherti https://www.jamescherti.com/ On 2024-11-07 04:42, Joost Kremers wrote: > On Thu, Nov 07 2024, Eli Zaretskii wrote: >> The need for adjusting the margins in this case is specific to how the >> visual-fill-column package uses the margins, it is not a general need. > > Yes, true. > >> What are the problems of using text-scale-mode-hook? Or even using >> add-variable-watcher to cause Emacs call your function when >> face-remapping-alist changes? > > I haven't actually tried those methods, since I rarely use > text-scale-adjust and James's is the first user request I received about it > in a long time. > >> IOW, why do you think this is a core Emacs issue, not an issue with >> how visual-fill-column is implemented? > > Reading your message, I'm not sure that it is. But I guess this is also a > question for James. > ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [External] : Re: Should text-scale trigger hooks? 2024-11-07 14:16 ` James Cherti @ 2024-11-08 17:47 ` Drew Adams 0 siblings, 0 replies; 9+ messages in thread From: Drew Adams @ 2024-11-08 17:47 UTC (permalink / raw) To: James Cherti, Joost Kremers, Eli Zaretskii; +Cc: emacs-devel@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] 9+ messages in thread
* Re: Should text-scale trigger hooks? 2024-11-07 1:17 Should text-scale trigger hooks? James Cherti 2024-11-07 1:52 ` James Cherti 2024-11-07 6:55 ` Eli Zaretskii @ 2024-11-07 8:10 ` Joost Kremers 2 siblings, 0 replies; 9+ messages in thread From: Joost Kremers @ 2024-11-07 8:10 UTC (permalink / raw) To: James Cherti; +Cc: emacs-devel On Wed, Nov 06 2024, James Cherti wrote: > I've implemented a similar solution for visual-fill-column (see > https://codeberg.org/joostkremers/visual-fill-column/pulls/16 ), but the > visual-fill-column maintainer thinks this is probably not the right > solution to this problem. I tend to agree with him. To be precise, for that solution to work, the function that has to run `window-configuration-change-hook` is itself in that hook. Even though it seemed to work, it doesn't seem like the right solution. -- Joost Kremers Life has its moments ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-11-08 17:47 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-11-07 1:17 Should text-scale trigger hooks? James Cherti 2024-11-07 1:52 ` James Cherti 2024-11-07 6:55 ` Eli Zaretskii 2024-11-07 8:21 ` Joost Kremers 2024-11-07 8:58 ` Eli Zaretskii 2024-11-07 9:42 ` Joost Kremers 2024-11-07 14:16 ` James Cherti 2024-11-08 17:47 ` [External] : " Drew Adams 2024-11-07 8:10 ` Joost Kremers
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).