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.
João Távora [Mon, 23 Mar 2015 10:10:56 +0000 (10:10 +0000)]
Add useful development assertion
When debugging snippets after M-x toggle-debug-on-error, errors in the
`post-command-hook' might cause `yas--post-command-handler' to be
removed. That's OK, always check that it's there before attempting any
`yas-expand-snippet' calls, since it is essential to check snippet
movement.
* yasnippet.el (yas-expand-snippet): Assert `yas-minor-mode' and
`yas--post-command-handler' active.
Stefan Monnier [Fri, 20 Mar 2015 10:34:33 +0000 (10:34 +0000)]
Getting rid of low-level assumptions in yasnippet
The main thrust is to get rid of the use of the `cl-struct-slots'
property which doesn't exist in Emacs-25 any more.
* yasnippet.el: Update copyright
(yas--template): Change constructor name from
`yas--make-blank-template' to `yas--make-template'
(yas--populate-template): Remove.
(yas--define-snippets-1): Use `yas--make-template'
(yas--define-snippets-1): Use `setf's
(yas-define-menu, yas--define-menu-1, yas-tryout-snippet): Use
`yas--make-template'
Noam Postavsky [Sun, 5 Oct 2014 00:52:58 +0000 (20:52 -0400)]
Signal an error on recursive yas--fallback calls
* yasnippet.el (yas--fallback): let-bind yas-fallback-behavior to
'yas--fallback before actually doing the fallback. Signal an error if
it's 'yas--fallback (indicating we're in an infinte loop).
João Távora [Wed, 20 Aug 2014 20:48:41 +0000 (21:48 +0100)]
Closes #495: Allow symbols as aliases in `yas-snippet-dirs'
* yasnippet.el (yas-installed-snippets-dir): New parameter. Set at
load time from `load-file-name'.
(yas--load-file-name): Removed.
(yas-snippet-dirs): Update docstring. Default value has symbol
`yas-installed-snippets-dir' as an alias to any bundled snippets.
(yas-snippet-dirs): Redesign for new `yas-snippet-dirs' semantics.
João Távora [Wed, 20 Aug 2014 19:23:00 +0000 (20:23 +0100)]
Prevent disabling errors from recent `yas-current-syntaxes` logic
* yasnippet.el (yas--templates-for-key-at-point): Don't error
since this function is called very frequently on TAB. Use new
`yas--warning'.
(yas--warning): New function.
Noam Postavsky [Sun, 10 Aug 2014 17:29:25 +0000 (13:29 -0400)]
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.
Noam Postavsky [Sun, 10 Aug 2014 16:21:47 +0000 (12:21 -0400)]
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.
Noam Postavsky [Wed, 14 May 2014 23:49:11 +0000 (19:49 -0400)]
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.
Noam Postavsky [Sat, 10 May 2014 23:01:32 +0000 (19:01 -0400)]
Don't lose error message when yas-good-grace is t
* yasnippet.el
(yas--eval-lisp-no-saves): Pass error message to message function.
(yas--handle-error): Pass "%s" to error to avoid accidentally
interpreting % in the error message as format codes.
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
Joao Tavora [Fri, 14 Mar 2014 09:55:22 +0000 (09:55 +0000)]
Closes #403: more uniform behaviour for `yas-use-menu'
Suggested by Noam Postavsky, this uses the :visible arg to
`easy-menu-define' to hide the whole "YASnippet" menu according to the
run-time value of `yas-use-menu'. Previously, only the load-time value
was considered and some functions we're noops when `yas-use-menu' was
nil.
The per-mode snippet submenus are now always updated even if
`yas-use-menu' is nil, although they won't be shown until it becomes
non-nil.
* yasnippet.el (yas--minor-mode-menu): Use :visible arg and eval `yas-use-menu'
(yas--update-template): Always update the menu.
(yas--show-menu-p): Always return t if `yas-use-menu' is non-nil and not `abbreviate'
(yas-define-menu): Always define a menu.
(yas-use-menu): Update docstring.