Browse Source

org-src: Clear overlay in Org buffer after major mode change

* lisp/org-src.el (org-src--allow-write-back):
(org-src--auto-save-timer):
(org-src--babel-info):
(org-src--beg-marker):
(org-src--block-indentation):
(org-src--end-marker):
(org-src--from-org-mode):
(org-src--overlay):
(org-src--preserve-indentation):
(org-src--remote):
(org-src--saved-temp-window-config):
(org-src--source-type):
(org-src--tab-width): Define as local and permanent variable.

(org-src--edit-element):
(org-edit-src-code):
(org-edit-inline-src-code): Use `setq' instead of `setq-local'.

When major mode is changed in an edit buffer, the variables above
would be cleared and the overlay in the source buffer could not be
removed anymore.
Nicolas Goaziou 1 year ago
parent
commit
631c4b703e
1 changed files with 51 additions and 26 deletions
  1. 51 26
      lisp/org-src.el

+ 51 - 26
lisp/org-src.el

@@ -229,23 +229,48 @@ issued in the language major mode buffer."
 
 ;;; Internal functions and variables
 
-(defvar org-src--allow-write-back t)
-(defvar org-src--auto-save-timer nil)
-(defvar org-src--babel-info nil)
-(defvar org-src--beg-marker nil)
-(defvar org-src--block-indentation nil)
-(defvar org-src--end-marker nil)
-(defvar org-src--from-org-mode nil)
-(defvar org-src--overlay nil)
-(defvar org-src--preserve-indentation nil)
-(defvar org-src--remote nil)
-(defvar org-src--saved-temp-window-config nil)
-(defvar org-src--source-type nil
+(defvar-local org-src--allow-write-back t)
+(put 'org-src--allow-write-back 'permanent-local t)
+
+(defvar-local org-src--auto-save-timer nil)
+(put 'org-src--auto-save-timer 'permanent-local t)
+
+(defvar-local org-src--babel-info nil)
+(put 'org-src--babel-info 'permanent-local t)
+
+(defvar-local org-src--beg-marker nil)
+(put 'org-src--beg-marker 'permanent-local t)
+
+(defvar-local org-src--block-indentation nil)
+(put 'org-src--block-indentation 'permanent-local t)
+
+(defvar-local org-src--end-marker nil)
+(put 'org-src--end-marker 'permanent-local t)
+
+(defvar-local org-src--from-org-mode nil)
+(put 'org-src--from-org-mode 'permanent-local t)
+
+(defvar-local org-src--overlay nil)
+(put 'org-src--overlay 'permanent-local t)
+
+(defvar-local org-src--preserve-indentation nil)
+(put 'org-src--preserve-indentation 'permanent-local t)
+
+(defvar-local org-src--remote nil)
+(put 'org-src--remote 'permanent-local t)
+
+(defvar-local org-src--saved-temp-window-config nil)
+(put 'org-src--saved-temp-window-config 'permanent-local t)
+
+(defvar-local org-src--source-type nil
   "Type of element being edited, as a symbol.")
-(defvar org-src--tab-width nil
+(put 'org-src--source-type 'permanent-local t)
+
+(defvar-local 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.")
+(put 'org-src--tab-width 'permanent-local t)
 
 (defun org-src--construct-edit-buffer-name (org-buffer-name lang)
   "Construct the buffer name for a source editing buffer."
@@ -498,16 +523,16 @@ Leave point in edit buffer."
 	;; Transmit buffer-local variables for exit function.  It must
 	;; be done after initializing major mode, as this operation
 	;; 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--beg-marker beg)
-	(setq-local org-src--end-marker end)
-	(setq-local org-src--remote remote)
-	(setq-local org-src--source-type type)
-	(setq-local org-src--block-indentation ind)
-	(setq-local org-src--preserve-indentation preserve-ind)
-	(setq-local org-src--overlay overlay)
-	(setq-local org-src--allow-write-back write-back)
+	(setq org-src--tab-width source-tab-width)
+	(setq org-src--from-org-mode org-mode-p)
+	(setq org-src--beg-marker beg)
+	(setq org-src--end-marker end)
+	(setq org-src--remote remote)
+	(setq org-src--source-type type)
+	(setq org-src--block-indentation ind)
+	(setq org-src--preserve-indentation preserve-ind)
+	(setq org-src--overlay overlay)
+	(setq org-src--allow-write-back write-back)
 	;; Start minor mode.
 	(org-src-mode)
 	;; Move mark and point in edit buffer to the corresponding
@@ -977,7 +1002,7 @@ name of the sub-editing buffer."
 		  (or (org-element-property :label-fmt element)
 		      org-coderef-label-format))
       (when (eq type 'src-block)
-	(setq-local org-src--babel-info babel-info)
+	(setq org-src--babel-info babel-info)
 	(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
 	  (when (fboundp edit-prep-func)
 	    (funcall edit-prep-func babel-info))))
@@ -1010,8 +1035,8 @@ name of the sub-editing buffer."
 	 (skip-chars-backward " \t")
 	 (delete-region (point) (point-max))))
       ;; Finalize buffer.
-      (setq-local org-src--babel-info babel-info)
-      (setq-local org-src--preserve-indentation t)
+      (setq org-src--babel-info babel-info)
+      (setq org-src--preserve-indentation t)
       (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
 	(when (fboundp edit-prep-func) (funcall edit-prep-func babel-info)))
       ;; Return success.