> It has happened multiple times to me that I edit an Emacs lisp snippet with
> org-edit-special and in the edit buffer have expanded a macro with macrostep
> [1]. If I then save the edit buffer, it writes the expanded macro back into
> the org src block, because macrostep replaces the text in the buffer. Today,
> I wanted to fix that by putting `macrostep-collapse-all' into
> `before-save-hook' or some equivalent for org-src-mode. However, after
> studying the code, no equivalent seems to exist today. Would it make sense to
> add one? Should `org-src-edit-save' and `org-src-edit-save' call
> `before-save-hook'? Or should there be a `org-src-edit-save-hook' or similar?
>
> [1] https://github.com/emacsorphanage/macrostep
>
> Best,
> Marten
I could see an argument for a specific before-save-hook for
org-edit-special. But currently, a solution can already be found for
your problem using the before-save-hook:
#+begin_src elisp
(defun my-maybe-call-macrostep-collapse-all ()
(when (and (org-src-edit-buffer-p)
(string-match-p (regexp-quote "emacs-lisp")
(buffer-name)))
(macrostep-collapse-all)))
(add-hook 'before-save-hook #'my-maybe-call-macrostep-collapse-all)
#+end_src