nonsequitur / inf-ruby

218 stars 69 forks source link

Consider adding ruby-send-line #98

Closed dgopstein closed 7 years ago

dgopstein commented 7 years ago

To send the contents of the current line to the repl.

While the functionality is achievable with ruby-send-region a dedicated implementation would be much more convenient.

Possible implementation:

(defun ruby-send-line ()
  "Send the current line to the inferior Ruby process."
  (interactive)
  (ruby-send-region (point-at-bol) (point-at-eol)))
dgutov commented 7 years ago

Any particular binding we should use?

dgopstein commented 7 years ago

Perhaps it would be prudent to follow the precedent set by ESS which uses C-c C-j for eval-line.

If this works for you, I'd be glad to send over a PR.

Incidentally, ESS also has a couple popular keybindings for eval-line-and-step and eval-region-or-line-and-step, which executes the current line (and sometimes a region, if selected) then advances the cursor one line. Those are bound to C-c C-n and C-<ret> respectively. Do you think there'd be value in adding these as well, or too much bloat?

lispercat commented 7 years ago

I wonder if the ruby-send-definition which is bound to C-M-x can be smart enough to detect that it's a single line that it needs to send (to make the editing experience more lisp-like)?

lispercat commented 7 years ago

For example I have a line like this: arr = Array.new(100) { rand(1...100) }

I would expect either ruby-send-last-sexp (C-x C-e) with the cursor at the end of line or ruby-send-definition (C-M-x) with the cursor anywhere in the line to work. Both of those options give me an error.

dgutov commented 7 years ago

arr = Array.new(100) { rand(1...100) }

But that's not a defun (even in Lisp terms), and the "last sexp" here is { rand(1...100) }. We could conceivably fix ruby-mode so that the last sexp here will be Array.new(100) { rand(1...100) }. But probably not arr = Array.new(100) { rand(1...100) }.

Although if you'd like to discuss that possibility, feel free to M-x report-emacs-bug that backward-sexp doesn't jump over the whole assignment. Maybe Stefan will have something to add.

dgutov commented 7 years ago

ruby-send-line has been added, BTW. Just without any default binding.