1

I've recently started using Emacs octave-mode and discovered that when using printf Emacs seems to block and I have to kill the execution of an Octave script with C-g.

I can reproduce that problem by having a file testprintf.m with just that single following line:

printf("Test");

or, alternatively, more authentical:

printf("Test: %d", 10);

Then, I execute this file with C-c C-i a (or, if you like, just that line with C-c C-i l) and I am seeing the mouse pointer turning into the waiting symbol signalling me that this Emacs command seems to hang. C-g terminates the command and allows further editing of the buffer. The Inferior Octave buffer does not show any output during and after this action.

Converting printf into a disp statement works but I'd like to make use of the convenient C-style formatting, Octave offers. Also, the same printf command works when directly copied into the Inferior Octave buffer with the expected out. I am using GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.11) and Octave 4.4.1. I have also tried it without my ~/.emacs with the same result, the mouse pointer turning into the waiting symbol.

2
  • You don't say what actions you take to make Emacs hang. You just show some text. The question seems unclear, so far.
    – Drew
    May 10 '20 at 15:33
  • Thanks, alright, I added some details in the hope this make my issue clearer.
    – Mario
    May 10 '20 at 15:52
2

I can reproduce this, but I think it's a buffering issue: try

printf("Test\n");

instead. Without the newline, accept-process-output seems to wait indefinitely.

Re: the comment from the OP - it should be fine to have multiple printf's without newlines, as long as there is a printf with a newline that is at the end of the code and is evaluated as part of that code - you just won't be able to evaluate things line by line. [LATER CORRECTION] But now that I have tried it, I see that it does not work: every printf has to have a newline, else accept-process-output waits indefinitely.

1
  • 1
    Thanks @NickD, indeed, adding a newline helps, e.g. printf("Test: %d\n", 10);. Sadly, newline's are what I frequently want to avoid to compose print output from different parts of the code in one line. Certainly, one can store output in variables, compose all into one call to printf with trailing \n. Still, a somewhat odd behaviour.
    – Mario
    May 11 '20 at 8:34

Your Answer

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

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