Path: blob/master/elisp/emacs-for-python/plugins/cython-mode.el
990 views
;; Cython mode12(require 'python-mode)34(add-to-list 'auto-mode-alist '("\\.pyx\\'" . cython-mode))5(add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode))6(add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode))789(defun cython-compile ()10"Compile the file via Cython."11(interactive)12(let ((cy-buffer (current-buffer)))13(with-current-buffer14(compile compile-command)15(set (make-local-variable 'cython-buffer) cy-buffer)16(add-to-list (make-local-variable 'compilation-finish-functions)17'cython-compilation-finish)))18)1920(defun cython-compilation-finish (buffer how)21"Called when Cython compilation finishes."22;; XXX could annotate source here23)2425(defvar cython-mode-map26(let ((map (make-sparse-keymap)))27;; Will inherit from `python-mode-map' thanks to define-derived-mode.28(define-key map "\C-c\C-c" 'cython-compile)29map)30"Keymap used in `cython-mode'.")3132(defvar cython-font-lock-keywords33`(;; new keywords in Cython language34(,(regexp-opt '("by" "cdef" "cimport" "cpdef" "ctypedef" "enum" "except?"35"extern" "gil" "include" "nogil" "property" "public"36"readonly" "struct" "union" "DEF" "IF" "ELIF" "ELSE") 'words)371 font-lock-keyword-face)38;; C and Python types (highlight as builtins)39(,(regexp-opt '("NULL" "bint" "char" "dict" "double" "float" "int" "list"40"long" "object" "Py_ssize_t" "short" "size_t" "void") 'words)411 font-lock-builtin-face)42;; cdef is used for more than functions, so simply highlighting the next43;; word is problematic. struct, enum and property work though.44("\\<\\(?:struct\\|enum\\)[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"451 py-class-name-face)46("\\<property[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"471 font-lock-function-name-face))48"Additional font lock keywords for Cython mode.")4950(define-derived-mode cython-mode python-mode "Cython"51"Major mode for Cython development, derived from Python mode.5253\\{cython-mode-map}"54(setcar font-lock-defaults55(append python-font-lock-keywords cython-font-lock-keywords))56(set (make-local-variable 'compile-command)57(concat "cython -a " buffer-file-name))58(add-to-list (make-local-variable 'compilation-finish-functions)59'cython-compilation-finish)60)6162(provide 'cython-mode)636465