Something I often do (and I'm hoping other folks do too) is write a script and run it through a interpreter.

Since I try to use org mode and org babel for scripting and literate programming, I end up with

#+BEGIN_SRC sh :results output replace
cat << EOF | psql 

All I have to do is C-c C-c and I have immediate results.

Sometimes it's a snippet of ruby code - piped to the 'bundle exec rails console' command, similar technique as above psql example.

My problem is, it hard to write anything substantial inside the "heredoc" block above because

emacs thinks I'm writing bash, when I'm writing sql
emacs thinks I'm writing bash, when I'm writing ruby

This means I loose syntax coloring, smart indentation, etc of the ruby/sql mode. In -nw mode (prelude) bash "herodocs" have a really low-contrast color, making the code I'm writing really hard to see.

I'm guessing a lot of people write code blocks in org mode that are eventually piped to an interpreter for quick feedback based development. So whats the best way to go about doing this?

  • Well, you can use another Babel block's source as the value of a variable in a different code block... I think, I even did this once combining JavaScript with HTML in such way... but it was a while ago, I'll need to find my old test examples. – wvxvw Aug 22 '18 at 17:30
  • stackoverflow.com/questions/9074967/… this isn't my example, but I think it was an inspiration for what I did. – wvxvw Aug 22 '18 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.