3 (defvar thrift-mode-hook nil
)
4 (add-to-list 'auto-mode-alist
'("\\.thrift\\'" . thrift-mode
))
6 (defvar thrift-indent-level
2
7 "Defines 2 spaces for thrift indentation.")
10 (defconst thrift-font-lock-keywords
12 '("#.*$" . font-lock-comment-face
) ;; perl style comments
13 '("\\<\\(include\\|struct\\|exception\\|typedef\\|cpp_namespace\\|java_package\\|cocoa_prefix\\|php_namespace\\|ruby_namespace\\|py_module\\|perl_package\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face
) ;; keywords
14 '("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face
) ;; built-in types
15 '("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face
) ;; ordinals
16 '("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face
)) ;; functions
21 (defun thrift-indent-line ()
22 "Indent current line as Thrift code."
27 (let ((not-indented t
) cur-indent
)
28 (if (looking-at "^[ \t]*\\(}\\|throws\\)")
29 (if (looking-at "^[ \t]*}")
33 (setq cur-indent
(- (current-indentation) thrift-indent-level
)))
39 (if (looking-at "^[ \t]*[\\.<>[:word:]]+[ \t]+[\\.<>[:word:]]+[ \t]*(")
40 (setq cur-indent
(+ (current-indentation) thrift-indent-level
))
41 (setq cur-indent
(current-indentation))))))
45 (if (looking-at "^[ \t]*}")
47 (setq cur-indent
(current-indentation))
48 (setq not-indented nil
))
49 (if (looking-at "^.*{[^}]*$")
51 (setq cur-indent
(+ (current-indentation) thrift-indent-level
))
52 (setq not-indented nil
))
54 (setq not-indented nil
)))
55 (if (looking-at "^[ \t]*throws")
57 (setq cur-indent
(- (current-indentation) thrift-indent-level
))
60 (setq not-indented nil
))
62 (setq not-indented nil
)))
63 (if (looking-at "^[ \t]*[\\.<>[:word:]]+[ \t]+[\\.<>[:word:]]+[ \t]*([^)]*$")
65 (setq cur-indent
(+ (current-indentation) thrift-indent-level
))
66 (setq not-indented nil
))
68 (setq not-indented nil
)))
69 (if (looking-at "^[ \t]*\\/\\*")
71 (setq cur-indent
(+ (current-indentation) 1))
72 (setq not-indented nil
))
74 (setq not-indented nil
)))
75 (if (looking-at "^[ \t]*\\*\\/")
77 (setq cur-indent
(- (current-indentation) 1))
78 (setq not-indented nil
))
80 (setq not-indented nil
)))
83 (indent-line-to cur-indent
)
84 (indent-line-to 0)))))
86 ;; C/C++ comments; also allowing underscore in words
87 (defvar thrift-mode-syntax-table
88 (let ((thrift-mode-syntax-table (make-syntax-table)))
89 (modify-syntax-entry ?_
"w" thrift-mode-syntax-table
)
90 (modify-syntax-entry ?
/ ". 124b" thrift-mode-syntax-table
)
91 (modify-syntax-entry ?
* ". 23" thrift-mode-syntax-table
)
92 (modify-syntax-entry ?
\n "> b" thrift-mode-syntax-table
)
93 thrift-mode-syntax-table
)
94 "Syntax table for thrift-mode")
97 "Mode for editing Thrift files"
99 (kill-all-local-variables)
100 (set-syntax-table thrift-mode-syntax-table
)
101 (set (make-local-variable 'font-lock-defaults
) '(thrift-font-lock-keywords))
102 (setq major-mode
'thrift-mode
)
103 (setq mode-name
"Thrift")
104 (run-hooks 'thrift-mode-hook
)
105 (set (make-local-variable 'indent-line-function
) 'thrift-indent-line
)
107 (provide 'thrift-mode
)