How do I discover Elm's REPL in VS Code? - visual-studio-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.

Related

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?

Sublime fails to open new_file in macro

In Sublime (Version 3.2.2, Build 3211) (Ubuntu 18.04.5), I'd like to record a macro where I select-all, copy and paste the current content into another, unsaved file. And then do other commands as well, but I'm not even getting that far. The new-file step doesn't seem to work – neither new, nor new_window, newWindow, new_file, newFile seem to work; not even reopen_last_file. It should be new_file, though.
The console throws this:
Unknown macro command new_file
Which is weird. The command new_file works fine in other contexts: looking at the key-bindings settings, ctrl+n is bound to the same command and the hotkey has no issues.
Selecting all, copying – even this following bit works as intended:
{
"command": "insert",
"args": {"characters": "Hello, Friend!\n"}
}
In their forums, user "jps" writes:
With regards to the other console messages (unknown command, etc), don’t worry about them, they’re supposed to be there :slight_smile:
… but this doesn't seem to be right if it's obviously not working.
I have a project open but closing the project has no effect.
Is there maybe a package or something missing?
Macros in sublime can only capture and replay TextCommand commands; that is, commands that directly modify the content of a buffer or it's visual state. Examples including adding or removing text, changing the selection, moving the cursor around or changing view specific settings (like toggling word wrap or changing rulers, etc).
Commands like new_file, new_window or opening and closing projects are WindowCommand commands, which can't be captured via a macro.
In order to run a sequence of commands that includes a WindowCommand (or ApplicationCommand), you need to use a package. Two examples of that which are readily available on Package Control are Chain of Command and Multicommand.

Use mit-scheme with REPL and editor together

I'm going through SICP course and as recommended installed mit-scheme. I want to use the REPL together with a scheme file. The reason is because I can add scheme code in the file and then run the commands in REPL. What I have works, but the problem is every time I edit the file, I have to quit terminal and reload the file for REPL to see changes.
Is there a way to reload the file easily or some other way for REPL to see changes from the file?
This my setup:
I installed mit-scheme with brew install mit-scheme
I have a local file named code.scm
In terminal, I load the file with mit-scheme --load /Users/name/Desktop/code.scm
Terminal now starts the REPL and everything works. The problem is that if I add new code to the file code.scm, I have to quit terminal and call this again: mit-scheme --load /Users/name/Desktop/code.scm
System details:
macOS Catalina - 10.15.6
Default Mac Terminal app - Version 2.10
MIT/GNU Scheme running under OS X
The text editor I use is Atom - 1.50.0
Question Edit #1 (Based on answer below)
I tried following instructions but this is complicated.
This is what I did:
Run mit-scheme < /Users/Desktop/code.scm
After this I ran mit-scheme --edit to open Edwin. I tried to use the code inside of the code.scm file but it doesn't recognize it. This is the code in code.scm file:
This is what I want to be able to do:
Notice in this picture, I can type a command, press enter and it automatically runs command. However, I want to be able to call (fib 5) and it references the function in code.scm file.
Could someone explain step by step how to do this? It's confusing looking at documentation for scheme websites.
There's actually a built-in load procedure available in the MIT Scheme REPL.
Evaluating
(load "path/to/file.scm")
causes the Scheme file located at path/to/file.scm to be evaluated at the top level (note that the double quotes around the file name are required).
And, as it turns out, this same function can be used to reload a file.
With this in mind, a possible "workflow" might look like this:
Create new source file
Evaluate (load "path/to/file.scm") in the REPL
Edit source file
Evaluate (load "path/to/file.scm") in the REPL
...etc.
Unfortunately, I don't think there is a built-in "reload" procedure.
But...if you find yourself reloading a lot (as I imagine you will), you can always quickly write your own at the beginning of a hacking session:
(define (reload)
(load "path/to/file.scm"))
And then just call (reload) whenever you make a change to your source file.
If you're interesting in using Emacs, I'd say it's worth a shot.
There's a bit of a learning curve, but it's not as steep as it looks up front :)
Also, I cannot recommend the Racket programming language(s) enough.
There is an incredibly straightforward way to set it up for SICP, and it's a much more forgiving environment than Emacs.
Let me know if you are interested and want any help getting started.
You should use emacs with xscheme.el. It works much better.
If you continue as you do, you can also do mit-scheme < code.scm or mit-scheme --edit code.scm and you will also get a *repl* buffer inside edwin.
I recommend you the emacs way, however.
A (load "/path/to/file") command should be available to you within MIT Scheme and the Edwin editor it comes with. However, I would actually recommend that you use Emacs, and use Geiser within that to access both the REPL and to help with scheme file editing. It also makes dealing with various Scheme REPLs such as Chez Scheme, Racket, MIT Scheme, Guile, Chicken, Gambit and Chibi Scheme fairly effortless. The same (load "/path/to/file") command would then be available to you within the REPL running under Geiser, within Emacs, but is generally much more powerful and seamless than when using the "naked" REPL. Emacs is very well tuned to use with Scheme and LISP. Highly recommended.
Evaluate entire buffer: press M-o (M is Alt on Windows). When in source file window, press it. It will evaluate the entire buffer i.e. (re)load the entire source file (without even saving it first). I found it by googling "mit scheme edwin tutorial". Edwin is kind of Emacs itself.
This page says: "C-c C-s when done in a scheme-mode buffer [i.e. Scheme source file window], will switch to the Scheme interaction buffer [i.e. REPL]". i.e. you press C-x C-s to save file, M-o to evaluate (i.e. load), C-c C-s to switch to the REPL.
If you've split your screen with C-x 2 between a source file buffer and the REPL ("interactions buffer"), you can switch between them by pressing C-x o (for "go to the other window").

Is there an autocomplete for Dr. Racket?

I usually use Sublime text editor and gnome terminal to edit and run my programs. Due to educational purposes, I am using the IDE Dr. Racket.
I could not find an autocomplete feature to use while typing. I checked this out on google and at Dr. Racket's menu.
For instance, if I am calling a function already defined I would like to accelerate the process of typing the functions name.
I have tried using control + /, but it does not work as an autocomplete for variables and procedures already defined.
Edit
#Sylwester, look, I tried that with a previous defined function, named square. It did not work:
Linux and Windows
CTRL + /.
Mac OSX
Command + /
The last "key" might not be a button on its own and if that's so it needs to be the combination to make a /. eg. on my norwegian keyboard its
CTRL + SHIFT + 7 since SHIFT + 7 makes a /.
I have no idea where it gets it's matches from since I see it finds fold even when it is not called that in #lang racket. It does not seem to catch user procedures either.
This answer is based on information from a racket mailing list entry from 2011. It's not documented in DrRacket shotcuts page so it might not be officially supported.
On top of the default autocomplete, there are various other options:
The drcomplete package provides several autocomplete features,
The quickscript-extra package contains the dynamic-abbrev script (autocomplete based on the contents of the file) and complete-word script (completion based on a given dictionary),
The quickscript-competition-2020 package contains the fishy-completion script (lexical-based completion).
For the latter 2, you get scripts entries in the Scripts menu in DrRacket, plus default keybindings that can be changed by editing the scripts. (Also note that the other scripts installed at the same time can be deactivated from the Scripts|Manage|Disable scripts… menu.)

Configure pointer focus properties of Matlab's command window

I'm running Matlab 2013a, under Linux, using Xmonad (using the XMonad.Config.Xfce package).
This problem occurs whether the command window is docked or not.
The command window prompt does not get the keyboard focus unless the pointer is located
over the command window.
Is there a way to get the Matlab command window to have focus behaviour just like other normal windows, like a terminal?
Most important: I'd like to have the keyboard focus follow the window focus,
and not require any special positioning of the pointer, so that I can just "Alt-Tab" around my windows and have the command window get the keyboard focus. All of the resources I've found so far relate to programmatic control of focus; I'm just trying to improve my user experience in an interactive session.
To get keyboard focus on the Command Window, include the following in your xmonad.hs
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageHelpers
and configure your ManageHook as follows
myManageHook = composeAll . concat $
[ [appName =? a --> doCenterFloat | a <- myFloatAS ]
, (your other hooks)
] where
myFloatAS = ["MATLAB"]
Finally, include setWMName "LG3D" in your startupHook. See here for a full xmonad.hs configuration which uses this (this is where I found the solution). If you have other Java apps that don't get focus as they should you can add them to the myFloatAS list.
It's a problem in the built-in java.
If i run:
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
matlab -desktop
Matlab works as expected.
I ran into this problem, running MATLAB2014a. I set up setWMName "LG3D" but still i couldn't get focus on my window. I had to click on the focused window to get the cursor, and sometimes the situation was even worse and I had to click on random places till i get my cursor back. This wouldn't happen on MATLAB2010. What worked for me was to use the native version of java as describe above.
In the end, i used the following bash script to start matlab8:
#!/bin/bash
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/
/usr/local/bin/matlab8 -desktop -nosplash