Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send word at cursor to REPL #35

Open
jobvisser03 opened this issue Jan 28, 2018 · 3 comments
Open

send word at cursor to REPL #35

jobvisser03 opened this issue Jan 28, 2018 · 3 comments

Comments

@jobvisser03
Copy link

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?

@terlar
Copy link
Contributor

terlar commented Jan 28, 2018

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)))

@jobvisser03
Copy link
Author

@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?

@terlar
Copy link
Contributor

terlar commented Jan 29, 2018

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))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants