1291 Commits

Author SHA1 Message Date
Noam Postavsky
ccc9adc3c4 Add register option for yas-wrap-around-region
Replace `cua' setting with more general behaviour that can use any given
register.  A `cua' setting is converted to ?0 for backwards
compatibility.

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

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

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

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

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

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

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

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

Copyright-paperwork-exempt: yes

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

Copyright-paperwork-exempt: yes
2016-04-02 10:30:10 -04:00
Noam Postavsky
572c73d50b Avoid error in case this-command isn't a symbol.
Fixes #664.

* yasnippet.el (yas--skip-and-clear-field-p): Only get
  `delete-selection' property of `this-command' when it's a symbol.
2016-02-26 16:59:39 -05:00
Noam Postavsky
88b7950554 Reduce `yas-new-snippet-default'
* yasnippet.el (yas-new-snippet-default): Remove
  "require-final-newline: nil", it's redundant since `snippet-mode' already
  sets that.  Also remove the direct-keybinding, since it's hardly ever
  used, and often the literal "# binding: direct-keybinding" ends up in
  actual snippets.
2016-01-31 12:48:06 -05:00
Noam Postavsky
8632262a50 Don't use yas-x-prompt by default
It is not a very pleasant method when there are many values, and
`yas-completing-prompt' will usually do a better job, in addition to
respecting customizations to `completing-read-function'.
`yas-dropdown-prompt' remains in first place, since it only takes effect
if the `dropdown' library is loaded, which likely indicates a preference
for it.

* yasnippet.el (yas-prompt-functions): Remove yas-x-prompt from default value.
2016-01-29 13:57:18 -05: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
80941c077f Update snippets submodule 0.9.1-snapshot 2016-01-22 13:56:26 -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
1a98c38d9c Fix silly mistake in previous commit
* yasnippet.el (yas--load-snippet-dirs): Put `make-directory' call in
  same branch of the `if' as the `dolist' loop.
2016-01-20 09:44:28 -05:00
Noam Postavsky
46256db43d Fix #648; create ~/.emacs.d/snippets automatically
* yasnippet.el (yas--load-snippet-dirs): Create
  yas--default-user-snippets-dir, if needed.
2016-01-20 09:27:24 -05:00
Noam Postavsky
100d8d1904 Fix bug reporting examples.
- There was a missing "." in the emacs invocation (thanks to Barrie
  Treloar for reporting).

- The example reports had too little plain observation, and too much
  interpretation.

* README.mdown: Add missing "." to bug reporting instructions, improve
  wording of example reports.

Close #646.
2016-01-15 17:00:48 -05:00
João Távora
af905283bd Fix debugging code for newer Emacsen
* yasnippet-debug.el (yas-debug-snippet-vars): Check for length of
`buffer-undo-list'. Don't assume all fields have integer
`yas--field-number'.
2016-01-06 10:40:58 +00:00
João Távora
a2c5292724 Bless Noam Postavsky as the new official maintainer
* yasnippet.el (yas-about): Bless Noam Postavsky as the official maintainer
2016-01-04 09:29:20 +00:00
Noam Postavsky
e6fff091f2 Don't choose ido prompting based on Emacs version
* yasnippet.el (yas-ido-prompt): Unconditionally use ido prompting,
  explicitly requireing ido.
(yas-maybe-ido-prompt): New function, call `yas-ido-prompt' if
`ido-mode' is enabled.
(yas-prompt-functions): Replace `yas-ido-prompt' with
`yas-maybe-ido-prompt' in the default value.
2015-12-27 18:50:21 -05:00
Noam Postavsky
61261c9bb4 Fix #576; don't override yas-prompt-functions
* yasnippet.el (yas-visit-snippet-file): Don't override
  `yas-prompt-functions'.
2015-12-27 18:26:07 -05:00
Noam Postavsky
140c415505 Respect y-b-l-cond from binding triggered snippets
The default value for `yas-buffer-local-condition' was only effective
for `yas-expand-from-trigger-key' command, so it didn't have any effect
when triggering snippets from a key binding (or if using the
`yas-expand' alias).

* yasnippet.el (yas-buffer-local-condition): Check if `this-command' is
  `yas-expand' or `yas-expand-from-keymap' too.

Fixes #305, close #638
2015-12-27 18:24:37 -05:00
Noam Postavsky
17fe7904ae Fix #515; only clear field on self-insert
* yasnippet.el (yas--on-field-overlay-modification): Only clear field if
  `this-command' is `self-insert-command'.  Clean up docstring.

Close #639.
2015-12-27 18:24:01 -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
Noam Postavsky
c80fbf2c0b Cleanup yas--on-field-overlay-modification
* yasnippet.el (yas--on-field-overlay-modification): Remove redundant
  `after?' check; use `=' to save marker vs number type checking.
2015-12-13 00:33:25 -05:00
Noam Postavsky
67a45a61de * README.mdown: Add link to textmate-to-yas.el. 2015-12-12 10:59:21 -05:00
JJ Asghar
444c882b64 * README.mdown: update melpa URL.
Copyright-paperwork-exempt: yes

Close #555.
2015-12-12 10:30:18 -05:00
Noam Postavsky
d78181a7f1 Remove yas--inhibit-overlay-hooks macro.
* yasnippet.el (yas--inhibit-overlay-hooks): Remove.
(yas--commit-snippet, yas--make-move-field-protection-overlays):
(yas-expand-snippet, yas--mirror-update-display):
(yas--field-update-display): Replace `yas--inhibit-overlay-hooks' with
its expansion.
2015-12-09 21:04:24 -05:00
Noam Postavsky
3cd64b74b3 yasnippet.el (yas--called-interactively-p): Remove.
It's unused since "fix: more idiomatic elisp..." 29 Aug 2013
(13d87aa3c0b0289ed918bab545d2b423974688a5).
2015-12-09 20:11:31 -05:00
Noam Postavsky
23ee54e10f Use destructive list functions in yas--s-a-p
`mapcar' already create a fresh list so there is no need to preserve it.

* yasnippet.el (yas--snippets-at-point): Use `delq' and `delete-dups'
  instead of `remove' and `remove-duplicates`, respectively.
2015-12-08 19:03:42 -05:00
Noam Postavsky
6c46878882 Fix #587; set `this-command' on fallback.
`this-original-command' is supposed to be for the command that
we're *not* executing because of key remapping, therefore it doesn't
make sense to set it to the command we're about to execute.

* yasnippet.el (yas--fallback): Set `this-command'.
2015-12-08 18:19:02 -05:00
João Távora
2100b89eb8 Closes #632: Use `user-emacs-directory' instead of hardcoded "~/emacs.d"
* yasnippet.el (yas--default-user-snippets-dir): New defconst.
(yas-snippet-dirs, yas--guess-snippet-directories): Use it.
2015-11-26 13:18:16 +00: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
beb02e5e9e * CONTRIBUTING.md: Add note about changelog only messages. 2015-11-07 08:54:08 -05:00
Noam Postavsky
f12164551f Fix #607; avoid Emacs bug #21824
See also
- https://github.com/capitaomorte/yasnippet/issues/607
- http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21824

* yasnippet.el (yas--on-field-overlay-modification): Do nothing if
  yas--active-field-overlay is not an overlay.
2015-11-03 22:16:17 -05:00