1319 Commits

Author SHA1 Message Date
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
6b785e185f Say how to hide the backquote side-effect warning
* yasnippet.el (yas--save-backquotes): Explain how to hide warning in
the warning message.
2016-06-22 19:58:56 -04:00
Noam Postavsky
655bda804b Merge: restore backquote evaluation behaviour
But add warnings if snippets use insertion from backquote expressions.
2016-06-21 22:15:08 -04:00
Noam Postavsky
85f39cec2b Warn about backquote exprs modifying the buffer
* yasnippet.el (yas--save-backquotes): Show a warning if evaluating the
backquote expression modifies the buffer.
2016-06-21 22:10:22 -04:00
Noam Postavsky
ee4efdbbde Revert "Separate parsing from evaluation of backquote lisp"
This reverts commit e21420a497c1d79edc6b36ffb1f3bf1bb70f6227.  This
breaks existing snippets which use side-effecting functions inside
backquotes to insert data instead of return the string to insert.  This
usage will be deprecated, but we still need to support it for at least
another release.

* yasnippet.el (yas--save-backquotes): Go back to interleaved parsing
and evaluating of backquoted lisp forms.
2016-06-21 22:09:28 -04:00
Noam Postavsky
e21420a497 Separate parsing from evaluation of backquote lisp
* yasnippet.el (yas--save-backquotes): Parse all backquoted lisp forms
and only then evaluate them.
2016-06-12 09:20:08 -04:00
Noam Postavsky
c7441486db Make yas-describe-tables easier to use from lisp
* yasnippet.el (yas-describe-table-by-namehash): new function.
(yas-describe-tables): remove query for by-namehash variant, replace
query for non-active tables with prefix arg.
2016-06-11 21:02:01 -04:00
songjie dong
1735a283d2 Add region contents to new snippet
* yasnippet.el (yas-new-snippet-default): Add yas-selected-text.
(yas-new-snippet): Let-bind yas-selected-text to region content.

Copyright-paperwork-exempt: yes
2016-06-11 19:40:54 -04:00
Noam Postavsky
bc80f67782 .travis.yml: Don't notify on success 2016-06-11 19:36:21 -04:00
Noam Postavsky
dc3e4ca345 Release 0.10.0
- Update NEWS
- Bump version number
- update snippets submodule
0.10.0
2016-06-11 14:45:42 -04:00
Noam Postavsky
e23a053b00 Avoid bug in insert-file-contents with REPLACE=t
* yasnippet.el (yas--load-directory-2): Call `erase-buffer' before
`insert-file-contents' instead of passing non-nil REPLACE, avoids Emacs
bug #23659.

Fixes #707.
2016-05-30 20:21:19 -04:00
João Távora
47dbe93d86 Fix broken links in README.mdown
After the Github acocunt name change (capitaomorte -> joaotavora), 
most links to repositories are redirected excpect Travis CI and 
Github Pages (documentation).

* README.mdown: Fix documentation and Travis badge links
2016-05-24 08:24:18 +01:00
Noam Postavsky
497867cea5 Rename yas-backport-obsolete-alias
* yasnippet.el (yas-alias-to-yas/prefix-p): Rename from
yas-backport-obsolete-alias.
(yas/root-directory): Only define if yas-alias-to-yas/prefix-p is
non-nil.  Mark obsolete.
2016-05-17 19:28:14 -04:00
USAMI Kenta
bbfa1f0c9a Add yas-backport-obsolete-alias option
* yasnippet.el (yas-backport-obsolete-alias): New option.
2016-05-17 08:03:25 -04:00
Noam Postavsky
0d79e6988e Extra measures to prevent premature yas-minor-mode
The user's hooks may try to enable yas-minor-mode before yasnippet.el
has finished loading.  In [1], we catch and ignore the errors arising
from this, but it's better if we can avoid hitting the error in the
first place.

This means we have 3 separate measures to avoid the problem, but since
this bug can leave Emacs unusable due to a failing post-command-hook,
a bit of redundant safety is not a bad thing.

* yasnippet.el (yas-minor-mode): Only turn on if yasnippet is fully
loaded.
(yas--font-lock-keywords): Disable user hooks.

[1]: "Avoid potential problems with user's hooks"
4c6064ce1aff07fe4481b5e2d987c8a7f044c207
2016-05-14 07:18:38 -04:00
Noam Postavsky
1b8f5b7a72 Don't use major-mode syntax-propertize-function
during snippet creation.  The snippet creation manipulates the
syntax-table which can lead to conflicts (see also
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23443).

