Multiline input and whitespace

question

#1

This issue came up when sending a function with a lot of blank lines in julia-repl. It can be reproduced like this:

julia> function f()
       
       
ERROR: syntax: incomplete: premature end of input

ie 3x RET after f(). Is this a bug? Should Julia wait for the end, or does it give up after a while? Is the threshold for the latter well-defined?


#2

REPL seems to allow two newlines before deciding that the end of input is premature.
I do not know if it is intended, but you can cheat it like this:

julia> [i for i in

       1:1]
1-element Array{Int64,1}:
 1

julia> [i for i in



       1:1]
1-element Array{Int64,1}:
 1

julia> [i for i in





       1:1]
1-element Array{Int64,1}:
 1

Here I obtained the second and third expression by going back the command history deleting 1:1], pressing two newlines, and reinserting 1:1]. Adding three newlines produces an error.


#3

To clarify: the intent of this question is to establish whether this is intended behavior or a bug before opening an issue.

If this is intended, it should be documented (I could not find it, but perhaps I was not looking at the right place). That said, my life would be much easier if this was a considered a bug and got fixed accordingly, otherwise I will have to so some magic to remove newlines from code (but not strings etc).


#4

As an aside, it would probably good to have a paste-mode. For this and also for pasting code including prompts.


#5

There is a paste mode (bracket paste) which is automatically enabled when pasting (in most terminals). This can be opted into by plugin by sending the correct ansi sequence to the repl, see https://cirw.in/blog/bracketed paste.


#6

Corrected link https://cirw.in/blog/bracketed-paste

Edit: Looks like emacs has some support for this https://www.gnu.org/software/emacs/manual/html_mono/efaq.html

Edit edit: more links: https://github.com/syl20bnr/spacemacs/issues/3064, https://www.emacswiki.org/emacs/bracketed-paste.el


#7

I think that @keno implemented this way back in the day and that it’s intentional. I’ve never used this feature personally, so I don’t really care if it stays or goes, but he may have more thoughts.


#8

Yes, it’s intentional. It’s there so people get a syntax error when they have incomplete sequences but don’t think they do. As was mentioned, use bracketed paste mode for pasting expressions.


#9

It does have the advantage that when someone gets frustrated and keeps hitting return, they eventually get an error and a new prompt instead of just a seemingly hung REPL.


#10

Yes, it’s the “angry user detection” heuristic. Note you can always press shift enter to get a literal newline.


#11

The shift+enter does not work for me. Does it work for anyone else?


#12

I think Keno meant alt+enter.


#13

I did, yes. Thanks for the correction.


#14

Unfortunately in Windows console alt+enter turns on full screen mode.


#15

Thanks. Bracketed paste solves my problems and I can see the rationale for this, so I am fine with it, just didn’t know about it.

But if I wanted to submit a PR documenting this (breaking out after 3 newlines, using Alt-Enter, mention bracketed paste mode), where should it go? Workflow tips?


#16

It’s documented at https://docs.julialang.org/en/stable/manual/interacting-with-julia/#Key-bindings-1


#17

Meta-Enter is indeed documented (thanks!), but I could not find the documentation for

  1. bracketed paste mode, and
  2. breaking out after 3 newlines

there. Are they somewhere else? If not, where should they go?