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.
* 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.
* 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.
* 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.
* 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.
* 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.
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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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'.
* 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,.
* 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.
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'.
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.
* 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.
* 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.
* 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.