Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Emacs 29's clean-mode #27

Closed
josephmturner opened this issue Sep 3, 2023 · 6 comments
Closed

Add Emacs 29's clean-mode #27

josephmturner opened this issue Sep 3, 2023 · 6 comments

Comments

@josephmturner
Copy link
Contributor

The definition uses define-derived-mode, which has no direct correlate in compat-macs.el:

(define-derived-mode clean-mode fundamental-mode "Clean"
  "A mode that removes all overlays and text properties."
  (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)
    (setq-local yank-excluded-properties t)))

Would you use compat-defmacro or maybe compat-defun on the macro-expansion of define-derived-mode?

@minad
Copy link
Member

minad commented Sep 3, 2023

According to the Emacs 29 news:

** New major mode 'clean-mode'.
This is a new major mode meant for debugging.  It kills absolutely all
local variables and removes overlays and text properties.

The mode seems to be supposed to be triggered interactively for debugging only? We avoid to add interactive functionality in Compat, see https://elpa.gnu.org/packages/doc/compat.html#Limitations. So probably this mode is out of scope of Compat. Do you intend to use the mode programmatically in a package of yours? If yes, how do you use it?

@phikal
Copy link
Member

phikal commented Sep 3, 2023 via email

@minad
Copy link
Member

minad commented Sep 3, 2023

(@phikal We just wrote at the same time.)

@josephmturner I've found the relevant mail regarding your hyperdrive package: https://lists.gnu.org/archive/html/emacs-devel/2023-09/msg00300.html

(unless hyperdrive-mode
  ;; Remove overlays/text properties that might be in effect.
  (hyperdrive-clean-mode)
  (when hyperdrive-honor-auto-mode-alist
    (let ((buffer-file-name (hyperdrive-entry-name entry)))
      (set-auto-mode)))
  (hyperdrive-mode))

Maybe rewrite this without relying on clean-mode, since clean-mode may have other unintended side effects (hooks etc)? Also you first turn on clean-mode and then hyperdrive-mode, which seems like an uncommon pattern. I am really not sure about the intended usage of clean-mode. For your usage I'd imagine that a function clean-buffer-overlay-and-properties would be better, instead of the mode.

@josephmturner
Copy link
Contributor Author

josephmturner commented Sep 3, 2023

@phikal @minad Thanks for your feedback.

Good point about unintended side effects. For the time being, I'll add a function hyperdrive--clean-buffer-overlay-and-properties, and I'll suggest the addition of clean-buffer-overlay-and-properties on the emacs-devel ML.

@minad
Copy link
Member

minad commented Sep 3, 2023

You're welcome!

I'll suggest the addition of clean-buffer-overlay-and-properties on the emacs-devel ML.

Sure, proposing and discussing it makes sense. I am not sure if adding such a function is worth the costs. It could be that the given code pattern, which removes overlays and properties, is repeated multiple times across the Emacs code base. clean-mode itself doesn't appear to be used at all in Emacs 29, so I believe it is really only for interactive debugging in case you want to completely reset a buffer.

@josephmturner
Copy link
Contributor Author

I believe it is really only for interactive debugging in case you want to completely reset a buffer.

I agree, especially since clean-mode includes (setq-local yank-excluded-properties t) at the end.

zhscn pushed a commit to zhscn/nongnu that referenced this issue Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants