diff --git a/layers/+lang/dart/README.org b/layers/+lang/dart/README.org new file mode 100644 index 000000000..9ab1ab39d --- /dev/null +++ b/layers/+lang/dart/README.org @@ -0,0 +1,94 @@ +#+TITLE: dart layer + +[[file:img/dart.png]] + +* Table of Contents :TOC_4_gh:noexport: +- [[#description][Description]] + - [[#features][Features:]] +- [[#install][Install]] + - [[#layer][Layer]] + - [[#dart-sdk-location][Dart SDK location]] + - [[#flutter-integration][Flutter integration]] +- [[#configuration][Configuration]] + - [[#use-analysis-server][Use analysis server]] + - [[#format-on-save][Format on save]] +- [[#key-bindings][Key bindings]] + - [[#normal-mode][Normal mode]] + - [[#insert-mode][Insert mode]] + - [[#popup-screens][Popup screens]] + +* Description + This layer adds support for Dart language, and could be optionally used for Flutter development as well. + +** Features: + - Syntax Highlight + - Error checking with ~flycheck~ + - Go to Definition + - Dart Analyzer integration + - Key bindings + +* Install +** Layer + To use this configuration layer, add it to your =~/.spacemacs=. You will need to + add =dart= to the existing =dotspacemacs-configuration-layers= list in this + file. + +** Dart SDK location + The layer itself will use the `dart` executable location if available on the execution path, but it is possible to define the location manually. + It should point to the folder, and end with `/`. + + #+BEGIN_SRC elisp + (dart :variables dart-sdk-path "~/path/to/dart-sdk/") + #+END_SRC + +*** Flutter integration + Flutter comes with a internal Dart SDK, which can be used to provide all the integration tools. + + #+BEGIN_SRC elisp + (dart :variables dart-sdk-path "/bin/cache/dart-sdk/") + #+END_SRC + +* Configuration + For more available variables check [[https://github.com/bradyt/dart-mode][dart-mode]] documentation. + +** Use analysis server + #+BEGIN_SRC elisp + (dart :variables dart-enable-analysis-server t) + #+END_SRC + +** Format on save + #+BEGIN_SRC elisp + (dart :variables dart-format-on-save t) + #+END_SRC + +* Key bindings +** Normal mode + Some of the commands will instantiate a new Dart Analyzer server if + necessary, while others work without using a Dart Analyzer connection. + + When ~dart-enable-analysis-server~ is enabled, most of the commands become Async, and there might be a delay when executing them. + + | Key Binding | Description | + |------------------------+---------------------------------------------------| + | ~SPC m h h~, ~SPC m ?~ | Displays hover information for the current point. | + | ~SPC m h b~ | Displays information at point on a new buffer. | + | ~gd~, ~SPC m g~ | Go to definition. | + | ~SPC m f f~ | Find reference at point. | + | ~SPC m f d~ | Find members declarations by name. | + | ~SPC m f r~ | Find members references by name. | + | ~SPC m f d~ | Find top-level declarations by name. | + | ~SPC m =~ | Format buffer | + +** Insert mode + + | Key Binding | Description | + |-------------+--------------------------------------------------| + | ~~ | Expand previous word using Analyzer if available | + | ~C-~ | Expand including parameters | + +** Popup screens + + | Key Binding | Description | + |-------------+-------------------------------------------| + | ~q~ | Close popup | + | ~gr~ | Execute last command to repopulate buffer | diff --git a/layers/+lang/dart/config.el b/layers/+lang/dart/config.el new file mode 100644 index 000000000..47a4ceb5c --- /dev/null +++ b/layers/+lang/dart/config.el @@ -0,0 +1,14 @@ +;;; config.el --- dart Layer configuration File for Spacemacs +;; +;; Copyright (c) 2012-2018 Sylvain Benner & Contributors +;; +;; Author: Bruno Tavares +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;; Variables + +(spacemacs|define-jump-handlers dart-mode) diff --git a/layers/+lang/dart/img/dart.png b/layers/+lang/dart/img/dart.png new file mode 100644 index 000000000..ea196610a Binary files /dev/null and b/layers/+lang/dart/img/dart.png differ diff --git a/layers/+lang/dart/packages.el b/layers/+lang/dart/packages.el new file mode 100644 index 000000000..d1d222e0c --- /dev/null +++ b/layers/+lang/dart/packages.el @@ -0,0 +1,76 @@ +;;; packages.el --- dart layer packages file for Spacemacs. +;; +;; Copyright (c) 2012-2018 Sylvain Benner & Contributors +;; +;; Author: Bruno Tavares +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;;; Code: + +;; TODO: offer lsp integration +(defconst dart-packages + '(dart-mode + flycheck)) + +;; TODO: Remove when https://github.com/bradyt/dart-mode/pull/67 +(defun dart/trigger-hooks () + (run-hooks 'change-major-mode-after-body-hook)) + +(defun dart/show-buffer () + "Shows information at point on a new buffer" + (interactive) + (dart-show-hover 't)) + +(defun dart/init-dart-mode () + (use-package dart-mode + :defer t + :mode "\\.dart\\'" + :init + (progn + (spacemacs/declare-prefix-for-mode 'dart-mode "mf" "find") + (spacemacs/declare-prefix-for-mode 'dart-mode "mh" "help") + (spacemacs/set-leader-keys-for-major-mode 'dart-mode + "=" 'dart-format + "?" 'dart-show-hover + "g" 'dart-goto + "hh" 'dart-show-hover + "hb" 'dart/show-buffer + "ff" 'dart-find-refs + "fe" 'dart-find-member-decls + "fr" 'dart-find-member-refs + "fd" 'dart-find-top-level-decls) + + (add-to-list 'spacemacs-jump-handlers-dart-mode '(dart-goto :async t)) + + (evil-define-key 'insert dart-mode-map + (kbd "") 'dart-expand + (kbd "C-") 'dart-expand-parameters) + + (evil-set-initial-state 'dart-popup-mode 'motion) + (evil-define-key 'motion dart-popup-mode-map + (kbd "gr") 'dart-do-it-again) + + (add-hook 'dart-mode-hook #'dart/trigger-hooks)) + + :config + ;; TODO: Remove when fix lands + ;; https://github.com/bradyt/dart-mode/pull/66 + (defun dart-formatter-command () + "The command for running the Dart formatter. +This can be customized by setting `dart-formatter-command-override'." + (or dart-formatter-command-override + (when dart-sdk-path + (concat dart-sdk-path + (file-name-as-directory "bin") + (if (memq system-type '(ms-dos windows-nt)) + "dartfmt.exe" + "dartfmt")))))) + + (defun dart/post-init-flycheck () + (spacemacs/add-flycheck-mode 'dart-mode))) + +;;; packages.el ends here