-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit-python.el
85 lines (71 loc) · 3.54 KB
/
init-python.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;; autocomplete: dont suggest numbers
;; http://stackoverflow.com/questions/14767277/can-emacs-ac-mode-autocomplete-mode-be-configured-to-ignore-numbers
;; (eval-after-load "auto-complete"
;; '(progn
;; (defun ac-prefix-default ()
;; "Same as `ac-prefix-symbol' but ignore a number prefix."
;; (let ((start (ac-prefix-symbol)))
;; (when (and start
;; (not (string-match "^\\(?:0[xX][0-9A-Fa-f]+\\|[0-9]+\\)$"
;; (buffer-substring-no-properties start (point)))))
;; start)))
;; ))
;; Configure to wait a bit longer after edits before starting
(setq-default flymake-no-changes-timeout '3)
;; Keymaps to navigate to the errors
(add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-cn" 'flymake-goto-next-error)))
(add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-cp" 'flymake-goto-prev-error)))
(add-hook 'python-mode-hook '(lambda () (define-key python-mode-map (kbd "C-c f t") 'flymake-mode)))
(add-hook 'python-mode-hook '(lambda () (visual-line-mode -1))) ;; force disable visual-line-mode
(add-hook 'python-mode-hook '(lambda () (eldoc-mode -1))) ;; force disable eldoc mode
;; To avoid having to mouse hover for the error message, these functions make flymake error messages
;; appear in the minibuffer
;(defun show-fly-err-at-point ()
; "If the cursor is sitting on a flymake error, display the message in the minibuffer"
; (require 'cl)
; (interactive)
; (let ((line-no (line-number-at-pos)))
; (dolist (elem flymake-err-info)
; (if (eq (car elem) line-no)
; (let ((err (car (second elem))))
; (message "%s" (flymake-ler-text err)))))))
;
;(add-hook 'post-command-hook 'show-fly-err-at-point)
(load "~/.emacs.d/lib/flymake-diagnostic-at-point.el")
(require 'flymake-diagnostic-at-point)
(eval-after-load 'flymake
(add-hook 'flymake-mode-hook #'flymake-diagnostic-at-point-mode))
(when (load "flymake" t)
(defun flymake-create-temp-in-system-tempdir (filename prefix)
(make-temp-file (or prefix "flymake")))
(defun flymake-pycheckers-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-in-system-tempdir))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "~/.emacs.d/lib/pycheckers.py" (list temp-file))))
(add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pycheckers-init))
)
;; load flymake automatically for python files
(add-hook 'python-mode-hook (lambda () (flymake-mode)))
(define-coding-system-alias 'UTF-8 'utf-8)
(defun my-py-insert-pdb-trace ()
"Insert PDB trace"
(interactive)
(insert "import pdb; pdb.set_trace()"))
(add-hook 'python-mode-hook (lambda () (local-set-key (kbd "C-c C-t C-t") 'my-py-insert-pdb-trace)))
(setq
python-shell-interpreter "ipython"
python-shell-interpreter-args ""
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion"
python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n"
python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
;; Easier to press these with godmode
(add-hook 'python-mode-hook (lambda () (local-set-key (kbd "C-c C-<") 'python-indent-shift-left)))
(add-hook 'python-mode-hook (lambda () (local-set-key (kbd "C-c C->") 'python-indent-shift-right)))