diff --git a/layers/+lang/swift/README.org b/layers/+lang/swift/README.org new file mode 100644 index 000000000000..801e913c085e --- /dev/null +++ b/layers/+lang/swift/README.org @@ -0,0 +1,64 @@ +#+TITLE: Swift contribution layer for Spacemacs + +[[file:img/swift.png]] + +* Table of Contens :TOC@4: + - [[#description][Description]] + - [[#install][Install]] + - [[#usage-information][Usage information]] + - [[#key-bindings][Key bindings]] + - [[#swift-mode][swift-mode]] + - [[#swift-repl-mode][swift-repl-mode]] + +* Description +This layer adds support for Apple's Swift programming language, used as a +general purpose scripting language. + +It relies on the [[https://github.com/chrisbarrett/swift-mode][swift-mode]] major-mode* for Emacs 24.4 or later, to provide the +following features: + +- Syntax highlighting +- Indentation +- Code navigation using ~imenu~ (built-in) +- Automatic syntax checking with ~flycheck~ (available with the + ~syntax-checking~ layer) + +* Install +To be able to use this layer you should be able to run this from the +command line: + +On OS X: +#+BEGIN_SRC sh + xcrun swift +#+END_SRC + +* Usage information + +Unless configured by the user, the REPL will be invoked using the command ~xcrun +swift~. + +You can launch the REPL using the keybinding ~SPC m s s~ (or ~C-c C-z~). + +The universal prefix ~SPC u~ (~C-u~) may be used to modify command invocation. + +* Key bindings + +** swift-mode + +| Emacs | Evil | Description | +|-------------------+-----------------------+------------------------| +| [~C-u~] ~C-c C-z~ | [~SPC u~] ~SPC m s s~ | swift-mode-run-repl | +| ~C-c C-f~ | ~SPC m s b~ | swift-mode-send-buffer | +| ~C-c C-r~ | ~SPC m s r~ | swift-mode-send-region | + +Notes: + +1. ~swift-mode-run-repl~ will run or switch to an existing REPL. +2. To edit the command invocation, prefix with ~SPC u~ (or ~C-u~). +3. Emacs key bindings in use are the those set by the package. + +** swift-repl-mode + +| Emacs | Evil | Description | +|-----------+-------------+-----------------------------| +| ~C-c C-z~ | ~SPC m s s~ | swift-repl-mode-switch-back | diff --git a/layers/+lang/swift/img/swift.png b/layers/+lang/swift/img/swift.png new file mode 100644 index 000000000000..cd9e5f926be6 Binary files /dev/null and b/layers/+lang/swift/img/swift.png differ diff --git a/layers/+lang/swift/packages.el b/layers/+lang/swift/packages.el new file mode 100644 index 000000000000..0faf873c7087 --- /dev/null +++ b/layers/+lang/swift/packages.el @@ -0,0 +1,77 @@ +;;; packages.el --- swift Layer packages File for Spacemacs +;; +;; Copyright (c) 2012-2014 Sylvain Benner +;; Copyright (c) 2014-2015 Uri Sharf & Contributors +;; +;; Author: Uri Sharf +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +(setq swift-packages + '( + flycheck + swift-mode + )) + +(when (configuration-layer/layer-usedp 'syntax-checking) + (spacemacs|use-package-add-hook flycheck + :post-config + (progn + (add-to-list 'flycheck-checkers 'swift)))) + +(defun swift/init-swift-mode () + "Initialize swift-mode" + (use-package swift-mode + :mode ("\\.swift\\'" . swift-mode) + :defer t + :init + (progn + (spacemacs|advise-commands + "store-initial-buffer-name" (swift-mode-run-repl) around + "Store current buffer bane in bufffer local variable, +before activiting or switching to REPL." + (let ((initial-buffer (current-buffer))) + ad-do-it + (with-current-buffer swift-repl-buffer + (setq swift-repl-mode-previous-buffer initial-buffer)))) + + ;; (defadvice swift-mode-run-repl (around store-initial-buffer activate) + ;; "Store current buffer in a buffer-local variable." + ;; (let ((initial-buffer (current-buffer))) + ;; ad-do-it + ;; (with-current-buffer swift-repl-buffer + ;; (setq swift-repl-mode-previous-buffer initial-buffer)))) + + (defun spacemacs/swift-repl-mode-hook () + "Hook to run when starting an interactive swift mode repl" + (make-variable-buffer-local 'swift-repl-mode-previous-buffer) + ) + (spacemacs/add-to-hook 'swift-repl-mode-hook '(spacemacs/swift-repl-mode-hook)) + + (defun spacemacs/swift-repl-mode-switch-back () + "Switch back to from REPL to editor." + (interactive) + (if swift-repl-mode-previous-buffer + (switch-to-buffer-other-window swift-repl-mode-previous-buffer) + (message "No previous buffer"))) + ) + :config + (progn + (evil-leader/set-key-for-mode 'swift-mode + "msS" 'swift-mode-run-repl ; run or switch to an existing swift repl + "mss" 'swift-mode-run-repl + "msb" 'swift-mode-send-buffer + "msr" 'swift-mode-send-region + ) + + (with-eval-after-load 'swift-repl-mode-map + ;; Switch back to editor from REPL + (evil-leader/set-key-for-mode 'swift-repl-mode + "mss" 'spacemacs/swift-repl-mode-switch-back) + (define-key swift-repl-mode-map + (kbd "C-c C-z") 'spacemacs/swift-repl-mode-switch-back) + ) + )))