1 ;; emacs: -*- mode: emacs-lisp; indent-tabs-mode: nil -*-
2 ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;
3 ;
4 ; See COPYING file distributed along with the PyMVPA package for the
5 ; copyright and license terms.
6 ;
7 ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;; ;;
8 ;;
9 ;; This file is to help PyMVPA users who use emacs for their needs.
10 ;; It enables suggested modes (if available), and sets up environment
11 ;; variables needed by Python and pylint
12 ;;
13 ;; Recommended usage:
14 ;;
15 ;; * symlink this file as .emacs.local into the root of PyMVPA project:
16 ;; ln -s doc/misc/emacs .emacs.local
17 ;;
18 ;; * add following snippet into your .emacs to enable loading of local
19 ;; emacs configuration:
20 ;; (push "." load-path) ;add current path
21 ;; (load ".emacs.local" t)
22 ;; (pop load-path) ;clean up
23 ;; * for flymake to work correctly, you would need to have epylint script
24 ;; installed anywhere in the PATH. You can obtain the script from
25 ;;
26 ;; http://git.onerussian.com/?p=etc/emacs.git;a=blob;f=.emacs.d/bin/epylint;hb=HEAD
27 ;;
28 ;; Now, whenever you start emacs in the root directory of PyMVPA project,
29 ;; it should load .emacs.local and setup suggested Emacs environment.
30 ;;
31 ;; Disclaimer: this config file is not extensively tested and was ripped away
32 ;; from Yaroslav's .emacs configuration available from
33 ;; http://git.onerussian.com/?p=etc/emacs.git;a=summary
36 (setenv "PYTHONPATH" (expand-file-name default-directory))
37 (setenv "PYLINTRC" (concat
38 (expand-file-name default-directory)
39 "doc/misc/pylintrc"))
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; Python
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 ;; Set IPython to be the python command and give it arguments
46 (when (locate-library "python-mode")
47 (when (locate-library "ipython")
48 (require 'ipython)
49 (when (locate-library "ansi-color")
50 (add-hook 'py-shell-hook 'my-activate-ansi-colors)))
52 ;; We want pylint call
53 (add-hook 'python-mode-hook
54 '(lambda ()
55 (when (and (stringp (buffer-file-name))
56 (not (string-match ".*/tmp/python-.*" (buffer-file-name))))
58 (when (locate-library "pylint")
59 (load-library "pylint")
60 (local-set-key "\C-xc" 'pylint) )
62 (when (locate-library "pymacs")
63 (load-library "pymacs")
64 (when (pymacs-load "ropemacs" "rope-" t)
65 (ropemacs-mode t)
66 (set ropemacs-guess-project t)))
68 (when (not indent-tabs-mode)
69 (when (locate-library "show-wspace")
70 (when (not show-ws-highlight-tabs-p)
71 (show-ws-toggle-show-tabs))))
73 (when (locate-library "outline")
74 (defun py-outline-level ()
75 "This is so that `current-column` DTRT in otherwise-hidden text"
76 ;; from ada-mode.el
77 (let (buffer-invisibility-spec)
78 (save-excursion
79 (beginning-of-line)
80 (skip-chars-forward "\t ")
81 (/ (current-column) py-indent-offset))))
83 ;; this fragment originally came from the web somewhere, but the outline-regexp
84 ;; was horribly broken and is broken in all instances of this code floating
85 ;; around. Finally fixed by Charl P. Botha
87 ;; enable our level computation
88 (setq outline-level 'py-outline-level)
89 ;;(setq outline-regexp "[^ tn]|[ t]*(def[ t]+|class[ t]+)")
90 ;;(setq outline-regexp "\\([ \t]*\n\\)?[ \t]*\\(if\\|for\\|def\\|class\\)[ \t]+.*[:\\\][ \t]*\\(#.*\\)?$")
91 ;; (setq outline-regexp "\\(^[ \t]*\n\\)?[ \t]*\\(if\\|for\\|def\\|class\\|else\\|elif\\|try\\|except\\|finally\\)")
92 ;; (setq outline-regexp "\\(^[ \t]*\n\\)?[ \t]*\\(def\\|class\\|@\\)")
93 (setq outline-regexp "\\([ \t]*\\(def\\|class\\|@\\)\\|^#\\)")
94 ;; without explicit keywords:
95 ;;(setq outline-regexp "^[ \t\n]*\\([^ \t]+\\)[ \t]+.*[:\\\][ \t]*\\(#.*\\)?$")
96 ;; custom shortcuts
97 ;;(outline-shortcuts)
98 ;; turn on outline mode
99 (outline-minor-mode t)
100 ;; initially hide all but the headers
101 (hide-body)
102 )
104 (show-paren-mode 1)
105 (flymake-mode 1)
106 ))) ;hook
107 ) ;python-mode
109 ;; Lets enable flymake + pylint tandem
110 (when (load "flymake" t)
111 (defun flymake-pylint-init ()
112 (let* ((temp-file (flymake-init-create-temp-buffer-copy
113 'flymake-create-temp-inplace))
114 (local-file (file-relative-name
115 temp-file
116 (file-name-directory buffer-file-name))))
117 (list "epylint" (list local-file))))
119 (add-to-list 'flymake-allowed-file-name-masks
120 '("\\.py\\'" flymake-pylint-init))
122 ;; helper to put pylint errors into the status line
123 ;; borrowed from
124 ;; http://plope.com/Members/chrism/flymake-mode
125 (load "flymake-cursor" t)
127 (add-hook 'find-file-hook 'flymake-find-file-hook)
128 )
130 (setq
131 enable-local-variables t
132 enable-local-eval t
133 search-highlight t ;highlight found matches
134 query-replace-highlight t ;highlight found matches
135 tab-width 4
136 show-trailing-whitespace t ;show trailing spaces by default
137 inhibit-startup-message t ;ok I've seen the copyleft &c
139 )
141 (custom-set-variables
142 '(safe-local-variable-values (quote ((py-indent-offset . 4)))))
