2017년 emacs python 설정

2017. 1. 20. 08:26

1) 들여쓰기 사이즈 조절

(setq-default python-indent-offset 2)


2) company-jedi 설치

company에서 python backend를 추가해주는 것

MELPA에서 company-jedi를 설치하고

(defun company-jedi-hook ()
  (add-to-list 'company-backends 'company-jedi))
(add-hook 'python-mode-hook 'company-jedi-hook)

를 추가

터미널에서
sudo apt-get install python-pip

pip install virtualenv

pip install sexpdata

pip install epc

를 실행한 후 이맥스에서

X-x jedi:install-server


3) ipython을 기본 인터프리터로

아나콘다 패키지 사용시 ipython을 제대로 실행하지 못한다.

(defun set-exec-path-from-shell-PATH ()
  (interactive)
  (let ((path-from-shell (replace-regexp-in-string "^.*\n.*shell\n" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))
(set-exec-path-from-shell-PATH)

를 추가해주고

(setq python-shell-interpreter "ipython"
    python-shell-interpreter-args "--simple-prompt -i")

를 추가해주면 .py파일을 수정하다가 C-c C-p했을 때 ipython이 실행된다.


4) elpy 설치

https://github.com/jorgenschaefer/elpy/wiki/Installation

를보고 emacs side만 따라하면 elpy가 동작한다.

C-c C-z : 인터프리터 켜기

C-c C-c : 버퍼 실행

C-c C-d : 문서 실행


windows환경에서 python 3과 emacs가 제대로 호환되지 않는 문제가 있는 것 같다. C-c C-z할 때마다 오류가 뜨는데, share-emacs-25.1-lisp-progmodes의 python.elc파일을 삭제하고, python.el파일을 연 후 "doesn't seem to"로 위치를 찾은후에 해당 lwarn 프로시져 부분만 주석처리해주면 제대로 동작한다.


5)  make return key as 'newline and indent'

;;general coding settings
(mapc (lambda (mode)
    (let ((hook (intern (concat (symbol-name mode)
                    "-mode-hook"))))
      (add-hook hook (lambda ()
               (autopair-mode +1)
               (local-set-key (kbd "RET") 'newline-and-indent)))))
      '(python c c++))

emacs/for Python