[Python-mode] what to (not) use with python-mode?

Tom Roche Tom_Roche at pobox.com
Fri Oct 7 17:57:37 CEST 2011


python-mode now

* contains pymacs
* does what helpers like the 'ipython' package did (i.e., run `ipython` in an emacs buffer)

and probably more of which I'm not aware. So it's time to clean up my emacs-python configuration, i.e., the file I load from my init.el containing python-related instructions. It now has

tlrPython.el
> (defconst LOCAL-PYTHON-LISP-DIR (concat LOCAL-EMACS-LISP-DIR "/python"))
> (defconst PYTHON-MODE-DIR (concat LOCAL-PYTHON-LISP-DIR "/python-mode"))
> (setq load-path
>   (append
>     (list
>       LOCAL-PYTHON-LISP-DIR
>       PYTHON-MODE-DIR
> ; no longer needed with python-mode >= 6.0.3
> ;      (concat LOCAL-PYTHON-LISP-DIR "/pymacs")
>       (concat LOCAL-PYTHON-LISP-DIR "/pylookup")
>     )
>   load-path)
> ) ; end (setq load-path

> ;;; python-mode: https://launchpad.net/python-mode
> (require 'python-mode)
> (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))

> ; no longer needed with python-mode >= 6.0.3
> ; (require 'ipython)

> ; no longer needed with python-mode >= 6.0.3
> ; ;; pymacs
> ; (autoload 'pymacs-apply "pymacs")
> ; (autoload 'pymacs-call "pymacs")
> ; (autoload 'pymacs-eval "pymacs" nil t)
> ; (autoload 'pymacs-exec "pymacs" nil t)
> ; (autoload 'pymacs-load "pymacs" nil t)
> ; ;; (pymacs-load "ropemacs" "rope-")
> ; ;; (setq ropemacs-enable-autoimport t)

> (require 'comint)
> (define-key comint-mode-map (kbd "M-") 'comint-next-input)
> (define-key comint-mode-map (kbd "M-") 'comint-previous-input)
> (define-key comint-mode-map [down] 'comint-next-matching-input-from-input)
> (define-key comint-mode-map [up] 'comint-previous-matching-input-from-input)

> ;;; pylookup: http://taesoo.org/Opensource/Pylookup
> ;;; following from pylookup-dir/README
> (setq pylookup-dir (concat LOCAL-PYTHON-LISP-DIR "/pylookup"))
> ; (add-to-list 'load-path pylookup-dir) ; done above
> ;; load pylookup @ compile time
> (eval-when-compile (require 'pylookup))
> ;; set executable file and db file
> (setq pylookup-program (concat pylookup-dir "/pylookup.py"))
> (setq pylookup-db-file (concat pylookup-dir "/pylookup.db"))
> ;; to speedup, just load it on demand
> (autoload 'pylookup-lookup "pylookup"
>   "Lookup SEARCH-TERM in the Python HTML indexes." t)
> (autoload 'pylookup-update "pylookup"
>   "Run pylookup-update and create the database at `pylookup-db-file'." t)
> (global-set-key "\C-ch" 'pylookup-lookup)
> ;;; to update offline, see pylookup-dir/README)

> ;;; autopair: http://code.google.com/p/autopair/
> (autoload 'autopair-global-mode "autopair" nil t)
> (autopair-global-mode)
> (add-hook 'lisp-mode-hook
>           #'(lambda () (setq autopair-dont-activate t)))
> (add-hook 'python-mode-hook
>           #'(lambda ()
>             (push '(?' . ?')
>                   (getf autopair-extra-pairs :code))
>             (setq autopair-handle-action-fns
>                   (list #'autopair-default-handle-action
>                         #'autopair-python-triple-quote-action))))

> ;; $ sudo aptitude install pylint pep8
> ;; The following NEW packages will be installed:
> ;; blt{a} pep8 pylint python-logilab-astng{a} python-logilab-common{a} python-tk{a} tcl8.5{a} tk8.5{a}
> ;; 0 packages upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
> ;; Need to get 5,797kB of archives. After unpacking 28.0MB will be used.
> (require 'python-pep8)
> (require 'python-pylint)

> ;;; yasnippet: http://code.google.com/p/yasnippet/
> (require 'yasnippet-bundle)
> (yas/initialize)
> (yas/load-directory (concat LOCAL-PYTHON-LISP-DIR "/my-snippets/"))

> ;;; nose support (for testing): see
> ;;; LOCAL-PYTHON-LISP-DIR/nose.el
> ;;; from
> ;;; https://bitbucket.org/jpellerin/nosemacs/src/0192bf439dc9/nose.el
> (require 'nose)
> ;;; to enable searching for test cases in current directory, `touch setup.py` there (e.g. with `M-x eshell`)
> ;;; following fails as of 29 Jul 11 01:17:03 PM: see
> ;;; https://bitbucket.org/jpellerin/nosemacs/issue/2/adding-py-to-nose-project-root-files-fails
> ;(add-to-list 'nose-project-root-files ".py")
> ;;; default keybindings from nose.el
> (add-hook 'python-mode-hook
>   (lambda ()
>     (local-set-key "\C-ca" 'nosetests-all)
>     (local-set-key "\C-cm" 'nosetests-module)
>     (local-set-key "\C-c." 'nosetests-one)
>     (local-set-key "\C-cpa" 'nosetests-pdb-all)
>     (local-set-key "\C-cpm" 'nosetests-pdb-module)
>     (local-set-key "\C-cp." 'nosetests-pdb-one)))

Has python-mode made any of the above superfluous?

Are there better settings for any of the above?

Also, if there's anything you currently use with emacs when writing python that you'd care to recommend, please do.

TIA, Tom Roche <Tom_Roche at pobox.com>


More information about the Python-mode mailing list