emacs 和 python 更新模块
atm 我正在使用 emacs 编写一些 python 代码,到目前为止它工作得很好,除了一个确实有点烦人的问题。
当我更新自己编写的模块中的某些内容时,我总是会重新评估缓冲区,并且 emacs 内的 python shell 中的模块不会更新。我总是必须结束 python 进程并再次启动它才能获得更改。我发现 emacs 将一些东西复制到 tmp 目录来执行它们,所以我想这与此有关。
也许有人遇到了同样的问题并且已经解决了,所以我们将不胜感激
atm i'm using emacs to write some python code, so far it works quite fine except one problem that is really a bit annoying.
Always when I update something inside a self written module i reevaluate the buffer and the module in the python shell inside emacs doesn't get updated. i always have to end the python process and start it again to get the change. I figured out that emacs copies some things to a tmp dir to execute them, so i guess it has something to do with this.
Maybe someone out there had the same problem and solved it already so help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须在 shell 中手动重新加载模块才能使其生效。
请参阅此处有关Python重新加载函数的文档
我问了一个类似的问题,您可以看到这里
You have to reload the module manually in the shell in order for it to take effect.
See the documentation here on the Python reload function
I asked a similar question which you can see here
我找到了一个不需要 emacs 配置的更好解决方案:
只需
创建 ipython 配置文件,
然后将以下内容放入其中,
然后重新启动 emacs。现在,每次您在 emacs 中保存对文件的更改时,ipython 都会自动重新加载它
我的 emacs 配置中有以下内容
,如果您想查看完整的 python 配置, ,它是 此处
I found a better solution that needs no emacs config:
simply do
that should create ipython profile in
then put the following inside
then restart emacs. Now each time you save changes to file inside emacs - ipython would reload it automatically
and the following I have in my emacs config
if you want to see my full python config, it's here
您可以建议 python-mode.el 函数来获得所需的效果(至少,如果我正确理解您的请求)。将以下内容放入 Emacs 初始化文件中:
现在,当您在 python 程序中时,您可以选择代码区域,按 C-| 来评估该区域,然后 python 程序将重新加载(如果之前没有加载,则导入)在 Python 解释器缓冲区中。整个模块将被重新加载,而不仅仅是所选区域,并且系统将提示您保存 python 文件(如果尚未保存)。请注意,在对 您之前的问题的回复中提到的警告 仍然适用(例如 - 如果您已经从导入的模块创建了类实例,已经实例化了其他对象等,则它们不会被重新加载)。可能会发生一般破损,所以买者自负!)。
You can advise a python-mode.el function to get the desired effect (at least, if I am understanding your request properly). Put the following in your Emacs init file:
Now, when you're in a python program, you can select a region of code, press C-| to evaluate the region and the python program will be reloaded (or imported if it wasn't previously loaded) in the Python interpreter buffer. The ENTIRE module will be reloaded, not just the region that was selected and you will be prompted to save the python file if it hasn't already been saved. Note that the caveats that were mentioned in the replies to your previous question still apply (e.g. - If you have class instances already created from the imported module, have instantiated other objects, etc, they won't be reloaded). General breakage may occur, so caveat emptor!).
我建议使用 Elpy,如此处< /a>.
将以下内容添加到您的 Emacs 配置文件中:
重新启动 Emacs 使用
Cc Cx Cc
运行您的代码简而言之,此代码具有“if 子句”,用于检查 Python 缓冲区是否存在打开。这将有助于在开发的任何时候运行
Cc Cx Cc
,即使没有打开任何 Python 进程也是如此。另一部分是kill-buffer-query-functions,它忽略了终止Python缓冲区的提示。I'd recommend using Elpy as discussed here.
Add the following to your Emacs configuration file:
restart your Emacs run your code using
C-c C-x C-c
In short, this code has the "if clause" for checking if Python buffer is open. This will help to be able to run
C-c C-x C-c
at any time of development even when there is no Python process already open. Another part iskill-buffer-query-functions
which neglects the prompt for killing the Python buffer.