Browse Source

org-src.el (org-edit-src-turn-on-auto-save): New option

* org-src.el (org-edit-src-turn-on-auto-save): New option.
(org-edit-src-code): Use it.
(org-edit-src-auto-save-idle-delay): Enhance docstring.

* doc/org.texi (Editing source code): Document
`org-edit-src-auto-save-idle-delay' and

Thanks to Charles C. Berry for bringing this up again.
Bastien Guerry 8 years ago
2 changed files with 27 additions and 7 deletions
  1. 9 4
  2. 18 3

+ 9 - 4

@@ -13465,11 +13465,16 @@ Source code in the specified language.
 @cindex code block, editing
 @cindex source code, editing
+@vindex org-edit-src-auto-save-idle-delay
+@vindex org-edit-src-turn-on-auto-save
 @kindex C-c '
-Use @kbd{C-c '} to edit the current code block.  This brings up
-a language major-mode edit buffer containing the body of the code
-block.  Saving this buffer will write the new contents back to the Org
-buffer.  Use @kbd{C-c '} again to exit.
+Use @kbd{C-c '} to edit the current code block.  This brings up a language
+major-mode edit buffer containing the body of the code block.  Manually
+saving this buffer with @key{C-x C-s} will write the contents back to the Org
+buffer.  You can also set @var{org-edit-src-auto-save-idle-delay} to save the
+base buffer after some idle delay, or @code{org-edit-src-turn-on-auto-save}
+to auto-save this buffer into a separate file using @code{auto-save-mode}.
+Use @kbd{C-c '} again to exit.
 The @code{org-src-mode} minor mode will be active in the edit buffer.  The
 following variables can be used to configure the behavior of the edit

+ 18 - 3

@@ -64,10 +64,25 @@ there are kept outside the narrowed region."
 		   (const :tag "from `lang' element")
 		   (const :tag "from `style' element")))))
+(defcustom org-edit-src-turn-on-auto-save nil
+  "Non-nil means turn `auto-save-mode' on when editing a source block.
+This will save the content of the source code editing buffer into
+a newly created file, not the base buffer for this source block.
+If you want to regularily save the base buffer instead of the source
+code editing buffer, see `org-edit-src-auto-save-idle-delay' instead."
+  :group 'org-edit-structure
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type 'boolean)
 (defcustom org-edit-src-auto-save-idle-delay 0
-  "Delay of idle time before auto-saving src code buffers.
+  "Delay before saving a source code buffer back into its base buffer.
 When a positive integer N, save after N seconds of idle time.
-When 0 (the default), don't auto-save."
+When 0 (the default), don't auto-save.
+If you want to save the source code buffer itself, don't use this.
+Check `org-edit-src-turn-on-auto-save' instead."
   :group 'org-edit-structure
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -351,7 +366,7 @@ the display of windows containing the Org buffer and the code buffer."
 	(set-buffer-modified-p nil)
 	(setq buffer-file-name nil)
-	(when auto-save-default
+	(when org-edit-src-turn-on-auto-save
 	  (setq buffer-auto-save-file-name
 		(concat (make-temp-name "org-src-")
 			(format-time-string "-%Y-%d-%m") ".txt")))