The question here is related (but NOT identical) and complementary to Change the "send code to interpreter" (C-c |) command in python-mode .
I work on a M
Here is something that was quickly cooked up to send a python line to python-shell. I tend to do it in R a lot as well. It's not completely automated yet but I might be useful.
Here are some that still remain to be made:
Send line to dedicated process if necessary
Assign a local key
(defun my-python-line ()
(interactive)
(save-excursion
(setq the_script_buffer (format (buffer-name)))
(end-of-line)
(kill-region (point) (progn (back-to-indentation) (point)))
;(setq the_py_buffer (format "*Python[%s]*" (buffer-file-name)))
(setq the_py_buffer "*Python*")
(switch-to-buffer-other-window the_py_buffer)
(goto-char (buffer-end 1))
(yank)
(comint-send-input)
(switch-to-buffer-other-window the_script_buffer)
(yank))
)
(global-set-key (kbd "C-c n") 'my-python-line)
Update
I have improved the code a little bit more:
possible to use the code directly to even if a python shell is not running yet.
A local set key have been set
Only the dedicated process remain to be made. Feel free to improve in the answer below
(defun my-python-line ()
(interactive)
(save-excursion
(setq the_script_buffer (format (buffer-name)))
(end-of-line)
(kill-region (point) (progn (back-to-indentation) (point)))
(if (get-buffer "*Python*")
(message "")
(run-python "ipython" nil nil))
;; (setq the_py_buffer (format "*Python[%s]*" (buffer-file-name)))
(setq the_py_buffer "*Python*")
(switch-to-buffer-other-window the_py_buffer)
(goto-char (buffer-end 1))
(yank)
(comint-send-input)
(switch-to-buffer-other-window the_script_buffer)
(yank))
(end-of-line)
(next-line)
)
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\C-cn" 'my-python-line)))