首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python模式、ipython、(ipython.el)版本/发行版和init.el/.emacs.d代码的哪个组合可以工作?

python模式、ipython、(ipython.el)版本/发行版和init.el/.emacs.d代码的哪个组合可以工作?
EN

Stack Overflow用户
提问于 2014-02-19 12:47:59
回答 2查看 3.5K关注 0票数 6

我的目标是使用Emacs 24作为我的python编辑器(也有一个Matlab和R编辑器,但这不是我的问题所在)。

(如果我遗漏了任何信息,或者我没有说清楚的话,请告诉我。)

我已经能够设置我的包和我的init.el文件,使我能够获得标签完成,正确的高亮显示和代码片段的python。我使用python-mode.el作为我的python模式。问题都围绕着这一点:我希望使用ipython作为我的python,以便在调试脚本时使用它的选项卡完成函数。

  • 但是,当我启动ipython (使用completion )时,没有选项卡完成。此外,它没有显示"1 in:",但是它显示了"1 out:“。
  • 我想在Emacs中将ipython作为我的默认shell。但是,尝试失败了(例如,将C:\PATH\TO\IPython.exe设置为py-python-命令)。
  • 当我试图使用C-c C-c运行我的Python脚本时,它使用普通的python运行,并且确实在我告诉调试器停止的位置停止(我使用ipdb.set_trace)。但是,当我使用另一种类型的命令来启动IPython (比如将区域设置为整个脚本并运行py-)时,IPython不起作用。它确实启动了一个IPython shell,或者至少看起来是这样,但是我可以像输入文本编辑器一样输入shell (fyi:在迷你缓冲区中显示"Comint:run编译“)。

,我的问题是:文件中的包版本和lisp代码的组合应该允许我在init.el文件中使用带有选项卡完成的ipython作为我的默认shell?如果有必要的话,我愿意降低一些软件包的等级。

附加信息

根据我在Python-mode.el的项目页面上所读到的内容,我了解到在这个包的最新版本中仍然存在一些关于IPython的bug,所以可能有必要使用旧版本。我一直在谷歌上搜索一个解决方案,但我一直找不到适合我的解决方案。

我在跑

我的init.el看起来像(python在底部):

代码语言:javascript
复制
;; 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-n-p)

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

EN

回答 2

Stack Overflow用户

发布于 2014-02-20 10:35:02

对于Emacs24,我使用默认的python.el (不是python-mode.el),它启动了论github

  1. 当我用python-shell-switch-to-shellC-c C-p (Python -> start解释器)启动ipython时,我会得到ipython。标签完成工程。
  2. ipython是默认的python解释器(请参阅init文件)
  3. 启动ipython后,我可以向其发送一个文件或选定的区域(菜单中可用的命令),并对其进行正确的评估。

顺便提一句,当你身处巨蟒外壳时,你可以用jedi:setup启动绝地自动完成。它提供了很好的弹出框参数帮助和文档,你可以选择在点(而不是在3个字符之后)激发它。见IPython自动完成emacs24不工作。它可以看作是对ipython的补充而不是替代。

按照我的配置:

代码语言:javascript
复制
;; 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

希望这能有所帮助。

票数 3
EN

Stack Overflow用户

发布于 2014-02-19 12:55:28

我不使用Emacs (我是一个VIM迷),但是通常当ipython不执行选项卡完成时,它意味着您缺少了读行模块https://pypi.python.org/pypi/readline/6.2.2

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21880950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档