How to exit the command but not the interpreter? - command-line

I wrote some code in stk like this :
STk> (+ 2 3 ]
]]
||))
However, this is wrong. I'm not able to either correct this by going to the previous line or get out of this command. The only way seems to be Ctrl+Z but that takes me out of STk and everything I've done in it is gone.
Is there a way I can be inside the interpreter and continue programming without having to exit the interpreter if I've made an error like the one above. My terminal is Xfce4 Terminal 0.6.3.

Try pressing Ctrl + D. This worked for an earlier version that I am using.

Related

Why do I have to restart VS Code every time I want to run my code with the latest (saved) changes?

I just started having this problem a few hours ago, and before that I never had this issue.
I am writing a code in Julia using VS Code also using Julia Repl and Revise. Since a few hours every time I make a change in the code I have to restart VS Code to be able to run my recently saved code. Otherwise, if I do not restart the code, terminal just tells that it is finished and the code ran already, which actually did not happen.
Does anyone have an idea how to solve this, or what the problem could be?
Thanks in advance!
I tried to save it different ways, and searched for similar problem online, but did not really find anything useful.
What if you restart the REPL inside the VSCode instead of restarting the whole program?
For this, you can use this key shortcut: Ctrl + J Ctrl + R. Also, you can find it using Ctrl + Shift + P and the search for Restart REPL.
For me, however, this didn't happen unless I wrote the code so it couldn't be mutated after the first run. For example, I can't redefine a composite type in Julia, and I do need to restart the Julia session to do it.

Why can't I continue executing Julia code in the VSCode REPL if I hit CTRL+F5?

Under Visual Studio Code (VSCode) with the Julia extension there are two REPLs. One is the standard REPL that comes with Julia. The other is some modified REPL provided by VSCode. This modified REPL has some advantages over the standard REPL.
I found two ways of running a program in the VSCode REPL. For both the first step is to select the file containing the code in the VSCode editor. The second step could be either one of these:
Hit CTRL+F5,
Click on an arrow (a triangle) that points rightwards and sits on the right-hand side of the bar with tabs at the top of the code editor.
Method 1 Is more convenient, especially since Method 2 sometimes does not work and has to be repeated.
However, there is a strong disadvantage to Method 1: After the program executes I get the message:
Terminal will be reused by tasks, press any key to close it.
After this I cannot execute code in the REPL since hitting any key indeed closes the Terminal.
This does not happen when the program is started by Method 2: after the program runs I can run Julia code in the Terminal.
Is there a way to have Method 1 work like Method 2?

Complete command from history in ipython

