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

View file

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

View file

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