簡體   English   中英

python-mode,ipython,(ipython.el)版本/發布和init.el / .emacs.d代碼的組合是什么?

[英]What combination of python-mode, ipython, (ipython.el) versions/releases and init.el/.emacs.d code work?

我的目標是使用Emacs 24作為我的python編輯器(也有一個Matlab和R編輯器,但這不是我的問題)。

(如果我遺漏了任何信息或者我沒有說明清楚的話,請告訴我。)

我已經能夠以這樣的方式設置我的包和我的init.el文件,以便我能夠獲得標簽完成,正確的突出顯示和python的片段。 我正在使用python-mode.el作為我的python模式。 問題都圍繞着這個問題 :我想使用ipython作為我的python shell,以便在調試腳本時使用它的選項卡完成功能。

  • 但是,當我啟動ipython(使用Mx ipython)時,我沒有完成選項卡。 此外,它沒有顯示“[1] in:”,但它確實顯示“[1] out:”。
  • 我想讓ipython成為我在Emacs中的默認shell。 但是,嘗試此操作失敗(例如將C:\\ PATH \\ TO \\ IPython.exe設置為py-python-command)。
  • 當我嘗試使用Cc Cc運行我的python腳本時,它使用普通的Python運行,並且確實停在我告訴調試器停止的位置(我使用ipdb.set_trace)。 但是當我使用另一種應該啟動IPython的命令時(比如將該區域設置為我的整個腳本並運行py-execute-region-ipython),IPython不起作用。 它確實啟動了一個IPython shell,或者至少它似乎是,但我可以像在文本編輯器中一樣鍵入shell(fyi:在mini緩沖區中它顯示“Comint:run shell-compile”)。

我的問題是:我的init.el文件中的包版本和lisp代碼的哪些組合應該允許我使用帶有tab完成的ipython作為我在Emacs中的默認shell? 如果有必要,我願意降級一些軟件包。

額外信息

從我在Python-mode.el的Project頁面上看到的內容,我了解到IPython仍然存在一些關於此軟件包的最新版本的錯誤,因此可能需要使用舊版本。 我一直在谷歌搜索尋找解決方案,我找不到一個適合我的解決方案。

我在跑

