├── README.org ├── config.el ├── img └── crystal.png └── packages.el /README.org: -------------------------------------------------------------------------------- 1 | #+TITLE: crystal layer 2 | #+HTML_HEAD_EXTRA: 3 | 4 | #+CAPTION: logo 5 | 6 | # The maximum height of the logo should be 200 pixels. 7 | [[img/crystal.png]] 8 | 9 | * Table of Contents :TOC_4_org:noexport: 10 | - [[Description][Description]] 11 | - [[Install][Install]] 12 | 13 | * Description 14 | This layer aims to provide support for the Crystal language with the following features: 15 | - syntax highlighting and indentation (provided by [[https://github.com/ggiraldez/emacs-crystal-mode/][an external package]]). 16 | - automatic file formatting 17 | - autocompletion snippets 18 | 19 | * Install 20 | To use this layer first clone it into your =~/.emacs.d/private= directory: 21 | 22 | #+BEGIN_SRC shell 23 | git clone git@github.com:juanedi/crystal-spacemacs-layer.git ~/.emacs.d/private/crystal 24 | #+END_SRC 25 | 26 | Then enable the layer in your =~/.spacemacs=: 27 | # To use this contribution add it to your =~/.spacemacs= 28 | 29 | #+begin_src emacs-lisp 30 | (setq-default dotspacemacs-configuration-layers '(crystal)) 31 | #+end_src 32 | 33 | # * Key bindings 34 | 35 | # | Key Binding | Description | 36 | # |-----------------+----------------| 37 | # | ~ x x x~ | Does thing01 | 38 | -------------------------------------------------------------------------------- /config.el: -------------------------------------------------------------------------------- 1 | ;;; config.el --- crystal layer packages file for Spacemacs. 2 | ;; 3 | ;; Copyright (c) 2012-2016 Sylvain Benner & Contributors 4 | ;; 5 | ;; Author: Juan Edi 6 | ;; URL: https://github.com/syl20bnr/spacemacs 7 | ;; 8 | ;; This file is not part of GNU Emacs. 9 | ;; 10 | ;;; License: GPLv3 11 | 12 | (spacemacs|defvar-company-backends crystal-mode) 13 | -------------------------------------------------------------------------------- /img/crystal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanedi/crystal-spacemacs-layer/b478938e15ff67710d4bd9f1445ff4a29745c925/img/crystal.png -------------------------------------------------------------------------------- /packages.el: -------------------------------------------------------------------------------- 1 | ;;; packages.el --- crystal layer packages file for Spacemacs. 2 | ;; 3 | ;; Copyright (c) 2012-2016 Sylvain Benner & Contributors 4 | ;; 5 | ;; Author: Juan Edi 6 | ;; URL: https://github.com/syl20bnr/spacemacs 7 | ;; 8 | ;; This file is not part of GNU Emacs. 9 | ;; 10 | ;;; License: GPLv3 11 | 12 | ;;; Code: 13 | 14 | (defconst crystal-packages 15 | '( 16 | (crystal-mode :location (recipe :fetcher github :repo "ggiraldez/emacs-crystal-mode")) 17 | popwin 18 | company 19 | ) 20 | ) 21 | 22 | (defvar crystal--format-buffer-name "*crystal formatter*") 23 | 24 | (defun crystal--format-output-buffer () 25 | (when (get-buffer crystal--format-buffer-name) 26 | (kill-buffer crystal--format-buffer-name)) 27 | (popwin:get-buffer crystal--format-buffer-name :create)) 28 | 29 | (defun crystal--run-formatter (buffer-file-name output-buffer) 30 | (call-process-shell-command (format "crystal tool format %s" buffer-file-name) nil output-buffer t)) 31 | 32 | (defun crystal--format-file () 33 | (when (and (configuration-layer/package-usedp 'popwin) 34 | (equal 'crystal-mode major-mode)) 35 | (let ((output-buffer (crystal--format-output-buffer))) 36 | (let ((exit-status (crystal--run-formatter buffer-file-name output-buffer))) 37 | (if (eq 0 exit-status) 38 | (revert-buffer t t) 39 | (popwin:popup-buffer output-buffer)))))) 40 | 41 | (defun crystal/pre-init-popwin () 42 | (spacemacs|use-package-add-hook popwin 43 | :post-config 44 | (push '("*crystal formatter*" :tail t :noselect t) popwin:special-display-config))) 45 | 46 | (defun crystal/init-crystal-mode ()) 47 | 48 | (defun crystal/post-init-crystal-mode () 49 | (add-hook 'after-save-hook #'crystal--format-file)) 50 | 51 | (defun crystal/post-init-company () 52 | (spacemacs|add-company-hook crystal-mode)) 53 | 54 | ;;; packages.el ends here 55 | --------------------------------------------------------------------------------