aboutsummaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.emacs.d/lisp/my/my-org.el26
1 files changed, 17 insertions, 9 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el
index 03b34ff..38eca7b 100644
--- a/emacs/.emacs.d/lisp/my/my-org.el
+++ b/emacs/.emacs.d/lisp/my/my-org.el
@@ -75,9 +75,14 @@ With a prefix, insert inactive dates.
(when (eq major-mode 'mhtml-mode)
(browse-url-of-buffer)))
+(defvar my-org-edit-src-was-live-window nil
+ "Set to non-nil by `my-org-edit-src-before-exit' if the edit src
+buffer was a live window.")
+
(defun my-org-edit-src-before-exit ()
"A :before advice for org-edit-src-exit."
- (delete-trailing-whitespace))
+ (delete-trailing-whitespace)
+ (setq my-org-edit-src-was-live-window (get-buffer-window (current-buffer))))
(defun my-org-element-block-p (element)
"Returns t if ELEMENT is an org block."
@@ -87,17 +92,20 @@ With a prefix, insert inactive dates.
special-block src-block verse-block)))
(defun my-org-edit-src-after-exit ()
- "An :after advice for org-edit-src-exit.
+ "An :after advice for `org-edit-src-exit'.
If the block is empty, remove it.
Otherwise deactivate mark and move point to after the block."
- (deactivate-mark)
- (let ((element (org-element-at-point)))
- (cl-assert (my-org-element-block-p element))
- (if (string-empty-p (org-element-property :value element))
- (delete-region (org-element-property :begin element)
- (org-element-property :end element))
- (goto-char (org-element-property :end element)))))
+ ;; Only proceed if buffer is in a live window, needed to avoid
+ ;; indenting triggering this function
+ (when my-org-edit-src-was-live-window
+ (deactivate-mark)
+ (let ((element (org-element-at-point)))
+ (cl-assert (my-org-element-block-p element))
+ (if (string-empty-p (org-element-property :value element))
+ (delete-region (org-element-property :begin element)
+ (org-element-property :end element))
+ (goto-char (org-element-property :end element))))))
;; navigation
(defun my-org-jump-to-last-visible-child ()