786 Commits

Author SHA1 Message Date
Stefan Monnier
2384fe1655 yasnippet.el (yas--version): Delete variable.
(yas-about): Fall back to the Git description only if the package
version is not available.
(yas--make-menu-binding): Don't quote lambdas.
2025-04-03 15:26:13 -04:00
Stefan Monnier
81a59d1a85 yasnippet.el: Bug fix release 0.14.2 2025-04-03 12:43:37 -04:00
Stefan Monnier
2c20b10fc3 Misc minor pending tweaks
* yasnippet.el (yas-minor-mode): Fix docstring (issue#1210).
(yas--save-restriction-and-widen): Use workaround only for the old
Emacsen where it was needed.
(yas--snippet-create): Adjust Emacs version where CC-mode needed
a workaround.
(help-snippet-def): Remove useless use of `purecopy`.
2025-04-03 12:40:54 -04:00
Stefan Monnier
03b1b11547 yasnippet.el (yas--font-lock-keywords): Avoid font-lock-*-face vars 2025-01-12 10:04:11 -05:00
Stefan Monnier
37d0b2790f yasnippet.el (yas-maybe-load-snippet-buffer): Don't move point (#1146) 2025-01-12 09:59:50 -05:00
Benson Chu
ce54f1958f Push modifications to buffer-undo-list, even if unwinding 2024-10-13 10:48:59 -05:00
Vito Van
e23a80177a
(yas--all-parents): delete-dups for fundamental-mode
Before this commit,

(yas--all-parents 'lisp-mode) would return:

`(lisp-mode lisp-data-mode prog-mode fundamental-mode fundamental-mode)`

which would cause duplicated entries when prompting,
if the snippet were for fundamental-mode.
2024-04-06 17:34:18 +08:00
Stefan Monnier
33587a8551 (yas-reload-all): Flush the all-parents caches (issue #1194)
* yasnippet.el (yas--flush-all-parents): New function.
(yas-reload-all): Use it.

* yasnippet.el (issue-492-and-494): Don't flush the all=parents cache any
more since `yas-reload-all` does it for us.
2024-03-08 03:15:33 -05:00
Stefan Monnier
1ec7e3b6f7 (yas--all-parents): Obey derived-mode-extra-parents (Issue #1193) 2024-02-15 14:09:24 -05:00
Stefan Monnier
8e9ce76f7a yasnippet.el: Recognize ${N} as an alternative syntax for $N
(yas-define-snippets): Warn about identity conflicts.
(yas--one-simple-fom): New fun, extracted from `yas--simple-fom-create`.
(yas--simple-fom-create): Use it.
(yas--field-parse-create): Use it for ${N}.
2024-02-12 11:45:51 -05:00
Stefan Monnier
297546f085 yasnippet.el: Bug fix release 0.14.1 2024-01-23 21:58:24 -05:00
Stefan Monnier
b8f3f11ee5 yasnippet.el (yas--indent-region): Workaround for issue #1183 2024-01-22 13:46:51 -05:00
Stefan Monnier
47b38b2133 yasnippet.el (yas-define-snippets): Remove costly no-op 2024-01-22 13:46:05 -05:00
Marten Lienen
9228fd983b * yasnippel.el (yas-buffer-local-condition): Check functionp before consp to allow closures 2024-01-22 11:08:44 +01:00
Stefan Monnier
1d0966ae34 * yasnippet.el (yas-buffer-local-condition): Accept functions
(yas-not-string-or-comment-condition): Make it a function.
(yas--funcall-condition): Rename from `yas--funcall-condition`, change
its calling convention.
(yas--template-can-expand-p, yas--describe-pretty-table):
Adjust accordingly.
(yas--require-template-specific-condition-p): Add support for functions
in `yas-buffer-local-condition`.

* doc/snippet-expansion.org (The condition system <<condition-system>>):
Adjust example to avoid quoted code.
2024-01-19 12:38:21 -05:00
Stefan Monnier
25f5d8808a Avoid shadowing the tab => TAB remapping
* yasnippet.el (yas-keymap): Don't bind `tab`.
(yas--read-keybinding): Prefer the more precise \` and \' regexps.
(yas--parse-template): Use `pcase`.
2024-01-19 08:57:17 -05:00
Stefan Monnier
3e14a8534f (yas--on-protection-overlay-modification): Fix thinko 2024-01-18 10:31:17 -05:00
Stefan Monnier
9f253badfb yasnippet.el: Work around Emacs bug#65929 (see also issue#1175)
(yas--on-protection-overlay-modification): Ignore clearly bogus calls.
(yas-keymap-disable-hook): Improve docstring.
2024-01-17 13:24:15 -05:00
Stefan Monnier
23c7a6fa51 yasnippet.el: Minor simplifications
(yas--check-commit-snippet): De Morgan.
(yas-expand-snippet): Use `yas-current-field`.
2024-01-17 13:07:51 -05:00
Stefan Monnier
d12428082c yasnippet-tests.el: Fix some failures
* yasnippet-tests.el (yas-call-with-saving-variables): Don't `set` when
there's nothing to change.
(yas-with-overriden-buffer-list): Fix `buffer-list` override.
(loading-with-cyclic-parenthood, extra-modes-parenthood): Tweak tests
to be a bit less sensitive to details of ordering and number of
repetitions in `yas--modes-to-activate`.

* yasnippet.el (yas--all-parents): Make sure `mode` is always first in
the output, as is the case for `derived-mode-all-parents`.
(yas--modes-to-activate): Put extra modes first and not reversed, as
required by test `extra-modes-parenthood`.
2024-01-15 00:53:00 -05:00
Stefan Monnier
8ce506e32f * yasnippet.el (yas--all-parents): Don't add fundamental-mode to itself
Rename `yas--all-children` to `yas--cached-children` since it doesn't
contain "all" children.
2024-01-14 00:34:22 -05:00
Stefan Monnier
d7f55c7501 (yas--all-parents): Fix stale cache issue #1180
* yasnippet.el (yas--all-parents): Record children in `yas--all-children`.
(yas--define-parents): Use it to flush the caches of the affected modes.
2024-01-08 11:42:46 -05:00
Stefan Monnier
ae36504a5f yasnippet.el: Use derived-mode-all-parents when available
This allows YASnippet to obey `derived-mode-add-parents`, which should
become the standard way to indicate "loose" relationships (such as
the fact that `js3-mode` is related to `js-mode` or for TS modes).

* yasnippet.el (yas--merge-ordered-lists, yas--all-parents): New functions.
(yas--modes-to-activate): Use them.
2024-01-04 15:13:51 -05:00
Stefan Monnier
bd2fdc8f7d * yasnippet.el (yas--snippet-create): Remove CC-mode workaround for #953 2024-01-01 19:47:31 -05:00
Stefan Monnier
362e9b551d yasnippet.el (yas-about): Use package-get-version 2024-01-01 19:45:05 -05:00
Stefan Monnier
66db827a86 yasnippet.el: Use setq-local and defvar-local 2024-01-01 19:40:47 -05:00
Stefan Monnier
bcefd0a1c1 * yasnippet.el: Remove compatibility for Emacs<24.4
Since we already require Emacs≥24.4, there's not point keeping that
compatibility code.

(yas--modes-to-activate): Remove redundant `fboundp` test.
(yas-activate-extra-mode): Don't bother converting hashtable to alist
to pass to `completing-read`.
(yas-dont-activate-functions): Get rid of Emacs≤23 code.
(snippet-mode): `prog-mode` is always available.
(yas-x-prompt): `posn-at-point` is always available.
(yas--merge-and-drop-dups): `delete-consecutive-dups` is always available.
2024-01-01 19:36:59 -05:00
Stefan Monnier
2b328e563e * yasnippet.el (yas-wrap-around-region): Fix warning
Fix placement of `:tag` arg to `const` custom type.
2024-01-01 19:18:11 -05:00
Stefan Monnier
b86b44cce6 (yas--modes-to-activate): Pay attention to major-mode-remap-alist
Should hopefully fix issue #1169.
2024-01-01 16:17:58 -05:00
Stefan Monnier
52a1c50319 * yasnippet.el (debug-ignored-errors): Don't modify it
(debug-ignored-errors): Remove left over code that became obsolete with
commit 175e0a3a102c22.
(yas--read-lisp): Fix code generation.
(yas-exception): Use `define-error`.
2023-09-14 10:00:37 -04:00
Stefan Monnier
58c92ba393 * yasnippet.el: Cosmetic changes
Prefer #' to quote function names.
(yas-after-exit-snippet-hook, yas-before-expand-snippet-hook)
(yas-after-reload-hook): A hook is not a function, but a symbol
containing functions.  Fix doc accordingly.
(yas-define-snippets, yas-longest-key-from-whitespace)
(yas--field-parse-create): Make the doc fit within 80 columns.
(yas-skip-and-clear-or-delete-char): Fix ordering between `declare` and
`interactive`.
2023-09-14 10:00:37 -04:00
Stefan Monnier
043c52a5a9 * yasnippet.el (yas-minor-mode-map): Don't bind to tab 2023-09-14 10:00:37 -04:00
Stefan Monnier
e991530108 * yasnippet.el: Use add-function and remove left-over debug code
Instead of using `setq` and storing the old value in
`yas--original-auto-fill-function`, use `add-function`.
This makes it virtually impossible for a bug like #873/#919 to appear.
Remove the left-over debug code we had added to try and track down
#873/#919.

This requires bumping the dependency on Emacs≥24.4.

(yas--original-auto-fill-function, yas--watch-auto-fill-backtrace):
Delete variables.
(yas--watch-auto-fill): Delete function.  Don't add it to variable watchers.
(yas--auto-fill-wrapper): Use `add-function`.
(yas-minor-mode): Use `remove-function`.
(yas--auto-fill): Adjust its calling convention for use with `:around`
in `add-function`.  Remove left-over debug code.
(yas--post-command-handler): Remove left-over debug code.
2023-09-14 10:00:37 -04:00
Stefan Monnier
97002af846 * yasnippet.el: Use lexical-binding 2023-09-14 10:00:37 -04:00
Noam Postavsky
5cbdbf0d20 Handle errors during evaluation properly
* yasnippet.el (yas--eval-for-string): Convert error to a string,
rather than returning the error data (which can only lead to confusing
type errors later when code expecting a string gets a list).
* yasnippet-tests.el (yas-no-memory-of-bad-snippet): Adjust test, now
that snippet expansion swallows errors properly.
2020-06-03 22:46:18 -04:00
João Távora
d3d6d70b1c Correct manual call to after-change-functions
The pre-change-len argument passed to each element of
after-change-fucntions must reflect the length of the affected region
before the change happened.

In Yasnippet's case, the change enacted in yas--snippet-create is the
replacement of a region (which is almost always of length 0) with a
ready-to-navigate snippet template.  The previous implementation
calculated the length of the affected region after that change
happened, which is wrong.

See https://github.com/joaotavora/eglot/issues/462 for a case where
this mattered.

* yasnippet.el (yas--snippet-create): Correct manual call to
after-change-functions.
2020-05-24 23:15:54 +01:00
Noam Postavsky
5b1217ab08 ; Add some notes about narrowing, font-lock cc-mode issues
* yasnippet-tests.el (yas--with-font-locked-temp-buffer)
(example-for-issue-474):
* yasnippet.el (yas--snippet-create): Add commentary.
2020-04-13 18:21:21 -04:00
Noam Postavsky
1cc1996074 Don't bind inhibit-modification-hooks in yas--snippet-create
* yasnippet.el (yas--snippet-create): Bind before-change-functions and
after-change-functions to nil instead of inhibit-modification-hooks to
t while expanding snippet.  The latter also needlessly blocks overlay
and text property modification hooks (which we don't call ourselves
afterwards).  This way we allow packages like iedit to better
co-operate with yasnippet.
2020-04-12 19:50:12 -04:00
Noam Postavsky
170d13d069 Scan nested fields properly
* yasnippet.el (yas--scan-for-field-end): New function.
(yas--field-parse-create): Use it instead of yas--scan-sexps, which
isn't able to distinguish between ${...} (a nested field) and
{...} (plain old braces in the snippet text).
* yasnippet-tests.el (yas-escaping-close-brace): New test.
2020-04-04 20:47:21 -04:00
Noam Postavsky
7c02bc142c Fix failure on depth 2+ nested snippets
* yasnippet.el (yas--advance-end-maybe-previous-fields): New function.
(yas--commit-snippet, yas--on-field-overlay-modification)
(yas-expand-snippet): Use it, so that all active fields will be
extended properly, even in case of deeply nested snippet expansion.
* yasnippet-tests.el (nested-snippet-expansion-depth-2): New test.
2020-03-29 10:34:42 -04:00
Noam Postavsky
3bf9a3b1af Release 0.14.0
* NEWS: Update for 0.14.
* yasnippet.el (yas-installed-snippets-dir, yas--version): Bump
version.
2019-12-22 17:06:42 -05:00
Noam Postavsky
4046f61588 * yasnippet.el (yas-field-highlight-face): Remove redundant quote. 2019-12-13 16:01:51 -05:00
João Távora
1bee3a33c7 Fix #979: grok curly braces with LSP-style escaping
* yasnippet-tests.el (escaping-for-lsp-style-snippet-syntax): New
test.

* yasnippet.el (yas--field-parse-create): rework real-match-end-0
calculation.
2019-10-30 13:31:17 +00:00
Bao Haojun
a66f15e6c9 Fix yas-insert-snippet for keyless snippets
* yasnippet.el (yas--table-templates): Get snippets from uuidhash
table too.

Copyright-paperwork-exempt: yes
2019-10-08 22:16:25 -04:00
Stefan Monnier
d91dd66f2a * yasnippet.el (yas--extra-modes): Move alias before def 2019-07-24 08:04:46 -04:00
Noam Postavsky
bd3572a9b3 Handle multiple uses of yas-auto-next
* yasnippet.el (yas--auto-next): Loop again after moving to the next
field.
* yasnippet-tests.el (auto-next-field): Test for multiple
yas-auto-next uses.
2019-07-23 18:05:40 -04:00
Noam Postavsky
476bc77c34 Fix snippet undo
* yasnippet.el (yas--snippet-revive): Add revived snippet to
yas--active-snippets.
* yasnippet-debug.el (yas-debug-snippets): Print yas--active-snippets
length.
* yasnippet-tests.el (undo-revive-and-do-again): New test.
2019-06-30 13:20:19 -04:00
Noam Postavsky
f056a4def8 Minor code shuffling and commenting
* yasnippet.el (yas--do-todo-snippet-indent): Renamed from
yas--do-todo-snippet-indent.
2019-05-02 18:14:52 -04:00
Noam Postavsky
55c448b991 Remove redundant arg to yas-expand-snippet
* yasnippet.el (yas--expand-or-visit-from-menu)
(yas--expand-or-prompt-for-template)
(yas-visit-snippet-file, yas-tryout-snippet): Don't pass expand-env
when to yas-expand-snippet when first arg is a yas--template record.
2019-05-02 18:13:15 -04:00
Noam Postavsky
c432e78ffd Fix field adjustment on deletion
For deletion, we need to check the bounds before the deletion happens,
otherwise the overlay may already be moved to wrong place.
* yasnippet.el (yas--before-change-modified-snippets): New variable.
(yas--merge-and-drop-dups): New function.
(yas--gather-active-snippets): New function.
(yas--on-field-overlay-modification): Use it.

* yasnippet.el
2019-05-02 07:34:23 -04:00