# Function interface to \`^Q\` shortcut behavior and generalization to get last stacktrace

**URL:** <https://discourse.julialang.org/t/function-interface-to-q-shortcut-behavior-and-generalization-to-get-last-stacktrace/58038>\
**Category:** Internals & Design\
**Created:** [March 26, 2021, 6:41pm UTC](https://discourse.julialang.org/t/function-interface-to-q-shortcut-behavior-and-generalization-to-get-last-stacktrace/58038 "2021-03-26T18:41:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [March 26, 2021, 6:41pm UTC](https://discourse.julialang.org/t/function-interface-to-q-shortcut-behavior-and-generalization-to-get-last-stacktrace/58038/1 "2021-03-26T18:41:04Z")

</div>

The [`^Q` shortcut](https://docs.julialang.org/en/v1/stdlib/REPL/#Key-bindings) lets a user jump to a source code line corresponding to a method or stackframe. It is just awesome. (It makes Julia a bit more like [the good parts of] SmallTalk)

What about a non-shortcut way to access the behavior? This would be useful if that shortcut doesn’t work for some reason (e.g. [by default in VS Code](https://github.com/julia-vscode/julia-vscode/issues/2077)), and could also possibly help with discoverability.

The current design remembers what was last displayed, and that information can be accessed in `Base.active_repl.last_shown_line_infos`. That structure is uniform whether what was displayed was a `Base.MethodList` or a a stacktrace via `showerror`.

What about a design that stores directly a `Base.MethodList` or a `Vector{Base.StackTraces.StackFrame}`?\* Combined with a definition like

```julia
edit(sf::StackTraces.StackFrame) = edit(sf.file, sf.line)

```

and

[`getindex` defined on `Base.MethodList`](https://github.com/JuliaLang/julia/issues/40195)

It should then work out to do something like `edit(Base.active_repl.last_shown[index])`.

As an additional benefit, this could be a way to get the last stacktrace, which I often want to e.g. copy it to my clipboard.

\*It’s not as simple as remembering in `show_backtrace`, but instead remembering in `show_reduced_backtrace` and `show_full_backtrace`. If the former is used, then `Base.active_repl.last_shown` should be bound to `displayed_stackframes`. This also means that there are two possible notions of the most recent stackframe…

(@tkf @simeonschaub)
