Topics in This Post

  1. Autocompletion

  2. Emmet

  3. Yasnippet


You can expand characters into customizable expressions with Emmet-Mode.

Try putting the cursor after some characters and pressing C-j

(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


You can insert pieces of code you've collected with Yasnippet.

Here's some configuration code:

(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)

Yasnippet-Hydra Image

emacs poseidon configuration yasnippet hydra code


You can insert an instant template then tab through it and enter information with Autoyas.

Here's some more 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