5

So, say I have a literate org file as follows:

#+TITLE: Random Scrap

* Do something
:PROPERTIES:
:tangle: scrap.pl
:comments: org
:END:

#+BEGIN_SRC perl
  sub my_func{
    my $var = pop;
#+END_SRC

some thoughts here..
and the func continues...
#+BEGIN_SRC perl
    my $var1 = $var+1;
 }
#+END_SRC

Tangling it to source using C-c C-v C-t gives me the following ugly code:

# Do something
# :PROPERTIES:
# :tangle: scrap.pl
# :comments: org
# :END:


sub my_func{
  my $var = pop;



# some thoughts here..
# and the func continues...


my $var1 = $var+1;
}

My questions are:

  1. Is there a simple way to preserve indentation across source blocks, when all of them are going to tangle to a single file?

  2. Is there a way to avoid the # :PROPERTIES: ... # :END: text to come to the header?

It would be great to have the first feature available. Org mode is a great tool for documenting source code. However, the wrong indentations put it off sometimes. At times, I break the code into fragments that indent properly. At other times, it is required to break code elsewhere, and causes issues like this.

Thanks in advance!

EDIT

(setq org-src-preserve-indentation t) solved my problem partially. The output tangled file now goes like:

# Do something
# :PROPERTIES:
# :tangle: scrap.pl
# :comments: org
# :END:


  sub my_func{
    my $var = pop;



# some thoughts here..
# and the func continues...


    my $var1 = $var+1;
  }

However, the comments are still out of indentation. Also, the responsibility of maintaining indentation now lies with me. And the header text is as is...

Any comments/answers? I feel this solution is a bit hacky...

3
  • Wanted to thank you for posting this, it clued me in to the problem I was having with indentation in source block output in HTML publishing.
    – EdwinW
    Commented Oct 12, 2017 at 19:08
  • I know that this might not be what you want to hear but, maybe you could refactor your code so that you don't need to write a paragraph of thoughts in the middle of the function code? I would consider that to be a "code smell"[1] telling me that I have to break up that function in more manageable parts. [1]: en.wikipedia.org/wiki/Code_smell
    – Martín
    Commented Feb 16, 2018 at 23:34
  • @Martín Agreed. That's what I eventually did. Thanks for the comment!
    – deejay
    Commented Feb 17, 2018 at 5:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.