141 Commits

Author SHA1 Message Date
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
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
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
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
a5e88b2fd4 Add test for snippet saving
* yasnippet-tests.el (snippet-save): New test.
2016-09-27 19:55:56 -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
9500b000fd Fix field navigation in the backwards direction
* yasnippet.el (yas--find-next-field): For negative N, actually give the
Nth previous field, not the 1st field.
* yasnippet-tests.el (field-navigation): Add a 3rd field, and test
calling `yas-prev-field' while on it.

Fixes #722.
2016-07-13 17:03:30 -04:00
Noam Postavsky
a4fafc3225 Add test for loading snippet with same uuid
* yasnippet-tests.el (snippet-load-uuid): New test.
2016-07-05 23:15:45 -04:00
Noam Postavsky
9c9952c19a Add test for indentation of single line mirrors
* yasnippet-tests.el (indent-mirrors-on-update): New test.
2016-06-24 16:19:22 -04:00
João Távora
d218ed8b1b Do indent the first line of mirrors, but in correct order
This changes the strategy for fixing #712 to a simpler alternative,
which doesn't remove the benefits of indenting single line mirrors.

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

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

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

* yasnippet.el (yas--font-lock-keywords): Escape $, even if first in the
regexp.
(yas--indent): Remove unused var `end'.
(yas--indent-parse-create): Remove unused arg `snippet'.  Update caller.
2016-06-22 22:50:51 -04:00
Noam Postavsky
e9406f5126 Document $> and fix escaping
* doc/snippet-development.org: New "Indentation markers" section.
* yasnippet-tests.el (indentation-markers): New test.
* yasnippet.el (yas--indent-markers): New variable.
(yas--indent): Use it instead of searching for $> directly.
(yas--indent-parse-create): New function, records occurences of $> into
`yas--indent-markers'.
(yas--snippet-parse-create): Call it.
2016-05-08 15:32:20 -04:00
Noam Postavsky
146b161112 Don't indent empty lines in snippet expansion
* yasnippet.el (yas--indent-region): Indent only non-empty lines.
* yasnippet-tests.el (basic-indentation): Add empy and non-empty (but
blank) lines in test snippet.
2016-05-04 12:35:48 -04:00
João Távora
eeb4b62efb Add new tests for multi-line mirror indentation
* yasnippet-tests.el (basic-indentation):
(navigate-a-snippet-with-multiline-mirrors-issue-665): New tests.
2016-04-30 18:32:30 -04:00
Noam Postavsky
14f830a37d Test expansion in an empty buffer
* yasnippet-tests.el (yas-should-expand, yas-should-not-expand): Call
`erase-buffer' instead of narrowing.
2016-04-30 18:32:30 -04:00
Noam Postavsky
bfe14f19ac Test and fix problem with mirror+autofill
cc-mode fill paragraph narrows to the paragraph being filled.  This
causes problems if there is a mirror needing to be updated outside of
the current paragraph.

* yasnippet-tests.el: New test.
* yasnippet.el (yas--update-mirrors): Widen while updating the mirrors.
2016-04-28 21:16:30 -04:00
Stefan Monnier
42601d2ff8 Apply changes from GNU ELPA
* doc/yas-doc-helper.el:
* yasnippet-debug.el:
* yasnippet-tests.el: Fix up copyright headers.

* yasnippet-tests.el: Fix lexical-binding cookie.
* yasnippet-debug.el: Require cl.

* yasnippet-tests.el: Silence byte-compiler.
(yas-saving-variables, yas-with-snippet-dirs): Move macros before their use.
(yas--barbaz, yas--foobarbaz): Declare.
(yas--phony-c-mode, yas--test-mode, yas--another-test-mode): Move out of
deftest, so the byte-compiler understands they're defined.
2016-01-28 14:36:19 -05:00
Noam Postavsky
acf2cdd03e Decide field clearing commands based on delsel
* yasnippet.el (yas--skip-and-clear-field-p): Check `delete-selection'
  of `this-command'.

Fix #644, close #645.
2016-01-22 11:45:01 -05:00
João Távora
4a6d923c9d Slightly improve on fix for #515: Refactor code and add tests
While I agree with the solution for #515 in commit 17fe790 for now,
other approaches might be interesting in the future, like clearing on
other types of insertion, not just self-insertion.

So add some tests and refactor a new function that could be used for
that purpose later on. For now, change no behaviour.

* yasnippet-tests.el (dont-clear-on-partial-deletion-issue-515,
  dont-clear-on-yank-issue-515): New tests. (yas-mock-yank): New
  function.

* yasnippet.el (yas--skip-and-clear-field-p): New function.
  (yas--on-field-overlay-modification): Use it.
2016-01-22 11:19:34 -05:00
Noam Postavsky
71f0142eda Improve test simulatulation of self-insert
* yasnippet-tests.el (yas-mock-insert): Use `ert-simulate-command' to
  simulate n self-insert-commands.
