Compare commits

...

225 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
23 changed files with 3517 additions and 1820 deletions

4
.gitignore vendored
View File

@ -9,3 +9,7 @@ extras/imported/**
*.elc
ert-x.*
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,13 +1,25 @@
language: generic
sudo: false
os: linux
dist: xenial
git:
submodules: false
env:
global:
- Wlexical=t
- Werror=t
- tests_Werror=t # For yasnippet-tests.el
jobs:
- EMACS_VERSION=23.4
- EMACS_VERSION=24.3
# 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-prerelease
- EMACS_VERSION=25.3
- EMACS_VERSION=26.3
- EMACS_VERSION=27-prerelease
install:
- curl -LO https://github.com/npostavs/emacs-travis/releases/download/bins/emacs-bin-${EMACS_VERSION}.tar.gz
@ -15,7 +27,7 @@ install:
# Configure $PATH: Emacs installed to /tmp/emacs
- 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.5.el ;
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
@ -25,7 +37,9 @@ install:
- emacs --version
script:
- rake compile
- rake yasnippet.elc
- rake yasnippet-debug.elc
- rake yasnippet-tests.elc Werror=$tests_Werror
- rake tests
notifications:

View File

@ -1,4 +1,8 @@
# Submitting Bug Reports
# Submitting Bug Reports or Patches
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
[Github issue tracker][issues].
Please read [Important note regarding bug reporting][bugnote].
@ -13,17 +17,21 @@ for Emacs also covers Yasnippet.
## Commit message format
The commit message format roughly follows Emacs conventions, although
there is no separate Changelog file.
The commit message format roughly follows Emacs conventions. There is
no separate Changelog file.
The commit message's first sentence should be capitalized, no period
Capitalize the first sentence, no period at the end
It may be followed by a paragraph with a longer explanation. The
changelog style entry goes at the end of the message.
* foo.el (a-function): Terse summary of per-function changes.
Please make sure the summary line can be understood without having
to lookup bug numbers. It may be followed by a paragraph with a
longer explanation. The changelog style entry goes at the end of
the message.
* 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
(the `* foo.el ...` part) is fine.
(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

255
NEWS
View File

@ -1,10 +1,261 @@
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.
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.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

View File

@ -15,7 +15,7 @@ YASnippet. Watch [a demo on YouTube][youtube-demo].
# Installation
## Install the most recent version
## Manual install from Git
Clone this repository somewhere
@ -33,12 +33,16 @@ Add your own snippets to `~/.emacs.d/snippets` by placing files there or invokin
## Install with `package-install`
In a recent emacs `M-x list-packages` is the recommended way to list and install packages.
[MELPA][melpa] keeps a very recent snapshot of YASnippet, see http://melpa.org/#installing.
In a recent emacs `M-x list-packages` is the recommended way to list
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
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.
## Use `yas-minor-mode` on a per-buffer basis
@ -55,33 +59,22 @@ where you want YASnippet enabled.
<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!
If you git-cloned yasnippet with the `--recursive` option you'll also
download "git submodules" and find two subdirs under the main tree.
1. `snippets/`
Points to [yasnippet-snippets] the snippet collection of
1. [yasnippet-snippets] - a snippet collection package maintained by
[AndreaCrotti](https://github.com/AndreaCrotti).
The default configuraiton already points to this dir, so to use
them, just make sure the submodule really was downloaded
(i.e. there are some files under `snippets/`)
It can be installed with `M-x package-install RET
yasnippet-snippets` if you have added MELPA to your package
sources.
2. `yasmate/`
Points to a github repo of the [yasmate] tool, which is dedicated
to converting textmate bundles into yasnippet snippets.
2. [yasmate] a tool which is dedicated to converting textmate bundles
into yasnippet snippets.
To use these snippets you have to run the tool first, so
[see its doc][yasmate]), and then point the `yas-snippet-dirs`
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]
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
"/path/to/some/collection/" ;; foo-mode and bar-mode snippet 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.
# Manual, issues etc
Please refer to the comprehensive [documentation][docs] for full
customisation and support. If you find a bug in the code or in the
documentation, please report it on [the GitHub issue tracker][issues].
There's comprehensive [documentation][docs] on using and customising
YASnippet.
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
@ -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
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!
[docs]: http://joaotavora.github.io/yasnippet/
[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
[forum]: http://groups.google.com/group/smart-snippet
[melpa]: http://melpa.milkbox.net/
[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
[yasnippet-snippets]: http://github.com/AndreaCrotti/yasnippet-snippets

116
Rakefile
View File

@ -1,116 +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, [:htmlize] do |t, args|
load_path = '-L .'
if args[:htmlize]
load_path += " -L #{args[:htmlize]}"
end
sh "#{$EMACS} -Q #{load_path} --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|
set_warnings = ""
if ENV['warnings']
set_warnings = " --eval \"(setq byte-compile-warnings #{ENV['warnings']})\""
end
sh "#{$EMACS} --batch -L . --eval \"(setq byte-compile-error-on-warn t)\"" +
"#{set_warnings} -f batch-byte-compile #{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
- *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?
If you have a newline at the end of the snippet definition file, then
YASnippet will add a newline when you expanding a snippet. Please don't
add a newline at the end if you don't want it when you saving the
snippet file.
If there is a newline at the end of a snippet definition file,
YASnippet will add a newline when expanding that snippet. When editing
or saving a snippet file, please be careful not to accidentally add a
terminal newline.
Note some editors will automatically add a newline for you. In Emacs, if
you set =require-final-newline= to =t=, it will add the final newline
for you 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=).
Note that some editors will automatically add a newline for you. In
Emacs, if you set =require-final-newline= to =t=, it will add the
final newline automatically.
* Why doesn't TAB navigation work with flyspell
A workaround is to inhibit flyspell overlays while the snippet is
active:
This is [[https://debbugs.gnu.org/26672][Emacs Bug#26672]], so you should upgrade to version 25.3 or
better. Otherwise, a workaround is to inhibit flyspell overlays while
the snippet is active:
#+BEGIN_SRC emacs-lisp
(add-hook 'flyspell-incorrect-hook
#'(lambda (dummy1 dummy2 dymmy3)
#'(lambda (&rest _)
(and yas-active-field-overlay
(overlay-buffer yas-active-field-overlay))))
#+END_SRC
This is apparently related to overlay priorities. For some reason, the
=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 do I use alternative keys, i.e. not TAB?
* 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:
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
if you want to respect [[sym:yas-keymap-disable-hook][=yas-keymap-disable-hook=]]:
#+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 "<the new key>") 'yas-expand)
(define-key yas-minor-mode-map (kbd "<the new key>") yas-maybe-expand)
;;keys for navigation
(define-key yas-keymap [(tab)] nil)
(define-key yas-keymap (kbd "TAB") nil)
(define-key yas-keymap [(shift tab)] 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-prev-field-key>") 'yas-prev)
(define-key yas-keymap (kbd "<new-next-field-key>")
(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
* 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?
- *Note*: This question applies if you're still defining snippets

View File

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

View File

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

View File

@ -8,7 +8,7 @@
There are some ways you can quickly find a snippet file or create a new one:
- =M-x yas-new-snippet=, key bindind: =C-c & C-n=
- =M-x yas-new-snippet=, key binding: =C-c & C-n=
Creates a new buffer with a template for making a new snippet. The
buffer is in =snippet-mode= (see [[snippet-mode][below]]). When you are done editing
@ -62,7 +62,7 @@ expanded.
Optionally, if the file contains a line of =# --=, the lines above it
count as comments, some of which can be /directives/ (or meta data).
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.
Here's a typical example:
@ -80,7 +80,7 @@ Here's a list of currently supported directives:
This is the probably the most important directive, it's the
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.
** =# name:= snippet name
@ -89,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 --
especially distinguishable among similar snippets.
If you omit this name it will default to the file name the snippet was
loaded from.
If you omit this name, it will default to the file name the snippet
was loaded from.
** =# 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
non-nil value.
@ -113,14 +113,14 @@ achieved by grouping snippets into sub-directories and using the
=.yas-make-groups= special file (for this see
[[./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.
=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.
** =# 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
used to override variable values while the snippet is being expanded.
@ -154,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
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
same snippet, for example in this "html-mode" snippet.
same snippet, for example in this =html-mode= snippet.
#+BEGIN_SRC snippet
# name: <p>...</p>
@ -172,7 +172,7 @@ will expand the paragraph tag without newlines.
** =# type:= =snippet= or =command=
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.
If it's =snippet= (the default when there is no =type= directive), the
@ -202,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
escaped as =\\= sometimes.
** Embedded Emacs-lisp code
** Embedded Emacs Lisp code
Emacs-Lisp code can be embedded inside the template, written inside
back-quotes (=`=). The lisp forms are evaluated when the snippet is
Emacs Lisp code can be embedded inside the template, written inside
back-quotes (=`=). The Lisp forms are evaluated when the snippet is
being expanded. The evaluation is done in the same buffer as the
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:
#+BEGIN_SRC snippet
@ -221,8 +221,8 @@ dynamically:
#endif /* $1 */
#+END_SRC
From version 0.6, snippets expansions are run with some special
Emacs-lisp variables bound. One of this is [[sym:yas-selected-text][=yas-selected-text=]]. You can
From version 0.6, snippet expansions are run with some special
Emacs Lisp variables bound. One of these is [[sym:yas-selected-text][=yas-selected-text=]]. You can
therefore define a snippet like:
#+BEGIN_SRC snippet
@ -237,7 +237,7 @@ Alternatively, you can also customize the variable
*** Note: backquote expressions should not modify the buffer
Please note that the lisp forms in backquotes should *not* modify the
Please note that the Lisp forms in backquotes should *not* modify the
buffer, doing so will trigger a warning. For example, instead of
doing
@ -277,16 +277,16 @@ like this:
${N:default value}
#+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.
The number can be omitted if you don't want to create [[mirrors-fields][mirrors]] or
[[mirror-transformations][transformations]] for this field.
** Mirrors <<mirrors-fields>>
We refer the tab stops with placeholders as a /field/. A field can have
mirrors. Its mirrors will get updated when you change the text of a
field. Here's an example:
We refer to tab stops with placeholders as a /field/. A field can
have mirrors. *All* mirrors get updated whenever you update any field
text. Here's an example:
#+BEGIN_SRC snippet
\begin{${1:enumerate}}
@ -299,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]]).
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
the field and others mirrors.
none of the tab stops have an initial value, the first one is selected as
the field and the others are its mirrors.
** Mirrors with transformations <<mirror-transformations>>
If the value of an =${n:=-construct starts with and contains =$(=,
then it is interpreted as a mirror for field =n= with a
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
content (string) contained in the field =n=. Here's an example for
Objective-C:
@ -362,12 +362,26 @@ is not. Here's an snippet for rst title:
$0
#+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
From version 0.6 on, you can also have lisp transformation inside
fields. These work mostly mirror transformations but are evaluated when
you first enter the field, after each change you make to the field and
also just before you exit the field.
From version 0.6 on, you can also have Lisp transformation inside
fields. These work mostly like mirror transformations. However, they
are evaluated when you first enter the field, after each change you
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
distinguish between fields and mirrors. In the following example
@ -398,25 +412,38 @@ the field, and with some useful variables bound, notably
can place a transformation in the primary field that lets you select
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
<div align="${2:$$(yas-choose-value '("right" "center" "left"))}">
<div align="${2:$$(yas-completing-read "Alignment? " '("right" "center" "left"))}">
$0
</div>
#+END_SRC
See the definition of [[sym:yas-choose-value][=yas-choose-value=]] to see how it was written using
the two variables.
See the definition of [[sym:yas-choose-value][=yas-completing-read=]] to see how it was written
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.
#+BEGIN_SRC snippet
\section{${1:"Titel der Tour"}}%
\index{$1}%
\label{{2:"waiting for reftex-label call..."$(unless yas-modified-p (reftex-label nil 'dont-
insert))}}%
\label{{2:"waiting for reftex-label call..."$(unless yas-modified-p (reftex-label nil 'dont-insert))}}%
#+END_SRC
The function [[sym:yas-verify-value][=yas-verify-value=]] has another neat trick, and makes use
@ -431,7 +458,7 @@ From version 0.6 on, you can also have nested placeholders of the type:
#+END_SRC
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=
(which executes [[sym:yas-skip-and-clear-or-delete-char][=yas-skip-and-clear-or-delete-char=]]) and go straight to
the exit marker.

View File

@ -21,7 +21,7 @@
- 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=).
- Use m2m's excellent auto-complete
@ -32,17 +32,33 @@
** Trigger key
[[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
=<tab>= by default, however, you can freely set it to some other key:
When [[sym:yas-minor-mode][=yas-minor-mode=]] is enabled, it binds [[sym:yas-maybe-expand][=yas-maybe-expand=]] to =TAB=
and =<tab>= by default, however, you can freely remove those bindings:
#+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 "<the new key>") 'yas-expand)
#+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
command [[sym:yas-global-mode][=yas-global-mode=]]. This will enable a modeline indicator,
=yas=:
@ -50,28 +66,18 @@ command [[sym:yas-global-mode][=yas-global-mode=]]. This will enable a modeline
[[./images/minor-mode-indicator.png]]
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
[[sym:yas-dont-active][=yas-dont-active=]] in the buffer's mode hook.
YASnippet in some buffers by calling [[sym:yas-minor-mode][=yas-minor-mode=]] with a negative
argument in the buffer's mode hook.
*** Fallback behaviour
[[sym:yas-fallback-behaviour][=yas-fallback-behaviour=]] is a customization variable bound to
'=call-other-command= by default. If [[sym:yas-expand][=yas-expand=]] failed to find any
suitable snippet to expand, it will disable the minor mode temporarily
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.
YASnippet used to support a more complicated way of sharing
keybindings before [[sym:yas-expand][=yas-maybe-expand=]] was added. This is now
obsolete.
** 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
first, and then for a snippet template if more than one template
exists for the same key.
@ -88,7 +94,7 @@ The prompting methods used are again controlled by
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
[[#yas-insert-snippet][=yas-insert-snippet=]]. Setting it to a character value (e.g. =?0=)
[[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
@ -135,7 +141,7 @@ See the internal documentation on [[sym:yas-expand-snippet][=yas-expand-snippet=
* Controlling expansion
** Eligible snippets
** Eligible snippets<<eligible-snippets>>
YASnippet does quite a bit of filtering to find out which snippets are
eligible for expanding at the current cursor position.
@ -157,13 +163,15 @@ In particular, the following things matter:
- Parent tables
Snippet tables defined as the parent of some other eligible table are
also considered. This works recursively, i.e. parents of parents of
eligible tables are also considered.
Snippet tables defined as the parent of some other eligible table
are also considered. This works recursively, i.e., parents of
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
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
mode. Typically, you call this from a minor mode hook, for example:
@ -175,29 +183,27 @@ In particular, the following things matter:
(yas-activate-extra-mode 'rails-mode)))
#+END_SRC
- Buffer-local
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]
variable
- Buffer-local [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] variable
This variable provides finer grained control over what snippets can
be expanded in the current buffer. The default value won't let you
expand snippets inside comments or string literals for example. See
The condition system\_ for more info.
be expanded in the current buffer. For example, the constant
[[sym:yas-not-string-or-comment-condition][=yas-not-string-or-comment-condition=]] has a value that disables
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
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
block or a string (e.g. in =python-mode=).
If you use the =# condition := directive (see
[[./snippet-development.org][Writing Snippets]]) you could just specify
the condition for =if= to be =(not (python-syntax-comment-or-string-p))=. But how
about =while=, =for=, etc. ? Writing the same condition for all the
snippets is just boring. So has a buffer local variable
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]. You can set this variable to
=(not (python-syntax-comment-or-string-p))= in =python-mode-hook=.
If you use the =# condition := directive (see [[./snippet-development.org][Writing Snippets]]) you
could just specify the condition for =if= to be =(not
(python-syntax-comment-or-string-p))=. But how about =while=, =for=,
etc? Writing the same condition for all the snippets is just boring.
So you can instead set [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] to =(not
(python-syntax-comment-or-string-p))= in =python-mode-hook=.
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
@ -206,22 +212,23 @@ inside a comment? Set [[sym:yas-buffer-local-condition][=yas-buffer-local-condit
(add-hook 'python-mode-hook
(lambda ()
(setq yas-buffer-local-condition
'(if (python-syntax-comment-or-string-p)
(lambda ()
(if (python-syntax-comment-or-string-p)
'(require-snippet-condition . force-in-comment)
t))))
t)))))
#+END_SRC
... and specify the condition for a snippet that you're going to expand
in comment to be evaluated to the symbol =force-in-comment=. Then it can
be expanded as you expected, while other snippets like =if= still can't
expanded in comment.
... and for a snippet that you want to expand in comments, specify a
condition which evaluates to the symbol =force-in-comment=. Then it
can be expanded as you expected, while other snippets like =if= still
can't expanded in comments.
For the full set of possible conditions, see the documentation for
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]].
** 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.
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=]]
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
[[sym:yas-snippet-dirs][=yas-snippet-dirs=]] and rebuilds the menus.

View File

@ -4,8 +4,9 @@
* Basic structure
Snippet collections can be stored in plain text files. They are arranged by
sub-directories naming *snippet tables*. These mostly name Emacs major names.
Snippet collections can be stored in plain text files. They are
arranged by sub-directories naming *snippet tables*. These mostly
name Emacs major mode names.
#+begin_example
.
@ -32,7 +33,7 @@
The default considers:
- 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
out:
@ -81,7 +82,7 @@
If you place an empty plain text file =.yas-make-groups= inside one
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:
[[./images/menu-groups.png]]

View File

@ -1,5 +1,14 @@
nav > ul > li.center > ul {
padding: 0;
.center { margin-left: auto; margin-right: auto; text-align: center; }
.current {
font-weight: bold;
background-color: #E0E8F0;
}
body { background-color: #E4F0F4 }
div#content {
max-width: 20cm;
margin-left: auto;
margin-right: auto;
}
nav li {
@ -9,20 +18,22 @@ nav li {
list-style-type: none;
padding: 0.5em;
}
nav > ul > li {
display: inline-block;
}
/* match org's css for <pre> */
code {
background-color: #F3F5F7;
font-family: courier, monospace;
.nopad {
padding: 0;
}
li.border {
border: solid;
border-width: 1px;
}
#content {
margin-left: 5%;
margin-right: 10%;
pre, code{ background-color: #F3F5F7; }
code {
/* http://neugierig.org/software/chromium/notes/2009/09/monospace-fonts-workaround.html */
font-family: WorkAroundWebKitAndMozilla, monospace;
white-space: nowrap;
}
/* Styles for htmlize.el fontification. */

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;
}
}

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>
;; Keywords: convenience
@ -25,39 +25,43 @@
;;; Code:
(eval-when-compile
(require 'cl))
(require 'cl-lib))
(require 'org)
(or (require 'org-publish nil t)
(require 'ox-publish))
(require 'ox-publish)
(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
;; http://orgmode.org/worg/org-8.0.html#sec-8-1
(format (if (version< org-version "8.0.0")
"@<%s>%s@</%s>" ; old: @<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)
(flet ((concat-lines (&rest lines)
(mapconcat #'identity lines "\n")))
(let* ((stars (make-string level ?*))
(args (and (fboundp symbol)
(mapcar #'symbol-name (help-function-arglist symbol t))))
(heading (cond ((fboundp symbol)
(format
"%s =%s= (%s)" stars symbol
"%s %s (%s)\n" stars (yas--org-raw-html "code" symbol "class='function'")
(mapconcat (lambda (a)
(format (if (string-prefix-p "&" a)
"/%s/" "=%s=") a))
"/%s/" "=%s=")
a))
args " ")))
(t
(format "%s =%s=\n" stars symbol))))
(after-heading
(concat-lines ":PROPERTIES:"
(format ":CUSTOM_ID: %s" symbol)
":END:"))
(format "%s %s\n" stars
(yas--org-raw-html "code" symbol "class='variable'")))))
(after-heading (format ":PROPERTIES:\n:CUSTOM_ID: %s\n:END:" symbol))
(text-quoting-style 'grave)
(body (or (cond ((fboundp symbol)
(let ((doc-synth (car-safe (get symbol 'function-documentation))))
(if (functionp doc-synth)
@ -69,10 +73,17 @@
(format "*WARNING*: no symbol named =%s=" symbol)))
(format "*WARNING*: no doc for symbol =%s=" symbol)))
(case-fold-search nil))
;; do some transformations on the body:
;; Do some transformations on the body:
;; ARGxxx becomes @<code>arg@</code>xxx
;; FOO becomes /foo/
;; `bar' becomes [[#bar][=bar=]]
;; (...) becomes #+BEGIN_SRC elisp (...) #+END_SRC
;; Info node `(some-manual) Node Name' becomes
;; [[https://www.gnu.org/software/emacs/manual/html_node/some-manual/Node-Name.html]
;; [(some-manual) Node Name]]
;;
;; This is fairly fragile, though it seems to be working for
;; now...
(setq body (replace-regexp-in-string
"\\<\\([A-Z][-A-Z0-9]+\\)\\(\\sw+\\)?\\>"
#'(lambda (match)
@ -87,30 +98,52 @@
match1)))
body t t 1)
body (replace-regexp-in-string
"`\\([a-z-]+\\)'"
"\\\\{[^}]+}"
(lambda (match)
(concat "#+BEGIN_EXAMPLE\n"
(substitute-command-keys match)
"#+END_EXAMPLE\n"))
body t t)
body (substitute-command-keys 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 name)))
(sym (intern-soft name)))
(if (memq sym yas--exported-syms)
(format "[[#%s][=%s=]]" name name)
(format "=%s=" name))))
body t))
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-lines heading
after-heading
body))))
(concat heading after-heading "\n" body)))
(defun yas--document-symbols (level &rest names-and-predicates)
(let ((sym-lists (make-vector (length names-and-predicates) nil))
(stars (make-string level ?*)))
(loop for sym in yas--exported-syms
do (loop for test in (mapcar #'cdr names-and-predicates)
(cl-loop for sym in yas--exported-syms
do (cl-loop for test in (mapcar #'cdr names-and-predicates)
for i from 0
do (when (funcall test sym)
(push sym (aref sym-lists i))
(return))))
(loop for slist across sym-lists
(cl-return))))
(cl-loop for slist across sym-lists
for name in (mapcar #'car names-and-predicates)
concat (format "\n%s %s\n" stars name)
concat (mapconcat (lambda (sym)
@ -121,31 +154,57 @@
(interactive)
(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
;; `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)
default-directory))
(rev (with-temp-file (expand-file-name "html-revision" dir)
(or (when (eq (call-process "git" nil t nil
"rev-parse" "--verify" "HEAD") 0)
(buffer-string))
(princ yas--version (current-buffer)))))
(src-epoch (getenv "SOURCE_DATE_EPOCH"))
;; Presence of SOURCE_DATE_EPOCH indicates a reproducible
;; build, don't depend on git.
(rev (unless src-epoch
(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
`(,@(when (fboundp 'org-html-publish-to-html)
'(:publishing-function org-html-publish-to-html))
:base-directory ,dir :publishing-directory ,dir
:html-preamble
,(with-temp-buffer
(insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
(buffer-string))
:html-preamble yas--make-preamble
;;:with-broken-links mark
:html-postamble
,(concat "<hr><p class='creator'>Generated by %c on %d from "
rev "</p>\n"
,(concat "<hr><p class='creator'>Generated by %c from "
rev " " date "</p>\n"
"<p class='xhtml-validation'>%v</p>\n")))
(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
(setcdr project proj-plist)
(push `("yasnippet" . ,proj-plist)

@ -1 +0,0 @@
Subproject commit 29da8e6c0444188406fdc5bb8b18e9b328fb710e

@ -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
;; This program is free software; you can redistribute it and/or modify
@ -20,114 +20,335 @@
;;; 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:
(require 'yasnippet)
(require 'cl)
(defconst yas--loaddir
(file-name-directory (or load-file-name buffer-file-name))
"Directory that yasnippet was loaded from.")
(defun yas-debug-snippet-vars ()
"Debug snippets, fields, mirrors and the `buffer-undo-list'."
(interactive)
(with-output-to-temp-buffer "*YASnippet trace*"
(princ "Interesting YASnippet vars: \n\n")
(require 'yasnippet (if (boundp 'yas--loaddir)
;; Don't require '-L <path>' when debugging.
(expand-file-name "yasnippet" yas--loaddir)))
(require 'cl-lib)
(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))
(princ (format "\nPre command hook: %s\n" pre-command-hook))
(defvar yas-debug-live-indicators
(make-hash-table :test #'eq))
(princ (format "%s live snippets in total\n" (length (yas--snippets-at-point (quote all-snippets)))))
(princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))
(princ (format "%s live snippets at point:\n\n" (length (yas--snippets-at-point))))
(defun yas-debug-live-colors ()
(let ((colors ()))
(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))
(princ (format "\tsid: %d control overlay from %d to %d\n"
(defun yas-debug-snippet (snippet &optional outbuf)
(yas-debug-with-tracebuf outbuf
(when-let* ((overlay (yas--snippet-control-overlay snippet)))
(printf "\tsid: %d control overlay %s\n"
(yas--snippet-id snippet)
(overlay-start (yas--snippet-control-overlay snippet))
(overlay-end (yas--snippet-control-overlay snippet))))
(princ (format "\tactive field: %s from %s to %s covering \"%s\"\n"
(yas--field-number (yas--snippet-active-field snippet))
(marker-position (yas--field-start (yas--snippet-active-field snippet)))
(marker-position (yas--field-end (yas--snippet-active-field snippet)))
(buffer-substring-no-properties (yas--field-start (yas--snippet-active-field snippet)) (yas--field-end (yas--snippet-active-field snippet)))))
(when (yas--snippet-exit snippet)
(princ (format "\tsnippet-exit: at %s next: %s\n"
(yas--exit-marker (yas--snippet-exit snippet))
(yas--exit-next (yas--snippet-exit snippet)))))
(yas-debug-live-range overlay)))
(when-let* ((active-field (yas--snippet-active-field snippet)))
(unless (consp (yas--field-start active-field))
(printf "\tactive field: #%d %s %s covering \"%s\"\n"
(or (yas--field-number active-field) -1)
(if (yas--field-modified-p active-field) "**" "--")
(yas-debug-live-range active-field)
(buffer-substring-no-properties (yas--field-start active-field) (yas--field-end active-field)))))
(when-let* ((exit (yas--snippet-exit snippet)))
(printf "\tsnippet-exit: %s next: %s\n"
(yas-debug-live-marker (yas--exit-marker exit))
(yas--exit-next exit)))
(dolist (field (yas--snippet-fields snippet))
(princ (format "\tfield: %s from %s to %s covering \"%s\" next: %s%s\n"
(yas--field-number field)
(marker-position (yas--field-start field))
(marker-position (yas--field-end field))
(unless (consp (yas--field-start field))
(printf "\tfield: %d %s %s covering \"%s\" next: %s%s\n"
(or (yas--field-number field) -1)
(if (yas--field-modified-p field) "**" "--")
(yas-debug-live-range field)
(buffer-substring-no-properties (yas--field-start field) (yas--field-end field))
(yas--debug-format-fom-concise (yas--field-next field))
(if (yas--field-parent-field field) "(has a parent)" "")))
(if (yas--field-parent-field field)
(format " parent: %s"
(yas--debug-format-fom-concise
(yas--field-parent-field field)))
"")))
(dolist (mirror (yas--field-mirrors field))
(princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"
(marker-position (yas--mirror-start mirror))
(marker-position (yas--mirror-end mirror))
(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)))))))
(yas--debug-format-fom-concise (yas--mirror-next mirror))))))))
(princ (format "\nUndo is %s and point-max is %s.\n"
(if (eq buffer-undo-list t)
"DISABLED"
"ENABLED")
(point-max)))
(unless (eq buffer-undo-list t)
(princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))
(let ((first-ten (subseq buffer-undo-list 0 (min 19
(length buffer-undo-list)))))
(dolist (undo-elem first-ten)
(princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
(defvar yas-debug-target-buffer nil)
(defvar yas-debug-target-snippets nil nil)
(make-variable-buffer-local 'yas-debug-target-snippets)
(defvar yas-debug-undo nil)
(defun yas-toggle-debug-undo (value)
(interactive (list (not yas-debug-undo)))
(setq yas-debug-undo value)
(yas--message 3 "debug undo %sabled" (if yas-debug-undo "en" "dis")))
(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)
(when fom
(cond ((yas--field-p fom)
(format "field %s from %d to %d"
(yas--field-number fom)
(marker-position (yas--field-start fom))
(marker-position (yas--field-end fom))))
(+ (yas--field-start fom))
(+ (yas--field-end fom))))
((yas--mirror-p fom)
(format "mirror from %d to %d"
(marker-position (yas--mirror-start fom))
(marker-position (yas--mirror-end fom))))
(+ (yas--mirror-start fom))
(+ (yas--mirror-end fom))))
(t
(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 ()
(interactive)
(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)))
(when command-line-args-left
(yas-debug-process-command-line))
(provide 'yasnippet-debug)
;; Local Variables:
;; indent-tabs-mode: nil
;; byte-compile-warnings: (not cl-functions)
;; autoload-compute-prefixes: nil
;; End:
;;; 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