Browse Source

Respect buffer-local value of `org-edit-src-content-indentation'

* lisp/org-src.el (org-src--content-indentation): Introduce
permanently buffer-local variable for storing away the potentially
buffer-local value of `org-edit-src-content-indentation' in the source
buffer.

(org-src--contents-for-write-back): Use `org-src--content-indentation'
instead of `org-edit-src-content-indentation' in the edit buffer.

(org-src--edit-element): Set `org-src--content-indentation' in editing
buffer.  For greater clarity and consistency, rename already existing
let-bound variable `ind' to `block-ind'.

* etc/ORG-NEWS: Add entry.
Sebastian Miele 2 months ago
parent
commit
a8575e16e2
2 changed files with 14 additions and 5 deletions
  1. 4 0
      etc/ORG-NEWS
  2. 10 5
      lisp/org-src.el

+ 4 - 0
etc/ORG-NEWS

@@ -434,6 +434,10 @@ leave unfolded subtrees unfolded.
 I.e. treat the whole file as if it was a subtree.
 
 *** Respect narrowing when agenda command is restricted to buffer
+*** Respect buffer-local value of ~org-edit-src-content-indentation~
+
+Use the potentially buffer-local value of `org-edit-src-content-indentation'
+from the source buffer instead of that from the editing buffer.
 
 * Version 9.2
 ** Incompatible changes

+ 10 - 5
lisp/org-src.el

@@ -258,6 +258,9 @@ issued in the language major mode buffer."
 (defvar-local org-src--block-indentation nil)
 (put 'org-src--block-indentation 'permanent-local t)
 
+(defvar-local org-src--content-indentation nil)
+(put 'org-src--content-indentation 'permanent-local t)
+
 (defvar-local org-src--end-marker nil)
 (put 'org-src--end-marker 'permanent-local t)
 
@@ -422,7 +425,7 @@ Assume point is in the corresponding edit buffer."
 	 (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
+		  org-src--content-indentation
 		0))))
 	(use-tabs? (and (> org-src--tab-width 0) t))
 	(source-tab-width org-src--tab-width)
@@ -484,9 +487,10 @@ Leave point in edit buffer."
 	     (source-file-name (buffer-file-name (buffer-base-buffer)))
 	     (source-tab-width (if indent-tabs-mode tab-width 0))
 	     (type (org-element-type datum))
-	     (ind (org-with-wide-buffer
-		   (goto-char (org-element-property :begin datum))
-		   (current-indentation)))
+	     (block-ind (org-with-wide-buffer
+			 (goto-char (org-element-property :begin datum))
+			 (current-indentation)))
+	     (content-ind org-edit-src-content-indentation)
 	     (preserve-ind
 	      (and (memq type '(example-block src-block))
 		   (or (org-element-property :preserve-indent datum)
@@ -529,7 +533,8 @@ Leave point in edit buffer."
 	(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--block-indentation block-ind)
+	(setq org-src--content-indentation content-ind)
 	(setq org-src--preserve-indentation preserve-ind)
 	(setq org-src--overlay overlay)
 	(setq org-src--allow-write-back write-back)