icr
icr copied to clipboard
Feature: adding an edit command
Pulling this in from https://github.com/crystal-community/icr/pull/75#issuecomment-349060653
@veelenga wrote :
edit command may be a nice addition now. It could allow user to edit the file in vim or something like that. @greyblake @jwoertink WDYT ?
I like the idea. It could pull from $EDITOR (or vim by default 😏 ), but wouldn't that basically be what the paste command does now?
Not really. Paste inserts new content into the file (and icr executes it then). Edit will give you a way to edit that file. So it will be possible to remove previously inserted "bad commands". But, i don't know, that may an overhead....
So that file could look something like
X = 1
class Test
end
def __icr_exec__
puts 1 + 1
puts X
end
puts "|||YIH22hSkVQN|||\def __icr_exec__...."
This edit would probably need a way to denote what can't be removed. Maybe a comment appended to the end of those lines?
Then again, now that I think about it. Would people want this as a feature vs just opening up a file and throwing some test code in that, then running it? If you're just talking about un-doing a bad command, that may go along with my initial commit I started for adding ctrl-C functionality. My thought there was like with irb, you can open a class or a method, then start defining stuff. If you mess up, you just hit ^C and wipe that out. I find myself typing "edn" a lot lol.
Right, this is what I'm afraid of as well. If we give a way to the users a direct way to edit the file, anyone can accidentally break a hole session while removing def __icr_exec__ line or a delimiter. I agree, this is dangerous and unwanted functionality.
I regularly use vicr for multi-line content, but sometimes just need to execute one line of code to test something, and icr is faster for this. So that's why i see some mixed approach (repl & editor) helpful.
Probably Ctrl-C will help. I have never used irb that way and should give it a try :)
Oh nice. I hadn't seen vicr until now. A mixed approach would be nice. Maybe we take this whole thing back to the drawing board, and look at icr from the ground up? Crystal has come a long way since the icr inception, so maybe there's new stuff we can take advantage of?