Compare commits

...

301 Commits

Author SHA1 Message Date
Xiyue Deng
c1e6ff23e9
Drop use of `yas--version' in doc/yas-doc-helper.el
- No longer available since 0.14.3
2025-06-04 01:29:16 -07:00
Stefan Monnier
dd570a6b22 yasnippet.el: Bump version to trigger release
* yasnippet-tests.el (string-suffix-p): Remove fallback definition.
2025-06-02 09:42:36 -04:00
Stefan Monnier
272b6067f1 Try and fix issue #1214
* yasnippet.el (yas--load-directory-1): Add a `lexical-binding` cookie
to the compiled-snippet files, and silence warnings if it's absent from them.
(yas--letenv-f): New function extracted from `yas--letenv`.
(yas--letenv): Use it.
2025-06-01 18:43:13 -04:00
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
5b315f1753 Misc fixes found via compilation warnings
* yasnippet-debug.el (yas-debug-snippets): Improve commit 009322196cfa.
* yasnippet-tests.el (test-rebindings): Avoid `copy-keymap`.
2025-01-12 17:51:54 -05: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
monnier
fe1f4e0e96
Merge pull request #1149 from pestctrl/quit-undo-tree
Push modifications to buffer-undo-list, even if unwinding
2024-10-13 11:57:55 -04:00
Benson Chu
ce54f1958f Push modifications to buffer-undo-list, even if unwinding 2024-10-13 10:48:59 -05:00
monnier
eb5ba2664c
Merge pull request #1196 from VitoVan/master
(yas--all-parents): delete-dups for fundamental-mode
2024-04-06 09:14:51 -04: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
monnier
15065c36b4
Merge pull request #1194 from gutron/master
Undo all-parents memoization in test
2024-03-01 18:27:46 -05:00
Ron Gut
ab03a754e7 Undo all-parents memoization in test
yas-reload-all does not undo the memoization done in yas--all-parents, which
causes the issue-492-and-494 test to fail when run after any tests that
expands yas-with-some-interesting-snippet-dirs.

With the memoization enabled, c++-mode is considered a parent of c-mode,
causing the issue-492-and-494 test to fail.  With the memoization reset,
this does not occur.
2024-02-28 19:26:45 -05:00
Stefan Monnier
5b565c54b0 NEWS: Give a few more details 2024-02-15 15:34:45 -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
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.
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
Noam Postavsky
e67592ce1b Don't use overlays to find active snippets
* yasnippet.el (yas--active-snippets): New buffer-local variable.
(yas-active-snippets): Use it, when asked for all active snippets.
(yas--commit-snippet): Remove finished snippet from list of active
snippets.
(yas--snippet-create): Add new snippet to list of active snippets.
(yas--check-commit-snippet): Consult list of active snippetes.
2018-06-06 20:22:57 -04:00
Noam Postavsky
4af33546d8 Make less garbage in overlay heavy buffers
* yasnippet.el (yas-active-snippets): Use dolist+when-push instead of
mapcar+delq.
2018-06-06 08:22:58 -04:00
João Távora
4f78d03f85 Close #937: Officially support automatically moving to next field
* yasnippet-tests.el (auto-next-field): New test.
(yas-saving-variables): Move up in the file.

* yasnippet.el (yas--auto-next): New helper.
(yas-auto-next): New user-visible snippet helper.

* doc/snippet-development.org (Choosing fields value from a list
and other tricks): Add mention of yas-auto-next.
2018-05-26 19:33:52 +01:00
Noam Postavsky
5a29fe67d7 Release 0.13.0
* yasnippet-debug.el:
* yasnippet-tests.el:
* yasnippet.el: Bump version to 0.13.0.  Bump copyright years.
* NEWS: Update for 0.13
2018-05-13 13:04:50 -04:00
Noam Postavsky
4755aa9781 Clarify behavior of mirror transforms
* doc/snippet-development.org (mirror-fields): Note that all mirros
are updated when any field is changed.
(mirror-transformations): Add an example of a mirror taking values
from multiple fields.
2018-05-13 12:11:05 -04:00
João Távora
b0aa5c2816 Tweak bug-reporting information slightly
In the README and in the FAQ, mention and link to the list of support
issues in the Github issue tracker.

Rewrite README.mdown slightly for readability and suggest the GH
tracker as primary place for YASnippet discussion.

Retire the YASnippet google group.

* README.mdown (Manual, issues, etc): Mention docs, support issues
and issue tracker separately.  Remove reference to the YASnippet
google group.
(Where are the snippets?): Properly write YASnippet for
consistency.

* doc/faq.org: Add note and link to support issues.
2018-04-29 01:38:27 +01:00
Noam Postavsky
f9231b0e3d Work around Emacs Bug#30931 (Misc_Free in undo list)
* yasnippet.el (yas--remove-misc-free-from-undo): New function.
(yas--save-restriction-and-widen): New macro.
(yas--eval-for-string, yas--snippet-parse-create)
(yas--indent-region, yas--save-backquotes)
(yas--restore-backquotes, yas--update-mirrors): Use it.
2018-04-12 18:48:12 -04:00
Noam Postavsky
16686075bb Don't add to disabled undo list
Previously, we were unconditionally pushing entries onto the undo
list, which effectively enables undo, even in buffers where it's
disabled.
* yasnippet.el (yas--commit-snippet, yas--snippet-revive)
(yas--snippet-create): Check that `buffer-undo-list' is a list before
pushing to it.
2018-04-12 18:48:12 -04:00
Noam Postavsky
fa6a71c42d ; Wait until post-command, or bad auto-fill call to print stacktrace
If we popup a warning as soon as yas--original-auto-fill-function is
changed to nil, we'll have false positives in cases where
auto-fill-function was *also* going to be turned nil afterwards.

* yasnippet.el (yas--watch-auto-fill-backtrace): New variable, to save
backtrace into.
(yas--watch-auto-fill): Check both yas--original-auto-fill-function
and auto-fill-function, but only save the backtrace, don't popup the
debugger.
(yas--auto-fill): Also print the saved backtrace if
yas--original-auto-fill-function is nil.
(yas--post-command-handler): Print the saved backtrace if
yas--original-auto-fill-function and auto-fill-function is
yas--auto-fill, which means we're in a bad state.
2018-03-19 09:07:34 -04:00
Noam Postavsky
a0d2cff79b ; Don't enter debugger for kill-all-local-variables case
* yasnippet.el (yas--watch-auto-fill): If we're called from
kill-all-local-variables, we don't need to check this, because
auto-fill-function will shortly be set to nil as well.
2018-03-18 09:39:00 -04:00
Noam Postavsky
ae95810289 ; Try to get more info about 873/919
* yasnippet.el (yas--watch-auto-fill): New variable watcher to catch
the problem.
(yas--auto-fill): If `yas--original-auto-fill-function' is nil, print
a warning with some info instead of signaling an error.
2018-03-17 07:31:54 -04:00
Noam Postavsky
5170f051ad Don't indent first and only line of expanded snippet
Unless yas-also-auto-indent-first-line applies.
* yasnippet.el (yas--indent): Check that forward-line successfully
moved 1 line forward before trying to indent.
* yasnippet-tests.el (yas-indent-first-line)
(yas-indent-first-line-fixed): New tests.
2018-03-10 19:14:42 -05:00
Noam Postavsky
15761e85d6 Adjust previous fix
* yasnippet.el (yas--indent): Call `beginning-of-line' before doing
fixed indentation.
2018-03-06 07:24:57 -05:00
Noam Postavsky
4467e934f3 Use fancy field adjustment for fixed indent too
* yasnippet.el (yas--indent): When `yas-indent-line' is `fixed',
instead of calling `indent-to-column' on each line directly, bind
`indent-line-function' and use `yas--indent-region'.  The latter uses
some clever tricks to keep field regions from extending into the newly
created whitespace.
2018-03-04 19:07:12 -05:00
Noam Postavsky
58b88d8be6 Merge: doc style improvements 2018-03-04 19:05:57 -05:00
Noam Postavsky
d364425176 * yasnippet.el (yas-field-value): Fix docstring. 2018-03-04 19:02:36 -05:00
Noam Postavsky
3032337831 Improve rendering of docstrings in manual's reference section
* doc/yas-doc-helper.el (yas--org-raw-html): Accept an ATTRS argument.
(yas--document-symbol): Render variables with <code
class='variable>... and functions with <code
class='function'>... instead of =...=.  Render indented lisp
forms (recognized as lines beginning 4+ spaces followed by open paren)
with #+BEGIN_SRC elisp...#+END_SRC.  Render \\{keymap} with
substitute-command-keys and #+BEGIN_EXAMPOE...#+END_EXAMPLE.  Link
"Info node `(manul) Node Name'" to gnu.org manual page.
* yasnippet.el (yas-prompt-functions): Add spaces to make example lisp
form be recognized as lisp.
2018-03-04 19:02:36 -05:00
Noam Postavsky
e261832b1a Add some styling to doc, improve top menu
* doc/snippet-expansion.org:
* doc/snippet-organization.org: Fix typos.
* doc/stylesheets/manual.css: Add some simple styling.  Mainly, this
sets 'max-width' for the main text, and centers it.  Adjust the
background color.
* doc/nav-menu.html.inc: Adjust 'class' of top menu.
* doc/yas-doc-helper.el (yas--make-preamble): New function, used for
:html-preamble.  It sets the element for the current page in the top
menu as bolded text to aid navigation.
* doc/stylesheets/styles.css: Remove, it was unused since the old rst
manual was removed.
2018-03-04 19:02:24 -05:00
Noam Postavsky
0afc638e16 Fix docs for new org mode
* Rakefile: Comment to remind me how to run it.
* doc/snippet-expansion.org:
* doc/snippet-menu.org: It seems org 9.x got a bit stricter about link
formatting.  Cross-file links *must* use the 'file:' prefix.
* doc/yas-doc-helper.el (yas--document-symbol): Org 9.x also got a bit
more strict about empty lines between a node and its property list.
Make sure not to put a blank line between variable nodes and the
property list.
2018-03-04 18:56:26 -05:00
Noam Postavsky
3d7cafccf8 Make yas-snippet-mode-buffer-p robust against symlinks
* yasnippet.el (yas-snippet-mode-buffer-p): Instead of a string
comparison of file names to check whether the buffer file is in on of
the `yas-snippet-dirs', use the builtin `file-in-directory-p'
function.
2018-02-18 07:59:33 -05:00
Noam Postavsky
cf23537279 Fix expansion of commands snippet
The previous changed failed to account for command snippets which have
lists for bodies, not strings.
* yasnippet.el (yas-expand-snippet): Don't error if SNIPPET is a list
representing a command snippet body.
* yasnippet-tests.el (yas-expand-command-snippet): New test.
2018-02-13 09:02:23 -05:00
Noam Postavsky
c9277d326e Change yas-lookup-snippet to return a yas--template struct
This allows proper handling of a snippet's expand-env field when doing

    (yas-expand-snippet (yas-lookup-snippet NAME))

* yasnippet.el (yas-expand-snippet): Return the yas--template struct
instead of snippet body.
(yas-expand-snippet): Let first argument be a yas--template struct.
* yasnippet-tests.el (snippet-lookup, snippet-load-uuid): Update tests
accordingly.
(yas-lookup-snippet-with-env): New test.
2018-02-11 17:42:24 -05:00
Noam Postavsky
05ac1da894 ; yasnippet-tests.el (yas-no-memory-of-bad-snippet): Fix docstring. 2018-02-07 18:37:00 -05:00
Noam Postavsky
caf3dba320 Don't use global variable for backquote expression locations
* yasnippet.el (yas--backquote-markers-and-strings): Remove.
(yas--save-backquotes): Return list of backquote expressions.
(yas--restore-backquotes): Receive it as a parameter.
(yas--snippet-parse-create): Keep it in a local variable.
* yasnippet-tests.el (yas-no-memory-of-bad-snippet): New test.
2018-02-04 19:13:48 -05:00
Noam Postavsky
7c9edb5b34 ; doc/snippet-development.org: Further copy edit. 2018-02-02 09:57:16 -05:00
Joerg Bornemann
60666310af Fix typos in "Writing Templates" documentation
* doc/snippet-development.org: Fix typos.

Copyright-paperwork-exempt: yes
2018-02-02 09:53:32 -05:00
Noam Postavsky
ba73f20bc3 Bind field skip and clear command conditionally
Rather than embedding the conditionality inside the function body, and
hardcoding fallback to `delete-char'.  This allows users who want, for
example, to use backspace for field skipping to simply do

    (define-key yas-minor-mode-map (kbd "DEL")
      yas-maybe-skip-and-clear-field)

* yasnippet.el (yas-skip-and-clear-field, yas-current-field)
(yas--maybe-clear-field-filter): New command and function, extracted
from yas-skip-and-clear-or-delete-char.
(yas-skip-and-clear-or-delete-char): Mark obsolete.
(yas-maybe-skip-and-clear-field): New constant, for conditional
binding.
(yas-keymap): Bind it to `C-d' instead of
`yas-skip-and-clear-or-delete-char'.
* yasnippet-tests.el (delete-numberless-inner-snippet-issue-562): Use
`yas-skip-and-clear-field' instead of
`yas-skip-and-clear-or-delete-char'.
2018-02-02 09:52:10 -05:00
Noam Postavsky
074d670be4 Add yasnippet-unload-function
* yasnippet.el (yasnippet-unload-function): New function.
* yasnippet-debug.el (yas-exterminate-package): Remove, it was only
doing a partial job of undoing modes, and uninterning is entirely not
needed.
* yasnippet-tests.el (yas-unload): New test.
2018-01-31 08:11:04 -05:00
Noam Postavsky
e35c031410 * yasnippet.el (yas--guess-snippet-directories): Guess major mode first. 2018-01-31 07:44:35 -05:00
Noam Postavsky
2e69471df2 ; yasnippet-debug.el: macroexp-progn is not avaiable in Emacs 23. 2018-01-31 07:39:37 -05:00
Noam Postavsky
ff8e833375 ; yasnippet-debug.el: Fix deprecation warning. 2018-01-31 07:37:48 -05:00
Noam Postavsky
6ffd1c7950 ; .travis.yml: Test with 25.3 and 26 prelease. 2018-01-31 06:36:35 -05:00
Noam Postavsky
fe9f8b6c98 ; yasnippet-debug.el: Update yas-debug-snippets arg for previous change. 2018-01-31 06:34:43 -05:00
João Távora
8b421bc78d Reinstate the old debug behaviour for yas-tryout-snippet
During a redesign of the debug facilities, the old shortcut C-u C-t
available and useful in snippet-mode, was lost.

* yasnippet-debug.el (yas-debug-snippets): Add docstring.
Add post-command-hook locally if HOOK is snippet-navigation.
Concisely describe parent field (not just mention it).

* yasnippet.el (yas-tryout-snippet): Call yas-debug-snippets and display
buffer.  Tweak docstring.
(yas-debug-snippets): Forward declare function defined in
yasnippet-debug.el
2018-01-24 22:45:14 +00:00
João Távora
ff26e3ba7f Close #824: Simple fields can be parented like other fields or mirrors
The fact that they didn't prevented a deletion of the parent field to
also delete the child, confusing snippet navigation.

* yasnippet-tests.el (delete-nested-simple-field-issue-824): Add a
test for this issue.

* yasnippet.el (yas--calculate-simple-fom-parentage): Renamed from
yas--calculate-mirrors-in-fields.  Generalize to FOMs.
(yas--transform-mirror-parse-create): Call yas--simple-fom-create
and yas--calculate-simple-fom-parentage.
(yas--simple-fom-create): Rename from
yas--simple-mirror-parse-create.  Call
yas--calculate-simple-fom-parentage also for fields.
2018-01-24 22:45:02 +00:00
Noam Postavsky
16c2b38bce Update `yas--take-care-of-redo' call in buffer undo list
On 2018-01-01 "Fix undo when first line indentation moves snippet
forward", `yas--take-care-of-redo' removed the BEG and END arguments,
but the call added to `buffer-undo-list' from `yas--snippet-revive',
was not updated accordingly.

* yasnippet.el (yas--snippet-revive): Remove `beg' and `end' from
`yas--take-care-of-redo' entry.
* yasnippet-tests.el (undo-redo): New test.
2018-01-21 15:13:25 -05:00
Noam Postavsky
203059a95e * yasnippet.el (yas-key-syntaxes): Prefer the longest key. 2018-01-11 18:33:53 -05:00
Noam Postavsky
ad3a4d192d Don't use prog-mode in older Emacs
* yasnippet.el (snippet-mode): Derive from prog-mode only if it's
fbound.
* yasnippet-tests.el (extra-modes-parenthood)
(loading-with-cyclic-parenthood): Fix comment typo.
2018-01-11 18:28:41 -05:00
Noam Postavsky
d806b04fc0 * yasnippet.el (snippet-mode): Derive from prog-mode. 2018-01-11 18:28:41 -05:00
Noam Postavsky
04062d8b4f Don't set yas-selected-text to non-selected text
* yasnippet.el (yas-expand-snippet): Only use the `to-delete' text if
`region-active-p' return true.
* yasnippet-tests.el (expand-with-unused-yas-selected-text): New test.
2018-01-02 21:24:48 -05:00
Noam Postavsky
ce11fd6690 * yasnippet.el (yas-reload-all): Mention if no snippets were found. 2018-01-01 15:11:56 -05:00
Noam Postavsky
b1ca219706 Remove submodules (snippet and yasmate)
* snippets:
* yasmate: Remove.
* README.mdown: Suggest yasnippet-snippets and yasmate as possible
things to download rather than submodules.
* yasnippet.el (yas-installed-snippets-dirn): Mark obsolete.
(yas-snippet-dirs): Remove `yas-installed-snippets-dir' from
default value.
2018-01-01 15:11:55 -05:00
Noam Postavsky
ee81da91d9 Allow "# --" end-of-header marker to have trailing space
* yasnippet.el (yas--parse-template): Allow trailing space after "#
--" marker.
2018-01-01 15:09:32 -05:00
Noam Postavsky
1292cd263a Refactor undo tests
* yasnippet-tests.el (yas-test-expand-and-undo): New helper function.
(undo-indentation-1, undo-indentation-2, undo-indentation-multiline-1)
(undo-indentation-multiline-2): Use it.
2018-01-01 15:07:01 -05:00
Noam Postavsky
7ea1305e67 Fix undo when first line indentation moves snippet forward
* yasnippet.el (yas--first-indent-undo, yas--get-indent-undo-pos):
Remove.
(yas-expand-snippet): Move undo-related code from here...
(yas--snippet-create): ... to here.  Collect undo information from
yas--indent in the normal, unsuppressed way.
(yas--indent-region): Don't collect undo information specially.
(yas--take-care-of-redo): Remove unused parameters.
* yasnippet-tests.el (undo-indentation-1): Rename from
undo-indentation.
(undo-indentation-2): New test.
(undo-indentation-multiline-1): Rename from
undo-indentation-multiline.
(undo-indentation-multiline-2): New test.
2018-01-01 15:07:01 -05:00
Noam Postavsky
e200a3b9b1 Let snippet insertion trigger active field clearing.
* yasnippet.el (yas-expand-snippet): Since the actual insertion must
happen with modification hooks inhibited, we can't rely on that
mechanism to clear the field.  Call yas--skip-and-clear-field-p on the
active field.
2018-01-01 14:59:25 -05:00
Juergen Hoetzel
ece7935d7a * yasnippet.el (yas--message): Fix invalid docstring reference.
Copyright-paperwork-exempt: yes
2018-01-01 14:44:09 -05:00
Kaligule
acec3ba3ae * doc/faq.org: Fix typo.
Copyright-paperwork-exempt: yes
2018-01-01 14:42:27 -05:00
Noam Postavsky
0b8d43490c Unset autoload-compute-prefixes for utility files
* yasnippet-debug.el:
* yasnippet-tests.el: Set autoload-compute-prefixes to nil
file-locally.
2018-01-01 12:59:52 -05:00
Noam Postavsky
4ab9cb5bac Set test to fail with newer org version
* yasnippet-tests.el (yas-org-native-tab-in-source-block): Expect to
fail for org 9.x.
2017-11-25 18:01:28 -05:00
Noam Postavsky
35a4df769c Let whitespace-global-mode work in new snippet buffers
* yasnippet.el (yas-new-snippet-buffer-name): New constant, holds the
name of new snippet buffers.  Change it to "+new-snippet+" to avoid
the leading "*" from fooling whitespace-global-mode into thinking it
shouldn't activate.
(yas-new-snippet):
* yasnippet-tests.el (snippet-save): Use the constant instead of
hardcoding the literal string.
2017-09-23 19:46:07 -04:00
Noam Postavsky
1fc34266a4 Add test relying on overlay hook inhibition in `yas-expand-snippet'
* yasnippet-tests.el
(insert-snippet-with-backslashes-in-active-field): New test.
2017-09-23 19:38:57 -04:00
Noam Postavsky
ba4e5c1736 * yasnippet-debug.el (yas-debug-snippet): Handle non-numbered fields. 2017-09-23 18:32:57 -04:00
Noam Postavsky
89eb7ab64d Release 0.12.2
* NEWS: Add changes for 0.12.2.
* yasnippet.el: Bump version.
* snippets: Update submodule.
2017-08-28 22:08:58 -04:00
Noam Postavsky
c79c8df599 Add yas-also-indent-empty-lines to allow old indent behavior
* yasnippet.el (yas-also-auto-indent-first-line): New option.
(yas--indent-region): Also indent empty lines if it's set.
* yasnippet-tests.el (yas-also-indent-empty-lines): New test.
2017-08-18 22:16:45 -04:00
Noam Postavsky
e371c119ec Don't keep region active when expanding from keymap
* yasnippet.el (yas-expand-snippet): Only keep region active if we are
going to field $0 and it has some text.
2017-08-08 12:40:33 -04:00
Noam Postavsky
0463c75b63 Release 0.12.1
* NEWS: Changes for 0.12.1.
* yasnippet.el (yas--version): Bump version number.
2017-07-23 18:30:56 -04:00
Noam Postavsky
dd65fe6186 Add compile_all target, fix all compilation warnings
* Rakefile (.elc): Set byte-compile-force-lexical-warnings when
compiling.
(:compile_all): New target that compiles yasnippet-debug.el and
yasnippet-tests.el too.
* .travis.yml (script): Use it instead of `compile'.  Update cl-lib to
0.6.1.  Don't error on warnings for Emacs 24.3 on yasnippet-tests.el.
* yasnippet-debug.el: Don't use `yas--loaddir' if it's not
bound (e.g., when compiling).  Require `color' and `edebug' at
toplevel.  Check if `subr-x' defines `when-let'.
(yas-debug-snippet-vars): Remove, it was unused and broken.
* yasnippet-tests.el (yas-with-snippet-dirs, (yas-should-expand)
(yas--collect-menu-items, yas-should-not-expand, yas-mock-insert)
(yas-mock-yank, yas--key-binding, yas-make-file-or-dirs)
(yas-variables, yas-call-with-saving-variables)
(yas-call-with-snippet-dirs, special-mode, string-suffix-p): Move to
top section.
(yas-tests--ran-exit-hook): Rename from yas--ran-exit-hook, and move
to top-level.
* yasnippet.el (yas--letenv): Evaluate the FORMs of ENV.
2017-07-23 08:11:36 -04:00
Stefan Monnier
304c01a44a Fix some compilation warnings
* yasnippet-debug.el (yas--condition-cache-timestamp): Move it before first use.
(yas-debug-live-marker, yas-debug-live-range, yas-debug-snippet-vars)
(yas-debug-process-command-line): Remove or mark unused
variable/parameters.
(yas--letenv): Use `cl-progv'.
(yas--mirror-update-display): Remove unused SNIPPET parameter, update
caller.
2017-07-23 08:11:35 -04:00
Pierre Téchoueyres
7365f9ed40 Avoid to indent snippets having setup `(yas-indent-line 'fixed)'
Avoid `yas--auto-fill' call to `yas--update-mirrors' without setting
the snippet environment.

* yasnippet.el (yas--auto-fill): Reinstate snippet environment before
calling `yas--update-mirrors'.
2017-07-23 07:18:20 -04:00
Noam Postavsky
75cbf7251b Update NEWS, version number to 0.12, and snippets submodule
* NEWS: Update for 0.12 changes.
* snippets/: Update to latest.
* yasnippet-debug.el:
* yasnippet-tests.el:
* yasnippet.el: Update copright years.  Update version number to
0.12.0.
2017-07-17 22:46:04 -04:00
Noam Postavsky
2a3a0cd2b1 Update CONTRIBUTING.md information
* README.mdown: Note that bugs can be submitted to main Emacs list.
* CONTRIBUTING.md: Fix double spacing, remove carriage returns.
Tighten up commit message example.
2017-07-16 19:38:41 -04:00
Noam Postavsky
1436d211d2 ; Merge yasnippet-debug.el updates 2017-07-16 15:23:04 -04:00
Noam Postavsky
164acd6869 * yasnippet-debug.el (yas-debug-snippet): Show modified flag. 2017-07-16 15:19:35 -04:00
Noam Postavsky
b0e729b1de Optionally add undo list to debug info
* yasnippet-debug.el (yas-debug-undo): New variable.
(yas-toggle-debug-undo): New command.
(yas-debug-snippets): Print undo list if `yas-debug-undo' is non-nil.
2017-07-16 15:19:35 -04:00
Noam Postavsky
7b03ac2030 Handle dead snippets better
* yasnippet-debug.el (yas-debug-live-marker)
(yas-debug-ov-fom-start, yas-debug-ov-fom-end)
(yas-debug-live-range, yas--debug-format-fom-concise): Don't assume
snippet has markers, it could have been converted to integer position.
2017-07-16 15:19:34 -04:00
Noam Postavsky
2f5cb2e2ef Make yas-debug-process-command-line easier to debug
* yasnippet-debug.el (yas-debug-process-command-line): Allow giving
options programatically
2017-07-16 15:19:34 -04:00
Noam Postavsky
274406ee44 Provide command line interface from yasnippet-debug.el
yasnippet-debug.el can now be used to quickly test and debug a snippet
in a file.

* Rakefile (itests): New target, runs tests interactively.
* yasnippet-debug.el: Set lexical binding.
(when-let): Backwards compabtility definition.
(yas-debug-live-indicators, yas-debug-live-colors)
(yas-debug-recently-live-indicators, yas-debug-get-live-indicator)
(yas-debug-live-marker, yas-debug-ov-fom-start, yas-debug-ov-fom-end)
(yas-debug-live-range, yas-debug-with-tracebuf, yas-debug-snippet)
(yas-debug-target-buffer, yas-debug-target-snippets)
(yas-debug-snippets, yas-debug-process-command-line): New functions
and variables.
(yas-debug-test): Remove.
* yasnippet.el (yas--snippet-revive): List snippet identifier in debug
message.
(yas--post-command-handler): Allow the debugger to run.
2017-07-16 15:19:34 -04:00
Noam Postavsky
c98672eb54 Fixup yasnippet-debug.el
* yasnippet-debug.el: Replace cl with cl-lib, replace
yas--snippets-at-point with yas-active-snippets.
2017-07-01 17:40:51 -04:00
Noam Postavsky
65952e3054 Allow customizing overlay priority
* yasnippet.el (yas-overlay-priority): New custom option.
(yas--make-control-overlay, yas--make-move-active-field-overlay): Use
it.
2017-06-24 11:03:07 -04:00
Noam Postavsky
e8ed276e2c Make sure tests don't rely on running order
* yasnippet-tests.el (undo-indentation)
(undo-indentation-multiline): Call `yas-reload-all'.
2017-06-06 23:07:26 -04:00
Noam Postavsky
1a860bd50b Fix undo information recording for multiline snippets
* yasnippet.el (yas--get-indent-undo-pos): Renamed from
yas--return-first-indent-undo.
(yas-expand-snippet): Bind it to line beginning of snippet expansion
position.
* yasnippet-tests.el (undo-indentation, undo-indentation-multiline):
New tests for this and previous fix.
2017-06-05 22:40:02 -04:00
Noam Postavsky
6102ff5049 Handle undo of snippet 1st line indent properly
* yasnippet.el (yas--first-indent-undo)
(yas--return-first-indent-undo): New variables.
(yas-expand-snippet): Use them to collect the exact undo info from
indenting the first snippet line, rather than trying to reconstruct
it.
(yas--indent-region): Put undo info from indenting snippet's first
line into `yas--first-indent-undo' if `yas--return-first-indent-undo'
is non-nil.
2017-06-01 22:07:49 -04:00
Noam Postavsky
1043b6c557 Restore syntax-propertize-function before indenting mirrors
* yasnippet.el (yas--snippet-parse-create): End binding of
syntax-propertize-function once snippet field parsing is finished.
2017-05-18 20:53:40 -04:00
Noam Postavsky
82818e5460 Don't delete snippets more than once.
* yasnippet.el (yas--on-field-overlay-modification): Don't commit
snippet again if the the triggering overlay has already been deleted.
2017-05-16 21:46:49 -04:00
Noam Postavsky
1bf7a4cbae Fix field parsing in modes that use the `syntax-table' property
* yasnippet.el (yas--indent-parse-create): Let-bind
`parse-sexp-lookup-properties' to nil.
2017-05-11 21:24:53 -04:00
Noam Postavsky
0f6d82feae * .travis.yml: Use Emacs 25.2 2017-05-11 08:03:34 -04:00
Noam Postavsky
8797a31337 * doc/snippet-expansion.org: Complete sentence fragment. 2017-04-20 21:00:22 -04:00
Noam Postavsky
462f5667fc Don't leave unreadable objects in the undo list
* yasnippet.el (yas--commit-snippet): Remove overlay object after
deleting it.
(yas--markers-to-points): Drop marker object.
(yas--points-to-markers): Create a new marker object.
2017-04-18 06:51:30 -04:00
Noam Postavsky
c3a94478b4 Fix condition timestamps in key filter functions
* yasnippet.el (yas--maybe-expand-key-filter):
(yas--maybe-expand-from-keymap-filter): Let-bind
`yas--condition-cache-timestamp' to the current time.
2017-04-17 16:03:15 -04:00
Noam Postavsky
47f37f70f4 Fix ${0:soon-to-be-deleted} with no other fields
* yasnippet.el (yas-expand-snippet): Unset `deactivate-mark'.
2017-04-09 23:44:34 -04:00
Noam Postavsky
394942130d Fix problems with auto-fill-mode interaction
* yasnippet-tests.el (auto-fill-with-multiparagraph): New test.
* yasnippet.el (yas--auto-fill): Don't snapshot markers outside of
current paragraph.
(yas--goto-saved-location, yas--snapshot-marker-location): Count
newlines as whitespace (even if mode marks them as non-whitespace
syntax, e.g., comment end).
(yas--snapshot-overlay-location, yas--restore-overlay-location): Don't
snapshot overlay position which is outside of BEG .. END.
2017-04-08 19:07:26 -04:00
Noam Postavsky
1babe81f7e * yasnippet.el (yas-about): Fix compile warnings in previous commit. 2017-04-07 22:28:00 -04:00
Noam Postavsky
ca04f69c10 Make `yas-about' more informative
* yasnippet.el (yas--loaddir): New constant.
(yas-installed-snippets-dir): Use it to compute value.
(yas-about): Get version from git or `package' if available.
2017-04-07 22:09:04 -04:00
Noam Postavsky
5043a96121 Correctly wrap auto-fill-function when it's toggled on later
* yasnippet.el (yas--auto-fill-wrapper): New function, extracted from
`yas-minor-mode'.
(yas-minor-mode): Call it, and it to `auto-fill-mode-hook'.
2017-03-26 13:30:28 -04:00
Noam Postavsky
b4d2f9cb4e Update snippets submodule 2017-03-26 11:00:48 -04:00
Noam Postavsky
22eeb1ef0e Fix interaction with c auto-fill
Save and restore all snippet marker and overlays in the current
paragraph around auto-fill calls.  Extend the marker/overlay snapshot
and restore mechanisms to work in multiline regions.

* yasnippet.el (yas-minor-mode): Install our auto-fill function around
the default one.
(yas--original-auto-fill-function): New variable.
(yas--auto-fill): New function, saves snippet markers & overlays,
calls original auto-fill-function, then restores markers and overlays.
(yas--snapshot-marker-location): Take new optional parameters BEG END,
allow for newlines in whitespace sequences (even if newline doesn't
have whitespace syntax).
(yas--snapshot-overlay-location): New function, takes BEG END,
produced non-line based location snapshots.
(yas--snapshot-overlay-line-location): Renamed from old
`yas--snapshot-overlay-location' function.
(yas--restore-overlay-line-location): Renamed from old
`yas--restore-overlay-location' function, narrow to line before calling
`yas--goto-saved-location'.
(yas--goto-saved-location): Use whole narrowed buffer instead of
assuming current line.
(yas--restore-overlay-location): New function, assume whole narrowed
buffer may be used.
(yas--prepare-snippets-for-move, yas--finish-moving-snippets):
(yas--indent-region): Adjust callers.
2017-03-26 10:15:31 -04:00
Noam Postavsky
30913fdfb7 Only update live snippets
* yasnippet.el (yas--snippet-live-p): New function.
(yas--on-field-overlay-modification): Use it to avoid updating a dead
snippet, give a warning instead.
2017-03-23 00:06:18 -04:00
Noam Postavsky
c5fddf8cec Restore syntax-propertize-function before indenting snippet
* yasnippet.el (yas--snippet-parse-create): Some modes require correct
syntax-propertizing to indent properly.
2017-03-22 21:29:01 -04:00
Noam Postavsky
63f44b4e48 Ensure inhibit-modification-hooks is nil while modifying buffer
* yasnippet.el (yas--on-field-overlay-modification): Bind
inhibit-modification-hooks to nil so that other packages' hooks can
run, yas--inhibit-overlay-hooks so that we won't run recursively.
2017-03-11 22:25:50 -05:00
Noam Postavsky
7f337f4488 Fix nested snippet expansion
* yasnippet.el (yas--place-overlays): Don't move active field overlays
unless we're working on the innermost snippet.
(yas--move-to-field): Keep `yas--active-field-overlay's `yas--snippet'
property in sync with its `yas--field' property.
* yasnippet-tests.el (nested-snippet-expansion-1): Rename from
nested-snippet-expansion-1.
(nested-snippet-expansion-2, nested-snippet-expansion-3): New tests.
2017-03-10 20:24:38 -05:00
Etienne
0d9afb2c69 Fix mirror transformation error with expand-env
* yasnippet.el (yas-expand-snippet): Use the snippet's bindings when
moving to the first field.  This prevents getting an error when using
a variable defined in expand-env.
* yasnippet-tests.el (snippet-mirror-bindings): New test, check if
mirror transformations have access to variables defined in the snippet
environment.
2017-03-09 13:50:06 -05:00
Etienne
6e9b7f9432 Fix running hook variable set as buffer-local
* yasnippet.el (yas--eval-for-effect): Use `yas--safely-call-fun'
instead of `yas--safely-run-hook'.
(yas--safely-call-fun): Display the called argument (even a lambda) on
errors.
(yas--safely-run-hook): Take a hook variable instead of the hook value
itself.  Use `run-hooks' to take buffer-local values into account.
This means it’s no longer possible to warn which hook function had an
error.
(yas--check-commit-snippet): Refactor to conform to
`yas--safely-run-hooks'.
* yasnippet-tests.el (snippet-exit-hooks-bindings): New test that
checks for buffer-local, global and env hooks support.
2017-02-26 19:38:32 -05:00
Noam Postavsky
cddb8260a0 Merge: let snippets expand in strings/comments by default
Also make yas-buffer-local-condition into a defcustom.
2017-02-16 22:28:31 -05:00
Noam Postavsky
14819c931f Make yas-buffer-local-condition into a defcustom
* yasnippet.el (yas-not-string-or-comment-condition): New constant,
holding the previous default value of `yas-buffer-local-condition'.
(yas-buffer-local-condition): Make into defcustom.
2017-02-16 22:27:15 -05:00
Noam Postavsky
4f37afd493 Let snippets expand in strings/comments by default
* yasnippet.el (yas-buffer-local-condition): Change default to t.
* doc/snippet-expansion.org: Update documentation.
2017-02-16 22:27:15 -05:00
Noam Postavsky
c87afe0901 Merge: snippet-local exit hook; error handling improvements 2017-02-12 11:32:27 -05:00
Noam Postavsky
f3d0e03a05 * yasnippet-tests.el (snippet-exit-hooks): New test. 2017-02-05 15:23:18 -05:00
Noam Postavsky
6c4fbb25b3 Fix snippet local exit hook
* yasnippet.el (yas--check-commit-snippet): Use
`yas-after-exit-snippet-hook' value of last exited snippet.
* yasnippet.el (yas--safely-run-hook): Also accept a list of functions.
* yasnippet.el (yas--safely-call-fun): New function, extracted from yas--safely-run-hook.
2017-02-05 15:23:18 -05:00
Noam Postavsky
b62cf52f35 Remove lambda list building hack
* yasnippet.el (yas-load-directory, yas--eval-for-effect): Use
`apply-partially' instead of building lambda lists.
2017-02-05 15:22:24 -05:00
Noam Postavsky
203df22e26 Use debug-on-error to simplify error handling
* yasnippet.el (yas--eval-for-string, yas--safely-run-hook: Let-bind
`debug-on-error' according to `yas-good-grace' and add `debug' to
condition handler to deduplicate evaluation.
2017-02-05 15:22:24 -05:00
Noam Postavsky
9c9547a628 Don't catch and rethrow yas-{-}exception
* yasnippet.el (yas--eval-for-string): Don't catch yas--exception.
(yas-throw): Signal `yas-exception', not `yas--exception'; DATA must be
a list.
(yas-exception): Add `error-message' property.
(yas-verify-value): Just use plain format since the new `error-message'
property for `yas-exception' will add the right prefix.
2017-02-05 15:22:24 -05:00
João Távora
ac26024837 Rework error handling
* yasnippet.el (yas-good-grace): Add support for `inline' and `hooks' options.
(yas--eval-for-string): Renamed from `yas--eval-lisp'.  Errors are
passed straight through (no rethrow) when `yas-good-grace' is nil.
(yas--handle-error): Removed.
(yas--eval-for-effect): Renamed from `yas--eval-lisp-no-saves'.  Use
`yas--safely-run-hook'.
(yas-define-snippets): Update docstring.
(yas-throw): Don't throw, just signal.
(yas--save-backquotes, yas--apply-transform): Use
`yas--eval-for-string'.
(yas--safely-run-hook): Renamed from `yas--safely-run-hooks'.  Takes 1
hook function, instead of a hook var; check `yas-good-grace'.
(yas-expand-snippet): Use `yas--eval-for-effect'.
2017-02-05 15:22:24 -05:00
Noam Postavsky
9abf842e35 Enable snippet-mode automatically
* yasnippet.el (yas-snippet-mode-buffer-p): New function, detects
buffers visiting files under `yas-snippet-dirs'.  Add it
`magic-fallback-mode-alist' to enable `snippet-mode' automatically,.
2017-02-03 09:26:11 -05:00
Noam Postavsky
e74f00e703 Fix whitespace lossage between mirrors
* yasnippet.el (yas--update-mirrors): Delay indentation until all
mirrors are updated.
(yas--mirror-update-display): Don't indent here.
* yasnippet-tests.el (single-line-multi-mirror-indentation-2): New test.
2017-01-28 00:28:57 -05:00
Noam Postavsky
0041efedf9 Make snippets work in org source blocks
org-mode implements the "native" tab for source blocks by copying the
source block text into a temporary buffer, calling the command bound to
<tab>, and then copying back the result.  To preserve snippets in this
scenario, when the temp buffer is killed we record the relative
locations of the snippet's markers and overlays and then put them into
place in the post command handler.

* yasnippet-tests.el (yas-org-native-tab-in-source-block): New test.
* yasnippet.el (yas--snippets-to-move): New variable.
(yas--prepare-snippets-for-move, yas--finish-moving-snippets): New
function.
(yas--on-buffer-kill): New function, add to `kill-buffer-hook'.
(yas--maybe-move-to-active-field): New function.
(yas--snippet-revive): Use it.
(yas--snapshot-marker-location): Change format of location info.
(yas--goto-saved-location): New function.
(yas--restore-marker-location): Use it.
(yas--snapshot-overlay-location): New function.
(yas--restore-overlay-location): Use it.
(yas--post-command-handler): Call `yas--finish-moving-snippets'.
2017-01-08 21:30:01 -05:00
Noam Postavsky
d0c6fecab5 Refactor snippet marker manipulating functions
* yasnippet.el (yas--snippet-map-markers): New function.
(yas--markers-to-points, yas--points-to-markers
(yas--collect-snippet-markers): Use it.
2017-01-08 21:30:01 -05:00
Noam Postavsky
0311fe2619 Use :filter instead of yas--fallback
Instead of making yas-expand and yas-expand-from-keymap search for the
command that would have been called, use a conditional keybinding so the
Emacs' builtin keybinding lookup code will do the searching instead.

* doc/faq.org: Remove section about old method binding method.  Update
example to use new method.
* doc/snippet-expansion.org (Trigger key): Update explanation for new
method.
* yasnippet.el (yas-fallback-behavior): Mark obsolete.
(yas--maybe-expand-key-filter): New function.
(yas-maybe-expand): New conditional binding.
(yas-minor-mode-map): Bind it to TAB and <tab>.
(yas--maybe-expand-from-keymap-filter): New function, extracted from
`yas-expand-from-keymap'.
(yas-maybe-expand-from-keymap): New conditional binding.
* yasnippet-tests.el (yas--key-binding): New function, like
`key-binding' but overrides `this-command-keys-vector'.
(snippet-load-uuid): Use it.
(test-yas-tab-binding, test-yas-in-org): Insert snippet key before
testing binding.
2017-01-08 21:30:00 -05:00
Noam Postavsky
48cd7163b2 Use more compact format for snippet menus
* yasnippet-tests.el (yas-with-even-more-interesting-snippet-dirs): Add
debug declaration.
(yas--collect-menu-items): New function.
(test-yas-define-menu): Use it to become keymap format agnostic.
* yasnippet.el (yas--delete-from-keymap): This function deletes entries
created by `yas--update-template-menu', which are always list elements.
Skip other types of keymap elements.
(yas--define-menu-1): Create a keymap with a vector element instead of a
list with gensym symbol binding list.
2016-12-21 22:53:53 -05:00
Barak A. Pearlmutter
7b3c29d210 * doc/faq.org: Typos and grammar.
Copyright-paperwork-exempt: yes
2016-12-21 22:48:21 -05:00
Noam Postavsky
e878afb883 Update handling of markers during indentation
* yasnippet.el (yas--snapshot-marker-location): New function, save a
regexp and whitespace count determining a marker's location in a line.
(yas--restore-marker-location): New function, restores a marker's
location based on info from `yas--snapshot-marker-location'.
(yas--indent-region): Use them to fix marker locations after indentation.
* yasnippet-tests.el (indent-org-property, indent-cc-mode):
(indent-snippet-mode): New tests.
2016-12-11 22:18:08 -05:00
Noam Postavsky
28d5496144 Use git describe for doc HTML output
* Rakefile (:doc:upload):
* doc/yas-doc-helper.el: Use 'git describe' output instead of 'git
rev-parse', since it's more readable.
2016-12-11 19:50:08 -05:00
Noam Postavsky
4ef1768e81 Add timestamp of source revision to HTML doc
* doc/yas-doc-helper.el: Put revision's commit date into :html-postamble
project property.  Use SOURCE_DATE_EPOCH instead of git data, if it's
defined.
2016-12-10 22:27:57 -05:00
Sean Whitton
cce2e0df5d Make the documentation build reproducible
* doc/org-setup.inc: Disable timestamp in HTML output.

Copyright-paperwork-exempt: yes
2016-12-10 13:16:20 -05:00
Noam Postavsky
4ee3835adf Use expand-env for all snippet evaluations
* yasnippet.el (yas--snippet): New field, expand-env.
(yas--letenv): New macro, evaluate body with a given environment.
(yas--find-next-field, yas--safely-run-hooks):
(yas--on-field-overlay-modification):
(yas-expand-snippet, yas--snippet-create): Use it.
2016-12-02 20:00:42 -05:00
Noam Postavsky
5534cab0b7 Respect yas-indent-line for mirror updates
* yasnippet.el (yas--mirror-update-display): Check yas-indent-line
before indenting.
2016-12-02 19:43:54 -05:00
Noam Postavsky
7b013dbbdb Keep yas--snippets-at-point for compatibility
While officially it was an "internal" function, there were at least 2
other packages using it.

* yasnippet.el (yas--snippets-at-point): Restore as obsolete alias of
yas-active-snippets.

Close #754.
2016-12-01 18:20:09 -05:00
Noam Postavsky
2ca6321b47 Promote yas--snippets-at-point to a public API
* yasnippet.el (yas-active-snippets): Rename from
yas--snippets-at-point, adjust callers.  Handle arbitrary positions and
ranges as a parameter.
* yasnippet-tests.el (nested-snippet-expansion): New test.
2016-11-30 20:54:55 -05:00
Noam Postavsky
c485d13995 Remove last use of flet
It is obsolete as of 24.3, and this particular use of flet in this place
isn't much use anyway.

* doc/yas-doc-helper.el (yas--document-symbol): Stop using flet.

Fixes #752
2016-11-28 22:22:23 -05:00
João Távora
8412d71e44 Reword #744 yet again
* yasnippet.el (yas-reload-all): Simplify message form.
2016-11-10 20:26:47 +00:00
João Távora
80a1098493 Rework yas-reload-all message introduced by #744
* yasnippet.el (yas-reload-all): Reword final message regarding
snippet loading.
2016-11-10 14:30:54 +00:00
Bost
4fa52e6ac2 Improve final message produced by yas-reload-all
* yasnippet.el (yas-reload-all): Clarify message.

Copyright-paperwork-exempt: yes
2016-11-09 21:47:44 -05:00
Noam Postavsky
e6b8651277 * NEWS: Update for 0.11.0.
* snippets/: Update snippets submodule.

* yasnippet.el: Bump version number.
2016-10-26 19:01:49 -04:00
Александар Симић
eaaec309b1 Replace all occurances of `capitaomorte'
* CONTRIBUTING.md:
* NEWS:
* README.mdown:
* doc/index.org:
* doc/nav-menu.html.inc:
* yasnippet.el: Since the new repo destination is now under
`joaotavora', fix all the stale links to point to the new destination.

Copyright-paperwork-exempt: yes
2016-10-22 09:46:15 -04:00
Noam Postavsky
ff6f31ee2c Replace yas--with-temp-redefs with cl-letf
* yasnippet-tests.el (yas--call-with-temporary-redefinitions):
yas--with-temporary-redefinitions): Remove.
* yasnippet-tests.el (yas-with-overriden-buffer-list):
(basic-jit-loading-with-compiled-snippets):
(visiting-compiled-snippets): Use cl-letf.
2016-10-07 20:04:52 -04:00
Noam Postavsky
00be21c717 Change cl dep to cl-lib for tests too
* yasnippet-tests.el (yas--call-with-temporary-redefinitions):
(yas-with-overriden-buffer-list):
(snippet-save, test-yas-define-menu, test-group-menus):
(test-group-menus-twisted, yas-call-with-saving-variables): Replace cl
function with cl-lib named equivalents.
2016-10-07 19:54:23 -04:00
Noam Postavsky
85a43ad8e5 Explain about backquote expressions in doc
* doc/snippet-development.org (Embedded Emacs-lisp code): Add a subsection
explaining that backquote expressions should not modify the buffer.
2016-10-07 19:28:23 -04:00
Noam Postavsky
a5e88b2fd4 Add test for snippet saving
* yasnippet-tests.el (snippet-save): New test.
2016-09-27 19:55:56 -04:00
Noam Postavsky
1532e66d76 Fix saving of new snippets
`buffer-file-name' is a permanent buffer-local variable, so if we reuse
the "*new snippet*" buffer, we could end up visiting the last new
snippet's file.

* yasnippet.el (yas-load-snippet-buffer-and-close): Rename the "*new
snippet*" buffer when making it visit a file.
2016-09-24 23:01:38 -04:00
Noam Postavsky
9cf92085e5 Fix test-rebindings
* yasnippet-tests.el (test-rebindings): Make the rebindings properly
temporary instead of just setting them back to what the presumed default
is.
2016-09-22 21:43:56 -04:00
Noam Postavsky
309fe157f6 * Rakefile: Handle unset `warnings' parameter 2016-08-01 18:25:15 -04:00
Noam Postavsky
4b12f7de7a Don't warn about cl-functions with old cl-lib
* .travis.yml (install): Set warnings to (not cl-functions) if cl-lib
needs to be downloaded.  Since the downloaded cl-lib just aliases cl.el
functions, trying to use cl- prefixed functions would cause compile
warnings otherwise.
* Rakefile: Pass environment variable `warnings' as
`byte-compile-warnings' value when compiling.
2016-08-01 17:33:54 -04:00
Stefan Monnier
5264379908 Cleanup redundant cl dependency, :group & :require
* yasnippet.el: Replace calls to cl functions with cl- prefixed cl-lib
equivalents.  Use #' to quote function symbols.
(yas-snippet-dirs, yas-new-snippet-default, yas-prompt-functions):
(yas-indent-line, yas-also-auto-indent-first-line):
(yas-snippet-revival, yas-triggers-in-field):
(yas-fallback-behavior, yas-choose-keys-first, yas-choose-tables-first):
(yas-use-menu, yas-trigger-symbol, yas-wrap-around-region):
(yas-good-grace, yas-visit-from-menu, yas-expand-only-for-last-commands):
(yas-field-highlight-face, yas--field-debug-face): Remove redundant
:group.
(yas-snippet-dirs, yas-global-mode): Remove :require.  The :set value
for yas-snippet-dirs checks if yas-reload-all is fbound, and the
autoload cookie on yas-global-mode makes :require redundant.
2016-08-01 14:42:58 -04:00
Sudarshan Gaikaiwari
7e0a0de499 Use new name of python-in-string/comment in docs
* doc/snippet-expansion.org:
* yasnippet.el (yas-buffer-local-condition): python.el renames
python-in-string/comment to python-syntax-comment-or-string-p.  Modify
the documentation to reflect that.

Copyright-paperwork-exempt: yes

Close #725
2016-07-23 08:10:48 -04:00
Noam Postavsky
5af9276f21 Support yas/ symbols in yas-define-menu
These symbols were overlooked in backporting because they're not bound
or fbound.

* yasnippet.el (yas--define-menu-1): Rewrite with `cl-loop', and support
yas/ prefixed symbols.
2016-07-19 20:23:12 -04:00
Noam Postavsky
244cdfa53b Merge: Simplify `yas-new-snippet' load&save logic 2016-07-18 21:46:35 -04:00
Noam Postavsky
dc098cf23e Fix yas--message verbosity levels
The yas--message function was comparing with `>' instead of `>=', which
meant it was quieter than intended (i.e., level 3 message were being
suppressed by defualt).  Also push the "Snippet %d exited" message up to
level 4, so the net effect should actually be quieter than before for
normal usage (the only level 3 messages are now for loading and saving
snippets).

* yasnippet.el (yas--message): Fix off-by-1 error.
(yas--load-snippet-dirs): Lowest yas--message level should be 1, not 0.
(yas--commit-snippet): "Snippet %d exited" is more of a debug message,
put it at level 4.
2016-07-18 21:44:33 -04:00
Noam Postavsky
3129040fe3 Load snippet after saving
* yasnippet.el (yas-maybe-load-snippet-buffer): New function.
(snippet-mode): Add it to `after-save-hook'.
2016-07-18 21:44:33 -04:00
João Távora
0ee86a2d1e Simplify `yas-new-snippet' load&save logic
Two significant changes:

1. The criteria for offering to save in upon
   `yas-load-snippet-buffer-and-close' is much simplified, and relies
   on `buffer-modified-p' solely.

2. C-x C-s snippet after `yas-new-snippet' or `yas-visit-snippet'
   suggests at least a sensible directory.

Still missing in this commit is the suggestion for loading upon
saving. The `after-save-hook' could be used for something like that.

* yasnippet.el (yas-new-snippet): Set `default-directory' based on
result of `yas--guess-snippet-directories'.
(yas-load-snippet-buffer): Return template object.
(yas-load-snippet-buffer-and-close): Simplify.
(yas--visit-snippet-file-1): Also set `default-directory' here.
(yas--guess-snippet-directories-1): Return directory names, i.e., ending
in slash.
2016-07-18 21:26:01 -04:00
Paul Eggert
ea9581fb19 Fix some quoting problems in doc strings
Most of these are minor issues involving, e.g., quoting `like this'
instead of 'like this'.  A few involve escaping ` and ' with a
preceding \= when the characters should not be turned into curved single
quotes.
2016-07-18 21:25:11 -04:00
Noam Postavsky
9500b000fd Fix field navigation in the backwards direction
* yasnippet.el (yas--find-next-field): For negative N, actually give the
Nth previous field, not the 1st field.
* yasnippet-tests.el (field-navigation): Add a 3rd field, and test
calling `yas-prev-field' while on it.

Fixes #722.
2016-07-13 17:03:30 -04:00
Noam Postavsky
0db65ee0bb Don't clobber match data in modification hooks
Since modification hooks run just after any function that changes buffer
contents, it's important to save the match data, or else the code doing
the modification can become really confused.  See also Emacs bugs #23917
and #23869.

* yasnippet.el (yas--on-field-overlay-modification): Wrap main body in
`save-match-data'.
2016-07-12 20:13:59 -04:00
Noam Postavsky
7661dc161d yasnippet.el (yas-escape-text): No error on nil text 2016-07-05 23:39:07 -04:00
Noam Postavsky
42b0c269ca Don't warn about modifications to other buffers
* yasnippet.el (yas--save-backquotes): Detect changes only in buffer
where snippet is being expanded.
2016-07-05 23:38:09 -04:00
Akinori MUSHA
d4da806e5c Fix removal of snippets by uuid
* yasnippet.el (yas--remove-template-by-uuid): Test uuid equality with
`equal' instead of `eq'.

Copyright-paperwork-exempt: yes

Close #714
2016-07-05 23:18:35 -04:00
Noam Postavsky
a4fafc3225 Add test for loading snippet with same uuid
* yasnippet-tests.el (snippet-load-uuid): New test.
2016-07-05 23:15:45 -04:00
Noam Postavsky
4296a86139 yasnippet.el (yas--quote-string): Remove. 2016-06-29 22:22:00 -04:00
rubikitch
8907fd1d42 Escape yas-selected-text for new snippet.
* yasnippet.el (yas-escape-text): New function.
(yas-new-snippet-default): Call it on yas-selected-text.

Close #709.
2016-06-29 22:22:00 -04:00
Noam Postavsky
8ca8c7de4f Merge: a different fix for #712.
"Don't indent first line of mirrors" had the drawback that sometimes
we *want* to indent the first line of mirrors.  So we fix the underlying
problem in a different way and add a test to make sure we don't lose
this behaviour again.
2016-06-24 16:26:14 -04:00
Noam Postavsky
9c9952c19a Add test for indentation of single line mirrors
* yasnippet-tests.el (indent-mirrors-on-update): New test.
2016-06-24 16:19:22 -04:00
João Távora
d218ed8b1b Do indent the first line of mirrors, but in correct order
This changes the strategy for fixing #712 to a simpler alternative,
which doesn't remove the benefits of indenting single line mirrors.

It reverts the functional parts of commit
351c1e3dcbb73e3154aae0755d5b7016f1561ebc, while keeping the tests.

* yasnippet.el (yas--update-mirrors): Sort mirrors to be updated by
  start position.
2016-06-24 13:17:34 +01:00
Noam Postavsky
351c1e3dcb Don't indent first line of mirrors
* yasnippet.el (yas--mirror-update-display): Don't indent the first line
of mirror output (meaning no indentation happens if there is a single
line).
* yasnippet-tests.el (single-line-multi-mirror-indentation): New test.
(snippet-with-multiline-mirrors-issue-665): Renamed from
navigate-a-snippet-with-multiline-mirrors-issue-665, test for precise
indentation in addition to navigation (this was already implemented,
contrary to its obsolete docstring).

Fixes #712
2016-06-23 20:09:49 -04:00
Stefan Monnier
ee6e7a9602 Fix some compilation warnings
* yasnippet-tests.el (complicated-yas-key-syntaxes): Avoid looking-back.

* yasnippet.el (yas--font-lock-keywords): Escape $, even if first in the
regexp.
(yas--indent): Remove unused var `end'.
(yas--indent-parse-create): Remove unused arg `snippet'.  Update caller.
2016-06-22 22:50:51 -04:00
Noam Postavsky
6b785e185f Say how to hide the backquote side-effect warning
* yasnippet.el (yas--save-backquotes): Explain how to hide warning in
the warning message.
2016-06-22 19:58:56 -04:00
Noam Postavsky
655bda804b Merge: restore backquote evaluation behaviour
But add warnings if snippets use insertion from backquote expressions.
2016-06-21 22:15:08 -04:00
Noam Postavsky
85f39cec2b Warn about backquote exprs modifying the buffer
* yasnippet.el (yas--save-backquotes): Show a warning if evaluating the
backquote expression modifies the buffer.
2016-06-21 22:10:22 -04:00
Noam Postavsky
ee4efdbbde Revert "Separate parsing from evaluation of backquote lisp"
This reverts commit e21420a497c1d79edc6b36ffb1f3bf1bb70f6227.  This
breaks existing snippets which use side-effecting functions inside
backquotes to insert data instead of return the string to insert.  This
usage will be deprecated, but we still need to support it for at least
another release.

* yasnippet.el (yas--save-backquotes): Go back to interleaved parsing
and evaluating of backquoted lisp forms.
2016-06-21 22:09:28 -04:00
Noam Postavsky
e21420a497 Separate parsing from evaluation of backquote lisp
* yasnippet.el (yas--save-backquotes): Parse all backquoted lisp forms
and only then evaluate them.
2016-06-12 09:20:08 -04:00
Noam Postavsky
c7441486db Make yas-describe-tables easier to use from lisp
* yasnippet.el (yas-describe-table-by-namehash): new function.
(yas-describe-tables): remove query for by-namehash variant, replace
query for non-active tables with prefix arg.
2016-06-11 21:02:01 -04:00
songjie dong
1735a283d2 Add region contents to new snippet
* yasnippet.el (yas-new-snippet-default): Add yas-selected-text.
(yas-new-snippet): Let-bind yas-selected-text to region content.

Copyright-paperwork-exempt: yes
2016-06-11 19:40:54 -04:00
Noam Postavsky
bc80f67782 .travis.yml: Don't notify on success 2016-06-11 19:36:21 -04:00
Noam Postavsky
dc3e4ca345 Release 0.10.0
- Update NEWS
- Bump version number
- update snippets submodule
2016-06-11 14:45:42 -04:00
Noam Postavsky
e23a053b00 Avoid bug in insert-file-contents with REPLACE=t
* yasnippet.el (yas--load-directory-2): Call `erase-buffer' before
`insert-file-contents' instead of passing non-nil REPLACE, avoids Emacs
bug #23659.

Fixes #707.
2016-05-30 20:21:19 -04:00
João Távora
47dbe93d86 Fix broken links in README.mdown
After the Github acocunt name change (capitaomorte -> joaotavora), 
most links to repositories are redirected excpect Travis CI and 
Github Pages (documentation).

* README.mdown: Fix documentation and Travis badge links
2016-05-24 08:24:18 +01:00
Noam Postavsky
497867cea5 Rename yas-backport-obsolete-alias
* yasnippet.el (yas-alias-to-yas/prefix-p): Rename from
yas-backport-obsolete-alias.
(yas/root-directory): Only define if yas-alias-to-yas/prefix-p is
non-nil.  Mark obsolete.
2016-05-17 19:28:14 -04:00
USAMI Kenta
bbfa1f0c9a Add yas-backport-obsolete-alias option
* yasnippet.el (yas-backport-obsolete-alias): New option.
2016-05-17 08:03:25 -04:00
Noam Postavsky
0d79e6988e Extra measures to prevent premature yas-minor-mode
The user's hooks may try to enable yas-minor-mode before yasnippet.el
has finished loading.  In [1], we catch and ignore the errors arising
from this, but it's better if we can avoid hitting the error in the
first place.

This means we have 3 separate measures to avoid the problem, but since
this bug can leave Emacs unusable due to a failing post-command-hook,
a bit of redundant safety is not a bad thing.

* yasnippet.el (yas-minor-mode): Only turn on if yasnippet is fully
loaded.
(yas--font-lock-keywords): Disable user hooks.

[1]: "Avoid potential problems with user's hooks"
4c6064ce1aff07fe4481b5e2d987c8a7f044c207
2016-05-14 07:18:38 -04:00
Noam Postavsky
1b8f5b7a72 Don't use major-mode syntax-propertize-function
during snippet creation.  The snippet creation manipulates the
syntax-table which can lead to conflicts (see also
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23443).

* yasnippet.el (yas-expand-snippet): Let-bind syntax-propertize-function
to nil and then call syntax-ppss-flush-cache afterwards.
2016-05-12 05:41:08 -04:00
Noam Postavsky
6180cc4059 Fix field transform application in yas-next-field
* yasnippet.el (yas--apply-transform): Don't let-bind yas-moving-away-p
to nil, it's nil by default.
(yas-next-field): Call `yas--field-update-display' instead of only
calling `yas--eval-lisp' so that the result of the transform is inserted
into the buffer.
2016-05-12 04:57:08 -04:00
Noam Postavsky
6f97316551 Fix outdated and misformatted docs
yas-find-snippets was removed by [1].

* doc/snippet-development.org: Add keybindings on same line as command
names, fixup intra document links, and remove mention of non-existent
command yas-find-snippets.
* yasnippet.el (yas-load-snippet-buffer):
(yas-load-snippet-buffer-and-close): Fix docstring formatting.

[1]: "cleanup: remove `yas/find-snippets\', complicated and no one seems
to use it anyway" 29 May, 2012 433c93746534ebb062afe4dbc7690f736be72d42.
2016-05-10 12:24:25 -04:00
Noam Postavsky
e9406f5126 Document $> and fix escaping
* doc/snippet-development.org: New "Indentation markers" section.
* yasnippet-tests.el (indentation-markers): New test.
* yasnippet.el (yas--indent-markers): New variable.
(yas--indent): Use it instead of searching for $> directly.
(yas--indent-parse-create): New function, records occurences of $> into
`yas--indent-markers'.
(yas--snippet-parse-create): Call it.
2016-05-08 15:32:20 -04:00
Noam Postavsky
146b161112 Don't indent empty lines in snippet expansion
* yasnippet.el (yas--indent-region): Indent only non-empty lines.
* yasnippet-tests.el (basic-indentation): Add empy and non-empty (but
blank) lines in test snippet.
2016-05-04 12:35:48 -04:00
Noam Postavsky
bdfab67eac Make yasnippet less chatty
Make sure output that occurs in normal use goes to verbosity levels 3 or
higher, and level 2 and below are reserved for something unexpected
happening.  Level 3 (the new default) should be a reasonably quiet but
informative level.

* yasnippet.el (yas--read-keybinding, yas--safely-run-hooks):
(yas--on-protection-overlay-modification): Put warnings at verbosity
level 2.
(yas--load-yas-setup-file, yas-load-directory):
(yas--load-directory-1, yas--load-snippet-dirs):
(yas-expand-snippet, yas--load-pending-jits): Put per-file loading and
other debug messages at level 4.
(yas-load-snippet-buffer, yas--template-get-file, yas-reload-all): Put
top level loading messages at level 3 (or 2 if there were errors).
(yas--define-menu-1, yas-insert-snippet, yas-tryout-snippet): Put error
messages at level 1.
(yas-verbosity): Reduce default verbosity to level 3.
2016-05-01 21:41:42 -04:00
Noam Postavsky
df229b9ab8 Fix some doc formatting
* doc/snippet-development.org (Template Syntax):
(Placeholder fields, Mirrors): Text inside dedicated target <<angle
brackets>> does not show up in output, so duplicate it.  Add
descriptions to avoid getting numbers instead of names in links.
2016-04-30 22:36:34 -04:00
Noam Postavsky
78fe979b7b Support htmlize.el in Rakefile doc target
Htmlized output can now be produced by

    rake doc[/path/to/htmlize/]

* Rakefile (doc): Add htmlize argument.
* doc/yas-doc-helper.el (yas--generate-html-batch): Tell org to use css
selectors only when exporting htmlized faces.
* doc/stylesheets/manual.css: Add styles for faces used by org export.
2016-04-30 22:36:34 -04:00
Noam Postavsky
beb2ba4d7f Fix fields following $0 + region insertion
When inserting text due to a  non-nil yas-wrap-around-region and the
snippet had fields occuring later in the buffer than $0, the insertion
of the text was shifting the location of later fields, thus invalidating
the calculation of yas--dollar-regions.

* yasnippet.el (yas--simple-mirror-parse-create): Don't insert text fo
yas-wrap-around-region here.
(yas--snippet-parse-create): Do it here, after deleting
`yas--dollar-regions`, instead.
2016-04-30 20:19:12 -04:00
Noam Postavsky
db4cd31a11 Delete active region for trigger key expansion
This makes yas-expand-from-trigger-key consistent with
yas-insert-snippet.

* yasnippet.el (yas-expand-from-trigger-key): Expand start end interval
with active region.
2016-04-30 20:19:12 -04:00
Noam Postavsky
5d44a9f15e Revert "Disable region wrapping for trigger key expansion"
This reverts commit f8d1af1f50f42ac1689c583c152c3b15e8774ae4.

Disabling this for trigger key introduced an inconsistency that is more
complicated to implement and document than simply fixing region wrapping
for trigger key expanded snippets.
2016-04-30 20:17:38 -04:00
Noam Postavsky
e37ce9e488 Disable region wrapping for trigger key expansion
It's too awkward to highlight the relevant text while maneuvering point
in front of the trigger key.

* yasnippet.el (yas-expand-from-trigger-key): Let-bind
yas-wrap-around-region to nil if it was t.
* doc/snippet-expansion.org: Document it.
2016-04-30 20:10:01 -04:00
Noam Postavsky
c1b2cb7c5e Improve documentation for new register option
* doc/snippet-expansion.org: Add new section about
yas-wrap-around-region.
* yasnippet.el (yas-wrap-around-region): Improve docstring.
2016-04-30 20:10:01 -04:00
Noam Postavsky
ccc9adc3c4 Add register option for yas-wrap-around-region
Replace `cua' setting with more general behaviour that can use any given
register.  A `cua' setting is converted to ?0 for backwards
compatibility.

* yasnippet.el (yas--simple-mirror-parse-create): Use contents of any
  register depending on `yas-wrap-around-region' value.
(yas-wrap-around-region): Update docstring.
2016-04-30 20:10:01 -04:00
João Távora
eca2f995c1 Indent multi-line output from mirrors
* yasnippet.el (yas--indent-region): Adapted and redesigned from
`yas--indent-according-to-mode'
(yas--indent-according-to-mode): Deleted.
(yas--indent): Use `yas--indent-region'.
(yas--real-line-beginning): Deleted.
(yas--update-mirrors): Always re-place active field overlay if it
exists.  Pass the snippet to `yas--mirror-update-display'.
(yas--mirror-update-display): Indent the mirror text after
inserting the reflection.
2016-04-30 19:00:53 -04:00
João Távora
eeb4b62efb Add new tests for multi-line mirror indentation
* yasnippet-tests.el (basic-indentation):
(navigate-a-snippet-with-multiline-mirrors-issue-665): New tests.
2016-04-30 18:32:30 -04:00
Noam Postavsky
14f830a37d Test expansion in an empty buffer
* yasnippet-tests.el (yas-should-expand, yas-should-not-expand): Call
`erase-buffer' instead of narrowing.
2016-04-30 18:32:30 -04:00
Noam Postavsky
a87ec549a6 yasnippet.el (yas-next-field-will-exit-p): New function. 2016-04-28 21:27:00 -04:00
Noam Postavsky
cc14db399c Refactor yas-next-field a bit
* yasnippet.el (yas--find-next-field): New function to find target field.
  (yas-next-field): Use it.
2016-04-28 21:26:59 -04:00
Noam Postavsky
bfe14f19ac Test and fix problem with mirror+autofill
cc-mode fill paragraph narrows to the paragraph being filled.  This
causes problems if there is a mirror needing to be updated outside of
the current paragraph.

* yasnippet-tests.el: New test.
* yasnippet.el (yas--update-mirrors): Widen while updating the mirrors.
2016-04-28 21:16:30 -04:00
Noam Postavsky
7799aa908b Document .yas-setup.el
* doc/snippet-organization.org: Explain .yas-setup.el.
2016-04-27 17:08:19 -04:00
Barak A. Pearlmutter
c0032e6e61 chmod -x doc/yas-doc-helper.el 2016-04-27 16:51:03 -04:00
Noam Postavsky
7f03a2319e Change Emacs installation method for Travis CI
* .travis.yml: Don't use sudo, submodules.
(env): Test with additional Emacs versions.
(install): Get Emacs binaries from
https://github.com/npostavs/emacs-travis/releases.  Download ert and
cl-lib if needed.
(script): Split compilation and testing into separate steps.
* Rakefile: Use batch-byte-compile.  Treat compilation warnings as
errors.
2016-04-24 17:29:05 -04:00
Noam Postavsky
567ada01e6 Decide field clearing based on command's effect
In [1] we started deciding clearing based on a command's
delete-selection property, but it turns out that some commands perform
insertion, and optionally use the region's contents.  So these commands
should have a nil delete-selection property, but they still ought to
clear a snippet field when used.

To achieve this, we now check if the command has inserted text in the
post-change hook of the field overlay.

* yasnippet.el (yas--skip-and-clear): Add optional FROM paramter.  Only
clear non-empty fields.
(yas--skip-and-clear-field-p): Check the change start and length
instead of current command delete-selection property.
(yas--on-field-overlay-modification): Perform field clearing on the
post-change call.

[1]: acf2cdd "Decide field clearing commands based on delsel"
2016-04-23 16:36:10 -04:00
Noam Postavsky
4f2aa1526a Only kill snippets for text length change
of protection overlay.  Changes that keep the same length of text are
probably harmless (e.g. just change of text properties).  It's possible
that some harmful changes don't change text length, but the protection
overlays are already unable to catch all important changes since they
only cover 1 character each at the edges.

cc-mode modifies text properties in the buffer to cache parsing results,
therefore it's important that yasnippet not kill yasnippets when parsing
is triggered by a function that only wants to parse the
buffer (e.g. which-function-mode).

* yasnippet.el (yas--on-protection-overlay-modification): Check length
of text change to decide if change is harmful.  Fix docstring.
2016-04-16 11:31:44 -04:00
Stefan Monnier
bd30a30d88 yas-dont-activate is a hook
* yasnippet.el (yas-dont-activate-functions): Rename from yas-dont-activate.
(yas-minor-mode-on): Use run-hook-with-args-until-success instead of
funcall.
2016-04-11 19:05:37 -04:00
BEN ENGLISCH
87710827e9 Don't add useless kill ring entries
while describing snippet tables.  This should also help users of
packages like pbcopy.el (which creates a new process on every
modification of the kill-ring, hence many `kill-region' calls at once
cause Emacs to run out of file descriptors).

* yasnippet.el (yas--create-snippet-xrefs): Use delete-region instead of kill-region.

Copyright-paperwork-exempt: yes

Close #675.
2016-04-10 11:33:31 -04:00
Noam Postavsky
3e67b1bb7b yasnippet.el (snippet-mode): Add autoload cookie. 2016-04-09 19:51:56 -04:00
Noam Postavsky
4c6064ce1a Avoid potential problems with user's hooks
* yasnippet.el (yas--font-lock-keywords): ignore-errors from
emacs-lisp-mode call, in case user's hooks cause problems (e.g. enabling
`yas-minor-mode' before we finish loading).
2016-04-09 19:50:47 -04:00
Noam Postavsky
4af9fc9815 Further cleanup
* yasnippet.el (yas-snippet-dirs): Fix :type.
(yas--modes-to-activate): Add explicit fboundp check instead of
ignore-errors.
(yas--font-lock-keywords): Remove redundant entries.
(yas--guess-snippet-directories): Simplify.
(yas-load-snippet-buffer-and-close): Use read-file-name.
2016-04-08 18:58:17 -04:00
Stefan Monnier
18f7b1b9fe Various cleanup
* yasnippet/yasnippet.el: Add Package-Requires since we use cl-lib.
(yas-installed-snippets-dir, yas--default-user-snippets-dir)
(yas--load-directory-1, yas-load-snippet-buffer-and-close):
Use expand-file-name.
(yas-buffer-local-condition): Let's not quote lambdas.
(yas--modes-to-activate): Fix compiler warning about free `dfs' var and
unused return value of `mapcar'.
(yas-minor-mode): Don't confuse emulation-mode-map-alists for a hook.
(yas--font-lock-keywords): Don't hardcode the name of emacs-lisp-mode's
font-lock keywords.
(yas--calculate-group): Use file-relative-name.
(yas--subdirs): Don't mismatch \n in file name.
(yas-expand-from-trigger-key, yas-tryout-snippet): Prefer numbers to
number names.
(yas--guess-snippet-directories): Use expand-file-name rather than
removing&adding / by hand.
(yas--on-field-overlay-modification): Mark `length' as unused.
(yas--update-mirrors): Try to better fit within 80 columns.
(yas--backported-syms, yas--exported-syms): Don't mismatch \n in
symbol name.
2016-04-08 18:57:48 -04:00
24 changed files with 4378 additions and 2320 deletions

4
.gitignore vendored
View File

@ -9,3 +9,7 @@ extras/imported/**
*.elc *.elc
ert-x.* ert-x.*
ert.* ert.*
# ELPA-generated files
/yasnippet-autoloads.el
/yasnippet-pkg.el

7
.gitmodules vendored
View File

@ -1,7 +0,0 @@
[submodule "snippets"]
path = snippets
url = https://github.com/AndreaCrotti/yasnippet-snippets.git
branch = master
[submodule "yasmate"]
path = yasmate
url = https://github.com/capitaomorte/yasmate.git

View File

@ -1,24 +1,49 @@
language: emacs language: generic
os: linux
dist: xenial
git:
submodules: false
env: env:
- "EMACS=emacs23" global:
- "EMACS=emacs24" - Wlexical=t
- Werror=t
- tests_Werror=t # For yasnippet-tests.el
jobs:
- EMACS_VERSION=23.4
# 24.3 gives a bunch of 'value returned from (car value-N) is
# unused' warnings.
- EMACS_VERSION=24.3 tests_Werror=nil
- EMACS_VERSION=24.5
- EMACS_VERSION=25.3
- EMACS_VERSION=26.3
- EMACS_VERSION=27-prerelease
install: install:
- if [ "$EMACS" = "emacs23" ]; then - curl -LO https://github.com/npostavs/emacs-travis/releases/download/bins/emacs-bin-${EMACS_VERSION}.tar.gz
sudo apt-get -qq update && - tar -xaf emacs-bin-${EMACS_VERSION}.tar.gz -C /
sudo apt-get -qq -f install && # Configure $PATH: Emacs installed to /tmp/emacs
sudo apt-get -qq install emacs23-nox && - export PATH=/tmp/emacs/bin:${PATH}
- if ! emacs -Q --batch --eval "(require 'cl-lib)" ; then
curl -Lo cl-lib.el http://elpa.gnu.org/packages/cl-lib-0.6.1.el ;
export warnings="'(not cl-functions)" ;
fi
- if ! emacs -Q --batch --eval "(require 'ert)" ; then
curl -LO https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el && curl -LO https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el &&
curl -LO https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert-x.el && curl -LO https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert-x.el ;
curl -Lo cl-lib.el http://elpa.gnu.org/packages/cl-lib-0.5.el;
fi
- if [ "$EMACS" = "emacs24" ]; then
sudo add-apt-repository -y ppa:cassou/emacs &&
sudo apt-get -qq update &&
sudo apt-get -qq -f install &&
sudo apt-get -qq install emacs24-nox;
fi fi
- emacs --version
script: script:
- rake compile; rake tests - rake yasnippet.elc
- rake yasnippet-debug.elc
- rake yasnippet-tests.elc Werror=$tests_Werror
- rake tests
notifications:
email:
# Default is change, but that includes a new branch's 1st success.
on_success: never
on_failure: always # The default.

View File

@ -1,29 +1,37 @@
# Submitting Bug Reports # Submitting Bug Reports or Patches
Please read [Important note regarding bug reporting][bugnote]. As a GNU ELPA package, bugs or patches may be submitted to the main
Emacs bug list, bug-gnu-emacs@gnu.org. Alternatively, you may use the
# Contributing to Yasnippet [Github issue tracker][issues].
## Copyright Assignment Please read [Important note regarding bug reporting][bugnote].
Yasnippet is part of GNU ELPA, so it falls under the same copyright # Contributing to Yasnippet
assignment policy as the rest of Emacs (see "Copyright Assignment" in
https://www.gnu.org/software/emacs/CONTRIBUTE). A copyright assignment ## Copyright Assignment
for Emacs also covers Yasnippet.
Yasnippet is part of GNU ELPA, so it falls under the same copyright
## Commit message format assignment policy as the rest of Emacs (see "Copyright Assignment" in
https://www.gnu.org/software/emacs/CONTRIBUTE). A copyright assignment
The commit message format roughly follows Emacs conventions, although for Emacs also covers Yasnippet.
there is no separate Changelog file.
## Commit message format
The commit message's first sentence should be capitalized, no period
The commit message format roughly follows Emacs conventions. There is
It may be followed by a paragraph with a longer explanation. The no separate Changelog file.
changelog style entry goes at the end of the message.
Capitalize the first sentence, no period at the end
* foo.el (a-function): Terse summary of per-function changes.
Please make sure the summary line can be understood without having
For trivial changes, a message consisting of just the changelog entry to lookup bug numbers. It may be followed by a paragraph with a
(the `* foo.el ...` part) is fine. longer explanation. The changelog style entry goes at the end of
the message.
[bugnote]: https://github.com/capitaomorte/yasnippet#important-note-regarding-bug-reporting * foo.el (a-function): Terse summary of per-function changes. Use
double spacing between sentences (set `sentence-end-double-space'
to t).
For trivial changes, a message consisting of just the changelog entry
(e.g., `* foo.el (a-function): Fix docstring typo.`) is fine.
[bugnote]: https://github.com/joaotavora/yasnippet#important-note-regarding-bug-reporting
[issues]: https://github.com/joaotavora/yasnippet/issues

46
Makefile Normal file
View File

@ -0,0 +1,46 @@
### Makefile for Yasnippet (stolen from Eglot)
# Variables
#
EMACS?=emacs
SELECTOR?=t
ERROR_ON_WARN=nil
LOAD_PATH=-L .
ELFILES := yasnippet.el yasnippet-tests.el
ELCFILES := $(ELFILES:.el=.elc)
BYTECOMP_ERROR_ON_WARN := \
--eval '(setq byte-compile-error-on-warn $(ERROR_ON_WARN))'
all: compile
%.elc: %.el
$(EMACS) -Q $(BYTECOMP_ERROR_ON_WARN) $(LOAD_PATH) \
--batch -f batch-byte-compile $<
compile: $(ELCFILES)
# Automated tests
#
yasnippet-check: compile
$(EMACS) -Q --batch \
$(LOAD_PATH) \
-l yasnippet \
-l yasnippet-tests \
--eval '(setq ert-batch-backtrace-right-margin 200)' \
--eval '(ert-run-tests-batch-and-exit (quote $(SELECTOR)))'
interactive: compile
$(EMACS) -Q \
$(LOAD_PATH) \
-l yasnippet \
-l yasnippet-tests \
check: yasnippet-check
# Cleanup
#
clean:
find . -iname '*.elc' -exec rm {} \;
.PHONY: all compile clean check

366
NEWS
View File

@ -1,10 +1,368 @@
Yasnippet NEWS -- history of user-visible changes. Yasnippet NEWS -- history of user-visible changes.
Copyright (C) 2016 Free Software Foundation, Inc. Copyright (C) 2017-2025 Free Software Foundation, Inc.
See the end of the file for license conditions. See the end of the file for license conditions.
Changes since 0.14.0:
- Silence warning about missing lexical-binding cookie.
- Bug fixes and code cleanups.
- Accept ${N} as another syntax for $N (issue #1012).
- Understand the new AUCTeX modes hierarchy (issue #1193).
- Try and use `major-mode-remap-alist` to find the right snippets for
Tree Sitter modes (issue #1169).
* 0.14.0 (Dec 22, 2019)
** Changes
*** New 'yas-auto-next' macro, automatically moves to next field.
See Github #937.
*** Yasnippet now officially requires Emacs 23 or greater.
See Github #940.
*** Snippets for 'fundamental-mode' are available in all modes.
See Github #949, and #936.
*** New function for snippets, 'yas-completing-read'.
See Github #934.
*** New function 'yas-maybe-expand-abbrev-key-filter'.
This can be used for making conditional keybindings for snippets.
Promoted from 'yas--maybe-expand-key-filter'. See Github #943.
*** DEL can now be used to clear fields, similar <delete>.
It is bound to the new conditional command 'yas-maybe-clear-field', which may
be bound to other keys as well. See Github #960 and #957.
*** Snippet field movement commands may now trigger eldoc.
See Github #952.
*** New variable 'yas-keymap-disable-hook'.
Can be used (e.g., for company-mode) to temporarily disable
'yas-keymap' bindings, or any binding made by the new function
'yas-filtered-definition'. See Github #987.
*** New variable 'yas-inhibit-overlay-modification-protection'.
This allows a snippet to remain active, even if some commands make
modifications outside the expected area (i.e., the active snippet
field).
*** 'yas-minor-mode' is no longer enabled in temp buffers.
That is, buffers whose name starts with a space. This setting may be
undone by removing 'yas-temp-buffer-p' from
'yas-dont-activate-functions'. See Github #985.
*** Accept unescaped '{', for LSP compatibility.
See Github #979.
** Fixed bugs
*** 'yas-not-string-or-comment-condition' no longer relies on 'this-command'.
This lets it work correctly with conditional key-bindings. See Github
#973, #991.
*** Fix snippet expansion in org src buffers.
Note that this still doesn't work in text-mode blocks.
See Github #976, #989.
*** Fix snippet insertion for keyless snippets.
See Github #1014.
*** Fix errors with company-mode completion within snippet fields.
See Github #995.
*** Fix errors with cc-mode.
See Github #962.
*** Fix problems with lsp-mode.
**** Improve performance in overlay heavy buffers (Github #926).
**** Fix double call of 'before/after-change-functions' (Github #966).
*** Fix errors with nested snippet expansion.
See Github #961, #1002.
*** Stop yas-field-highlight-face inheriting from bogus 'quote' face.
* 0.9.1 (est. March 2016) * 0.13.0 (May 13, 2018)
** Changes
*** Snippets for Yasnippet must now be installed separately. The
submodule linking to yasnippet-snippets was removed, as were the
"classic" snippets that came with the GNU ELPA package. The latter
can now be installed via the 'yasnippet-classic-snippets' package from
GNU ELPA.
See Github #848, #858, #834, #775.
*** 'snippet-mode' no longer derives from 'text-mode'.
It will derive from 'prog-mode' where available (Emacs 24.1 and newer)
or 'fundamental-mode' otherwise. See Github #826.
*** The default value of 'yas-key-syntaxes' is changed
Longer snippet abbrev keys are now preferred over shorter ones.
See Github #805.
*** New snippets are now created for the current major mode by default
Previously, extra activated modes could be guessed first.
See Github #875.
*** Yasnippet supports 'unload-feature' via 'yasnippet-unload-function'
See Github #753, #891.
*** New command 'yas-skip-and-clear-field' conditionally bound to 'C-d'
replaces obsoleted 'yas-skip-and-clear-or-delete-char'. The new
function may be bound to any key via the conditional binding value
'yas-maybe-skip-and-clear-field', instead of hardcoding the
'delete-char' fallback action. See Github #408, #892.
*** 'yas-lookup-snippet' now returns a struct
This allows 'yas-expand-snippet' to take looked up snippet's
environment into account. 'yas-expand-snippet' handles both
structured snippets, and plain text snippet bodies.
See Github #897.
** Fixed bugs
*** Avoid crashing due to Emacs Bug#30931
This prevents yasnippet's routines from triggering the bug, although
it is still possible to trigger it independently.
*** Don't enable undo when it's disabled
*** yas-also-auto-indent-first-line is once again respected
Yasnippet was behaving as if it was always t for single line snippets.
See Github #912.
*** Fixed handling of fixed indent with fields at beginning of line
See Github #906, #908.
*** Fixed incorrect snippets leaving "bad memory"
and possibly corrupting future expansions.
See Github #800.
*** 'global-whitespace-mode' now functions in new snippet buffers.
To fix this, the buffer name for new snippet buffers is now '+new
snippet+' instead of '*new snippet*'. See Github #842.
*** Nest snippet expansion may clear default field text
See Github #844.
*** Fixed undo list corruption snippet expand+indent.
See Github #869.
*** The '# --' marker in snippets now allows trailing whitespace.
See Github #862.
*** Fixed handling of nested simple $n fields
See Github #824, #894.
* 0.12.2 (Aug 28, 2017)
** The new option 'yas-also-auto-indent-empty-lines' allows restoring
the old indent behavior. See Github #850, #710, #685, #679.
** Keybinding triggered snippets once again deactivate the mark.
See Github #840.
* 0.12.1 (Jul 23, 2017)
This is a quick bugfix release.
** Compilation errors in yasnippet-tests.el and yasnippet-debug.el are fixed.
** A snippet-local setting of 'yas-indent-line' is now respected
during indentation triggered by auto-fill as well. See Github #838.
* 0.12.0 (Jul 17, 2017)
** Changes and New Features
*** Snippets can now expand in strings & comments by default again.
'yas-buffer-local-condition' is now a defcustom See Github #774.
*** 'yas-after-exit-snippet-hook' can now be bound in 'expand-env' of
snippets. See Github #28, #702, #779, #786.
*** Snippets under directories in 'yas-snippet-dirs' are now in
snippet-mode automatically.
*** Snippets can now be expanded in org source blocks, if
'org-src-tab-acts-natively' and 'org-src-fontify-natively' are set.
See Github #761.
*** 'yas-fallback-behavior' is now obsolete, 'yas-expand' is now bound
conditionally with an extended menu item, 'yas-maybe-expand'.
Therefore users wanting to bind 'yas-expand' to a different key, SPC
for example, should do
(define-key yas-minor-mode-map (kbd "SPC") yas-maybe-expand)
See Github #760, #808.
*** The documentation build output is now reproducible. The timestamp
now depends on the commit date, or the environment variable
SOURCE_DATE_EPOCH is that is set.
*** 'yas-indent-line' and 'expand-env' are now respected during mirror
updates. See Github #743.
*** New function 'yas-active-snippets'. Renamed from
'yas--snippets-at-point', which remains as an obsolete alias. See
Github #727.
*** New custom option 'yas-overlay-priority'. This is can be used to
give the snippet navigation keymaps higher priority than keymaps from
overlays created by other packages, like 'auto-complete'. See Github
#828.
** Fixed bugs
*** Snippets having ${0:soon-to-be-deleted} with no other fields now
correctly put the field 0 text in the active region after exiting.
See Github #653.
*** Fix undo of snippet insertion which also triggers indentation.
See Github #821.
*** Fixed a bug causing whitespace loss between mirrors.
*** Fixed several bugs causing problems when combining Yasnippet with
other modes and packages, like 'auto-fill-mode', 'c++-mode',
'rust-mode', and 'lentic'.
**** Fix another bug with auto-fill-mode.
See Github #784, #794.
**** Fix a bug in parsing of snippet fields for modes that use the
'syntax-table' text property, 'c++-mode' is one example of this. See
Github #815.
**** 'syntax-propertize-function' is now restored before indenting the
snippet. This improves compatibility with modes which rely on it for
indentation, like 'rust-mode'. See Github #782, #818.
**** Avoid trying to delete a snippet which is already deleted. This
prevents an error when using 'rust-mode's 'rust-format-buffer'
command.
**** Ensure inhibit-modification-hooks is nil while modifying buffer.
This fixes problems for packages relying on modification hooks, like
'lentic'. See Github #756, #712.
* 0.11.0 (Oct 26, 2016)
** Changes and New Features
*** Modifying buffer in backquoted expressions is deprecated!
Backquoted expressions should only return a string that will be
inserted. Snippets which modify the buffer as a side-effect will now
trigger a warning.
*** The verbosity levels for messages have been adjusted.
While the default verbosity level was increased by 1 (it was only
lower before due to a bug), several messages now only print at the
level 4, so the overall effect should be less messages by default.
*** Saving and loading snippets has been streamlined. Saving the
snippet to a file will now automatically load it. Additionally, the
buffer will be renamed from "*new snippet*" to whatever the snippet is
named. See also Github #718, #733, and #734.
*** `yas-escape-text' no longer signals an error when given nil.
*** `yas-describe-tables' is split into simpler commands.
**** `yas-describe-tables' takes a prefix arg to show non-active tables.
**** New command `yas-describe-tables-by-namehash' shows table by namehash.
*** Use the region contents as the snippet body of new snippets.
*** The dependency on `cl' is removed.
Yasnippet now only requires `cl-lib'.
** Fixed Bugs
*** Fix field navigation (tabbing) in the backwards direction.
See Github #722
*** Add support for deprecated yas/ symbols in `yas-define-menu'.
It was left out by accident. This support is conditional on
`yas-alias-to-yas/prefix-p', just like other obsolete yas/ bindings.
*** Fix overriding of snippet by a new snippet with same uuid.
See Github #714.
*** Fix handling of snippets with 2 mirros on the same line.
See Github #712.
* 0.10.0 (June 11th, 2016)
** Changes and New Features
*** Yasnippet now prints far fewer message by default.
See Github #682, #683.
*** `yas-wrap-around-region' can be set to a register.
The register's content will be used. This is like the old `cua'
option, but can be used with any register and doesn't require enabling
cua-mode.
*** Clearing of snippet fields is now decided by the command's effect.
The `delete-selection' property is no longer consulted. See Github #662.
*** Empty lines in snippet expansion are no longer indented.
See Github #679.
*** All lines from mirror output are now indented.
See Github #665.
*** New variable yas-alias-to-yas/prefix-p
See Github #696, #699.
*** New function yas-next-field-will-exit-p
See Github #561.
*** `snippet-mode' is now autoloaded.
** Fixed Bugs
*** Fix incompatibility with Emacs 25 and haskell-mode.
This should also help other modes with a non-nil syntax-propertize
function. See Github #687.
*** Text property changes no longer disable snippets.
This prevents cc-mode based modes from causing premature exit of
snippets. See Github #677.
*** Fields are now transformed correctly after `yas-next-field'.
See Github #381.
*** The $> construct is now escaped correctly, and documented.
See Github #640.
*** Avoid corruption of snippet content when loading from files.
See Github #707 and Emacs bug #23659.
*** `yas-wrap-around-region' now works for snippets with fields
farther down the buffer than $0. See Github #636.
*** The active region is deleted when using `yas-expand'.
This makes it consistent with `yas-insert-snippet'. See Github #523.
*** Fix mirror+autofill interaction.
See Github #643 and http://emacs.stackexchange.com/q/19206/5296.
*** Snippet insertion no longer adds irrelevant strings to kill ring.
See Github #675.
* 0.9.1 (April 3rd, 2016)
** Changes and New Features ** Changes and New Features
@ -53,7 +411,7 @@ good enough. See issue #497.
*** Documentation rewritten in org-mode and updated. *** Documentation rewritten in org-mode and updated.
A tremendous effort by Noam Postavsky. Hopefully easier to maintain A tremendous effort by Noam Postavsky. Hopefully easier to maintain
and navigate. Available at <http://capitaomorte.github.io/yasnippet>. and navigate. Available at <http://joaotavora.github.io/yasnippet>.
*** Snippets are now maintained in their own repo. *** Snippets are now maintained in their own repo.
Snippets live in Andrea Crotti's Snippets live in Andrea Crotti's
@ -61,7 +419,7 @@ Snippets live in Andrea Crotti's
for more details. for more details.
*** Textmate snippet importer moved to separate `yasmate' repo. *** Textmate snippet importer moved to separate `yasmate' repo.
URL is <https://github.com/capitaomorte/yasmate>. See README.md for URL is <https://github.com/joaotavora/yasmate>. See README.md for
more details. more details.
*** `yas-snippet-dirs' now allows symbols as aliases to directories. *** `yas-snippet-dirs' now allows symbols as aliases to directories.

View File

@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/capitaomorte/yasnippet.png)](https://travis-ci.org/capitaomorte/yasnippet) [![Build Status](https://travis-ci.org/joaotavora/yasnippet.png)](https://travis-ci.org/joaotavora/yasnippet)
# Intro # Intro
@ -15,12 +15,12 @@ YASnippet. Watch [a demo on YouTube][youtube-demo].
# Installation # Installation
## Install the most recent version ## Manual install from Git
Clone this repository somewhere Clone this repository somewhere
$ cd ~/.emacs.d/plugins $ cd ~/.emacs.d/plugins
$ git clone --recursive https://github.com/capitaomorte/yasnippet $ git clone --recursive https://github.com/joaotavora/yasnippet
Add the following in your `.emacs` file: Add the following in your `.emacs` file:
@ -33,12 +33,16 @@ Add your own snippets to `~/.emacs.d/snippets` by placing files there or invokin
## Install with `package-install` ## Install with `package-install`
In a recent emacs `M-x list-packages` is the recommended way to list and install packages. In a recent emacs `M-x list-packages` is the recommended way to list
[MELPA][melpa] keeps a very recent snapshot of YASnippet, see http://melpa.org/#installing. and install packages.
It's available from [GNU ELPA][gnuelpa].
If you need a very recent snapshot, you can get it from
[GNU-devel ELPA][gnudevel] as well as [MELPA][melpa]
(see http://melpa.org/#installing).
## Install with el-get ## Install with el-get
El-get is a nice way to get the most recent version, too. See El-get is another nice way to get the most recent version, too. See
https://github.com/dimitri/el-get for instructions. https://github.com/dimitri/el-get for instructions.
## Use `yas-minor-mode` on a per-buffer basis ## Use `yas-minor-mode` on a per-buffer basis
@ -55,33 +59,22 @@ where you want YASnippet enabled.
<a name="import"></a> <a name="import"></a>
Yasnippet no longer bundles snippets directly, but it's very easy to YASnippet no longer bundles snippets directly, but it's very easy to
get some! get some!
If you git-cloned yasnippet with the `--recursive` option you'll also 1. [yasnippet-snippets] - a snippet collection package maintained by
download "git submodules" and find two subdirs under the main tree.
1. `snippets/`
Points to [yasnippet-snippets] the snippet collection of
[AndreaCrotti](https://github.com/AndreaCrotti). [AndreaCrotti](https://github.com/AndreaCrotti).
The default configuraiton already points to this dir, so to use It can be installed with `M-x package-install RET
them, just make sure the submodule really was downloaded yasnippet-snippets` if you have added MELPA to your package
(i.e. there are some files under `snippets/`) sources.
2. `yasmate/` 2. [yasmate] a tool which is dedicated to converting textmate bundles
into yasnippet snippets.
Points to a github repo of the [yasmate] tool, which is dedicated
to converting textmate bundles into yasnippet snippets.
To use these snippets you have to run the tool first, so To use these snippets you have to run the tool first, so
[see its doc][yasmate]), and then point the `yas-snippet-dirs` [see its doc][yasmate]), and then point the `yas-snippet-dirs`
variable to the `.../yasmate/snippets` subdir. variable to the `.../yasmate/snippets` subdir.
If you have a working ruby environment, you can probably get lucky
directly with `rake convert-bundles`.
3. [textmate-to-yas.el] 3. [textmate-to-yas.el]
This is another textmate bundle converting tool using Elisp This is another textmate bundle converting tool using Elisp
@ -96,16 +89,23 @@ should be added like this to `yas-snippet-dirs`:
'("~/.emacs.d/snippets" ;; personal snippets '("~/.emacs.d/snippets" ;; personal snippets
"/path/to/some/collection/" ;; foo-mode and bar-mode snippet collection "/path/to/some/collection/" ;; foo-mode and bar-mode snippet collection
"/path/to/yasnippet/yasmate/snippets" ;; the yasmate collection "/path/to/yasnippet/yasmate/snippets" ;; the yasmate collection
"/path/to/yasnippet/snippets" ;; the default collection
)) ))
(yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already. (yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already.
# Manual, issues etc # Manual, issues etc
Please refer to the comprehensive [documentation][docs] for full There's comprehensive [documentation][docs] on using and customising
customisation and support. If you find a bug in the code or in the YASnippet.
documentation, please report it on [the GitHub issue tracker][issues].
There's a [list of support issues][support-issues], with solutions to
common problems and practical snippet examples.
The [Github issue tracker][issues] is where most YASnippet-related
discussion happens. Nevertheless, since YASnippet is a part of Emacs,
you may alternatively report bugs to Emacs via `M-x report-emacs-bug` or
sending an email to `bug-gnu-emacs@gnu.org`, putting "yasnippet"
somewhere in the subject.
## Important note regarding bug reporting ## Important note regarding bug reporting
@ -117,14 +117,14 @@ a way to reproduce the problem exactly like it happened to you.
To do this, we need to rule out interference from external factors To do this, we need to rule out interference from external factors
like other Emacs extensions or your own customisations. like other Emacs extensions or your own customisations.
Here's an example report that "sandboxes" an Emacs session just for Here's an example report that "sandboxes" an Emacs session just for
reproducing a bug. reproducing a bug.
``` ```
$ emacs --version $ emacs --version
Emacs 24.3 Emacs 24.3
$ cd /tmp/ $ cd /tmp/
$ git clone https://github.com/capitaomorte/yasnippet.git yasnippet-bug $ git clone https://github.com/joaotavora/yasnippet.git yasnippet-bug
$ cd yasnippet-bug $ cd yasnippet-bug
$ git log -1 --oneline $ git log -1 --oneline
6053db0 Closes #527: Unbreak case where yas-fallback-behaviour is a list 6053db0 Closes #527: Unbreak case where yas-fallback-behaviour is a list
@ -138,11 +138,11 @@ OR
When loading yasnippet I see "Error: failed to frobnicate"! When loading yasnippet I see "Error: failed to frobnicate"!
``` ```
Using `emacs -Q` or temporarily moving your `.emacs` init file to the side Using `emacs -Q` or temporarily moving your `.emacs` init file to the side
is another way to achieve good reproducibility. is another way to achieve good reproducibility.
Here's a Here's a
[another example](https://github.com/capitaomorte/yasnippet/issues/318) [another example](https://github.com/joaotavora/yasnippet/issues/318)
of a bug report. It has everything needed for a successful analysis of a bug report. It has everything needed for a successful analysis
and speedy resolution. and speedy resolution.
@ -153,19 +153,16 @@ do `git log -1` in the dir).
Any more info is welcome, but don't just paste a backtrace or an error Any more info is welcome, but don't just paste a backtrace or an error
message string you got, unless we ask for it. message string you got, unless we ask for it.
There is also a [YASnippet google group][forum]. I will keep the group
open for reference and for discussion among users. Unfortunately I
can't guarantee a timely response, so maybe it's better to create a
github issue clearly marking your intent (user support/bug/feature
request).
Finally, thank you very much for using YASnippet! Finally, thank you very much for using YASnippet!
[docs]: http://capitaomorte.github.com/yasnippet/ [docs]: http://joaotavora.github.io/yasnippet/
[issues]: https://github.com/capitaomorte/yasnippet/issues [issues]: https://github.com/joaotavora/yasnippet/issues
[support-issues]: https://github.com/joaotavora/yasnippet/issues?q=label%3Asupport
[googlecode tracker]: http://code.google.com/p/yasnippet/issues/list [googlecode tracker]: http://code.google.com/p/yasnippet/issues/list
[forum]: http://groups.google.com/group/smart-snippet [forum]: http://groups.google.com/group/smart-snippet
[melpa]: http://melpa.milkbox.net/ [melpa]: http://melpa.milkbox.net/
[yasmate]: http://github.com/capitaomorte/yasmate [gnuelpa]: http://elpa.gnu.org/packages/yasnippet.html
[gnudevel]: http://elpa.gnu.org/devel/yasnippet.html
[yasmate]: http://github.com/joaotavora/yasmate
[textmate-to-yas.el]: https://github.com/mattfidler/textmate-to-yas.el [textmate-to-yas.el]: https://github.com/mattfidler/textmate-to-yas.el
[yasnippet-snippets]: http://github.com/AndreaCrotti/yasnippet-snippets [yasnippet-snippets]: http://github.com/AndreaCrotti/yasnippet-snippets

107
Rakefile
View File

@ -1,107 +0,0 @@
# -*- Ruby -*-
require 'fileutils'
$EMACS = ENV["EMACS"]
if not $EMACS or $EMACS == 't'
$EMACS = "emacs"
end
def find_version
File.read("yasnippet.el", :encoding => "UTF-8") =~ /;; Package-version: *([0-9.]+?) *$/
$version = $1
end
find_version
FileUtils.mkdir_p('pkg')
desc "run tests in batch mode"
task :tests do
sh "#{$EMACS} -Q -L . -l yasnippet-tests.el" +
" --batch -f ert-run-tests-batch-and-exit"
end
desc "create a release package"
task :package do
release_dir = "pkg/yasnippet-#{$version}"
FileUtils.mkdir_p(release_dir)
files = ['snippets', 'yasnippet.el']
FileUtils.cp_r files, release_dir
File.open(File.join(release_dir,'yasnippet-pkg.el'), 'w') do |file|
file.puts <<END
(define-package "yasnippet"
"#{$version}"
"A template system for Emacs")
END
end
sh "git clean -f snippets"
FileUtils.cd 'pkg' do
sh "tar cf yasnippet-#{$version}.tar yasnippet-#{$version}"
end
end
desc "create a release package and upload it to google code"
task :release => [:package, 'doc:archive'] do
raise "Not implemented for github yet!"
end
desc "Generate document"
task :doc do
sh "#{$EMACS} -Q -L . --batch -l doc/yas-doc-helper.el" +
" -f yas--generate-html-batch"
end
namespace :doc do
task :archive do
release_dir = "pkg/yasnippet-#{$version}"
FileUtils.mkdir_p(release_dir)
sh "tar cjf pkg/yasnippet-doc-#{$version}.tar.bz2 " +
"--exclude=doc/.svn --exclude=doc/images/.svn doc/*.html doc/images"
end
task :upload do
if File.exists? 'doc/gh-pages'
Dir.chdir 'doc/gh-pages' do
sh "git checkout gh-pages"
end
Dir.glob("doc/*.{html,css}").each do |file|
FileUtils.cp file, 'doc/gh-pages'
end
Dir.glob("doc/images/*").each do |file|
FileUtils.cp file, 'doc/gh-pages/images'
end
Dir.glob("doc/stylesheets/*.css").each do |file|
FileUtils.cp file, 'doc/gh-pages/stylesheets'
end
curRev = `git rev-parse --verify HEAD`.chomp()
expRev = IO.read('doc/html-revision').chomp()
if curRev != expRev
raise ("The HTML rev: #{expRev},\n" +
"current rev: #{curRev}!\n")
end
if !system "git diff-index --quiet HEAD"
system "git status --untracked-files=no"
raise "You have uncommitted changes!"
end
Dir.chdir 'doc/gh-pages' do
sh "git commit -a -m 'Automatic documentation update.\n\n" +
"From #{curRev.chomp()}'"
sh "git push"
end
end
end
end
desc "Compile yasnippet.el into yasnippet.elc"
rule '.elc' => '.el' do |t|
sh "#{$EMACS} --batch -L . --eval \"(byte-compile-file \\\"#{t.source}\\\")\""
end
task :compile => FileList["yasnippet.el"].ext('elc')
task :default => :doc
desc "use yasmate to convert textmate bundles"
task :convert_bundles do
cd "yasmate"
sh "rake convert_bundles"
end

View File

@ -2,138 +2,67 @@
#+TITLE: Frequently Asked Questions #+TITLE: Frequently Asked Questions
- *Note*: In addition to the questions and answers presented here,
you might also with to visit the list of [[https://github.com/joaotavora/yasnippet/issues?q=label%3Asupport][solved support issues]] in
the Github issue tracker. It might be more up-to-date than this
list.
* Why are my snippet abbrev keys triggering when I don't want them too?
Expansion of abbrev keys is controlled by [[sym:yas-key-syntaxes][=yas-key-syntaxes=]]. Try
removing entries which correspond to the abbrev key character syntax.
For example, if you have a snippet with abbrev key "bar", that you
don't want to trigger when point follows the text =foo_bar=, remove
the ="w"= entry (since "bar" has only word syntax characters).
* Why aren't my snippet abbrev keys triggering when I want them too?
See previous question, but in reverse.
* Why is there an extra newline? * Why is there an extra newline?
If you have a newline at the end of the snippet definition file, then If there is a newline at the end of a snippet definition file,
YASnippet will add a newline when you expanding a snippet. Please don't YASnippet will add a newline when expanding that snippet. When editing
add a newline at the end if you don't want it when you saving the or saving a snippet file, please be careful not to accidentally add a
snippet file. terminal newline.
Note some editors will automatically add a newline for you. In Emacs, if Note that some editors will automatically add a newline for you. In
you set =require-final-newline= to =t=, it will add the final newline Emacs, if you set =require-final-newline= to =t=, it will add the
for you automatically. final newline automatically.
* Why doesn't TAB expand a snippet?
First check the mode line to see if there's =yas=. If not, then try
=M-x yas-minor-mode= to manually turn on the minor mode and try to
expand the snippet again. If it works, then, you can add the following
code to your =.emacs= /before/ loading YASnippet:
#+BEGIN_SRC emacs-lisp
(add-hook 'the-major-mode-hook 'yas-minor-mode-on)
#+END_SRC
where =the-major-mode= is the major mode in which [[sym:yas-minor-mode][=yas-minor-mode=]] isn't
enabled by default.
From YASnippet 0.6 you can also use the command =M-x yas-global-mode= to
turn on YASnippet automatically for /all/ major modes.
If [[sym:yas-minor-mode][=yas-minor-mode=]] is on but the snippet still not expanded. Then try
to see what command is bound to the =TAB= key: press =C-h k= and then
press =TAB=. Emacs will show you the result.
You'll see a buffer prompted by Emacs saying that
=TAB runs the command ...=. Alternatively, you might see
=<tab> runs the command ...=, note the difference between =TAB= and
=<tab>= where the latter has priority. If you see =<tab>= bound to a
command other than [[sym:yas-expand][=yas-expand=]], (e.g. in =org-mode=) you can try the
following code to work around:
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook
(let ((original-command (lookup-key org-mode-map [tab])))
`(lambda ()
(setq yas-fallback-behavior
'(apply ,original-command))
(local-set-key [tab] 'yas-expand))))
#+END_SRC
replace =org-mode-hook= and =org-mode-map= with the major mode hook you
are dealing with (Use =C-h m= to see what major mode you are in).
As an alternative, you can also try
#+BEGIN_SRC emacs-lisp
(defun yas-advise-indent-function (function-symbol)
(eval `(defadvice ,function-symbol (around yas-try-expand-first activate)
,(format
"Try to expand a snippet before point, then call `%s' as usual"
function-symbol)
(let ((yas-fallback-behavior nil))
(unless (and (interactive-p)
(yas-expand))
ad-do-it)))))
(yas-advise-indent-function 'ruby-indent-line)
#+END_SRC
To /advise/ the modes indentation function bound to TAB, (in this case
=ruby-indent-line=) to first try to run [[sym:yas-expand][=yas-expand=]].
If the output of =C-h k RET <tab>= tells you that =<tab>= is indeed
bound to [[sym:yas-expand][=yas-expand=]] but YASnippet still doesn't work, check your
configuration and you may also ask for help on the [[http://groups.google.com/group/smart-snippet][discussion group]].
See this particular [[http://code.google.com/p/yasnippet/issues/detail?id=93&can=1][thread]] for quite some solutions and alternatives.
Don't forget to attach the information on what command is bound to TAB
as well as the mode information (Can be obtained by =C-h m=).
* Why doesn't TAB navigation work with flyspell * Why doesn't TAB navigation work with flyspell
A workaround is to inhibit flyspell overlays while the snippet is This is [[https://debbugs.gnu.org/26672][Emacs Bug#26672]], so you should upgrade to version 25.3 or
active: better. Otherwise, a workaround is to inhibit flyspell overlays while
the snippet is active:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-hook 'flyspell-incorrect-hook (add-hook 'flyspell-incorrect-hook
#'(lambda (dummy1 dummy2 dymmy3) #'(lambda (&rest _)
(and yas-active-field-overlay (and yas-active-field-overlay
(overlay-buffer yas-active-field-overlay)))) (overlay-buffer yas-active-field-overlay))))
#+END_SRC #+END_SRC
This is apparently related to overlay priorities. For some reason, the * How do I use alternative keys, i.e. not TAB?
=keymap= property of flyspell's overlays always takes priority over the
same property in YASnippet's overlays, even if one sets the latter's
=priority= property to something big. If you know emacs-lisp and can
solve this problem, drop a line in the
[[http://groups.google.com/group/smart-snippet][discussion group]].
* How to I use alternative keys, i.e. not TAB? Edit the keymaps [[sym:yas-minor-mode-map][=yas-minor-mode-map=]] and [[sym:yas-keymap][=yas-keymap=]] as you would
any other keymap, but use [[sym:yas-filtered-definition][=yas-filtered-definition=]] on the definition
Edit the keymaps [[sym:yas-minor-mode-map][=yas-minor-mode-map=]] and if you want to respect [[sym:yas-keymap-disable-hook][=yas-keymap-disable-hook=]]:
[[sym:yas-keymap][=yas-keymap=]] as you would any other keymap:
#+begin_src emacs-lisp :exports code #+begin_src emacs-lisp :exports code
(define-key yas-minor-mode-map (kbd "<tab>") nil) (define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<the new key>") 'yas-expand) (define-key yas-minor-mode-map (kbd "<the new key>") yas-maybe-expand)
;;keys for navigation ;;keys for navigation
(define-key yas-keymap [(tab)] nil) (define-key yas-keymap [(tab)] nil)
(define-key yas-keymap (kbd "TAB") nil) (define-key yas-keymap (kbd "TAB") nil)
(define-key yas-keymap [(shift tab)] nil) (define-key yas-keymap [(shift tab)] nil)
(define-key yas-keymap [backtab] nil) (define-key yas-keymap [backtab] nil)
(define-key yas-keymap (kbd "<new-next-field-key>") 'yas-next-field-or-maybe-expand) (define-key yas-keymap (kbd "<new-next-field-key>")
(define-key yas-keymap (kbd "<new-prev-field-key>") 'yas-prev) (yas-filtered-definition 'yas-next-field-or-maybe-expand))
(define-key yas-keymap (kbd "<new-prev-field-key>")
(yas-filtered-definition 'yas-prev-field))
#+end_src #+end_src
* How do I turn off the minor mode where in some buffers?
The best way, since version 0.6.1c, is to set the default value of the
variable [[sym:yas-dont-activate][=yas-dont-activate=]] to a lambda function like so:
#+BEGIN_SRC emacs-lisp
(set-default 'yas-dont-activate
#'(lambda ()
(and yas-root-directory
(null (yas-get-snippet-tables)))))
#+END_SRC
This is also the default value starting for that version. It skips the
minor mode in buffers where it is not applicable (no snippet tables),
but only once you have setup your yas-root-directory.
* How do I define an abbrev key containing characters not supported by the filesystem? * How do I define an abbrev key containing characters not supported by the filesystem?
- *Note*: This question applies if you're still defining snippets - *Note*: This question applies if you're still defining snippets

View File

@ -3,7 +3,7 @@
The YASnippet documentation has been split into separate parts: The YASnippet documentation has been split into separate parts:
0. [[https://github.com/capitaomorte/yasnippet/blob/master/README.mdown][README]] 0. [[https://github.com/joaotavora/yasnippet/blob/master/README.mdown][README]]
Contains an introduction, installation instructions and other important Contains an introduction, installation instructions and other important
notes. notes.

View File

@ -1,10 +1,10 @@
<nav> <nav>
<ul class="center"> <ul class="center">
<li> <a href="index.html">Overview</a> <li> <a href="index.html">Overview</a>
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown"> <li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
Intro and Tutorial</a> Intro and Tutorial</a>
<li class="center">Snippet <li class="center border">Snippet
<ul> <ul class="nopad">
<li> <a href="snippet-organization.html">Organization</a> <li> <a href="snippet-organization.html">Organization</a>
<li> <a href="snippet-expansion.html">Expansion</a> <li> <a href="snippet-expansion.html">Expansion</a>
<li> <a href="snippet-development.html">Development</a> <li> <a href="snippet-development.html">Development</a>

View File

@ -4,7 +4,7 @@
#+LINK: sym file:snippet-reference.org::#%s #+LINK: sym file:snippet-reference.org::#%s
#+OPTIONS: author:nil num:nil #+OPTIONS: author:nil num:nil timestamp:nil
#+AUTHOR: #+AUTHOR:
# org < 8.0 use +STYLE, after use +HTML_HEAD # org < 8.0 use +STYLE, after use +HTML_HEAD
#+STYLE: <link rel="stylesheet" type="text/css" href="stylesheets/manual.css" /> #+STYLE: <link rel="stylesheet" type="text/css" href="stylesheets/manual.css" />

View File

@ -8,52 +8,48 @@
There are some ways you can quickly find a snippet file or create a new one: There are some ways you can quickly find a snippet file or create a new one:
- =M-x yas-new-snippet= - =M-x yas-new-snippet=, key binding: =C-c & C-n=
Creates a new buffer with a template for making a new snippet. Creates a new buffer with a template for making a new snippet. The
The buffer is in =snippet-mode= (see below). When you are done buffer is in =snippet-mode= (see [[snippet-mode][below]]). When you are done editing
editing the new snippet, use =C-c C-c= to save it. This will the new snippet, use [[yas-load-snippet-buffer-and-close][=C-c C-c=]] to save it.
prompt for a directory two steps: first, the snippet table
(with a default based on the major mode you started in), and then
then snippet collection directory (defaults to the first directory
in =yas-snippet-dirs=. (See [[file:snippet-organization.org][Organizing Snippets]]
for more detail on how snippets are organized.)
- =M-x yas-find-snippets= - =M-x yas-visit-snippet-file=, key binding: =C-c & C-v=
Lets you find the snippet file in the directory the snippet was
loaded from (if it exists) like =find-file-other-window=. The
directory searching logic is similar to =M-x yas-new-snippet=.
- =M-x yas-visit-snippet-file=
Prompts you for possible snippet expansions like Prompts you for possible snippet expansions like
[[sym:yas-insert-snippet][=yas-insert-snippet=]], but instead of expanding it, takes you directly [[sym:yas-insert-snippet][=yas-insert-snippet=]], but instead of expanding it, takes you directly
to the snippet definition's file, if it exists. to the snippet definition's file, if it exists.
Once you find this file it will be set to =snippet-mode= (see ahead) and Once you find this file it will be set to =snippet-mode= (see [[snippet-mode][ahead]])
you can start editing your snippet. and you can start editing your snippet.
** Using the =snippet-mode= major mode ** Using the =snippet-mode= major mode <<snippet-mode>>
There is a major mode =snippet-mode= to edit snippets. You can set the There is a major mode =snippet-mode= to edit snippets. You can set the
buffer to this mode with =M-x snippet-mode=. It provides reasonably buffer to this mode with =M-x snippet-mode=. It provides reasonably
useful syntax highlighting. useful syntax highlighting.
Two commands are defined in this mode: Three commands are defined in this mode:
- =M-x yas-load-snippet-buffer= - =M-x yas-load-snippet-buffer=, key binding: =C-c C-l=
When editing a snippet, this loads the snippet into the correct Prompts for a snippet table (with a default based on snippet's
mode and menu. Bound to =C-c C-c= by default while in major mode) and loads the snippet currently being edited.
=snippet-mode=.
- =M-x yas-tryout-snippet= - =M-x yas-load-snippet-buffer-and-close=, key binding: =C-c C-c=
<<yas-load-snippet-buffer-and-close>>
When editing a snippet, this opens a new empty buffer, sets it to Like =yas-load-snippet-buffer=, but also saves the snippet and
the appropriate major mode and inserts the snippet there, so you calls =quit-window=. The destination is decided based on the
can see what it looks like. This is bound to =C-c C-t= while in chosen snippet table and snippet collection directly (defaulting to
=snippet-mode=. the first directory in =yas-snippet-dirs= (see [[file:snippet-organization.org][Organizing Snippets]]
for more detail on how snippets are organized).
- =M-x yas-tryout-snippet=, key binding: =C-c C-t=
When editing a snippet, this opens a new empty buffer, sets it to
the appropriate major mode and inserts the snippet there, so you
can see what it looks like.
There are also /snippets for writing snippets/: =vars=, =$f= and =$m= There are also /snippets for writing snippets/: =vars=, =$f= and =$m=
:-). :-).
@ -66,7 +62,7 @@ expanded.
Optionally, if the file contains a line of =# --=, the lines above it Optionally, if the file contains a line of =# --=, the lines above it
count as comments, some of which can be /directives/ (or meta data). count as comments, some of which can be /directives/ (or meta data).
Snippet directives look like =# property: value= and tweak certain Snippet directives look like =# property: value= and tweak certain
snippets properties described below. If no =# --= is found, the whole snippet properties described below. If no =# --= is found, the whole
file is considered the snippet template. file is considered the snippet template.
Here's a typical example: Here's a typical example:
@ -84,7 +80,7 @@ Here's a list of currently supported directives:
This is the probably the most important directive, it's the This is the probably the most important directive, it's the
abbreviation you type to expand a snippet just before hitting the key abbreviation you type to expand a snippet just before hitting the key
that runs [[sym:yas-expand][=yas-expand=]]. If you don't specify this that runs [[sym:yas-expand][=yas-expand=]]. If you don't specify this,
the snippet will not be expandable through the trigger mechanism. the snippet will not be expandable through the trigger mechanism.
** =# name:= snippet name ** =# name:= snippet name
@ -93,12 +89,12 @@ This is a one-line description of the snippet. It will be displayed in
the menu. It's a good idea to select a descriptive name for a snippet -- the menu. It's a good idea to select a descriptive name for a snippet --
especially distinguishable among similar snippets. especially distinguishable among similar snippets.
If you omit this name it will default to the file name the snippet was If you omit this name, it will default to the file name the snippet
loaded from. was loaded from.
** =# condition:= snippet condition ** =# condition:= snippet condition
This is a piece of Emacs-lisp code. If a snippet has a condition, then This is a piece of Emacs Lisp code. If a snippet has a condition, then
it will only be expanded when the condition code evaluate to some it will only be expanded when the condition code evaluate to some
non-nil value. non-nil value.
@ -108,7 +104,7 @@ See also [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] in
** =# group:= snippet menu grouping ** =# group:= snippet menu grouping
When expanding/visiting snippets from the menu-bar menu, snippets for a When expanding/visiting snippets from the menu-bar menu, snippets for a
given mode can be grouped into sub-menus . This is useful if one has too given mode can be grouped into sub-menus. This is useful if one has too
many snippets for a mode which will make the menu too long. many snippets for a mode which will make the menu too long.
The =# group:= property only affect menu construction (See The =# group:= property only affect menu construction (See
@ -117,14 +113,14 @@ achieved by grouping snippets into sub-directories and using the
=.yas-make-groups= special file (for this see =.yas-make-groups= special file (for this see
[[./snippet-organization.org][Organizing Snippets]] [[./snippet-organization.org][Organizing Snippets]]
Refer to the bundled snippets for =ruby-mode= for examples on the Refer to the bundled snippets for =ruby-mode= for examples of the
=# group:= directive. Group can also be nested, e.g. =# group:= directive. Group can also be nested, e.g.
=control structure.loops= tells that the snippet is under the =loops= =control structure.loops= indicates that the snippet is under the =loops=
group which is under the =control structure= group. group which is under the =control structure= group.
** =# expand-env:= expand environment ** =# expand-env:= expand environment
This is another piece of Emacs-lisp code in the form of a =let= /varlist This is another piece of Emacs Lisp code in the form of a =let= /varlist
form/, i.e. a list of lists assigning values to variables. It can be form/, i.e. a list of lists assigning values to variables. It can be
used to override variable values while the snippet is being expanded. used to override variable values while the snippet is being expanded.
@ -158,9 +154,9 @@ You can use this directive to expand a snippet directly from a normal
Emacs keybinding. The keybinding will be registered in the Emacs keymap Emacs keybinding. The keybinding will be registered in the Emacs keymap
named after the major mode the snippet is active for. named after the major mode the snippet is active for.
Additionally a variable [[sym:yas-prefix][=yas-prefix=]] is set to to the prefix argument Additionally a variable [[sym:yas-prefix][=yas-prefix=]] is set to the prefix argument
you normally use for a command. This allows for small variations on the you normally use for a command. This allows for small variations on the
same snippet, for example in this "html-mode" snippet. same snippet, for example in this =html-mode= snippet.
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
# name: <p>...</p> # name: <p>...</p>
@ -176,7 +172,7 @@ will expand the paragraph tag without newlines.
** =# type:= =snippet= or =command= ** =# type:= =snippet= or =command=
If the =type= directive is set to =command=, the body of the snippet If the =type= directive is set to =command=, the body of the snippet
is interpreted as lisp code to be evaluated when the snippet is is interpreted as Lisp code to be evaluated when the snippet is
triggered. triggered.
If it's =snippet= (the default when there is no =type= directive), the If it's =snippet= (the default when there is no =type= directive), the
@ -194,7 +190,7 @@ previous snippet.
This is optional and has no effect whatsoever on snippet functionality, This is optional and has no effect whatsoever on snippet functionality,
but it looks nice. but it looks nice.
* <<Template syntax>> * Template Syntax
The syntax of the snippet template is simple but powerful, very similar The syntax of the snippet template is simple but powerful, very similar
to TextMate's. to TextMate's.
@ -206,14 +202,14 @@ usually interpreted as plain text, except =$= and =`=. You need to
use =\= to escape them: =\$= and =\`=. The =\= itself may also needed to be use =\= to escape them: =\$= and =\`=. The =\= itself may also needed to be
escaped as =\\= sometimes. escaped as =\\= sometimes.
** Embedded Emacs-lisp code ** Embedded Emacs Lisp code
Emacs-Lisp code can be embedded inside the template, written inside Emacs Lisp code can be embedded inside the template, written inside
back-quotes (=`=). The lisp forms are evaluated when the snippet is back-quotes (=`=). The Lisp forms are evaluated when the snippet is
being expanded. The evaluation is done in the same buffer as the being expanded. The evaluation is done in the same buffer as the
snippet being expanded. snippet being expanded.
Here's an example for c-mode` to calculate the header file guard Here's an example for =c-mode= to calculate the header file guard
dynamically: dynamically:
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
@ -225,8 +221,8 @@ dynamically:
#endif /* $1 */ #endif /* $1 */
#+END_SRC #+END_SRC
From version 0.6, snippets expansions are run with some special From version 0.6, snippet expansions are run with some special
Emacs-lisp variables bound. One of this is [[sym:yas-selected-text][=yas-selected-text=]]. You can Emacs Lisp variables bound. One of these is [[sym:yas-selected-text][=yas-selected-text=]]. You can
therefore define a snippet like: therefore define a snippet like:
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
@ -239,6 +235,27 @@ to "wrap" the selected region inside your recently inserted snippet.
Alternatively, you can also customize the variable Alternatively, you can also customize the variable
[[sym:yas-wrap-around-region][=yas-wrap-around-region=]] to =t= which will do this automatically. [[sym:yas-wrap-around-region][=yas-wrap-around-region=]] to =t= which will do this automatically.
*** Note: backquote expressions should not modify the buffer
Please note that the Lisp forms in backquotes should *not* modify the
buffer, doing so will trigger a warning. For example, instead of
doing
#+BEGIN_SRC snippet
Timestamp: `(insert (current-time-string))`
#+END_SRC
do this:
#+BEGIN_SRC snippet
Timestamp: `(current-time-string)`
#+END_SRC
The warning may be suppressed with the following code in your init file:
#+BEGIN_SRC emacs-lisp
(add-to-list 'warning-suppress-types '(yasnippet backquote-change))
#+END_SRC
** Tab stop fields ** Tab stop fields
Tab stops are fields that you can navigate back and forth by =TAB= and Tab stops are fields that you can navigate back and forth by =TAB= and
@ -260,16 +277,16 @@ like this:
${N:default value} ${N:default value}
#+END_SRC #+END_SRC
They acts as the default value for a tab stop. But when you firstly They act as the default value for a tab stop. But when you first
type at a tab stop, the default value will be replaced by your typing. type at a tab stop, the default value will be replaced by your typing.
The number can be omitted if you don't want to create [[mirrors]] or The number can be omitted if you don't want to create [[mirrors-fields][mirrors]] or
[[transformations]] for this field. [[mirror-transformations][transformations]] for this field.
** <<Mirrors>> ** Mirrors <<mirrors-fields>>
We refer the tab stops with placeholders as a /field/. A field can have We refer to tab stops with placeholders as a /field/. A field can
mirrors. Its mirrors will get updated when you change the text of a have mirrors. *All* mirrors get updated whenever you update any field
field. Here's an example: text. Here's an example:
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
\begin{${1:enumerate}} \begin{${1:enumerate}}
@ -282,15 +299,15 @@ also be inserted at =\end{$1}=. The best explanation is to see the
screencast([[http://www.youtube.com/watch?v=vOj7btx3ATg][YouTube]] or [[http://yasnippet.googlecode.com/files/yasnippet.avi][avi video]]). screencast([[http://www.youtube.com/watch?v=vOj7btx3ATg][YouTube]] or [[http://yasnippet.googlecode.com/files/yasnippet.avi][avi video]]).
The tab stops with the same number to the field act as its mirrors. If The tab stops with the same number to the field act as its mirrors. If
none of the tab stops has an initial value, the first one is selected as none of the tab stops have an initial value, the first one is selected as
the field and others mirrors. the field and the others are its mirrors.
** Mirrors with <<transformations>> ** Mirrors with transformations <<mirror-transformations>>
If the value of an =${n:=-construct starts with and contains =$(=, If the value of an =${n:=-construct starts with and contains =$(=,
then it is interpreted as a mirror for field =n= with a then it is interpreted as a mirror for field =n= with a
transformation. The mirror's text content is calculated according to transformation. The mirror's text content is calculated according to
this transformation, which is Emacs-lisp code that gets evaluated in this transformation, which is Emacs Lisp code that gets evaluated in
an environment where the variable [[sym:yas-text][=yas-text=]] is bound to the text an environment where the variable [[sym:yas-text][=yas-text=]] is bound to the text
content (string) contained in the field =n=. Here's an example for content (string) contained in the field =n=. Here's an example for
Objective-C: Objective-C:
@ -345,12 +362,26 @@ is not. Here's an snippet for rst title:
$0 $0
#+END_SRC #+END_SRC
Note that a mirror with a transform is not restricted to the text of
the field it is mirroring. By making use of [[sym:yas-field-value][=yas-field-value=]], a
mirror can look at any of the snippet's field (as mentioned above, all
mirrors are updated when any field is updated). Here is an example
which shows a "live" result of calling format:
#+BEGIN_SRC snippet
(format "${1:formatted %s}" "${2:value}")
=> "${1:$(ignore-errors (format (yas-field-value 1) (yas-field-value 2)))}"
#+END_SRC
To keep the example simple, it uses =ignore-errors= to suppress errors
due to incomplete format codes.
** Fields with transformations ** Fields with transformations
From version 0.6 on, you can also have lisp transformation inside From version 0.6 on, you can also have Lisp transformation inside
fields. These work mostly mirror transformations but are evaluated when fields. These work mostly like mirror transformations. However, they
you first enter the field, after each change you make to the field and are evaluated when you first enter the field, after each change you
also just before you exit the field. make to the field and also just before you exit the field.
The syntax is also a tiny bit different, so that the parser can The syntax is also a tiny bit different, so that the parser can
distinguish between fields and mirrors. In the following example distinguish between fields and mirrors. In the following example
@ -381,25 +412,38 @@ the field, and with some useful variables bound, notably
can place a transformation in the primary field that lets you select can place a transformation in the primary field that lets you select
default values for it. default values for it.
The [[sym:yas-choose-value][=yas-choose-value=]] does this work for you. For example: For example, the [[sym:yas-choose-value][=yas-completing-read=]] function is version of
=completing-read= which checks these variables. For example, asking
the user for the initial value of a field:
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
<div align="${2:$$(yas-choose-value '("right" "center" "left"))}"> <div align="${2:$$(yas-completing-read "Alignment? " '("right" "center" "left"))}">
$0 $0
</div> </div>
#+END_SRC #+END_SRC
See the definition of [[sym:yas-choose-value][=yas-choose-value=]] to see how it was written using See the definition of [[sym:yas-choose-value][=yas-completing-read=]] to see how it was written
the two variables. using the two variables. If you're really lazy :) and can't spare a
tab keypress, you can automatically move to the next field (or exit)
after choosing the value with [[sym:yas-auto-next][=yas-auto-next=]]. The snippet above
becomes:
Here's another use, for LaTeX-mode, which calls reftex-label just as you #+BEGIN_SRC snippet
<div align="${2:$$(yas-auto-next
(yas-completing-read
"Alignment? "
'("right" "center" "left")))}">
$0
</div>
#+END_SRC
Here's another use, for =LaTeX-mode=, which calls reftex-label just as you
enter snippet field 2. This one makes use of [[sym:yas-modified-p][=yas-modified-p=]] directly. enter snippet field 2. This one makes use of [[sym:yas-modified-p][=yas-modified-p=]] directly.
#+BEGIN_SRC snippet #+BEGIN_SRC snippet
\section{${1:"Titel der Tour"}}% \section{${1:"Titel der Tour"}}%
\index{$1}% \index{$1}%
\label{{2:"waiting for reftex-label call..."$(unless yas-modified-p (reftex-label nil 'dont- \label{{2:"waiting for reftex-label call..."$(unless yas-modified-p (reftex-label nil 'dont-insert))}}%
insert))}}%
#+END_SRC #+END_SRC
The function [[sym:yas-verify-value][=yas-verify-value=]] has another neat trick, and makes use The function [[sym:yas-verify-value][=yas-verify-value=]] has another neat trick, and makes use
@ -414,7 +458,7 @@ From version 0.6 on, you can also have nested placeholders of the type:
#+END_SRC #+END_SRC
This allows you to choose if you want to give this =div= an =id= This allows you to choose if you want to give this =div= an =id=
attribute. If you tab forward after expanding it will let you change attribute. If you tab forward after expanding, it will let you change
"some\_id" to whatever you like. Alternatively, you can just press =C-d= "some\_id" to whatever you like. Alternatively, you can just press =C-d=
(which executes [[sym:yas-skip-and-clear-or-delete-char][=yas-skip-and-clear-or-delete-char=]]) and go straight to (which executes [[sym:yas-skip-and-clear-or-delete-char][=yas-skip-and-clear-or-delete-char=]]) and go straight to
the exit marker. the exit marker.
@ -422,3 +466,9 @@ the exit marker.
By the way, =C-d= will only clear the field if you cursor is at the By the way, =C-d= will only clear the field if you cursor is at the
beginning of the field /and/ it hasn't been changed yet. Otherwise, it beginning of the field /and/ it hasn't been changed yet. Otherwise, it
performs the normal Emacs =delete-char= command. performs the normal Emacs =delete-char= command.
** Indentation markers
If [[sym:yas-indent-line][=yas-indent-line=]] is *not* set to '=auto=, it's still possible to
indent specific lines by adding an indentation marker, =$>=, somewhere
on the line.

View File

@ -21,7 +21,7 @@
- Using hippie-expand - Using hippie-expand
- Call [[sym:yas-insert-snippet][=yas-insert-snippet=]] (use =M-x yas-insert-snippet== or its - Call [[sym:yas-insert-snippet][=yas-insert-snippet=]] (use =M-x yas-insert-snippet= or its
keybinding =C-c & C-s=). keybinding =C-c & C-s=).
- Use m2m's excellent auto-complete - Use m2m's excellent auto-complete
@ -32,17 +32,33 @@
** Trigger key ** Trigger key
[[sym:yas-expand][=yas-expand=]] tries to expand a /snippet abbrev/ (also known as [[sym:yas-expand][=yas-expand=]] tries to expand a /snippet abbrev/ (also known as
/snippet key/) before point. /snippet key/) before point. YASnippet also provides a /conditional
binding/ for this command: the variable [[sym:yas-expand][=yas-maybe-expand=]] contains a
special value which, when bound in a keymap, tells Emacs to call
[[sym:yas-expand][=yas-expand=]] if and only if there is a snippet abbrev before point.
If there is no snippet to expand, Emacs will behave as if [[sym:yas-expand][=yas-expand=]]
is unbound and so will run whatever command is bound to that key
normally.
When [[sym:yas-minor-mode][=yas-minor-mode=]] is enabled, it binds [[sym:yas-expand][=yas-expand=]] to =TAB= and When [[sym:yas-minor-mode][=yas-minor-mode=]] is enabled, it binds [[sym:yas-maybe-expand][=yas-maybe-expand=]] to =TAB=
=<tab>= by default, however, you can freely set it to some other key: and =<tab>= by default, however, you can freely remove those bindings:
#+begin_src emacs-lisp :exports code #+begin_src emacs-lisp :exports code
(define-key yas-minor-mode-map (kbd "<tab>") nil) (define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<the new key>") 'yas-expand)
#+end_src #+end_src
And set your own:
#+begin_src emacs-lisp :exports code
;; Bind `SPC' to `yas-expand' when snippet expansion available (it
;; will still call `self-insert-command' otherwise).
(define-key yas-minor-mode-map (kbd "SPC") yas-maybe-expand)
;; Bind `C-c y' to `yas-expand' ONLY.
(define-key yas-minor-mode-map (kbd "C-c y") #'yas-expand)
#+end_src
To enable the YASnippet minor mode in all buffers globally use the To enable the YASnippet minor mode in all buffers globally use the
command [[sym:yas-global-mode][=yas-global-mode=]]. This will enable a modeline indicator, command [[sym:yas-global-mode][=yas-global-mode=]]. This will enable a modeline indicator,
=yas=: =yas=:
@ -50,28 +66,18 @@ command [[sym:yas-global-mode][=yas-global-mode=]]. This will enable a modeline
[[./images/minor-mode-indicator.png]] [[./images/minor-mode-indicator.png]]
When you use [[sym:yas-global-mode][=yas-global-mode=]] you can also selectively disable When you use [[sym:yas-global-mode][=yas-global-mode=]] you can also selectively disable
YASnippet in some buffers by setting the buffer-local variable YASnippet in some buffers by calling [[sym:yas-minor-mode][=yas-minor-mode=]] with a negative
[[sym:yas-dont-active][=yas-dont-active=]] in the buffer's mode hook. argument in the buffer's mode hook.
*** Fallback behaviour *** Fallback behaviour
[[sym:yas-fallback-behaviour][=yas-fallback-behaviour=]] is a customization variable bound to YASnippet used to support a more complicated way of sharing
'=call-other-command= by default. If [[sym:yas-expand][=yas-expand=]] failed to find any keybindings before [[sym:yas-expand][=yas-maybe-expand=]] was added. This is now
suitable snippet to expand, it will disable the minor mode temporarily obsolete.
and find if there's any other command bound to the same key.
If found, the command will be called. Usually this works very well
--when there's a snippet, expand it, otherwise, call whatever command
originally bind to the trigger key.
However, you can change this behavior by customizing the
[[sym:yas-fallback-behavior][=yas-fallback-behavior=]] variable. If you set this variable to
'=return-nil=, it will return =nil= instead of trying to call the
/original/ command when no snippet is found.
** Insert at point ** Insert at point
The command [[#yas-insert-snippet][=yas-insert-snippet=]] lets you insert snippets at point The command [[sym:yas-insert-snippet][=yas-insert-snippet=]] lets you insert snippets at point
/for your current major mode/. It prompts you for the snippet key /for your current major mode/. It prompts you for the snippet key
first, and then for a snippet template if more than one template first, and then for a snippet template if more than one template
exists for the same key. exists for the same key.
@ -83,6 +89,19 @@ snippets for the major mode, prefix this command with =C-u=.
The prompting methods used are again controlled by The prompting methods used are again controlled by
[[sym:yas-prompt-functions][=yas-prompt-functions=]]. [[sym:yas-prompt-functions][=yas-prompt-functions=]].
*** Inserting region or register contents into snippet
It's often useful to inject already written text in the middle of a
snippet. The variable [[sym:yas-wrap-around-region][=yas-wrap-around-region=]] when to t substitute
the region contents into the =$0= placeholder of a snippet expanded by
[[sym:yas-insert-snippet][=yas-insert-snippet=]]. Setting it to a character value (e.g. =?0=)
will insert the contents of corresponding register.
Older (versions 0.9.1 and below) of Yasnippet, supported a setting of
=cua= that is equivalent to =?0= but only worked with =cua-mode=
turned on. This setting is still supported for backwards
compatibility, but is now entirely equivalent to =?0=.
** Snippet keybinding ** Snippet keybinding
See the section of the =# binding:= directive in See the section of the =# binding:= directive in
@ -122,7 +141,7 @@ See the internal documentation on [[sym:yas-expand-snippet][=yas-expand-snippet=
* Controlling expansion * Controlling expansion
** Eligible snippets ** Eligible snippets<<eligible-snippets>>
YASnippet does quite a bit of filtering to find out which snippets are YASnippet does quite a bit of filtering to find out which snippets are
eligible for expanding at the current cursor position. eligible for expanding at the current cursor position.
@ -142,15 +161,17 @@ In particular, the following things matter:
=M-x describe-variable RET major-mode RET= to find out which major =M-x describe-variable RET major-mode RET= to find out which major
mode you are in currently. mode you are in currently.
- Parent tables - Parent tables
Snippet tables defined as the parent of some other eligible table are Snippet tables defined as the parent of some other eligible table
also considered. This works recursively, i.e. parents of parents of are also considered. This works recursively, i.e., parents of
eligible tables are also considered. parents of eligible tables are also considered. As a special case,
if a mode doesn't have a parent, then =fundamental-mode= is
considered to be its parent.
- Buffer-local list of extra modes - Buffer-local list of extra modes
Use [[#yas-activate-extra-mode][=yas-activate-extra-mode=]] to Use [[sym:yas-activate-extra-mode][=yas-activate-extra-mode=]] to
consider snippet tables whose name does not correspond to a major consider snippet tables whose name does not correspond to a major
mode. Typically, you call this from a minor mode hook, for example: mode. Typically, you call this from a minor mode hook, for example:
@ -162,53 +183,52 @@ In particular, the following things matter:
(yas-activate-extra-mode 'rails-mode))) (yas-activate-extra-mode 'rails-mode)))
#+END_SRC #+END_SRC
- Buffer-local - Buffer-local [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] variable
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]
variable
This variable provides finer grained control over what snippets can This variable provides finer grained control over what snippets can
be expanded in the current buffer. The default value won't let you be expanded in the current buffer. For example, the constant
expand snippets inside comments or string literals for example. See [[sym:yas-not-string-or-comment-condition][=yas-not-string-or-comment-condition=]] has a value that disables
The condition system\_ for more info. snippet expansion inside comments or string literals. See [[condition-system][the
condition system]] for more info.
** The condition system ** The condition system <<condition-system>>
Consider this scenario: you are an old Emacs hacker. You like the Consider this scenario: you are an old Emacs hacker. You like the
abbrev-way and bind [[sym:yas-expand][=yas-expand=]] to =SPC=. However, you don't want abbrev-way and bind [[sym:yas-expand][=yas-expand=]] to =SPC=. However, you don't want
=if= to be expanded as a snippet when you are typing in a comment =if= to be expanded as a snippet when you are typing in a comment
block or a string (e.g. in =python-mode=). block or a string (e.g. in =python-mode=).
If you use the =# condition := directive (see If you use the =# condition := directive (see [[./snippet-development.org][Writing Snippets]]) you
[[./snippet-development.org][Writing Snippets]]) you could just specify could just specify the condition for =if= to be =(not
the condition for =if= to be =(not (python-in-string/comment))=. But how (python-syntax-comment-or-string-p))=. But how about =while=, =for=,
about =while=, =for=, etc. ? Writing the same condition for all the etc? Writing the same condition for all the snippets is just boring.
snippets is just boring. So has a buffer local variable So you can instead set [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] to =(not
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]. You can set this variable to (python-syntax-comment-or-string-p))= in =python-mode-hook=.
=(not (python-in-string/comment))= in =python-mode-hook=.
Then, what if you really want some particular snippet to expand even Then, what if you really want some particular snippet to expand even
inside a comment? Set [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] like this inside a comment? Set [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] like this
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-hook 'python-mode-hook (add-hook 'python-mode-hook
(lambda () (lambda ()
(setq yas-buffer-local-condition (setq yas-buffer-local-condition
'(if (python-in-string/comment) (lambda ()
'(require-snippet-condition . force-in-comment) (if (python-syntax-comment-or-string-p)
t)))) '(require-snippet-condition . force-in-comment)
t)))))
#+END_SRC #+END_SRC
... and specify the condition for a snippet that you're going to expand ... and for a snippet that you want to expand in comments, specify a
in comment to be evaluated to the symbol =force-in-comment=. Then it can condition which evaluates to the symbol =force-in-comment=. Then it
be expanded as you expected, while other snippets like =if= still can't can be expanded as you expected, while other snippets like =if= still
expanded in comment. can't expanded in comments.
For the full set of possible conditions, see the documentation for For the full set of possible conditions, see the documentation for
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]. [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]].
** Multiples snippet with the same key ** Multiples snippet with the same key
The rules outlined [[Eligible%20snippets][above]] can return more than The rules outlined [[eligible-snippets][above]] can return more than
one snippet to be expanded at point. one snippet to be expanded at point.
When there are multiple candidates, YASnippet will let you select one. When there are multiple candidates, YASnippet will let you select one.

View File

@ -24,7 +24,7 @@ In this menu, you can find
Invoking "Load snippets..." from the menu invokes [[sym:yas-load-directory][=yas-load-directory=]] Invoking "Load snippets..." from the menu invokes [[sym:yas-load-directory][=yas-load-directory=]]
and prompts you for a snippet directory hierarchy to load. and prompts you for a snippet directory hierarchy to load.
Also useful is the "Reload everything" item to invoke [[#yas-reload-all][=yas-reload-all=]] Also useful is the "Reload everything" item to invoke [[sym:yas-reload-all][=yas-reload-all=]]
which uncondionally reloads all the snippets directories defined in which uncondionally reloads all the snippets directories defined in
[[sym:yas-snippet-dirs][=yas-snippet-dirs=]] and rebuilds the menus. [[sym:yas-snippet-dirs][=yas-snippet-dirs=]] and rebuilds the menus.

View File

@ -4,8 +4,9 @@
* Basic structure * Basic structure
Snippet collections can be stored in plain text files. They are arranged by Snippet collections can be stored in plain text files. They are
sub-directories naming *snippet tables*. These mostly name Emacs major names. arranged by sub-directories naming *snippet tables*. These mostly
name Emacs major mode names.
#+begin_example #+begin_example
. .
@ -32,7 +33,7 @@
The default considers: The default considers:
- a personal collection that lives in =~/.emacs.d/snippets= - a personal collection that lives in =~/.emacs.d/snippets=
- the bundled collection, taken as a relative path to =yasnippet.el= localtion - the bundled collection, taken as a relative path to =yasnippet.el= location
When you come across other snippet collections, do the following to try them When you come across other snippet collections, do the following to try them
out: out:
@ -81,7 +82,7 @@
If you place an empty plain text file =.yas-make-groups= inside one If you place an empty plain text file =.yas-make-groups= inside one
of the mode directories, the names of these sub-directories are of the mode directories, the names of these sub-directories are
considered groups of snippets and [[snippet-menu.org][the menu]] is organized much more considered groups of snippets and [[file:snippet-menu.org][the menu]] is organized much more
cleanly: cleanly:
[[./images/menu-groups.png]] [[./images/menu-groups.png]]
@ -108,9 +109,11 @@
Yet another way to create a nice snippet menu is to write into Yet another way to create a nice snippet menu is to write into
=.yas-make-groups= a menu definition. TODO =.yas-make-groups= a menu definition. TODO
* TODO The =.yas-setup.el= file * The =.yas-setup.el= file
** TODO If there is file named =.yas-setup.el= in a mode's snippet
subdirectory, it is loaded along with the snippets. Utility
functions used by the snippets can be put here.
* The =.yas-compiled-snippet.el= file * The =.yas-compiled-snippet.el= file
@ -127,5 +130,3 @@
A =.yas-skip= file in a mode's snippet subdirectory tells YASnippet A =.yas-skip= file in a mode's snippet subdirectory tells YASnippet
not to load snippets from there. not to load snippets from there.
** TODO

View File

@ -1,5 +1,14 @@
nav > ul > li.center > ul { .center { margin-left: auto; margin-right: auto; text-align: center; }
padding: 0; .current {
font-weight: bold;
background-color: #E0E8F0;
}
body { background-color: #E4F0F4 }
div#content {
max-width: 20cm;
margin-left: auto;
margin-right: auto;
} }
nav li { nav li {
@ -9,18 +18,53 @@ nav li {
list-style-type: none; list-style-type: none;
padding: 0.5em; padding: 0.5em;
} }
nav > ul > li { nav > ul > li {
display: inline-block; display: inline-block;
} }
.nopad {
padding: 0;
}
li.border {
border: solid;
border-width: 1px;
}
/* match org's css for <pre> */ pre, code{ background-color: #F3F5F7; }
code { code {
background-color: #F3F5F7; /* http://neugierig.org/software/chromium/notes/2009/09/monospace-fonts-workaround.html */
font-family: courier, monospace; font-family: WorkAroundWebKitAndMozilla, monospace;
white-space: nowrap;
} }
#content { /* Styles for htmlize.el fontification. */
margin-left: 5%;
margin-right: 10%; .org-comment { color: #005000; } /* font-lock-comment-face */
} .org-keyword { font-weight: bold; } /* font-lock-keyword-face */
.org-string { color: #8b0000; } /* font-lock-string-face */
.org-warning { color: #ff8c00;
font-weight: bold; } /* warning */
.org-warning-1 { color: #ff0000;
font-weight: bold; } /* font-lock-warning-face */
.org-preprocessor { color: #483d8b; } /* font-lock-preprocessor-face */
.org-constant { color: #008b8b; } /* font-lock-constant-face */
.org-function-name { color: #0000ff; } /* font-lock-function-name-face */
.org-type { color: #228b22; } /* font-lock-type-face */
.org-variable-name { color: #a0522d; } /* font-lock-variable-name-face */
.org-rst-adornment { color: #a020f0; } /* rst-adornment */
.org-rst-block { color: #a020f0; } /* rst-block */
.org-rst-comment { color: #b22222; } /* rst-comment */
.org-rst-definition { color: #0000ff; } /* rst-definition */
.org-rst-directive { color: #483d8b; } /* rst-directive */
.org-rst-emphasis1 { font-style: italic; } /* rst-emphasis1 */
.org-rst-emphasis2 { font-weight: bold; } /* rst-emphasis2 */
.org-rst-external { color: #228b22; } /* rst-external */
.org-rst-level-1 { background-color: #d9d9d9; } /* rst-level-1 */
.org-rst-level-2 { background-color: #c7c7c7; } /* rst-level-2 */
.org-rst-level-3 { background-color: #b5b5b5; } /* rst-level-3 */
.org-rst-level-4 { background-color: #a3a3a3; } /* rst-level-4 */
.org-rst-level-5 { background-color: #919191; } /* rst-level-5 */
.org-rst-level-6 { background-color: #7f7f7f; } /* rst-level-6 */
.org-rst-literal { color: #8b2252; } /* rst-literal */
.org-rst-reference { color: #a0522d; } /* rst-reference */
.org-rst-transition { color: #a020f0; } /* rst-transition */

View File

@ -1,93 +0,0 @@
@media all
{
body {
margin: 1em auto;
/*margin: 10px 18% 10px 18%;*/
font-family: Arial;
/*text-align: justify;*/
font-size: 14pt;
padding: 10px;
line-height: 1.2em;
max-width: 600pt;
}
div#table-of-contents {
position: fixed;
left: 0%;
right: 0%;
top: 0px;
z-index: 100;
background: black;
}
div#table-of-contents h2 {
display: none;
}
div#table-of-contents a {
text-decoration: none;
color: white;
}
div#table-of-contents a:visited {
color: white;
}
div#table-of-contents a:hover {
color: orange;
}
div.outline-2 h2{
padding-top: 50px;
}
div#text-table-of-contents {
text-color: white;
text-align: center;
margin-left: 30%;
margin-right: 30%;
}
div#text-table-of-contents ul {
height: 2em;
width: 500px;
list-style: none;
margin: auto;
}
div#text-table-of-contents ul li {
float: left;
margin-left:auto;
margin-right: auto;
padding-left: 10px;
}
div#postamble{
position: fixed;
width: 800px;
height: 250px;
left: 50%;
right: 50%;
margin:-75px 0 0 -400px;
bottom: -20px;
font-size: 10pt;
color: grey;
background: url('siscog-bottom-logo.png') no-repeat;
/* background-size: 100% 100%; */
}
div#postamble *{
display: none;
}
div#postamble p.date{
position: relative;
bottom: -200px;
text-align: center;
display: block;
}
}

244
doc/yas-doc-helper.el Executable file → Normal file
View File

@ -1,6 +1,6 @@
;;; yas-doc-helper.el --- Help generate documentation for YASnippet ;;; yas-doc-helper.el --- Help generate documentation for YASnippet -*- lexical-binding: t; -*-
;; Copyright (C) 2012, 2013 Free Software Foundation, Inc. ;; Copyright (C) 2012-2023 Free Software Foundation, Inc.
;; Author: João Távora <joaotavora@gmail.com> ;; Author: João Távora <joaotavora@gmail.com>
;; Keywords: convenience ;; Keywords: convenience
@ -25,127 +25,186 @@
;;; Code: ;;; Code:
(eval-when-compile (eval-when-compile
(require 'cl)) (require 'cl-lib))
(require 'org) (require 'org)
(or (require 'org-publish nil t) (require 'ox-publish)
(require 'ox-publish))
(require 'yasnippet) ; docstrings must be loaded (require 'yasnippet) ; docstrings must be loaded
(defun yas--org-raw-html (tag content) ;; Presumably one of org/ox-publish provided the following vars:
(defvar org-publish-project-alist)
(defvar org-publish-use-timestamps-flag)
(defvar org-export-copy-to-kill-ring)
(defvar org-html-htmlize-output-type)
(defun yas--org-raw-html (tag content &optional attrs)
;; in version 8.0 org-mode changed the export syntax, see ;; in version 8.0 org-mode changed the export syntax, see
;; http://orgmode.org/worg/org-8.0.html#sec-8-1 ;; http://orgmode.org/worg/org-8.0.html#sec-8-1
(format (if (version< org-version "8.0.0") (format (if (version< org-version "8.0.0")
"@<%s>%s@</%s>" ; old: @<tag> "@<%s>%s@</%s>" ; old: @<tag>
"@@html:<%s>@@%s@@html:</%s>@@") ; new: @@html:<tag>@@ "@@html:<%s>@@%s@@html:</%s>@@") ; new: @@html:<tag>@@
tag content tag)) (concat tag (if attrs " ") attrs)
content tag))
(defun yas--document-symbol (symbol level) (defun yas--document-symbol (symbol level)
(flet ((concat-lines (&rest lines) (let* ((stars (make-string level ?*))
(mapconcat #'identity lines "\n"))) (args (and (fboundp symbol)
(let* ((stars (make-string level ?*)) (mapcar #'symbol-name (help-function-arglist symbol t))))
(args (and (fboundp symbol) (heading (cond ((fboundp symbol)
(mapcar #'symbol-name (help-function-arglist symbol t)))) (format
(heading (cond ((fboundp symbol) "%s %s (%s)\n" stars (yas--org-raw-html "code" symbol "class='function'")
(format (mapconcat (lambda (a)
"%s =%s= (%s)" stars symbol (format (if (string-prefix-p "&" a)
(mapconcat (lambda (a) "/%s/" "=%s=")
(format (if (string-prefix-p "&" a) a))
"/%s/" "=%s=") a)) args " ")))
args " "))) (t
(t (format "%s %s\n" stars
(format "%s =%s=\n" stars symbol)))) (yas--org-raw-html "code" symbol "class='variable'")))))
(after-heading (after-heading (format ":PROPERTIES:\n:CUSTOM_ID: %s\n:END:" symbol))
(concat-lines ":PROPERTIES:" (text-quoting-style 'grave)
(format ":CUSTOM_ID: %s" symbol) (body (or (cond ((fboundp symbol)
":END:")) (let ((doc-synth (car-safe (get symbol 'function-documentation))))
(body (or (cond ((fboundp symbol) (if (functionp doc-synth)
(let ((doc-synth (car-safe (get symbol 'function-documentation)))) (funcall doc-synth nil)
(if (functionp doc-synth) (documentation symbol t))))
(funcall doc-synth nil) ((boundp symbol)
(documentation symbol t)))) (documentation-property symbol 'variable-documentation t))
((boundp symbol) (t
(documentation-property symbol 'variable-documentation t)) (format "*WARNING*: no symbol named =%s=" symbol)))
(t (format "*WARNING*: no doc for symbol =%s=" symbol)))
(format "*WARNING*: no symbol named =%s=" symbol))) (case-fold-search nil))
(format "*WARNING*: no doc for symbol =%s=" symbol))) ;; Do some transformations on the body:
(case-fold-search nil)) ;; ARGxxx becomes @<code>arg@</code>xxx
;; do some transformations on the body: ;; FOO becomes /foo/
;; ARGxxx becomes @<code>arg@</code>xxx ;; `bar' becomes [[#bar][=bar=]]
;; FOO becomes /foo/ ;; (...) becomes #+BEGIN_SRC elisp (...) #+END_SRC
;; `bar' becomes [[#bar][=bar=]] ;; Info node `(some-manual) Node Name' becomes
(setq body (replace-regexp-in-string ;; [[https://www.gnu.org/software/emacs/manual/html_node/some-manual/Node-Name.html]
"\\<\\([A-Z][-A-Z0-9]+\\)\\(\\sw+\\)?\\>" ;; [(some-manual) Node Name]]
#'(lambda (match) ;;
(let* ((match1 (match-string 1 match)) ;; This is fairly fragile, though it seems to be working for
(prefix (downcase match1)) ;; now...
(suffix (match-string 2 match)) (setq body (replace-regexp-in-string
(fmt (cond "\\<\\([A-Z][-A-Z0-9]+\\)\\(\\sw+\\)?\\>"
((member prefix args) #'(lambda (match)
(yas--org-raw-html "code" "%s")) (let* ((match1 (match-string 1 match))
((null suffix) "/%s/")))) (prefix (downcase match1))
(if fmt (format fmt prefix) (suffix (match-string 2 match))
match1))) (fmt (cond
body t t 1) ((member prefix args)
body (replace-regexp-in-string (yas--org-raw-html "code" "%s"))
"`\\([a-z-]+\\)'" ((null suffix) "/%s/"))))
#'(lambda (match) (if fmt (format fmt prefix)
(let* ((name (downcase (match-string 1 match))) match1)))
(sym (intern name))) body t t 1)
(if (memq sym yas--exported-syms) body (replace-regexp-in-string
(format "[[#%s][=%s=]]" name name) "\\\\{[^}]+}"
(format "=%s=" name)))) (lambda (match)
body t)) (concat "#+BEGIN_EXAMPLE\n"
;; output the paragraph (substitute-command-keys match)
;; "#+END_EXAMPLE\n"))
(concat-lines heading body t t)
after-heading body (substitute-command-keys body)
body)))) body (replace-regexp-in-string
"Info node `(\\([-a-z]+\\)) \\([A-Za-z0-9 ]+\\)'"
(lambda (match)
(let* ((manual (match-string 1 match))
(node (match-string 2 match))
(html-node (replace-regexp-in-string " " "-" node t t)))
(format "Info node\
[[https://www.gnu.org/software/emacs/manual/html_node/%s/%s.html][(%s) %s]]"
manual html-node manual node)))
body t t)
body (replace-regexp-in-string
"`\\([-a-z]+\\)'"
#'(lambda (match)
(let* ((name (downcase (match-string 1 match)))
(sym (intern-soft name)))
(if (memq sym yas--exported-syms)
(format "[[#%s][=%s=]]" name name)
(format "=%s=" name))))
body t t)
body (replace-regexp-in-string
"\n\n +(.+\\(?:\n +.+\\)*"
(lambda (match)
(concat "\n#+BEGIN_SRC elisp\n"
match
"\n#+END_SRC\n"))
body t t))
;; output the paragraph
(concat heading after-heading "\n" body)))
(defun yas--document-symbols (level &rest names-and-predicates) (defun yas--document-symbols (level &rest names-and-predicates)
(let ((sym-lists (make-vector (length names-and-predicates) nil)) (let ((sym-lists (make-vector (length names-and-predicates) nil))
(stars (make-string level ?*))) (stars (make-string level ?*)))
(loop for sym in yas--exported-syms (cl-loop for sym in yas--exported-syms
do (loop for test in (mapcar #'cdr names-and-predicates) do (cl-loop for test in (mapcar #'cdr names-and-predicates)
for i from 0 for i from 0
do (when (funcall test sym) do (when (funcall test sym)
(push sym (aref sym-lists i)) (push sym (aref sym-lists i))
(return)))) (cl-return))))
(loop for slist across sym-lists (cl-loop for slist across sym-lists
for name in (mapcar #'car names-and-predicates) for name in (mapcar #'car names-and-predicates)
concat (format "\n%s %s\n" stars name) concat (format "\n%s %s\n" stars name)
concat (mapconcat (lambda (sym) concat (mapconcat (lambda (sym)
(yas--document-symbol sym (1+ level))) (yas--document-symbol sym (1+ level)))
slist "\n\n")))) slist "\n\n"))))
(defun yas--internal-link-snippet () (defun yas--internal-link-snippet ()
(interactive) (interactive)
(yas-expand-snippet "[[#$1][=${1:`yas/selected-text`}=]]")) (yas-expand-snippet "[[#$1][=${1:`yas/selected-text`}=]]"))
(define-key org-mode-map [M-f8] 'yas--internal-link-snippet) (define-key org-mode-map [M-f8] #'yas--internal-link-snippet)
;; This lets all the org files be exported to HTML with ;; This lets all the org files be exported to HTML with
;; `org-publish-current-project' (C-c C-e P). ;; `org-publish-current-project' (C-c C-e P).
(defun yas--make-preamble (props)
"Return contents of nav-menu-html.inc.
But replace link to \"current\" page with a span element."
(with-temp-buffer
(let ((dir (file-name-directory (plist-get props :input-file))))
(insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
(goto-char (point-min))
(search-forward (concat "<a href=\""
(file-name-nondirectory
(plist-get props :output-file))
"\">"))
(replace-match "<span class='current'>")
(search-forward "</a>")
(replace-match "</span>")
(buffer-string))))
(let* ((dir (if load-file-name (file-name-directory load-file-name) (let* ((dir (if load-file-name (file-name-directory load-file-name)
default-directory)) default-directory))
(rev (with-temp-file (expand-file-name "html-revision" dir) (src-epoch (getenv "SOURCE_DATE_EPOCH"))
(or (when (eq (call-process "git" nil t nil ;; Presence of SOURCE_DATE_EPOCH indicates a reproducible
"rev-parse" "--verify" "HEAD") 0) ;; build, don't depend on git.
(buffer-string)) (rev (unless src-epoch
(princ yas--version (current-buffer))))) (ignore-errors
(car (process-lines "git" "describe" "--dirty")))))
(date (format-time-string
"(%Y-%m-%d %H:%M:%S)"
(seconds-to-time
(string-to-number
(or (if rev (car (process-lines "git" "show" "--format=%ct"))
src-epoch)
"0")))
t))
(proj-plist (proj-plist
`(,@(when (fboundp 'org-html-publish-to-html) `(,@(when (fboundp 'org-html-publish-to-html)
'(:publishing-function org-html-publish-to-html)) '(:publishing-function org-html-publish-to-html))
:base-directory ,dir :publishing-directory ,dir :base-directory ,dir :publishing-directory ,dir
:html-preamble :html-preamble yas--make-preamble
,(with-temp-buffer ;;:with-broken-links mark
(insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
(buffer-string))
:html-postamble :html-postamble
,(concat "<hr><p class='creator'>Generated by %c on %d from " ,(concat "<hr><p class='creator'>Generated by %c from "
rev "</p>\n" rev " " date "</p>\n"
"<p class='xhtml-validation'>%v</p>\n"))) "<p class='xhtml-validation'>%v</p>\n")))
(project (assoc "yasnippet" org-publish-project-alist))) (project (assoc "yasnippet" org-publish-project-alist)))
(when rev ;; Rakefile :doc:upload uses "html-revision".
(with-temp-file (expand-file-name "html-revision" dir)
(princ rev (current-buffer))))
(if project (if project
(setcdr project proj-plist) (setcdr project proj-plist)
(push `("yasnippet" . ,proj-plist) (push `("yasnippet" . ,proj-plist)
@ -155,7 +214,8 @@
(let ((org-publish-use-timestamps-flag nil) (let ((org-publish-use-timestamps-flag nil)
(org-export-copy-to-kill-ring nil) (org-export-copy-to-kill-ring nil)
(org-confirm-babel-evaluate nil) (org-confirm-babel-evaluate nil)
(make-backup-files nil)) (make-backup-files nil)
(org-html-htmlize-output-type 'css))
(org-publish "yasnippet" 'force))) (org-publish "yasnippet" 'force)))

@ -1 +0,0 @@
Subproject commit 3f3ff6f642d100bfcf093d282603f9fc0088cfe5

@ -1 +0,0 @@
Subproject commit 0543618bd34a6715918992f01161c118f136bb37

View File

@ -1,8 +1,8 @@
;;; yasnippet-debug.el --- debug functions for yasnippet ;;; yasnippet-debug.el --- debug functions for yasnippet -*- lexical-binding: t -*-
;; Copyright (C) 2010, 2013, 2014 Free Software Foundation, Inc. ;; Copyright (C) 2010-2025 Free Software Foundation, Inc.
;; Author: João Távora ;; Author: João Távora
;; Keywords: emulations, convenience ;; Keywords: emulations, convenience
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -20,114 +20,335 @@
;;; Commentary: ;;; Commentary:
;; Just some debug functions ;; Some debug functions. When loaded from the command line, provides
;; quick way to test out snippets in a fresh Emacs instance.
;;
;; emacs -Q -l yasnippet-debug [-v[v]]
;; [-M:<modename>] [-M.<filext>] [-S:[<snippet-file|name>]]
;; [-- <more-arguments-passed-to-Emacs>...]
;;
;; See the source in `yas-debug-process-command-line' for meaning of
;; args.
;;
;;; Code: ;;; Code:
(require 'yasnippet) (defconst yas--loaddir
(require 'cl) (file-name-directory (or load-file-name buffer-file-name))
"Directory that yasnippet was loaded from.")
(defun yas-debug-snippet-vars () (require 'yasnippet (if (boundp 'yas--loaddir)
"Debug snippets, fields, mirrors and the `buffer-undo-list'." ;; Don't require '-L <path>' when debugging.
(interactive) (expand-file-name "yasnippet" yas--loaddir)))
(with-output-to-temp-buffer "*YASnippet trace*" (require 'cl-lib)
(princ "Interesting YASnippet vars: \n\n") (require 'color nil t)
(require 'edebug)
(eval-when-compile
(require 'subr-x nil t)
(cond ((fboundp 'when-let*) nil) ; Introduced in 26.
((fboundp 'when-let) ; Introduced in 25.1,
(defalias 'when-let* 'when-let)) ; deprecated in 26.
(t (defmacro when-let* (key-vals &rest body)
(declare (indent 1) (debug ((symbolp form) body)))
(let ((key-val (pop key-vals)))
(if key-val
`(let ((,(car key-val) ,(cadr key-val)))
(if ,(car key-val)
(when-let* ,key-vals
,@body)))
`(progn ,@body)))))))
(princ (format "\nPost command hook: %s\n" post-command-hook)) (defvar yas-debug-live-indicators
(princ (format "\nPre command hook: %s\n" pre-command-hook)) (make-hash-table :test #'eq))
(princ (format "%s live snippets in total\n" (length (yas--snippets-at-point (quote all-snippets))))) (defun yas-debug-live-colors ()
(princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max))))) (let ((colors ()))
(princ (format "%s live snippets at point:\n\n" (length (yas--snippets-at-point)))) (maphash (lambda (_k v) (push (nth 1 (car v)) colors)) yas-debug-live-indicators)
colors))
(defvar yas-debug-recently-live-indicators)
(defun yas-debug-get-live-indicator (location)
(require 'color)
(when (boundp 'yas-debug-recently-live-indicators)
(push location yas-debug-recently-live-indicators))
(let (beg end)
(if (markerp location)
(setq beg (setq end (marker-position location)))
(setq beg (yas-debug-ov-fom-start location)
end (yas-debug-ov-fom-end location)))
(or (when-let* ((color-ov (gethash location yas-debug-live-indicators)))
(if (and beg end) (move-overlay (cdr color-ov) beg end)
(delete-overlay (cdr color-ov)))
color-ov)
(let* ((live-colors (yas-debug-live-colors))
(color
(cl-loop with best-color = nil with max-dist = -1
for color = (format "#%06X" (random #x1000000))
for comp = (if (fboundp 'color-complement)
(apply #'color-rgb-to-hex (color-complement color))
color)
if (< (color-distance color (face-foreground 'default))
(color-distance comp (face-foreground 'default)))
do (setq color comp)
for dist = (cl-loop for c in live-colors
minimize (color-distance c color))
if (or (not live-colors) (> dist max-dist))
do (setq best-color color) (setq max-dist dist)
repeat (if live-colors 100 1)
finally return `(:background ,best-color)))
(ov (make-overlay beg end)))
(if (markerp location)
(overlay-put ov 'before-string (propertize "" 'face color))
(overlay-put ov 'before-string (propertize "" 'face color))
(overlay-put ov 'after-string (propertize "" 'face color)))
(puthash location (cons color ov) yas-debug-live-indicators)))))
(defun yas-debug-live-marker (marker)
(let* ((color-ov (yas-debug-get-live-indicator marker))
(color (car color-ov))
(ov (cdr color-ov))
(decorator (overlay-get ov 'before-string))
(str (format "at %d" (+ marker))))
(if (markerp marker)
(propertize str
'cursor-sensor-functions
`(,(lambda (_window _oldpos dir)
(overlay-put
ov 'before-string
(propertize decorator
'face (if (eq dir 'entered)
'mode-line-highlight color)))))
'face color)
str)))
(defun yas-debug-ov-fom-start (ovfom)
(cond ((overlayp ovfom) (overlay-start ovfom))
((integerp ovfom) ovfom)
(t (yas--fom-start ovfom))))
(defun yas-debug-ov-fom-end (ovfom)
(cond ((overlayp ovfom) (overlay-end ovfom))
((integerp ovfom) ovfom)
(t (yas--fom-end ovfom))))
(defun yas-debug-live-range (range)
(let* ((color-ov (yas-debug-get-live-indicator range))
(color (car color-ov))
(ov (cdr color-ov))
(decorator-beg (overlay-get ov 'before-string))
(decorator-end (overlay-get ov 'after-string))
(beg (yas-debug-ov-fom-start range))
(end (yas-debug-ov-fom-end range)))
(if (and beg end (or (overlayp range)
(and (not (integerp beg))
(not (integerp end)))))
(propertize (format "from %d to %d" (+ beg) (+ end))
'cursor-sensor-functions
`(,(lambda (_window _oldpos dir)
(let ((face (if (eq dir 'entered)
'mode-line-highlight color)))
(overlay-put ov 'before-string
(propertize decorator-beg 'face face))
(overlay-put ov 'after-string
(propertize decorator-end 'face face)))))
'face color)
"<dead>")))
(defmacro yas-debug-with-tracebuf (outbuf &rest body)
(declare (indent 1) (debug (sexp body)))
(let ((tracebuf-var (make-symbol "tracebuf")))
`(let ((,tracebuf-var (or ,outbuf (get-buffer-create "*YASnippet trace*"))))
(unless (eq ,tracebuf-var (current-buffer))
(cl-flet ((printf (fmt &rest args)
(with-current-buffer ,tracebuf-var
(insert (apply #'format fmt args)))))
(unless ,outbuf
(with-current-buffer ,tracebuf-var
(erase-buffer)
(when (fboundp 'cursor-sensor-mode)
(cursor-sensor-mode +1))
(setq truncate-lines t)))
(setq ,outbuf ,tracebuf-var)
(save-restriction
(widen)
,@body))))))
(dolist (snippet (yas--snippets-at-point)) (defun yas-debug-snippet (snippet &optional outbuf)
(princ (format "\tsid: %d control overlay from %d to %d\n" (yas-debug-with-tracebuf outbuf
(yas--snippet-id snippet) (when-let* ((overlay (yas--snippet-control-overlay snippet)))
(overlay-start (yas--snippet-control-overlay snippet)) (printf "\tsid: %d control overlay %s\n"
(overlay-end (yas--snippet-control-overlay snippet)))) (yas--snippet-id snippet)
(princ (format "\tactive field: %s from %s to %s covering \"%s\"\n" (yas-debug-live-range overlay)))
(yas--field-number (yas--snippet-active-field snippet)) (when-let* ((active-field (yas--snippet-active-field snippet)))
(marker-position (yas--field-start (yas--snippet-active-field snippet))) (unless (consp (yas--field-start active-field))
(marker-position (yas--field-end (yas--snippet-active-field snippet))) (printf "\tactive field: #%d %s %s covering \"%s\"\n"
(buffer-substring-no-properties (yas--field-start (yas--snippet-active-field snippet)) (yas--field-end (yas--snippet-active-field snippet))))) (or (yas--field-number active-field) -1)
(when (yas--snippet-exit snippet) (if (yas--field-modified-p active-field) "**" "--")
(princ (format "\tsnippet-exit: at %s next: %s\n" (yas-debug-live-range active-field)
(yas--exit-marker (yas--snippet-exit snippet)) (buffer-substring-no-properties (yas--field-start active-field) (yas--field-end active-field)))))
(yas--exit-next (yas--snippet-exit snippet))))) (when-let* ((exit (yas--snippet-exit snippet)))
(dolist (field (yas--snippet-fields snippet)) (printf "\tsnippet-exit: %s next: %s\n"
(princ (format "\tfield: %s from %s to %s covering \"%s\" next: %s%s\n" (yas-debug-live-marker (yas--exit-marker exit))
(yas--field-number field) (yas--exit-next exit)))
(marker-position (yas--field-start field)) (dolist (field (yas--snippet-fields snippet))
(marker-position (yas--field-end field)) (unless (consp (yas--field-start field))
(buffer-substring-no-properties (yas--field-start field) (yas--field-end field)) (printf "\tfield: %d %s %s covering \"%s\" next: %s%s\n"
(yas--debug-format-fom-concise (yas--field-next field)) (or (yas--field-number field) -1)
(if (yas--field-parent-field field) "(has a parent)" ""))) (if (yas--field-modified-p field) "**" "--")
(dolist (mirror (yas--field-mirrors field)) (yas-debug-live-range field)
(princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n" (buffer-substring-no-properties (yas--field-start field) (yas--field-end field))
(marker-position (yas--mirror-start mirror)) (yas--debug-format-fom-concise (yas--field-next field))
(marker-position (yas--mirror-end mirror)) (if (yas--field-parent-field field)
(buffer-substring-no-properties (yas--mirror-start mirror) (yas--mirror-end mirror)) (format " parent: %s"
(yas--debug-format-fom-concise (yas--mirror-next mirror))))))) (yas--debug-format-fom-concise
(yas--field-parent-field field)))
"")))
(dolist (mirror (yas--field-mirrors field))
(unless (consp (yas--mirror-start mirror))
(printf "\t\tmirror: %s covering \"%s\" next: %s\n"
(yas-debug-live-range mirror)
(buffer-substring-no-properties (yas--mirror-start mirror) (yas--mirror-end mirror))
(yas--debug-format-fom-concise (yas--mirror-next mirror))))))))
(princ (format "\nUndo is %s and point-max is %s.\n" (defvar yas-debug-target-buffer nil)
(if (eq buffer-undo-list t) (defvar yas-debug-target-snippets nil nil)
"DISABLED" (make-variable-buffer-local 'yas-debug-target-snippets)
"ENABLED")
(point-max))) (defvar yas-debug-undo nil)
(unless (eq buffer-undo-list t)
(princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list))) (defun yas-toggle-debug-undo (value)
(let ((first-ten (subseq buffer-undo-list 0 (min 19 (interactive (list (not yas-debug-undo)))
(length buffer-undo-list))))) (setq yas-debug-undo value)
(dolist (undo-elem first-ten) (yas--message 3 "debug undo %sabled" (if yas-debug-undo "en" "dis")))
(princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
(defun yas-debug--target-snippet (snippet)
(add-to-list 'yas-debug-target-snippets snippet))
(defun yas-debug--untarget-snippet (snippet)
(setq yas-debug-target-snippets
(remq snippet yas-debug-target-snippets))
(maphash (lambda (_k color-ov)
(delete-overlay (cdr color-ov)))
yas-debug-live-indicators)
(clrhash yas-debug-live-indicators))
(defun yas-debug-snippets (&optional outbuf hook)
"Print debug information on active snippets to buffer OUTBUF.
If OUTBUF is nil, use a buffer named \"*YASsnippet trace*\".
If HOOK is non-nil, install `yas-debug-snippets' in
`post-command-hook' to update the information on every command
after this one. If it is `snippet-navigation' then install hook
buffer-locally, otherwise install it globally. If HOOK is
`edebug-create', also instrument the function
`yas--snippet-parse-create' with `edebug' and show its source."
(interactive (list nil t))
(condition-case err
(yas-debug-with-tracebuf outbuf
(unless (buffer-live-p yas-debug-target-buffer)
(setq yas-debug-target-buffer nil))
(with-current-buffer (or yas-debug-target-buffer (current-buffer))
(when yas-debug-target-snippets
(setq yas-debug-target-snippets
(cl-delete-if-not #'yas--snippet-p yas-debug-target-snippets)))
(let ((yas-debug-recently-live-indicators nil))
(printf "(length yas--snippets-snippets) => %d\n"
(length yas--active-snippets))
(dolist (snippet (or yas-debug-target-snippets
(yas-active-snippets)))
(printf "snippet %d\n" (yas--snippet-id snippet))
(yas-debug-snippet snippet outbuf))
(maphash (lambda (loc color-ov)
(unless (memq loc yas-debug-recently-live-indicators)
(delete-overlay (cdr color-ov))
(remhash loc yas-debug-live-indicators)))
yas-debug-live-indicators))
(when (and yas-debug-undo (listp buffer-undo-list))
(printf "Undo list has %s elements:\n" (length buffer-undo-list))
(cl-loop for undo-elem in buffer-undo-list
do (printf "%S\n" undo-elem))))
(when hook
(setq yas-debug-target-buffer (current-buffer))
(advice-add 'yas--snippet-parse-create :before #'yas-debug--target-snippet)
(advice-add 'yas--commit-snippet :after #'yas-debug--untarget-snippet)
(add-hook 'post-command-hook #'yas-debug-snippets
nil (eq hook 'snippet-navigation))
;; Window management is slapped together, it does what I
;; want when the caller has a single window open. Good
;; enough for now.
(when (eq hook 'edebug-create)
(edebug-instrument-function 'yas--snippet-parse-create)
(let ((buf-point (find-function-noselect 'yas--snippet-parse-create)))
(with-current-buffer (car buf-point)
(goto-char (cdr buf-point)))))
outbuf))
((debug error) (signal (car err) (cdr err)))))
(defun yas-debug-snippet-create ()
(yas-debug-snippets nil 'create))
(defun yas--debug-format-fom-concise (fom) (defun yas--debug-format-fom-concise (fom)
(when fom (when fom
(cond ((yas--field-p fom) (cond ((yas--field-p fom)
(format "field %s from %d to %d" (format "field %s from %d to %d"
(yas--field-number fom) (yas--field-number fom)
(marker-position (yas--field-start fom)) (+ (yas--field-start fom))
(marker-position (yas--field-end fom)))) (+ (yas--field-end fom))))
((yas--mirror-p fom) ((yas--mirror-p fom)
(format "mirror from %d to %d" (format "mirror from %d to %d"
(marker-position (yas--mirror-start fom)) (+ (yas--mirror-start fom))
(marker-position (yas--mirror-end fom)))) (+ (yas--mirror-end fom))))
(t (t
(format "snippet exit at %d" (format "snippet exit at %d"
(marker-position (yas--fom-start fom))))))) (+ (yas--fom-start fom)))))))
(defun yas-debug-process-command-line (&optional options)
"Implement command line processing."
(setq yas-verbosity 99)
(setq yas-triggers-in-field t)
(setq debug-on-error t)
(let* ((snippet-mode 'fundamental-mode)
(snippet-key nil))
(unless options
(setq options (cl-loop for opt = (pop command-line-args-left)
while (and opt (not (equal opt "--"))
(string-prefix-p "-" opt))
collect opt)))
(when-let* ((mode (cl-member "-M:" options :test #'string-prefix-p)))
(setq snippet-mode (intern (concat (substring (car mode) 3) "-mode"))))
(when-let* ((mode (cl-member "-M." options :test #'string-prefix-p)))
(setq snippet-mode
(cdr (cl-assoc (substring (car mode) 2) auto-mode-alist
:test (lambda (ext regexp) (string-match-p regexp ext))))))
(switch-to-buffer (get-buffer-create "*yas test*"))
(funcall snippet-mode)
(when-let* ((snippet-file (cl-member "-S:" options :test #'string-prefix-p)))
(setq snippet-file (substring (car snippet-file) 3))
(if (file-exists-p snippet-file)
(with-temp-buffer
(insert-file-contents snippet-file)
(let ((snippet-deflist (yas--parse-template snippet-file)))
(yas-define-snippets snippet-mode (list snippet-deflist))
(setq snippet-key (car snippet-deflist))))
(yas-reload-all)
(let ((template (yas--lookup-snippet-1 snippet-file snippet-mode)))
(if template
(setq snippet-key (yas--template-key template))
(error "No such snippet `%s'" snippet-file)))))
(display-buffer (find-file-noselect
(expand-file-name "yasnippet.el" yas--loaddir)))
(when-let* ((verbosity (car (or (member "-v" options) (member "-vv" options)))))
(set-window-buffer
(split-window) (yas-debug-snippets
nil (if (equal verbosity "-vv") 'edebug-create t))))
(yas-minor-mode +1)
(when snippet-key (insert snippet-key))))
(defun yas-exterminate-package () (when command-line-args-left
(interactive) (yas-debug-process-command-line))
(yas-global-mode -1)
(yas-minor-mode -1)
(mapatoms #'(lambda (atom)
(when (string-match "yas[-/]" (symbol-name atom))
(unintern atom obarray)))))
(defun yas-debug-test (&optional quiet)
(interactive "P")
(yas-load-directory (or (and (listp yas-snippet-dirs)
(first yas-snippet-dirs))
yas-snippet-dirs
"~/Source/yasnippet/snippets/"))
(set-buffer (switch-to-buffer "*YAS TEST*"))
(mapc #'yas--commit-snippet (yas--snippets-at-point 'all-snippets))
(erase-buffer)
(setq buffer-undo-list nil)
(setq undo-in-progress nil)
(snippet-mode)
(yas-minor-mode 1)
(let ((abbrev))
(setq abbrev "$f")
(insert abbrev))
(unless quiet
(add-hook 'post-command-hook 'yas-debug-snippet-vars 't 'local)))
(provide 'yasnippet-debug) (provide 'yasnippet-debug)
;; Local Variables: ;; Local Variables:
;; indent-tabs-mode: nil ;; indent-tabs-mode: nil
;; byte-compile-warnings: (not cl-functions) ;; autoload-compute-prefixes: nil
;; End: ;; End:
;;; yasnippet-debug.el ends here ;;; yasnippet-debug.el ends here

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff