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

add Ansible contrib layer #617

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
35 changes: 35 additions & 0 deletions contrib/ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ansible contribution layer for Spacemacs

![ansible](img/ansible.png)

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**

- [Ansible contribution layer for Spacemacs](#ansible-contribution-layer-for-spacemacs)
- [Description](#description)
- [Install](#install)
- [Key bindings](#key-bindings)

<!-- markdown-toc end -->

## Description

This layer add support for Ansible-flavored YAML buffers.

## Install

To use this contribution add it to your `~/.spacemacs`

```elisp
(setq-default dotspacemacs-configuration-layers '(ansible)
"List of contribution to load."
)
```

## Key bindings

Key Binding | Description
--------------|------------------------------------------------------------
`<SPC> m a ?` | looks up documentation using [`ansible-doc`][ansible-doc]

[ansible-doc]: https://github.com/lunaryorn/ansible-doc.el
16 changes: 16 additions & 0 deletions contrib/ansible/config.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;;; funcs.el --- Ansible Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2015 Brian Hicks & Contributors
;;
;; Author: Brian Hicks <brian@brianthicks.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

;; detect filenames compatible with Ansible's recommended layout.
;; http://docs.ansible.com/playbooks_best_practices.html#directory-layout
(setq ansible/ansible-filename-re
"\\(site\.yml\\|roles/.+\.yml\\|group_vars/.+\\|host_vars/.+\\)")
24 changes: 24 additions & 0 deletions contrib/ansible/funcs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;;; funcs.el --- Ansible Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2015 Brian Hicks & Contributors
;;
;; Author: Brian Hicks <brian@brianthicks.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun ansible/ansible-should-enable? ()
(and (stringp buffer-file-name)
(string-match ansible/ansible-filename-re buffer-file-name)))

(defun ansible/ansible-maybe-enable ()
(when (ansible/ansible-should-enable?)
(ansible 1)))

(defun ansible/ansible-doc-maybe-enable ()
(when (ansible/ansible-should-enable?)
(ansible-doc-mode 1)
(evil-leader/set-key-for-mode 'yaml-mode
"ma?" 'ansible-doc)))
Binary file added contrib/ansible/img/ansible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions contrib/ansible/packages.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;;; extensions.el --- Ansible Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2015 Brian Hicks & Contributors
;;
;; Author: Brian Hicks <brian@brianthicks.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar ansible-packages '(yaml-mode
ansible
ansible-doc))

(defun ansible/init-yaml-mode ()
(use-package yaml-mode
:defer t))

(defun ansible/init-ansible ()
(use-package ansible
:defer t
:init (progn
(eval-after-load 'yaml-mode
'(add-hook 'yaml-mode-hook 'ansible/ansible-maybe-enable))

;; ansible-mode requires ac-user-dictionary-files. If the
;; config is using company-mode this variable will not be
;; set, so we set it to a dummy value.
;;
;; Tracking here:
;; https://github.com/k1LoW/emacs-ansible/issues/2
(when (member 'company-mode dotspacemacs-configuration-layers)
(setq ac-user-dictionary-files '())))))

(defun ansible/init-ansible-doc ()
(use-package ansible-doc
:defer t
:init (eval-after-load 'yaml-mode
'(add-hook 'yaml-mode-hook 'ansible/ansible-doc-maybe-enable))))