feature/snippets: refactor, cleanup & stability tweaks

This commit is contained in:
Henrik Lissner 2017-03-22 17:42:51 -04:00
parent f380cff5c4
commit 29e844c92e
3 changed files with 12 additions and 15 deletions

View file

@ -10,8 +10,8 @@ and switches to insert mode if there are editable fields."
(cl-letf (((symbol-function 'region-beginning) (lambda () evil-visual-beginning))
((symbol-function 'region-end) (lambda () evil-visual-end)))
(yas-insert-snippet))
(let* ((snippet (first (yas--snippets-at-point)))
(fields (yas--snippet-fields snippet)))
(when-let (snippet (car-safe (yas--snippets-at-point)))
(let ((fields (yas--snippet-fields snippet)))
(evil-insert-state +1)
(unless fields (evil-change-state 'normal))))
(unless fields (evil-change-state 'normal)))))

View file

@ -57,7 +57,3 @@ buggy behavior when <delete> is pressed in an empty field."
(when (and field (> (point) sof))
(delete-region sof (point)))))
;; TODO move this to ivy
;;;###autoload
(defun +snippets/ivy-prompt (prompt choices &optional display-fn)
(yas-completing-prompt prompt choices display-fn #'ivy-completing-read))

View file

@ -23,7 +23,8 @@
yas-indent-line 'auto
yas-also-auto-indent-first-line t
yas-prompt-functions '(yas-completing-prompt yas-ido-prompt yas-no-prompt)
yas-snippet-dirs '(yas-installed-snippets-dir))
yas-snippet-dirs '(yas-installed-snippets-dir)
yas-use-menu nil)
;; Allows project-specific snippets
(defun +snippets|enable-project-modes (mode &rest _)
@ -43,6 +44,7 @@
"<M-right>" '+snippets/goto-end-of-field
"<M-left>" '+snippets/goto-start-of-field
"<S-tab>" 'yas-prev-field
"<backtab>" 'yas-prev-field
"<M-backspace>" '+snippets/delete-to-start-of-field
"<escape>" 'evil-normal-state
[backspace] '+snippets/delete-backward-char
@ -61,10 +63,9 @@
"Strip out the shitespace before a line selection."
(when (and (evil-visual-state-p)
(eq (evil-visual-type) 'line))
(setq-local
yas-selected-text
(setq yas-selected-text
(replace-regexp-in-string
"\\(^ *\\|\n? $\\)" ""
"\\(^\\s-*\\|\n? $\\)" ""
(buffer-substring-no-properties evil-visual-beginning
evil-visual-end)))))
(add-hook 'yas-before-expand-snippet-hook '+snippets|yas-before-expand)