[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode 199709f 148/192: Removes cc-mode
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode 199709f 148/192: Removes cc-mode |
Date: |
Sun, 29 Aug 2021 11:02:07 -0400 (EDT) |
branch: elpa/dart-mode
commit 199709f7b456607773d641a1fd046e18e6597f3f
Author: bradyt <bradyt@users.noreply.github.com>
Commit: Brady Trainor <mail@bradyt.com>
Removes cc-mode
Almost everything with mention of `cc-*` or `c-*` has been removed.
The following has been changed to replace `cc-mode`.
- For `M-;` to work, `comment-start` and `comment-end` have been
added.
- For `font-lock` to highlight comments and single quoted strings, the
syntax table has changes at `//`, `\n`, and `'`.
- For now, only syntax highlighting of several keywords, and numbers,
have been added. Highlighting of variables, functions, classes, etc,
should be straightforward, perhaps after agreement on whether it's
just declarations and definitions, etc. The number regex can be
improved to match specification in ECMA for Dart.
- Electric indent occurs on `RET`, `)`, `]`, and `}`.
- Indentation function seems to be very simple after all. It uses
`syntax-ppss` to check depth in open parentheses, then decrements
depth if first non-whitespace char is a closing paren, and
multiplies this by the `tab-width` (`tab-width` of course is two).
Current indent-line-function behavior, together with existing
`dart-formatter` should be convenient enough for users.
---
dart-mode.el | 441 ++++++++---------------------------------------------------
1 file changed, 60 insertions(+), 381 deletions(-)
diff --git a/dart-mode.el b/dart-mode.el
index 8a0e8b9..4297cdd 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -78,16 +78,6 @@
;;; Code:
-(require 'cc-mode)
-(eval-when-compile
- (and (= emacs-major-version 24)
- (>= emacs-minor-version 4)
- (require 'cl))
- (require 'cc-langs)
- (require 'cc-fonts))
-
-(eval-and-compile (c-add-language 'dart-mode 'java-mode))
-
(require 'cl-lib)
(require 'compile)
(require 'dash)
@@ -95,10 +85,9 @@
(require 'flycheck))
(require 'help-mode)
(require 'json)
+(require 'rx)
(require 's)
-(add-to-list 'c-require-final-newline '(dart-mode . t))
-
;;; Utility functions and macros
(defun dart-beginning-of-statement ()
@@ -306,174 +295,9 @@ Returns nil if `dart-sdk-path' is nil."
"dart"))))
-;;; CC configuration
-
-(c-lang-defconst c-symbol-start
- dart (concat "[" c-alpha "_]"))
-
-(c-lang-defconst c-identifier-ops
- dart nil)
-
-(c-lang-defconst c-after-id-concat-ops
- dart nil)
-
-(c-lang-defconst c-multiline-string-start-char
- dart ?@)
-
-(c-lang-defconst c-opt-cpp-prefix
- dart "\\s *#\\s *")
-
-(c-lang-defconst c-cpp-message-directives
- dart nil)
-
-(c-lang-defconst c-cpp-include-directives
- dart nil)
-
-(c-lang-defconst c-opt-cpp-macro-define
- dart nil)
-
-(c-lang-defconst c-cpp-expr-directives
- dart '("import" "source" "library" "resource"))
-
-(c-lang-defconst c-cpp-expr-functions
- dart nil)
-
-(c-lang-defconst c-operators
- dart `((prefix "#")
- (postfix-if-paren "<" ">")
- (prefix "super")
- (left-assoc ".")
- (postfix "++" "--" "[" "]" "(" ")")
- (unary "++" "--" "+" "-" "!" "~" "negate" "new" "const")
- (left-assoc "*" "/" "%")
- (left-assoc "+" "-")
- (left-assoc "<<" ">>" ">>>")
- (left-assoc "<" ">" "<=" ">=")
- (left-assoc "==" "!=" "===" "!==" "is" "is!")
- (left-assoc "&")
- (left-assoc "^")
- (left-assoc "|")
- (left-assoc "&&")
- (left-assoc "||")
- (right-assoc-sequence "?" ":")
- (left-assoc "=>")
- (right-assoc ,@(c-lang-const c-assignment-operators))
- (left-assoc ",")))
-
-(c-lang-defconst c-overloadable-operators
- dart '("==" "<" ">" "<=" ">=" "-" "+" "*" "/" "%" "|" "^" "&"
- "<<" ">>" ">>>" "[]=" "[]" "~" "negate"))
-
-(c-lang-defconst c-opt-op-identifier-prefix
- dart (c-make-keywords-re t '("operator")))
-
-(c-lang-defconst c-doc-comment-start-regexp
- dart nil)
-
-(c-lang-defconst c-paragraph-start
- dart "$")
-
-(c-lang-defconst c-primitive-type-kwds
- dart '("Dynamic" "void" "num" "int" "double" "bool"))
-
-(c-lang-defconst c-class-decl-kwds
- dart '("class" "interface"))
-
-;; Don't put these in c-modifier-kwds because they can be used without a type
-;; following them.
-(c-lang-defconst c-typeless-decl-kwds
- dart '("abstract" "const" "factory" "final" "operator" "static" "typedef"
"var"))
-
-(c-lang-defconst c-modifier-kwds
- dart nil)
-
-(c-lang-defconst c-other-decl-kwds
- dart nil)
-
-(c-lang-defconst c-decl-hangon-kwds
- dart '("get" "set" "native"))
-
-(c-lang-defconst c-postfix-decl-spec-kwds
- dart '("extends" "implements" "factory"))
-
-(c-lang-defconst c-type-list-kwds
- dart '("new" "const" "is" "is!" "extends" "implements" "factory"))
-
-(c-lang-defconst c-ref-list-kwds
- dart nil)
-
-(c-lang-defconst c-block-stmt-2-kwds
- dart '("for" "if" "switch" "while" "catch"))
-
-(c-lang-defconst c-simple-stmt-kwds
- dart '("break" "continue" "return" "throw"))
-
-(c-lang-defconst c-before-label-kwds
- dart '("break" "continue"))
-
-(c-lang-defconst c-nonlabel-token-key
- dart (concat (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key))))
+;;; Configuration
-(c-lang-defconst c-inexpr-class-kwds
- dart nil)
-
-(c-lang-defconst c-inexpr-brace-list-kwds
- dart nil)
-
-(c-lang-defconst c-other-kwds
- dart '("in"))
-
-(c-lang-defconst c-decl-prefix-re
- dart "\\([\{\}\([;,<]+\\)")
-
-(c-lang-defconst c-cast-parens
- dart nil)
-
-(c-lang-defconst c-block-prefix-disallowed-chars
- dart (cl-set-difference (c-lang-const c-block-prefix-disallowed-chars)
- '(?\" ?')))
-
-(c-lang-defconst c-type-decl-prefix-key
- dart "\\(\(\\)\\([^=]\\|$\\)")
-
-(c-lang-defconst c-after-suffixed-type-decl-key
- dart (concat (c-lang-const c-after-suffixed-type-decl-key) "\\|:"))
-
-(c-lang-defconst c-opt-type-suffix-key
- dart nil)
-
-(c-lang-defconst c-recognize-typeless-decls
- dart t)
-
-(c-lang-defconst c-recognize-<>-arglists
- dart t)
-
-(c-lang-defconst c-opt-postfix-decl-spec-kwds
- dart '("native"))
-
-(c-lang-defconst c-opt-postfix-decl-spec-kwds
- dart '("native"))
-
-(push '(dart-brace-list-cont-nonempty . 0)
- (get 'c-offsets-alist 'c-stylevar-fallback))
-
-(defconst dart-c-style
- '("java"
- (c-basic-offset . 2)
- (indent-tabs-mode . nil)
- (fill-column . 80)
- (c-offsets-alist . ((arglist-intro . ++)
- (arglist-cont-nonempty . ++)
- (statement-block-intro . dart-block-offset)
- (block-close . dart-block-offset)
- (dart-brace-list-cont-nonempty .
- dart-brace-list-cont-nonempty-offset)
- (case-label . +))))
- "The default Dart styles.")
-
-(c-add-style "dart" dart-c-style)
-
-(defvar dart-mode-map (c-make-inherited-keymap)
+(defvar dart-mode-map (make-sparse-keymap)
"Keymap used in dart-mode buffers.")
(define-key dart-mode-map (kbd "C-c ?") 'dart-show-hover)
(define-key dart-mode-map (kbd "C-c C-g") 'dart-goto)
@@ -485,172 +309,52 @@ Returns nil if `dart-sdk-path' is nil."
(define-key dart-mode-map (kbd "M-/") 'dart-expand)
(define-key dart-mode-map (kbd "M-?") 'dart-expand-parameters)
-;;; CC indentation support
-
-(defun dart-block-offset (info)
- "Calculate the correct indentation for inline functions.
-
-When indenting inline functions, we want to pretend that
-functions taking them as parameters essentially don't exist."
- (cl-destructuring-bind (syntax . anchor) info
- (let ((arglist-count
- (cl-loop for (symbol . _) in c-syntactic-context
- count (eq symbol 'arglist-cont-nonempty))))
- (if (> arglist-count 0)
- (- (* -1 c-basic-offset arglist-count)
- (if (eq syntax 'block-close) c-basic-offset 0))
- (if (eq syntax 'block-close) 0 '+)))))
-
-(defun dart-brace-list-cont-nonempty-offset (info)
- "Indent a brace-list line in the same style as arglist-cont-nonempty.
-This could be either an actual brace-list or an optional parameter."
- (cl-destructuring-bind (_ . anchor) info
- ;; If we're in a function definition with optional arguments, indent as if
- ;; the brace wasn't there. Currently this misses the in-function function
- ;; definition, but that's probably acceptable.
- (if (and
- (save-excursion (backward-up-list) (eq (char-after) ?\[))
- (assq 'topmost-intro
- (save-excursion (goto-char anchor) (c-guess-basic-syntax))))
- '++
- ;; Otherwise, we're in an actual brace list, in which case only indent
- ;; once.
- '+)))
-
-(defun dart-in-block-p (syntax-guess)
- "Return whether or not the immediately enclosing {} block is a code block.
-The other option, of course, is a map literal.
-
-SYNTAX-GUESS is the output of `c-guess-basic-syntax'."
- (save-excursion
- (c-safe
- ;; If we're in a continued statement within a class, we want to know
we're
- ;; in a class so we can return true.
- (when (eq 'statement-cont (caar syntax-guess))
- (save-excursion
- (c-beginning-of-statement-1 nil t t)
- (setq syntax-guess (c-guess-basic-syntax))))
-
- (backward-up-list)
- (when (= (char-after) ?\{)
- (c-backward-comments)
- (or
- ;; Both anonymous and named functions have a ")" immediately before
the
- ;; code block.
- (= (char-before) ?\))
- ;; "else" and "try" are the only keywords that come immediately before
- ;; a block. Look only back at most 4 characters (the length of
- ;; "else") for performance reasons.
- (looking-back "\\<\\(else\\|try\\)\\>" (- (point) 4))
- ;; CC is good at figuring out if we're in a class.
- (assq 'inclass syntax-guess))))))
-
-(defadvice c-guess-basic-syntax (after dart-guess-basic-syntax activate)
- (when (c-major-mode-is 'dart-mode)
- (let* ((syntax (car (last ad-return-value)))
- (type (car syntax)))
- (save-excursion
- (back-to-indentation)
- (or
- ;; Handle indentation in a constructor with an initializer on a
- ;; separate line.
- (when (memq type '(defun-block-intro inline-close))
- (save-excursion
- (c-safe
- (goto-char (cadr syntax))
- (when (= (char-after) ?:)
- (c-beginning-of-statement-1)
- (setq ad-return-value `((,type ,(point))))
- t))))
-
- ;; Handle array literal indentation
- (when (memq type
- '(arglist-intro
- arglist-cont
- arglist-cont-nonempty
- arglist-close))
- (save-excursion
- (c-safe
- (backward-up-list)
- (when (= (char-after) ?\[)
- (setq ad-return-value
- `((,(cl-case type
- (arglist-intro 'brace-list-intro)
- (arglist-cont 'brace-list-entry)
- (arglist-cont-nonempty
'dart-brace-list-cont-nonempty)
- (arglist-close 'brace-list-close))
- ,(cadr syntax)))))
- t)))
-
- ;; Handle map literal indentation
- (when (and (memq type '(label statement-block-intro statement-cont
statement
- block-close defun-block-intro defun-close))
- (not (dart-in-block-p ad-return-value)))
- (save-excursion
- (c-safe
- (if (= (char-after) ?\})
- (progn
- (backward-up-list)
- (when (= (char-after) ?\{)
- (back-to-indentation)
- (setq ad-return-value `((brace-list-close ,(point))))))
- (c-backward-comments)
- ;; Completely reset ad-return-value here because otherwise it
- ;; gets super-screwy.
- (if (= (char-before) ?\{)
- (progn
- (back-to-indentation)
- (setq ad-return-value `((brace-list-intro ,(point))))
- t)
- (backward-up-list)
- (when (= (char-after) ?\{)
- (forward-char)
- (let ((contp (not (looking-at "\\s-*$"))))
- (c-forward-comments)
- (back-to-indentation)
- (setq ad-return-value
- `((,(if contp 'dart-brace-list-cont-nonempty
- 'brace-list-entry)
- ,(point))))
- t))))))))))))
-
-(defadvice c-inside-bracelist-p (after dart-inside-bracelist-p activate)
- ;; This function is only called within c-guess-basic-syntax. Since we do all
- ;; out brace-list detection in our advice, we just never report being in a
- ;; bracelist there.
- (when (c-major-mode-is 'dart-mode)
- (setq ad-return-value nil)))
-
-(defadvice c-search-decl-header-end (around dart-search-decl-header-end
activate)
- (if (not (c-major-mode-is 'dart-mode)) ad-do-it
- (let ((base (point)))
- (while (and
- (c-syntactic-re-search-forward "[;{=:]" nil 'move t t)
- (c-end-of-current-token base))
- (setq base (point)))
- ;; If we hit :, we're in a member initialization list and we want to
- ;; ignore = signs.
- (when (= (char-before) ?:)
- (while (and
- (c-syntactic-re-search-forward "[;{]" nil 'move t t)
- (c-end-of-current-token base))
- (setq base (point)))))))
-
-(if (fboundp 'c-parse-state-1)
- (defadvice c-parse-state (around dart-c-parse-state activate)
- (if (not (c-major-mode-is 'dart-mode)) ad-do-it
- ;; c-parse-state is a wrapper around c-parse-state-1 that does some
tricks
- ;; to ensure that dangling brackets in preprocessor commands don't screw
up
- ;; parse information for the real world. In Dart, all "preprocessor"
- ;; directives have matched braces, so we don't need to worry about that.
The
- ;; wrapper was also screwing up indentation in weird ways, so we just
ignore
- ;; it.
- (setq ad-return-value (c-parse-state-1)))))
+;;; Indentation support
+
+(defun dart-indent-line-function ()
+ (let (pt)
+ (save-excursion
+ (back-to-indentation)
+ (let ((depth (car (syntax-ppss))))
+ (if (= (char-syntax (char-after)) ?\))
+ (setq depth (1- depth)))
+ (indent-line-to (* depth tab-width)))
+ (setq pt (point)))
+ (when (< (point) pt)
+ (back-to-indentation))))
;;; Additional fontification support
+(setq dart--builtins
+ ;; ECMA 408; Section: Identifier Reference
+ ;; "Built-in identifiers"
+ '("abstract" "as" "deferred" "dynamic" "export" "external"
+ "factory" "get" "implements" "import" "library" "operator"
+ "part" "set" "static" "typedef"))
+
+(setq dart--keywords
+ ;; ECMA 408; Section: Reserved Words
+ '("assert" "break" "case" "catch" "class" "const" "continue"
+ "default" "do" "else" "enum" "extends" "false" "final"
+ "finally" "for" "if" "in" "is" "new" "null" "rethrow" "return"
+ "super" "switch" "this" "throw" "true" "try" "var" "void"
+ "while" "with"))
+
+(setq dart--types '("double" "int" "num" "string"))
+
+(setq dart--number-re
+ (rx (and symbol-start
+ (one-or-more digit)
+ (zero-or-one (and "." (one-or-more digit))))))
+
+(setq dart-font-lock-defaults
+ `((,(regexp-opt dart--keywords 'words)
+ (,(regexp-opt dart--builtins 'words) . font-lock-builtin-face)
+ (,dart--number-re . font-lock-constant-face)
+ (,(regexp-opt dart--types 'words) . font-lock-type-face))))
+
(defun dart-fontify-region (beg end)
"Use fontify the region between BEG and END as Dart.
@@ -701,29 +405,6 @@ whichever comes first."
Each list item should be a regexp matching a single identifier."
:group 'dart-mode)
-(c-override-default-keywords 'dart-font-lock-keywords)
-
-(defconst dart-font-lock-keywords-1 (c-lang-const c-matchers-1 dart)
- "Minimal highlighting for Dart mode.")
-
-(defconst dart-font-lock-keywords-2 (c-lang-const c-matchers-2 dart)
- "Fast normal highlighting for Dart mode.")
-
-(defconst dart-font-lock-keywords-3
- (cons
- '(dart-highlight-interpolation 1 font-lock-variable-name-face prepend)
- (c-lang-const c-matchers-3 dart))
- "Accurate normal highlighting for Dart mode.")
-
-(defvar dart-font-lock-keywords dart-font-lock-keywords-3
- "Default expressions to highlight in Dart mode.")
-
-(defvar dart-mode-syntax-table nil
- "Syntax table used in dart-mode buffers.")
-(unless dart-mode-syntax-table
- (setq dart-mode-syntax-table
- (funcall (c-lang-const c-make-mode-syntax-table dart))))
-
;;; Dart analysis server
@@ -1855,24 +1536,26 @@ This replaces references to TEMP-FILE with REAL-FILE."
;;;###autoload (add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode))
;;;###autoload
-(defun dart-mode ()
+(define-derived-mode dart-mode prog-mode "Dart"
"Major mode for editing Dart files.
-The hook `c-mode-common-hook' is run with no args at mode
-initialization, then `dart-mode-hook'.
+The hook `dart-mode-hook' is run with no args at mode
+initialization.
Key bindings:
\\{dart-mode-map}"
- (interactive)
- (kill-all-local-variables)
- (c-initialize-cc-mode t)
- (set-syntax-table dart-mode-syntax-table)
- (setq major-mode 'dart-mode
- mode-name "Dart")
- (use-local-map dart-mode-map)
- (c-init-language-vars dart-mode)
- (c-common-init 'dart-mode)
- (c-set-style "dart")
+ (modify-syntax-entry ?/ "_ 124b")
+ (modify-syntax-entry ?* ". 23")
+ (modify-syntax-entry ?\n "> b")
+ (modify-syntax-entry ?\' "\"")
+ (setq-local electric-indent-chars '(?\n ?\) ?\] ?\}))
+ (setq comment-start "//")
+ (setq comment-end "")
+ (setq fill-column 80)
+ (setq font-lock-defaults dart-font-lock-defaults)
+ (setq indent-line-function 'dart-indent-line-function)
+ (setq indent-tabs-mode nil)
+ (setq tab-width 2)
(when dart-enable-analysis-server
(if (null dart-sdk-path)
(dart-log
@@ -1880,11 +1563,7 @@ Key bindings:
(dart--start-analysis-server-for-current-buffer)))
(add-hook (make-local-variable 'before-save-hook)
- (lambda () (when dart-format-on-save (dart-format))))
-
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'dart-mode-hook)
- (c-update-modeline))
+ (lambda () (when dart-format-on-save (dart-format)))))
(provide 'dart-mode)
- [nongnu] elpa/dart-mode 89573d5 067/192: Use a pipe instead of a pty for the analysis server, (continued)
- [nongnu] elpa/dart-mode 89573d5 067/192: Use a pipe instead of a pty for the analysis server, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 35a794c 086/192: Add workaround for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=18845 (#40), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9b11e8f 088/192: Another attempt at fixing byte compilation. (#42), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3a73a1f 090/192: Make dart-executable-path resilient to wrappers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode b4e592f 098/192: Add more search commands, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c172f19 106/192: Support completing multiple parameters, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2b085f5 125/192: Do not fail if Flycheck is not available. (#52), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c973dea 127/192: Require ‘help-mode’., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 68f7f4f 132/192: Require cl for emacs 24.4, 24.5, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode caa7a19 124/192: Don't error out with revert-buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 199709f 148/192: Removes cc-mode,
ELPA Syncer <=
- [nongnu] elpa/dart-mode da244c6 144/192: Fixes no such file or directory, dartfmt.exe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9db2679 143/192: Fixes invalid file path format on Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 06e2d4b 160/192: Respect font-lock-maximum-decoration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3082066 185/192: Don't font lock anchor in a string, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ad93bc1 165/192: Edit headers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f6a1c9a79 171/192: Fix byte-compiling errors and warnings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1273ccb 191/192: Make changes to list of dart-mode keywords easier to diff, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode a9899a9 182/192: Fontify abstract methods, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c523992 004/192: Handle map indentation with identifiers., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 30f9326 007/192: Make constants better., ELPA Syncer, 2021/08/29