> "Marten Lienen" <[email protected]> writes:
>
> > 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
>
> Hello Marten,
>
> I'm not certain what best practice is but would something like this
> work? It uses the 'org-src-mode-hook' to set a buffer local hook.
>
> #+begin_src elisp
> (add-hook
> 'org-src-mode-hook
> (lambda ()
> (when (derived-mode-p 'emacs-lisp-mode)
> (add-hook 'before-save-hook #'macrostep-collapse-all nil 'local))))
> #+end_src
>
> Morgan
>
@Morgan Smith
If you take a look at my first response, you will see that I already
shared basically the same snippet. Unfortunately, this idea doesn't
work. As Marten already pointed out, save is called in the original
buffer, not the src buffer. Check my second response for a workaround.