--extensions= variables. =pre= extensions are
loaded before the packages and =post= extensions are loaded after. The name of
the extension is the name of the folder it is in. Using the above example
structure, the extensions would be activated like so:
#+begin_src emacs-lisp
(setq layer-name-pre-extensions '())
(setq layer-name-post-extensions '(example-mode-1 example-mode-n))
#+end_src
Notice the matching folder and extension names.
Extensions also require an =init= function to be used. They use the same naming
pattern as packages.
Make sure you [[*Activating%20a%20Layer][add]] your layer to your =.dotspacemacs= file and restart to
activate it.
** Installing a single package
Sometimes creating a layer is a bit overkill. Maybe you just want one package
and don't want to maintain a whole layer. Spacemacs provides a variable in the
=dotspacemacs/init= function in =.spacemacs= called
=dotspacemacs-additional-packages=. Just add a package name to the list and it
will be installed when you restart. Loading the package is covered in the next
[[*Loading%20packages][section.]]
** Loading packages
Ever wonder how Spacemacs can load over a 100 packages in just a few seconds?
Such low loading times must require some kind of unreadable black magic that no
one can understand. Thanks to [[https://github.com/jwiegley/use-package][use-package]], this is not true. It is a package
that allows easy lazy-loading and configuration of packages. Here are the basics
to using it:
#+begin_src emacs-lisp
;; Basic form of use-package declaration. The :defer t tells use-package to
;; try to lazy load the package.
(use-package package-name
:defer t)
;; The :init section is run before the package loads The :config section is
;; run after the package loads
(use-package package-name
:defer t
:init
(progn
;; Change some variables
(setq variable1 t variable2 nil)
;; Define a function
(defun foo () (message "%s" "Hello, World!")))
:config
(progn
;; Calling a function that is defined when the package loads
(function-defined-when-package-loads)))
#+end_src
This is just a very basic overview of =use-package=. There are many other ways
to control how a package loads using it that aren't covered here.
** Uninstalling a package
Spacemacs provides a variable in the =dotspacemacs/init= function in
=.spacemacs= called =dotspacemacs-excluded-packages=. Just add a package name
to the list and it will be uninstalled when you restart.
** Common tweaks
This section is for things many will want to change. All of these settings go in
the =dotspacemacs/config= function in your =.spacemacs= unless otherwise noted.
*** Changing the escape key
Spacemacs uses =[[https://github.com/syl20bnr/evil-escape][evil-escape]]= to allow escaping from many =major-modes= with one
keybinding. You can customize the variable in your =dotspacemacs/init= like
this:
#+begin_src emacs-lisp
(defun dotspacemacs/init ()
;; ...
;; Set escape keybinding to "jk"
(setq-default evil-escape-key-sequence "jk"))
#+end_src
This is one of the few variables that must be set in =dotspacemacs/init=. More
documentation is found in the =evil-escape= README.
*** Changing the colorscheme
The =.spacemacs= file contains the =dotspacemacs-themes= variable in the
=dotspacemacs/init= function. This is a list of themes that can be cycled
through with the @@html:@@ SPC T n @@html:@@ keybinding. The first
theme in the list is the one that is loaded at startup. Here is an example:
#+begin_src emacs-lisp
(defun dotspacemacs/init
;; Darktooth theme is the default theme
;; Each theme is automatically installed.
;; Note that we drop the -theme from the package name.
;; Ex. darktooth-theme -> darktooth
(setq-default dotspacemacs-themes '(darktooth
soothe
gotham)))
#+end_src
All installed themes can be listed and chosen using the @@html:@@ SPC T h
@@html:@@ keybinding.
*** Nohlsearch
Spacemacs emulates the default vim behavior which highlights search results even
when you are not navigating between them. You can use @@html:@@ SPC s c
@@html:@@ or @@html:@@ :nohlsearch @@html:@@ to disable search
result highlighting.
To disable the result highlighting when it is not needed anymore automatically,
you can [[*Uninstalling%20a%20package][uninstall]] the =evil-search-highlight-persist= package.
*** Sessions
Spacemacs does not automatically restore your windows and buffers when you
reopen it. If you use vim sessions regularly you may want to add
=(desktop-save-mode t)= to you =dotspacemacs/config= in your =.spacemacs= to get
this functionality. You will then be able to load the saved session using
@@html:@@ SPC : desktop-read @@html:@@. The location of the desktop
file can be set with the variable =desktop-dirname=. To automatically load a
session, add =(desktop-read)= to your =.spacemacs=.
*** Navigating using visual lines
Spacemacs uses the vim default of navigating by actual lines, even if they are
wrapped. If you want @@html:@@ j @@html:@@ and @@html:@@ k
@@html:@@ to behave like @@html:@@ g j @@html:@@ and
@@html:@@ g k @@html:@@, add this to your =.spacemacs=:
#+begin_src emacs-lisp
(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
#+end_src
* Other useful links
- [[https://www.gnu.org/software/emacs/manual/emacs.html][Emacs Manual]]
- [[file:DOCUMENTATION.md][Spacemacs Documentation]]
- [[http://ian.mccowan.space/2015/04/07/Spacemacs/][Spacemacs: A Vimmer's Emacs Prerequisites]]
- Note: The article refers to @@html:@@ SPC b s @@html:@@
as the keybinding to switch buffers. It is @@html:@@ SPC b b
@@html:@@
- [[http://thume.ca/howto/2015/03/07/configuring-spacemacs-a-tutorial/][Configuring Spacemacs: A Tutorial]]
- [[http://juanjoalvarez.net/es/detail/2014/sep/19/vim-emacsevil-chaotic-migration-guide/][From Vim to Emacs+Evil chaotic migration guide]]