1

Let's say I'm creating many babel code blocks in a growing org-mode buffer and I'm tangling them all to a single file. However, I want certain blocks to appear above others. For example,

#+begin_src haskell :eval never :exports code :tangle fp41.hs
module FP41 where
import Data.List
#+end_src

#+begin_src haskell :eval never :exports code :tangle fp41.hs
data Mood = Blah | Woot deriving (Show, Eq)

changeMood Blah = Woot
changeMood _ = Blah
#+end_src

This works wonderfully, but I always have to watch what order the blocks are int to avoid spaghetti code. So what if I want to add another import way down in the buffer

#+begin_src haskell :eval never :exports code :tangle fp41.hs
import GHC.Int
#+end_src

but not have it below regular code in the tangled file? That is, I want it going to the header block in the tangled code file fp41.hs, grouped/following the previous last import. I could tangle them to separate files -- one for "header" stuff, one for code. If that's the route, is there any way then to automate combining them into a single file?

2
  • 1
    I think they get tangled in sequence: I don't know of any way to change that. But I think you can use Noweb.
    – NickD
    Dec 23, 2021 at 0:55
  • As usual, thanks for the tip. noweb will work, although it requires my top source block containing the module info to refer to the desired named blocks below, i.e., the process isn't fire and forget.
    – 147pm
    Dec 23, 2021 at 4:06

1 Answer 1

1

There doesn't appear to be an exact solution, but the next-best thing would be something like this

* Test
:PROPERTIES:
:header-args: :noweb-sep "\n\n"
:END:

#+begin_src haskell :eval never :tangle nowebtest.hs :noweb yes
module FP41 where
import Data.List
<<ghcInt-imp>>
<<mood>>
#+end_src

#+name: mood
#+begin_src haskell :eval never

data Mood = Blah | Woot deriving (Show, Eq)

changeMood Blah = Woot
changeMood _ = Blah
#+end_src

#+name: ghcInt-imp
#+begin_src haskell :eval never
import GHC.Int
#+end_src

following the noweb docs here. This produces what's needed

module FP41 where
import Data.List
import GHC.Int

data Mood = Blah | Woot deriving (Show, Eq)

changeMood Blah = Woot
changeMood _ = Blah

although that :noweb-sep doesn't seem to work and I don't find anything on it other than it's mention.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.