简体   繁体   中英

Customizing emacs like pycharm IDE

I am newbie to Emacs. I mostly work in python (specifically twisted) & trying to configure it more like Pycharm IDE. I installed package 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). But I am trying to make it more like Pycharm.

Has anybody greater luck with this ? Why pycharm is so good in case of autocompletion and finding definitions/sources of functions/classes ? Also Can we configure virtualenv in emacs ?

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!. And hopefully this is can be useful for those never used emacs before as well. 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 )

Final Result Should Have (Check the image at the end):

  • Auto-complete ( CMi )
  • Line number ( Mx linum-mode )
  • Python Virtual Environment ( Mx pyvenv-workon )
  • Syntax-checking ( Mx flycheck-mode )
    • Warning is orange
    • Error is red
  • Show Doc of that function/class ( M-? )

Table of Content :

  • Note
  • Optional Stuff
  • Prerequisites for Installing Spacemacs
  • Installation of Spacemacs
  • Prerequisites for Installing Python Layer
    • Skip to here to if you already installed spacemacs
  • Installation of Python Layer
  • Testing Python Layer
  • Final Note
  • Summary

Note :

  • commandline (Windows) and Terminal (Linux) as Terminal
  • Mx is to hold alt-key and x-key together

Optional Stuff :

  • Some knowledge on Vim style key-binding*
  • Patience reading through a lot text
  • Courage to start from scratch

Prerequisites for Installing Spacemacs :

  1. Install Emacs (Version >= 24.5)
  2. Install Git

Installation of Spacemacs :

  1. Start Emacs and close it.
  2. Go rename (if any) .emacs.d folder to .emacs.d.bak .
    • Windows: Should be in %appdata%
    • Linux: Should be in Home directory (Might be hidden)
  3. Open Spacemacs website, click on install Copy the link provided.
  4. Open up terminal , paste the link, press enter
  5. Wait for the operation to finish
  6. Open up emacs

By now you should see: Something like this

  1. Follow the Dotfile-wizard-installer
    • Note: that I use vim **, standard (Spacemacs), heavy and full-feature (Helm)
  2. Get a cup of tea of your choice while spacemacs install some packages
    • Note: If any package fails to install, restart emacs and it should attempt to reinstall the failed packages.
  3. Close emacs

Prerequisites for Installing Python Layer :

  1. Python Virtual Environment

Installation of Python Layer :

  1. Open emacs
  2. Mx find-file and open a python file
  3. There will be a prompt to install python layer, accept the offer
  4. Get some cookie while it get packages for python layer
  5. Close emacs
  6. Open dotspacemacs file ( .spacemacs ) in any text editor
  7. Go to dotspacemacs-configuration-layers and:
    • Uncomment auto-completion , spell-checking and syntax-checking
    • Uncomment mean remove ;; in front
  8. Go to dotspacemacs-additional-packages and add the following between the brackets
    • flycheck-pyflakes
    • Pyflakes is for error checking
  9. In terminal , run pip install pyflakes , in virtual environment of your choice
  10. Open emacs and with for it to install some stuff

Testing Python Layer :

  1. Mx pyvenv-workon and choose your prefered environment
  2. Mx find-file and open a python file and make some errors
  3. Mx linum-mode to show line number
  4. Make a function
    • def asdf4ninja(): pass
  5. Type partial function in like asdf4
  6. It should autocomplete for you, otherwise auto-complete with anaconda CMi

    • CMi is hold Ctrl , Alt and character i
  7. In the same file, import hashlib

  8. Type in the next line 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

Final Note :

  • M-? to show documentation
  • You will need to manually
    • Mx pyvenv-workon to choose environment on start
    • Mx linum-mode to enable lines
  • Because I don't know how to make layers to automatically enable them

Summary :

  • CMi to auto-complete
  • M-? to show documentation
  • place the cursor in the open bracket () to see the function signature
  • Read more at spacemacs
  • Enjoy!

You can add one more thing in your list

Automatic save - (add-hook 'focus-out-hook 'save-buffer)

In case, your emacs slows down try (global-hl-line-mode -1) in dotspacemacs/user-config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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