emacs-devel
[Top][All Lists]
Advanced

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

Re: [IDEA] Add function clean-buffer


From: Joseph Turner
Subject: Re: [IDEA] Add function clean-buffer
Date: Tue, 05 Sep 2023 12:37:30 -0700

Philip Kaludercic <philipk@posteo.net> writes:

> Joseph Turner <joseph@breatheoutbreathe.in> writes:
>
>> Prompted by Daniel Mendler's comment here:
>>
>> https://github.com/emacs-compat/compat/issues/27#issuecomment-1704381157
>>
>> IIUC, clean-mode is intended for interactive, debugging usage.  I am
>> interested in a function that performs some of the internal behavior of
>> the Emacs 29 clean-mode in non-interactive use.  Note that
>> yank-excluded-properties is not set in clean-buffer.
>
> Perhaps you could explain what the concrete example is where you need
> the functionality?

In hyperdrive.el, when writing an existing buffer to a hyperdrive file,
we want to first remove overlays, text properties, and local variables,
and then use set-auto-mode to set the major mode (along with its
overlays, text properties, and local variable). The reason for doing
this is so that after writing a buffer to a file, users will see the
buffer as it will appear on another peer's machine.

For example, if you call hyperdrive-write-buffer on a magit log buffer,
we want the overlays to disappear so that users don't expect others to
be able to see the overlays when they load the file.

>> (defun clean-buffer (&optional buffer)
>>   "Remove all local variables, overlays, and text properties in BUFFER.
>> When BUFFER is nil, act on current buffer."
>>   (with-current-buffer (or buffer (current-buffer))
>>     (kill-all-local-variables t)
>>     (let ((inhibit-read-only t))
>>       (dolist (overlay (overlays-in (point-min) (point-max)))
>>         (delete-overlay overlay))
>>       (set-text-properties (point-min) (point-max) nil))))
>>
>> It could also be used internally in clean-mode.
>
> Could you prepare this as a patch?

See attached patches. I'm not sure if subr.el is the right place for
this change, and I haven't added added to the NEWS file.

Attachment: 0001-Add-new-function-clean-buffer.patch
Description: Text Data

Attachment: 0002-Refactor-clean-mode-to-use-clean-buffer.patch
Description: Text Data


reply via email to

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