Skip to content

Instantly share code, notes, and snippets.

@talwrii
Created March 25, 2017 09:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save talwrii/1025e35439e0a7fbc1175564b905d969 to your computer and use it in GitHub Desktop.
Save talwrii/1025e35439e0a7fbc1175564b905d969 to your computer and use it in GitHub Desktop.
Start defining a snippet if it does not exist
;; yas-edit.el -- Quickly edit yas snippets
;; Copyright Tal Wrii (talwrii@gmail.com)
;; LICENSED UNDER GPLv3
(require 'yasnippet)
(defvar yas-edit-callback nil)
(defvar yas-edit-last nil "The last snippet expanded")
(defun yas-edit (prefix)
(interactive "P")
(let (
(snippet (if (null prefix) (read-from-minibuffer "Snippet name:" yas-edit-last) prefix))
(mode major-mode)
;; damn newlines
)
(find-file (concat (car yas/root-directory) "/" (symbol-name major-mode) "/" snippet))
(message "Recursive edit. Exit recursive edit when done")
(funcall mode)
(let ((require-final-newline nil))
(if yas-edit-callback
(funcall yas-edit-callback))
(recursive-edit))
(kill-buffer)
(yas/reload-all)))
(defun yas-edit-repeat ()
"Repeat the last expansion"
;; Horrible hack
(interactive)
(evil-insert nil)
(insert yas-edit-last)
(yas-expand))
(defun yas-edit-last ()
(interactive)
(yas-edit yas-edit-last))
(defun yas-expand-or-edit ()
"Expand the word before the point or define a mapping"
(interactive)
(setq yas-edit-last (buffer-substring-no-properties (point) (save-excursion (backward-word) (point))))
(let ((expand-point (save-excursion (if
(equal (yas-expand) t)
(point) nil))))
;; HACK - this is not what yas does
(if
(equal expand-point nil)
(progn
(yas-edit (symbol-name (symbol-at-point)))
(yas-expand))
(goto-char expand-point))))
(provide 'yas-edit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment