;; xemacs config for using python-mode.el (provide 'python) (message "loading python.el") ;; font lock options (require 'font-lock) (setq font-lock-support-mode 'font-lock-mode) (setq font-lock-maximum-decoration t) (setq global-font-lock-mode t) (setq python-mode-hook '(font-lock-mode)) (set-face-foreground 'font-lock-function-name-face (make-color-specifier "#000088")) (set-face-underline-p 'font-lock-function-name-face nil) (set-face-foreground 'font-lock-type-face ;; class names (make-color-specifier "#000088")) (set-face-underline-p 'font-lock-type-face t) (require 'autoload) (require 'python-mode) (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) (add-to-list 'auto-mode-alist '("\\.ptl\\'" . python-mode)) ;; Highlight trailing whitespace. ;; I like to use this with a color that is almost the same as my background. (make-face 'trailing-space) (set-face-background 'trailing-space (make-color-specifier "#d4d4d4")) (add-to-list 'python-font-lock-keywords '("\\([ \t]+$\\)" 1 trailing-space)) ;; Highlight bad trailing whitespace. (make-face 'bad-trailing-space) (set-face-background 'bad-trailing-space (make-color-specifier "#ff8888")) (add-to-list 'python-font-lock-keywords '("[^\n\t ]\\([ \t][ \t]+$\\)" 1 bad-trailing-space)) ;; Highlight characters beyond the pale. (make-face 'too-long) (set-face-background 'too-long (make-color-specifier "#ffff88")) (add-to-list 'python-font-lock-keywords '("[^\n]\\{80\\}\\([^\n]*\\)$" 1 too-long)) ;; Highlight wretched characters. (make-face 'wretched) (set-face-background 'wretched (make-color-specifier "#6666ff")) (add-to-list 'python-font-lock-keywords '("\\([\t]+\\)" 1 wretched)) (add-to-list 'python-font-lock-keywords '("^[ \t]*\\(template\\)[ \t]+[a-zA-Z_]" 1 font-lock-keyword-face)) ;; other (setq column-number-mode t) (setq line-number-mode t) (setq indent-tabs-mode nil) (defun de-trail () ;; Remove trailing whitespace (interactive) (goto-char 0) (replace-regexp "[ \t]+$" "") ) (defun python-nav () (interactive) (let ((start (save-excursion (re-search-backward "^[^ \t\n#]" nil t)))) (save-excursion (let ((result nil) (name nil) (indentation nil)) (while (re-search-backward "^\\( *\\)\\(def\\|class\\)\\b *\\([a-zA-Z_]+\\)" start t) (if (or (null indentation) (< (length (match-string 1)) (length indentation))) (setq indentation (match-string 1) name (match-string 3) result (if result (concat name "." result) name)))) result)))) (defvar modeline-format-default modeline-format) (defun python-modeline () (interactive) (setq modeline-format (list "" (cons modeline-modified-extent 'modeline-modified) (cons modeline-buffer-id-extent 'modeline-buffer-identification) " " (cons 12 "(%p L%l %c) ") (python-nav) )) modeline-format) (defun py-hook () (add-local-hook 'post-command-hook (function python-modeline))) (setq python-mode-hook (function py-hook))