Yesterday wrote about the Python coding convention PEP8 ..
While writing Python source code in Emacs, it would be even more useful if PEP8 conformance was constantly checked and visualized.
With Emacs Lisp introduced here, PEP8 conformance violations are always visualized on Emacs as shown below.
Also, only while editing Python, you will be able to see the PEP8 check results in the minibuffer with certain key bindings.
First, prepare Emacs Lisp, which is a prerequisite for developing Python with Emacs.
python-mode.el
There are several major modes in Python, but my recommendation is python-mode.el.
python-mode.el http://www.emacswiki.org/emacs/PythonProgrammingInEmacs
This is the most feature rich.
flymake-cursor.el
Works with flymake, which is the default in Emacs 23 and later, to display a flymake error on the current line in the minibuffer.
flymake-cursor.el https://github.com/illusori/emacs-flymake-cursor
In the article yesterday (when (load "python-pep8") (define-key global-map "\ Cc \ p"'python-pep8)) However, this causes pep8 to be checked by Cc p while editing any file. So it's a good idea to use the python-mode hook and enable it only while editing Python.
With this in mind, write the settings for python-mode in Emacs Lisp as follows:
;; python-Load mode
(when (autoload 'python-mode "python-mode" "Python editing mode." t)
;; python-python only in mode-Enable key bindings for pep8
(setq python-mode-hook
(function (lambda ()
(local-set-key "\C-c\ p" 'python-pep8))))
(setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist (cons '("python" . python-mode)
interpreter-mode-alist)))
;; flymake for python
(add-hook 'python-mode-hook 'flymake-find-file-hook)
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
;;Specify your own shell script introduced yesterday
;;Please edit according to each environment
(list "/usr/local/sbin/pyck" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(load-library "flymake-cursor")
This is the state introduced at the beginning. The error you want to ignore can be specified in the shell script called from above and in python-pep8.
To ignore the error in python-pep8.el, edit Emacs Lisp and pass it as an option in pep8 as follows:
(defcustom python-pep8-options '("--ignore=E302")
"Options to pass to pep8.py"
:type '(repeat string)
:group 'python-pep8)
The settings of Emacs are different for each person, but if you create an environment that is easy for each person to develop based on this content, you will be happier.
Recommended Posts