(simple-mirror, mirror-with-transformation):
(primary-field-transformation, nested-placeholders-kill-superfield):
(nested-placeholders-use-subfield):
(mirrors-adjacent-to-fields-with-nested-mirrors):
(deep-nested-mirroring-issue-351, example-for-issue-271):
(string-match-with-subregexp-in-mirror-transformations): Call
`yas-mock-insert' directly instead of with `ert-simulate-command'.
2015-12-13 00:37:36 -05:00
Sharif Nassar
1cf723a408 Ignore trailing spaces in snippet definitions
Probably nobody wants a snippet `key` with a trailing space. It can
be hard to differentiate from a `key` without trailing space. The
default `<TAB>` behavior of yasnippet will never expand these.

* yasnippet.el (yas--parse-template): Ignore trailing spaces in snippet
  definitions.
* yasnippet-tests.el (deftest ignore-trailing-whitespace): New test for
  new behavior.

Copyright-paperwork-exempt: yes
2015-11-08 18:05:09 -05:00
Sharif Nassar
3aa7cb29d4 M-x delete-trailing-whitespace
* yasnippet.el: delete-trailing-whitespace
* yasnippet-tests.el: delete-trailing-whitespace

Copyright-paperwork-exempt: yes (trivial)
2015-11-08 18:04:08 -05:00
Noam Postavsky
cd05da61f9 Activate extra and major modes first
This prevents snippets from a parent mode from overriding those of the
major-mode's (or yas--extra-modes).  Snippets of ancestor modes may
still override snippets of some other ancestor modes, but hopefully this
won't cause much trouble in practice.

See [1] and subsequent comments.

[1]: https://github.com/capitaomorte/yasnippet/issues/619#issuecomment-149127150

* yasnippet.el (yas--modes-to-activate): Reverse result, so that parents
  of yas--extra-modes and major are later in the list.
* yasnippet-tests.el (loading-with-cyclic-parenthood)
(extra-modes-parenthood): Test it.

Close #626.
2015-11-01 18:35:52 -05:00
Noam Postavsky
00b84ceaf4 Add (failing) yas--modes-to-activate test
* yasnippet-tests.el (extra-modes-parenthood): New (failing) test.
(loading-with-cyclic-parenthood): Use equal + sort instead of set
operation + length.
2015-10-11 13:08:53 -04:00
Noam Postavsky
041821a210 * yasnippet-tests.el (string-suffix-p): Define for older Emacsen. 2015-09-05 16:20:04 -04:00
Noam Postavsky
e3f03cabe0 Test visiting compiled snippets
* yasnippet-tests.el (visiting-compiled-snippets): New Test.
* yasnippet.el (yas--lookup-snippet-1, yas-lookup-snippet): Split new
  function yas--lookup-snippet-1 from yas-lookup-snippet.
