emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should text-scale trigger hooks?


From: James Cherti
Subject: Re: Should text-scale trigger hooks?
Date: Wed, 6 Nov 2024 20:52:56 -0500
User-agent: Mozilla Thunderbird

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]