📜 ⬆️ ⬇️

Emacs as an IDE for Python

As you know, there are many solutions that allow you to make a more or less convenient IDE for the Python language from the “console” editor (vim / emacs). I present to your attention the most successful, in my opinion, implementation of the development environment in the emacs editor based on the python-jedi.el package . I note that the bundle replacing rope (* - jedi) is also for vim, an instruction for setting it up can be found here .

image

1. Setup preparation


To set up emacs, you should be aware of the standard configuration file, which is located in ~ / .emacs and the ~ / .emacs.d directory where we will add the plugins.
You should also familiarize yourself with the abbreviations and notation of "hot" keys. Such as C (default Ctrl) and Meta (default Alt). There are also certain rules when writing shortcuts, for example: Ch t This command means that you need to simultaneously press Ctrl and h, release, then t. Full list of "hot" keys.
After you have dealt with the main keys and the order of their use, you can begin to turn the editor into an IDE.

2. Required packages


Of course, besides python-jedi, we will need more such packages as:

Python-jedi itself is an extended auto-complement of the code, i.e. unlike auto-complete , it can also supplement the code that you have not yet entered in this file, for example, the addition of import
')
2.1 Installing packages in Emacs-24

For simple and quick installation of packages in emacs, it is best to use ELPA (Emacs Lisp Package Archive), for this you need to add repositories to the .emacs config file and define the directory where the modules will be loaded from
 (add-to-list 'load-path "~/.emacs.d/") (load "package") (require 'package) (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") ("marmalade" . "http://marmalade-repo.org/packages/") ("melpa" . "http://melpa.milkbox.net/packages/"))) 

After that you can get a list
 Mx: package-list-packages 

and stop installing auto-complete, autopair, flycheck, ipython packages
 Mx: package-install 

However, besides the package, there is an el-get solution, the distinctive feature of which is the ability to automatically download dependencies. To install el-get, go to the * scratch * ( Cx b ) buffer and insert the following lines:
 (url-retrieve "https://raw.github.com/dimitri/el-get/master/el-get-install.el" (lambda (s) (let (el-get-master-branch) (goto-char (point-max)) (eval-print-last-sexp)))) 

then press Cj (this will execute the code), then add the el-get directory to the config with the script reload condition
 (add-to-list 'load-path "~/.emacs.d/el-get/el-get") (unless (require 'el-get nil 'noerror) (with-current-buffer (url-retrieve-synchronously "https://raw.github.com/dimitri/el-get/master/el-get-install.el") (let (el-get-master-branch) (goto-char (point-max)) (eval-print-last-sexp)))) (el-get 'sync) 

Since ido package is already present in emacs 24, then just activate it via .emacs:
 (require 'ido) (ido-mode t) 


2.2 Installing jedi

For python-jedi to work correctly, the python module of virtualenv is needed, in most OSs, by default, it is missing, install via pip:
 pip install virtualenv 

 Mx: el-get-install jedi 

After that we add to the configuration file
 (add-hook 'python-mode-hook 'auto-complete-mode) (add-hook 'python-mode-hook 'jedi:ac-setup) 


2.2 Project navigation

To navigate through the project directory, it is proposed to use emacs-nav
 Mx: el-get-install emacs-nav 

image

3. Additional packages


Additionally, you can install a module to automatically highlight errors and automatically close quotes and brackets. Right .emacs:
 (add-hook 'after-init-hook #'global-flycheck-mode) (require 'autopair) (autopair-global-mode) 

I note that the last (autopair) can create a lot of brackets or quotes when copy-paste, to disable it, you should delete the last two lines.
In order to use ipython as a default shell, add lines
 (setq-default py-shell-name "ipython") (setq-default py-which-bufname "IPython") 


Conclusion


That's all, from a simple editor, we got, by functionality, an IDE with its own package manager and extensibility.
image
Thanks to everyone who read to the end.

Source: https://habr.com/ru/post/188376/


All Articles