From: W. Trevor King Date: Tue, 29 Nov 2011 12:08:37 +0000 (-0500) Subject: Add cython-mode.el to emacs packages. X-Git-Tag: v0.3~46 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cad9bfd8e9518f04252fa8a1adddb6eab9b7285e;p=dotfiles-framework.git Add cython-mode.el to emacs packages. This is a fresh download from the Cython repository: https://raw.github.com/cython/cython/master/Tools/cython-mode.el --- diff --git a/src/.emacs.d/load/cython-mode.el b/src/.emacs.d/load/cython-mode.el new file mode 100644 index 0000000..66a2d5e --- /dev/null +++ b/src/.emacs.d/load/cython-mode.el @@ -0,0 +1,65 @@ +;; Cython mode + +;; Load python-mode if available, otherwise use builtin emacs python package +(when (not(require 'python-mode nil t)) + (require 'python)) + +(add-to-list 'auto-mode-alist '("\\.pyx\\'" . cython-mode)) +(add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode)) +(add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode)) + + +(defun cython-compile () + "Compile the file via Cython." + (interactive) + (let ((cy-buffer (current-buffer))) + (with-current-buffer + (compile compile-command) + (set (make-local-variable 'cython-buffer) cy-buffer) + (add-to-list (make-local-variable 'compilation-finish-functions) + 'cython-compilation-finish))) + ) + +(defun cython-compilation-finish (buffer how) + "Called when Cython compilation finishes." + ;; XXX could annotate source here + ) + +(defvar cython-mode-map + (let ((map (make-sparse-keymap))) + ;; Will inherit from `python-mode-map' thanks to define-derived-mode. + (define-key map "\C-c\C-c" 'cython-compile) + map) + "Keymap used in `cython-mode'.") + +(defvar cython-font-lock-keywords + `(;; new keywords in Cython language + (,(regexp-opt '("by" "cdef" "cimport" "cpdef" "ctypedef" "enum" "except?" + "extern" "gil" "include" "nogil" "property" "public" + "readonly" "struct" "union" "DEF" "IF" "ELIF" "ELSE") 'words) + 1 font-lock-keyword-face) + ;; C and Python types (highlight as builtins) + (,(regexp-opt '("NULL" "bint" "char" "dict" "double" "float" "int" "list" + "long" "object" "Py_ssize_t" "short" "size_t" "void") 'words) + 1 font-lock-builtin-face) + ;; cdef is used for more than functions, so simply highlighting the next + ;; word is problematic. struct, enum and property work though. + ("\\<\\(?:struct\\|enum\\)[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" + 1 py-class-name-face) + ("\\