emmet-mode: bind to TAB & enable in reason-mode

TAB now either indents, expands the snippet at point, or expands the
emmet expression at point.

Also it now falls back to emmet-expand-line if yasnippet won't load.
This commit is contained in:
Henrik Lissner 2018-08-01 19:25:06 +02:00
parent 8bbff852f7
commit a876d87f5e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 21 additions and 5 deletions

View file

@ -105,3 +105,18 @@ function @ http://ergoemacs.org/emacs/elisp_replace_html_entities_command.html"
"Decode HTML entities in region."
(interactive "r")
(+web--entities-region beg end t))
;;;###autoload
(defun +web/indent-or-yas-or-emmet-expand ()
"Invoke `indent-for-tab-command' if at or before text bol, `yas-expand' if on
a snippet, or `emmet-expand-yas'/`emmet-expand-line', depending on whether
`yas-minor-mode' is enabled or not."
(interactive)
(call-interactively
(cond ((<= (current-column) (current-indentation))
#'indent-for-tab-command)
((bound-and-true-p yas-minor-mode)
(if (yas--templates-for-key-at-point)
#'yas-expand
#'emmet-expand-yas))
(#'emmet-expand-line))))

View file

@ -16,14 +16,15 @@
(def-package! emmet-mode
:commands emmet-mode
:preface (defvar emmet-mode-keymap (make-sparse-keymap))
:hook (css-mode web-mode html-mode haml-mode nxml-mode rjsx-mode)
:hook (css-mode web-mode html-mode haml-mode nxml-mode rjsx-mode reason-mode)
:config
(when (require 'yasnippet nil t)
(add-hook 'emmet-mode-hook #'yas-minor-mode-on))
(setq emmet-move-cursor-between-quotes t)
(add-hook! 'rjsx-mode-hook
(setq-local emmet-expand-jsx-className? t))
(setq-hook! 'rjsx-mode-hook emmet-expand-jsx-className? t)
(map! :map emmet-mode-keymap
:v "M-e" #'emmet-wrap-with-markup
:i "M-e" #'emmet-expand-yas
:v [tab] #'emmet-wrap-with-markup
:i [tab] #'+web/indent-or-yas-or-emmet-expand
:i "M-E" #'emmet-expand-line))