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