shirok / Gauche

Scheme Scripting Engine
https://practical-scheme.net/gauche
Other
813 stars 81 forks source link

Line editor prompt character #692

Open lassik opened 4 years ago

lassik commented 4 years ago

The current prompt character is $:

$ GAUCHE_READ_EDIT=yes gosh
gosh$ (+ 1 2 3)
6
gosh$

Could we change it to something other than the dollar sign, which has a strong connotation of "unix shell"? I've tried to type shell commands to it by accident :)

> is a common prompt for interpreters.

If we know the terminal encoding supports a lambda, we could use that.

shirok commented 4 years ago

> is already used for the default (non-editing) prompt. I'd like to distinguish editing and non-editing clearly.

Personally I kind of like $, for it is a shell to me but just has different syntax. (I even tempted to make REPL recognizes shell commands; the obstacle is that a command with no arguments can't be distinguished from variable reference.) If it turns out too confusing though, I can change. Or I can add a way to customize it.

Write in here your choice of prompt character.

pclouds commented 4 years ago

I even tempted to make REPL recognizes shell commands; the obstacle is that a command with no arguments can't be distinguished from variable reference.

Don't you dare make me live in gosh prompt 24/7!

But how about recogizing shell commands only if it starts ,! (new top level command)? ! seems to be the symbol for running external commands (at least in vim). Or ,, to type easier.

If that opens up the ability of mixing shell commands and scheme expressions, I might actually just live in it...

shirok commented 4 years ago

I considered ,!, but needed to press shift key which bothered me. So as a temporary compromise I use ,sh. ,, can be another candidate.

lassik commented 4 years ago

There have been several experiments mash-up of Lisp/Scheme interpreter and Unix shell.

lassik commented 4 years ago

Write in here your choice of prompt character.

I would just go with > or a Unicode lambda.

Using $ to distinguish between line-editing and no line-editing is not that simple, since people can also get line editing from tools like Emacs shell-mode and rlwrap.

lassik commented 4 years ago

If there's an interactive line editor, you could perhaps press TAB when the input is blank to toggle between Scheme and shell input. The prompt could say which one is active, perhaps with a different color for the input to make it even more obvious.

shirok commented 4 years ago

I don't think I would need to change prompt for rlwrap or Emacs; what I care is whether Gauche's editing mode is on or off. What I can do differs in external tools.

Toggling input mode seems interesting.

IIRC, scsh doesn't have alternative shell syntax, or does it? Thought it is intended to replace shell scripts, but the interactive part is an ordinary Scheme repl. An interesting model is tclsh of Tcl. It uses undefined-procedure trap to invoke shell commands, that is, if you type something that's not a command known to Tcl, it calls exec(). So it can replace your login shell. Of course Tcl's syntax is pretty similar to shell's, and in our case that's not blend in.

lassik commented 4 years ago

I don't think I would need to change prompt for rlwrap or Emacs; what I care is whether Gauche's editing mode is on or off. What I can do differs in external tools.

Fair enough. Your project, your call :)

IIRC, scsh doesn't have alternative shell syntax, or does it?

Not sure. Maybe it doesn't.

An interesting model is tclsh of Tcl. It uses undefined-procedure trap to invoke shell commands, that is, if you type something that's not a command known to Tcl, it calls exec(). So it can replace your login shell. Of course Tcl's syntax is pretty similar to shell's, and in our case that's not blend in.

Indeed, that sounds like it would work better with more shell-like syntax :)

One option would be interpreting lines that start with whitespace as shell commands. But it's easy to get preceding whitespace when copy/pasting Scheme code into a REPL so that wouldn't work out well.

lassik commented 4 years ago

Here are some of the others: