Hacker News new | past | comments | ask | show | jobs | submit login

My absolute favorite web-console feature (in Chrome and Firefox at least) is the ability to go back in the REPL history to edit a previous function definition. A standard REPL just gives you back one line at a time, so if you want to make a change to line 3 of a 4 line function, then you have to type:

    UP UP UP UP ENTER UP UP UP ENTER UP UP
before you can edit that line. But the web consoles allow you to type UP just once, and then move your cursor around the entire function definition. I wish all REPLs had this feature.



You should try binding UP/DOWN to history-search-backward and history-search-forward[1]. Adding this to your ~/.inputrc

    "\e[A": history-search-backward
    "\e[B": history-search-forward
enables searching by the current line's prefix in all programs that use readline (a lot of languages use readline for their REPL). That is, if you type "cp<UP>" you immediately get the previous command that started with "cp", regardless of how far back it is in your history.

[1] https://codeinthehole.com/tips/the-most-important-command-li...


This is a useful trick, but I don't see how it addresses the issue they talked about. As I understand it, they were saying that Firefox and Chrome's Javascript REPL's scroll up through expressions rather than lines. If you say "const f = () => {" and press enter, it doesn't submit it until you close that brace, and when you use the up arrow to scroll back to it later, you get the whole thing (newlines preserved) instead of single lines of it.


This is trivial in the right environments. Not shockingly, in emacs I get that.

It actually takes a little getting used to at first, that up literally just moves the cursor up into the output of the previous command. Nowdays, it is severely restricting to have the same commands move the cursor that change the current command. (That is, left/right move cursor, up/down do a ton more in most terminals. That is not the case in emacs shells.)

Really, though, the repl is a fun stepping stone to just sending function definitions from the file you are working on into an environment. https://github.com/skeeto/skewer-mode is a fun video showing the idea for javascript, amusingly.

That said, there was a fun video a while back of the guy that did Minecraft live coding a video game. Basically, the game would be running, and he could make a change and it would live update, just like the javascript video above. But it was in java.

This is harder in non-managed runtimes, I believe. But not impossible.


> UP UP UP UP ENTER UP UP UP ENTER UP UP

If the REPL uses readline (or mimics it), then

    UP UP UP UP ^O ^O
will do the same thing as that sequence.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: