Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Side by Side Diff: dart/tools/utils/elisp/dart-mode.el

Issue 9836085: Require compile mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 ;;; dart-mode.el --- a Dart mode for emacs based upon CC mode. 1 ;;; dart-mode.el --- a Dart mode for emacs based upon CC mode.
2 2
3 ;; This program is free software; you can redistribute it and/or modify 3 ;; This program is free software; you can redistribute it and/or modify
4 ;; it under the terms of the GNU General Public License as published by 4 ;; it under the terms of the GNU General Public License as published by
5 ;; the Free Software Foundation; either version 2 of the License, or 5 ;; the Free Software Foundation; either version 2 of the License, or
6 ;; (at your option) any later version. 6 ;; (at your option) any later version.
7 ;; 7 ;;
8 ;; This program is distributed in the hope that it will be useful, 8 ;; This program is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details. 11 ;; GNU General Public License for more details.
12 ;; 12 ;;
13 ;; You should have received a copy of the GNU General Public License 13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this program; see the file COPYING. If not, write to 14 ;; along with this program; see the file COPYING. If not, write to
15 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 ;; Boston, MA 02111-1307, USA. 16 ;; Boston, MA 02111-1307, USA.
17 17
18 ;;; Commentary: 18 ;;; Commentary:
19 19
20 ;; This is a basic Dart mode based on Martin Stjernholm's GPL'd 20 ;; This is a basic Dart mode based on Martin Stjernholm's GPL'd
21 ;; derived-mode-ex.el template. It uses cc-mode and falls back on 21 ;; derived-mode-ex.el template. It uses cc-mode and falls back on
22 ;; Java for basic rules. 22 ;; Java for basic rules.
23 ;; 23 ;;
24 ;; Note: The interface used in this file requires CC Mode 5.30 or 24 ;; Note: The interface used in this file requires CC Mode 5.30 or
25 ;; later. 25 ;; later.
26 26
27 ;;; Code: 27 ;;; Code:
28 28
29 (require 'cc-mode) 29 (require 'cc-mode)
30 (require 'compile)
30 31
31 ;; These are only required at compile time to get the sources for the 32 ;; These are only required at compile time to get the sources for the
32 ;; language constants. (The cc-fonts require and the font-lock 33 ;; language constants. (The cc-fonts require and the font-lock
33 ;; related constants could additionally be put inside an 34 ;; related constants could additionally be put inside an
34 ;; (eval-after-load "font-lock" ...) but then some trickery is 35 ;; (eval-after-load "font-lock" ...) but then some trickery is
35 ;; necessary to get them compiled.) 36 ;; necessary to get them compiled.)
36 (eval-when-compile 37 (eval-when-compile
37 (require 'cc-langs) 38 (require 'cc-langs)
38 (require 'cc-fonts)) 39 (require 'cc-fonts))
39 40
40 (eval-and-compile 41 (eval-and-compile
41 ;; Make our mode known to the language constant system. Use Java 42 ;; Make our mode known to the language constant system. Use Java
42 ;; mode as the fallback for the constants we don't change here. 43 ;; mode as the fallback for the constants we don't change here.
43 ;; This needs to be done also at compile time since the language 44 ;; This needs to be done also at compile time since the language
44 ;; constants are evaluated then. 45 ;; constants are evaluated then.
45 (c-add-language 'dart-mode 'java-mode)) 46 (c-add-language 'dart-mode 'java-mode))
46 47
47 ;; Dart has no boolean but a string and a vector type. 48 ;; Dart has no boolean but a string and a vector type.
48 (c-lang-defconst c-primitive-type-kwds 49 (c-lang-defconst c-primitive-type-kwds
49 dart (append '("bool" "var") 50 dart (append '("bool" "var")
50 » (delete "boolean" 51 (delete "boolean"
51 » » ;; Use append to not be destructive on the 52 ;; Use append to not be destructive on the
52 » » ;; return value below. 53 ;; return value below.
53 » » (append 54 (append
54 » » ;; Due to the fallback to Java, we need not give 55 ;; Due to the fallback to Java, we need not give
55 » » ;; a language to `c-lang-const'. 56 ;; a language to `c-lang-const'.
56 » » (c-lang-const c-primitive-type-kwds) 57 (c-lang-const c-primitive-type-kwds)
57 » » nil)))) 58 nil))))
58 59
59 ;; Recognize member init lists after colons in Dart. 60 ;; Recognize member init lists after colons in Dart.
60 (c-lang-defconst c-nonlabel-token-key 61 (c-lang-defconst c-nonlabel-token-key
61 dart (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key))) 62 dart (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
62 63
63 ;; No cpp in this language, but there's still a "#include" directive to 64 ;; No cpp in this language, but there's still a "#include" directive to
64 ;; fontify. (The definitions for the extra keywords above are enough 65 ;; fontify. (The definitions for the extra keywords above are enough
65 ;; to incorporate them into the fontification regexps for types and 66 ;; to incorporate them into the fontification regexps for types and
66 ;; keywords, so no additional font-lock patterns are required.) 67 ;; keywords, so no additional font-lock patterns are required.)
67 (c-lang-defconst c-cpp-matchers 68 (c-lang-defconst c-cpp-matchers
68 dart (cons 69 dart (cons
69 ;; Use the eval form for `font-lock-keywords' to be able to use 70 ;; Use the eval form for `font-lock-keywords' to be able to use
70 ;; the `c-preprocessor-face-name' variable that maps to a 71 ;; the `c-preprocessor-face-name' variable that maps to a
71 ;; suitable face depending on the (X)Emacs version. 72 ;; suitable face depending on the (X)Emacs version.
72 '(eval . (list "^\\s *\\(#include\\)\\>\\(.*\\)" 73 '(eval . (list "^\\s *\\(#include\\)\\>\\(.*\\)"
73 » » (list 1 c-preprocessor-face-name) 74 (list 1 c-preprocessor-face-name)
74 » » '(2 font-lock-string-face))) 75 '(2 font-lock-string-face)))
75 ;; There are some other things in `c-cpp-matchers' besides the 76 ;; There are some other things in `c-cpp-matchers' besides the
76 ;; preprocessor support, so include it. 77 ;; preprocessor support, so include it.
77 (c-lang-const c-cpp-matchers))) 78 (c-lang-const c-cpp-matchers)))
78 79
79 (defcustom dart-font-lock-extra-types nil 80 (defcustom dart-font-lock-extra-types nil
80 "*List of extra types (aside from the type keywords) to recognize in Dart mode . 81 "*List of extra types (aside from the type keywords) to recognize in Dart mode .
81 Each list item should be a regexp matching a single identifier.") 82 Each list item should be a regexp matching a single identifier.")
82 83
83 (defconst dart-font-lock-keywords-1 (c-lang-const c-matchers-1 dart) 84 (defconst dart-font-lock-keywords-1 (c-lang-const c-matchers-1 dart)
84 "Minimal highlighting for Dart mode.") 85 "Minimal highlighting for Dart mode.")
85 86
86 (defconst dart-font-lock-keywords-2 (c-lang-const c-matchers-2 dart) 87 (defconst dart-font-lock-keywords-2 (c-lang-const c-matchers-2 dart)
87 "Fast normal highlighting for Dart mode.") 88 "Fast normal highlighting for Dart mode.")
88 89
89 (defconst dart-font-lock-keywords-3 (c-lang-const c-matchers-3 dart) 90 (defconst dart-font-lock-keywords-3 (c-lang-const c-matchers-3 dart)
90 "Accurate normal highlighting for Dart mode.") 91 "Accurate normal highlighting for Dart mode.")
91 92
92 (defvar dart-font-lock-keywords dart-font-lock-keywords-3 93 (defvar dart-font-lock-keywords dart-font-lock-keywords-3
93 "Default expressions to highlight in Dart mode.") 94 "Default expressions to highlight in Dart mode.")
94 95
95 (defvar dart-mode-syntax-table nil 96 (defvar dart-mode-syntax-table nil
96 "Syntax table used in dart-mode buffers.") 97 "Syntax table used in dart-mode buffers.")
97 (or dart-mode-syntax-table 98 (or dart-mode-syntax-table
98 (setq dart-mode-syntax-table 99 (setq dart-mode-syntax-table
99 » (funcall (c-lang-const c-make-mode-syntax-table dart)))) 100 (funcall (c-lang-const c-make-mode-syntax-table dart))))
100 101
101 (defvar dart-mode-abbrev-table nil 102 (defvar dart-mode-abbrev-table nil
102 "Abbreviation table used in dart-mode buffers.") 103 "Abbreviation table used in dart-mode buffers.")
103 (c-define-abbrev-table 'dart-mode-abbrev-table 104 (c-define-abbrev-table 'dart-mode-abbrev-table
104 ;; Keywords that if they occur first on a line might alter the 105 ;; Keywords that if they occur first on a line might alter the
105 ;; syntactic context, and which therefore should trig reindentation 106 ;; syntactic context, and which therefore should trig reindentation
106 ;; when they are completed. 107 ;; when they are completed.
107 '(("else" "else" c-electric-continued-statement 0) 108 '(("else" "else" c-electric-continued-statement 0)
108 ("while" "while" c-electric-continued-statement 0) 109 ("while" "while" c-electric-continued-statement 0)
109 ("catch" "catch" c-electric-continued-statement 0) 110 ("catch" "catch" c-electric-continued-statement 0)
110 ("finally" "finally" c-electric-continued-statement 0))) 111 ("finally" "finally" c-electric-continued-statement 0)))
111 112
112 (defvar dart-mode-map (let ((map (c-make-inherited-keymap))) 113 (defvar dart-mode-map (let ((map (c-make-inherited-keymap)))
113 » » ;; Add bindings which are only useful for Dart 114 ;; Add bindings which are only useful for Dart
114 » » map) 115 map)
115 "Keymap used in dart-mode buffers.") 116 "Keymap used in dart-mode buffers.")
116 117
117 (easy-menu-define dart-menu dart-mode-map "Dart Mode Commands" 118 (easy-menu-define dart-menu dart-mode-map "Dart Mode Commands"
118 » » ;; Can use `dart' as the language for `c-mode-menu' 119 ;; Can use `dart' as the language for `c-mode-menu'
119 » » ;; since its definition covers any language. In 120 ;; since its definition covers any language. In
120 » » ;; this case the language is used to adapt to the 121 ;; this case the language is used to adapt to the
121 » » ;; nonexistence of a cpp pass and thus removing some 122 ;; nonexistence of a cpp pass and thus removing some
122 » » ;; irrelevant menu alternatives. 123 ;; irrelevant menu alternatives.
123 » » (cons "Dart" (c-lang-const c-mode-menu dart))) 124 (cons "Dart" (c-lang-const c-mode-menu dart)))
124 125
125 ;;;###autoload 126 ;;;###autoload
126 (add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode)) 127 (add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode))
127 128
128 ;;;###autoload 129 ;;;###autoload
129 (defun dart-mode () 130 (defun dart-mode ()
130 "Major mode for editing Dart code. 131 "Major mode for editing Dart code.
131 This is a simple example of a separate mode derived from CC Mode to 132 This is a simple example of a separate mode derived from CC Mode to
132 support a language with syntax similar to C/C++/ObjC/Java/IDL/Pike. 133 support a language with syntax similar to C/C++/ObjC/Java/IDL/Pike.
133 134
134 The hook `c-mode-common-hook' is run with no args at mode 135 The hook `c-mode-common-hook' is run with no args at mode
135 initialization, then `dart-mode-hook'. 136 initialization, then `dart-mode-hook'.
136 137
137 Key bindings: 138 Key bindings:
138 \\{dart-mode-map}" 139 \\{dart-mode-map}"
139 (interactive) 140 (interactive)
140 (kill-all-local-variables) 141 (kill-all-local-variables)
141 (c-initialize-cc-mode t) 142 (c-initialize-cc-mode t)
142 (set-syntax-table dart-mode-syntax-table) 143 (set-syntax-table dart-mode-syntax-table)
143 (setq major-mode 'dart-mode 144 (setq major-mode 'dart-mode
144 » mode-name "Dart" 145 mode-name "Dart"
145 » local-abbrev-table dart-mode-abbrev-table 146 local-abbrev-table dart-mode-abbrev-table
146 » abbrev-mode t) 147 abbrev-mode t)
147 (use-local-map dart-mode-map) 148 (use-local-map dart-mode-map)
148 ;; `c-init-language-vars' is a macro that is expanded at compile 149 ;; `c-init-language-vars' is a macro that is expanded at compile
149 ;; time to a large `setq' with all the language variables and their 150 ;; time to a large `setq' with all the language variables and their
150 ;; customized values for our language. 151 ;; customized values for our language.
151 (c-init-language-vars dart-mode) 152 (c-init-language-vars dart-mode)
152 ;; `c-common-init' initializes most of the components of a CC Mode 153 ;; `c-common-init' initializes most of the components of a CC Mode
153 ;; buffer, including setup of the mode menu, font-lock, etc. 154 ;; buffer, including setup of the mode menu, font-lock, etc.
154 ;; There's also a lower level routine `c-basic-common-init' that 155 ;; There's also a lower level routine `c-basic-common-init' that
155 ;; only makes the necessary initialization to get the syntactic 156 ;; only makes the necessary initialization to get the syntactic
156 ;; analysis and similar things working. 157 ;; analysis and similar things working.
157 (c-common-init 'dart-mode) 158 (c-common-init 'dart-mode)
158 (easy-menu-add dart-menu) 159 (easy-menu-add dart-menu)
159 (run-hooks 'c-mode-common-hook) 160 (run-hooks 'c-mode-common-hook)
160 (run-hooks 'dart-mode-hook) 161 (run-hooks 'dart-mode-hook)
161 (c-update-modeline)) 162 (c-update-modeline))
162 163
163 (add-to-list 'compilation-error-regexp-alist 'dart) 164 (add-to-list 'compilation-error-regexp-alist 'dart)
164 (add-to-list 'compilation-error-regexp-alist-alist '(dart "Function: '[^']*' url : 'file://\\([^']*\\)' line:\\([0-9]*\\) col:\\([0-9]*\\)" 1 2 3)) 165 (add-to-list 'compilation-error-regexp-alist-alist '(dart "Function: '[^']*' url : 'file://\\([^']*\\)' line:\\([0-9]*\\) col:\\([0-9]*\\)" 1 2 3))
165 166
166 (provide 'dart-mode) 167 (provide 'dart-mode)
167 168
168 ;;; dart-mode.el ends here 169 ;;; dart-mode.el ends here
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698