emacs 26.2 macOs Mojave 10.14.6 python 3.7.3
在我的emacs_py.el 配置如下: ;;; function definitions (defun elpy-goto-definition-or-rgrep () “Go to the definition of the symbol at point, if found. Otherwise, run `elpy-rgrep-symbol’.” (interactive) (ring-insert find-tag-marker-ring (point-marker)) (condition-case nil (elpy-goto-definition) (error (elpy-rgrep-symbol (concat “\(def\|class\)\s” (thing-at-point 'symbol) “(”)))))
(defun rename-python-symbol-at-point (symbol-name) (interactive "snew symbol name: ") (call-interactively 'elpy-multiedit-python-symbol-at-point) (execute-kbd-macro (kbd “diw”)) (insert symbol-name) (elpy-multiedit-stop) (evil-backward-word-begin))
(defun settings-for-elpy () (flycheck-mode) (setq elpy-project-root initial-directory) (setq elpy-get-info-from-shell t) (setq elpy-shell-display-buffer-after-send t) ;;(setq python-shell-interpreter “ipython” python-shell-interpreter-args “-i --simple-prompt”) ;;(setq python-shell-interpreter “python” python-shell-interpreter-args “-i”) (setq python-shell-interpreter “ipython” python-shell-interpreter-args “–simple-prompt -c exec(‘import(\‘readline\’)’) -i”) (setq elpy-autodoc-delay 0.3) (define-evil-normal-keys (“x” . (make-interactive (elpy-format-code) (save-buffer))) (“f d” . 'elpy-doc) (“f f” . 'xref-find-references) (“f F” . 'xref-find-apropos) (“f g” . 'elpy-pdb-debug-buffer) (“f r” . 'rename-python-symbol-at-point) (“f t” . 'elpy-test) (“j” . (with-marker (elpy-goto-definition-or-rgrep))) (“C-j” . (with-marker (elpy-goto-definition-other-window)))) (define-key elpy-mode-map (kbd “C-c C-e”) 'elpy-shell-send-statement))
(defun settings-for-inferior-python () (linum-mode) (define-key inferior-python-mode-map (kbd “C-c C-z”) 'elpy-shell-switch-to-buffer))
;;; elpy (require 'elpy) (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)) (advice-add 'elpy-shell–insert-and-font-lock :around (lambda (f string face &optional no-font-lock) (if (not (eq face 'comint-highlight-input)) (funcall f string face no-font-lock) (funcall f string face t) (python-shell-font-lock-post-command-hook))))
(advice-add 'comint-send-input :around (lambda (f &rest args) (if (eq major-mode 'inferior-python-mode) (cl-letf ((g (symbol-function 'add-text-properties)) ((symbol-function 'add-text-properties) (lambda (start end properties &optional object) (unless (eq (nth 3 properties) 'comint-highlight-input) (funcall g start end properties object))))) (apply f args)) (apply f args))))
(load-file “~/.emacs.d/rc/ycmd.el”)
(add-programming-hook '((lambda () (setq company-backends '(company-ycmd))) ycmd-mode elpy-mode) 'python-mode-hook)
(add-hook 'elpy-mode-hook 'settings-for-elpy) (add-hook 'inferior-python-mode-hook 'settings-for-inferior-python)
(add-to-list 'modes-need-show-buffer-modified 'python-mode) (setq grep-file-exts '(“*.py”)) (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) (set-language-environment 'utf-8) (set-keyboard-coding-system 'utf-8-mac) ; For old Carbon emacs on OS X only (setq locale-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-terminal-coding-system 'utf-8) (set-selection-coding-system (if (eq system-type 'windows-nt) 'utf-16-le ;; Pasting Unicode characters in Emacs (Windows) - Rufflewind's Scratchpad 'utf-8)) (prefer-coding-system 'utf-8)
(setq-default buffer-file-coding-system 'utf-8) (setenv “PYTHONIOENCODING” “utf-8”) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-language-environment “UTF-8”)