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