"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

Reply via email to