1

I am running a short bash command from an org mode code block, using the program fold to wrap it at 60 characters. If I run the code without a session argument, the results display as expected. However, when I set the session argument (which I have to do in the context of the long literate analysis I'm doing), some of the output characters don't appear.

Steps to reproduce:

emacs -Q

Open the following file and execute each code block in turn:

#+BEGIN_SRC elisp setup
(org-babel-do-load-languages
 'org-babel-load-languages
 '((shell . t)))
#+END_SRC

#+RESULTS:

#+BEGIN_SRC bash no session :results replace verbatim
 echo 'CCCC8,,CEFGDF,,,CC,CF:,,C8CFGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCFGGGG@GGGGGGGGGGGGGGGGGGGGGGGGGGGGG+FF:B3CDFGGGFGGCFDGGGFCF:,FF9>FEC,F<FEG*?FFFFFGGG*CFEEECGGGGC+>FDGGDGFDFFEEFGEGC5>5?C*CGGF+3:*<7*2>+*<9CGCD::C=*@DCFCFFGG<C9<)7*9.5<@BA*7' | fold -w 60
#+END_SRC

#+RESULTS:
: CCCC8,,CEFGDF,,,CC,CF:,,C8CFGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
: GGGGGGCFGGGG@GGGGGGGGGGGGGGGGGGGGGGGGGGGGG+FF:B3CDFGGGFGGCFD
: GGGFCF:,FF9>FEC,F<FEG*?FFFFFGGG*CFEEECGGGGC+>FDGGDGFDFFEEFGE
: GC5>5?C*CGGF+3:*<7*2>+*<9CGCD::C=*@DCFCFFGG<C9<)7*9.5<@BA*7

#+BEGIN_SRC bash session :results replace verbatim :session my-session
 echo 'CCCC8,,CEFGDF,,,CC,CF:,,C8CFGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCFGGGG@GGGGGGGGGGGGGGGGGGGGGGGGGGGGG+FF:B3CDFGGGFGGCFDGGGFCF:,FF9>FEC,F<FEG*?FFFFFGGG*CFEEECGGGGC+>FDGGDGFDFFEEFGEGC5>5?C*CGGF+3:*<7*2>+*<9CGCD::C=*@DCFCFFGG<C9<)7*9.5<@BA*7' | fold -w 60
#+END_SRC

#+RESULTS:
: CCCC8,,CEFGDF,,,CC,CF:,,C8CFGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
: GGGGGGCFGGGG@GGGGGGGGGGGGGGGGGGGGGGGGGGGGG+FF:B3CDFGGGFGGCFD
: FEC,F<FEG*?FFFFFGGG*CFEEECGGGGC+>FDGGDGFDFFEEFGE
: 5?C*CGGF+3:*<7*2>+*<9CGCD::C=*@DCFCFFGG<C9<)7*9.5<@BA*7

Notice the difference between the two bash results blocks. In the first, the input string is folded at column 60, without any other changes. In the second, a string of characters has been deleted:

  • GGGFCF:,FF9> from the beginning of the third line
  • GC5> from the beginning of the fourth line

The fact that the deleted strings both start at the beginning of a line and end with a > suggests that the session thinks they should be redirected somehow, and in the process is dropping them completely. However, when I look at the session buffer, the output appears as expected, with no missing characters.

How do I force the babel session to leave the output alone, and print it verbatim into the org file?

GNU Emacs 26.0.90 Org mode version 9.1.4

  • 1
    In session mode, a function aptly named org-babel-sh-strip-weird-long-prompt is called. Good place to start the investigation. – Juancho Feb 21 '18 at 12:41
  • Good suggestion @Juancho, but that doesn't seem to be the culprit. I tried redefining that function to return the string unaltered, but it didn't fix the problem. – Tyler Feb 21 '18 at 22:05
  • 1
    shell-prompt-pattern sets comint-prompt-regexp to a pattern that matches the parts you're missing. org-babel-comint-with-output uses the pattern to split the strings returned from the process. – mutbuerger Feb 23 '18 at 20:33
  • Thanks @mutbuerger that's the problem. Now I just need a way to set comint-prompt-regexp to one value for an orgmode session, and another for a regular M-x shell session. – Tyler Feb 23 '18 at 21:08

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.