|
@@ -240,6 +240,12 @@ issued in the language major mode buffer."
|
|
(defvar org-src--preserve-indentation nil)
|
|
(defvar org-src--preserve-indentation nil)
|
|
(defvar org-src--remote nil)
|
|
(defvar org-src--remote nil)
|
|
(defvar org-src--saved-temp-window-config nil)
|
|
(defvar org-src--saved-temp-window-config nil)
|
|
|
|
+(defvar org-src--source-type nil
|
|
|
|
+ "Type of element being edited, as a symbol.")
|
|
|
|
+(defvar org-src--tab-width nil
|
|
|
|
+ "Contains `tab-width' value from Org source buffer.
|
|
|
|
+However, if `indent-tabs-mode' is nil in that buffer, its value
|
|
|
|
+is 0.")
|
|
|
|
|
|
(defun org-src--construct-edit-buffer-name (org-buffer-name lang)
|
|
(defun org-src--construct-edit-buffer-name (org-buffer-name lang)
|
|
"Construct the buffer name for a source editing buffer."
|
|
"Construct the buffer name for a source editing buffer."
|
|
@@ -387,20 +393,34 @@ spaces after it as being outside."
|
|
(defun org-src--contents-for-write-back ()
|
|
(defun org-src--contents-for-write-back ()
|
|
"Return buffer contents in a format appropriate for write back.
|
|
"Return buffer contents in a format appropriate for write back.
|
|
Assume point is in the corresponding edit buffer."
|
|
Assume point is in the corresponding edit buffer."
|
|
- (let ((indentation (or org-src--block-indentation 0))
|
|
|
|
- (preserve-indentation org-src--preserve-indentation)
|
|
|
|
|
|
+ (let ((indentation-offset
|
|
|
|
+ (if org-src--preserve-indentation 0
|
|
|
|
+ (+ (or org-src--block-indentation 0)
|
|
|
|
+ (if (memq org-src--source-type '(example-block src-block))
|
|
|
|
+ org-edit-src-content-indentation
|
|
|
|
+ 0))))
|
|
|
|
+ (use-tabs? (and (> org-src--tab-width 0) t))
|
|
|
|
+ (source-tab-width org-src--tab-width)
|
|
(contents (org-with-wide-buffer (buffer-string)))
|
|
(contents (org-with-wide-buffer (buffer-string)))
|
|
(write-back org-src--allow-write-back))
|
|
(write-back org-src--allow-write-back))
|
|
(with-temp-buffer
|
|
(with-temp-buffer
|
|
|
|
+ ;; Reproduce indentation parameters from source buffer.
|
|
|
|
+ (setq-local indent-tabs-mode use-tabs?)
|
|
|
|
+ (when (> source-tab-width 0) (setq-local tab-width source-tab-width))
|
|
|
|
+ ;; Apply WRITE-BACK function on edit buffer contents.
|
|
(insert (org-no-properties contents))
|
|
(insert (org-no-properties contents))
|
|
(goto-char (point-min))
|
|
(goto-char (point-min))
|
|
- (when (functionp write-back) (funcall write-back))
|
|
|
|
- (unless (or preserve-indentation (= indentation 0))
|
|
|
|
- (let ((ind (make-string indentation ?\s)))
|
|
|
|
- (goto-char (point-min))
|
|
|
|
- (while (not (eobp))
|
|
|
|
- (when (looking-at-p "[ \t]*\\S-") (insert ind))
|
|
|
|
- (forward-line))))
|
|
|
|
|
|
+ (when (functionp write-back) (save-excursion (funcall write-back)))
|
|
|
|
+ ;; Add INDENTATION-OFFSET to every non-empty line in buffer,
|
|
|
|
+ ;; unless indentation is meant to be preserved.
|
|
|
|
+ (when (> indentation-offset 0)
|
|
|
|
+ (while (not (eobp))
|
|
|
|
+ (skip-chars-forward " \t")
|
|
|
|
+ (unless (eolp) ;ignore blank lines
|
|
|
|
+ (let ((i (current-column)))
|
|
|
|
+ (delete-region (line-beginning-position) (point))
|
|
|
|
+ (indent-to (+ i indentation-offset))))
|
|
|
|
+ (forward-line)))
|
|
(buffer-string))))
|
|
(buffer-string))))
|
|
|
|
|
|
(defun org-src--edit-element
|
|
(defun org-src--edit-element
|
|
@@ -438,6 +458,7 @@ Leave point in edit buffer."
|
|
(with-current-buffer old-edit-buffer (org-src--remove-overlay))
|
|
(with-current-buffer old-edit-buffer (org-src--remove-overlay))
|
|
(kill-buffer old-edit-buffer))
|
|
(kill-buffer old-edit-buffer))
|
|
(let* ((org-mode-p (derived-mode-p 'org-mode))
|
|
(let* ((org-mode-p (derived-mode-p 'org-mode))
|
|
|
|
+ (source-tab-width (if indent-tabs-mode tab-width 0))
|
|
(type (org-element-type datum))
|
|
(type (org-element-type datum))
|
|
(ind (org-with-wide-buffer
|
|
(ind (org-with-wide-buffer
|
|
(goto-char (org-element-property :begin datum))
|
|
(goto-char (org-element-property :begin datum))
|
|
@@ -477,10 +498,12 @@ Leave point in edit buffer."
|
|
;; Transmit buffer-local variables for exit function. It must
|
|
;; Transmit buffer-local variables for exit function. It must
|
|
;; be done after initializing major mode, as this operation
|
|
;; be done after initializing major mode, as this operation
|
|
;; may reset them otherwise.
|
|
;; may reset them otherwise.
|
|
|
|
+ (setq-local org-src--tab-width source-tab-width)
|
|
(setq-local org-src--from-org-mode org-mode-p)
|
|
(setq-local org-src--from-org-mode org-mode-p)
|
|
(setq-local org-src--beg-marker beg)
|
|
(setq-local org-src--beg-marker beg)
|
|
(setq-local org-src--end-marker end)
|
|
(setq-local org-src--end-marker end)
|
|
(setq-local org-src--remote remote)
|
|
(setq-local org-src--remote remote)
|
|
|
|
+ (setq-local org-src--source-type type)
|
|
(setq-local org-src--block-indentation ind)
|
|
(setq-local org-src--block-indentation ind)
|
|
(setq-local org-src--preserve-indentation preserve-ind)
|
|
(setq-local org-src--preserve-indentation preserve-ind)
|
|
(setq-local org-src--overlay overlay)
|
|
(setq-local org-src--overlay overlay)
|
|
@@ -917,16 +940,7 @@ name of the sub-editing buffer."
|
|
(org-src--construct-edit-buffer-name (buffer-name) lang))
|
|
(org-src--construct-edit-buffer-name (buffer-name) lang))
|
|
lang-f
|
|
lang-f
|
|
(and (null code)
|
|
(and (null code)
|
|
- `(lambda ()
|
|
|
|
- (unless ,(or org-src-preserve-indentation
|
|
|
|
- (org-element-property :preserve-indent element))
|
|
|
|
- (when (> org-edit-src-content-indentation 0)
|
|
|
|
- (while (not (eobp))
|
|
|
|
- (unless (looking-at "[ \t]*$")
|
|
|
|
- (indent-line-to (+ (org-get-indentation)
|
|
|
|
- org-edit-src-content-indentation)))
|
|
|
|
- (forward-line))))
|
|
|
|
- (org-escape-code-in-region (point-min) (point-max))))
|
|
|
|
|
|
+ (lambda () (org-escape-code-in-region (point-min) (point-max))))
|
|
(and code (org-unescape-code-in-string code)))
|
|
(and code (org-unescape-code-in-string code)))
|
|
;; Finalize buffer.
|
|
;; Finalize buffer.
|
|
(setq-local org-coderef-label-format
|
|
(setq-local org-coderef-label-format
|