eval-in-repl
eval-in-repl copied to clipboard
send word at cursor to REPL
I want to improve my Python workflow in the following way:
- Send word at cursor to REPL
- Send word.info() from word (variable) at cursor to REPL
- Send type(word) from word (variable) at cursor to REPL
I do the following with Elpy but since I use spacemacs I'd rather not use it since it is big.
(defun jv-python/elpy-shell-send-word ()
"Send word at cursor."
(interactive)
(elpy-shell--ensure-shell-running)
(when (not elpy-shell-echo-input) (elpy-shell--append-to-shell-output "\n"))
(elpy-shell--with-maybe-echo
(python-shell-send-string (thing-at-point 'symbol)))
)
Can someone please help me with the points above using spacemacs + eir?
You could use (thing-at-point 'word)
but I think symbol is better fit.
These are the three things you are looking for:
(require 'eval-in-repl-python)
(eir-python-shell-send-string (thing-at-point 'symbol))
(eir-python-shell-send-string (format "%s.info()" (thing-at-point 'symbol)))
(eir-python-shell-send-string (format "type(%s)" (thing-at-point 'symbol)))
@terlar Thank you!!!
Last question: How can I replicate the functionality of elpy's send-current-line-or-statement? eval-in-repl can send a line, but when I call it from within a loop it gives and indent error. (the line is indented)
Is there a way to realise this behaviour?
You could do something like this, it will strip all leading space from the line if that is what you are looking for. The current line eval is made to be line by line, and therefore saves the indentation.
(eir-python-shell-send-string
(replace-regexp-in-string
"\\`[ \t\n]*"
""
(buffer-substring-no-properties (line-beginning-position) (line-end-position))))