dotfiles / emacs.d / mspython.el

Full commit
;;; My python configuration
;; Highlights
;; + Pyflakes
;; + Support for syntax highlighting in common files like tap, tac, tml, yaml
;; + Pymacs + Rope for Refactoring, Completion, Help at Point, etc
;;  *
;;  *

(add-to-list 'auto-mode-alist '("\\.tap\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.tac\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.tml\\'" . python-mode))

;; configure hooks to run pyflakes automatically with flymake mode:
;; NOTE: this is super sweet
(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
           (local-file (file-relative-name
                        (file-name-directory buffer-file-name))))
      (list "pyflakes" (list local-file))))
;; If you need to change the xml command you can do it be defining a flymake-xml-init function:
  ;; (defun flymake-xml-init ()
  ;;   (list "/usr/local/bin/xml" (list "validate --err" (flymake-init-create-temp-buffer-copy
  ;;                                           ;'flymake-create-temp-inplace
  ;;                                           'flymake-create-temp-with-folder-structure
  ;;                                           ))))
  (delete '("\\.html?\\'" flymake-xml-init) flymake-allowed-file-name-masks)
  (delete '("\\.xml?\\'" flymake-xml-init) flymake-allowed-file-name-masks)
  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pyflakes-init)))
(add-hook 'find-file-hook 'flymake-find-file-hook)

;; run pyflakes(instead of pychecker) manually with C-c C-w:
;; python-mode.el from python
(setq py-pychecker-command "pyflakes")
(setq py-pychecker-command-args "")
;; python.el from emacs
(setq python-check-command "pyflakes")

;; Subword mode might make navigating CapWords / camelCaseWords a bit nicer:
(add-hook 'python-mode-hook (lambda () (subword-mode 1)))

;; Spell checking could be helpful as well:
(add-hook 'rst-mode-hook (lambda () (flyspell-mode 1)))

;; TODO: Probably shouldn't be python specific:
(require 'mstest)

;; YAML mode:
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))

;; Let's try treating psp files as xml?
(add-to-list 'auto-mode-alist '("\\.psp\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.jinja2\\'" . nxml-mode))
;;(add-to-list 'auto-mode-alist '("\\.jsp\\'" . jsp-mode))

;; Pymacs
;;  Provides elisp to python bridge allowing you to call elisp from
;;  python and vice versa.  Also enables extensions to Emacs through
;;  Python code.
;;  see ~/etc/
;; (require 'pymacs)
;; (autoload 'pymacs "pymacs" nil t)
;; (autoload 'pymacs-load "pymacs" nil t)
;; (autoload 'pymacs-eval "pymacs" nil t)
;; (autoload 'pymacs-apply "pymacs")
;; (autoload 'pymacs-call "pymacs")

;; Rope and RopeEmacs
;; Refactoring and Autocompletion
;; Although I'm only using Rope for Python it is
;; a general library and can be used with other languages.
;; set ~/etc/
;;(pymacs-load "ropemacs" "rope-")