jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.85k stars 3.34k forks source link

org writer: indentation in code blocks #5440

Closed jgm closed 2 years ago

jgm commented 5 years ago
% pandoc -t org

hi

^D
#+BEGIN_EXAMPLE
    hi
#+END_EXAMPLE

As far as I can see, the indentation here is completely unnecessary, and we could just emit

#+BEGIN_EXAMPLE
hi
#+END_EXAMPLE

@tarleb is that correct? Should this be changed?

tarleb commented 5 years ago

This is correct, the indentation is technically unnecessary. However, the standard way seems to be to indent with two spaces. That is also what emacs produces when editing a source block in a separate buffer, e.g. by pressing C-c ' while on a block. So maybe we should keep the indentation, but reduce it to two spaces?

jgm commented 5 years ago

Albert Krewinkel notifications@github.com writes:

This is correct, the indentation is technically unnecessary. However, the standard way seems to be to indent with two spaces. That is also what emacs produces when editing a source block in a separate buffer, e.g. by pressing C-c ' while on a block. So maybe we should keep the indentation, but reduce it to two spaces?

That would be fine with me. But I wonder why the two spaces? That makes copy-paste trickier.

gregoryg commented 5 years ago

@jgm It's common to execute an org-mode command that brings up the code block in its own buffer using the specified program language mode (C-c', or org-edit-special as mentioned by @tarleb ). In that buffer, the lines are no longer indented. Also, any org-mode command that exports will "do the right thing" for the export, which usually means losing the indentation.

jgm commented 5 years ago

OK, I'm fine with reducing indentation to 2 spaces, if that's the standard.

tarleb commented 5 years ago

I wonder why the two spaces?

I don't know, really. Seems inconsistent, as, e.g., contents of QUOTE blocks is not indented when hitting tab. Whether a line in a SRC block is indented when hitting tab depends, among others, on whether org-src-tab-acts-natively is non-nil. I fail to recognize an underlying concept for these behaviors.

alexalekseyenko commented 3 years ago

Would it make sense to put this behind an option? In practice, this convention may [hopefully] be on its way out:

xeruf commented 2 years ago

I agree, I never used these spaces. But there is another issue:

❯ printf '```sh\necho hi\n```' | pandoc -t org
#+begin_example
  echo hi
#+end_example

why is this an example block? I would expect (duh!) a source block:

#+begin_source sh
echo hi
#+end_source
jgm commented 2 years ago

I'm reopening this as a proposal that we remove the indentation. I haven't really heard anyone speak up in favor of it. It seems it's only a convention, and one that is fading. And of course, the two space indent creates problems with copy/paste.

As for example vs source, the writer uses example when no valid language is specified. sh is not a valid language. Here's the list of languages the writer recognizes -- I'm not sure where this came from, and it may be out of date. In that case, we can change it:

-- | List of language identifiers recognized by org-mode.              
orgLangIdentifiers :: [Text]       
orgLangIdentifiers =               
  [ "abc", "asymptote", "awk", "axiom", "C", "cpp", "calc", "clojure","comint"
  , "coq", "css", "D", "ditaa", "dot", "ebnf", "elixir", "eukleides", "fomus"
  , "forth", "F90", "gnuplot", "Translate", "groovy", "haskell" , "browser"
  , "request", "io", "ipython", "J", "java", "js", "julia", "kotlin", "latex"     , "ledger", "ly", "lisp", "Flavored", "makefile", "mathematica", "mathomatic"
  , "matlab", "max", "mongo", "mscgen", "cypher", "Caml", "octave" , "org", "oz"
  , "perl", "picolisp", "plantuml", "processing", "prolog", "python" , "R"
  , "rec", "ruby", "sass", "scala", "scheme", "screen", "sed", "shell", "shen"
  , "sql", "sqlite", "stan", "ML", "stata", "tcl", "typescript", "vala"
  ]    
jgm commented 2 years ago

I found this: https://orgmode.org/manual/Languages.html

asymptote
lisp
awk
lua
C
matlab
C++
mscgen
clojure
ocaml
css
octave
D
org
ditaa
oz
calc
perl
emacs-lisp
plantuml
eshell
processing
fortran
python
gnuplot
R
screen
ruby
dot
sass
haskell
scheme
java
sed
js
sh
latex
sql
ledger
sqlite
lilypond
vala

I'll update.

xeruf commented 2 years ago

thx :)