2016-08-22 20:22:59 +00:00
|
|
|
#+TITLE: Templates layer
|
|
|
|
|
2019-05-02 21:49:30 +00:00
|
|
|
#+TAGS: completion|layer
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
* Table of Contents :TOC_4_gh:noexport:
|
2018-05-23 04:20:35 +00:00
|
|
|
- [[#description][Description]]
|
|
|
|
- [[#features][Features:]]
|
|
|
|
- [[#install][Install]]
|
|
|
|
- [[#configuration][Configuration]]
|
|
|
|
- [[#default-insertions][Default insertions]]
|
|
|
|
- [[#querying][Querying]]
|
2016-08-22 20:22:59 +00:00
|
|
|
|
|
|
|
* Description
|
|
|
|
This layer provides templates to Spacemacs. A template consists of text that is
|
|
|
|
automatically inserted into a new file when it is opened. This is done via
|
|
|
|
[[https://github.com/mineo/yatemplate][yatemplate]], which leverages [[https://github.com/joaotavora/yasnippet][yasnippet]].
|
|
|
|
|
2018-05-23 04:20:35 +00:00
|
|
|
** Features:
|
|
|
|
- Auto-insert snippets when creating specific new files.
|
|
|
|
|
2016-08-22 20:22:59 +00:00
|
|
|
* Install
|
|
|
|
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
|
|
|
add =templates= to the existing =dotspacemacs-configuration-layers= list in this
|
|
|
|
file.
|
|
|
|
|
|
|
|
* Configuration
|
2018-08-04 15:02:49 +00:00
|
|
|
Drop your templates in =~/.emacs.d/private/templates=.
|
2018-05-23 04:20:35 +00:00
|
|
|
|
|
|
|
You can also specify a different location with =templates-private-directory=:
|
2016-08-22 20:22:59 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq-default dotspacemacs-configuration-layers
|
2018-08-04 15:02:49 +00:00
|
|
|
'((templates :variables templates-private-directory "~/.spacemacs.d/templates")))
|
2016-08-22 20:22:59 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Each file in this directory must be of the form =XXX:regexp= where =regexp= is a
|
|
|
|
regular expression that will be matched against filenames. The prefix =XXX= can
|
|
|
|
be used to enforce an ordering (templates that come first will have priority).
|
|
|
|
It is not part of the final regexp. Therefore, more specific templates should
|
|
|
|
come first. For example,
|
|
|
|
|
2018-05-24 05:39:07 +00:00
|
|
|
#+BEGIN_EXAMPLE
|
2018-09-19 03:54:47 +00:00
|
|
|
00:test_.*.py
|
|
|
|
01:.*.py
|
2018-05-24 05:39:07 +00:00
|
|
|
#+END_EXAMPLE
|
2016-08-22 20:22:59 +00:00
|
|
|
|
|
|
|
See the [[https://github.com/mineo/yatemplate][yatemplate]] documentation for specifics. Full yasnippet syntax is
|
|
|
|
supported, so consult the [[http://joaotavora.github.io/yasnippet/snippet-development.html][yasnippet]] documentation for details.
|
|
|
|
|
|
|
|
** Default insertions
|
|
|
|
Note that Emacs ships with some default templates. If these are not to your
|
2018-08-04 14:56:23 +00:00
|
|
|
liking, set the layer variable =templates-use-default-templates= to =nil=.
|
2016-08-22 20:22:59 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq-default dotspacemacs-configuration-layers
|
2018-08-04 14:56:23 +00:00
|
|
|
'((templates :variables templates-use-default-templates nil)))
|
2016-08-22 20:22:59 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Querying
|
|
|
|
To disable the automatic querying each time a new file is opened, set
|
|
|
|
=auto-insert-query= to =nil=.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq auto-insert-query nil)
|
|
|
|
#+END_SRC
|