diff --git a/modules/editor/snippets/autoload/snippets.el b/modules/editor/snippets/autoload/snippets.el index 5228f198e..1a651e6d2 100644 --- a/modules/editor/snippets/autoload/snippets.el +++ b/modules/editor/snippets/autoload/snippets.el @@ -47,7 +47,7 @@ ignored. This makes it easy to override built-in snippets with private ones." (abbreviate-file-name (yas--template-load-file tpl))) collect (progn - (set-text-properties 0 (length txt) `(uuid ,(yas--template-name tpl) + (set-text-properties 0 (length txt) `(uuid ,(yas--template-uuid tpl) path ,(yas--template-load-file tpl)) txt) txt)) @@ -169,9 +169,9 @@ buggy behavior when is pressed in an empty field." (interactive (list (+snippet--completing-read-uuid "Visit snippet: " current-prefix-arg))) - (if-let (template (yas--get-template-by-uuid major-mode template-uuid)) - (let* ((template (yas--get-template-by-uuid major-mode template-uuid)) - (template-path (yas--template-load-file template))) + (if-let* ((template (yas--get-template-by-uuid major-mode template-uuid)) + (template-path (yas--template-load-file template))) + (progn (unless (file-readable-p template-path) (user-error "Cannot read %S" template-path)) (find-file template-path) @@ -239,21 +239,22 @@ shadow the default snippet)." (list (+snippet--completing-read-uuid "Select snippet to alias: " current-prefix-arg))) - (let* ((major-mode (if (eq major-mode 'snippet-mode) - (intern (file-name-base (directory-file-name default-directory))) - major-mode)) - (template (yas--get-template-by-uuid major-mode template-uuid)) - (template-path (yas--template-load-file template))) - (if (file-in-directory-p template-path +snippets-dir) - (find-file template-path) - (let ((buf (get-buffer-create (format "*%s*" (file-name-nondirectory template-path))))) - (with-current-buffer (switch-to-buffer buf) - (insert-file-contents template-path) - (snippet-mode) - (setq default-directory - (expand-file-name (file-name-nondirectory template-path) - (expand-file-name (symbol-name major-mode) - +snippets-dir)))))))) + (if-let* ((major-mode (if (eq major-mode 'snippet-mode) + (intern (file-name-base (directory-file-name default-directory))) + major-mode)) + (template (yas--get-template-by-uuid major-mode template-uuid)) + (template-path (yas--template-load-file template))) + (if (file-in-directory-p template-path +snippets-dir) + (find-file template-path) + (let ((buf (get-buffer-create (format "*%s*" (file-name-nondirectory template-path))))) + (with-current-buffer (switch-to-buffer buf) + (insert-file-contents template-path) + (snippet-mode) + (setq default-directory + (expand-file-name (file-name-nondirectory template-path) + (expand-file-name (symbol-name major-mode) + +snippets-dir)))))) + (user-error "Couldn't find a snippet with uuid %S" template-uuid))) ;;;###autoload (defun +snippets-show-hints-in-header-line-h () diff --git a/modules/editor/snippets/config.el b/modules/editor/snippets/config.el index e35c223ba..37070e84c 100644 --- a/modules/editor/snippets/config.el +++ b/modules/editor/snippets/config.el @@ -78,18 +78,20 @@ ;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir') (add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h) - (map! :map yas-keymap - "C-e" #'+snippets/goto-end-of-field - "C-a" #'+snippets/goto-start-of-field - [M-right] #'+snippets/goto-end-of-field - [M-left] #'+snippets/goto-start-of-field - [M-backspace] #'+snippets/delete-to-start-of-field - [backspace] #'+snippets/delete-backward-char - [delete] #'+snippets/delete-forward-char-or-field - ;; Replace commands with superior alternatives - :map yas-minor-mode-map - [remap yas-new-snippet] #'+snippets/new - [remap yas-visit-snippet-file] #'+snippets/edit) + (map! (:map yas-keymap + "C-e" #'+snippets/goto-end-of-field + "C-a" #'+snippets/goto-start-of-field + [M-right] #'+snippets/goto-end-of-field + [M-left] #'+snippets/goto-start-of-field + [M-backspace] #'+snippets/delete-to-start-of-field + [backspace] #'+snippets/delete-backward-char + [delete] #'+snippets/delete-forward-char-or-field + ;; Replace commands with superior alternatives + :map yas-minor-mode-map + [remap yas-new-snippet] #'+snippets/new + [remap yas-visit-snippet-file] #'+snippets/edit) + (:map snippet-mode-map + "C-c C-k" #'+snippet--abort)) ;; REVIEW Fix #2639: For some reason `yas--all-templates' returns duplicates ;; of some templates. Until I figure out the real cause this fixes it.