Noam Postavsky [Sat, 14 May 2016 11:18:38 +0000 (07:18 -0400)]
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.
Noam Postavsky [Thu, 12 May 2016 09:41:08 +0000 (05:41 -0400)]
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.
Noam Postavsky [Thu, 12 May 2016 08:57:08 +0000 (04:57 -0400)]
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.
Noam Postavsky [Tue, 10 May 2016 16:21:14 +0000 (12:21 -0400)]
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.
Noam Postavsky [Sun, 8 May 2016 19:32:20 +0000 (15:32 -0400)]
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.
Noam Postavsky [Wed, 4 May 2016 16:35:48 +0000 (12:35 -0400)]
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.
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.
Noam Postavsky [Sun, 1 May 2016 02:29:57 +0000 (22:29 -0400)]
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.
Noam Postavsky [Sun, 1 May 2016 02:11:49 +0000 (22:11 -0400)]
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.
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.
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.
Noam Postavsky [Thu, 10 Dec 2015 04:15:39 +0000 (23:15 -0500)]
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.
João Távora [Fri, 4 Mar 2016 17:34:40 +0000 (17:34 +0000)]
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.
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.
* .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.
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"
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.
Stefan Monnier [Sun, 10 Apr 2016 14:14:56 +0000 (10:14 -0400)]
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.
BEN ENGLISCH [Sat, 9 Apr 2016 17:52:16 +0000 (12:52 -0500)]
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.
* 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).
Stefan Monnier [Wed, 6 Apr 2016 03:48:01 +0000 (23:48 -0400)]
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.
Noam Postavsky [Sun, 31 Jan 2016 17:48:06 +0000 (12:48 -0500)]
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.
Noam Postavsky [Fri, 29 Jan 2016 18:55:00 +0000 (13:55 -0500)]
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.
* 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.
João Távora [Mon, 4 Jan 2016 10:15:31 +0000 (10:15 +0000)]
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.
Noam Postavsky [Fri, 11 Dec 2015 02:37:06 +0000 (21:37 -0500)]
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.
Noam Postavsky [Sat, 12 Dec 2015 03:54:21 +0000 (22:54 -0500)]
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.
Noam Postavsky [Sun, 13 Dec 2015 05:14:44 +0000 (00:14 -0500)]
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'.
Noam Postavsky [Tue, 8 Dec 2015 23:19:02 +0000 (18:19 -0500)]
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'.
Sharif Nassar [Sun, 8 Nov 2015 18:28:16 +0000 (10:28 -0800)]
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.
Noam Postavsky [Sat, 31 Oct 2015 19:54:33 +0000 (15:54 -0400)]
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.
* 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.
Noam Postavsky [Mon, 12 Oct 2015 01:23:36 +0000 (21:23 -0400)]
Simplify string matching.
* yasnippet.el (yas--field-parse-create): Use string-match-p to instead
of save-match-data, anchor regexp with \` (start of string) to instead
of (eq ... 0)
Noam Postavsky [Sun, 11 Oct 2015 16:40:17 +0000 (12:40 -0400)]
Build a single `explored' list.
* yasnippet.el (yas--modes-to-activate): Make helper dfs function
produce the list of modes only by updating a single `explored' list,
instead of building up the list by value and having to remove
duplicated after.
Noam Postavsky [Sun, 11 Oct 2015 16:25:20 +0000 (12:25 -0400)]
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.
* 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.
yas-define-snippets was making assumptions that happended to be true for
its current calls, but could fail if given differently formatted snippet
lists that still meet the docstring description.
Fix #597; use SAVE-FILE to visit compiled snippets
Rename the existing FILE field to LOAD-FILE, and add a new SAVE-FILE to
yas--template struct. Normally they will be the same, but compiled
snippets have only SAVE-FILE because they are loaded by "compiled" code.
* yasnippet.el (yas--template): Remove field file, add load-file and
save-file.
(yas--parse-template): Update snippet-definition list in docstrings.
(yas-define-snippets): Move LOAD-FILE value to SAVE-FILE when compiling.
(yas--template-get-file): New function.
(yas--visit-snippet-file-1, yas-load-snippet-buffer,
yas-load-snippet-buffer-and-close): Use yas--template-load-file,
yas--template-save-file, or yas--template-get-file, as appropriate.
* doc/snippet-organization.org (The =.yas-compiled-snippet.el= file):
Remove caveat that is no longer relevant.
* yasnippet.el (yas--template): New yas--define-snippets-2 constructor
with arguments matching yas-define-snippets format.
(yas--define-snippets-1): Use it.
(yas--update-template): Return TEMPLATE argument.
Noam Postavsky [Tue, 4 Aug 2015 18:20:29 +0000 (14:20 -0400)]
Simplify some code
* yasnippet.el (yas-define-snippets): Modify the list instead of
reconstructing it.
(yas-load-snippet-buffer-and-close): Replace listp and second with
cdr-safe. Use string-prefix-p rather than string-match-p.