yasnippet.el (yas-maybe-load-snippet-buffer): Don't move point (#1146)

This commit is contained in:
Stefan Monnier 2025-01-12 09:59:50 -05:00
parent fe1f4e0e96
commit 37d0b2790f

View File

@ -1,6 +1,6 @@
;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*- ;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*-
;; Copyright (C) 2008-2024 Free Software Foundation, Inc. ;; Copyright (C) 2008-2025 Free Software Foundation, Inc.
;; Authors: pluskid <pluskid@gmail.com>, ;; Authors: pluskid <pluskid@gmail.com>,
;; João Távora <joaotavora@gmail.com>, ;; João Távora <joaotavora@gmail.com>,
;; Noam Postavsky <npostavs@gmail.com> ;; Noam Postavsky <npostavs@gmail.com>
@ -2784,18 +2784,20 @@ Return the `yas--template' object created"
(defun yas-maybe-load-snippet-buffer () (defun yas-maybe-load-snippet-buffer ()
"Added to `after-save-hook' in `snippet-mode'." "Added to `after-save-hook' in `snippet-mode'."
(let* ((mode (intern (file-name-sans-extension (save-excursion ;; Issue #1146. Here or in `yas--parse-template`?
(file-name-nondirectory (let* ((mode (intern (file-name-sans-extension
(directory-file-name default-directory))))) (file-name-nondirectory
(current-snippet (directory-file-name default-directory)))))
(apply #'yas--define-snippets-2 (yas--table-get-create mode) (current-snippet
(yas--parse-template buffer-file-name))) (apply #'yas--define-snippets-2 (yas--table-get-create mode)
(uuid (yas--template-uuid current-snippet))) ;; FIXME: `yas-load-snippet-buffer' will *re*parse!
(unless (equal current-snippet (yas--parse-template buffer-file-name)))
(if uuid (yas--get-template-by-uuid mode uuid) (uuid (yas--template-uuid current-snippet)))
(yas--lookup-snippet-1 (unless (equal current-snippet
(yas--template-name current-snippet) mode))) (if uuid (yas--get-template-by-uuid mode uuid)
(yas-load-snippet-buffer mode t)))) (yas--lookup-snippet-1
(yas--template-name current-snippet) mode)))
(yas-load-snippet-buffer mode t)))))
(defun yas-load-snippet-buffer-and-close (table &optional kill) (defun yas-load-snippet-buffer-and-close (table &optional kill)
"Load and save the snippet, then `quit-window' if saved. "Load and save the snippet, then `quit-window' if saved.