Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift contribution layer #3464

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions layers/+lang/swift/README.org
Original file line number Diff line number Diff line change
@@ -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 |
Binary file added layers/+lang/swift/img/swift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions layers/+lang/swift/packages.el
Original file line number Diff line number Diff line change
@@ -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 <uri.sharf@me.com>
;; 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)
)
)))