5 (add-to-list 'auto-mode-alist '("\\.pyx\\'" . cython-mode))
6 (add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode))
7 (add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode))
10 (defun cython-compile ()
11 "Compile the file via Cython."
13 (let ((cy-buffer (current-buffer)))
15 (compile compile-command)
16 (set (make-local-variable 'cython-buffer) cy-buffer)
17 (add-to-list (make-local-variable 'compilation-finish-functions)
18 'cython-compilation-finish)))
21 (defun cython-compilation-finish (buffer how)
22 "Called when Cython compilation finishes."
23 ;; XXX could annotate source here
26 (defvar cython-mode-map
27 (let ((map (make-sparse-keymap)))
28 ;; Will inherit from `python-mode-map' thanks to define-derived-mode.
29 (define-key map "\C-c\C-c" 'cython-compile)
31 "Keymap used in `cython-mode'.")
33 (defvar cython-font-lock-keywords
34 `(;; new keywords in Cython language
35 (,(regexp-opt '("by" "cdef" "cimport" "cpdef" "ctypedef" "enum" "except?"
36 "extern" "gil" "include" "nogil" "property" "public"
37 "readonly" "struct" "union" "DEF" "IF" "ELIF" "ELSE") 'words)
38 1 font-lock-keyword-face)
39 ;; C and Python types (highlight as builtins)
40 (,(regexp-opt '("NULL" "bint" "char" "dict" "double" "float" "int" "list"
41 "long" "object" "Py_ssize_t" "short" "size_t" "void") 'words)
42 1 font-lock-builtin-face)
43 ;; cdef is used for more than functions, so simply highlighting the next
44 ;; word is problematic. struct, enum and property work though.
45 ("\\<\\(?:struct\\|enum\\)[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
47 ("\\<property[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
48 1 font-lock-function-name-face))
49 "Additional font lock keywords for Cython mode.")
51 (define-derived-mode cython-mode python-mode "Cython"
52 "Major mode for Cython development, derived from Python mode.
55 (setcar font-lock-defaults
56 (append python-font-lock-keywords cython-font-lock-keywords))
57 (set (make-local-variable 'compile-command)
58 (concat "cython -a " buffer-file-name))
59 (add-to-list (make-local-variable 'compilation-finish-functions)
60 'cython-compilation-finish)
63 (provide 'cython-mode)