Topics in This Post

  1. Autocompletion

  2. Emmet

  3. Yasnippet

Emmet

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)

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

:bind
("C-j" . emmet-expand-line)
((:map emmet-mode-keymap
         ("C-c [" . emmet-prev-edit-point)
         ("C-c ]" . emmet-next-edit-point)))

);end emmet mode

Yasnippet

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)

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

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

;packages

(use-package yasnippet-snippets
:defer t
);end use-package snippets

;load those snippets

(yas-reload-all)
;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/some/collection/"
;"/path/to/yasnippet/yasmate/snippets" ;; the yasmate collection
));yasnippets directories

(global-set-key (kbd "C-c C-s") 'yas/insert-snippet)

;hydra-title

(defvar yasnippet-title (with-faicon "scissors" "SNIPPETS"))
:pretty-hydra
(Yasnippet (:color red :quit-key "q" :title yasnippet-title)
(
"Inserts"
(
          ("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

:bind
("<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


Autoyas

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)
:init
(add-to-list 'load-path auto-yas-p)
:config
(setq aya-persist-snippets-dir auto-yas-dir-p)
;; No need to be so verbose
);end auto-yasnippet