1303 Commits

Author SHA1 Message Date
Stefan Monnier
47b38b2133 yasnippet.el (yas-define-snippets): Remove costly no-op 2024-01-22 13:46:05 -05:00
monnier
5af84cdb94
Merge pull request #1184 from martenlienen/local-condition-closure
Allow closures in yas-buffer-local-condition
2024-01-22 08:23:30 -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
d7a79d4a96 Fix remaining failing tests
* yasnippet-tests.el (issue-492-and-494): Make the test a bit less picky.
(test-yas-tab-binding, test-yas-in-org): Test TAB rather than `tab`
because at the level at which we do the test, `tab` is not remapped to TAB.
2024-01-19 08:55: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
c6488ac6fb README.mdown: Minor tweaks 2024-01-15 00:55:21 -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
9596631bde * README.mdown: Tweak install instructions
(Installation): Rename the Git install section to make it sound less
like the "normal&recommanded" way to install YAsnippet.
(Install with `package-install`): Mention GNU ELPA and GNU-devel ELPA.
2024-01-01 19:12:03 -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
009322196c * yasnippet-debug.el: Use advice-add i.s.o defadvice.
Now that we use `add-function`, we may as well avoid using the deprecated
`defadvice`

(cl-flet): Remove confusing `cl-flet` fallback, always provided by `cl-lib`.
(yas--snippet-parse-create, yas--commit-snippet):
Use `advice-add` i.s.o `defadvice`.
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
Stefan Monnier
b09ab98419 * yasnippet-tests.el: Minor cosmetic changes
Use utf-8 rather than latin-1.
Prefer #' to quote function names.
(special-mode): Remove backward compatibility code which never worked
since it uses `fundamental` which doesn't exist).
2023-09-14 10:00:29 -04:00
Stefan Monnier
6e4de312cf * doc/yas-doc-helper.el: Use cl-lib and lexical-binding
Also silence compiler warnings.
2023-09-14 09:59:23 -04:00
Stefan Monnier
946b27ddca * .gitignore: Add patterns for ELPA-generated files 2023-09-14 09:59:23 -04:00
João Távora
76e1eee654 Merge commit '0650f1989b6da752f60a15aa6b5222e340388cc2' from elpa.git 2023-09-12 11:13:25 -05:00
João Távora
3393975e1c Fix compilation problems of doc/yas-doc-helper.el 2023-09-05 02:05:16 +01:00
João Távora
849a134c2d Unbreak link in org docs
* doc/snippet-expansion.org: Fix a link
2023-09-05 02:03:14 +01:00
João Távora
50ba4f3821 Replace Rakefile with Makefile
* Makefile: New file
* Rakefile: Delete
2023-09-05 01:28:07 +01:00
Philipp Stephani
1ca316fb6d Unbreak unit tests under Emacs 28.
- Emacs 28 has a new mode ‘lisp-data-mode’ for Lisp data.
- A test that was temporarily broken passes again.
- The default for ‘org-adapt-indentation’ has changed.
2023-09-05 00:26:53 +01:00
Morgan Smith
0650f1989b Fix tests failing because of lisp-data-mode
* yasnippet-tests.el (extra-modes-parenthood): Add lisp-data-mode
(bug#48102).
2021-05-02 09:53:02 +02: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
291873ee13 ; .travis.yml: Clean up validator warnings/infos 2020-04-04 20:52:38 -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
ac03c2f192 ; Test on Emacs 27
* .travis.yml: Add 27-prerelease.  Change 26-prerelease to 26.3.
2020-03-25 22:38:30 -04:00
Noam Postavsky
3bf9a3b1af Release 0.14.0
* NEWS: Update for 0.14.
* yasnippet.el (yas-installed-snippets-dir, yas--version): Bump
version.
0.14.0
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