* yasnippet.el (yas-expand-snippet): Let-bind syntax-propertize-function
to nil and then call syntax-ppss-flush-cache afterwards.
2016-05-12 05:41:08 -04:00
Noam Postavsky
6180cc4059 Fix field transform application in yas-next-field
* yasnippet.el (yas--apply-transform): Don't let-bind yas-moving-away-p
to nil, it's nil by default.
(yas-next-field): Call `yas--field-update-display' instead of only
calling `yas--eval-lisp' so that the result of the transform is inserted
into the buffer.
2016-05-12 04:57:08 -04:00
Noam Postavsky
6f97316551 Fix outdated and misformatted docs
yas-find-snippets was removed by [1].

* doc/snippet-development.org: Add keybindings on same line as command
names, fixup intra document links, and remove mention of non-existent
command yas-find-snippets.
* yasnippet.el (yas-load-snippet-buffer):
(yas-load-snippet-buffer-and-close): Fix docstring formatting.

[1]: "cleanup: remove `yas/find-snippets\', complicated and no one seems
to use it anyway" 29 May, 2012 433c93746534ebb062afe4dbc7690f736be72d42.
2016-05-10 12:24:25 -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
Noam Postavsky
bdfab67eac Make yasnippet less chatty
Make sure output that occurs in normal use goes to verbosity levels 3 or
higher, and level 2 and below are reserved for something unexpected
happening.  Level 3 (the new default) should be a reasonably quiet but
informative level.

* yasnippet.el (yas--read-keybinding, yas--safely-run-hooks):
(yas--on-protection-overlay-modification): Put warnings at verbosity
level 2.
(yas--load-yas-setup-file, yas-load-directory):
(yas--load-directory-1, yas--load-snippet-dirs):
(yas-expand-snippet, yas--load-pending-jits): Put per-file loading and
other debug messages at level 4.
(yas-load-snippet-buffer, yas--template-get-file, yas-reload-all): Put
top level loading messages at level 3 (or 2 if there were errors).
(yas--define-menu-1, yas-insert-snippet, yas-tryout-snippet): Put error
messages at level 1.
(yas-verbosity): Reduce default verbosity to level 3.
2016-05-01 21:41:42 -04:00
Noam Postavsky
df229b9ab8 Fix some doc formatting
* doc/snippet-development.org (Template Syntax):
(Placeholder fields, Mirrors): Text inside dedicated target <<angle
brackets>> does not show up in output, so duplicate it.  Add
descriptions to avoid getting numbers instead of names in links.
2016-04-30 22:36:34 -04:00
Noam Postavsky
78fe979b7b Support htmlize.el in Rakefile doc target
Htmlized output can now be produced by

    rake doc[/path/to/htmlize/]

* Rakefile (doc): Add htmlize argument.
* doc/yas-doc-helper.el (yas--generate-html-batch): Tell org to use css
selectors only when exporting htmlized faces.
* doc/stylesheets/manual.css: Add styles for faces used by org export.
2016-04-30 22:36:34 -04:00
Noam Postavsky
beb2ba4d7f Fix fields following $0 + region insertion
When inserting text due to a  non-nil yas-wrap-around-region and the
snippet had fields occuring later in the buffer than $0, the insertion
of the text was shifting the location of later fields, thus invalidating
the calculation of yas--dollar-regions.

* yasnippet.el (yas--simple-mirror-parse-create): Don't insert text fo
yas-wrap-around-region here.
(yas--snippet-parse-create): Do it here, after deleting
`yas--dollar-regions`, instead.
2016-04-30 20:19:12 -04:00
Noam Postavsky
db4cd31a11 Delete active region for trigger key expansion
This makes yas-expand-from-trigger-key consistent with
yas-insert-snippet.

* yasnippet.el (yas-expand-from-trigger-key): Expand start end interval
with active region.
2016-04-30 20:19:12 -04:00
Noam Postavsky
5d44a9f15e Revert "Disable region wrapping for trigger key expansion"
This reverts commit f8d1af1f50f42ac1689c583c152c3b15e8774ae4.

Disabling this for trigger key introduced an inconsistency that is more
complicated to implement and document than simply fixing region wrapping
for trigger key expanded snippets.
2016-04-30 20:17:38 -04:00
Noam Postavsky
e37ce9e488 Disable region wrapping for trigger key expansion
It's too awkward to highlight the relevant text while maneuvering point
in front of the trigger key.

* yasnippet.el (yas-expand-from-trigger-key): Let-bind
yas-wrap-around-region to nil if it was t.
* doc/snippet-expansion.org: Document it.
2016-04-30 20:10:01 -04:00
Noam Postavsky
c1b2cb7c5e Improve documentation for new register option
* doc/snippet-expansion.org: Add new section about
yas-wrap-around-region.
* yasnippet.el (yas-wrap-around-region): Improve docstring.
2016-04-30 20:10:01 -04:00
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