2015-09-05 15:42:32 -04:00
Noam Postavsky
7bce1a6473 Add new function yas-lookup-snippet
* yasnippet.el (yas-lookup-snippet): New function.
(yas--get-snippet-tables, yas--modes-to-activate): Add optional mode
parameter.
* yasnippet-tests.el (snippet-lookup): New test for yas-lookup-snippet.
* doc/snippet-expansion.org (Expanding from emacs-lisp code): Mention
  yas-lookup-snippet.
2015-08-03 10:36:46 -04:00
João Távora
a46701966a `yas-minor-mode' assertion broke a test. Good. Fix it.
* yasnippet-tests.el
(be-careful-when-escaping-in-yas-selected-text-2): Add
`yas-minor-mode'.
2015-03-23 10:21:26 +00:00
João Távora
316435e03e Closes #562: Deleting inner numberless snippet causes error
* yasnippet.el (yas--field-probably-deleted-p): Protect against
nil `yas--field-number'.

* yasnippet-tests.el (delete-numberless-inner-snippet-issue-562): New test
2015-03-23 10:11:06 +00:00
Jonas Bernoulli
70de82164c enforce use of spaces for indentation 2014-09-07 14:20:07 +02:00
Jonas Bernoulli
241465cea2 move eof footer to the actual eof 2014-09-07 14:20:07 +02:00
João Távora
1d4618b022 Closes #504: Correctly discover buffers needing snippets immediately
* yasnippet-tests.el (issue-504-tricky-jit): New test.

* yasnippet.el (yas-load-directory): Use a new `impatient-buffers'
local and call `yas--load-pending-juts' in all those at the end.

* yasnippet.el (cl-lib): Don't need `eval-and-compile'.
2014-08-20 21:29:32 +01:00
Noam Postavsky
d982b701fc Fix edge case in yas-longest-key-from-whitespace
* yasnippet.el (yas-longest-key-from-whitespace): don't try again if
  start-point is on whitespace.
* yasnippet-tests.el (complicated-yas-key-syntaxes): check edge case.
2014-08-10 14:05:26 -04:00
Noam Postavsky
5d10b5dfee Add yas-longest-key-from-whitespace
Example yas-key-syntaxes function.

* yasnippet.el (yas-longest-key-from-whitespace): new function.
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.
2014-08-10 14:05:25 -04:00
Noam Postavsky
10ecde158e Pass start point to yas-key-syntaxes functions
* yasnippet-tests.el (complicated-yas-key-syntaxes): accept argument.
* yasnippet.el (yas-try-key-from-whitespace): accept argument.
  (yas-shortest-key-until-whitespace): accept argument.
  (yas--templates-for-key-at-point): pass start point the methods.
  (yas-key-syntaxes): update docstring.
2014-08-10 14:05:25 -04:00
Noam Postavsky
280ece2af4 Add yas-shortest-key-until-whitespace
Example yas-key-syntaxes function.

* yasnippet.el (yas-shortest-key-until-whitespace): new function.
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.
2014-08-10 14:05:25 -04:00
Noam Postavsky
de34d91a3c Closes #470, handle non-whitespace newlines
Many modes put newlines in comment ender class because they have line
comments.

* yasnippet.el (yas-try-key-from-whitespace): new function.
(yas-key-syntaxes): use it in place of "^ ".
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.
2014-08-10 14:05:01 -04:00
João Távora
7761deeeb5 Closes #497: Allow functions as elements in yas-key-syntaxes
* yasnippet.el (yas--templates-for-key-at-point): Renamed from
`yas--current-key'.
(yas-key-syntaxes): Overhaul documentation.
(yas-expand-from-trigger-key): Use
`yas--templates-for-key-at-point'.

* yasnippet-tests.el (complicated-yas-key-syntaxes): New test.
(yas-should-expand, yas-should-not-expand): Friendlier failure
message.
2014-07-29 01:19:58 +01:00
João Távora
0b7b34a333 Closes #492, closes #494: Consider defalias when calculating parent modes
* yasnippet-tests.el (issue-492-and-494): New test.

