> I tried your snippet, but it does not work. The problem is that
> `org-edit-src-save' calls `save-buffer' on the source (org) buffer, not the
> edit buffer, and `org-edit-src-exit' does not call it at all in any buffer,
> but only writes the edit buffer's content into the org buffer. Of course, I
> can fix it by advising these functions, but maybe it would make semantic
> sense to run `before-save-hook' in the edit buffer?
My bad, I did not take that into account. Try the following snippet instead:
#+begin_src elisp :tangle yes
;; this function must be interactive
(defun my-maybe-call-macrostep-collapse-all ()
(interactive)
(when (or (string-match-p (regexp-quote "emacs-lisp")
(buffer-name))
(string-match-p (regexp-quote "elisp")
(buffer-name)))
(macrostep-collapse-all)
(org-edit-src-save)))
(defun my-bind-maybe-call-macrostep-collapse-all ()
(keymap-set org-src-mode-map "C-x C-s"
'my-maybe-call-macrostep-collapse-all))
(add-hook 'org-src-mode-hook #'my-bind-maybe-call-macrostep-collapse-all 100)
#+end_src
Admittedly, this is a little complicated. I overrode the local "C-x
C-s" by adding #'my-bind-maybe-call-macrostep-collapse-all to the
'org-src-mode-hook. You would also need to duplicate this for "\C-c'"
'org-edit-src-exit. And of course, this solution only works when you
use the keybindings. So, yeah I think a patch would actually be a
great idea. In this case, I believe that the proper solution would be
to create `org-src-edit-save-hook'. Then, this is all you would need
to do:
;; example patch
(defun org-edit-src-save ()
"Save parent buffer with current state source-code buffer."
(interactive)
(unless (org-src-edit-buffer-p) (user-error "Not in a sub-editing buffer"))
+ (run-hooks 'org-src-edit-save-hook)
(set-buffer-modified-p nil)
(let ((write-back-buf (generate-new-buffer "*org-src-write-back*"))