[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Should write-contents-functions be permanent-local?
From: |
Joseph Turner |
Subject: |
Re: Should write-contents-functions be permanent-local? |
Date: |
Tue, 15 Aug 2023 18:48:51 -0700 |
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Joseph Turner <joseph@breatheoutbreathe.in>
>> Date: Mon, 14 Aug 2023 23:35:44 -0700
>>
>> WDYT about making write-contents-functions permanent-local?
>
> That cannot be done, sorry. Some modes set this to mode-specific
> values, you can find this even in the Emacs source tree. But even
> without those examples, a variable that were not permanent-local for
> so long cannot be suddenly made permanent-local, because it will
> almost certainly break something somewhere.
Thank you for the explanation!
> In any case, if you are okay with making the variable permanent-local,
> then why not just
>
> (put 'write-contents-functions 'permanent-local t)
>
> in your package, and be done with it? The effect of the above is the
> same global effect as if we would do that by default in Emacs, right?
I was concerned that would break things. (whereas I thought if we made
the change in Emacs, we'd have a chance to ensure that it did not.)
Probably best not to change things - our current solution seems to work:
(defun hyperdrive--hack-write-contents-functions ()
(cl-pushnew #'hyperdrive--write-contents write-contents-functions))
(put 'hyperdrive--hack-write-contents-functions 'permanent-local-hook t)
(define-minor-mode hyperdrive-mode
"Minor mode for buffers opened from hyperdrives."
(if hyperdrive-mode
(progn
(cl-pushnew #'hyperdrive--write-contents write-contents-functions)
(add-hook 'after-change-major-mode-hook
#'hyperdrive--hack-write-contents-functions nil 'local))
(setq-local write-contents-functions
(remove #'hyperdrive--write-contents write-contents-functions))
(remove-hook 'after-change-major-mode-hook
#'hyperdrive--hack-write-contents-functions 'local)))