Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pasted lines to switch to pkg, shell and help repl modes #40604

Merged

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Apr 26, 2021

Currently it's possible to paste julia> 1+1 into the repl, and julia> will be stripped, and the 1+1 evaluated, etc.

This adds the handling of pkg> , shell> , and help?> prefixes, which are stripped and the mode changed.

With this PR, for instance if I copy this

julia> 1 + 1

shell> pwd

help?> trues

pkg> st

and paste it into the julia> repl mode, I get:

julia> 1 + 1
2

shell> pwd
/Users/ian/Documents/GitHub/julia

help?> trues
search: trues truncate InterruptException promote_rule isstructtype AbstractUnitRange

  trues(dims)

  Create a BitArray with all values set to true.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> trues(2,3)
  2×3 BitMatrix:
   1  1  1
   1  1  1

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [6e4b80f9] BenchmarkTools v0.7.0
  [295af30f] Revise v3.1.15

(@v1.7) pkg> 

Note that this only works for pasted text. Typing pkg> st into the julia> repl won't trigger the same behavior as it is paste-specific like the existing julia> prefix handling

@@ -76,6 +76,9 @@ end
answer_color(::AbstractREPL) = ""

const JULIA_PROMPT = "julia> "
const PKG_PROMPT = "pkg> "
Copy link
Member Author

@IanButterworth IanButterworth Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this lands, perhaps Pkg should use this const for constructing the prefix

@IanButterworth IanButterworth added the REPL Julia's REPL (Read Eval Print Loop) label Apr 26, 2021
@IanButterworth IanButterworth force-pushed the ib/more_repl_paste_mode_handling branch from ffce624 to 0d515aa Compare April 26, 2021 05:09
@KristofferC
Copy link
Member

Can I paste in

julia> 1+1
2

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [d2c73de3] GR_jll v0.57.2+0

shell> echo foo
foo

?

@IanButterworth
Copy link
Member Author

Ah no, good point. That one needs to be a regex

@IanButterworth
Copy link
Member Author

IanButterworth commented Apr 27, 2021

@KristofferC I've fixed the pkg prompt with env prefixes, but I didn't see the shell issue coming..

This is the result of pasting in your example. Why isn't the newline executing the echo??

julia> 1+1
2

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [6e4b80f9] BenchmarkTools v0.7.0
  [3da002f7] ColorTypes v0.10.12
  [295af30f] Revise v3.1.15

shell> echo foo
       foo

If I then press return I get

shell> echo foo
       foo
foo foo

@simeonschaub
Copy link
Member

If I then press return I get

shell> echo foo
       foo
foo foo

Pretty sure that is the expected behavior for multiline commands. Not great, I agree, but it is what it is.

@IanButterworth
Copy link
Member Author

I think the thing to do is to check if the next line is indented to the prompt start, and if so, treat it like a multiline command and add a return at the end to execute it

@IanButterworth IanButterworth force-pushed the ib/more_repl_paste_mode_handling branch from 0b24cae to ee3d6c8 Compare May 2, 2021 06:25
@IanButterworth
Copy link
Member Author

IanButterworth commented May 2, 2021

Multiline shell commands are now handled by identifying them if they are indented in alignment with the prompt.

Also, the indented prompts in the docstrings that might show in help mode are ignored until the next non-indented prompt. So indented prompts are still handled as before, just not within a a help?>.

So pasting this in looks identical after execution

julia> 1 + 1
2

shell> echo foo
       foo
foo foo

shell> echo foo
foo

help?> trues
search: trues truncate InterruptException promote_rule isstructtype AbstractUnitRange

  trues(dims)

  Create a BitArray with all values set to true.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> trues(2,3)
  2×3 BitMatrix:
   1  1  1
   1  1  1

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [6e4b80f9] BenchmarkTools v0.7.0
  [295af30f] Revise v3.1.15

(@v1.7) pkg> 

@IanButterworth IanButterworth force-pushed the ib/more_repl_paste_mode_handling branch from 84d80a0 to f7a46cc Compare May 4, 2021 19:00
@IanButterworth
Copy link
Member Author

Good to merge?

@oscardssmith oscardssmith merged commit 7c63647 into JuliaLang:master May 13, 2021
@IanButterworth IanButterworth deleted the ib/more_repl_paste_mode_handling branch May 13, 2021 19:53
shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
…aLang#40604)

* allow pasted lines to switch to pkg, shell and help modes
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
…aLang#40604)

* allow pasted lines to switch to pkg, shell and help modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants