【问题标题】:Emacs python-mode.elEmacs python-mode.el
【发布时间】:2013-11-06 08:01:38
【问题描述】:

我正在尝试让 python-mode.el 和 ipython 与 emacs 一起使用。我下载了最新的 GNU emacs 和 python-mode.el,将文件放入 .emacs.d/python-mode.el-6.1.2 并在 emacs init 文件中写入以下内容:

; Python-mode
(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.2")
(add-to-list 'load-path "~/.emacs.d/python-mode.el-6.1.2")
(require 'python-mode)

从这里它应该能够识别 python 模式,但我无法识别它。当我打开一个 .py 文件时,模式是 Python (python.el),而不是 Py (python-mode)。我究竟做错了什么?接下来我希望能够通过 ipython 从 emacs 执行代码 - 我想只是关注官方网站:http://ipython.org/ipython-doc/stable/config/editors.html..

有关于 python 模式的帮助和关于 ipython 兼容性的建议吗? 我已经启动并运行了 python 和 ipython,但我对 emacs 很陌生。

提前致谢!

【问题讨论】:

  • 这里有一些可以帮助ipython的东西:*.com/questions/19495889/…
  • 如果您是 emacs 的新手,我建议您阅读此 wiki wikemacs.org/index.php/Python 并使用...安装包... packages: M-x list-packages 在 emacs 24 中并寻找 python-mode 和 ipython (并阅读说明)。希望这会有所帮助。

标签: python emacs editor ipython python-mode


【解决方案1】:

你还需要告诉emacs在打开.py文件时使用哪种模式

(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

【讨论】:

  • 仍然没有使用 py 模式。收到以下错误: 警告(初始化):加载/Users/tazz_dk/.emacs': error: The command named 'bzr' can not be found with executable-find 时发生错误为确保正常运行,您应该调查并删除初始化文件中的错误原因。使用 `--debug-init' 选项启动 Emacs 以查看完整的错误回溯。
  • @MathiasJørgensen 假设您有一些代码调用 DVC 系统集市。有一种方法可以通过bazaar获取python-mode.el,但是不影响运行,所以不需要bazaar。
  • @MathiasJørgensen 我不认为这不是来自python-mode.el
  • 感谢您的回答。 add-to-list 命令似乎不起作用。在安装 python-mode 时一定做错了什么?手动激活 python 模式的命令是什么?我尝试了 M-x python-mode 等,但它说它不能“猜测 python-indent-offset”,只是激活了 python.el 模式。
  • 听起来你有一个混合了制表符和空格的文件。我会在不读取您的 .emacs 文件(有一个命令行开关)的情况下启动 emacs,并有选择地执行与 python-mode 相关的命令,看看它是否有效。