Metalinguistic Abstraction

Computer Languages, Programming, and Free Software

emacs develock customization for Python

with one comment

This has been annoying me for some time: develock mode doesn’t support Python out of the box.  I had a hacked-up develock where I simply changed all references of Ruby (via string-replace) to Python, and things worked pretty well…but I had to constantly load my hacked up develock.

Well, I finally got around to customizing develock properly post-facto, I think.  Rejoice, fellow whitespace pedants.  Here’s the snippet:

;;
;; develock-py.el
;;
;; Made by Daniel Farina
;; Login   <drfarina@acm.org>
;;
;; Started on  Sun Feb 14 09:21:21 2010 Daniel Farina
;; Last update Sun Feb 14 09:27:12 2010 Daniel Farina
;;

(require 'develock)

(defcustom develock-python-font-lock-keywords
 '(;; a long line
 (develock-find-long-lines
 (1 'develock-long-line-1 t)
 (2 'develock-long-line-2 t))
 ;; long spaces
 (develock-find-tab-or-long-space
 (1 'develock-whitespace-2)
 (2 'develock-whitespace-3 nil t))
 ;; trailing whitespace
 ("[^\t\n ]\\([\t ]+\\)$"
 (1 'develock-whitespace-1 t))
 ;; spaces before tabs
 ("\\( +\\)\\(\t+\\)"
 (1 'develock-whitespace-1 t)
 (2 'develock-whitespace-2 t))
 ;; tab space tab
 ("\\(\t\\) \t"
 (1 'develock-whitespace-2 append))
 ;; only tabs or spaces in the line
 ("^[\t ]+$"
 (0 'develock-whitespace-2 append))
 ;; reachable E-mail addresses
 ("<?[-+.0-9A-Z_a-z]+@[-0-9A-Z_a-z]+\\(\\.[-0-9A-Z_a-z]+\\)+>?"
 (0 'develock-reachable-mail-address t))
 ;; things to be paid attention
 ("\\<\\(?:[Ff][Ii][Xx][Mm][Ee]\\|[Tt][Oo][Dd][Oo]\\)\\(?::\\|\\>\\)"
 (0 'develock-attention t)))
 "Extraordinary level highlighting for the Python mode."
 :type develock-keywords-custom-type
 :set 'develock-keywords-custom-set
 :group 'develock
 :group 'font-lock)

(defvar python-font-lock-keywords-x nil
 "Extraordinary level font-lock keywords for the Python mode.")

(setq develock-keywords-alist
 (cons '(python-mode
 python-font-lock-keywords-x
 develock-python-font-lock-keywords)
 develock-keywords-alist))

(plist-put develock-max-column-plist 'python-mode 79)

This text is made available under the license CC0 1.0 Universal (CC0 1.0).

Advertisements

Written by fdr

February 14, 2010 at 9:53 am

Posted in lisp, python

Tagged with , , ,

One Response

Subscribe to comments with RSS.

  1. […] it a very long time. Unfortunately python isn’t supported out of the box, but no worries, someone has done the work already. So all you have to do is something along the lines […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: