Merge branch 'maint'

This commit is contained in:
Bastien 2021-05-16 14:11:08 +02:00
commit e738211f73
1 changed files with 15 additions and 8 deletions

View File

@ -433,7 +433,7 @@ spaces after it as being outside."
(point)))))) (point))))))
(defun org-src--contents-for-write-back (write-back-buf) (defun org-src--contents-for-write-back (write-back-buf)
"Populate write-back-buf with contents in a format appropriate for write back. "Populate WRITE-BACK-BUF with contents in the appropriate format.
Assume point is in the corresponding edit buffer." Assume point is in the corresponding edit buffer."
(let ((indentation-offset (let ((indentation-offset
(if org-src--preserve-indentation 0 (if org-src--preserve-indentation 0
@ -1218,38 +1218,45 @@ Throw an error if there is no such buffer."
(defun org-edit-src-exit () (defun org-edit-src-exit ()
"Kill current sub-editing buffer and return to source buffer." "Kill current sub-editing buffer and return to source buffer."
(interactive) (interactive)
(unless (org-src-edit-buffer-p) (error "Not in a sub-editing buffer")) (unless (org-src-edit-buffer-p)
(error "Not in a sub-editing buffer"))
(let* ((beg org-src--beg-marker) (let* ((beg org-src--beg-marker)
(end org-src--end-marker) (end org-src--end-marker)
(write-back org-src--allow-write-back) (write-back org-src--allow-write-back)
(remote org-src--remote) (remote org-src--remote)
(coordinates (and (not remote) (coordinates (and (not remote)
(org-src--coordinates (point) 1 (point-max)))) (org-src--coordinates (point) 1 (point-max))))
(write-back-buf (and write-back (generate-new-buffer "*org-src-write-back*")))) (write-back-buf
(and write-back (generate-new-buffer "*org-src-write-back*"))))
(when write-back (org-src--contents-for-write-back write-back-buf)) (when write-back (org-src--contents-for-write-back write-back-buf))
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
;; Switch to source buffer. Kill sub-editing buffer. ;; Switch to source buffer. Kill sub-editing buffer.
(let ((edit-buffer (current-buffer)) (let ((edit-buffer (current-buffer))
(source-buffer (marker-buffer beg))) (source-buffer (marker-buffer beg)))
(unless source-buffer (error "Source buffer disappeared. Aborting")) (unless source-buffer
(when write-back-buf (kill-buffer write-back-buf))
(error "Source buffer disappeared. Aborting"))
(org-src-switch-to-buffer source-buffer 'exit) (org-src-switch-to-buffer source-buffer 'exit)
(kill-buffer edit-buffer)) (kill-buffer edit-buffer))
;; Insert modified code. Ensure it ends with a newline character. ;; Insert modified code. Ensure it ends with a newline character.
(org-with-wide-buffer (org-with-wide-buffer
(when (and write-back (not (equal (buffer-substring beg end) (when (and write-back
(with-current-buffer write-back-buf (buffer-string))))) (not (equal (buffer-substring beg end)
(with-current-buffer write-back-buf
(buffer-string)))))
(undo-boundary) (undo-boundary)
(goto-char beg) (goto-char beg)
(let ((expecting-bol (bolp))) (let ((expecting-bol (bolp)))
(if (version< emacs-version "26.1") (if (version< emacs-version "26.1")
(progn (delete-region beg end) (progn (delete-region beg end)
(insert (with-current-buffer write-back-buf (buffer-string)))) (insert (with-current-buffer write-back-buf
(buffer-string))))
(save-restriction (save-restriction
(narrow-to-region beg end) (narrow-to-region beg end)
(replace-buffer-contents write-back-buf) (replace-buffer-contents write-back-buf)
(goto-char (point-max)))) (goto-char (point-max))))
(when (and expecting-bol (not (bolp))) (insert "\n"))) (when (and expecting-bol (not (bolp))) (insert "\n")))
(kill-buffer write-back-buf))) (when write-back-buf (kill-buffer write-back-buf))))
;; If we are to return to source buffer, put point at an ;; If we are to return to source buffer, put point at an
;; appropriate location. In particular, if block is hidden, move ;; appropriate location. In particular, if block is hidden, move
;; to the beginning of the block opening line. ;; to the beginning of the block opening line.