5

I want to have both emmet-mode and yasnippet trigger with the same key C-return: in a html-mode buffer, C-return should first try yas-expand and then emmet-expand-line if no suitable snippet was found.

It seems I am missing something about the binding keywords in use-package. Currently only emmet-mode's bind is active in a HTML buffer.

lisp/init-emmet.el

(use-package emmet-mode
  :defer t
  :init
  (add-hook 'css-mode-hook 'emmet-mode)
  (add-hook 'sgml-mode-hook 'emmet-mode)
  :config
  (setq-default
   emmet-move-cursor-between-quotes t
   emmet-preview-default nil)
  (unbind-key "C-M-<left>" emmet-mode-keymap)
  (unbind-key "C-M-<right>" emmet-mode-keymap))

lisp/init-yasnippet.el

(use-package yasnippet
  :defer t
  :bind (:map yas-minor-mode-map ("<C-return>" . yas-expand))
  :init
  (add-hook 'js-mode-hook 'yas-minor-mode)
  (add-hook 'sgml-mode-hook 'yas-minor-mode)
  :config
  (setq-default yas-snippet-dirs '("~/.emacs.d/snippets"))
  (yas-reload-all)
  (unbind-key "TAB" yas-minor-mode-map))
4
  • As an aside, passing a :map to bind-keys* (including via :bind*) doesn't do anything; it will ignore the map argument and bind its keys in override-global-map. Commented Mar 3, 2016 at 16:37
  • Yes, what I have doesn't actually make sense (mere and futile attempt after many others). So both emmet-mode and yasnippet should have their binds bound to their own map, but how do I set "priority" (?) of one over another? Commented Mar 3, 2016 at 16:41
  • 1
    Check out emacswiki.org/emacs/minor-mode-hack.el
    – npostavs
    Commented Mar 3, 2016 at 21:17
  • Oh dear, someone needs to get that into a publically hosted git repo, and published to MELPA pronto!
    – ocodo
    Commented Apr 2, 2016 at 0:57

1 Answer 1

4

I ended up using hippie-expand which is built-in to Emacs (24+?).

emmet-mode

(use-package emmet-mode
  :defer t
  :init
  (add-hook 'css-mode-hook 'emmet-mode)
  (add-hook 'sgml-mode-hook 'emmet-mode)
  :config
  (setq-default emmet-move-cursor-between-quote t)
  (unbind-key "<C-return>" emmet-mode-keymap)
  (unbind-key "C-M-<left>" emmet-mode-keymap)
  (unbind-key "C-M-<right>" emmet-mode-keymap))

hippie-expand

(use-package hippie-exp
  :ensure nil
  :defer t
  :bind ("<C-return>" . hippie-expand)
  :config
  (setq-default hippie-expand-try-functions-list
                '(yas-hippie-try-expand emmet-expand-line)))

yasnippet

(use-package yasnippet
  :defer t
  :init
  (add-hook 'js-mode-hook 'yas-minor-mode)
  (add-hook 'sgml-mode-hook 'yas-minor-mode)
  :config
  (setq-default yas-snippet-dirs '("~/.emacs.d/snippets"))
  (yas-reload-all)
  (unbind-key "TAB" yas-minor-mode-map)
  (unbind-key "<tab>" yas-minor-mode-map))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.