| | 1 | {{{ |
| | 2 | #!rst |
| | 3 | |
| | 4 | ========================================= |
| | 5 | Configuring Emacs for NumPy/SciPy editing |
| | 6 | ========================================= |
| | 7 | |
| | 8 | .. contents :: |
| | 9 | |
| | 10 | .. note :: |
| | 11 | |
| | 12 | Downloaded lisp (``.el``) files should be placed in a directory on |
| | 13 | the Emacs path. I typically use ``~/elisp`` and add it to the |
| | 14 | search path using |
| | 15 | |
| | 16 | :: |
| | 17 | |
| | 18 | (add-to-list 'load-path "~/elisp") |
| | 19 | |
| | 20 | Essential to producing well-formed code |
| | 21 | ======================================= |
| | 22 | |
| | 23 | Never use tabs |
| | 24 | -------------- |
| | 25 | |
| | 26 | :: |
| | 27 | |
| | 28 | (setq-default indent-tabs-mode nil) |
| | 29 | |
| | 30 | |
| | 31 | Clean up tabs and trailing whitespace |
| | 32 | ------------------------------------- |
| | 33 | |
| | 34 | ``M-x untabify`` |
| | 35 | |
| | 36 | and |
| | 37 | |
| | 38 | ``M-x whitespace-cleanup`` |
| | 39 | |
| | 40 | |
| | 41 | Highlight unnecessary whitespace |
| | 42 | -------------------------------- |
| | 43 | |
| | 44 | Download |
| | 45 | `show-wspace.el <http://www.emacswiki.org/cgi-bin/wiki/show-wspace.el>`__ |
| | 46 | |
| | 47 | :: |
| | 48 | |
| | 49 | ; Show whitespace |
| | 50 | (require 'show-wspace) |
| | 51 | (add-hook 'python-mode-hook 'highlight-tabs) |
| | 52 | (add-hook 'font-lock-mode-hook 'highlight-trailing-whitespace) |
| | 53 | |
| | 54 | Wrap lines longer than 79 characters |
| | 55 | ------------------------------------ |
| | 56 | |
| | 57 | :: |
| | 58 | |
| | 59 | (setq fill-column 79) |
| | 60 | |
| | 61 | The ``fill-paragraph`` command (``M-q`` or ``ESC-q``) also comes in |
| | 62 | handy. |
| | 63 | |
| | 64 | Other useful tools |
| | 65 | ================== |
| | 66 | |
| | 67 | Highlight column 79 |
| | 68 | ------------------- |
| | 69 | |
| | 70 | Prevent lines from exceeding 79 characters in length. |
| | 71 | |
| | 72 | Download |
| | 73 | `column-marker.el <http://www.emacswiki.org/cgi-bin/wiki/column-marker.el>`__ |
| | 74 | |
| | 75 | :: |
| | 76 | |
| | 77 | (require 'column-marker) |
| | 78 | (add-hook 'font-lock-mode-hook (lambda () (interactive) (column-marker-1 80))) |
| | 79 | |
| | 80 | |
| | 81 | Show a ruler with the current column position |
| | 82 | --------------------------------------------- |
| | 83 | |
| | 84 | :: |
| | 85 | |
| | 86 | (require 'ruler-mode) |
| | 87 | (add-hook 'font-lock-mode-hook 'ruler-mode) |
| | 88 | |
| | 89 | Enable restructured text (ReST) editing |
| | 90 | --------------------------------------- |
| | 91 | |
| | 92 | :: |
| | 93 | |
| | 94 | (require 'rst) |
| | 95 | (add-hook 'text-mode-hook 'rst-text-mode-bindings) |
| | 96 | |
| | 97 | Fix outline-mode to work with Python |
| | 98 | ------------------------------------ |
| | 99 | |
| | 100 | :: |
| | 101 | |
| | 102 | (add-hook 'python-mode-hook 'my-python-hook) |
| | 103 | (defun py-outline-level () |
| | 104 | "This is so that `current-column` DTRT in otherwise-hidden text" |
| | 105 | ;; from ada-mode.el |
| | 106 | (let (buffer-invisibility-spec) |
| | 107 | (save-excursion |
| | 108 | (skip-chars-forward "\t ") |
| | 109 | (current-column)))) |
| | 110 | |
| | 111 | :: |
| | 112 | |
| | 113 | ; this fragment originally came from the web somewhere, but the outline-regexp |
| | 114 | ; was horribly broken and is broken in all instances of this code floating |
| | 115 | ; around. Finally fixed by Charl P. Botha |
| | 116 | ; <<a href="http://cpbotha.net/">http://cpbotha.net/</a>> |
| | 117 | (defun my-python-hook () |
| | 118 | (setq outline-regexp "[^ \t\n]\\|[ \t]*\\(def[ \t]+\\|class[ \t]+\\)") |
| | 119 | ; enable our level computation |
| | 120 | (setq outline-level 'py-outline-level) |
| | 121 | ; do not use their \C-c@ prefix, too hard to type. Note this overides |
| | 122 | ;some python mode bindings |
| | 123 | ;(setq outline-minor-mode-prefix "\C-c") |
| | 124 | ; turn on outline mode |
| | 125 | (outline-minor-mode t) |
| | 126 | ; initially hide all but the headers |
| | 127 | ; (hide-body) |
| | 128 | (show-paren-mode 1) |
| | 129 | ) |
| | 130 | }}} |