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

RFC: jump to numbered stackframe with hotkey #19680

Merged
merged 4 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Library improvements

* The `chop` and `chomp` functions now return a `SubString` ([#18339]).

* Numbered stackframes printed in stacktraces can be opened in an editor by entering the corresponding number in the REPL and pressing `^Q` ([#19680]).

* The REPL now supports something called *prompt pasting* ([#17599]).
This activates when pasting text that starts with `julia> ` into the REPL.
In that case, only expressions starting with `julia> ` are parsed, the rest are removed.
Expand Down Expand Up @@ -801,4 +803,5 @@ Language tooling improvements
[#19543]: https://github.com/JuliaLang/julia/issues/19543
[#19598]: https://github.com/JuliaLang/julia/issues/19598
[#19635]: https://github.com/JuliaLang/julia/issues/19635
[#19680]: https://github.com/JuliaLang/julia/issues/19680
[#19787]: https://github.com/JuliaLang/julia/issues/19787
20 changes: 20 additions & 0 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,26 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
firstline = false
end
end,

# Open the editor at the location of a stackframe
# This is accessing a global variable that gets set in
# the show_backtrace function.
"^Q" => (s, o...) -> begin
linfos = Base.LAST_BACKTRACE_LINE_INFOS
str = String(take!(LineEdit.buffer(s)))
n = tryparse(Int, str)
isnull(n) && @goto writeback
Copy link
Member Author

Choose a reason for hiding this comment

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

These @goto shenanigans are probably not worth it. :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with it. This sort of interactive input use case is actually one of the places where goto seems to actually be clearer and easier than anything else.

n = get(n)
if n <= 0 || n > length(linfos) || startswith(linfos[n][1], "./REPL")
@goto writeback
end
Base.edit(linfos[n][1], linfos[n][2])
Base.LineEdit.refresh_line(s)
return
@label writeback
write(Base.LineEdit.buffer(s), str)
return
end,
)

prefix_prompt, prefix_keymap = LineEdit.setup_prefix_keymap(hp, julia_prompt)
Expand Down
7 changes: 7 additions & 0 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,21 @@ function show_trace_entry(io, frame, n; prefix = " in ")
n > 1 && print(io, " (repeats ", n, " times)")
end

# Contains file name and file number. Gets set when a backtrace
# is shown. Used by the REPL to make it possible to open
# the location of a stackframe in the edítor.
global LAST_BACKTRACE_LINE_INFOS = Tuple{String, Int}[]

function show_backtrace(io::IO, t::Vector)
n_frames = 0
frame_counter = 0
resize!(LAST_BACKTRACE_LINE_INFOS, 0)
process_backtrace((a,b) -> n_frames += 1, t)
n_frames != 0 && print(io, "\nStacktrace:")
process_entry = (last_frame, n) -> begin
frame_counter += 1
show_trace_entry(io, last_frame, n, prefix = string(" [", frame_counter, "] "))
push!(LAST_BACKTRACE_LINE_INFOS, (string(last_frame.file), last_frame.line))
end
process_backtrace(process_entry, t)
end
Expand Down
66 changes: 34 additions & 32 deletions doc/src/manual/interacting-with-julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,40 @@ control-key, there are also meta-key bindings. These vary more by platform, but
default to using alt- or option- held down with a key to send the meta-key (or can be configured
to do so).

| Keybinding | Description |
|:------------------- |:---------------------------------------------------------------------------- |
| **Program control** |   |
| `^D` | Exit (when buffer is empty) |
| `^C` | Interrupt or cancel |
| `^L` | Clear console screen |
| Return/Enter, `^J` | New line, executing if it is complete |
| meta-Return/Enter | Insert new line without executing it |
| `?` or `;` | Enter help or shell mode (when at start of a line) |
| `^R`, `^S` | Incremental history search, described above |
| **Cursor movement** |   |
| Right arrow, `^F` | Move right one character |
| Left arrow, `^B` | Move left one character |
| Home, `^A` | Move to beginning of line |
| End, `^E` | Move to end of line |
| `^P` | Change to the previous or next history entry |
| `^N` | Change to the next history entry |
| Up arrow | Move up one line (or to the previous history entry) |
| Down arrow | Move down one line (or to the next history entry) |
| Page-up | Change to the previous history entry that matches the text before the cursor |
| Page-down | Change to the next history entry that matches the text before the cursor |
| `meta-F` | Move right one word |
| `meta-B` | Move left one word |
| **Editing** |   |
| Backspace, `^H` | Delete the previous character |
| Delete, `^D` | Forward delete one character (when buffer has text) |
| meta-Backspace | Delete the previous word |
| `meta-D` | Forward delete the next word |
| `^W` | Delete previous text up to the nearest whitespace |
| `^K` | "Kill" to end of line, placing the text in a buffer |
| `^Y` | "Yank" insert the text from the kill buffer |
| `^T` | Transpose the characters about the cursor |
| Keybinding | Description |
|:------------------- |:-------------------------------------------------------------------------------- |
| **Program control** |   |
| `^D` | Exit (when buffer is empty) |
| `^C` | Interrupt or cancel |
| `^L` | Clear console screen |
| Return/Enter, `^J` | New line, executing if it is complete |
| meta-Return/Enter | Insert new line without executing it |
| `?` or `;` | Enter help or shell mode (when at start of a line) |
| `^R`, `^S` | Incremental history search, described above |
| **Cursor movement** |   |
| Right arrow, `^F` | Move right one character |
| Left arrow, `^B` | Move left one character |
| Home, `^A` | Move to beginning of line |
| End, `^E` | Move to end of line |
| `^P` | Change to the previous or next history entry |
| `^N` | Change to the next history entry |
| Up arrow | Move up one line (or to the previous history entry) |
| Down arrow | Move down one line (or to the next history entry) |
| Page-up | Change to the previous history entry that matches the text before the cursor |
| Page-down | Change to the next history entry that matches the text before the cursor |
| `meta-F` | Move right one word |
| `meta-B` | Move left one word |
| **Editing** |   |
| Backspace, `^H` | Delete the previous character |
| Delete, `^D` | Forward delete one character (when buffer has text) |
| meta-Backspace | Delete the previous word |
| `meta-D` | Forward delete the next word |
| `^W` | Delete previous text up to the nearest whitespace |
| `^K` | "Kill" to end of line, placing the text in a buffer |
| `^Y` | "Yank" insert the text from the kill buffer |
| `^T` | Transpose the characters about the cursor |
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe |


### Customizing keybindings

Expand Down