This post covers the following sections from my init.

  1. Autocompletion

  2. Emmet

  3. Yasnippet


Emacs is old school. You're either new to it - which means you wouldn't be here unless it was your type of thing - or you know what you're looking for. In either case, search 'Emacs' in tags or search on this site. Then read the posts y date from oldest to newest.

In the last emacs post I covered lines 2773 - 2942. This post covers lines 2995 - 3057. I include the lines for anyone that wants to patch together the entire init from start to finish. The lines won't always match up because I take stuff out when I'm in the init.

Autocompletion and snippet insertion are major components of any modern text editor and/or word processing set-up. Emmet mode expands characters typed into expressions while Yasnippet Mode inserts pre-selected sections of code.

Here are the configurations I use:


(use-package emmet-mode
:after(web-mode css-mode scss-mode)
:commands (emmet-mode emmet-expand-line yas/insert-snippet yas-insert-snippet company-complete)
(setq emmet-move-cursor-between-quotes t)
(add-hook 'emmet-mode-hook (lambda () (setq emmet-indent-after-insert nil)))
(add-hook 'sgml-mode-hook 'emmet-mode) ;; Auto-start on any markup modes
(add-hook 'css-mode-hook  'emmet-mode) ;; enable Emmet's css abbreviation.
;(setq emmet-indentation 2)
(unbind-key "C-M-<left>" emmet-mode-keymap)
(unbind-key "C-M-<right>" emmet-mode-keymap)
("C-j" . emmet-expand-line)
((:map emmet-mode-keymap
         ("C-c [" . emmet-prev-edit-point)
         ("C-c ]" . emmet-next-edit-point)))
);end emmet mode


The ':after' in the use package declaration gets emacs to run this code only after specified modes are called. The commands does the same only with commands called. The hooks autostart emmet on modes. I unbinded some key configurations that conflicted with my own.

I use Emmet a lot for html tags. To run it, put cursor after some keys typed and press C-j.


Snippets are pieces of code you've collected for easy insertion. I use Yasnippet a lot and I'm happy with it. The main things you want to set up are the places you put your snippets, how you back them up, what your naming convention is (so you can remember them when you need to find them), and how to bring them up.

My system enables me to do the various operations from a hydra panel (see image below). To create the snippets I usually don't bother with the hydra but just jump to the directory I've bookmarked (using bookmark package) and use dir to create a new snippet file. Then I cut and paste some code from a past snippet and configure it. This way anything I do once I can do again super easily.

Here's the configuration:

(use-package yasnippet
:diminish yas-minor-mode
:commands (yas-reload-all yas/minor-mode yas/global-mode yas/insert-snippet yas-insert-snippet yas-activate-extra-mode hydra-helm/body yas-new-snippet yas-load-directory yas-visit-snippet-file yas-tryout-snippet yas-describe-tables Yasnippet/body)

(add-to-list 'load-path yas-p)
(require 'yasnippet)
(yas-global-mode 1)
:after hydra

(add-to-list 'auto-mode-alist '("yasnippet/snippets" . snippet-mode))
(add-to-list 'auto-mode-alist '("\\.yasnippet\\'" . snippet-mode))
(setq yas-verbosity 1)
(setq yas-use-menu 'full)
;; Wrap around region
(setq yas-wrap-around-region t)
(setq yas-indent-line (quote none))

(use-package yasnippet-snippets
:defer t
);end use-package snippets
;load those snippets
;integration yasnippet and company
(setq yas-snippet-dirs '(
yas-snippets-p; main snippet director (when yasnippets snippets updated paste here with overwrite)
auto-yas-dir-p;autoyas snippet directories
;"/path/to/yasnippet/yasmate/snippets" ;; the yasmate collection
));yasnippets directories
(global-set-key (kbd "C-c C-s") 'yas/insert-snippet)

(defvar yasnippet-title (with-faicon "scissors" "SNIPPETS"))
(Yasnippet (:color red :quit-key "q" :title yasnippet-title)
          ("i" yas-insert-snippet "Insert a Snippet":color blue)
          ("a" yas-reload-all "Reload Snippets" :color blue)
          ("e" yas-activate-extra-mode "Extra Mode")
          ("d" yas-load-directory "Load a Snippet Directory")
          ("m" yas/minor-mode "Activate Yas Minor":toggle t)
          ("g" yas/global-mode "Always Use Yas":toggle t)
);end inserts

"Manage Snippets"
          ("l" yas-describe-tables "List Snippets" :color blue)
          ("n" yas-new-snippet "Create A New Snippet")
          ("t" yas-tryout-snippet "Tryout A Snippet")
          ("s" yas-load-snippet-buffer-and-close "Load and Save New Snippet" :color blue)

          ("f" yas-visit-snippet-file "Edit Snippet File" :color blue)
);manage snippets

"Auto Snippets"
          ("w" aya-create "Create an Auto Snippet")
          ("y" aya-expand "Expand an Auto Snippet" :color blue)
          ("o" aya-open-line "Open Line")
          ("h" hydra-helm/body "Return To Helm" :color blue )
          ("<SPC>" nil "Exit Hydra" :color blue )
);end tabbable snippets
);end heads
);end pretty hydra
("<C-m> y" . Yasnippet/body)
);end use-package yasnippet
;ensure no new lines in snippet mode
(defun do-not-require-new-line () (set (make-local-variable 'require-final-newline) nil))
(add-hook 'snippet-mode 'do-not-require-new-line)


You can google the various pieces of code above or try them out. The main gist is that you need to load the libraries then set some directories for your code. I hardwired my directories earlier in my init so they are stored in variables 'auto-yas-dir-p,' and 'yas-snippets-p.'

It's also nice to get some premade snippets, which you get above with package yasnippet-snippets (I put some spaces in the code so easy to find). Then you get the hydra, which has most of the functions you use with yasnippet hardwired.

emacs poseidon configuration yasnippet hydra code


I don't use autoyasnippet a lot. It's a macro system for one-off jobs. For example, if you need to repeat a construction multiple times and you want to paste it then tab through it and enter information, then paste it again, and so on, you would use autoyas.

Here's the code:

(use-package auto-yasnippet
:commands (aya-create aya-expand aya-yank-snippet aya-expand-and-exit)
(add-to-list 'load-path auto-yas-p)
(setq aya-persist-snippets-dir auto-yas-dir-p)
;; No need to be so verbose
);end auto-yasnippet

That’s all for now…