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)) (cl-letf (((symbol-function 'region-beginning) (lambda () evil-visual-beginning))
((symbol-function 'region-end) (lambda () evil-visual-end))) ((symbol-function 'region-end) (lambda () evil-visual-end)))
(yas-insert-snippet)) (yas-insert-snippet))
(let* ((snippet (first (yas--snippets-at-point))) (when-let (snippet (car-safe (yas--snippets-at-point)))
(fields (yas--snippet-fields snippet))) (let ((fields (yas--snippet-fields snippet)))
(evil-insert-state +1) (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)) (when (and field (> (point) sof))
(delete-region sof (point))))) (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-indent-line 'auto
yas-also-auto-indent-first-line t yas-also-auto-indent-first-line t
yas-prompt-functions '(yas-completing-prompt yas-ido-prompt yas-no-prompt) 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 ;; Allows project-specific snippets
(defun +snippets|enable-project-modes (mode &rest _) (defun +snippets|enable-project-modes (mode &rest _)
@ -43,6 +44,7 @@
"<M-right>" '+snippets/goto-end-of-field "<M-right>" '+snippets/goto-end-of-field
"<M-left>" '+snippets/goto-start-of-field "<M-left>" '+snippets/goto-start-of-field
"<S-tab>" 'yas-prev-field "<S-tab>" 'yas-prev-field
"<backtab>" 'yas-prev-field
"<M-backspace>" '+snippets/delete-to-start-of-field "<M-backspace>" '+snippets/delete-to-start-of-field
"<escape>" 'evil-normal-state "<escape>" 'evil-normal-state
[backspace] '+snippets/delete-backward-char [backspace] '+snippets/delete-backward-char
@ -61,12 +63,11 @@
"Strip out the shitespace before a line selection." "Strip out the shitespace before a line selection."
(when (and (evil-visual-state-p) (when (and (evil-visual-state-p)
(eq (evil-visual-type) 'line)) (eq (evil-visual-type) 'line))
(setq-local (setq yas-selected-text
yas-selected-text (replace-regexp-in-string
(replace-regexp-in-string "\\(^\\s-*\\|\n? $\\)" ""
"\\(^ *\\|\n? $\\)" "" (buffer-substring-no-properties evil-visual-beginning
(buffer-substring-no-properties evil-visual-beginning evil-visual-end)))))
evil-visual-end)))))
(add-hook 'yas-before-expand-snippet-hook '+snippets|yas-before-expand) (add-hook 'yas-before-expand-snippet-hook '+snippets|yas-before-expand)
(defun +snippets|yas-after-expand () (defun +snippets|yas-after-expand ()