For reasons outside of my control I'm stuck using python 2.6.6 and IPython 0.10.2. I also normally use the tcsh shell, and have gotten quite used to completing a command from the history using <A-p> (i.e. pressing the ALT key and p). However, this doesn't work in IPython. I know I can press <C-r> and then start typing a command, but what inevitably is happening is that I start a command, press <A-p>, get a colon indicating some weird state, then exit out of that state, delete my command, press <C-r> then search for my command. It's getting rather irritating. Is there any way to make <A-p> complete my already started command by relying on the history?
Ouch, this is an old version of IPython, Python (and pip). The bad news is I don't have much experience with such an old version of IPython, the good new is; it was way simpler at that time.
Most of the shortcut and feature are provided using readline, and the python bindings of stdlib. Meaning that most likely what you are trying to configure is readline itself and not only IPython; so you can find more information on that outside of IPython !
The secret is to grep in the source-code for parse_and_bind, then you'll find the following example configuration, leading me to change the ~/.ipython/ipy_user_conf.py to be like so at around line 99 (all indented an extra 4 space to be in the main() function):
import readline
readline.parse_and_bind('set completion-query-items 1000')
readline.parse_and_bind('set page-completions no')
rlopts = """\
tab: complete
"\C-l": possible-completions
set show-all-if-ambiguous on
"\C-o": tab-insert
"\M-i": " "
"\M-o": "\d\d\d\d"
"\M-I": "\d\d\d\d"
"\C-r": reverse-search-history
"\C-s": forward-search-history
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-k": kill-line
"\C-u": unix-line-discard"""
for cmd in rlopts.split('\n'):
readline.parse_and_bind(cmd)
The repetition of commands make me think that what \C,\M or [e mean might be system dependant. I would bet on \C being Control, and \M being Meta (Alt, Opt), but at least one of these line did the trick for me (and also now tab allows to complete). See also man readline for the list of commands you can bind to what, and enjoy! Hoping you can upgrade to Python 3 and IPython 6 at some point.
[Edit]
See Eric Carlsen second comment under this answer for how it was resolved.

How do I discover Elm's REPL in VS Code?

How do I discover Elm's REPL in VS Code?
Specifically, I have no clue how to get up and running with Elm and VS Code.
My past experience involves using F# and Visual Studio.
How do I send instructions to Elm's REPL?
Where is Elm's REPL located within VS Code's IDE?
Any suggestions?
Once you've installed the Elm package, you can use the Elm: REPL - Start command to start a REPL session.
(You access this command the same way as you access other commands in VS Code: by opening the Command Palette. This can be done through the View menu (View -> Command Palette) or with a keyboard shortcut (Ctrl + Shift + P or Cmd + Shift + P, depending on whether you use Windows or Mac).
Once the session has started, you can send lines or selections to the REPL. Type a line into your editor, then run the Elm: REPL - Send Line command to send it to the REPL. There is a default keyboard shortcut for this (Alt + /) as well.
If you want to send more than a line, highlight the thing you'd like to send (probably a function or value definition), and run the Elm: REPL - Send Selection command. Again, there's a keyboard shortcut: Alt + Enter.
Note that the REPL does not support type annotations; sending type annotations to the REPL will result in an error. You can still annotate your function and value definitions in your code, but when you highlight the definitions to send to the REPL, just make sure not to highlight the type annotations.
If you're just looking to play around in the Elm repl, just do this:
1) install Elm globally (using npm, or using an installer from elm-lang.org)
2) open VS Code, then press CTRL + ` (or Cmd + ` on a Mac); this opens VS Code's built-in terminal
3) type elm-repl -- this starts elm's repl, and you can try out snippets, etc
However since your real question is about getting up and running w/ Elm in VS Code, here's a start:
1) download/install elm-format from https://github.com/avh4/elm-format
2) install VS Code
3) install VS Code extension "elm" (it's by a Sascha Brink); add "elm.formatOnSave": true to your VS Code settings
Now when you create/edit a .elm file you'll get code coloring, etc.
If your Elm code is for an app (as opposed to repl snippets), you'll want to see results in elm-reactor. So start a VS Code terminal (see above), type elm-reactor, and your app should be served at http://localhost:8000
In short; You don't want to use vscode (yet) for Elm development. Either go with Atom (Elmjutsu) or IntelliJ (CE works fine with the elm-plugin).
You get support for refactoring and fast navigation. The reason I don't recommend using vscode is because the elm-plugin is underdeveloped.
Unfortunately, the elm-plugin with IntelliJ also is a little underdeveloped, since it does not underline-highlight errors in your sourcecode – so tracking errors does have a cognitive tax.
I know that this question is related to the elm-repl and the possibility to send your selection to the repl is a nice one. But it only saves you two shortcuts (copy selection, send to repl vs copy selection, alt-tab to repl, paste and enter). The way lines are formatted (in elm-format) renders send-single-line as mostly a not-properly-thougth-through feature.
What I do is open a terminal and open elm-repl there, and I split my screen so I always have the output available.

Would it be possible to jump between prev/next Terminal command prompts?

I'm using zsh in OS X Terminal.app and for quite a while, I've been longing for a way to jump back and forth between prev/next prompts in the terminal's output.
One convenience with this would be to be able to review (and track errors at) the end of each command's output; eg. when you building stuff from source with ./configure; make; make install. Note: I'm obviously not referring to jumping back and forth in the command-history, but for a way to take a peek at the endings of each command's output.
Has anyone heard of such functionality in the *nix (preferrably also Mac) world? Would it require some sort of OS-centric Terminal plugin, or can it be programmatically done via a shell script which can be tied to a keyboard shortcut? Maybe I'm the only one thinking about this? :)
Edit: Here's an example scenario: Let's say I want to compile and install some program (using standard ./configure && make && make install procedure) and after the make command, I run into some errors. Now, the way I understand it (I may be completely wrong), the crucial error causing the make command to fail usually shows up in the last line(s) in the output, no? Anyway, at this point, I might do something like cat INSTALL to read up on the INSTALL document to check whether there's something I've missed. NOW, if I want to go back to see what the error was, that caused my initial make command to fail, I then have to manually scroll up to that position again, since my cat INSTALL command printed a ton of text after it.
I don't know if this scenario is the most elucidative – but there are many other situations where I wish I could just "jump" back to previous prompt lines and check up on previous command output; whether it was a simple ls command, make, git status, or whatever it was – swapping positions in the window by means of using prompt lines as "bookmark" positions seems an interesting idea to me.
command + left or right goes between tabs in iterm. is this what you are asking?
Emacs has a shell-mode that runs a shell inside the Emacs editor, providing a rich environment of additional commands for navigating and working with shell commands. This includes commands for going to the previous/next prompt, and deleting the output from commands so you can "clean up" and issue another command.
If you aren't familiar with Emacs: to start a shell inside Emacs, run emacs from the shell, then type Esc-x (or Meta-x, if you have "Use option as meta key" enabled in Terminal > Preferences > Settings > [profile] > Keyboard). This will ask for a command to execute. Enter shell.
To see a list of commands you can use in Shell Mode, enter Control-h m. Here are the ones for moving the cursor to the previous/next prompt:
C-c C-n comint-next-prompt
C-c C-p comint-previous-prompt
These commands would also be useful:
C-c C-r comint-show-output
C-c C-o comint-delete-output