Parcourir la source

org-element: Do not alter indentation upon parsing

* lisp/org-element.el (org-element-src-block-parser):
(org-element-example-block-parser): Do not remove any indentation when
  parsing the element.
* testing/lisp/test-org-element.el (test-org-element/src-block-parser):
* testing/lisp/test-org-element.el (test-org-element/src-block-parser):
  Update test.

Properly handling indentation requires knowing about
`org-src-preserve-indentation''s value.  This is out of the scope of the
parser.
Nicolas Goaziou il y a 9 ans
Parent
commit
111905ff84
2 fichiers modifiés avec 7 ajouts et 40 suppressions
  1. 7 14
      lisp/org-element.el
  2. 0 26
      testing/lisp/test-org-element.el

+ 7 - 14
lisp/org-element.el

@@ -1900,13 +1900,10 @@ containing `:begin', `:end', `:number-lines', `:preserve-indent',
 		 ;; Standard block parsing.
 		 (begin (car affiliated))
 		 (post-affiliated (point))
-		 (block-ind (progn (skip-chars-forward " \t") (current-column)))
-		 (contents-begin (progn (forward-line) (point)))
-		 (value (org-remove-indentation
-			 (org-unescape-code-in-string
-			  (buffer-substring-no-properties
-			   contents-begin contents-end))
-			 block-ind))
+		 (contents-begin (line-beginning-position 2))
+		 (value (org-unescape-code-in-string
+			 (buffer-substring-no-properties
+			  contents-begin contents-end)))
 		 (pos-before-blank (progn (goto-char contents-end)
 					  (forward-line)
 					  (point)))
@@ -2406,14 +2403,10 @@ Assume point is at the beginning of the block."
 		  (or (not switches)
 		      (and retain-labels
 			   (not (string-match "-k\\>" switches)))))
-		 ;; Indentation.
-		 (block-ind (progn (skip-chars-forward " \t") (current-column)))
 		 ;; Retrieve code.
-		 (value (org-remove-indentation
-			 (org-unescape-code-in-string
-			  (buffer-substring-no-properties
-			   (progn (forward-line) (point)) contents-end))
-			 block-ind))
+		 (value (org-unescape-code-in-string
+			 (buffer-substring-no-properties
+			  (line-beginning-position 2) contents-end)))
 		 (pos-before-blank (progn (goto-char contents-end)
 					  (forward-line)
 					  (point)))

+ 0 - 26
testing/lisp/test-org-element.el

@@ -699,19 +699,6 @@ Some other text
 	  (org-test-with-temp-text
 	      "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
 	    (org-element-property :value (org-element-at-point)))))
-  ;; Remove block indentation according to block boundaries, unless
-  ;; block contents are less indented than block boundaries.
-  (should
-   (equal " L1\nL2\n"
-	  (org-test-with-temp-text " #+BEGIN_EXAMPLE\n  L1\n L2\n #+END_EXAMPLE"
-	    (let ((org-src-preserve-indentation t))
-	      (org-element-property :value (org-element-at-point))))))
-  (should
-   (equal
-    "  L1\n L2\n"
-    (org-test-with-temp-text "  #+BEGIN_EXAMPLE\n  L1\n L2\n  #+END_EXAMPLE"
-      (let ((org-src-preserve-indentation t))
-	(org-element-property :value (org-element-at-point))))))
   ;; Handle non-empty blank line at the end of buffer.
   (should
    (org-test-with-temp-text "#+BEGIN_EXAMPLE\nC\n#+END_EXAMPLE\n "
@@ -2058,19 +2045,6 @@ Outside list"
 	  (org-test-with-temp-text
 	      "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
 	    (org-element-property :value (org-element-at-point)))))
-  ;; Remove block indentation according to block boundaries, unless
-  ;; block contents are less indented than block boundaries.
-  (should
-   (equal " L1\nL2\n"
-	  (org-test-with-temp-text " #+BEGIN_SRC org\n  L1\n L2\n #+END_SRC"
-	    (let ((org-src-preserve-indentation t))
-	      (org-element-property :value (org-element-at-point))))))
-  (should
-   (equal
-    "  L1\n L2\n"
-    (org-test-with-temp-text "  #+BEGIN_SRC org\n  L1\n L2\n  #+END_SRC"
-      (let ((org-src-preserve-indentation t))
-	(org-element-property :value (org-element-at-point))))))
   ;; Handle non-empty blank line at the end of buffer.
   (should
    (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\nC\n#+END_SRC\n "