我的init.el看起來像(python的東西在底部):

 ;; Requisites: Emacs >= 24 (require 'package) (package-initialize) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/")) (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/") t) (package-refresh-contents) (defun install-if-needed (package) (unless (package-installed-p package) (package-install package))) ;; make more packages available with the package installer --> ;; removed python mode since the version I got had errors (setq to-install '( ;python-mode magit yasnippet jedi auto-complete autopair find-file-in-repository flycheck)) (mapc 'install-if-needed to-install) ;;------------R STUFF----------- (add-to-list 'load-path "C:\\\\emacs-24.3\\\\site-lisp\\\\ess-13.09-1") (setq ess-use-auto-complete t) (load "ess-site") ;;------------MatLab STUFF----------- ; add folder of matlab-mode.el (add-to-list 'load-path "C:\\\\Users\\\\Rob Ter Horst\\\\AppData\\\\Roaming\\\\.emacs.d\\\\elpa\\\\matlab-mode-20130829.142") (load-library "matlab-load") (matlab-cedet-setup) (setq matlab-show-mlint-warnings t) (add-hook 'matlab-mode-hook 'auto-complete-mode) (add-hook 'matlab-mode-hook 'mlint-minor-mode) ;;------------GENERAL STUFF----------- ; Ido mode: Ido-powered versions of code. Most ido commands are named ido-xxxxx ; so find-file becomes ido-find-file, and so on. (setq ido-enable-flex-matching t) (setq ido-everywhere t) (ido-mode t) (global-linum-mode t) ;Use y or n always instead of yes/no (defalias 'yes-or-no-p 'y-or-np) ;; -------------------- extra nice things Andrea Crotti-------------------- ;; use shift to move around windows (windmove-default-keybindings 'shift) (show-paren-mode t) ; Turn beep off (setq visible-bell nil) (custom-set-variables '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"]) '(custom-enabled-themes (quote (wheatgrass)))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (put 'downcase-region 'disabled nil) ;;------------PYTHON STUFF----------- ;(require 'magit) ;(global-set-key "\\C-xg" 'magit-status) (require 'auto-complete) (require 'autopair) (require 'yasnippet) (require 'jedi) ;yasnipped settings (setq yas-snippet-dirs '("C:\\\\Users\\\\Rob Ter Horst\\\\AppData\\\\Roaming\\\\.emacs.d\\\\elpa\\\\yasnippet-20140106.1009\\\\snippets")) (add-to-list 'load-path "C:\\\\Users\\\\Rob Ter Horst\\\\AppData\\\\Roaming\\\\.emacs.d\\\\elpa\\\\yasnippet-20140106.1009") (global-set-key [f7] 'find-file-in-repository) ; auto-complete mode extra settings (setq ac-auto-start 2 ac-override-local-map nil ac-use-menu-map t ac-candidate-limit 20) ;; ;; Python mode settings (setq py-install-directory "C:\\\\Users\\\\Rob Ter Horst\\\\AppData\\\\Roaming\\\\.emacs.d\\\\self_installed\\\\python-mode.el-6.1.3") (add-to-list 'load-path py-install-directory) (add-to-list 'auto-mode-alist '("\\\\.py$" . python-mode)) (when (featurep 'python) (unload-feature 'python t)) (require 'python-mode) (setq py-electric-colon-active t) (add-hook 'python-mode-hook 'autopair-mode) (add-hook 'python-mode-hook 'yas-minor-mode) (add-hook 'python-mode-hook 'auto-complete-mode) ;; ;; Jedi settings ;; It's also required to run "pip install --user jedi" and "pip ;; install --user epc" to get the Python side of the library work ;; correctly. ;; With the same interpreter you're using. ;; if you need to change your python intepreter, if you want to change it ;; (setq jedi:server-command ;; '("python2" "/home/andrea/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py")) (add-hook 'python-mode-hook (lambda () (jedi:setup) (jedi:ac-setup) (local-set-key "\\C-cd" 'jedi:show-doc) (local-set-key (kbd "M-SPC") 'jedi:complete) (local-set-key (kbd "M-.") 'jedi:goto-definition))) ; ipython settings (setq py-python-command "C:\\\\Python27\\\\Scripts\\\\ipython.exe") (setq py-complete-function 'ipython-complete py-shell-complete-function 'ipython-complete py-shell-name "ipython" py-which-bufname "IPython") ;(require 'ipython) ;With tab autocompletion in ipdb I get an error that might be solved by changing this var ;the error: "variable binding depth exceeds max-specpdl-size" (setq max-specpdl-size 32000) ; Try to add flycheck --> flycheck causes emacs to become incredibly slow on big script with ; many style errors (as present in a lot of my older scripts, so I do not want to activate it ; by default ;(setq flycheck-highlighting-mode 'lines) ;(add-hook 'python-mode-hook 'global-flycheck-mode) ;(flycheck-select-checker 'python-flake8) ;(provide 'init-flycheck) (yas-reload-all) 

使用Emacs24,我使用默認的python.el(不是python-mode.el),它在github上啟動。

  1. 當我用python-shell-switch-to-shellCc Cp (Python菜單 - >啟動解釋器)啟動ipython時,我得到了ipython。 標簽完成工作。

  2. ipython是默認的python解釋器(參見我的init文件)

  3. 當我啟動一個ipython shell時,我可以向它發送一個文件或選定的區域(菜單中可用的命令),並且它會被正確評估。

作為旁注,您可以使用jedi:setup啟動jedi自動完成jedi:setup在python shell中設置。 它提供了帶有參數help和doc的漂亮彈出窗口,您可以選擇在點(而不是3個字符后)觸發它。 請參閱IPython自動完成emacs24不起作用 它可以被看作是ipython的補充而不是替代。

按照我的配置:

;; trying ipython tab completion: that works :)
(setq
 python-shell-interpreter "ipython"
 python-shell-interpreter-args ""
 python-shell-prompt-regexp "In \\[[0-9]+\\]: "
 python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
 python-shell-completion-setup-code "from IPython.core.completerlib import module_completion"
  python-shell-completion-module-string-code "';'.join(module_completion('''%s'''))\n"
  python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"
     )

取自http://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc5

希望這可以幫助。

在IPython-shell中,python-mode.el為它提供了TAB調用py-indent-line 這樣循環可能的縮進就像腳本緩沖區一樣。 完成工作在M-TAB 您可以重新定義這些密鑰。

我不使用Emacs(我是VIM粉絲),但通常當ipython沒有執行制表時,這意味着你錯過了readline模塊https://pypi.python.org/pypi/readline/6.2.2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM