简体   繁体   English

从python-mode.el切换到python.el

[英]Switching from python-mode.el to python.el

I recently tried switching from using python-mode.el to python.el for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. 我最近尝试从使用python-mode.el切换到python.el来编辑emacs中的python文件,发现这种体验有点陌生和没有效果,并且匆匆回来。 I've been using python-mode.el for something like ten years, so perhaps I'm a little set in my ways. 我已经使用python-mode.el做了十年的事情,所以也许我的方式有点python-mode.el I'd be interested in hearing from anyone who's carefully evaluated the two modes, in particular of the pros and cons they perceive of each and how their work generally interacts with the features specific to python.el . 我有兴趣听到任何仔细评估这两种模式的人,特别是他们对每种模式的利弊,以及他们的工作如何与python.el特有的功能相互作用。

The two major issues for me with python.el were python.el给我的两个主要问题是

  1. Each buffer visiting a python file gets its own inferior interactive python shell. 访问python文件的每个缓冲区都有自己的劣质交互式python shell。 I am used to doing development in one interactive shell and sharing data between python files. 我习惯在一个交互式shell中进行开发,并在python文件之间共享数据。 (Might seem like bad practice from a software-engineering perspective, but I'm usually working with huge datasets which take a while to load into memory.) (从软件工程的角度来看,可能看起来很糟糕,但我通常使用大量数据集,这些数据集需要一段时间才能加载到内存中。)

  2. The skeleton-mode support in python.el, which seemed absolutely gratuitous (python's syntax makes such automation unnecessary) and badly designed (for instance, it has no knowledge of " for " loop generator expressions or " <expr 1> if <cond> else <expr 2> " expressions, so you have to go back and remove the colons it helpfully inserts after insisting that you enter the expression clauses in the minibuffer.) I couldn't figure out how to turn it off. python.el中的骨架模式支持,似乎绝对无偿(python的语法使得这种自动化不必要)和设计糟糕(例如,它不知道“ for ”循环生成器表达式或“ <expr 1> if <cond> else <expr 2> “表达式,所以你必须返回并删除它有助于在迷你缓冲区中输入表达式子句后插入的冒号。)我无法弄清楚如何关闭它。 There was a python.el variable which claimed to control this, but it didn't seem to work. 有一个python.el变量声称可以控制它,但似乎没有用。 It could be that the version of python.el I was using was broken (it came from the debian emacs-snapshot package) so if anyone knows of an up-to-date version of it, I'd like to hear about it. 可能是我使用的python.el的版本被破坏了(它来自debian emacs-snapshot包)所以如果有人知道它的最新版本,我想听听它。 (I had the same problem with the version in CVS emacs as of approximately two weeks ago.) (大约两周前,我在CVS emacs中的版本遇到了同样的问题。)

For what it's worth, I do not see the behavior you are seeing in issue #1, "Each buffer visiting a python file gets its own inferior interactive python shell." 对于它的价值,我没有看到你在问题#1中看到的行为,“访问python文件的每个缓冲区都有它自己的低级交互式python shell。”

This is what I did using python.el from Emacs 22.2. 这就是我使用Emacs 22.2中的python.el所做的。

Cx Cf foo.py [insert: print "foo"] Cx Cf foo.py [insert:print“foo”]

Cx Cf bar.py [insert: print "bar"] Cx Cf bar.py [insert:print“bar”]

Cc Cz [*Python* buffer appears] Cc Cz [* Python *缓冲区出现]

Cx o Cx o

Cc Cl RET ["bar" is printed in *Python*] Cc Cl RET [“bar”以* Python *打印]

Cx b foo.py RET Cx b foo.py RET

Cc Cl RET ["foo" is printed in the same *Python* buffer] Cc Cl RET [“foo”打印在相同的* Python *缓冲区中]

Therefore the two files are sharing the same inferior python shell. 因此这两个文件共享相同的下级python shell。 Perhaps there is some unforeseen interaction between your personal customizations of python-mode and the default behaviors of python.el. 也许你的python-mode的个人定制和python.el的默认行为之间存在一些无法预见的交互。 Have you tried using python.el without your .emacs customizations and checking if it behaves the same way? 您是否尝试过使用python.el而不使用.emacs自定义并检查它是否以相同的方式运行?

The major feature addition of python.el over python-mode is the symbol completion function python-complete-symbol. python.el在python-mode上的主要特性是符号完成函数python-complete-symbol。 You can add something like this 你可以添加这样的东西

(define-key inferior-python-mode-map "\C-c\t" 'python-complete-symbol)

Then typing 然后输入

>>> import os
>>> os.f[C-c TAB]

you'll get a *Completions* buffer containing 你会得到一个* Completions *缓冲区包含

Click <mouse-2> on a completion to select it.
In this buffer, type RET to select the completion near point.

Possible completions are:
os.fchdir                          os.fdatasync
os.fdopen                          os.fork
os.forkpty                         os.fpathconf
os.fstat                           os.fstatvfs
os.fsync                           os.ftruncate

It'll work in .py file buffers too. 它也可以在.py文件缓冲区中工作。

  1. I can't reproduce this behavior on Emacs v23.1, this must have been changed since then. 我无法在Emacs v23.1上重现此行为,此后必须进行更改。

  2. Forget about any mode's skeleton support and use the hyper-advanced and extensible yasnippet instead, it's really worth a try! 忘记任何模式的骨架支持并使用超高级和可扩展的yasnippet ,它真的值得一试!

Note nearly everything said here is obsolete meanwhile as things changed. 注意,随着事情发生变化,这里所说的几乎所有内容都已过时。

python-mode.el commands are prefixed "py-" basically, you should be able to use commands from both, nonewithstanding which one was loaded first. python-mode.el命令基本上以“py-”作为前缀,你应该能够使用两者中的命令,尽管首先加载了哪一个。

python-mode.el does not unload python.el; python-mode.el不卸载python.el; beside of python-mode-map, which is re-defined. 旁边是python-mode-map,它是重新定义的。

The diff is in the menu displayed and keysetting however, the last one loaded will determine. 差异在菜单显示和键设置中,然而,最后一个加载将确定。

python-mode.el has no support triple-quoted strings, so if your program contains long docstrings, all the syntax coloring (and associated syntaxic features) tends to break down. python-mode.el不支持三引号字符串,因此如果您的程序包含长文档字符串,则所有语法着色(以及相关的语法特征)都会出现故障。

my .02 我的.02

python-mode.el is written by the Python community. python-mode.el由Python社区编写。 python.el is written by the emacs community. python.el由emacs社区编写。 I've used python-mode.el for as long as I can remember and python.el doesn't even come close to the standards of python-mode.el. 我已经使用了python-mode.el,因为我记得并且python.el甚至没有接近python-mode.el的标准。 I trust the Python community better than the Emacs community to come up with a decent mode file. 我相信Python社区比Emacs社区更能提出一个体面的模式文件。 Just stick with python-mode.el, is there really a reason not to? 坚持使用python-mode.el,真的有理由不去吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM