When doing literate programming in , I frequently use C-c '[aka M-x org-edit-special] to enter the source-block-edit-buffer, so that I have appropriate s etc.

I then accidentally save this buffer with :w, and end up with files like
Network.org[*Org Src Network.org[ graphviz-dot ]*] littering my folder.

How can I avoid saving these files? Ideally, I would want the attempt to save the source-block-edit-buffer trigger saving the "parent" org file.

Edit: I now realize after the answer from @lawlist, that I was not having this problem every-time I save. Only, when I was using the :w ex mode command, not with C-x C-s. I use both, depending which is easier in context to type. I always thought this was equivalent, so I did not mention it when I first submitted the question. Sorry, since this sightly shifts the topic of the question.

  • As for research: I have been reading around some on this site, and think, the answer should be some kind of function I add to a "save"-hook, which then derives the filename of the parent, and then triggers a save there Feb 24, 2018 at 14:26

1 Answer 1


There is already a built-in default keyboard shortcut to save edits (made in the editing buffer) to the parent buffer; i.e., C-x C-s -- which calls org-edit-src-save.

There are many ways to handle the issue described in the original question above. This answer overrides the global keyboard shortcut for save-buffer by remapping it to the org-src-mode-map which is an active minor-mode keyboard shortcut map in the editing buffer by virtue of the org-src-mode minor-mode. [Instead of 'hello-world, the O.P. could use 'ignore to have a silent approach with the same effect.]

(defun hello-world ()
  (message "You have remapped `save-buffer'."))

(require 'org-src)
(define-key org-src-mode-map [remap save-buffer] 'hello-world)
  • +1, thank you for the effort. After your answer, I realized, my question was imprecise. Evil is involved, and only :w has the problem, not C-x C-s. I updated the question. I am currently looking if your answer helps me understand the new scenario. Please mark this comment obsolete once you've read it. Feb 25, 2018 at 20:22
  • 1
    I am unfamiliar with the Evil package, sorry. I'll leave the answer for now in the event that it inspires you and/or someone else who may be interested in taking advantage of the org-src-mode-map to override other key bindings. The concept is essentially to disable the keyboard shortcut that you accidentally hit, and/or remap it to a different function that you would prefer be executed instead.
    – lawlist
    Feb 25, 2018 at 20:26
  • OK, I think I understand. I will look for "1) Find the name of the current evil mode keymap of the org-src-mode-buffer. 2) find the function evil calls on :w. 3) in the org-src-mode-buffer hook it to call org-edit-src-save instead". This sounds doable, but I would still be glad, if one of the veterans could accelerate the process :) Feb 25, 2018 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.