Answers:
这是我的工作流程。我将emacs设置为使用ipython
(setq
python-shell-interpreter "ipython3"
python-shell-interpreter-args "--simple-prompt --pprint")
然后在〜/ .ipython / profile_default / startup / 00-ipython_init.py中,输入以下内容:
ip = get_ipython()
ip.magic('load_ext autoreload')
然后,每当我修改并想在ipython中重新加载我的模块时,我都键入此内容。我喜欢它,因为它适用于所有模块,而且我不必担心导入依赖性。
%autoreload
您可以通过修改python-run并强制Python进程重新启动来完成此操作:
;; Run python and pop-up its shell.
;; Kill process to solve the reload modules problem.
(defun my-python-shell-run ()
(interactive)
(when (get-buffer-process "*Python*")
(set-process-query-on-exit-flag (get-buffer-process "*Python*") nil)
(kill-process (get-buffer-process "*Python*"))
;; Uncomment If you want to clean the buffer too.
;;(kill-buffer "*Python*")
;; Not so fast!
(sleep-for 0.5))
(run-python (python-shell-parse-command) nil nil)
(python-shell-send-buffer)
;; Pop new window only if shell isnt visible
;; in any frame.
(unless (get-buffer-window "*Python*" t)
(python-shell-switch-to-shell)))
(defun my-python-shell-run-region ()
(interactive)
(python-shell-send-region (region-beginning) (region-end))
(python-shell-switch-to-shell))
(eval-after-load "python"
'(progn
(define-key python-mode-map (kbd "C-c C-c") 'my-python-shell-run)
(define-key python-mode-map (kbd "C-c C-r") 'my-python-shell-run-region)
(define-key python-mode-map (kbd "C-h f") 'python-eldoc-at-point)))
http://lgmoneda.github.io/2017/02/19/emacs-python-shell-config-eng.html