1180 Commits

Author SHA1 Message Date
Etienne
0d9afb2c69 Fix mirror transformation error with expand-env
* yasnippet.el (yas-expand-snippet): Use the snippet's bindings when
moving to the first field.  This prevents getting an error when using
a variable defined in expand-env.
* yasnippet-tests.el (snippet-mirror-bindings): New test, check if
mirror transformations have access to variables defined in the snippet
environment.
2017-03-09 13:50:06 -05:00
Etienne
6e9b7f9432 Fix running hook variable set as buffer-local
* yasnippet.el (yas--eval-for-effect): Use `yas--safely-call-fun'
instead of `yas--safely-run-hook'.
(yas--safely-call-fun): Display the called argument (even a lambda) on
errors.
(yas--safely-run-hook): Take a hook variable instead of the hook value
itself.  Use `run-hooks' to take buffer-local values into account.
This means it’s no longer possible to warn which hook function had an
error.
(yas--check-commit-snippet): Refactor to conform to
`yas--safely-run-hooks'.
* yasnippet-tests.el (snippet-exit-hooks-bindings): New test that
checks for buffer-local, global and env hooks support.
2017-02-26 19:38:32 -05:00
Noam Postavsky
cddb8260a0 Merge: let snippets expand in strings/comments by default
Also make yas-buffer-local-condition into a defcustom.
2017-02-16 22:28:31 -05:00
Noam Postavsky
14819c931f Make yas-buffer-local-condition into a defcustom
* yasnippet.el (yas-not-string-or-comment-condition): New constant,
holding the previous default value of `yas-buffer-local-condition'.
(yas-buffer-local-condition): Make into defcustom.
2017-02-16 22:27:15 -05:00
Noam Postavsky
4f37afd493 Let snippets expand in strings/comments by default
* yasnippet.el (yas-buffer-local-condition): Change default to t.
* doc/snippet-expansion.org: Update documentation.
2017-02-16 22:27:15 -05:00
Noam Postavsky
c87afe0901 Merge: snippet-local exit hook; error handling improvements 2017-02-12 11:32:27 -05:00
Noam Postavsky
f3d0e03a05 * yasnippet-tests.el (snippet-exit-hooks): New test. 2017-02-05 15:23:18 -05:00
Noam Postavsky
6c4fbb25b3 Fix snippet local exit hook
* yasnippet.el (yas--check-commit-snippet): Use
`yas-after-exit-snippet-hook' value of last exited snippet.
* yasnippet.el (yas--safely-run-hook): Also accept a list of functions.
* yasnippet.el (yas--safely-call-fun): New function, extracted from yas--safely-run-hook.
2017-02-05 15:23:18 -05:00
Noam Postavsky
b62cf52f35 Remove lambda list building hack
* yasnippet.el (yas-load-directory, yas--eval-for-effect): Use
`apply-partially' instead of building lambda lists.
2017-02-05 15:22:24 -05:00
Noam Postavsky
203df22e26 Use debug-on-error to simplify error handling
* yasnippet.el (yas--eval-for-string, yas--safely-run-hook: Let-bind
`debug-on-error' according to `yas-good-grace' and add `debug' to
condition handler to deduplicate evaluation.
2017-02-05 15:22:24 -05:00
Noam Postavsky
9c9547a628 Don't catch and rethrow yas-{-}exception
* yasnippet.el (yas--eval-for-string): Don't catch yas--exception.
(yas-throw): Signal `yas-exception', not `yas--exception'; DATA must be
a list.
(yas-exception): Add `error-message' property.
(yas-verify-value): Just use plain format since the new `error-message'
property for `yas-exception' will add the right prefix.
2017-02-05 15:22:24 -05:00
João Távora
ac26024837 Rework error handling
* yasnippet.el (yas-good-grace): Add support for `inline' and `hooks' options.
(yas--eval-for-string): Renamed from `yas--eval-lisp'.  Errors are
passed straight through (no rethrow) when `yas-good-grace' is nil.
(yas--handle-error): Removed.
(yas--eval-for-effect): Renamed from `yas--eval-lisp-no-saves'.  Use
`yas--safely-run-hook'.
(yas-define-snippets): Update docstring.
(yas-throw): Don't throw, just signal.
(yas--save-backquotes, yas--apply-transform): Use
`yas--eval-for-string'.
(yas--safely-run-hook): Renamed from `yas--safely-run-hooks'.  Takes 1
hook function, instead of a hook var; check `yas-good-grace'.
(yas-expand-snippet): Use `yas--eval-for-effect'.
2017-02-05 15:22:24 -05:00
Noam Postavsky
9abf842e35 Enable snippet-mode automatically
* yasnippet.el (yas-snippet-mode-buffer-p): New function, detects
buffers visiting files under `yas-snippet-dirs'.  Add it
`magic-fallback-mode-alist' to enable `snippet-mode' automatically,.
2017-02-03 09:26:11 -05:00
Noam Postavsky
e74f00e703 Fix whitespace lossage between mirrors
* yasnippet.el (yas--update-mirrors): Delay indentation until all
mirrors are updated.
(yas--mirror-update-display): Don't indent here.
* yasnippet-tests.el (single-line-multi-mirror-indentation-2): New test.
2017-01-28 00:28:57 -05:00
Noam Postavsky
0041efedf9 Make snippets work in org source blocks
org-mode implements the "native" tab for source blocks by copying the
source block text into a temporary buffer, calling the command bound to
<tab>, and then copying back the result.  To preserve snippets in this
scenario, when the temp buffer is killed we record the relative
locations of the snippet's markers and overlays and then put them into
place in the post command handler.

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

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

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

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

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

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

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

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

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

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

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

Copyright-paperwork-exempt: yes

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

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

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

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

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

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

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

Fixes #722.
2016-07-13 17:03:30 -04:00