Created
July 20, 2023 12:44
-
-
Save Tokubara/e612f4652b422afbc6dfc7df17cc2331 to your computer and use it in GitHub Desktop.
delete-yasnippet-snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my/get-yasnippet-snippet-name () | |
"Get the name of the Yasnippet defined in the current buffer." | |
(save-excursion | |
(goto-char (point-min)) | |
(forward-line) | |
(when (looking-at "# name: \\(.*\\)$") | |
(match-string-no-properties 1)))) | |
(defun my/get-yasnippet-mode () | |
(when (eq major-mode 'snippet-mode) | |
(let* ((filename (buffer-file-name)) | |
(mode (file-name-directory filename))) | |
(car (last (split-string mode "/" t))) | |
))) | |
(defun my/delete-current-yasnippet-file () | |
(interactive) | |
(when (eq major-mode 'snippet-mode) | |
(let* ((filename (buffer-file-name)) | |
(uuid (my/get-yasnippet-snippet-name))) | |
(when (yes-or-no-p (format "Are sure you want to delete the snippet with UUID: %s?" uuid)) | |
(yas--remove-template-by-uuid (yas--table-get-create (intern (my/get-yasnippet-mode))) uuid) | |
(kill-buffer (current-buffer)) | |
(move-file-to-trash filename) | |
)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment