Konubinix' opinionated web of thoughts

Org Babel Bash With Noop Lines

Fleeting

After make org-babel-sh-evaluate handle no newline input lines correctly and make org-babel-sh-evaluate handle noop lines, there have been works on org-mode that supposedly fixed sole issues. Yet some still remain.

When using a session, org mode keeps a comint buffer open, sends the input to it and gets its output.

When you interact with a repl, it

  • prints the prompt,
  • meaning wait for input (ending with a newline character),
  • the input line
  • the output
  • therefore, go back to printing the prompt,

Inside the comint buffer, because it basically is just a wrapper around a repl, all the lines are sent and the code tries hard to get rid of the prompt that gets intertwined with the output.

ob-shell does this is looking for prompts a beginning of line, with a regexp like ^\\$1 and getting rid of it.2

This works right when all the lines generate some output and end with a newline.


  1. the actual regexp is

    (setq-local comint-prompt-regexp
                (concat "^" (regexp-quote org-babel-sh-prompt)
                        " *"))
    
     ↩︎
  2. this is done by org-babel-comint-with-output

                                  (replace-regexp-in-string
                                   comint-prompt-regexp
                                   ,org-babel-comint-prompt-separator
                                   text))))
    
    ... then later
    
             (delete "" (split-string
                         string-buffer
                         ,org-babel-comint-prompt-separator))))))
    
     ↩︎