joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.76k stars 314 forks source link

Expanding ${0:placeholder} doesn't replace placeholder text #1141

Open ruds opened 1 year ago

ruds commented 1 year ago
% emacs --version
GNU Emacs 28.1
Copyright (C) 2022 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
% git log -1 --oneline
5cbdbf0 (HEAD -> master, origin/master, origin/HEAD) Handle errors during evaluation properly
% HOME=$PWD emacs -L .

I evaluated the following elisp:

(require 'yasnippet)
(yas-global-mode 1)
(defun test-a ()
  (interactive)
  (yas-expand-snippet "return ${0:expression};"))

(defun test-b ()
  (interactive)
  (yas-expand-snippet "return ${1:expression};"))

When I do M-x test-a, the text return expression; is generated with point just before expression, but typing does not replace that placeholder text.

When I do M-x test-b, the same text is generated with point in the same place, but (as expected) typing replaces the placeholder expression.

The first snippet is produced by lsp-mode for completing code snippets in c-mode. When I filed https://github.com/emacs-lsp/lsp-mode/issues/3665 they suggested that I should file an issue in this project, because they expect that placeholders work for $0.

xiliuya commented 1 year ago

I had the same problem with eglot and clangd. Did you solve it?

xiliuya commented 1 year ago

I found my problem was the conflict with symbol-overlay. issues

KaranAhlawat commented 9 months ago

@ruds Did you ever find a fix for this?

dgutov commented 9 months ago

For anybody else who comes here: try adding (delete-selection-mode 1) to your init script.