2015-06-15 09:05:52 +02:00
|
|
|
;;; defuns-yasnippet.el
|
|
|
|
;; for ../core-yasnippet.el
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom|yas-before-expand ()
|
2015-11-25 06:00:49 -05:00
|
|
|
"Strip out the shitespace before a line selection."
|
2016-05-20 22:37:30 -04:00
|
|
|
(when (doom/evil-visual-line-state-p)
|
2015-11-25 06:00:49 -05:00
|
|
|
(setq-local
|
|
|
|
yas-selected-text
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"\\(^ *\\|\n? $\\)" ""
|
|
|
|
(buffer-substring-no-properties (region-beginning)
|
|
|
|
(1- (region-end)))))))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom|yas-after-expand ()
|
2015-06-15 09:05:52 +02:00
|
|
|
"Switch to insert mode when expanding a template via backtab, or go back to
|
|
|
|
normal mode if there are no fields."
|
|
|
|
(setq yas-selected-text nil))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-insert-snippet ()
|
2015-06-15 09:05:52 +02:00
|
|
|
"Switch to insert mode when expanding a template via backtab, or go back to
|
|
|
|
normal mode if there are no fields."
|
|
|
|
(interactive)
|
2016-03-13 15:29:58 -04:00
|
|
|
(when (evil-visual-state-p)
|
|
|
|
(let ((end (region-end)))
|
|
|
|
(evil-visual-select
|
|
|
|
(region-beginning)
|
|
|
|
(if (eq evil-this-type 'line) end (1+ end))
|
|
|
|
'inclusive)))
|
2015-06-15 09:05:52 +02:00
|
|
|
(yas-insert-snippet)
|
2015-11-25 06:00:49 -05:00
|
|
|
(let* ((snippet (first (yas--snippets-at-point)))
|
|
|
|
(fields (yas--snippet-fields snippet)))
|
|
|
|
(evil-insert-state +1)
|
2015-11-25 21:21:01 -05:00
|
|
|
(unless fields (evil-change-state 'normal))))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-goto-start-of-field ()
|
2015-06-15 09:05:52 +02:00
|
|
|
"Go to the beginning of a field."
|
|
|
|
(interactive)
|
|
|
|
(let* ((snippet (car (yas--snippets-at-point)))
|
|
|
|
(position (yas--field-start (yas--snippet-active-field snippet))))
|
|
|
|
(if (= (point) position)
|
|
|
|
(move-beginning-of-line 1)
|
|
|
|
(goto-char position))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-goto-end-of-field ()
|
2015-06-15 09:05:52 +02:00
|
|
|
(interactive)
|
|
|
|
(let* ((snippet (car (yas--snippets-at-point)))
|
|
|
|
(position (yas--field-end (yas--snippet-active-field snippet))))
|
|
|
|
(if (= (point) position)
|
|
|
|
(move-end-of-line 1)
|
|
|
|
(goto-char position))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-backspace (&optional field)
|
2015-06-15 09:05:52 +02:00
|
|
|
"Prevents Yas from stepping on my toes when I use backspace."
|
|
|
|
(interactive)
|
|
|
|
(let ((field (or field (and yas--active-field-overlay
|
|
|
|
(overlay-buffer yas--active-field-overlay)
|
|
|
|
(overlay-get yas--active-field-overlay 'yas--field)))))
|
|
|
|
(cond ((eq (point) (marker-position (yas--field-start field))) nil)
|
|
|
|
(t (delete-char -1)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-delete (&optional field)
|
2015-06-15 09:05:52 +02:00
|
|
|
(interactive)
|
|
|
|
(let ((field (or field (and yas--active-field-overlay
|
|
|
|
(overlay-buffer yas--active-field-overlay)
|
|
|
|
(overlay-get yas--active-field-overlay 'yas--field)))))
|
|
|
|
(cond ((and field
|
|
|
|
(not (yas--field-modified-p field))
|
|
|
|
(eq (point) (marker-position (yas--field-start field))))
|
|
|
|
(yas--skip-and-clear field)
|
|
|
|
(yas-next-field 1))
|
|
|
|
((eq (point) (marker-position (yas--field-end field))) nil)
|
|
|
|
(t (delete-char 1)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-clear-to-sof (&optional field)
|
2015-06-15 09:05:52 +02:00
|
|
|
(interactive)
|
|
|
|
(let* ((field (or field (and yas--active-field-overlay
|
|
|
|
(overlay-buffer yas--active-field-overlay)
|
|
|
|
(overlay-get yas--active-field-overlay 'yas--field))))
|
|
|
|
(sof (marker-position (yas--field-start field))))
|
|
|
|
(when (and field (> (point) sof))
|
|
|
|
(delete-region sof (point)))))
|
|
|
|
|
|
|
|
;; Snippet helpers ;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/yas-find-file ()
|
2015-12-09 17:10:35 -05:00
|
|
|
"Browse through snippets folder"
|
2015-06-15 09:05:52 +02:00
|
|
|
(interactive)
|
2016-06-04 22:47:20 -04:00
|
|
|
(projectile-find-file-in-directory (car yas-snippet-dirs)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/yas-ivy-prompt (prompt choices &optional display-fn)
|
|
|
|
(yas-completing-prompt prompt choices display-fn #'ivy-completing-read))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
(provide 'defuns-yasnippet)
|
|
|
|
;;; nlinum-defuns.el ends here
|