1321 Commits

Author SHA1 Message Date
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
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
Bill Sacks
e45e3de357 * doc/faq.org: yas-prev should be yas-prev-field
Copyright-paperwork-exempt: yes
2019-05-08 18:42:08 -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
Noam Postavsky
ffce236268 Do auto indentation only in post command hook
* yasnippet.el (yas--todo-snippet-indent): New variable.
(yas--on-field-overlay-modification): Save snippet to it, and don't
indent after mirror update.
(yas--do-todo-field-updates): New function.
(yas--post-command-handler): Call it.
(yas--snippet-field-mirrors, yas--indent-mirrors-of-snippet): New
functions, split out from...
(yas--snippet-field-mirrors): ...here.
* yasnippet-tests.el (yas-test-delete-and-insert-command)
(indent-mirrors-on-complex-update): New test and helper function.
2019-05-01 17:52:26 -04:00
Noam Postavsky
6a738b581f ; doc/faq.org: Fix example keybinding code. 2019-04-30 20:44:40 -04:00
Noam Postavsky
fc33b2fbae Make overlay-modification protection optional
* yasnippet.el (yas-inhibit-overlay-modification-protection): New
variable.
(yas--on-protection-overlay-modification): Consult it.
2019-04-22 22:06:40 -04:00
Noam Postavsky
bae20af3de ; * doc/faq.org: Linkify bug reference. 2019-04-22 11:23:49 -04:00
Noam Postavsky
189f7375b6 * doc/faq.org: Note that Flyspell problem is (now fixed) Emacs bug. 2019-04-21 16:18:01 -04:00
Noam Postavsky
9cedd596ec Allow disabling snippet keybindings from hook
* yasnippet.el (yas-keymap-disable-hook): New hook.
(yas-filtered-definition): New function.
(yas-keymap): Use it.
* doc/faq.org: Update key redefinition example.
2019-04-21 16:11:44 -04:00
Noam Postavsky
7612bc1b70 Don't check this-command in yas-not-string-or-comment-condition
Since we now check conditions in conditional keybindings, it can be
evaluated before 'this-command' has been assigned.
* yasnippet.el (yas-not-string-or-comment-condition): Remove check of
'this-command'.
2019-04-21 15:25:02 -04:00
Noam Postavsky
6a3619b4f2 Fix additional corner case with org source block integration
* yasnippet.el (yas--on-buffer-kill): Check if the org-marker still points
to a buffer.
2019-04-21 14:18:14 -04:00
Noam Postavsky
048d030b68 Fix line-relative snapshotting for org src blocks
There was some half-backed code getting confused between "plain"
snapshort info and line+snapshot info leading to some type errors when
expanding snippets in org-mode src blocks.  I had wrongly assumed the
failures were only due to org version 9 changes (in fact, the org
changes only affect snippet expansion for text-mode (and probably
other non-fontifying modes too)).  Reorganize the snapshotting
functions so that line+snaphot has the line info after the marker,
next to the rest of the snapshot info.  This removes the need for list
manipulation and simplifies the code.  Furthermore, let the
restoration functions take the info as a list, rather than separate
arguments, this removes the need for several uses of `apply'.
* yasnippet.el (yas--snapshot-location): Renamed from
yas--snapshot-marker-location, don't return marker.
(yas--snapshot-line-location): New function.
(yas--goto-saved-location): Take single list arg.  Return point.
(yas--restore-marker-location): Remove, open code callers.
(yas--goto-saved-line-location)
(yas--restore-overlay-line-location): New functions.
(yas--prepare-snippets-for-move, yas--finish-moving-snippets)
(yas--auto-fill, yas--indent-region): Adjust callers of previously
mentioned functions accordingly.
* yasnippet-tests.el (yas-org-native-tab-in-source-block-text):
Renamed from yas-org-native-tab-in-source-block.
(yas-org-native-tab-in-source-block-emacs-lisp): New test.
(do-yas-org-native-tab-in-source-block): Take MODE parameter.
2019-04-14 12:06:44 -04:00
Noam Postavsky
dabc719921 Don't turn on yas-minor-mode in temp buffers
Generally, the user won't be interacting with, or creating snippets in
temporary buffers.
* yasnippet.el (yas-temp-buffer-p): New function.
(yas-dont-activate-functions): Add it to default value.
* yasnippet-tests.el (complicated-yas-key-syntaxes)
(test-yas-activate-extra-modes): Call yas-minor-mode instead of
yas-minor-mode-on, to ensure activation.
2019-04-10 08:06:25 -04:00
Martin Harrigan
8b25d627a4 * doc/snippet-development.org: Fix typos.
Copyright-paperwork-exempt: yes
2019-03-31 21:54:38 -04:00
Benjamin Hipple
03aa5618ae * doc/snippet-organization.org: Fix typo.
Copyright-paperwork-exempt: yes
2019-03-31 21:39:07 -04:00
Noam Postavsky
1d96da2e08 Don't call before/after change-functions twice
* yasnippet.el (yas--snippet-create): Let-bind
inhibit-modification-hooks for snippet insertion, so that we don't
call change functions automatically, we already call them manually
after insertion and parsing.
2018-10-15 08:12:51 -04:00
Noam Postavsky
9f51cf29c9 Register snippet movement comments for eldoc
* yasnippet.el (top-level): Call eldoc-add-command.
2018-10-13 17:22:12 -04:00
James Nguyen
bceb65ba29 Make backspace/DEL clear field (#957)
* yasnippet.el (yas-clear-field): New command.
(yas-maybe-clear-field): New conditional binding value.
(yas-keymap): Bind it to DEL.
2018-10-13 17:12:48 -04:00
Noam Postavsky
fb253ac607 New public function yas-maybe-expand-abbrev-key-filter
* yasnippet.el (yas-maybe-expand-abbrev-key-filter): Renamed from
yas--maybe-expand-key-filter.
2018-10-13 17:08:32 -04:00
Noam Postavsky
0f05a7555a Add yas-completing-read
* yasnippet.el (yas-completing-read): New function.
(yas-verify-value): Simplify with `member' instead of `cl-notany'.
* doc/snippet-development.org (Template Syntax): Show
`yas-completing-read' instead of `yas-choose-value' in the example.
2018-10-13 17:04:50 -04:00
Noam Postavsky
845222774b Consider fundamental-mode as ultimate ancestor
* yasnippet.el (yas--modes-to-activate): If a mode doesn't have a
`derived-mode-parent' property, use `fundamental-mode'.
* yasnippet-tests.el (loading-with-cyclic-parenthood)
(issue-492-and-494): Expect fundamental-mode to be active.
* doc/snippet-expansion.org (Eligible snippets): Mention that
fundamental-mode is a fallback parent mode.
2018-10-13 17:02:10 -04:00
Kofi Laing
760f77afb9 Test for mirroring more than one field
* yasnippet-tests.el (yas-mirror-many-fields): New test.
2018-10-08 22:51:28 -04:00
Noam Postavsky
3c0be40e21 Update FAQ
* doc/faq.org: Add two questions about yas-key-syntaxes.  Remove
reference to obsolete Google Groups.  Remove question about turning
off minor mode in some buffers, it was out of date, and not frequently
asked.
* yasnippet.el (yas-key-syntaxes): Fix docstring.
2018-10-07 18:30:44 -04:00
Noam Postavsky
eeb05f0910 Handle field adjust of pending active fields
* yasnippet.el (yas--on-field-overlay-modification): Call
yas--advance-end-maybe on all pending active snippets in case of
stacked expansion.
(yas-next-field): Get current snippet according to
active field bounds.
* yasnippet-tests.el (nested-snippet-expansion-4): New test.
2018-10-07 15:06:51 -04:00
Noam Postavsky
ffc733d4cf ; Debug code fixes
* yasnippet-debug.el (yas-debug-live-range): Consider an overlay as
live, not dead even though it has integer bounds.
(yas-debug-with-tracebuf): Add debug declaration.
2018-10-07 15:06:51 -04:00
Noam Postavsky
8328c38d77 Fix another failure of cc-mode indentation
Suggested by OGAWA Hirofumi in
https://github.com/joaotavora/yasnippet/issues/953.
* yasnippet.el (yas--snippet-create): Call before and after change
functions around yas--snippet-parse-create.
* yasnippet-tests.el (indent-cc-mode-2): New test.
2018-10-07 05:55:20 -04:00
Noam Postavsky
7a178a2ca0 Remove spurious change of before-change-functions
Found by OGAWA Hirofumi in
<https://github.com/joaotavora/yasnippet/issues/953>.
* yasnippet.el (yas--save-backquotes): Don't remove first entry of
before-change-functions.
2018-09-16 17:15:26 -04:00
João Távora
1e71360868
Per #947: fix typo in README.md
* README.md (Where are the snippets?): package-install, 
not install-package.
2018-07-22 18:31:33 +01:00
Noam Postavsky
d3bb879356 Remove last-buffer-undo-list compat definition
* yasnippet.el (last-buffer-undo-list): Remove, apparently it works
around some bug in "Carbon Emacs", but yasnippet is probably not the
right place for such a workaround anyway (yasnippet does not use
last-buffer-undo-list).
2018-06-20 20:50:52 -04:00
Noam Postavsky
79b90c9489 Remove compatibility code for Emacs 22 and earlier
* yasnippet.el (region-active-p, locate-dominating-stop-dir-regexp)
(locate-dominating-file): Remove.
2018-06-20 20:50:52 -04:00