Browse Source

org-src: Unify source editing tools

* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
  org-edit-src-force-single-line, org-edit-src-picture,
  org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
  org-edit-src-beg-marker, org-edit-src-end-marker,
  org-edit-src-overlay, org-edit-src-block-indentation,
  org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
  Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.

(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.

(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables.  Change

* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
  Use new functions and variables.

* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.

This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...).  It introduces export block editing.  It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
Nicolas Goaziou 6 years ago
3 changed files with 545 additions and 541 deletions
  1. 4 7
  2. 539 529
  3. 2 5

+ 4 - 7

@@ -49,9 +49,8 @@
 (declare-function tramp-file-name-host "tramp" (vec))
 (declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body))
 (declare-function org-icompleting-read "org" (&rest args))
-(declare-function org-edit-src-code "org-src"
-                  (&optional context code edit-buffer-name quietp))
-(declare-function org-edit-src-exit "org-src"  (&optional context))
+(declare-function org-edit-src-code "org-src" (&optional code edit-buffer-name))
+(declare-function org-edit-src-exit "org-src"  ())
 (declare-function org-open-at-point "org" (&optional in-emacs reference-buffer))
 (declare-function org-save-outline-visibility "org-macs" (use-markers &rest body))
 (declare-function org-outline-overlay-data "org" (&optional use-markers))
@@ -777,8 +776,7 @@ arguments and pop open the results in a preview buffer."
 			      (funcall assignments-cmd params))))))
     (if (org-called-interactively-p 'any)
-	 nil expanded
-	 (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))
+	 expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))
 (defun org-babel-edit-distance (s1 s2)
@@ -994,8 +992,7 @@ Return t if a code block was found at point, nil otherwise."
      (when (and (org-babel-where-is-src-block-head)
        (unwind-protect (progn ,@body)
-	 (if (org-bound-and-true-p org-edit-src-from-org-mode)
-	     (org-edit-src-exit)))
+	 (org-edit-src-exit))
 (def-edebug-spec org-babel-do-in-edit-buffer (body))

File diff suppressed because it is too large
+ 539 - 529

+ 2 - 5

@@ -22745,8 +22745,7 @@ Also align node properties according to `org-property-format'."
 		      (goto-char (org-element-property :end element))
 		      (skip-chars-backward " \r\t\n")
-	     (let ((org-src-strip-leading-and-trailing-blank-lines nil))
-	       (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB"))))
+	     (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))
 	     (let ((column (org--get-expected-indentation element nil)))
 	       ;; Preserve current column.
@@ -22854,9 +22853,7 @@ assumed to be significant there."
 		     ;; `org-src-tab-acts-natively' is non-nil.
 		     (when (and (< (point) end) org-src-tab-acts-natively)
-			 (let (org-src-strip-leading-and-trailing-blank-lines
-			       ;; Region boundaries in edit buffer.
-			       (start (1+ (- (point) cbeg)))
+			 (let ((start (1+ (- (point) cbeg)))
 			       (end (- (min cend end) cbeg)))
 			    (indent-region start end))))))