Org writer: always indent src blocks content by 2 spaces

Emacs always uses two spaces when indenting the content of src blocks,
e.g., when exiting a `C-c '` edit-buffer. Pandoc used to indent contents
by the space-equivalent of one tab, but now always uses two spaces, too.

Closes: #5440
This commit is contained in:
Albert Krewinkel 2019-05-12 14:19:01 +02:00
parent 5c7ad59ffe
commit da9638e6a3
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
3 changed files with 27 additions and 29 deletions

View file

@ -169,8 +169,6 @@ blockToOrg (Header level attr inlines) = do
else cr <> nest (level + 1) (propertiesDrawer attr)
return $ headerStr <> " " <> contents <> drawerStr <> blankline
blockToOrg (CodeBlock (_,classes,kvs) str) = do
opts <- gets stOptions
let tabstop = writerTabStop opts
let startnum = maybe "" (\x -> ' ' : trimr x) $ lookup "startFrom" kvs
let numberlines = if "numberLines" `elem` classes
then if "continuedSourceBlock" `elem` classes
@ -181,7 +179,7 @@ blockToOrg (CodeBlock (_,classes,kvs) str) = do
let (beg, end) = case at of
[] -> ("#+BEGIN_EXAMPLE" ++ numberlines, "#+END_EXAMPLE")
(x:_) -> ("#+BEGIN_SRC " ++ x ++ numberlines, "#+END_SRC")
return $ text beg $$ nest tabstop (text str) $$ text end $$ blankline
return $ text beg $$ nest 2 (text str) $$ text end $$ blankline
blockToOrg (BlockQuote blocks) = do
contents <- blockListToOrg blocks
return $ blankline $$ "#+BEGIN_QUOTE" $$

View file

@ -7,19 +7,19 @@
unsafePerformIO main
^D
#+BEGIN_SRC haskell -n 42
main = putStrLn "Hello World!"
unsafePerformIO main
main = putStrLn "Hello World!"
unsafePerformIO main
#+END_SRC
```
```
% pandoc -f org -t native
#+BEGIN_SRC lisp -n 20
(+ 1 1)
(+ 1 1)
#+END_SRC
#+BEGIN_SRC lisp +n 10
(+ 2 2)
(+ 2 2)
#+END_SRC
^D
[CodeBlock ("",["commonlisp","numberLines"],[("org-language","lisp"),("startFrom","20")]) "(+ 1 1)\n"
@ -32,10 +32,10 @@
,CodeBlock ("",["commonlisp","numberLines","continuedSourceBlock"],[("org-language","lisp"),("startFrom","10")]) "(+ 2 2)\n"]
^D
#+BEGIN_SRC lisp -n 20
(+ 1 1)
(+ 1 1)
#+END_SRC
#+BEGIN_SRC lisp +n 10
(+ 2 2)
(+ 2 2)
#+END_SRC
```

View file

@ -92,9 +92,9 @@ E-mail style:
Code in a block quote:
#+BEGIN_EXAMPLE
sub status {
print "working";
}
sub status {
print "working";
}
#+END_EXAMPLE
A list:
@ -127,21 +127,21 @@ And a following paragraph.
Code:
#+BEGIN_EXAMPLE
---- (should be four hyphens)
---- (should be four hyphens)
sub status {
print "working";
}
sub status {
print "working";
}
this code block is indented by one tab
this code block is indented by one tab
#+END_EXAMPLE
And:
#+BEGIN_EXAMPLE
this code block is indented by two tabs
this code block is indented by two tabs
These should not be escaped: \$ \\ \> \[ \{
These should not be escaped: \$ \\ \> \[ \{
#+END_EXAMPLE
--------------
@ -364,7 +364,7 @@ Multiple blocks with italics:
- /orange/ :: orange fruit
#+BEGIN_EXAMPLE
{ orange code block }
{ orange code block }
#+END_EXAMPLE
#+BEGIN_QUOTE
@ -463,15 +463,15 @@ foo
This should be a code block, though:
#+BEGIN_EXAMPLE
<div>
foo
</div>
<div>
foo
</div>
#+END_EXAMPLE
As should this:
#+BEGIN_EXAMPLE
<div>foo</div>
<div>foo</div>
#+END_EXAMPLE
Now, nested:
@ -502,7 +502,7 @@ Multiline:
Code block:
#+BEGIN_EXAMPLE
<!-- Comment -->
<!-- Comment -->
#+END_EXAMPLE
Just plain comment, with trailing spaces on the line:
@ -514,7 +514,7 @@ Just plain comment, with trailing spaces on the line:
Code:
#+BEGIN_EXAMPLE
<hr />
<hr />
#+END_EXAMPLE
Hr's:
@ -751,7 +751,7 @@ Indented [[/url][thrice]].
This should [not][] be a link.
#+BEGIN_EXAMPLE
[not]: /url
[not]: /url
#+END_EXAMPLE
Foo [[/url/][bar]].
@ -792,7 +792,7 @@ An e-mail address: [[mailto:nobody@nowhere.net][nobody@nowhere.net]]
Auto-links should not occur here: =<http://example.com/>=
#+BEGIN_EXAMPLE
or here: <http://example.com/>
or here: <http://example.com/>
#+END_EXAMPLE
--------------
@ -837,7 +837,7 @@ This paragraph should not be part of the note, as it is not indented.
(as with list items).
#+BEGIN_EXAMPLE
{ <code> }
{ <code> }
#+END_EXAMPLE
If you want, you can indent every line, but you can also be lazy and