简体   繁体   English

自定义pycharm IDE等emacs

[英]Customizing emacs like pycharm IDE

I am newbie to Emacs. 我是Emacs的新手。 I mostly work in python (specifically twisted) & trying to configure it more like Pycharm IDE. 我主要使用python(特别是扭曲的)工作,并尝试更像Pycharm IDE进行配置。 I installed package elpy . 我安装了软件包elpy But still it doesn't work well in case of auto completion. 但是,在自动完成的情况下,它仍然无法正常运行。 Also it shows all errors in red color either they are errors or warnings. 它还以红色显示所有错误,无论是错误还是警告。 I tweaked pyflakes to show only specific errors ( instead of showing all errors mentioned in PEP8 specifications). 我对pyflakes进行了调整,使其仅显示特定的错误(而不是显示PEP8规范中提到的所有错误)。 But I am trying to make it more like Pycharm. 但我正在尝试使其更像Pycharm。

Has anybody greater luck with this ? 有人有更大的运气吗? Why pycharm is so good in case of autocompletion and finding definitions/sources of functions/classes ? 为什么pycharm在自动补全和查找函数/类的定义/源的情况下如此好? Also Can we configure virtualenv in emacs ? 还可以在emacs中配置virtualenv吗?

Any suggestions/resources/ideas will be welcome. 任何建议/资源/想法将受到欢迎。

I am a newbie myself, but I did have more luck with spacemacs , thanks to the community behind it!. 我本人是新手,但由于背后的社区,我确实对spacemacs感到更幸运! And hopefully this is can be useful for those never used emacs before as well. 希望这对于以前从未使用过的emacs也是有用的。 I had hard time installing so I will make the guide very detail. 我在安装时花了很多时间,因此我将详细介绍该指南。 I'll be updating this if I find any more package to improve the experience Read more at github spacemacs (Google spacemacs refactor python code ) 如果我找到更多软件包来改善体验,我将进行更新,请访问github spacemacs (Google spacemacs refactor python code )。

