Fix #4127: arrayp error on some snippets via +snippets/edit

This commit is contained in:
Henrik Lissner 2020-11-14 14:16:01 -05:00
parent ed1996e6f9
commit 523ced6e9a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 34 additions and 31 deletions

View file

@ -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))) (abbreviate-file-name (yas--template-load-file tpl)))
collect collect
(progn (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)) path ,(yas--template-load-file tpl))
txt) txt)
txt)) txt))
@ -169,9 +169,9 @@ buggy behavior when <delete> is pressed in an empty field."
(interactive (interactive
(list (list
(+snippet--completing-read-uuid "Visit snippet: " current-prefix-arg))) (+snippet--completing-read-uuid "Visit snippet: " current-prefix-arg)))
(if-let (template (yas--get-template-by-uuid major-mode template-uuid)) (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))) (template-path (yas--template-load-file template)))
(progn
(unless (file-readable-p template-path) (unless (file-readable-p template-path)
(user-error "Cannot read %S" template-path)) (user-error "Cannot read %S" template-path))
(find-file template-path) (find-file template-path)
@ -239,7 +239,7 @@ shadow the default snippet)."
(list (list
(+snippet--completing-read-uuid "Select snippet to alias: " (+snippet--completing-read-uuid "Select snippet to alias: "
current-prefix-arg))) current-prefix-arg)))
(let* ((major-mode (if (eq major-mode 'snippet-mode) (if-let* ((major-mode (if (eq major-mode 'snippet-mode)
(intern (file-name-base (directory-file-name default-directory))) (intern (file-name-base (directory-file-name default-directory)))
major-mode)) major-mode))
(template (yas--get-template-by-uuid major-mode template-uuid)) (template (yas--get-template-by-uuid major-mode template-uuid))
@ -253,7 +253,8 @@ shadow the default snippet)."
(setq default-directory (setq default-directory
(expand-file-name (file-name-nondirectory template-path) (expand-file-name (file-name-nondirectory template-path)
(expand-file-name (symbol-name major-mode) (expand-file-name (symbol-name major-mode)
+snippets-dir)))))))) +snippets-dir))))))
(user-error "Couldn't find a snippet with uuid %S" template-uuid)))
;;;###autoload ;;;###autoload
(defun +snippets-show-hints-in-header-line-h () (defun +snippets-show-hints-in-header-line-h ()

View file

@ -78,7 +78,7 @@
;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir') ;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir')
(add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h) (add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h)
(map! :map yas-keymap (map! (:map yas-keymap
"C-e" #'+snippets/goto-end-of-field "C-e" #'+snippets/goto-end-of-field
"C-a" #'+snippets/goto-start-of-field "C-a" #'+snippets/goto-start-of-field
[M-right] #'+snippets/goto-end-of-field [M-right] #'+snippets/goto-end-of-field
@ -90,6 +90,8 @@
:map yas-minor-mode-map :map yas-minor-mode-map
[remap yas-new-snippet] #'+snippets/new [remap yas-new-snippet] #'+snippets/new
[remap yas-visit-snippet-file] #'+snippets/edit) [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 ;; REVIEW Fix #2639: For some reason `yas--all-templates' returns duplicates
;; of some templates. Until I figure out the real cause this fixes it. ;; of some templates. Until I figure out the real cause this fixes it.