* yasnippet.el (yas--modes-to-activate): Consider each mode's
symbol-function as a neighbour in case it's a symbol as well.
2014-07-28 23:23:04 +01:00
Noam Postavsky
763f5faa14 Closes #474: fix more cc-mode font-lock conflicts
* yasnippet-tests.el (example-for-issue-474): Don't call insert from
  within backquotes, it's redundant and prevents proper testing of
  backquote expansion.

* yasnippet.el (yas--restore-backquotes, yas--save-backquotes): Ensure
  the buffer isn't narrowed while modifying it to avoid conflicting with
  cc-mode fontification.
2014-05-14 19:49:11 -04:00
Noam Postavsky
4473b4ede5 New test for cc-mode's fontification functions
This issue requires font locking to trigger. This can be be done by
let-binding noninteractive to nil and using a buffer name that doesn't
start with a space, instead of the external emacs hack which is now
redundant.

* yasnippet-tests.el (yas--with-font-locked-temp-buffer): new macro
similar to with-temp-buffer but enables font-lock-mode even in -batch
mode.
(example-for-issue-474): new test
(example-for-issue-404, example-for-issue-404-c-mode): use new macro
(example-for-issue-404-external-emacs): removed
2014-04-27 14:49:02 -04:00
João Távora
b36a4f7449 Properly closes #469: Don't use `yas--init-minor-keymap'
Previous reverted commit 498cbe4 forgot to take into account that one
of the tests used the `yas--init-minor-keymap' function that was
removed.

* yasnippet.el (yas-use-menu): Don't allow `nil' value, it's
useless.
(yas--minor-mode-menu): Use top-level `easy-menu-define' form.
(yas--init-minor-keymap): Remove definition.

* yasnippet-tests.el (test-rebindings): Don't use
`yas--init-minor-keymap'. Restore bindings explicitly. Not ideal,
but should work.
2014-03-13 20:29:06 +00:00
Joao Tavora
12b7f82dd8 Add Travis CI and update tests. Start a Changelog.
* .travis.yml: new file

* README.mdown: Add Travis CI badge.

* Rakefile: use ert-run-tests-batch-and-exit.

* yasnippet-tests.el (example-for-issue-404-external-emacs): Use
`yas-with-snippet-dirs' to not depend on bundled snippets.
(yas--call-with-temporary-redefinitions): Use `cl-labels' since no
cl-flet in emacs-24.3's cl-lib.el.
(loading-with-cyclic-parenthood): prog-mode doesn't exist in emacs
24.3.
(yas-batch-run-tests): remove it.

* yasnippet.el (require): require cl-lib during byte-compilation
and load.
2013-12-31 15:58:21 +00:00
Joao Tavora
7d4e4aa34c Closes #440: don't use make-variable-buffer-local' for yas--extra-modes' 2013-12-03 15:20:53 +00:00
João Távora
0f67c07ddd Merge pull request #424 from ljos/de/activate-extra-mode
Feature: de/activate-extra-mode
2013-10-31 06:28:26 -07:00
Joao Tavora
43a484e943 add: external test for issue #404 2013-10-31 13:03:32 +01:00
Bjarte Johansen
d5d6e456bf Feature: de/activate-extra-mode
Adds functionality to deactivate/activate extra modes. Two new functions
are added: `activate-extra-mode', `deactivate-extra-mode'. These two
functions activate and deactivate snippets for the given mode in the
current buffer. The use-case for the functions is to have a simple
interface for adding new snippets when activating a new minor mode.

The previous way of doing this, using `yas-extra-modes', is made
obsolete and the new deactivate/activate should be the preferred
instead. The reason for making `yas-extra-modes' obsolete is to keep a
simple interface.

See issue #420 for more information.
2013-10-27 20:38:12 +01:00