Final Result Should Have (Check the image at the end): 最终结果应该有最后检查图像):

  • Auto-complete ( CMi ) 自动完成( CMi
  • Line number ( Mx linum-mode ) 行号( Mx linum-mode
  • Python Virtual Environment ( Mx pyvenv-workon ) Python虚拟环境( Mx pyvenv-workon
  • Syntax-checking ( Mx flycheck-mode ) 语法检查( Mx flycheck-mode
    • Warning is orange 警告是橙色
    • Error is red 错误为红色
  • Show Doc of that function/class ( M-? ) 显示该功能/类的文档( M-?

Table of Content : 目录

  • Note 注意
  • Optional Stuff 可选的东西
  • Prerequisites for Installing Spacemacs 安装Spacemacs的先决条件
  • Installation of Spacemacs 安装Spacemacs
  • Prerequisites for Installing Python Layer 安装Python层的先决条件
    • Skip to here to if you already installed spacemacs 如果您已经安装了spacemacs,请跳至此处
  • Installation of Python Layer 安装Python层
  • Testing Python Layer 测试Python层
  • Final Note 最后说明
  • Summary 摘要

Note : 注意事项

  • commandline (Windows) and Terminal (Linux) as Terminal commandline (Windows)和Terminal (Linux)作为Terminal
  • Mx is to hold alt-key and x-key together Mx将Alt键和X键组合在一起

Optional Stuff : 可选的东西

  • Some knowledge on Vim style key-binding* 有关Vim样式键绑定的一些知识*
  • Patience reading through a lot text 耐心阅读大量文字
  • Courage to start from scratch 从头开始的勇气

Prerequisites for Installing Spacemacs : 安装Spacemacs的先决条件

  1. Install Emacs (Version >= 24.5) 安装Emacs (版本> = 24.5)
  2. Install Git 安装Git

Installation of Spacemacs : 安装Spacemacs

  1. Start Emacs and close it. 启动Emacs并关闭它。
  2. Go rename (if any) .emacs.d folder to .emacs.d.bak . .emacs.d文件夹(如果有)重命名为.emacs.d.bak
    • Windows: Should be in %appdata% Windows:应位于%appdata%
    • Linux: Should be in Home directory (Might be hidden) Linux:应位于主目录中(可能是隐藏的)
  3. Open Spacemacs website, click on install Copy the link provided. 打开Spacemacs网站,单击install复制提供的链接。
  4. Open up terminal , paste the link, press enter 打开terminal ,粘贴链接,按enter
  5. Wait for the operation to finish 等待操作完成
  6. Open up emacs 打开emacs

By now you should see: Something like this 现在,您应该看到: 像这样的东西

  1. Follow the Dotfile-wizard-installer 遵循Dotfile-wizard-installer
    • Note: that I use vim **, standard (Spacemacs), heavy and full-feature (Helm) 注意:我使用的是vim **, standard (Spacemacs), heavy and full-feature (Helm)
  2. Get a cup of tea of your choice while spacemacs install some packages 在spacemacs安装一些软件包的同时, tea以供选择
    • Note: If any package fails to install, restart emacs and it should attempt to reinstall the failed packages. 注意:如果任何软件包安装失败,请重新启动emacs,它应尝试重新安装失败的软件包。
  3. Close emacs 关闭emacs

Prerequisites for Installing Python Layer : 安装Python层的先决条件

  1. Python Virtual Environment Python虚拟环境

Installation of Python Layer : 安装Python层

  1. Open emacs 打开emacs
  2. Mx find-file and open a python file Mx find-file并打开python文件
  3. There will be a prompt to install python layer, accept the offer 将提示安装python层,接受报价
  4. Get some cookie while it get packages for python layer 获取一些cookie,同时获取python层的软件包
  5. Close emacs 关闭emacs
  6. Open dotspacemacs file ( .spacemacs ) in any text editor 在任何文本编辑器中打开dotspacemacs文件( .spacemacs
  7. Go to dotspacemacs-configuration-layers and: 转到dotspacemacs-configuration-layers并执行以下操作:
    • Uncomment auto-completion , spell-checking and syntax-checking 取消注释auto-completionspell-checkingsyntax-checking
    • Uncomment mean remove ;; 取消注释意味着删除;; in front 在前
  8. Go to dotspacemacs-additional-packages and add the following between the brackets 转到dotspacemacs-additional-packages并在方括号之间添加以下内容
    • flycheck-pyflakes
    • Pyflakes is for error checking Pyflakes用于错误检查
  9. In terminal , run pip install pyflakes , in virtual environment of your choice terminal ,在您选择的虚拟环境中运行pip install pyflakes
  10. Open emacs and with for it to install some stuff 打开emacs并为其安装一些东西

Testing Python Layer : 测试Python层

  1. Mx pyvenv-workon and choose your prefered environment Mx pyvenv-workon并选择您喜欢的环境
  2. Mx find-file and open a python file and make some errors Mx find-file并打开python文件并出错
  3. Mx linum-mode to show line number Mx linum-mode显示行号
  4. Make a function 发挥作用
    • def asdf4ninja(): pass
  5. Type partial function in like asdf4 asdf4键入部分函数
  6. It should autocomplete for you, otherwise auto-complete with anaconda CMi 它应该为您自动完成,否则使用anaconda CMi自动完成

    • CMi is hold Ctrl , Alt and character i CMi按住CtrlAlt和字符i
  7. In the same file, import hashlib 在同一文件中, import hashlib

  8. Type in the next line hashlib. 输入下一行hashlib. (Note the dot . ) (注意点.

You should see: Something like this 您应该看到: 像这样的东西

Note: The error checking and bottom right py3.4 is the virtual environment I am using 注意:错误检查和右下方的py3.4是我正在使用的虚拟环境

Final Note : 最后说明

  • M-? to show documentation 显示文件
  • You will need to manually 您将需要手动
    • Mx pyvenv-workon to choose environment on start Mx pyvenv-workon在开始时选择环境
    • Mx linum-mode to enable lines Mx linum-mode启用线路
  • Because I don't know how to make layers to automatically enable them 因为我不知道如何制作图层以自动启用它们

Summary : 总结

  • CMi to auto-complete CMi自动完成
  • M-? to show documentation 显示文件
  • place the cursor in the open bracket () to see the function signature 将光标放在方括号()以查看功能签名
  • Read more at spacemacs spacemacs了解更多
  • Enjoy! 请享用!

You can add one more thing in your list 您可以在列表中再添加一件事

Automatic save - (add-hook 'focus-out-hook 'save-buffer) 自动保存- (add-hook 'focus-out-hook 'save-buffer)

In case, your emacs slows down try (global-hl-line-mode -1) in dotspacemacs/user-config 万一您的emacs减慢了dotspacemacs/user-config try (global-hl-line-mode -1)

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

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