diff --git a/vim/bundle/ultisnips/.gitignore b/vim/bundle/ultisnips/.gitignore index bb169b4..2584ce0 100644 --- a/vim/bundle/ultisnips/.gitignore +++ b/vim/bundle/ultisnips/.gitignore @@ -1,3 +1,4 @@ *.pyc *.swp doc/tags +.ropeproject/ diff --git a/vim/bundle/ultisnips/.travis.yml b/vim/bundle/ultisnips/.travis.yml new file mode 100644 index 0000000..7cd60de --- /dev/null +++ b/vim/bundle/ultisnips/.travis.yml @@ -0,0 +1,29 @@ +language: python + +python: + - 2.7 + - 3.3 + - 3.4 +env: + - VIM_VERSION="74" + - VIM_VERSION="mercurial" + # - VIM_VERSION="NEOVIM" + +install: + # Some of these commands fail transiently. We keep retrying them until they succeed. + - until sudo add-apt-repository ppa:kalakris/tmux -y; do sleep 10; done + - until sudo add-apt-repository ppa:neovim-ppa/unstable -y; do sleep 10; done + - until sudo apt-get update -qq; do sleep 10; done + - until sudo apt-get install -qq -y --force-yes tmux xclip gdb neovim mercurial; do sleep 10; done + - ./travis_install.sh + +script: + - ./travis_test.sh + +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/558acac434012ba838cd + on_success: change # options: [always|never|change] default: always + on_failure: always # options: [always|never|change] default: always + on_start: false # default: false diff --git a/vim/bundle/ultisnips/ChangeLog b/vim/bundle/ultisnips/ChangeLog index 2665648..f8cdc04 100644 --- a/vim/bundle/ultisnips/ChangeLog +++ b/vim/bundle/ultisnips/ChangeLog @@ -1,4 +1,71 @@ -version 2.2: +version 3.1 (TODO: date): + - This is the last release done by @SirVer. The new maintainer of UltiSnips + is @seletskiy. The repository remains https://github.com/SirVer/ultisnips, + so this should not affect any users. This is also the last release to be + published on vim.org. Please follow the master branch on GitHub for the + latest stable version. + - New option `e`: Context aware snippets. This gives very precise and + powerful control over which snippet should be expanded depending on + surrounding code. *UltiSnips-context-snippets* + - New option `m`: Trim whitespace in all snippet lines. + - Very powerful, freely configurable pre/post-expand and post-jump actions + allow for transforming the buffer outside the snippet. *UltiSnips-snippet-actions* + - Automatic triggering of snippets without the need to press the expand + trigger. *UltiSnips-autotrigger* + - Better error reporting for snippet errors including python stacktraces + and listing of executed code. + - Undo is more granular. Each jump and expand is now a separate undo step. + - UltiSnips now emits autocommands on certain events. *UltiSnips-custom-autocommands* + - clearsnippets now clears all snippets below the current priority. This + fits better with the priority system introduced in 3.0. + - snipMate snippets support can be disabled. *UltiSnipsEnableSnipMate* + - UltiSnipsEditSplit got a new value 'context'. *UltiSnipsEditSplit* + - Improved syntax highlighting for snippets filetype. + - Mappings and autocommands are now only established when needed, i.e. when + a snippet is active. This boosts performance outside of snippets. + - New integration with Unite, TagBar, and deoplete. + - New Ctags configuration file for snippet definitions. + - Bug fixes, performance improvements, code cleanups and refactorings. + - No longer supports Vim < 7.4. + +version 3.0 (02-Mar-2014): + - Organisational changes: The project is now hosted on github. Snippets are + now shipped separately - please track honza/vim-snippets. + - UltiSnips is now a drop in replacement for snipMate - it parses snipMate + snippets and expands them emulating snipMates smaller feature set. + - Filetype tab completion for UltiSnipsEdit. + - UltiSnipsEdit now only edits private snippet files. Use UltiSnipsEdit! if + you want to edit shipped files. + - New option 's' which strips trailing whitespace before jumping to next + tabstop + - New option 'a' which converts non-ascii characters into ascii characters + in transformations. + - New keyword in snippet files: priority defines which snippets should + overwrite others. This deprecates the '!' option. + *UltiSnips-adding-snippets* + - Remove common whitespace of visual line selections before inserting in an + indented tabstop. + - Support for overwriting the snippet directory name on a per buffer basis + to support per project snippets. *UltiSnips-snippet-search-path* + - The keymaps for jumping in snippets are now only mapped when a snippet is + active, allowing them to be used for something else otherwise. + - Expanding and jumping no longer overwrites the unnamed register. + - Integration with Valloric/YouCompleteMe and Shougo/neocomplete.vim. + - Other plugins can add sources for snippets to create snippets on the fly. + *UltiSnips-extending* + - Vim functions now indicates if it did any work. + *UltiSnips-trigger-functions* + - For python extensions: UltiSnips adds itself to the sys.path and can be + easily imported if it is available. *UltiSnips-python-module-path* + - A new function giving programmatic access to the snippets currently + available for expansion for other plugins integrating with UltiSnips. + *UltiSnips_SnippetsInCurrentScope* + - New or improved snippets (now in a different repo): all, bib, c, cpp, cs, + d, django, eruby, go, haskell, html, html, htmljinja, java, javascript, + js, ledger, ocaml, perl, php, puppet, python, ruby, scss, sh, tex, vim, + xml, zsh. + +version 2.2 (01-Sep-2012): - Support to silence Python-not-found warnings. *UltiSnips-python-warning* - Matchit support for snippet files. - Improvements to syntax file. @@ -9,17 +76,17 @@ version 2.2: json, html, coffee, coffee_jasmine, javascript_jasmine, ruby, php, markdown. -version 2.1: +version 2.1 (14-Feb-2012): - Python interpolation access to text from visual selection via snip.v. - Support for transformations of ${VISUAL} texts. - New or improved snippets: python, tex, texmath, ruby, rails, html, django - -version 2.0: + +version 2.0 (05-Feb-2012): - Backwards incompatible change: Support for normal mode editing. Snippets are no longer exited when leaving insert mode but only by leaving the text span of the snippets. This allows usage of normal mode commands and autoformatting. It also increases compatibility with other plugins. - - Backwards incompatible change: Changed glob patterns for snippets to + - Backwards incompatible change: Changed glob patterns for snippets to behave more like Vim *UltiSnips-adding-snippets* - Backwards incompatible change: Zero Tabstop is no longer removed in nested snippets @@ -28,21 +95,21 @@ version 2.0: - Full support for :py3. UltiSnips now works with python >= 2.6 or >= 3.2. - New or improved snippets: python, all -version 1.6: +version 1.6 (30-Dec-2011): - Significant speed improvements and a few bugs fixed. - Better handling of non ASCII chars in snippets by assuming UTF-8 encoding when no other information is available. - Contributions for UltiSnips are now also accepted on GitHub: https://github.com/SirVer/ultisnips/ - New or improved snippets: ruby, rails, xhtml -version 1.5: +version 1.5 (24-Sep-2011): - Some critical bug fixes for new vim versions. - New or improved snippets: tex, texmath, python, jinja2, go, puppet, xhtml - - Configuration of search path for snippets *UltiSnips-snippet-search-path* + - Configuration of search path for snippets *UltiSnips-snippet-search-path* - New parser implementation: A little faster, more flexible and less bugged. -version 1.4: - - New or improved snippets: php, html, djangohtml, mako, lua +version 1.4 (17-Jul-2011): + - New or improved snippets: php, html, djangohtml, mako, lua - Snippets are now listed alphabetically by their trigger, no longer in order of appearance - Snippet files are now automatically reloaded when they change. @@ -55,7 +122,7 @@ version 1.4: - snippets definition files now have the filetype 'snippets'. It used to be 'snippet'. -version 1.3: +version 1.3 (14-Feb-2011): - Erlang snippets (g0rdin) - Other VimScripts can now define and immediately expand anonymous snippets ( *UltiSnips_Anon* ) (Ryan Wooden) @@ -68,7 +135,7 @@ version 1.3: missing. (Rupa Deadwyler) - Added UltiSnipsReset and UltiSnipsEdit (Idea by JCEB) -version 1.2: +version 1.2 (24-Aug-2010): - many bugs were fixed - smode mappings for printable characters are now removed before expanding a snippet. This is configurable. *UltiSnips-warning-smappings* @@ -77,17 +144,17 @@ version 1.2: more *UltiSnips-globals* - added support for multi word and regular expression triggers. Very powerful in combination with python interpolation. - - Python interpolation became much more powerful *UltiSnips-python* + - Python interpolation became much more powerful *UltiSnips-python* - added support for clearsnippets command *UltiSnips-clearing-snippets* - added support for option w which is a little more strict than i. - added support for listing of valid triggers. Defaults to . - added support for option i (inword expansion) - extends keyword is now supported on the first line of snippet files. This makes it easy to define special cases, for example cpp extends c: a cpp trigger is useless - in c, but a c trigger is valuable for cpp. + in c, but a c trigger is valuable for cpp. - UltiSnips now adheres to expandtab and tabstop options of vim -version 1.1: +version 1.1 (21-Jul-2009): - Made triggers configurable. You can also use the same trigger for expanding and tabbing. The TextMate configuration and is now possible. @@ -98,4 +165,3 @@ version 1.1: with the same tab trigger ( *UltiSnips-adding-snippets* ) - Support for dotted filetype syntax. Now snippets for more than one filetype can be active ( *UltiSnips-adding-snippets* ) - diff --git a/vim/bundle/ultisnips/README.md b/vim/bundle/ultisnips/README.md new file mode 100644 index 0000000..d03d6eb --- /dev/null +++ b/vim/bundle/ultisnips/README.md @@ -0,0 +1,73 @@ +[![Build Status](https://travis-ci.org/SirVer/ultisnips.svg?branch=master)](https://travis-ci.org/SirVer/ultisnips) +[![Stories in Ready](https://badge.waffle.io/SirVer/ultisnips.png?label=ready&title=Ready)](https://waffle.io/SirVer/ultisnips) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/SirVer/ultisnips?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +UltiSnips +========= + +UltiSnips is the ultimate solution for snippets in Vim. It has tons of features +and is very fast. + +![GIF Demo](https://raw.github.com/SirVer/ultisnips/master/doc/demo.gif) + +In this demo I am editing a python file. I first expand the `#!` snippet, then +the `class` snippet. The completion menu comes from +[YouCompleteMe](https://github.com/Valloric/YouCompleteMe), UltiSnips also +integrates with [neocomplete](https://github.com/Shougo/neocomplete.vim). I can +jump through placeholders and add text while the snippet inserts text in other +places automatically: when I add `Animal` as a base class, `__init__` gets +updated to call the base class constructor. When I add arguments to the +constructor, they automatically get assigned to instance variables. I then +insert my personal snippet for `print` debugging. Note that I left insert mode, +inserted another snippet and went back to add an additional argument to +`__init__` and the class snippet was still active and added another instance +variable. + +The official home of UltiSnips is at . +Please add pull requests and issues there. + +UltiSnips was started in Jun 2009 by @SirVer. In Dec 2015, maintenance was +handed over to @seletskiy. + +Quick Start +----------- + +This assumes you are using [Vundle](https://github.com/gmarik/Vundle.vim). Adapt +for your plugin manager of choice. Put this into your `.vimrc`. + + " Track the engine. + Plugin 'SirVer/ultisnips' + + " Snippets are separated from the engine. Add this if you want them: + Plugin 'honza/vim-snippets' + + " Trigger configuration. Do not use if you use https://github.com/Valloric/YouCompleteMe. + let g:UltiSnipsExpandTrigger="" + let g:UltiSnipsJumpForwardTrigger="" + let g:UltiSnipsJumpBackwardTrigger="" + + " If you want :UltiSnipsEdit to split your window. + let g:UltiSnipsEditSplit="vertical" + +UltiSnips comes with comprehensive +[documentation](https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt). +As there are more options and tons of features I suggest you at least skim it. + +Screencasts +----------- + +From a gentle introduction to really advanced in a few minutes: The blog posts +of the screencasts contain more advanced examples of the things discussed in the +videos. + +- [Episode 1: What are snippets and do I need them?](http://www.sirver.net/blog/2011/12/30/first-episode-of-ultisnips-screencast/) +- [Episode 2: Creating Basic Snippets](http://www.sirver.net/blog/2012/01/08/second-episode-of-ultisnips-screencast/) +- [Episode 3: What's new in version 2.0](http://www.sirver.net/blog/2012/02/05/third-episode-of-ultisnips-screencast/) +- [Episode 4: Python Interpolation](http://www.sirver.net/blog/2012/03/31/fourth-episode-of-ultisnips-screencast/) + +Also the excellent [Vimcasts](http://vimcasts.org) dedicated three episodes to +UltiSnips: + +- [Meet UltiSnips](http://vimcasts.org/episodes/meet-ultisnips/) +- [Using Python interpolation in UltiSnips snippets](http://vimcasts.org/episodes/ultisnips-python-interpolation/) +- [Using selected text in UltiSnips snippets](http://vimcasts.org/episodes/ultisnips-visual-placeholder/) diff --git a/vim/bundle/ultisnips/README.rst b/vim/bundle/ultisnips/README.rst deleted file mode 100644 index a5c261f..0000000 --- a/vim/bundle/ultisnips/README.rst +++ /dev/null @@ -1,22 +0,0 @@ -UltiSnips -========= - -This is the official repository for UltiSnips. Send Pull request to -SirVer/ultisnips, not the automatic clone from vim-scripts or any -other fork of this project. - -Screencasts ------------ - -The blog posts of the screencasts contain more advanced examples of the things -discussed in the videos. - -* `Episode 1: What are snippets and do I need them?`__ -* `Episode 2: Creating Basic Snippets`__ -* `Episode 3: What's new in version 2.0`__ -* `Episode 4: Python Interpolation`__ - -__ http://www.sirver.net/blog/2011/12/30/first-episode-of-ultisnips-screencast/ -__ http://www.sirver.net/blog/2012/01/08/second-episode-of-ultisnips-screencast/ -__ http://www.sirver.net/blog/2012/02/05/third-episode-of-ultisnips-screencast/ -__ http://www.sirver.net/blog/2012/03/31/fourth-episode-of-ultisnips-screencast/ diff --git a/vim/bundle/ultisnips/UltiSnips/README b/vim/bundle/ultisnips/UltiSnips/README deleted file mode 100644 index eafd086..0000000 --- a/vim/bundle/ultisnips/UltiSnips/README +++ /dev/null @@ -1,21 +0,0 @@ -This directory contains the main scripts that come bundled with UltiSnips. - -Standing On The Shoulders of Giants -=================================== - -The snippets have been collected from various other project which I want to -express my gratitude for. My main source for inspiration where the following -two projects: - - TextMate: http://svn.textmate.org/trunk/Bundles/ - SnipMate: http://code.google.com/p/snipmate/ - -All snippets from those sources were copied and cleaned up, so that they are - - not using shell script, only python (so they are cross platform compatible) - - not using any feature that UltiSnips doesn't offer - -UltiSnips has seen contributions by various individuals. Those contributions -have been merged into this collection seamlessly and without further comments. - --- vim:ft=rst:nospell: - diff --git a/vim/bundle/ultisnips/UltiSnips/all.snippets b/vim/bundle/ultisnips/UltiSnips/all.snippets deleted file mode 100644 index 085440a..0000000 --- a/vim/bundle/ultisnips/UltiSnips/all.snippets +++ /dev/null @@ -1,120 +0,0 @@ -# This file contains snippets that are always defined. I personally -# have snippets for signatures and often needed texts - -priority -50 - -############## -# NICE BOXES # -############## -global !p -import string, vim - -""" Maps a filetype to comment format used for boxes. -Automatically filled during usage""" -_commentDict = { } - -def _parse_comments(s): - """ Parses vim's comments option to extract comment format """ - i = iter(s.split(",")) - - rv = [] - try: - while True: - # get the flags and text of a comment part - flags, text = next(i).split(':', 1) - - if len(flags) == 0: - rv.append((text, text, text, "")) - # parse 3-part comment, but ignore those with O flag - elif flags[0] == 's' and 'O' not in flags: - ctriple = [] - indent = "" - - if flags[-1] in string.digits: - indent = " " * int(flags[-1]) - ctriple.append(text) - - flags,text = next(i).split(':', 1) - assert(flags[0] == 'm') - ctriple.append(text) - - flags,text = next(i).split(':', 1) - assert(flags[0] == 'e') - ctriple.append(text) - ctriple.append(indent) - - rv.append(ctriple) - elif flags[0] == 'b': - if len(text) == 1: - rv.insert(0, (text,text,text, "")) - except StopIteration: - return rv - -def _get_comment_format(): - """ Returns a 4-element tuple representing the comment format for - the current file. """ - return _parse_comments(vim.eval("&comments"))[0] - - -def make_box(twidth, bwidth=None): - b, m, e, i = _get_comment_format() - bwidth_inner = bwidth - 3 - max(len(b), len(i + e)) if bwidth else twidth + 2 - sline = b + m + bwidth_inner * m[0] + 2 * m[0] - nspaces = (bwidth_inner - twidth) // 2 - mlines = i + m + " " + " " * nspaces - mlinee = " " + " "*(bwidth_inner - twidth - nspaces) + m - eline = i + m + bwidth_inner * m[0] + 2 * m[0] + e - return sline, mlines, mlinee, eline - -def foldmarker(): - "Return a tuple of (open fold marker, close fold marker)" - return vim.eval("&foldmarker").split(",") - -endglobal - -snippet box "A nice box with the current comment symbol" b -`!p -box = make_box(len(t[1])) -snip.rv = box[0] + '\n' + box[1] -`${1:content}`!p -box = make_box(len(t[1])) -snip.rv = box[2] + '\n' + box[3]` -$0 -endsnippet - -snippet bbox "A nice box over the full width" b -`!p -width = int(vim.eval("&textwidth")) or 71 -box = make_box(len(t[1]), width) -snip.rv = box[0] + '\n' + box[1] -`${1:content}`!p -box = make_box(len(t[1]), width) -snip.rv = box[2] + '\n' + box[3]` -$0 -endsnippet - -snippet fold "Insert a vim fold marker" b -`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]`${2:1} `!p snip.rv = _get_comment_format()[2]` -endsnippet - -snippet foldc "Insert a vim fold close marker" b -`!p snip.rv = _get_comment_format()[0]` ${2:1}`!p snip.rv = foldmarker()[1]` `!p snip.rv = _get_comment_format()[2]` -endsnippet - -snippet foldp "Insert a vim fold marker pair" b -`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]` `!p snip.rv = _get_comment_format()[2]` -${2:${VISUAL:Content}} -`!p snip.rv = _get_comment_format()[0]` `!p snip.rv = foldmarker()[1]` $1 `!p snip.rv = _get_comment_format()[2]` -endsnippet - -########################## -# LOREM IPSUM GENERATORS # -########################## -snippet lorem "Lorem Ipsum - 50 Words" b -Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod -tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At -vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, -no sea takimata sanctus est Lorem ipsum dolor sit amet. -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/bib.snippets b/vim/bundle/ultisnips/UltiSnips/bib.snippets deleted file mode 100644 index c9b8df5..0000000 --- a/vim/bundle/ultisnips/UltiSnips/bib.snippets +++ /dev/null @@ -1,52 +0,0 @@ -priority -50 - -snippet online "Online resource" b -@online{${1:name}, - author={${2:author}}, - title={${3:title}}, - date={${4:date}}, - url={${5:url}} -} -$0 -endsnippet - -snippet article "Article reference" b -@article{${1:name}, - author={${2:author}}, - title={${3:title}}, - journaltitle={${4:journal}}, - volume={${5:NN}}, - number={${6:NN}}, - year={${7:YYYY}}, - pages={${8:NN}--${9:NN}} -} -$0 -endsnippet - -snippet book "Book reference" b -@book{${1:name}, - author={${2:author}}, - title={${3:title}}, - subtitle={${4:subtitle}}, - year={${5:YYYY}}, - location={${6:somewhere}}, - publisher={${7:publisher}}, - pages={${8:NN}--${9:NN}} -} -$0 -endsnippet - -snippet inb "In Book reference" b -@inbook{${1:name}, - author={${2:author}}, - title={${3:title}}, - subtitle={${4:subtitle}}, - booktitle={${5:book}}, - editor={${6:editor}}, - year={${7:YYYY}}, - location={${8:somewhere}}, - publisher={${9:publisher}}, - pages={${10:NN}--${11:NN}} -} -$0 -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/bindzone.snippets b/vim/bundle/ultisnips/UltiSnips/bindzone.snippets deleted file mode 100644 index b8ab0df..0000000 --- a/vim/bundle/ultisnips/UltiSnips/bindzone.snippets +++ /dev/null @@ -1,29 +0,0 @@ -priority -50 - -global !p -def newsoa(): - import datetime - now = datetime.datetime.now() - # return standard SOA formatted serial for today - return now.strftime("%Y%m%d00") -endglobal - -snippet zone "Bootstrap a new Bind zonefile" b -$TTL 86400 -@ IN SOA ${1:example.net}. ${2:hostmaster.$1}.( - `!p snip.rv = newsoa()`; serial - 21600; refresh every 6 hours - 3600; retry after one hour - 604800; expire after a week - 86400 ); minimum TTL of 1 day - - IN NS ns01.$1. - IN MX 10 mail.$1. - -ns01.$1 IN A -mail.$1 IN A -endsnippet - -snippet A "Insert A Record" b -${1:hostname} IN A ${2:ip} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/c.snippets b/vim/bundle/ultisnips/UltiSnips/c.snippets deleted file mode 100644 index 5b8eae8..0000000 --- a/vim/bundle/ultisnips/UltiSnips/c.snippets +++ /dev/null @@ -1,155 +0,0 @@ -########################################################################### -# TextMate Snippets # -########################################################################### - -priority -50 - -snippet def "#define ..." -#define ${1} -endsnippet - -snippet ifndef "#ifndef ... #define ... #endif" -#ifndef ${1/([A-Za-z0-9_]+).*/$1/} -#define ${1:SYMBOL} ${2:value} -#endif -endsnippet - -snippet #if "#if #endif" b -#if ${1:0} -${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}} -#endif -endsnippet - -snippet inc "#include local header (inc)" -#include "${1:`!p snip.rv = snip.basename + '.h'`}" -endsnippet - -snippet Inc "#include <> (Inc)" -#include <${1:.h}> -endsnippet - -snippet mark "#pragma mark (mark)" -#if 0 -${1:#pragma mark - -}#pragma mark $2 -#endif - -$0 -endsnippet - -snippet main "main() (main)" -int main(int argc, char *argv[]) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} - return 0; -} -endsnippet - -snippet for "for loop (for)" -for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet fori "for int loop (fori)" -for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet enum "Enumeration" -enum ${1:name} { $0 }; -endsnippet - -snippet once "Include header once only guard" -#ifndef ${1:`!p -if not snip.c: - import random, string - name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper() - rand = ''.join(random.sample(string.ascii_letters+string.digits, 8)) - snip.rv = ('%s_%s' % (name,rand)).upper() -else: - snip.rv = snip.c`} -#define $1 - -${0} - -#endif /* end of include guard: $1 */ - -endsnippet - -snippet td "Typedef" -typedef ${1:int} ${2:MyCustomType}; -endsnippet - -snippet wh "while loop" -while(${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet do "do...while loop (do)" -do { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} while(${1:/* condition */}); -endsnippet - -snippet fprintf "fprintf ..." -fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\);)/} -endsnippet - -snippet if "if .. (if)" -if (${1:/* condition */}) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet el "else .. (else)" -else { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet eli "else if .. (eli)" -else if (${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet ife "if .. else (ife)" -if (${1:/* condition */}) -{ - ${2:/* code */} -} -else -{ - ${3:/* else */} -} -endsnippet - -snippet printf "printf .. (printf)" -printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/} -endsnippet - -snippet st "struct" -struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`} -{ - ${0:/* data */} -}; -endsnippet - -snippet fun "function" b -${1:void} ${2:function_name}(${3}) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -} -endsnippet - -snippet fund "function declaration" b -${1:void} ${2:function_name}(${3}); -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/coffee.snippets b/vim/bundle/ultisnips/UltiSnips/coffee.snippets deleted file mode 100644 index 68fe31c..0000000 --- a/vim/bundle/ultisnips/UltiSnips/coffee.snippets +++ /dev/null @@ -1,91 +0,0 @@ -# From the TextMate bundle - -priority -50 - -snippet fun "Function" b -${1:name} = (${2:args}) -> - ${0:# body...} -endsnippet - -snippet bfun "Function (bound)" b -${1:(${2:args}) }=> - ${0:# body...} -endsnippet - -snippet if "If" b -if ${1:condition} - ${0:# body...} -endsnippet - -snippet ife "If .. Else" b -if ${1:condition} - ${2:# body...} -else - ${3:# body...} -endsnippet - -snippet elif "Else if" b -else if ${1:condition} - ${0:# body...} -endsnippet - -snippet ifte "Ternary if" b -if ${1:condition} then ${2:value} else ${3:other} -endsnippet - -snippet unl "Unless" b -${1:action} unless ${2:condition} -endsnippet - -snippet fora "Array Comprehension" b -for ${1:name} in ${2:array} - ${0:# body...} -endsnippet - -snippet foro "Object Comprehension" b -for ${1:key}, ${2:value} of ${3:Object} - ${0:# body...} -endsnippet - -snippet forr "Range Comprehension (inclusive)" b -for ${1:name} in [${2:start}..${3:finish}]${4: by ${5:step}} - ${0:# body...} -endsnippet - -snippet forrex "Range Comprehension (exclusive)" b -for ${1:name} in [${2:start}...${3:finish}]${4: by ${5:step}} - ${0:# body...} -endsnippet - -snippet swi "Switch" b -switch ${1:object} - when ${2:value} - ${0:# body...} -endsnippet - -snippet cla "Class" b -class ${1:ClassName}${2: extends ${3:Ancestor}} - - ${4:constructor: (${5:args}) -> - ${6:# body...}} - $7 -endsnippet - -snippet try "Try .. Catch" b -try - $1 -catch ${2:error} - $3 -endsnippet - -snippet req "Require" b -${1/^'?(\w+)'?$/\L$1\E/} = require(${1:'${2:sys}'}) -endsnippet - -snippet # "Interpolated Code" -#{$1}$0 -endsnippet - -snippet log "Log" b -console.log ${1:"${2:msg}"} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/coffee_jasmine.snippets b/vim/bundle/ultisnips/UltiSnips/coffee_jasmine.snippets deleted file mode 100644 index 0dd35cd..0000000 --- a/vim/bundle/ultisnips/UltiSnips/coffee_jasmine.snippets +++ /dev/null @@ -1,166 +0,0 @@ -# -# CoffeeScript versions -- adapted from the JS TextMate bundle + additions -# for some jasmine-jquery matchers -# -priority -50 - -extends coffee - -priority -49 - -snippet des "Describe (coffee)" b -describe '${1:description}', -> - $0 -endsnippet - -snippet it "it (coffee)" b -it '${1:description}', -> - $0 -endsnippet - -snippet bef "before each (coffee)" b -beforeEach -> - $0 -endsnippet - -snippet aft "after each (coffee)" b -afterEach -> - $0 -endsnippet - -snippet any "any (coffee)" b -jasmine.any($1) -endsnippet - -snippet ru "runs (coffee)" b -runs -> - $0 -endsnippet - -snippet wa "waits (coffee)" b -waits($1) -endsnippet - -snippet ex "expect (coffee)" b -expect(${1:target})$0 -endsnippet - -snippet ee "expect to equal (coffee)" b -expect(${1:target}).toEqual(${2:value}) -endsnippet - -snippet em "expect to match (coffee)" b -expect(${1:target}).toMatch(${2:pattern}) -endsnippet - -snippet eha "expect to have attribute (coffee)" b -expect(${1:target}).toHaveAttr('${2:attr}'${3:, '${4:value}'}) -endsnippet - -snippet et "expect to be truthy (coffee)" b -expect(${1:target}).toBeTruthy() -endsnippet - -snippet ef "expect to be falsy (coffee)" b -expect(${1:target}).toBeFalsy() -endsnippet - -snippet ed "expect to be defined (coffee)" b -expect(${1:target}).toBeDefined() -endsnippet - -snippet en "expect to be null (coffee)" b -expect(${1:target}).toBeNull() -endsnippet - -snippet ec "expect to contain (coffee)" b -expect(${1:target}).toContain(${2:value}) -endsnippet - -snippet ev "expect to be visible (coffee)" b -expect(${1:target}).toBeVisible() -endsnippet - -snippet eh "expect to be hidden (coffee)" b -expect(${1:target}).toBeHidden() -endsnippet - -snippet notx "expect not (coffee)" b -expect(${1:target}).not$0 -endsnippet - -snippet note "expect not to equal (coffee)" b -expect(${1:target}).not.toEqual(${2:value}) -endsnippet - -snippet notm "expect not to match (coffee)" b -expect(${1:target}).not.toMatch(${2:pattern}) -endsnippet - -snippet notha "expect to not have attribute (coffee)" b -expect(${1:target}).not.toHaveAttr('${2:attr}'${3:, '${4:value}'}) -endsnippet - -snippet nott "expect not to be truthy (coffee)" b -expect(${1:target}).not.toBeTruthy() -endsnippet - -snippet notf "expect not to be falsy (coffee)" b -expect(${1:target}).not.toBeFalsy() -endsnippet - -snippet notd "expect not to be defined (coffee)" b -expect(${1:target}).not.toBeDefined() -endsnippet - -snippet notn "expect not to be null (coffee)" b -expect(${1:target}).not.toBeNull() -endsnippet - -snippet notc "expect not to contain (coffee)" b -expect(${1:target}).not.toContain(${2:value}) -endsnippet - -snippet notv "expect not to be visible (coffee)" b -expect(${1:target}).not.toBeVisible() -endsnippet - -snippet noth "expect not to be hidden (coffee)" b -expect(${1:target}).not.toBeHidden() -endsnippet - -snippet s "spy on (coffee)" b -spyOn(${1:object}, "${2:method}")$0 -endsnippet - -snippet sr "spy on and return (coffee)" b -spyOn(${1:object}, "${2:method}").andReturn(${3:arguments}) -endsnippet - -snippet st "spy on and throw (coffee)" b -spyOn(${1:object}, "${2:method}").andThrow(${3:exception}) -endsnippet - -snippet sct "spy on and call through (coffee)" b -spyOn(${1:object}, "${2:method}").andCallThrough() -endsnippet - -snippet scf "spy on and call fake (coffee)" b -spyOn(${1:object}, "${2:method}").andCallFake(${3:function}) -endsnippet - -snippet esc "expect was called (coffee)" b -expect(${1:target}).wasCalled() -endsnippet - -snippet escw "expect was called with (coffee)" b -expect(${1:target}).wasCalledWith(${2:arguments}) -endsnippet - -snippet notsc "expect was not called (coffee)" b -expect(${1:target}).wasNotCalled() -endsnippet - -snippet noscw "expect was not called with (coffee)" b -expect(${1:target}).wasNotCalledWith(${2:arguments}) -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/cpp.snippets b/vim/bundle/ultisnips/UltiSnips/cpp.snippets deleted file mode 100644 index 3d79a64..0000000 --- a/vim/bundle/ultisnips/UltiSnips/cpp.snippets +++ /dev/null @@ -1,57 +0,0 @@ -priority -50 - -extends c - -# We want to overwrite everything in parent ft. -priority -49 - -########################################################################### -# TextMate Snippets # -########################################################################### -snippet beginend "$1.begin(), $1.end() (beginend)" -${1:v}${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}begin(), $1${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}end() -endsnippet - -snippet cl "class .. (class)" -class ${1:`!p snip.rv = snip.basename or "name"`} -{ -public: - ${1/(\w+).*/$1/} (${2:arguments}); - virtual ~${1/(\w+).*/$1/} (); - -private: - ${0:/* data */} -}; -endsnippet - -snippet ns "namespace .. (namespace)" -namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`} -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} -}${1/.+/ \/* /m}$1${1/.+/ *\/ /m} -endsnippet - -snippet readfile "read file (readF)" -std::vector v; -if (FILE *fp = fopen(${1:"filename"}, "r")) -{ - char buf[1024]; - while(size_t len = fread(buf, 1, sizeof(buf), fp)) - v.insert(v.end(), buf, buf + len); - fclose(fp); -} -endsnippet - -snippet map "std::map (map)" -std::map<${1:key}, ${2:value}> map$0; -endsnippet - -snippet vector "std::vector (v)" -std::vector<${1:char}> v$0; -endsnippet - -snippet tp "template (template)" -template -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/cs.snippets b/vim/bundle/ultisnips/UltiSnips/cs.snippets deleted file mode 100644 index aca245e..0000000 --- a/vim/bundle/ultisnips/UltiSnips/cs.snippets +++ /dev/null @@ -1,328 +0,0 @@ -####################################################################### -# C# Snippets for UltiSnips # -####################################################################### - -priority -50 - -######################### -# classes and structs # -######################### - -snippet namespace "namespace" b -namespace ${1:MyNamespace} -{ - ${VISUAL}$0 -} -endsnippet - -snippet class "class" w -class ${1:MyClass} -{ - $0 -} -endsnippet - -snippet struct "struct" w -struct ${1:MyStruct} -{ - $0 -} -endsnippet - -snippet interface "interface" w -interface I${1:Interface} -{ - $0 -} -endsnippet - -snippet enum "enumeration" b -enum ${1:MyEnum} { ${2:Item} }; -endsnippet - - -############ -# Main() # -############ - -snippet sim "static int main" b -static int Main(string[] args) -{ - $0 -} -endsnippet - -snippet svm "static void main" b -static void Main(string[] args) -{ - $0 -} -endsnippet - - -################ -# properties # -################ - -snippet prop "Simple property declaration" b -public ${1:int} ${2:MyProperty} { get; set; } -endsnippet - -snippet propfull "Full property declaration" b -private ${1:int} ${2:_myProperty}; - -public $1 ${3:MyProperty} -{ - get { return $2; } - set { $2 = value; } -} -endsnippet - -snippet propg "Property with a private setter" b -public ${1:int} ${2:MyProperty} { get; private set; } -endsnippet - - -############ -# blocks # -############ - -snippet #if "#if #endif" b -#if ${1:DEBUG} -${VISUAL}$0 -#endif -endsnippet - -snippet #region "#region #endregion" b -#region ${1:Region} -${VISUAL}$0 -#endregion -endsnippet - - -########### -# loops # -########### - -snippet for "for loop" b -for (int ${1:i} = 0; $1 < ${2:10}; $1++) -{ - ${VISUAL}$0 -} -endsnippet - -snippet forr "for loop (reverse)" b -for (int ${1:i} = ${2:10}; $1 >= 0; $1--) -{ - ${VISUAL}$0 -} -endsnippet - -snippet foreach "foreach loop" b -foreach (${3:var} ${2:item} in ${1:items}) -{ - ${VISUAL}$0 -} -endsnippet - -snippet while "while loop" b -while (${1:true}) -{ - ${VISUAL}$0 -} -endsnippet - -snippet do "do loop" b -do -{ - ${VISUAL}$0 -} while (${1:true}); -endsnippet - - -############### -# branching # -############### - -snippet if "if statement" b -if ($1) -{ - ${VISUAL}$0 -} -endsnippet - -snippet ife "if else statement" b -if ($1) -{ - ${VISUAL}$0 -} -else -{ -} -endsnippet - -snippet elif "else if" b -else if ($1) -{ - $0 -} -endsnippet - -snippet elseif "else if" b -else if ($1) -{ - $0 -} -endsnippet - -snippet ifnn "if not null" b -if ($1 != null) -{ - ${VISUAL}$0 -} -endsnippet - -snippet switch "switch statement" b -switch (${1:statement}) -{ - case ${2:value}: - break; - - default: - $0break; -} -endsnippet - -snippet case "case" b -case ${1:value}: - $2 - break; -endsnippet - - -############## -# wrappers # -############## - -snippet using "using statement" b -using (${1:resource}) -{ - ${VISUAL}$0 -} -endsnippet - -snippet unchecked "unchecked block" b -unchecked -{ - ${VISUAL}$0 -} -endsnippet - -snippet checked "checked block" b -checked -{ - ${VISUAL}$0 -} -endsnippet - -snippet unsafe "unsafe" b -unsafe -{ - ${VISUAL}$0 -} -endsnippet - - -######################## -# exception handling # -######################## - -snippet try "try catch block" b -try -{ - ${VISUAL}$0 -} -catch (${1:Exception} ${2:e}) -{ - throw; -} -endsnippet - -snippet tryf "try finally block" b -try -{ - ${VISUAL}$0 -} -finally -{ -} -endsnippet - -snippet throw "throw" -throw new ${1}Exception("${2}"); -endsnippet - - -########## -# LINQ # -########## - -snippet from "LINQ syntax" b -var ${1:seq} = - from ${2:item1} in ${3:items1} - join ${4:item2} in ${5:items2} on $2.${6:prop1} equals $4.${7:prop2} - select ${8:$2.prop3} - where ${9:clause} -endsnippet - - -############################ -# feedback and debugging # -############################ - -snippet da "Debug.Assert" b -Debug.Assert(${1:true}); -endsnippet - -snippet cw "Console.WriteLine" b -Console.WriteLine("$1"); -endsnippet - -# as you first type comma-separated parameters on the right, {n} values appear in the format string -snippet cwp "Console.WriteLine with parameters" b -Console.WriteLine("${2:`!p -snip.rv = ' '.join(['{' + str(i) + '}' for i in range(t[1].count(','))]) -`}"${1:, something}); -endsnippet - -snippet mbox "Message box" b -MessageBox.Show("${1:message}"); -endsnippet - - -################## -# full methods # -################## - -snippet equals "Equals method" b -public override bool Equals(object obj) -{ - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - $0 - return base.Equals(obj); -} -endsnippet - - -############## -# comments # -############## - -snippet /// "XML comment" b -/// -/// $1 -/// -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/css.snippets b/vim/bundle/ultisnips/UltiSnips/css.snippets deleted file mode 100644 index 32c3f21..0000000 --- a/vim/bundle/ultisnips/UltiSnips/css.snippets +++ /dev/null @@ -1,407 +0,0 @@ -########################################################################### -# Most of these came from TextMate # -########################################################################### - -priority -50 - -snippet ! "!important CSS (!)" -${1:!important} -endsnippet - -snippet fixed "Fixed Position Bottom 100% wide IE6" -${2:bottom: auto;}top: expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-${1:THE HEIGHT OF THIS THING IN PIXELS})); -${3:left: expression(eval(document.documentElement.scrollLeft)); -}${4:width: expression(eval(document.documentElement.clientWidth));}$0 -endsnippet - -snippet background "background-attachment: scroll:fixed (background)" -background-attachment: ${1:scroll/fixed};$0 -endsnippet - -snippet background "background-color: color-hex (background)" -background-color: #${1:DDD};$0 -endsnippet - -snippet background "background-color: color-name (background)" -background-color: ${1:red};$0 -endsnippet - -snippet background "background-color: color-rgb (background)" -background-color: rgb(${1:255},${2:255},${3:255});$0 -endsnippet - -snippet background "background-color: transparent (background)" -background-color: transparent;$0 -endsnippet - -snippet background "background-image: none (background)" -background-image: none;$0 -endsnippet - -snippet background "background-image: url (background)" -background-image: url($1);$0 -endsnippet - -snippet background "background-position: position (background)" -background-position: ${1:top left/top center/top right/center left/center center/center right/bottom left/bottom center/bottom right/x-% y-%/x-pos y-pos};$0 -endsnippet - -snippet background "background-repeat: r:r-x:r-y:n-r (background)" -background-repeat: ${1:repeat/repeat-x/repeat-y/no-repeat};$0 -endsnippet - -snippet background "background: color image repeat attachment position (background)" -background:${6: #${1:DDD}} url($2) ${3:repeat/repeat-x/repeat-y/no-repeat} ${4:scroll/fixed} ${5:top left/top center/top right/center left/center center/center right/bottom left/bottom center/bottom right/x-% y-%/x-pos y-pos};$0 -endsnippet - -snippet border "border-bottom-color: size style color (border)" -border-bottom-color: #${1:999};$0 -endsnippet - -snippet border "border-bottom-style: size style color (border)" -border-bottom-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0 -endsnippet - -snippet border "border-bottom-width: size style color (border)" -border-bottom-width: ${1:1}px ${2:solid} #${3:999};$0 -endsnippet - -snippet border "border-bottom: size style color (border)" -border-bottom: ${1:1}px ${2:solid} #${3:999};$0 -endsnippet - -snippet border "border-color: color (border)" -border-color: ${1:999};$0 -endsnippet - -snippet border "border-left-color: color (border)" -border-right-color: #${1:999};$0 -endsnippet - -snippet border "border-left-style: style (border)" -border-left-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0 -endsnippet - -snippet border "border-left-width: size (border)" -border-left-width: ${1:1}px -endsnippet - -snippet border "border-left: size style color (border)" -border-left: ${1:1}px ${2:solid} #${3:999};$0 -endsnippet - -snippet border "border-right-color: color (border)" -border-right-color: #${1:999};$0 -endsnippet - -snippet border "border-right-style: style (border)" -border-right-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0 -endsnippet - -snippet border "border-right-width: size (border)" -border-right-width: ${1:1}px -endsnippet - -snippet border "border-right: size style color (border)" -border-right: ${1:1}px ${2:solid} #${3:999};$0 -endsnippet - -snippet border "border-style: style (border)" -border-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0 -endsnippet - -snippet border "border-top-color: color (border)" -border-top-color: #${1:999};$0 -endsnippet - -snippet border "border-top-style: style (border)" -border-top-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0 -endsnippet - -snippet border "border-top-width: size (border)" -border-top-width: ${1:1}px -endsnippet - -snippet border "border-top: size style color (border)" -border-top: ${1:1}px ${2:solid} #${3:999};$0 -endsnippet - -snippet border "border-width: width (border)" -border-width: ${1:1px};$0 -endsnippet - -snippet border "border: size style color (border)" -border: ${1:1px} ${2:solid} #${3:999};$0 -endsnippet - -snippet clear "clear: value (clear)" -clear: ${1:left/right/both/none};$0 -endsnippet - -snippet color "color: color-hex (color)" -color: #${1:DDD};$0 -endsnippet - -snippet color "color: color-name (color)" -color: ${1:red};$0 -endsnippet - -snippet color "color: color-rgb (color)" -color: rgb(${1:255},${2:255},${3:255});$0 -endsnippet - -snippet cursor "cursor: type (cursor)" -cursor: ${1:default/auto/crosshair/pointer/move/*-resize/text/wait/help};$0 -endsnippet - -snippet cursor "cursor: url (cursor)" -cursor: url($1);$0 -endsnippet - -snippet direction "direction: ltr|rtl (direction)" -direction: ${1:ltr|rtl};$0 -endsnippet - -snippet display "display: block (display)" -display: block;$0 -endsnippet - -snippet display "display: common-types (display)" -display: ${1:none/inline/block/list-item/run-in/compact/marker};$0 -endsnippet - -snippet display "display: inline (display)" -display: inline;$0 -endsnippet - -snippet display "display: table-types (display)" -display: ${1:table/inline-table/table-row-group/table-header-group/table-footer-group/table-row/table-column-group/table-column/table-cell/table-caption};$0 -endsnippet - -snippet float "float: left:right:none (float)" -float: ${1:left/right/none};$0 -endsnippet - -snippet font "font-family: family (font)" -font-family: ${1:Arial, "MS Trebuchet"}, ${2:sans-}serif;$0 -endsnippet - -snippet font "font-size: size (font)" -font-size: ${1:100%};$0 -endsnippet - -snippet font "font-style: normal:italic:oblique (font)" -font-style: ${1:normal/italic/oblique};$0 -endsnippet - -snippet font "font-variant: normal:small-caps (font)" -font-variant: ${1:normal/small-caps};$0 -endsnippet - -snippet font "font-weight: weight (font)" -font-weight: ${1:normal/bold};$0 -endsnippet - -snippet font "font: style variant weight size:line-height font -family (font)" -font: ${1:normal/italic/oblique} ${2:normal/small-caps} ${3:normal/bold} ${4:1em/1.5em} ${5:Arial}, ${6:sans-}serif;$0 -endsnippet - -snippet font "font: size font (font)" -font: ${1:75%} ${2:"Lucida Grande", "Trebuchet MS", Verdana,} ${3:sans-}serif;$0 -endsnippet - -snippet letter "letter-spacing: length-em (letter)" -letter-spacing: $1em;$0 -endsnippet - -snippet letter "letter-spacing: length-px (letter)" -letter-spacing: $1px;$0 -endsnippet - -snippet list "list-style-image: url (list)" -list-style-image: url($1);$0 -endsnippet - -snippet list "list-style-position: pos (list)" -list-style-position: ${1:inside/outside};$0 -endsnippet - -snippet list "list-style-type: asian (list)" -list-style-type: ${1:cjk-ideographic/hiragana/katakana/hiragana-iroha/katakana-iroha};$0 -endsnippet - -snippet list "list-style-type: marker(list)" -list-style-type: ${1:none/disc/circle/square};$0 -endsnippet - -snippet list "list-style-type: numeric (list)" -list-style-type: ${1:decimal/decimal-leading-zero/zero};$0 -endsnippet - -snippet list "list-style-type: other (list)" -list-style-type: ${1:hebrew/armenian/georgian};$0 -endsnippet - -snippet list "list-style-type: roman-alpha-greek (list)" -list-style-type: ${1:lower-roman/upper-roman/lower-alpha/upper-alpha/lower-greek/lower-latin/upper-latin};$0 -endsnippet - -snippet list "list-style: type position image (list)" -list-style: ${1:none/disc/circle/square/decimal/zero} ${2:inside/outside} url($3);$0 -endsnippet - -snippet margin "margin-bottom: length (margin)" -margin-bottom: ${1:20px};$0 -endsnippet - -snippet margin "margin-left: length (margin)" -margin-left: ${1:20px};$0 -endsnippet - -snippet margin "margin-right: length (margin)" -margin-right: ${1:20px};$0 -endsnippet - -snippet margin "margin-top: length (margin)" -margin-top: ${1:20px};$0 -endsnippet - -snippet margin "margin: all (margin)" -margin: ${1:20px};$0 -endsnippet - -snippet margin "margin: T R B L (margin)" -margin: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0 -endsnippet - -snippet margin "margin: V H (margin)" -margin: ${1:20px} ${2:0px};$0 -endsnippet - -snippet marker "marker-offset: auto (marker)" -marker-offset: auto;$0 -endsnippet - -snippet marker "marker-offset: length (marker)" -marker-offset: ${1:10px};$0 -endsnippet - -snippet overflow "overflow: type (overflow)" -overflow: ${1:visible/hidden/scroll/auto};$0 -endsnippet - -snippet padding "padding-bottom: length (margin)" -padding-bottom: ${1:20px};$0 -endsnippet - -snippet padding "padding-left: length (margin)" -padding-left: ${1:20px};$0 -endsnippet - -snippet padding "padding-right: length (margin)" -padding-right: ${1:20px};$0 -endsnippet - -snippet padding "padding-top: length (margin)" -padding-top: ${1:20px};$0 -endsnippet - -snippet padding "padding: T R B L (padding)" -padding: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0 -endsnippet - -snippet padding "padding: V H (padding)" -padding: ${1:20px} ${2:0px};$0 -endsnippet - -snippet padding "padding: all (padding)" -padding: ${1:20px};$0 -endsnippet - -snippet position "position: type (position)" -position: ${1:static/relative/absolute/fixed};$0 -endsnippet - -snippet { "properties { } ( } )" -{ - /* $1 */ - $0 - -endsnippet - -snippet scrollbar "scrollbar" -scrollbar-base-color: ${1:#CCCCCC};${2: -scrollbar-arrow-color: ${3:#000000}; -scrollbar-track-color: ${4:#999999}; -scrollbar-3dlight-color: ${5:#EEEEEE}; -scrollbar-highlight-color: ${6:#FFFFFF}; -scrollbar-face-color: ${7:#CCCCCC}; -scrollbar-shadow-color: ${9:#999999}; -scrollbar-darkshadow-color: ${8:#666666};} -endsnippet - -snippet selection "selection" -$1::-moz-selection, -$1::selection { - color: ${2:inherit}; - background: ${3:inherit}; -} -endsnippet - -snippet text "text-align: left:center:right (txt)" -text-align: ${1:left/right/center/justify};$0 -endsnippet - -snippet text "text-decoration: none:underline:overline:line-through:blink (text)" -text-decoration: ${1:none/underline/overline/line-through/blink};$0 -endsnippet - -snippet text "text-indent: length (text)" -text-indent: ${1:10}px;$0 -endsnippet - -snippet text "text-shadow: color-hex x y blur (text)" -text-shadow: #${1:DDD} ${2:10px} ${3:10px} ${4:2px};$0 -endsnippet - -snippet text "text-shadow: color-rgb x y blur (text)" -text-shadow: rgb(${1:255},${2:255},${3:255}) ${4:10px} ${5:10px} ${6:2px};$0 -endsnippet - -snippet text "text-shadow: none (text)" -text-shadow: none;$0 -endsnippet - -snippet text "text-transform: capitalize:upper:lower (text)" -text-transform: ${1:capitalize/uppercase/lowercase};$0 -endsnippet - -snippet text "text-transform: none (text)" -text-transform: none;$0 -endsnippet - -snippet vertical "vertical-align: type (vertical)" -vertical-align: ${1:baseline/sub/super/top/text-top/middle/bottom/text-bottom/length/%};$0 -endsnippet - -snippet visibility "visibility: type (visibility)" -visibility: ${1:visible/hidden/collapse};$0 -endsnippet - -snippet white "white-space: normal:pre:nowrap (white)" -white-space: ${1:normal/pre/nowrap};$0 -endsnippet - -snippet word "word-spacing: length (word)" -word-spacing: ${1:10px};$0 -endsnippet - -snippet word "word-spacing: normal (word)" -word-spacing: normal;$0 -endsnippet - -snippet z "z-index: index (z)" -z-index: $1;$0 -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/d.snippets b/vim/bundle/ultisnips/UltiSnips/d.snippets deleted file mode 100644 index 3a718c3..0000000 --- a/vim/bundle/ultisnips/UltiSnips/d.snippets +++ /dev/null @@ -1,584 +0,0 @@ -# Simple shortcuts - -priority -50 - -snippet imp "import (imp)" b -import ${1:std.stdio}; -endsnippet - -snippet pimp "public import (pimp)" b -public import ${1:/*module*/}; -endsnippet - -snippet over "override (over)" b -override ${1:/*function*/} -endsnippet - -snippet al "alias (al)" -alias ${1:/*orig*/} ${2:/*alias*/}; -endsnippet - -snippet mixin "mixin (mixin)" b -mixin ${1:/*mixed_in*/} ${2:/*name*/}; -endsnippet - -snippet new "new (new)" -new ${1}(${2}); -endsnippet - -snippet scpn "@safe const pure nothrow (scpn)" -@safe const pure nothrow -endsnippet - -snippet spn "@safe pure nothrow (spn)" -@safe pure nothrow -endsnippet - -snippet cont "continue (cont)" -continue; -endsnippet - -snippet dis "@disable (dis)" b -@disable ${1:/*method*/}; -endsnippet - -snippet pub "public (pub)" b -public: - ${1:/*members*/} -endsnippet - -snippet priv "private (priv)" b -private: - ${1:/*members*/} -endsnippet - -snippet prot "protected (prot)" b -protected: - ${1:/*members*/} -endsnippet - -snippet pack "package (pack)" b -package: - ${1:/*members*/} -endsnippet - -snippet ret "return (ret)" -return ${1:/*value to return*/}; -endsnippet - -snippet auto "auto (auto)" b -auto ${1:/*variable*/} = ${2:/*value*/}; -endsnippet - -snippet con "const (con)" b -const ${1:/*variable*/} = ${2:/*value*/}; -endsnippet - -snippet siz "size_t (siz)" b -size_t ${1:/*variable*/} = ${2:/*value*/}; -endsnippet - -snippet sup "super (sup)" b -super(${1:/*args*/}); -endsnippet - -# Phobos - -snippet tup "tuple (tup)" -tuple(${1:/*args*/}) -endsnippet - -snippet wr "writeln (wr)" -writeln(${1:/*args*/}); -endsnippet - -snippet to "to (to)" -to!(${1:/*type*/})(${2:/*arg*/}) -endsnippet - -snippet enf "enforce (enf)" b -enforce(${1:/*condition*/}, - new ${2}Exception(${3:/*args*/})); -endsnippet - -# Branches - -snippet if "if .. (if)" -if(${1:/*condition*/}) -{ - ${VISUAL}${0:/*code*/} -} -endsnippet - -snippet ife "if .. else (ife)" b -if(${1:/*condition*/}) -{ - ${2:/*code*/} -} -else -{ - ${3:/*else*/} -} -endsnippet - -snippet el "else (el)" b -else -{ - ${VISUAL}${1:/*code*/} -} -endsnippet - -snippet elif "else if (elif)" b -else if(${1:/*condition*/}) -{ - ${VISUAL}${0:/*code*/} -} -endsnippet - -snippet sw "switch (sw)" -switch(${1:/*var*/}) -{ - case ${2:/*value*/}: - ${3:/*code*/} - break; - case ${4:/*value*/}: - ${5:/*code*/} - break; - ${7:/*more cases*/} - default: - ${6:assert(false);} -} -endsnippet - -snippet fsw "final switch (fsw)" -switch(${1:/*var*/}) -{ - case ${2:/*value*/}: - ${3:/*code*/} - break; - case ${4:/*value*/}: - ${5:/*code*/} - break; - ${7:/*more cases*/} -} -endsnippet - -snippet case "case (case)" b -case ${1:/*value*/}: - ${2:/*code*/} - break; -endsnippet - -snippet ?: "ternary operator (?:)" -${1:/*condition*/} ? ${2:/*then*/} : ${3:/*else*/}$4 -endsnippet - -# Loops - -snippet do "do while (do)" b -do -{ - ${VISUAL}${2:/*code*/} -} while(${1:/*condition*/}); -endsnippet - -snippet wh "while (wh)" b -while(${1:/*condition*/}) -{ - ${VISUAL}${2:/*code*/} -} -endsnippet - -snippet for "for (for)" b -for (${4:size_t} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) -{ - ${VISUAL}${0:/*code*/} -} -endsnippet - -snippet forever "forever (forever)" b -for(;;) -{ - ${VISUAL}${0:/*code*/} -} -endsnippet - -snippet fore "foreach (fore)" -foreach(${1:/*elem*/}; ${2:/*range*/}) -{ - ${VISUAL}${3:/*code*/} -} -endsnippet - -snippet forif "foreach if (forif)" b -foreach(${1:/*elem*/}; ${2:/*range*/}) if(${3:/*condition*/}) -{ - ${VISUAL}${4:/*code*/} -} -endsnippet - -# Contracts -snippet in "in contract (in)" b -in -{ - assert(${1:/*condition*/}, "${2:error message}"); - ${3} -} -body -endsnippet - -snippet out "out contract (out)" b -out${1:(result)} -{ - assert(${2:/*condition*/}, "${3:error message}"); - ${4} -} -body -endsnippet - -snippet inv "invariant (inv)" b -invariant() -{ - assert(${1:/*condition*/}, "${2:error message}"); - ${3} -} -endsnippet - -# Functions (generic) - -snippet fun "function definition (fun)" -${1:void} ${2:/*function name*/}(${3:/*args*/}) ${4:@safe pure nothrow} -{ - ${VISUAL}${5:/*code*/} -} -endsnippet - -snippet void "void function definition (void)" -void ${1:/*function name*/}(${2:/*args*/}) ${3:@safe pure nothrow} -{ - ${VISUAL}${4:/*code*/} -} -endsnippet - -snippet this "ctor (this)" w -this(${1:/*args*/}) -{ - ${VISUAL}${2:/*code*/} -} -endsnippet - -snippet get "getter property (get)" -@property ${1:/*type*/} ${2:/*member_name*/}() const pure nothrow {return ${3:$2_};} -endsnippet - -snippet set "setter property (set)" -@property void ${1:/*member_name*/}(${2:/*type*/} rhs) pure nothrow {${3:$1_} = rhs;} -endsnippet - -# Functions (concrete) - -snippet main "Main" b -void main(string[] args) -{ - ${VISUAL}${0: /*code*/} -} -endsnippet - -# Mixins - -snippet signal "signal (signal)" b -mixin Signal!(${1:/*args*/}) ${2:/*name*/}; -endsnippet - -# Scope - -snippet scope "scope (scope)" b -scope(${1:exit}) -{ - ${VISUAL}${2:/*code*/} -} -endsnippet - -# With - -snippet with "with (with)" -with(${1}) -{ - ${VISUAL}${2:/*code*/} -} -endsnippet - -# Exception handling - -snippet try "try/catch (try)" b -try -{ - ${VISUAL}${1:/*code to try*/} -} -catch(${2}Exception e) -{ - ${3:/*handle exception*/} -} -endsnippet - -snippet tryf "try/catch/finally (tryf)" b -try -{ - ${VISUAL}${1:/*code to try*/} -} -catch(${2}Exception e) -{ - ${3:/*handle exception*/} -} -finally -{ - ${4:/*cleanup*/} -} -endsnippet - -snippet catch "catch (catch)" b -catch(${1}Exception e) -{ - ${2:/*handle exception*/} -} -endsnippet - -snippet thr "throw (thr)" -throw new ${1}Exception("${2}"); -endsnippet - - -# Type declarations - -snippet struct "struct (struct)" -struct ${1:`!p snip.rv = (snip.basename or "name")`} -{ - ${2} -} -endsnippet - -snippet union "union (union)" -union ${1:`!p snip.rv = (snip.basename or "name")`} -{ - ${2} -} -endsnippet - -snippet class "class (class)" -class ${1:`!p snip.rv = (snip.basename or "name")`} -{ - ${2} -} -endsnippet - -snippet inter "interface (inter)" -interface ${1:`!p snip.rv = (snip.basename or "name")`} -{ - ${2} -} -endsnippet - -snippet enum "enum (enum)" -enum ${1:`!p snip.rv = (snip.basename or "name")`} -{ - ${2} -} -endsnippet - - -# Exception declarations - -snippet exc "exception declaration (exc)" b -/// ${3:/*documentation*/} -class ${1}Exception : ${2}Exception -{ - public this(string msg, string file = __FILE__, int line = __LINE__) - { - super(msg, file, line); - } -} -endsnippet - - -# Conditional compilation - -snippet version "version (version)" b -version(${1:/*version name*/}) -{ - ${VISUAL}${2:/*code*/} -} -endsnippet - -snippet debug "debug" b -debug -{ - ${VISUAL}${1:/*code*/} -} -endsnippet - - -# Templates - -snippet temp "template (temp)" b -template ${2:/*name*/}(${1:/*args*/}) -{ - ${3:/*code*/} -} -endsnippet - - -# Asserts - -snippet ass "assert (ass)" b -assert(${1:false}, "${2:TODO}"); - -endsnippet - - -# Unittests - -snippet unittest "unittest (unittest)" b -unittest -{ - ${1:/*code*/} -} -endsnippet - - -# Common member functions - -snippet opDis "opDispatch (opDis)" b -${1:/*return type*/} opDispatch(string s)() -{ - ${2:/*code*/}; -} -endsnippet - -snippet op= "opAssign (op=)" b -void opAssign(${1} rhs) ${2:@safe pure nothrow} -{ - ${2:/*code*/} -} -endsnippet - -snippet opCmp "opCmp (opCmp)" b -int opCmp(${1} rhs) @safe const pure nothrow -{ - ${2:/*code*/} -} -endsnippet - -snippet opApply "opApply (opApply)" b -int opApply(int delegate(ref ${1:/*iterated type/s*/}) dg) -{ - int result = 0; - ${2:/*loop*/} - { - result = dg(${3:/*arg/s*/}); - if(result){break;} - } - return result; -} -endsnippet - -snippet toString "toString (toString)" b -string toString() @safe const pure nothrow -{ - ${1:/*code*/} -} -endsnippet - - -# Comments - - -snippet todo "TODO (todo)" -// TODO: ${1} -endsnippet - - -# DDoc - -snippet doc "generic ddoc block (doc)" b -/// ${1:description} -/// -/// ${2:details} -endsnippet - -snippet fdoc "function ddoc block (fdoc)" b -/// ${1:description} -/// -/// ${2:Params: ${3:param} = ${4:param description} -/// ${5}} -/// -/// ${6:Returns: ${7:return value}} -/// -/// ${8:Throws: ${9}Exception ${10}} -endsnippet - -snippet Par "Params (Par)" -Params: ${1:param} = ${2:param description} -/// ${3} -endsnippet - -snippet Ret "Returns (Ret)" -Returns: ${1:return value/s} -endsnippet - -snippet Thr "Throws (Thr)" -Throws: ${1}Exception ${2} -endsnippet - -snippet Example "Examples (Example)" -Examples: -/// -------------------- -/// ${1:example code} -/// -------------------- -endsnippet - - -# License blocks - -snippet gpl "GPL (gpl)" b -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -// Copyright (C) ${1:Author}, `!v strftime("%Y")` - -${2} -endsnippet - -snippet boost "Boost (boost)" b -// Copyright ${1:Author} `!v strftime("%Y")`. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -${2} -endsnippet - - -# New module - -snippet module "New module (module)" b -// Copyright ${1:Author} `!v strftime("%Y")`. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -module ${2}.`!v Filename('$1', 'name')`; - - -${3} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/django.snippets b/vim/bundle/ultisnips/UltiSnips/django.snippets deleted file mode 100644 index 9d6ce27..0000000 --- a/vim/bundle/ultisnips/UltiSnips/django.snippets +++ /dev/null @@ -1,238 +0,0 @@ -priority -50 - -# Generic Tags -snippet % -{% ${1} %}${2} -endsnippet - -snippet %% -{% ${1:tag_name} %} - ${2} -{% end$1 %} -endsnippet - -snippet { -{{ ${1} }}${2} -endsnippet - -# Template Tags - -snippet autoescape -{% autoescape ${1:off} %} - ${2} -{% endautoescape %} -endsnippet - -snippet block -{% block ${1} %} - ${2} -{% endblock $1 %} -endsnippet - -snippet # -{# ${1:comment} #} -endsnippet - -snippet comment -{% comment %} - ${1} -{% endcomment %} -endsnippet - -snippet cycle -{% cycle ${1:val1} ${2:val2} ${3:as ${4}} %} -endsnippet - -snippet debug -{% debug %} -endsnippet - -snippet extends -{% extends "${1:base.html}" %} -endsnippet - -snippet filter -{% filter ${1} %} - ${2} -{% endfilter %} -endsnippet - -snippet firstof -{% firstof ${1} %} -endsnippet - -snippet for -{% for ${1} in ${2} %} - ${3} -{% endfor %} -endsnippet - -snippet empty -{% empty %} - ${1} -endsnippet - -snippet if -{% if ${1} %} - ${2} -{% endif %} -endsnippet - -snippet else -{% else %} - ${1} -endsnippet - -snippet ifchanged -{% ifchanged %}${1}{% endifchanged %} -endsnippet - -snippet ifequal -{% ifequal ${1} ${2} %} - ${3} -{% endifequal %} -endsnippet - -snippet ifnotequal -{% ifnotequal ${1} ${2} %} - ${3} -{% endifnotequal %} -endsnippet - -snippet include -{% include "${1}" %} -endsnippet - -snippet load -{% load ${1} %} -endsnippet - -snippet now -{% now "${1:jS F Y H:i}" %} -endsnippet - -snippet regroup -{% regroup ${1} by ${2} as ${3} %} -endsnippet - -snippet spaceless -{% spaceless %}${1}{% endspaceless %} -endsnippet - -snippet ssi -{% ssi ${1} %} -endsnippet - -snippet trans -{% trans "${1:string}" %} -endsnippet - -snippet url -{% url ${1} as ${2} %} -endsnippet - -snippet widthratio -{% widthratio ${1:this_value} ${2:max_value} ${3:100} %} -endsnippet - -snippet with -{% with ${1} as ${2} %} -endsnippet - -# Template Filters - -# Note: Since SnipMate can't determine which template filter you are -# expanding without the "|" character, these do not add the "|" -# character. These save a few keystrokes still. - -# Note: Template tags that take no arguments are not implemented. - -snippet add -add:"${1}" -endsnippet - -snippet center -center:"${1}" -endsnippet - -snippet cut -cut:"${1}" -endsnippet - -snippet date -date:"${1}" -endsnippet - -snippet default -default:"${1}" -endsnippet - -snippet defaultifnone -default_if_none:"${1}" -endsnippet - -snippet dictsort -dictsort:"${1}" -endsnippet - -snippet dictsortrev -dictsortreversed:"${1}" -endsnippet - -snippet divisibleby -divisibleby:"${1}" -endsnippet - -snippet floatformat -floatformat:"${1}" -endsnippet - -snippet getdigit -get_digit:"${1}" -endsnippet - -snippet join -join:"${1}" -endsnippet - -snippet lengthis -length_is:"${1}" -endsnippet - -snippet pluralize -pluralize:"${1}" -endsnippet - -snippet removetags -removetags:"${1}" -endsnippet - -snippet slice -slice:"${1}" -endsnippet - -snippet stringformat -stringformat:"${1}" -endsnippet - -snippet time -time:"${1}" -endsnippet - -snippet truncatewords -truncatewords:${1} -endsnippet - -snippet truncatewordshtml -truncatewords_html:${1} -endsnippet - -snippet urlizetrunc -urlizetrunc:${1} -endsnippet - -snippet wordwrap -wordwrap:${1} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/erlang.snippets b/vim/bundle/ultisnips/UltiSnips/erlang.snippets deleted file mode 100644 index e27fbef..0000000 --- a/vim/bundle/ultisnips/UltiSnips/erlang.snippets +++ /dev/null @@ -1,100 +0,0 @@ -########################################################################### -# TEXTMATE SNIPPETS # -########################################################################### - -priority -50 - -snippet pat "Case:Receive:Try Clause" -${1:pattern}${2: when ${3:guard}} ->; - ${4:body} -endsnippet - -snippet beh "Behaviour Directive" --behaviour (${1:behaviour}). -endsnippet - -snippet case "Case Expression" -case ${1:expression} of - ${2:pattern}${3: when ${4:guard}} -> - ${5:body} -end -endsnippet - -snippet def "Define Directive" --define (${1:macro}${2: (${3:param})}, ${4:body}). -endsnippet - -snippet exp "Export Directive" --export ([${1:function}/${2:arity}]). -endsnippet - -snippet fun "Fun Expression" -fun - (${1:pattern})${2: when ${3:guard}} -> - ${4:body} -end -endsnippet - -snippet fu "Function" -${1:function} (${2:param})${3: when ${4:guard}} -> - ${5:body} -endsnippet - -snippet if "If Expression" -if - ${1:guard} -> - ${2:body} -end -endsnippet - -snippet ifdef "Ifdef Directive" --ifdef (${1:macro}). -endsnippet - -snippet ifndef "Ifndef Directive" --ifndef (${1:macro}). -endsnippet - -snippet imp "Import Directive" --import (${1:module}, [${2:function}/${3:arity}]). -endsnippet - -snippet inc "Include Directive" --include ("${1:file}"). -endsnippet - -snippet mod "Module Directive" --module (${1:`!p snip.rv = snip.basename or "module"`}). -endsnippet - -snippet rcv "Receive Expression" -receive -${1: ${2:pattern}${3: when ${4:guard}} -> - ${5:body}} -${6:after - ${7:expression} -> - ${8:body}} -end -endsnippet - -snippet rec "Record Directive" --record (${1:record}, {${2:field}${3: = ${4:value}}}). -endsnippet - -snippet try "Try Expression" -try${1: ${2:expression}${3: of - ${4:pattern}${5: when ${6:guard}} -> - ${7:body}}} -${8:catch - ${9:pattern}${10: when ${11:guard}} -> - ${12:body}} -${13:after - ${14:body}} -end -endsnippet - -snippet undef "Undef Directive" --undef (${1:macro}). -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/eruby.snippets b/vim/bundle/ultisnips/UltiSnips/eruby.snippets deleted file mode 100644 index cd87c1c..0000000 --- a/vim/bundle/ultisnips/UltiSnips/eruby.snippets +++ /dev/null @@ -1,280 +0,0 @@ -priority -50 - -# TextMate added these variables to cope with changes in ERB handling -# in different versions of Rails -- for instance, Rails 3 automatically -# strips whitespace so that it's no longer necessary to use a form like -# <% end -%>, but if you're still maintaining Rails 2 projects, you -# can't omit the minus sign and get the same behavior. -# -# The following regex replace substitutes the function below for the -# TextMate variable references after the snippets are converted: -# -# /\v\$\{(TM_RAILS_TEMPLATE_([^_]+)_RUBY_([^_\s]+))\}/`!p textmate_var('\1', snip)`/g -# -global !p -def textmate_var(var, snip): - lookup = dict( - TM_RAILS_TEMPLATE_START_RUBY_EXPR = snip.opt('g:tm_rails_template_start_ruby_expr', '<%= '), - TM_RAILS_TEMPLATE_END_RUBY_EXPR = snip.opt('g:tm_rails_template_end_ruby_expr', ' %>'), - TM_RAILS_TEMPLATE_START_RUBY_INLINE = snip.opt('g:tm_rails_template_start_ruby_inline', '<% '), - TM_RAILS_TEMPLATE_END_RUBY_INLINE = snip.opt('g:tm_rails_template_end_ruby_inline', ' %>'), - TM_RAILS_TEMPLATE_END_RUBY_BLOCK = '<% end %>' - ) - snip.rv = lookup[var] - return -endglobal - - -########################################################################### -# GENERATED FROM get_tm_snippets.py + REGEX REPLACE # -########################################################################### - -snippet fi "<%= Fixtures.identify(:symbol) %>" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`Fixtures.identify(:${1:name})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`$0 -endsnippet - -snippet ft "form_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_tag(${1::action => "${5:update}"}${6:, {:${8:class} => "${9:form}"\}}) do`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` - $0 -`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` -endsnippet - -snippet end "end (ERB)" -<% end -%> -endsnippet - -snippet for "for loop (ERB)" -<% if !${1:list}.blank? %> - <% for ${2:item} in ${1} %> - $3 - <% end %> -<% else %> - $4 -<% end %> - -endsnippet - -snippet ffcb "form_for check_box" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.check_box :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffff "form_for file_field 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.file_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffhf "form_for hidden_field 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.hidden_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffl "form_for label 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.label :${1:attribute}${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffpf "form_for password_field 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.password_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffrb "form_for radio_box 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.radio_box :${1:attribute}, :${2:tag_value}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffs "form_for submit 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.submit "${1:Submit}"${2:, :disable_with => '${3:$1ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffta "form_for text_area 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_area :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet fftf "form_for text_field 2" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet fields "fields_for" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`fields_for :${1:model}, @${2:$1} do |$1|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)` - $0 -`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` -endsnippet - -snippet f. "f_fields_for (nff)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`f.fields_for :${1:attribute} do |${2:f}|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)` -$0 -`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` -endsnippet - -snippet f. "f.checkbox" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.check_box :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.file_field" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.file_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.hidden_field" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.hidden_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.label" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.label :${1:attribute}${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.password_field" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.password_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.radio_box" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.radio_box :${1:attribute}, :${2:tag_value}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.submit" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.submit "${1:Submit}"${2:, :disable_with => '${3:$1ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.text_area" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_area :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet f. "f.text_field" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet ffe "form_for with errors" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`error_messages_for :${1:model}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` - -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${2:$1} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` - $0 -`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` -endsnippet - -snippet ff "form_for" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${1:model} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` - $0 -`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` -endsnippet - -snippet ist "image_submit_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_submit_tag("${1:agree.png}"${2:${3:, :id => "${4:${1/^(\w+)(\.\w*)?$/$1/}}"}${5:, :name => "${6:${1/^(\w+)(\.\w*)?$/$1/}}"}${7:, :class => "${8:${1/^(\w+)(\.\w*)?$/$1/}-button}"}${9:, :disabled => ${10:false}}})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet it "image_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_tag "$1${2:.png}"${3:${4:, :title => "${5:title}"}${6:, :class => "${7:class}"}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet layout "layout" -layout "${1:template_name}"${2:${3:, :only => ${4:[:${5:action}, :${6:action}]}}${7:, :except => ${8:[:${9:action}, :${10:action}]}}} -endsnippet - -snippet jit "javascript_include_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`javascript_include_tag ${1::all}${2:, :cache => ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lia "link_to (action)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :action => "${2:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet liai "link_to (action, id)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :action => "${2:edit}", :id => ${3:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lic "link_to (controller)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lica "link_to (controller, action)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}", :action => "${3:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet licai "link_to (controller, action, id)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}", :action => "${3:edit}", :id => ${4:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet linpp "link_to (nested path plural)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${10:parent}_${11:child}_path(${12:@}${13:${10}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet linp "link_to (nested path)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lipp "link_to (path plural)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${4:model}s_path}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lip "link_to (path)" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:model}_path(${13:@}${14:${12}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet lim "link_to model" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:model}.${2:name}, ${3:${4:$1}_path(${14:$1})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet hide "page.hide (*ids)" -page.hide ${1:"${2:id(s)}"} -endsnippet - -snippet ins "page.insert_html (position, id, partial)" -page.insert_html :${1:top}, ${2:"${3:id}"}, :${4:partial => "${5:template}"} -endsnippet - -snippet rep "page.replace (id, partial)" -page.replace ${1:"${2:id}"}, :${3:partial => "${4:template}"} -endsnippet - -snippet reph "page.replace_html (id, partial)" -page.replace_html ${1:"${2:id}"}, :${3:partial => "${4:template}"} -endsnippet - -snippet show "page.show (*ids)" -page.show ${1:"${2:id(s)}"} -endsnippet - -snippet tog "page.toggle (*ids)" -page.toggle ${1:"${2:id(s)}"} -endsnippet - -snippet vis "page.visual_effect (effect, id)" -page.visual_effect :${1:toggle_slide}, ${2:"${3:DOM ID}"} -endsnippet - -snippet rp "render (partial) (rp)" -render :partial => "${1:item}" -endsnippet - -snippet rpc "render (partial,collection) (rpc)" -render :partial => "${1:item}", :collection => ${2:@$1s} -endsnippet - -snippet rpl "render (partial,locals) (rpl)" -render :partial => "${1:item}", :locals => { :${2:$1} => ${3:@$1}$0 } -endsnippet - -snippet rpo "render (partial,object) (rpo)" -render :partial => "${1:item}", :object => ${2:@$1} -endsnippet - -snippet rps "render (partial,status) (rps)" -render :partial => "${1:item}", :status => ${2:500} -endsnippet - -snippet slt "stylesheet_link_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`stylesheet_link_tag ${1::all}${2:, :cache => ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet st "submit_tag" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`submit_tag "${1:Save changes}"${2:, :id => "${3:submit}"}${4:, :name => "${5:$3}"}${6:, :class => "${7:form_$3}"}${8:, :disabled => ${9:false}}${10:, :disable_with => "${11:Please wait...}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -snippet else "else (ERB)" -<% else %> - $0 -endsnippet - -snippet if "if (ERB)" -<% if ${1:condition} %>$0 -endsnippet - -snippet lf "link_to_function" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to_function ${1:"${2:Greeting}"}, "${3:alert('Hello world!')}"$4`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/go.snippets b/vim/bundle/ultisnips/UltiSnips/go.snippets deleted file mode 100644 index d01e3f1..0000000 --- a/vim/bundle/ultisnips/UltiSnips/go.snippets +++ /dev/null @@ -1,131 +0,0 @@ -# Snippets for Go - -priority -50 - -# when to abbriviate and when not? -# b doesn't work here, because it ignores whitespace -# optional local name? -snippet /^import/ "Import declaration" r -import ( - "${1:package}" -) -endsnippet - -snippet /^package/ "Package declaration" r -// Package $1 provides ... -package ${1:main} -endsnippet - -# Mostly converted from: https://github.com/AlanQuatermain/go-tmbundle -snippet /^cons/ "Constants declaration" r -const ( - ${1:constant}${2/(.+)/ /}${2:type} = ${0:value} -) -endsnippet - -snippet /^con/ "Constant declaration" r -const ${1:name}${2/(.+)/ /}${2:type} = ${0:value} -endsnippet - -snippet iota "Iota constant generator" b -const ( - ${1:constant}${2/(.+)/ /}${2:type} = iota -) -endsnippet - -snippet struct "Struct declaration" b -type ${1:Struct} struct { - ${0:${VISUAL}} -} -endsnippet - -snippet interface "Interface declaration" b -type ${1:Interface} interface { - ${0:${VISUAL}} -} -endsnippet - -# statements -snippet for "For loop" b -for ${1:condition}${1/(.+)/ /}{ - ${0:${VISUAL}} -} -endsnippet - -snippet forr "For range loop" b -for ${2:name} := range ${1:collection} { - ${0:${VISUAL}} -} -endsnippet - -snippet if "If statement" b -if ${1:condition}${1/(.+)/ /}{ - ${0:${VISUAL}} -} -endsnippet - -snippet switch "Switch statement" b -switch ${1:expression}${1/(.+)/ /}{ -case${0} -} -endsnippet - -snippet select "Select statement" b -select { -case${0} -} -endsnippet - -snippet case "Case clause" b -case ${1:condition}: - ${0:${VISUAL}} -endsnippet - -snippet default "Default clause" b -default: - ${0:${VISUAL}} -endsnippet - -# functions -snippet /^main/ "Main function" r -func main() { - ${0:${VISUAL}} -} -endsnippet - -snippet /^meth/ "Method" r -func (${1:receiver} ${2:type}) ${3:name}(${4:params})${5/(.+)/ /}${5:type} { - ${0:${VISUAL}} -} -endsnippet - -snippet func "Function" b -func ${1:name}(${2:params})${3/(.+)/ /}${3:type} { - ${0:${VISUAL}} -} -endsnippet - -# types and variables -snippet map "Map type" b -map[${1:keytype}]${2:valtype} -endsnippet - -snippet : "Variable declaration :=" b -${1:name} := ${0:value} -endsnippet - -snippet var "Variable declaration" b -var ${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value}} -endsnippet - -snippet vars "Variables declaration" b -var ( - ${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value} } -) -endsnippet - -snippet json "JSON field" -\`json:"${1:displayName}"\` -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/haskell.snippets b/vim/bundle/ultisnips/UltiSnips/haskell.snippets deleted file mode 100644 index ad217fd..0000000 --- a/vim/bundle/ultisnips/UltiSnips/haskell.snippets +++ /dev/null @@ -1,63 +0,0 @@ -priority -50 - -snippet if "if ... then ... else ..." -if ${1:condition} - then ${2:expression} - else ${3:expression} -endsnippet - -snippet case "case ... of ..." -case ${1:expression} of - ${2:pattern} -> ${3:expression} - ${4:pattern} -> ${5:expression} -endsnippet - -snippet :: "Type signature" -${1:name} :: ${2:Type} -> ${3:Type} -endsnippet - -snippet => "Type constraint" -(${1:Class} ${2:Type var}) => ${3:$2} -endsnippet - -snippet def "Function definition" -${1:name} :: ${2:Type} -> ${3:Type} -endsnippet - -snippet def[] "Function definition for list patterns" -${1:name} :: [${2:Type}] -> ${3:Type} -$1 [] = ${4:undefined} -$1 ${5:(x:xs)} = ${6:undefined} -endsnippet - -snippet = "Function clause" -${1:name} ${2:pattern} = ${3:undefined} -endsnippet - -snippet 2= "Function clause" -${1:name} ${2:pattern} = ${3:undefined} -$1 ${4:pattern} = ${5:undefined} -endsnippet - -snippet 3= "Function clause" -${1:name} ${2:pattern} = ${3:undefined} -$1 ${4:pattern} = ${5:undefined} -$1 ${6:pattern} = ${7:undefined} -endsnippet - -snippet | "Guard" -| ${1:predicate} = ${2:undefined} -endsnippet - -snippet \ "Lambda expression" -\ ${1:pattern} -> ${2:expression} -endsnippet - -snippet [|] "List comprehension" -[${3:foo }$1 | ${1:x} <- ${2:xs} ] -endsnippet - -snippet let "let ... in ..." -let ${1:name} = ${2:expression} -in ${3:expression} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/help.snippets b/vim/bundle/ultisnips/UltiSnips/help.snippets deleted file mode 100644 index 6132738..0000000 --- a/vim/bundle/ultisnips/UltiSnips/help.snippets +++ /dev/null @@ -1,32 +0,0 @@ -# Snippets for VIM Help Files - -priority -50 - -global !p -def sec_title(snip, t): - file_start = snip.fn.split('.')[0] - sec_name = t[1].strip("1234567890. ").lower().replace(' ', '-') - return ("*%s-%s*" % (file_start, sec_name)).rjust(78-len(t[1])) -endglobal - -snippet sec "Section marker" b -============================================================================== -${1:SECTION}`!p snip.rv = sec_title(snip, t)` - -$0 -endsnippet - -snippet ssec "Sub section marker" b -${1:Subsection}`!p snip.rv = sec_title(snip, t) -snip += "-"*len(t[1])` - -$0 -endsnippet - -snippet sssec "Subsub Section marker" b -${1:SubSubsection}:`!p snip.rv = sec_title(snip, t)` - -$0 -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/html.snippets b/vim/bundle/ultisnips/UltiSnips/html.snippets deleted file mode 100644 index 31f7cc3..0000000 --- a/vim/bundle/ultisnips/UltiSnips/html.snippets +++ /dev/null @@ -1,302 +0,0 @@ -priority -50 - -########################################################################### -# TextMate Snippets # -########################################################################### - -global !p -def x(snip): - if snip.ft.startswith("x"): - snip.rv = '/' - else: - snip.rv = "" -endglobal - -############ -# Doctypes # -############ -snippet doctype "DocType XHTML 1.0 Strict" b - - -endsnippet - -snippet doctype "DocType XHTML 1.0 Transitional" b - - -endsnippet - -snippet doctype "DocType XHTML 1.1" b - - -endsnippet - -snippet doctype "HTML - 4.0 Transitional (doctype)" b - - -endsnippet - -snippet doctype "HTML - 5.0 (doctype)" b - - -endsnippet - -############# -# Shortcuts # -############# -snippet down "Down (down)" -↓ -endsnippet - -snippet enter "Enter (enter)" -⌅ -endsnippet - -snippet escape "Escape (escape)" -⎋ -endsnippet - -snippet shift "Shift (shift)" -⇧ -endsnippet - -snippet tab "Tab (tab)" -⇥ -endsnippet - -snippet up "Up (up)" -↑ -endsnippet - -snippet return "Return (return)" -↩ -endsnippet - -snippet right "Right (right)" -→ -endsnippet - -snippet left "Left (left)" -← -endsnippet - -snippet option "Option (option)" -⌥ -endsnippet - -####################### -# Conditional inserts # -####################### -snippet ! "IE Conditional Comment: Internet Explorer 5_0 only" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer 5_5 only" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer 5_x" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer 6 and below" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer 6 only" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer 7+" -$0 -endsnippet - -snippet ! "IE Conditional Comment: Internet Explorer" -$0 -endsnippet - -snippet ! "IE Conditional Comment: NOT Internet Explorer" -${1: IE Conditional Comment: NOT Internet Explorer }$0 -endsnippet - -############# -# HTML TAGS # -############# -snippet input "Input with Label" w - - -endsnippet - -snippet input "XHTML " w - -endsnippet - - -snippet opt "Option" w -${3:$2} -endsnippet - -snippet select "Select Box" w - -endsnippet - - -snippet textarea "XHTML -endsnippet - -snippet mailto "XHTML " w -${3:email me} -endsnippet - -snippet base "XHTML " w - -endsnippet - -snippet img "XHTML " w - -endsnippet - -snippet body "XHTML " - - $0 - -endsnippet - -snippet div "XHTML
" w - - $0 -
-endsnippet - -snippet form "XHTML
" w - - $0 - -

-
-endsnippet - -snippet h1 "XHTML

" w -

${1}

-endsnippet - -snippet head "XHTML " - - - ${1:`!p snip.rv = snip.basename or "Page Title"`} - $0 - -endsnippet - -snippet link "XHTML " w - -endsnippet - -snippet meta "XHTML " w - -endsnippet - -snippet scriptsrc "XHTML -endsnippet - -snippet script "XHTML -endsnippet - -snippet style "XHTML -endsnippet - -snippet table "XHTML " w -
- - -
${5:Header}
${0:Data}
-endsnippet - -snippet a "Link" w -${4:Anchor Text} -endsnippet - -snippet p "paragraph" w -

$0

-endsnippet - -snippet li "list item" w -
  • $0
  • -endsnippet - -snippet ul "unordered list" w -
      -$0 -
    -endsnippet - -snippet td "table cell" w -$0 -endsnippet - -snippet tr "table row" w -$0 -endsnippet - -snippet title "XHTML " w -<title>${1:`!p snip.rv = snip.basename or "Page Title"`} -endsnippet - -snippet fieldset "Fieldset" w -
    - $1 - $0 -
    -endsnippet - -snippet movie "Embed QT movie (movie)" b - - - - - - -endsnippet - -snippet html5 "HTML5 Template" - - - - ${1} - - - -
    - ${2} -
    -
    - ${4} -
    - - -endsnippet -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/htmldjango.snippets b/vim/bundle/ultisnips/UltiSnips/htmldjango.snippets deleted file mode 100644 index 5836a2f..0000000 --- a/vim/bundle/ultisnips/UltiSnips/htmldjango.snippets +++ /dev/null @@ -1,3 +0,0 @@ -priority -50 - -extends html, django diff --git a/vim/bundle/ultisnips/UltiSnips/htmljinja.snippets b/vim/bundle/ultisnips/UltiSnips/htmljinja.snippets deleted file mode 100644 index fa3b3c2..0000000 --- a/vim/bundle/ultisnips/UltiSnips/htmljinja.snippets +++ /dev/null @@ -1,3 +0,0 @@ -priority -50 - -extends html, jinja2 diff --git a/vim/bundle/ultisnips/UltiSnips/java.snippets b/vim/bundle/ultisnips/UltiSnips/java.snippets deleted file mode 100644 index 96cc7a9..0000000 --- a/vim/bundle/ultisnips/UltiSnips/java.snippets +++ /dev/null @@ -1,431 +0,0 @@ -priority -50 - -# Many of the snippets here use a global option called -# "g:ultisnips_java_brace_style" which, if set to "nl" will put a newline -# before '{' braces. -# Setting "g:ultisnips_java_junit" will change how the test method snippet -# looks, it is defaulted to junit4, setting this option to 3 will remove the -# @Test annotation from the method - -global !p -def junit(snip): - if snip.opt("g:ultisnips_java_junit", "") == "3": - snip += "" - else: - snip.rv += "@Test\n\t" - -def nl(snip): - if snip.opt("g:ultisnips_java_brace_style", "") == "nl": - snip += "" - else: - snip.rv += " " -def getArgs(group): - import re - word = re.compile('[a-zA-Z><.]+ \w+') - return [i.split(" ") for i in word.findall(group) ] - -def camel(word): - return word[0].upper() + word[1:] - -endglobal - -snippet sleep "try sleep catch" b -try { - Thread.sleep(${1:1000}); -} catch (InterruptedException e){ - e.printStackTrace(); -} -endsnippet - -snippet /i|n/ "new primitive or int" br -${1:int} ${2:i} = ${3:1}; -$0 -endsnippet - -snippet /o|v/ "new Object or variable" br -${1:Object} ${2:var} = new $1(${3}); -endsnippet - -snippet f "field" b -${1:private} ${2:String} ${3:`!p snip.rv = t[2].lower()`}; -endsnippet - -snippet ab "abstract" b -abstract $0 -endsnippet - -snippet as "assert" b -assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};$0 -endsnippet - -snippet at "assert true" b -assertTrue(${1:actual}); -endsnippet - -snippet af "assert false" b -assertFalse(${1:actual});$0 -endsnippet - -snippet ae "assert equals" b -assertEquals(${1:expected}, ${2:actual}); -endsnippet - -snippet br "break" -break; - -endsnippet - -snippet cs "case" b -case $1: - $2 -$0 -endsnippet - -snippet ca "catch" b -catch (${1:Exception} ${2:e})`!p nl(snip)`{ - $0 -} -endsnippet - -snippet cle "class extends" b -public class ${1:`!p -snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }${4:implements ${5:Interface} }{ - $0 -} -endsnippet - -snippet clc "class with constructor, fields, setter and getters" b -public class `!p -snip.rv = snip.basename or "untitled"` { -`!p -args = getArgs(t[1]) -if len(args) == 0: snip.rv = "" -for i in args: - snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";" -if len(args) > 0: - snip.rv += "\n"` - public `!p snip.rv = snip.basename or "unknown"`($1) { `!p -args = getArgs(t[1]) -for i in args: - snip.rv += "\n\t\tthis." + i[1] + " = " + i[1] + ";" -if len(args) == 0: - snip.rv += "\n"` - }$0 -`!p -args = getArgs(t[1]) -if len(args) == 0: snip.rv = "" -for i in args: - snip.rv += "\n\tpublic void set" + camel(i[1]) + "(" + i[0] + " " + i[1] + ") {\n" + "\ - \tthis." + i[1] + " = " + i[1] + ";\n\t}\n" - - snip.rv += "\n\tpublic " + i[0] + " get" + camel(i[1]) + "() {\ - \n\t\treturn " + i[1] + ";\n\t}\n" -` -} -endsnippet - -snippet clc "class with constructor, with field names" b -public class `!p -snip.rv = snip.basename or "untitled"` { -`!p -args = getArgs(t[1]) -for i in args: - snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";" -if len(args) > 0: - snip.rv += "\n"` - public `!p snip.rv = snip.basename or "unknown"`($1) { `!p -args = getArgs(t[1]) -for i in args: - snip.rv += "\n\t\tthis." + i[1] + " = " + i[1] -if len(args) == 0: - snip.rv += "\n"` - } -} -endsnippet - -snippet clc "class and constructor" b -public class `!p -snip.rv = snip.basename or "untitled"` { - - public `!p snip.rv = snip.basename or "untitled"`($2) { - $0 - } -} -endsnippet - -snippet cl "class" b -public class ${1:`!p -snip.rv = snip.basename or "untitled"`} { - $0 -} -endsnippet - -snippet cos "constant string" b -public static final String ${1:var} = "$2";$0 -endsnippet - -snippet co "constant" b -public static final ${1:String} ${2:var} = $3;$0 -endsnippet - -snippet de "default" b -default: - $0 -endsnippet - -snippet elif "else if" b -else if ($1)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet /el(se)?/ "else" br -else`!p nl(snip)`{ - $0 -} -endsnippet - -snippet fi "final" b -final $0 -endsnippet - -snippet fore "for (each)" b -for ($1 : $2)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet fori "for" b -for (int ${1:i} = 0; $1 < ${2:10}; $1++)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet for "for" b -for ($1; $2; $3)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet if "if" b -if ($1)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet imt "import junit_framework_TestCase;" b -import junit.framework.TestCase; -$0 -endsnippet - -snippet im "import" b -import ${1:java}.${2:util}.$0 -endsnippet - -snippet in "interface" b -interface ${1:`!p snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }{ - $0 -} -endsnippet - -snippet cc "constructor call or setter body" -this.${1:var} = $1; -endsnippet - -snippet list "Collections List" b -List<${1:String}> ${2:list} = new ${3:Array}List<$1>(); -endsnippet - -snippet map "Collections Map" b -Map<${1:String}, ${2:String}> ${3:map} = new ${4:Hash}Map<$1, $2>(); -endsnippet - -snippet set "Collections Set" b -Set<${1:String}> ${2:set} = new ${3:Hash}Set<$1>(); -endsnippet - -snippet /Str?|str/ "String" br -String $0 -endsnippet - -snippet cn "Constructor" b -public `!p snip.rv = snip.basename or "untitled"`(${1:}) { - $0 -} -endsnippet - -snippet cn "constructor, \w fields + assigments" b - `!p -args = getArgs(t[1]) -for i in args: - snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";" -if len(args) > 0: - snip.rv += "\n"` -public `!p snip.rv = snip.basename or "unknown"`($1) { `!p -args = getArgs(t[1]) -for i in args: - snip.rv += "\n\t\tthis." + i[1] + " = " + i[1] -if len(args) == 0: - snip.rv += "\n"` -} -endsnippet - -snippet j.b "java_beans_" i -java.beans. -endsnippet - -snippet j.i "java_io" i -java.io. -endsnippet - -snippet j.m "java_math" i -java.math. -endsnippet - -snippet j.n "java_net_" i -java.net. -endsnippet - -snippet j.u "java_util_" i -java.util. -endsnippet - -snippet main "method (main)" b -public static void main(String[] args)`!p nl(snip)`{ - $0 -} -endsnippet - -snippet try "try/catch" b -try { - $1 -} catch(${2:Exception} ${3:e}){ - ${4:e.printStackTrace();} -} -endsnippet - -snippet mt "method throws" b -${1:private} ${2:void} ${3:method}(${4}) ${5:throws $6 }{ - $0 -} -endsnippet - -snippet m "method" b -${1:private} ${2:void} ${3:method}(${4}) { - $0 -} -endsnippet - -snippet md "Method With javadoc" b -/** - * ${7:Short Description}`!p -for i in getArgs(t[4]): - snip.rv += "\n\t * @param " + i[1] + " usage..."` - * `!p -if "throws" in t[5]: - snip.rv = "\n\t * @throws " + t[6] -else: - snip.rv = ""` `!p -if not "void" in t[2]: - snip.rv = "\n\t * @return object" -else: - snip.rv = ""` - **/ -${1:public} ${2:void} ${3:method}($4) ${5:throws $6 }{ - $0 -} -endsnippet - -snippet /get(ter)?/ "getter" br -public ${1:String} get${2:Name}() { - return `!p snip.rv = t[2].lower()`; -} -endsnippet - -snippet /set(ter)?/ "setter" br -public void set${1:Name}(${2:String} $1) { - return this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`; -} -endsnippet - -snippet /se?tge?t|ge?tse?t|gs/ "setter and getter" br -public void set${1:Name}(${2:String} `!p snip.rv = t[1].lower()`) { - this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`; -} - -public $2 get$1() { - return `!p snip.rv = t[1].lower()`; -} -endsnippet - -snippet pa "package" b -package $0 -endsnippet - -snippet p "print" b -System.out.print($1);$0 -endsnippet - -snippet pl "println" b -System.out.println($1);$0 -endsnippet - -snippet pr "private" b -private $0 -endsnippet - -snippet po "protected" b -protected $0 -endsnippet - -snippet pu "public" b -public $0 -endsnippet - -snippet re "return" b -return $0 -endsnippet - -snippet st "static" -static $0 -endsnippet - -snippet sw "switch" b -switch ($1)`!p nl(snip)`{ - case $2: $0 -} -endsnippet - -snippet sy "synchronized" -synchronized $0 -endsnippet - -snippet tc "test case" -public class ${1:`!p snip.rv = snip.basename or "untitled"`} extends ${2:TestCase}`!p nl(snip)`{ - $0 -} -endsnippet - -snippet t "test" b -`!p junit(snip)`public void test${1:Name}() { - $0 -} -endsnippet - -snippet tt "test throws" b -`!p junit(snip)`public void test${1:Name}() ${2:throws Exception }{ - $0 -} -endsnippet - -snippet th "throw" b -throw new $0 -endsnippet - -snippet wh "while" b -while ($1)`!p nl(snip)`{ - $0 -} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/javascript.snippets b/vim/bundle/ultisnips/UltiSnips/javascript.snippets deleted file mode 100644 index f8d4790..0000000 --- a/vim/bundle/ultisnips/UltiSnips/javascript.snippets +++ /dev/null @@ -1,162 +0,0 @@ -priority -50 - -########################################################################### -# TextMate Snippets # -########################################################################### -snippet get "Get Elements" -getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}('$2') -endsnippet - -snippet '':f "object method string" -'${1:${2:#thing}:${3:click}}': function(element) { - ${VISUAL}$0 -}${10:,} -endsnippet - -snippet :f "Object Method" -${1:method_name}: function(${3:attribute}) { - ${VISUAL}$0 -}${10:,} -endsnippet - -snippet :, "Object Value JS" -${1:value_name}: ${0:value}, -endsnippet - -snippet : "Object key key: 'value'" -${1:key}: ${2:"${3:value}"}${4:, } -endsnippet - -snippet proto "Prototype (proto)" -${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { - ${VISUAL}$0 -}; - -endsnippet - -snippet for "for (...) {...} (counting up)" b -for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { - ${VISUAL}$0 -} -endsnippet - -snippet ford "for (...) {...} (counting down, faster)" b -for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { - ${VISUAL}$0 -} -endsnippet - -snippet fun "function (fun)" -function ${1:function_name}(${2:argument}) { - ${VISUAL}$0 -} -endsnippet - -snippet iife "Immediately-Invoked Function Expression (iife)" -(function (${1:argument}) { - ${VISUAL}$0 -}(${2:$1})); -endsnippet - -snippet ife "if ___ else" -if (${1:condition}) { - ${2://code} -} -else { - ${3://code} -} -endsnippet - -snippet if "if" -if (${1:condition}) { - ${VISUAL}$0 -} -endsnippet - -snippet timeout "setTimeout function" -setTimeout(function() { - ${VISUAL}$0 -}${2:.bind(${3:this})}, ${1:10}); -endsnippet - -# Snippets for Console Debug Output - -snippet ca "console.assert" b -console.assert(${1:assertion}, ${2:"${3:message}"}); -endsnippet - -snippet cclear "console.clear" b -console.clear(); -endsnippet - -snippet cdir "console.dir" b -console.dir(${1:object}); -endsnippet - -snippet cdirx "console.dirxml" b -console.dirxml(${1:object}); -endsnippet - -snippet ce "console.error" b -console.error(${1:"${2:value}"}); -endsnippet - -snippet cgroup "console.group" b -console.group("${1:label}"); -${VISUAL}$0 -console.groupEnd(); -endsnippet - -snippet cgroupc "console.groupCollapsed" b -console.groupCollapsed("${1:label}"); -${VISUAL}$0 -console.groupEnd(); -endsnippet - -snippet ci "console.info" b -console.info(${1:"${2:value}"}); -endsnippet - -snippet cl "console.log" b -console.log(${1:"${2:value}"}); -endsnippet - -snippet cprof "console.profile" b -console.profile("${1:label}"); -${VISUAL}$0 -console.profileEnd(); -endsnippet - -snippet ctable "console.table" b -console.table(${1:"${2:value}"}); -endsnippet - -snippet ctime "console.time" b -console.time("${1:label}"); -${VISUAL}$0 -console.timeEnd("$1"); -endsnippet - -snippet ctimestamp "console.timeStamp" b -console.timeStamp("${1:label}"); -endsnippet - -snippet ctrace "console.trace" b -console.trace(); -endsnippet - -snippet cw "console.warn" b -console.warn(${1:"${2:value}"}); -endsnippet - -# AMD (Asynchronous Module Definition) snippets - -snippet def "define an AMD module" -define(${1:optional_name, }[${2:'jquery'}], ${3:callback}); -endsnippet - -snippet req "require an AMD module" -require([${1:'dependencies'}], ${2:callback}); -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/javascript_jasmine.snippets b/vim/bundle/ultisnips/UltiSnips/javascript_jasmine.snippets deleted file mode 100644 index 0d8f7af..0000000 --- a/vim/bundle/ultisnips/UltiSnips/javascript_jasmine.snippets +++ /dev/null @@ -1,169 +0,0 @@ -priority -50 -extends javascript -priority -49 - -# JavaScript versions -- from the TextMate bundle + some additions -# for jasmine-jquery matchers -# - -snippet des "Describe (js)" b -describe('${1:description}', function() { - $0 -}); -endsnippet - -snippet it "it (js)" b -it('${1:description}', function() { - $0 -}); -endsnippet - -snippet bef "before each (js)" b -beforeEach(function() { - $0 -}); -endsnippet - -snippet aft "after each (js)" b -afterEach(function() { - $0 -}); -endsnippet - -snippet any "any (js)" b -jasmine.any($1) -endsnippet - -snippet ru "runs (js)" b -runs(function() { - $0 -}); -endsnippet - -snippet wa "waits (js)" b -waits($1); -endsnippet - -snippet ex "expect (js)" b -expect(${1:target})$0; -endsnippet - -snippet ee "expect to equal (js)" b -expect(${1:target}).toEqual(${2:value}); -endsnippet - -snippet em "expect to match (js)" b -expect(${1:target}).toMatch(${2:pattern}); -endsnippet - -snippet eha "expect to have attribute (js)" b -expect(${1:target}).toHaveAttr('${2:attr}'${3:, '${4:value}'}); -endsnippet - -snippet et "expect to be truthy (js)" b -expect(${1:target}).toBeTruthy(); -endsnippet - -snippet ef "expect to be falsy (js)" b -expect(${1:target}).toBeFalsy(); -endsnippet - -snippet ed "expect to be defined (js)" b -expect(${1:target}).toBeDefined(); -endsnippet - -snippet en "expect to be null (js)" b -expect(${1:target}).toBeNull(); -endsnippet - -snippet ec "expect to contain (js)" b -expect(${1:target}).toContain(${2:value}); -endsnippet - -snippet ev "expect to be visible (js)" b -expect(${1:target}).toBeVisible(); -endsnippet - -snippet eh "expect to be hidden (js)" b -expect(${1:target}).toBeHidden(); -endsnippet - -snippet notx "expect not (js)" b -expect(${1:target}).not$0; -endsnippet - -snippet note "expect not to equal (js)" b -expect(${1:target}).not.toEqual(${2:value}); -endsnippet - -snippet notm "expect not to match (js)" b -expect(${1:target}).not.toMatch(${2:pattern}); -endsnippet - -snippet notha "expect to not have attribute (js)" b -expect(${1:target}).not.toHaveAttr('${2:attr}'${3:, '${4:value}'}); -endsnippet - -snippet nott "expect not to be truthy (js)" b -expect(${1:target}).not.toBeTruthy(); -endsnippet - -snippet notf "expect not to be falsy (js)" b -expect(${1:target}).not.toBeFalsy(); -endsnippet - -snippet notd "expect not to be defined (js)" b -expect(${1:target}).not.toBeDefined(); -endsnippet - -snippet notn "expect not to be null (js)" b -expect(${1:target}).not.toBeNull(); -endsnippet - -snippet notc "expect not to contain (js)" b -expect(${1:target}).not.toContain(${2:value}); -endsnippet - -snippet notv "expect not to be visible (js)" b -expect(${1:target}).not.toBeVisible(); -endsnippet - -snippet noth "expect not to be hidden (js)" b -expect(${1:target}).not.toBeHidden(); -endsnippet - -snippet s "spy on (js)" b -spyOn(${1:object}, '${2:method}')$0; -endsnippet - -snippet sr "spy on and return (js)" b -spyOn(${1:object}, '${2:method}').andReturn(${3:arguments}); -endsnippet - -snippet st "spy on and throw (js)" b -spyOn(${1:object}, '${2:method}').andThrow(${3:exception}); -endsnippet - -snippet sct "spy on and call through (js)" b -spyOn(${1:object}, '${2:method}').andCallThrough(); -endsnippet - -snippet scf "spy on and call fake (js)" b -spyOn(${1:object}, '${2:method}').andCallFake(${3:function}); -endsnippet - -snippet esc "expect was called (js)" b -expect(${1:target}).wasCalled(); -endsnippet - -snippet escw "expect was called with (js)" b -expect(${1:target}).wasCalledWith(${2:arguments}); -endsnippet - -snippet notsc "expect was not called (js)" b -expect(${1:target}).wasNotCalled(); -endsnippet - -snippet noscw "expect was not called with (js)" b -expect(${1:target}).wasNotCalledWith(${2:arguments}); -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/javascript_jsdoc.snippets b/vim/bundle/ultisnips/UltiSnips/javascript_jsdoc.snippets deleted file mode 100644 index ca943fc..0000000 --- a/vim/bundle/ultisnips/UltiSnips/javascript_jsdoc.snippets +++ /dev/null @@ -1,51 +0,0 @@ -priority -50 - -# JSDoc snippets - -snippet /* "A JSDoc comment" b -/** - * ${1:${VISUAL}}$0 - */ -endsnippet - -snippet @au "@author email (First Last)" -@author ${1:`!v g:snips_author_email`} (${2:`!v g:snips_author`}) -endsnippet - -snippet @li "@license Description" -@license ${1:MIT}$0 -endsnippet - -snippet @ver "@version Semantic version" -@version ${1:0.1.0}$0 -endsnippet - -snippet @fileo "@fileoverview Description" b -/** - * @fileoverview ${1:${VISUAL:A description of the file}}$0 - */ -endsnippet - -snippet @constr "@constructor" -@constructor -endsnippet - -snippet @p "@param {Type} varname Description" -@param {${1:Type}} ${2:varname} ${3:Description} -endsnippet - -snippet @ret "@return {Type} Description" -@return {${1:Type}} ${2:Description} -endsnippet - -snippet @pri "@private" -@private -endsnippet - -snippet @over "@override" -@override -endsnippet - -snippet @pro "@protected" -@protected -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/jinja2.snippets b/vim/bundle/ultisnips/UltiSnips/jinja2.snippets deleted file mode 100644 index ded01dc..0000000 --- a/vim/bundle/ultisnips/UltiSnips/jinja2.snippets +++ /dev/null @@ -1,209 +0,0 @@ -priority -50 - -# http://jinja.pocoo.org/ - -# jinja2 is a full featured template engine for Python. It has full -# unicode support, an optional integrated sandboxed execution -# environment, widely used and BSD licensed. - -# possible extends: -#extends html - - -snippet block "block" b -{% block ${1:name} %} - $2 -{% endblock $1 %} -endsnippet - - -snippet {{ "variable" b -{{ $1 }} -endsnippet - - -snippet {# "comment" b -{# $1 #} -endsnippet - - -snippet # "comment" b -{# $1 #} -endsnippet - - -snippet raw "escaped block" b -{% raw %} - $1 -{% endraw %} -endsnippet - - -snippet extends "extends" b -{% extends "${1:template}" %} -endsnippet - - -snippet include "include" b -{% include "${1:template}" %} -endsnippet - - -snippet import "import" b -{% import "${1:template}" %} -endsnippet - - -snippet from "from/import/as" b -{% from "${1:template}" import ${2:name}${3: as ${4:$2}} %} -endsnippet - - -snippet filter "filter" b -{% filter ${1:filter} %} - $2 -{% endfilter %} -endsnippet - - -# Being able to quickly remove the whole 'else' block seems faster to me than -# choosing between 'for' and 'for/else' snippets from the menu. -# snippet for "for" b -# {% for ${1:item} in ${2:sequence} %} -# $3${4: -# {% else %} -# $5} -# {% endfor %} -# endsnippet - - -snippet for "for" b -{% for ${1:item} in ${2:sequence} %} - $3 -{% endfor %} -endsnippet - - -snippet for "for/else" b -{% for ${1:item} in ${2:sequence} %} - $3 -{% else %} - $4 -{% endfor %} -endsnippet - - -snippet if "if" b -{% if ${1:expr} %} - $2 -{% endif %} -endsnippet - - -snippet if "if/else" b -{% if ${1:expr} %} - $2 -{% else %} - $3 -{% endif %} -endsnippet - - -snippet if "if/elif/else" b -{% if ${1:expr} %} - $2 -{% elif %} - $3 -{% else %} - $4 -{% endif %} -endsnippet - - -snippet macro "macro" b -{% macro ${1:name}(${2:args}) %} - $3 -{% endmacro %} -endsnippet - - -snippet call "call" b -{% call ${1:name}(${2:args}) %} - $3 -{% endcall %} -endsnippet - - -snippet set "set" b -{% set ${1:name} = ${2:'value'} %} -endsnippet - - -snippet trans "translation" b -{% trans %} - $1 -{% endtrans %} -endsnippet - - -snippet with "with" b -{% with %} - $1 -{% endwith %} -endsnippet - -snippet autoescape "autoescape" b -{% autoescape ${1:true} %} - $2 -{% endautoescape %} -endsnippet - -# Filters -# @todo: expand only when snippet is preceeded by a | - -snippet batch "batch items" w -batch(linecount=$1, fill_with=${2:None}) -endsnippet - - -snippet dictsort "sort and yield (key, value) pairs" w -dictsort(case_sensitive=${1:False}, by=${2:'key'}) -endsnippet - - -snippet round "round number" w -round(precision=${1:0}, method=${2:'common|ceil|floor'}) -endsnippet - - -snippet urlize "convert plain-text url to " w -urlize(trim_url_limit=${1:None}, nofollow=${2:False}) -endsnippet - - -snippet wordwrap "wordwrap" w -wordwrap(width=${1:79}, break_long_words=${2:True}) -endsnippet - - -snippet truncate "truncate" w -truncate(lenght=${1:79}, killwords=${2:False}, end=${3:'...''}) -endsnippet - - -snippet sum "sum of sequence of numbers + start" w -sum(attribute=${1:None}, start=${2:0}) -endsnippet - - -snippet sort "sort an iterable" w -sort(reverse=${1:False}, case_sensitive=${2:False}, attribute=${3:None}) -endsnippet - - -snippet indent "indent" w -indent(width=${1:4}, indentfirst=${2:False}) -endsnippet - - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/json.snippets b/vim/bundle/ultisnips/UltiSnips/json.snippets deleted file mode 100644 index b0cad83..0000000 --- a/vim/bundle/ultisnips/UltiSnips/json.snippets +++ /dev/null @@ -1,20 +0,0 @@ -priority -50 - -snippet s "String" b -"${1:key}": "${0:value}", -endsnippet - -snippet n "number" b -"${1:key}": ${0:value}, -endsnippet - -snippet a "Array" b -[ - ${VISUAL}$0 -], -endsnippet -snippet o "Object" b -{ - ${VISUAL}$0 -}, -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/ledger.snippets b/vim/bundle/ultisnips/UltiSnips/ledger.snippets deleted file mode 100644 index 4bf4691..0000000 --- a/vim/bundle/ultisnips/UltiSnips/ledger.snippets +++ /dev/null @@ -1,8 +0,0 @@ -priority -50 - -snippet t "Transaction" b -${1:`!v strftime("%Y")`}-${2:`!v strftime("%m")`}-${3:`!v strftime("%d")`} ${4:*} ${5:Payee} - ${6:Expenses} \$${7:0.00} - ${8:Assets:Checking} -$0 -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/lhaskell.snippets b/vim/bundle/ultisnips/UltiSnips/lhaskell.snippets deleted file mode 100644 index 29169a5..0000000 --- a/vim/bundle/ultisnips/UltiSnips/lhaskell.snippets +++ /dev/null @@ -1,3 +0,0 @@ -priority -50 - -extends haskell diff --git a/vim/bundle/ultisnips/UltiSnips/lua.snippets b/vim/bundle/ultisnips/UltiSnips/lua.snippets deleted file mode 100644 index bc59c60..0000000 --- a/vim/bundle/ultisnips/UltiSnips/lua.snippets +++ /dev/null @@ -1,39 +0,0 @@ -priority -50 - -################################# -# Snippets for the Lua language # -################################# -snippet #! "Shebang header" b -#!/usr/bin/env lua -$0 -endsnippet - -snippet !fun(ction)?! "New function" br -function ${1:new_function}(${2:args}) - $0 -end -endsnippet - -snippet forp "pair for loop" b -for ${1:name},${2:val} in pairs(${3:table_name}) do - $0 -end -endsnippet - -snippet fori "ipair for foop" b -for ${1:idx},${2:val} in ipairs(${3:table_name}) do - $0 -end -endsnippet - -snippet for "numeric for loop" b -for ${1:i}=${2:first},${3:last}${4/^..*/(?0:,:)/}${4:step} do - $0 -end -endsnippet - -snippet local "local x = 1" -local ${1:x} = ${0:1} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/mako.snippets b/vim/bundle/ultisnips/UltiSnips/mako.snippets deleted file mode 100644 index fb31ec8..0000000 --- a/vim/bundle/ultisnips/UltiSnips/mako.snippets +++ /dev/null @@ -1,92 +0,0 @@ -priority -50 - -################# -# From snipmate # -################# -snippet def "definition" b -<%def name="${1:name}"> - ${2:} - -endsnippet - -snippet call "call" b -<%call expr="${1:name}"> - ${2:} - -endsnippet - -snippet doc "doc" b -<%doc> - ${1:} - -endsnippet - -snippet text "text" b -<%text> - ${1:} - -endsnippet - -snippet for "for" b -% for ${1:i} in ${2:iter}: - ${3:} -% endfor -endsnippet - -snippet if "if " b -% if ${1:condition}: - ${2:} -% endif -endsnippet - -snippet if "if/else" b -% if ${1:condition}: - ${2:} -% else: - ${3:} -% endif -endsnippet - -snippet try "try" b -% try: - ${1:} -% except${2:}: - ${3:pass} -% endtry -endsnippet - -snippet wh "wh" b -% while ${1:}: - ${2:} -% endwhile -endsnippet - -snippet $ "$" i -${${1:}} -endsnippet - -snippet <% "<%" b -<% ${1:} %> -endsnippet - -snippet -endsnippet - -snippet inherit "inherit" b -<%inherit file="${1:filename}" /> -endsnippet - -snippet include "include" b -<%include file="${1:filename}" /> -endsnippet - -snippet namespace "namespace" b -<%namespace file="${1:name}" /> -endsnippet - -snippet page "page" b -<%page args="${1:}" /> -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/markdown.snippets b/vim/bundle/ultisnips/UltiSnips/markdown.snippets deleted file mode 100644 index fa708ab..0000000 --- a/vim/bundle/ultisnips/UltiSnips/markdown.snippets +++ /dev/null @@ -1,42 +0,0 @@ -priority -50 - -########################### -# Sections and Paragraphs # -########################### -snippet sec "Section" b -# ${1:Section Name} # -$0 -endsnippet - -snippet ssec "Sub Section" b -## ${1:Section Name} ## -$0 -endsnippet - -snippet sssec "SubSub Section" b -### ${1:Section Name} ### -$0 -endsnippet - -snippet par "Paragraph" b -#### ${1:Paragraph Name} #### -$0 -endsnippet - -snippet spar "Paragraph" b -##### ${1:Paragraph Name} ##### -$0 -endsnippet - -################ -# Common stuff # -################ -snippet link "Link to something" -[${1:${VISUAL:Text}}](${3:http://${2:www.url.com}})$0 -endsnippet - -snippet img "Image" -![${1:pic alt}](${2:path}${3/.+/ "/}${3:opt title}${3/.+/"/})$0 -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/objc.snippets b/vim/bundle/ultisnips/UltiSnips/objc.snippets deleted file mode 100644 index 45e41fc..0000000 --- a/vim/bundle/ultisnips/UltiSnips/objc.snippets +++ /dev/null @@ -1,272 +0,0 @@ -priority -50 - -########################################################################### -# TextMate Snippets # -########################################################################### - -snippet imp "#import (imp)" b -#import "${1:`!p snip.rv = re.sub(r'\..*$', '.h', fn)`}" -endsnippet - -snippet Imp "#import <> (Imp)" -#import <${1:Cocoa/Cocoa.h}> -endsnippet - -snippet cl "020 Class (objc)" -@interface ${1:`!p -if len(fn): - snip.rv = re.sub(r'\..*$', '', fn) -else: - snip.rv = "object" -`} : ${2:NSObject} -{ -} -@end - -@implementation $1 -- (id)init -{ - if((self = [super init])) - {$0 - } - return self; -} -@end -endsnippet - -snippet array "NSArray (array)" -NSMutableArray *${1:array} = [NSMutableArray array]; -endsnippet - -snippet dict "NSDictionary (dict)" -NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary]; -endsnippet - -snippet forarray "for NSArray loop (forarray)" -unsigned int ${1:object}Count = [${2:array} count]; - -for(unsigned int index = 0; index < $1Count; index += 1) -{ - ${3:id} $1 = [$2 objectAtIndex:index]; - $0 -} -endsnippet - -snippet objacc "Object Accessors (objacc)" -- (${1:id})${2:thing} -{ - return $2; -} - -- (void)set${2/./\u$0/}:($1)aValue -{ - $0${1/( \*)?$/(?1:$1: )/}old${2/./\u$0/} = $2; - $2 = [aValue retain]; - [old${2/./\u$0/} release]; -} -endsnippet - -snippet sel "@selector" -@selector(${1:method}:) -endsnippet - -snippet cdacc "CoreData Accessors Implementation" -- (${1:id})${2:attribute} -{ - [self willAccessValueForKey:@"$2"]; - $1 value = [self primitiveValueForKey:@"$2"]; - [self didAccessValueForKey:@"$2"]; - return value; -} - -- (void)set${2/./\u$0/}:($1)aValue -{ - [self willChangeValueForKey:@"$2"]; - [self setPrimitiveValue:aValue forKey:@"$2"]; - [self didChangeValueForKey:@"$2"]; -} -endsnippet - -snippet delegate "Delegate Responds to Selector" -if([${1:[self delegate]} respondsToSelector:@selector(${2:selfDidSomething:})]) - [$1 ${3:${2/((^\s*([A-Za-z0-9_]*:)\s*)|(:\s*$)|(:\s*))/(?2:$2self :\:<>)(?4::)(?5: :)/g}}]; - -endsnippet - -snippet thread "Detach New NSThread" -[NSThread detachNewThreadSelector:@selector(${1:method}:) toTarget:${2:aTarget} withObject:${3:anArgument}] -endsnippet - -snippet ibo "IBOutlet (ibo)" -IBOutlet ${1:NSSomeClass} *${2:${1/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}}; -endsnippet - -snippet I "Initialize Implementation (I)" -+ (void)initialize -{ - [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: - $0@"value", @"key", - nil]]; -} -endsnippet - -snippet bind "Key:value binding (bind)" -bind:@"${1:binding}" toObject:${2:observableController} withKeyPath:@"${3:keyPath}" options:${4:nil} -endsnippet - -snippet arracc "LoD array (arracc)" -- (void)addObjectTo${1:Things}:(${2:id})anObject -{ - [${3:${1/./\l$0/}} addObject:anObject]; -} - -- (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i -{ - [$3 insertObject:anObject atIndex:i]; -} - -- ($2)objectIn$1AtIndex:(unsigned int)i -{ - return [$3 objectAtIndex:i]; -} - -- (unsigned int)indexOfObjectIn$1:($2)anObject -{ - return [$3 indexOfObject:anObject]; -} - -- (void)removeObjectFrom$1AtIndex:(unsigned int)i -{ - [$3 removeObjectAtIndex:i]; -} - -- (unsigned int)countOf$1 -{ - return [$3 count]; -} - -- (NSArray *${1/./\l$0/} -{ - return $3; -} - -- (void)set$1:(NSArray *)new$1 -{ - [$3 setArray:new$1]; -} -endsnippet - -snippet arracc "LoD array interface (arracc)" -- (void)addObjectTo${1:Things}:(${2:id})anObject; -- (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i; -- ($2)objectIn$1AtIndex:(unsigned int)i; -- (unsigned int)indexOfObjectIn$1:($2)anObject; -- (void)removeObjectFrom$1AtIndex:(unsigned int)i; -- (unsigned int)countOf$1; -- (NSArray *)${1/./\l$0/}; -- (void)set$1:(NSArray *)new$1; -endsnippet - -snippet focus "Lock Focus" -[self lockFocus]; -$0 -[self unlockFocus]; -endsnippet - -snippet pool "NSAutoreleasePool (pool)" -NSAutoreleasePool *pool = [NSAutoreleasePool new]; -$0 -[pool drain]; -endsnippet - -snippet log "NSLog (log) 2" -NSLog(@"$1"${1/[^%]*(%)?.*/(?1:, :\);)/}$2${1/[^%]*(%)?.*/(?1:\);)/} -endsnippet - -snippet alert "NSRunAlertPanel (alert)" -int choice = NSRunAlertPanel(@"${1:Something important!}", @"${2:Something important just happend, and now I need to ask you, do you want to continue?}", @"${3:Continue}", @"${4:Cancel}", nil); -if(choice == NSAlertDefaultReturn) // "$3" -{ - $0; -} -else if(choice == NSAlertAlternateReturn) // "$4" -{ - $0 -} -endsnippet - -snippet format "NSString stringWithFormat (format)" -[NSString stringWithFormat:@"$1", $2]$0 -endsnippet - -snippet objacc "Object Accessors Interface (objacc)" -- (${1:id})${2:thing}; -- (void)set${2/./\u$0/}:($1)aValue; -endsnippet - -snippet prop "Property" -@property (${1/^(e)$|.*/(?1:r)/}${1:r}${1/^(?:(r)|(e)|(c)|(a))$|.*/(?1:etain)(?2:adonly)(?3:opy)(?4:ssign)/}) ${2:NSSomeClass}$ *${3:${2/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}}; -endsnippet - -snippet getprefs "Read from defaults (getprefs)" -[[NSUserDefaults standardUserDefaults] objectForKey:${1:key}]; -endsnippet - -snippet obs "Register for Notification" -[[NSNotificationCenter defaultCenter] addObserver:${1:self} selector:@selector(${3:${2/^([A-Z]{2})?(.+?)(Notification)?$/\l$2/}}:) name:${2:NSWindowDidBecomeMainNotification} object:${4:nil}]; -endsnippet - -snippet responds "Responds to Selector" -if ([${1:self} respondsToSelector:@selector(${2:someSelector:})]) -{ - [$1 ${3:${2/((:\s*$)|(:\s*))/:<>(?3: )/g}}]; -} -endsnippet - -snippet gsave "Save and Restore Graphics Context (gsave)" -[NSGraphicsContext saveGraphicsState]; -$0 -[NSGraphicsContext restoreGraphicsState]; - -endsnippet - -snippet acc "Scalar Accessors (acc)" -- (${1:unsigned int})${2:thing} -{ - return ${3:$2}; -} - -- (void)set${2/./\u$0/}:(${1:unsigned int})new${2/./\u$0/} -{ - $3 = new${2/./\u$0/}; -} -endsnippet - -snippet acc "Scalar Accessors Interface (acc)" -- (${1:unsigned int})${2:thing}; -- (void)set${2/./\u$0/}:($1)new${2/./\u$0/}; -endsnippet - -snippet stracc "String Accessors (stracc)" -- (NSString *)${1:thing} -{ - return ${2:$1}; -} - -- (void)set${1/.*/\u$0/}:(NSString *)/})${3:a${1/.*/\u$0/}} -{ - $3 = [$3 copy]; - [$2 release]; - $2 = $3; -} -endsnippet - -snippet syn "Synthesize" -@synthesize ${1:property}; -endsnippet - -snippet setprefs "Write to defaults (setprefs)" -[[NSUserDefaults standardUserDefaults] setObject:${1:object} forKey:${2:key}]; -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/ocaml.snippets b/vim/bundle/ultisnips/UltiSnips/ocaml.snippets deleted file mode 100644 index 1ebc347..0000000 --- a/vim/bundle/ultisnips/UltiSnips/ocaml.snippets +++ /dev/null @@ -1,174 +0,0 @@ -priority -50 - -snippet rs "raise" b -raise (${1:Not_found}) -endsnippet - -snippet open "open" -let open ${1:module} in -${2:e} -endsnippet - -snippet try "try" -try ${1:e} -with ${2:Not_found} -> ${3:()} -endsnippet - -snippet ref "ref" -let ${1:name} = ref ${2:val} in -${3:e} -endsnippet - -snippet matchl "pattern match on a list" -match ${1:list} with -| [] -> ${2:()} -| x::xs -> ${3:()} -endsnippet - -snippet matcho "pattern match on an option type" -match ${1:x} with -| Some(${2:y}) -> ${3:()} -| None -> ${4:()} -endsnippet - -snippet fun "anonymous function" -(fun ${1:x} -> ${2:x}) -endsnippet - -snippet cc "commment" -(* ${1:comment} *) -endsnippet - -snippet let "let .. in binding" -let ${1:x} = ${2:v} in -${3:e} -endsnippet - -snippet lr "let rec" -let rec ${1:f} = - ${2:expr} -endsnippet - -snippet if "if" -if ${1:(* condition *)} then - ${2:(* A *)} -else - ${3:(* B *)} -endsnippet - -snippet If "If" -if ${1:(* condition *)} then - ${2:(* A *)} -endsnippet - -snippet while "while" -while ${1:(* condition *)} do - ${2:(* A *)} -done -endsnippet - -snippet for "for" -for ${1:i} = ${2:1} to ${3:10} do - ${4:(* BODY *)} -done -endsnippet - -snippet match "match" -match ${1:(* e1 *)} with -| ${2:p} -> ${3:e2} -endsnippet - -snippet Match "match" -match ${1:(* e1 *)} with -| ${2:p} -> ${3:e2} -endsnippet - -snippet class "class" -class ${1:name} = object - ${2:methods} -end -endsnippet - -snippet obj "obj" -object - ${2:methods} -end -endsnippet - -snippet Obj "object" -object (self) - ${2:methods} -end -endsnippet - -snippet {{ "object functional update" -{< ${1:x} = ${2:y} >} -endsnippet - -snippet beg "beg" -begin - ${1:block} -end -endsnippet - -snippet ml "module instantiantion with functor" -module ${1:Mod} = ${2:Functor}(${3:Arg}) -endsnippet - -snippet mod "module - no signature" -module ${1:(* Name *)} = struct - ${2:(* BODY *)} -end -endsnippet - -snippet Mod "module with signature" -module ${1:(* Name *)} : ${2:(* SIG *)} = struct - ${3:(* BODY *)} -end -endsnippet - -snippet sig "anonymous signature" -sig - ${2:(* BODY *)} -end -endsnippet - -snippet sigf "functor signature or anonymous functor" -functor (${1:Arg} : ${2:ARG}) -> ${3:(* BODY *)} -endsnippet - -snippet func "define functor - no signature" -module ${1:M} (${2:Arg} : ${3:ARG}) = struct - ${4:(* BODY *)} -end -endsnippet - -snippet Func "define functor - with signature" -module ${1:M} (${2:Arg} : ${3:ARG}) : ${4:SIG} = struct - ${5:(* BODY *)} -end -endsnippet - -snippet mot "Declare module signature" -module type ${1:(* Name *)} = sig - ${2:(* BODY *)} -end -endsnippet - -snippet module "Module with anonymous signature" -module ${1:(* Name *)} : sig - ${2:(* SIGNATURE *)} -end = struct - ${3:(* BODY *)} -end -endsnippet - -snippet oo "odoc" -(** ${1:odoc} *) -endsnippet - -snippet qt "inline qtest" -(*$T ${1:name} - ${2:test} -*) -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/perl.snippets b/vim/bundle/ultisnips/UltiSnips/perl.snippets deleted file mode 100644 index abaae3f..0000000 --- a/vim/bundle/ultisnips/UltiSnips/perl.snippets +++ /dev/null @@ -1,132 +0,0 @@ -priority -50 - -########################################################################### -# TextMate Snippets # -########################################################################### -snippet ife "Conditional if..else (ife)" -if ($1) { - ${2:# body...} -} -else { - ${3:# else...} -} - -endsnippet - -snippet ifee "Conditional if..elsif..else (ifee)" -if ($1) { - ${2:# body...} -} -elsif ($3) { - ${4:# elsif...} -} -else { - ${5:# else...} -} - -endsnippet - -snippet xunless "Conditional one-line (unless)" -${1:expression} unless ${2:condition}; - -endsnippet - -snippet xif "Conditional one-line (xif)" -${1:expression} if ${2:condition}; - -endsnippet - -snippet sub "Function (sub)" -sub ${1:function_name} { - ${2:# body...} -} - -endsnippet - -snippet xfore "Loop one-line (xforeach)" -${1:expression} foreach @${2:array}; - -endsnippet - -snippet xwhile "Loop one-line (xwhile)" -${1:expression} while ${2:condition}; - -endsnippet - -snippet test "Test" -#!/usr/bin/env perl -w - -use strict; -use Test::More tests => ${1:1}; -use ${2:ModuleName}; - -ok(${3:assertion}); - -endsnippet - -snippet class "class" -package ${1:ClassName}; - -${2:use parent qw(${3:ParentClass});}${2/.+/\n\n/}sub new { - my $class = shift; - $class = ref $class if ref $class; - my $self = bless {}, $class; - $self; -} - -1; - -endsnippet - -snippet eval "eval" -local $@; -eval { - ${1:# do something risky...} -}; -if (my $${2:exception} = $@) { - ${3:# handle failure...} -} - -endsnippet - -snippet for "for" -for (my $${1:var} = 0; $$1 < ${2:expression}; $$1++) { - ${3:# body...} -} - -endsnippet - -snippet fore "foreach" -foreach ${1:my $${2:x}} (@${3:array}) { - ${4:# body...} -} - -endsnippet - -snippet if "if" -if ($1) { - ${2:# body...} -} - -endsnippet - -snippet slurp "slurp" -my $${1:var} = do { local $/ = undef; open my $fh, '<', ${2:$file}; <$fh> }; - -endsnippet - -snippet unless "unless" -unless ($1) { - ${2:# body...} -} - -endsnippet - -snippet while "while" -while ($1) { - ${2:# body...} -} - -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/php.snippets b/vim/bundle/ultisnips/UltiSnips/php.snippets deleted file mode 100644 index 24f6cc5..0000000 --- a/vim/bundle/ultisnips/UltiSnips/php.snippets +++ /dev/null @@ -1,264 +0,0 @@ -priority -50 - -## Snippets from SnipMate, taken from -## https://github.com/scrooloose/snipmate-snippets.git - -snippet array "array" -$${1:arrayName} = array('${2}' => ${3});${4} -endsnippet - -snippet def "def" -define('${1}'${2});${3} -endsnippet - -snippet do "do" -do { - ${2:// code... } -} while (${1:/* condition */});" -endsnippet - -snippet doc_f "doc_f" -/** - * $2 - * @return ${4:void} - * @author ${5:`!v g:snips_author`} - **/ -${1:public }function ${2:someFunc}(${3}) -{${6} -} -endsnippet - -snippet doc_i "doc_i" -/** - * $1 - * @package ${2:default} - * @author ${3:`!v g:snips_author`} - **/ -interface ${1:someClass} -{${4} -} // END interface $1" -endsnippet - -snippet else "else" -else { - ${1:// code...} -} -endsnippet - -snippet for "for" -for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) { - ${4:// code...} -} -endsnippet - -snippet foreachk "foreachk" -foreach ($${1:variable} as $${2:key} => $${3:value}){ - ${4:// code...} -} -endsnippet - -snippet get "get" -$_GET['${1}']${2} -endsnippet - -snippet if "if" -if (${1:/* condition */}) { - ${2:// code...} -} -endsnippet - -snippet inc "inc" -include '${1:file}';${2} -endsnippet - -snippet log "log" -error_log(var_export(${1}, true));${2} -endsnippet - -snippet post "post" -$_POST['${1}']${2} -endsnippet - -snippet req1 "req1" -require_once '${1:file}';${2} -endsnippet - -snippet session "session" -$_SESSION['${1}']${2} -endsnippet - -snippet t "t" -$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5} -endsnippet - -snippet var "var" -var_export(${1});${2} -endsnippet - -snippet getter "PHP Class Getter" b -/* - * Getter for $1 - */ -public function get${1/\w+\s*/\u$0/}() -{ - return $this->$1;$2 -} -$4 -endsnippet - -snippet setter "PHP Class Setter" b -/* - * Setter for $1 - */ -public function set${1/\w+\s*/\u$0/}($$1) -{ - $this->$1 = $$1;$3 - ${4:return $this;} -} -$0 -endsnippet - -snippet gs "PHP Class Getter Setter" b -/* - * Getter for ${1/(\w+)\s*;/$1/} - */ -public function get${1/(\w+)\s*;/\u$1/}() -{ - return $this->${1/(\w+)\s*;/$1/};$2 -} - -/* - * Setter for ${1/(\w+)\s*;/$1/} - */ -public function set${1/(\w+)\s*;/\u$1/}($${1/(\w+)\s*;/$1/}) -{ - $this->${1/(\w+)\s*;/$1/} = $${1/(\w+)\s*;/$1/};$3 - ${4:return $this;} -} -$0 -endsnippet - -snippet pub "Public function" b -public function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet pro "Protected function" b -protected function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet pri "Private function" b -private function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet pubs "Public static function" b -public static function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet pros "Protected static function" b -protected static function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet pris "Private static function" b -private static function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet fu "Function snip" b -function ${1:name}(${2:$param}) -{ - ${VISUAL}${3:return null;} -} -$0 -endsnippet - -snippet fore "Foreach loop" -foreach ($${1:variable} as $${3:value}){ - ${VISUAL}${4} -} -$0 -endsnippet - -snippet new "New class instance" b -$$1 = new $1($2); -$0 -endsnippet - -snippet ife "if else" -if (${1:/* condition */}) { - ${2:// code...} -} else { - ${3:// code...} -} -$0 -endsnippet - -snippet class "Class declaration template" b -/** - * Class ${1:`!p snip.rv=snip.fn.split('.')[0]`} - * @author ${2:`!v g:snips_author`} - */ -class $1 -{ - public function ${3:__construct}(${4:$options}) - { - ${4:// code} - } -} -$0 -endsnippet - -snippet construct "__construct()" b -/** - * @param $2mixed ${1/, /\n * \@param mixed /g} - */ -public function __construct(${1:$dependencies}) -{${1/\$(\w+)(, )*/\n $this->$1 = $$1;/g} -} -$0 -endsnippet - -snippet pr "Dumb debug helper in HTML" -echo '
    ' . var_export($1, 1) . '
    ';$0 -endsnippet - -snippet pc "Dumb debug helper in cli" -var_export($1);$0 -endsnippet - -# Symfony 2 based snippets -snippet sfa "Symfony 2 Controller action" -/** -* @Route("/${1:route_name}", name="$1") -* @Template() -*/ -public function $1Action($2) -{ - $3 - return ${4:array();}$0 -} -endsnippet - -# :vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/puppet.snippets b/vim/bundle/ultisnips/UltiSnips/puppet.snippets deleted file mode 100644 index a8fc1ed..0000000 --- a/vim/bundle/ultisnips/UltiSnips/puppet.snippets +++ /dev/null @@ -1,232 +0,0 @@ -priority -50 - -######################################################################### -# Python helper code # -######################################################################### - -global !p -import vim -import os.path -def get_module_namespace_and_basename(): - """This function will try to guess the current class or define name you are - trying to create. Note that for this to work you should be using the module - structure as per the style guide. Examples inputs and it's output - * /home/nikolavp/puppet/modules/collectd/manifests/init.pp -> collectd - * /home/nikolavp/puppet/modules/collectd/manfistes/mysql.pp -> collectd::mysql - """ - first_time = True - current_file_path_without_ext = vim.eval('expand("%:p:r")') or "" - if not current_file_path_without_ext: - return "name" - parts = os.path.split(current_file_path_without_ext) - namespace = '' - while parts[0] and parts[0] != '/': - if parts[1] == 'init' and first_time and not namespace: - first_time = False - parts = os.path.split(parts[0]) - continue - if parts[1] == 'manifests': - return os.path.split(parts[0])[1] + ('::' + namespace).rstrip(':') - else: - namespace = parts[1] + '::' + namespace - parts = os.path.split(parts[0]) - # couldn't guess the namespace. The user is editing a raw file in no module like the site.pp file - return "name" -endglobal - -############################################################################### -# Puppet Language Constructs # -# See http://docs.puppetlabs.com/puppet/latest/reference/lang_summary.html # -############################################################################### - -snippet class "Class declaration" b -class ${1:`!p snip.rv = get_module_namespace_and_basename()`} { - ${0:# body} -} -endsnippet - -snippet define "Definition" b -define ${1:`!p snip.rv = get_module_namespace_and_basename()`} { - ${0:# body} -} -endsnippet - -################################################################# -# Puppet Types # -# See http://docs.puppetlabs.com/references/latest/type.html # -################################################################# - -snippet cron "Cron resource type" b -cron { '${1:name}': - user => ${2:user}, - command => '${3:command}', - minute => ${3:minute}, - hour => ${4:hour}, -} -endsnippet - -snippet exec "Exec resource type" b -exec { '${1:command}': - refreshonly => true, -} -endsnippet - -snippet file "File resource type" b -file { '${1:name}': - source => "puppet://${2:path}", - mode => ${3:mode}, -endsnippet - -snippet File "Defaults for file" b -File { - owner => ${1:username}, - group => ${2:groupname}, -} -endsnippet - -snippet group "Group resource type" b -group { '${1:groupname}': - ensure => ${3:present}, - gid => ${2:gid}, -endsnippet - -snippet mount "Mount resource type" b -mount { '${1:path}': - device => '${2:/dev}', - fstype => '${3:filesystem}', - ensure => mounted, - options => 'rw,errors=remount-ro', -} -endsnippet - -snippet package "Package resource type" b -package { '${1:name}': - ensure => ${2:installed}, -} -endsnippet - -snippet user "user resource type" b -user { '${1:username}': - ensure => ${2:present}, - uid => ${3:uid}, - gid => ${4:gid}, - comment => ${5:gecos}, - home => ${6:homedirectory}, - managehome => false, - require => Group['${7:group'}], -endsnippet - -snippet service "Service resource type" b -service { '${1:name}': - hasstatus => true, - enable => true, - ensure => running, -} -endsnippet - -######################################################################## -# Puppet Functions # -# See http://docs.puppetlabs.com/references/latest/function.html # -######################################################################## - -snippet alert "Alert Function" b -alert("${1:message}")${0} -endsnippet - -snippet crit "Crit Function" b -crit("${1:message}")${0} -endsnippet - -snippet debug "Debug Function" b -debug("${1:message}")${0} -endsnippet - -snippet defined "Defined Function" b -defined(${1:Resource}["${2:name}"])${0} -endsnippet - -snippet emerg "Emerg Function" b -emerg("${1:message}")${0} -endsnippet - -snippet extlookup "Simple Extlookup" b -$${1:Variable} = extlookup("${2:Lookup}")${0} -endsnippet - -snippet extlookup "Extlookup with defaults" b -$${1:Variable} = extlookup("${2:Lookup}", ${3:Default})${0} -endsnippet - -snippet extlookup "Extlookup with defaults and custom data file" b -$${1:Variable} = extlookup("${2:Lookup}", ${3:Default}, ${4:Data Source})${0} -endsnippet - -snippet fail "Fail Function" b -fail("${1:message}")${0} -endsnippet - -snippet hiera "Hiera Function" b -$${1:Variable} = hiera("${2:Lookup}")${0} -endsnippet - -snippet hiera "Hiera with defaults" b -$${1:Variable} = hiera("${2:Lookup}", ${3:Default})${0} -endsnippet - -snippet hiera "Hiera with defaults and override" b -$${1:Variable} = hiera("${2:Lookup}", ${3:Default}, ${4:Override})${0} -endsnippet - -snippet hiera_hash "Hiera Hash Function" b -$${1:Variable} = hiera_hash("${2:Lookup}")${0} -endsnippet - -snippet hiera_hash "Hiera Hash with defaults" b -$${1:Variable} = hiera_hash("${2:Lookup}", ${3:Default})${0} -endsnippet - -snippet hiera_hash "Hiera Hash with defaults and override" b -$${1:Variable} = hiera_hash("${2:Lookup}", ${3:Default}, ${4:Override})${0} -endsnippet - -snippet hiera_include "Hiera Include Function" b -hiera_include("${1:Lookup}")${0} -endsnippet - -snippet include "Include Function" b -include ${1:classname}${0} -endsnippet - -snippet info "Info Function" b -info("${1:message}")${0} -endsnippet - -snippet inline_template "Inline Template Function" b -inline_template("<%= ${1:template} %>")${0} -endsnippet - -snippet notice "Notice Function" b -notice("${1:message}")${0} -endsnippet - -snippet realize "Realize Function" b -realize(${1:Resource}["${2:name}"])${0} -endsnippet - -snippet regsubst "Regsubst Function" b -regsubst($${1:Target}, '${2:regexp}', '${3:replacement}')${0} -endsnippet - -snippet split "Split Function" b -$${1:Variable} = split($${1:Target}, '${2:regexp}')${0} -endsnippet - -snippet versioncmp "Version Compare Function" b -$${1:Variable} = versioncmp('${1:version}', '${2:version}')${0} -endsnippet - -snippet warning "Warning Function" b -warning("${1:message}")${0} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/python.snippets b/vim/bundle/ultisnips/UltiSnips/python.snippets deleted file mode 100644 index 357d01d..0000000 --- a/vim/bundle/ultisnips/UltiSnips/python.snippets +++ /dev/null @@ -1,533 +0,0 @@ -priority -50 - -########################################################################### -# TEXTMATE SNIPPETS # -########################################################################### - -#! header -snippet #! "Shebang header for python scripts" b -#!/usr/bin/env python -# encoding: utf-8 -$0 -endsnippet - -snippet ifmain "ifmain" b -if __name__ == '__main__': - ${1:main()}$0 -endsnippet - -snippet for "for loop" b -for ${1:item} in ${2:iterable}: - ${3:pass} -endsnippet - -########## -# COMMON # -########## - -# The smart def and smart class snippets use a global option called -# "g:ultisnips_python_style" which, if set to "doxygen" will use doxygen -# style comments in docstrings. - -global !p - -NORMAL = 0x1 -DOXYGEN = 0x2 -SPHINX = 0x3 - -SINGLE_QUOTES = 0x1 -DOUBLE_QUOTES = 0x2 - -def get_args(arglist): - args = [arg.split('=')[0].strip() for arg in arglist.split(',') if arg] - args = [arg for arg in args if arg and arg != "self"] - - return args - - -def get_quoting_style(snip): - style = snip.opt("g:ultisnips_python_quoting_style", "double") - if style == 'single': - return SINGLE_QUOTES - return DOUBLE_QUOTES - -def tripple_quotes(snip): - if get_quoting_style(snip) == SINGLE_QUOTES: - return "'''" - return '"""' - -def get_style(snip): - style = snip.opt("g:ultisnips_python_style", "normal") - - if style == "doxygen": return DOXYGEN - elif style == "sphinx": return SPHINX - else: return NORMAL - - -def format_arg(arg, style): - if style == DOXYGEN: - return "@param %s @todo" % arg - elif style == SPHINX: - return ":param %s: @todo" % arg - elif style == NORMAL: - return ":%s: @todo" % arg - - -def format_return(style): - if style == DOXYGEN: - return "@return: @todo" - elif style in (NORMAL, SPHINX): - return ":returns: @todo" - - -def write_docstring_args(args, snip): - if not args: - snip.rv += ' {0}'.format(tripple_quotes(snip)) - return - - snip.rv += '\n' + snip.mkline('', indent='') - - style = get_style(snip) - - for arg in args: - snip += format_arg(arg, style) - - -def write_init_body(args, parents, snip): - parents = [p.strip() for p in parents.split(",")] - parents = [p for p in parents if p != 'object'] - - for p in parents: - snip += p + ".__init__(self)" - - if parents: - snip.rv += '\n' + snip.mkline('', indent='') - - for arg in args: - snip += "self._%s = %s" % (arg, arg) - - -def write_slots_args(args, snip): - args = ['"_%s"' % arg for arg in args] - snip += '__slots__ = (%s,)' % ', '.join(args) - -endglobal - -######################################## -# Class & Special Method Name Snippets # -######################################## - -snippet class "class with docstrings" b -class ${1:MyClass}(${2:object}): - - `!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` - - def __init__(self$4): - `!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined1.}`!p -snip.rv = "" -snip >> 2 - -args = get_args(t[4]) - -write_docstring_args(args, snip) -if args: - snip.rv += '\n' + snip.mkline('', indent='') - snip += '{0}'.format(tripple_quotes(snip)) - -write_init_body(args, t[2], snip) -` - $0 -endsnippet - - -snippet slotclass "class with slots and docstrings" b -class ${1:MyClass}(${2:object}): - - `!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` -`!p -snip >> 1 -args = get_args(t[4]) -write_slots_args(args, snip) -` - - def __init__(self$4): - `!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined.}`!p -snip.rv = "" -snip >> 2 - -args = get_args(t[4]) - -write_docstring_args(args, snip) -if args: - snip.rv += '\n' + snip.mkline('', indent='') - snip += tripple_quotes(snip) - -write_init_body(args, t[2], snip) -` - $0 -endsnippet - - -snippet contain "methods for emulating a container type" b -def __len__(self): - ${1:pass} - -def __getitem__(self, key): - ${2:pass} - -def __setitem__(self, key, value): - ${3:pass} - -def __delitem__(self, key): - ${4:pass} - -def __iter__(self): - ${5:pass} - -def __reversed__(self): - ${6:pass} - -def __contains__(self, item): - ${7:pass} -endsnippet - - -snippet context "context manager methods" b -def __enter__(self): - ${1:pass} - -def __exit__(self, exc_type, exc_value, traceback): - ${2:pass} -endsnippet - - -snippet attr "methods for customizing attribute access" b -def __getattr__(self, name): - ${1:pass} - -def __setattr__(self, name, value): - ${2:pass} - -def __delattr__(self, name): - ${3:pass} -endsnippet - - -snippet desc "methods implementing descriptors" b -def __get__(self, instance, owner): - ${1:pass} - -def __set__(self, instance, value): - ${2:pass} - -def __delete__(self, instance): - ${3:pass} -endsnippet - - -snippet cmp "methods implementing rich comparison" -def __eq__(self, other): - ${1:pass} - -def __ne__(self, other): - ${2:pass} - -def __lt__(self, other): - ${3:pass} - -def __le__(self, other): - ${4:pass} - -def __gt__(self, other): - ${5:pass} - -def __ge__(self, other): - ${6:pass} - -def __cmp__(self, other): - ${7:pass} -endsnippet - - -snippet repr "methods implementing string representation" -def __repr__(self): - ${1:pass} - -def __str__(self): - ${2:pass} - -def __unicode__(self): - ${3:pass} -endsnippet - - -# note: reflected operands and augmented arithmeitc assignements have been -# intentionally ommited to reduce verbosity. -snippet numeric "methods for emulating a numeric type" b -def __add__(self, other): - ${1:pass} - -def __sub__(self, other): - ${2:pass} - -def __mul__(self, other): - ${3:pass} - -def __div__(self, other): - ${4:pass} - -def __truediv__(self, other): - ${5:pass} - -def __floordiv__(self, other): - ${6:pass} - - -def __mod__(self, other): - ${7:pass} - -def __divmod__(self, other): - ${8:pass} - -def __pow__(self, other): - ${9:pass} - - -def __lshift__(self, other): - ${10:pass} - -def __rshift__(self, other): - ${11:pass} - -def __and__(self, other): - ${12:pass} - -def __xor__(self, other): - ${13:pass} - -def __or__(self, other): - ${14:pass} - - -def __neg__(self): - ${15:pass} - -def __pos__(self): - ${16:pass} - -def __abs__(self): - ${17:pass} - -def __invert__(self): - ${18:pass} - - -def __complex__(self): - ${19:pass} - -def __int__(self): - ${20:pass} - -def __long__(self): - ${21:pass} - -def __float__(self): - ${22:pass} - - -def __oct__(self): - ${22:pass} - -def __hex__(self): - ${23:pass} - - -def __index__(self): - ${24:pass} - -def __coerce__(self, other): - ${25:pass} -endsnippet - -snippet def "function with docstrings" b -def ${1:function}(`!p -if snip.indent: - snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}): - `!p snip.rv = tripple_quotes(snip)`${4:@todo: Docstring for $1.}`!p -snip.rv = "" -snip >> 1 - -args = get_args(t[2]) -if args: - write_docstring_args(args, snip) - -style = get_style(snip) -snip += format_return(style) -snip.rv += '\n' + snip.mkline('', indent='') -snip += tripple_quotes(snip) ` - ${0:pass} -endsnippet - - -# doesn't expand when there is a word in front -snippet /(^|(?<=\W))\./ "self." r -self. -endsnippet - -snippet from "from module import name" b -from ${1:module} import ${2:Stuff} -endsnippet - - -############## -# PROPERTIES # -############## -snippet roprop "Read Only Property" b -@property -def ${1:name}(self): - ${2:return self._$1}$0 -endsnippet - -snippet rwprop "Read write property" b -def ${1:name}(): - `!p snip.rv = tripple_quotes(snip) if t[2] else '' -`${2:@todo: Docstring for $1.}`!p -if t[2]: - snip >> 1 - - style = get_style(snip) - snip.rv += '\n' + snip.mkline('', indent='') - snip += format_return(style) - snip.rv += '\n' + snip.mkline('', indent='') - snip += tripple_quotes(snip) -else: - snip.rv = ""` - def fget(self): - return self._$1$0 - - def fset(self, value): - self._$1 = value - return locals() - -$1 = property(**$1(), doc=$1.__doc__) -endsnippet - - -#################### -# If / Else / Elif # -#################### -snippet if "If" b -if ${1:condition}: - ${2:pass} -endsnippet - -snippet ife "If / Else" b -if ${1:condition}: - ${2:pass} -else: - ${3:pass} -endsnippet - -snippet ifee "If / Elif / Else" b -if ${1:condition}: - ${2:pass} -elif ${3:condition}: - ${4:pass} -else: - ${5:pass} -endsnippet - - -########################## -# Try / Except / Finally # -########################## -snippet try "Try / Except" b -try: - ${1:pass} -except ${2:Exception}, ${3:e}: - ${4:raise $3} -endsnippet - -snippet try "Try / Except / Else" b -try: - ${1:pass} -except ${2:Exception}, ${3:e}: - ${4:raise $3} -else: - ${5:pass} -endsnippet - -snippet try "Try / Except / Finally" b -try: - ${1:pass} -except ${2:Exception}, ${3:e}: - ${4:raise $3} -finally: - ${5:pass} -endsnippet - -snippet try "Try / Except / Else / Finally" b -try: - ${1:pass} -except${2: ${3:Exception}, ${4:e}}: - ${5:raise} -else: - ${6:pass} -finally: - ${7:pass} -endsnippet - - -##################### -# Assertions & Tests # -##################### - -snippet pdb "Set PDB breakpoint" b -import pdb; pdb.set_trace() -endsnippet - -snippet ipdb "Set IPDB breakpoint" b -import ipdb; ipdb.set_trace() -endsnippet - -snippet pudb "Set PUDB breakpoint" b -import pudb; pudb.set_trace() -endsnippet - -snippet ae "Assert equal" b -self.assertEqual(${1:first},${2:second}) -endsnippet - -snippet at "Assert True" b -self.assertTrue(${0:exp}) -endsnippet - -snippet af "Assert False" b -self.assertFalse(${1:expression}) -endsnippet - -snippet aae "Assert almost equal" b -self.assertAlmostEqual(${1:first},${2:second}) -endsnippet - -snippet ar "Assert raises" b -self.assertRaises(${1:exception}, ${2:func}${3/.+/, /}${3:arguments}) -endsnippet - - -snippet testcase "pyunit testcase" b -class Test${1:Class}(${2:unittest.TestCase}): - - `!p snip.rv = tripple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = tripple_quotes(snip)` - - def setUp(self): - ${4:pass} - - def tearDown(self): - ${5:pass} - - def test_${6:name}(self): - ${7:pass} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/rails.snippets b/vim/bundle/ultisnips/UltiSnips/rails.snippets deleted file mode 100644 index 5c52179..0000000 --- a/vim/bundle/ultisnips/UltiSnips/rails.snippets +++ /dev/null @@ -1,904 +0,0 @@ -priority -50 - -snippet anaf "accepts_nested_attributes_for" -accepts_nested_attributes_for :${1:association_name}${2:${3:, :allow_destroy => true}${4:, :reject_if => proc \{ |obj| ${5:obj.blank?} \}}} - -endsnippet - -snippet tcbi "Create binary column" -t.binary :${1:title}${2:, :limit => ${3:2}.megabytes} -$0 -endsnippet - -snippet tcb "Create boolean column" -t.boolean :${1:title} -$0 -endsnippet - -snippet cla "Create controller class" -class ${1:Model}Controller < ApplicationController - before_filter :find_${2:model} - - $0 - - private - def find_${2} - @$2 = ${3:$1}.find(params[:id]) if params[:id] - end -end -endsnippet - -snippet tcda "Create date column" -t.date :${1:title} -$0 -endsnippet - -snippet tcdt "Create datetime column" -t.datetime :${1:title} -$0 -endsnippet - -snippet tcd "Create decimal column" -t.decimal :${1:title}${2:${3:, :precision => ${4:10}}${5:, :scale => ${6:2}}} -$0 -endsnippet - -snippet tcf "Create float column" -t.float :${1:title} -$0 -endsnippet - -snippet cla "Create functional test class" -require 'test_helper' - -class ${1:Model}ControllerTest < ActionController::TestCase - test$0 -end - -endsnippet - -snippet tci "Create integer column" -t.integer :${1:title} -$0 -endsnippet - -snippet tcl "Create lock_version column" -t.integer :lock_version, :null => false, :default => 0 -$0 -endsnippet - -# FIXME: handling literal bracket pair inside of nested tab groups? -snippet tcr "Create references column" -t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}} -$0 -endsnippet - -snippet resources "Create resources controller class" -class ${1:Model}sController < ApplicationController - before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy] - - # GET /${1/./\l$0/}s - # GET /${1/./\l$0/}s.xml - def index - @${1/./\l$0/}s = ${1:Model}.all - - respond_to do |wants| - wants.html # index.html.erb - wants.xml { render :xml => @${1/./\l$0/}s } - end - end - - # GET /${1/./\l$0/}s/1 - # GET /${1/./\l$0/}s/1.xml - def show - respond_to do |wants| - wants.html # show.html.erb - wants.xml { render :xml => @${1/./\l$0/} } - end - end - - # GET /${1/./\l$0/}s/new - # GET /${1/./\l$0/}s/new.xml - def new - @${1/./\l$0/} = ${1:Model}.new - - respond_to do |wants| - wants.html # new.html.erb - wants.xml { render :xml => @${1/./\l$0/} } - end - end - - # GET /${1/./\l$0/}s/1/edit - def edit - end - - # POST /${1/./\l$0/}s - # POST /${1/./\l$0/}s.xml - def create - @${1/./\l$0/} = ${1:Model}.new(params[:${1/./\l$0/}]) - - respond_to do |wants| - if @${1/./\l$0/}.save - flash[:notice] = '${1:Model} was successfully created.' - wants.html { redirect_to(@${1/./\l$0/}) } - wants.xml { render :xml => @${1/./\l$0/}, :status => :created, :location => @${1/./\l$0/} } - else - wants.html { render :action => "new" } - wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } - end - end - end - - # PUT /${1/./\l$0/}s/1 - # PUT /${1/./\l$0/}s/1.xml - def update - respond_to do |wants| - if @${1/./\l$0/}.update_attributes(params[:${1/./\l$0/}]) - flash[:notice] = '${1:Model} was successfully updated.' - wants.html { redirect_to(@${1/./\l$0/}) } - wants.xml { head :ok } - else - wants.html { render :action => "edit" } - wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } - end - end - end - - # DELETE /${1/./\l$0/}s/1 - # DELETE /${1/./\l$0/}s/1.xml - def destroy - @${1/./\l$0/}.destroy - - respond_to do |wants| - wants.html { redirect_to(${1/./\l$0/}s_url) } - wants.xml { head :ok } - end - end - - private - def find_${1/./\l$0/} - @${1/./\l$0/} = ${1:Model}.find(params[:id]) - end - -end - -endsnippet - -snippet tcs "Create string column" -t.string :${1:title} -$0 -endsnippet - -snippet tct "Create text column" -t.text :${1:title} -$0 -endsnippet - -snippet tcti "Create time column" -t.time :${1:title} -$0 -endsnippet - -snippet tcts "Create timestamp column" -t.timestamp :${1:title} -$0 -endsnippet - -snippet tctss "Create timestamps columns" -t.timestamps -$0 -endsnippet - -snippet mcol "Migration Create Column (mcc)" -t.column ${1:title}, :${2:string} -$0 -endsnippet - -snippet mccc "Migration Create Column Continue (mccc)" -t.column ${1:title}, :${2:string} -mccc$0 -endsnippet - -snippet mtab "Migration Drop Create Table (mdct)" -drop_table :${1:table}${2: [press tab twice to generate create_table]} -endsnippet - -snippet mcol "Migration Remove and Add Column (mrac)" -remove_column :${1:table}, :${2:column}${3: [press tab twice to generate add_column]} -endsnippet - -snippet rdb "RAILS_DEFAULT_LOGGER.debug (rdb)" -RAILS_DEFAULT_LOGGER.debug "${1:message}"$0 -endsnippet - -snippet tre "Table column(s) rename" -t.rename(:${1:old_column_name}, :${2:new_column_name}) -$0 -endsnippet - -snippet art "Test Assert Redirected To (art)" -assert_redirected_to ${2::action => "${1:index}"} -endsnippet - -snippet asre "Test Assert Response (are)" -assert_response :${1:success}, @response.body$0 -endsnippet - -snippet aftc "after_create" -after_create $0 -endsnippet - -snippet aftd "after_destroy" -after_destroy $0 -endsnippet - -snippet afts "after_save" -after_save $0 -endsnippet - -snippet aftu "after_update" -after_update $0 -endsnippet - -snippet aftv "after_validation" -after_validation $0 -endsnippet - -snippet aftvoc "after_validation_on_create" -after_validation_on_create $0 -endsnippet - -snippet aftvou "after_validation_on_update" -after_validation_on_update $0 -endsnippet - -snippet asg "assert(var = assigns(:var))" -assert(${1:var} = assigns(:${1}), "Cannot find @${1}") -$0 -endsnippet - -snippet asd "assert_difference" -assert_difference "${1:Model}.${2:count}", ${3:1} do - $0 -end -endsnippet - -snippet asnd "assert_no_difference" -assert_no_difference "${1:Model}.${2:count}" do - $0 -end -endsnippet - -snippet artnpp "assert_redirected_to (nested path plural)" -assert_redirected_to ${10:${2:parent}_${3:child}_path(${4:@}${5:${2}})} -endsnippet - -snippet artnp "assert_redirected_to (nested path)" -assert_redirected_to ${2:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})} -endsnippet - -snippet artpp "assert_redirected_to (path plural)" -assert_redirected_to ${10:${2:model}s_path} -endsnippet - -snippet artp "assert_redirected_to (path)" -assert_redirected_to ${2:${12:model}_path(${13:@}${14:${12}})} -endsnippet - -snippet asrj "assert_rjs" -assert_rjs :${1:replace}, ${2:"${3:dom id}"} -endsnippet - -snippet ass "assert_select" -assert_select '${1:path}'${2:, :${3:text} => ${4:'${5:inner_html}'}}${6: do - $0 -end} -endsnippet - -snippet befc "before_create" -before_create $0 -endsnippet - -snippet befd "before_destroy" -before_destroy $0 -endsnippet - -snippet befs "before_save" -before_save $0 -endsnippet - -snippet befu "before_update" -before_update $0 -endsnippet - -snippet befv "before_validation" -before_validation $0 -endsnippet - -snippet befvoc "before_validation_on_create" -before_validation_on_create $0 -endsnippet - -snippet befvou "before_validation_on_update" -before_validation_on_update -endsnippet - -snippet bt "belongs_to (bt)" -belongs_to :${1:object}${2:, :class_name => "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"} -endsnippet - -snippet crw "cattr_accessor" -cattr_accessor :${0:attr_names} -endsnippet - -snippet defcreate "def create - resource" -def create - @${1:model} = ${2:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}.new(params[:$1]) - $0 - respond_to do |wants| - if @$1.save - flash[:notice] = '$2 was successfully created.' - wants.html { redirect_to(@$1) } - wants.xml { render :xml => @$1, :status => :created, :location => @$1 } - else - wants.html { render :action => "new" } - wants.xml { render :xml => @$1.errors, :status => :unprocessable_entity } - end - end -end - -endsnippet - -snippet test "test do..end" -test "${1:something interesting}" do - $0 -end -endsnippet - -snippet deftg "def get request" -def test_should_get_${1:action} - ${2:@${3:model} = ${4:$3s}(:${5:fixture_name}) - }get :${1}${6:, :id => @$3.to_param} - assert_response :success - $0 -end -endsnippet - -snippet deftp "def post request" -def test_should_post_${1:action} - ${3:@$2 = ${4:$2s}(:${5:fixture_name}) - }post :${1}${6:, :id => @$2.to_param}, :${2:model} => { $0 } - assert_response :redirect - -end -endsnippet - -snippet fina "find(:all)" -find(:all${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]}) -endsnippet - -snippet finf "find(:first)" -find(:first${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]}) -endsnippet - -snippet fini "find(id)" -find(${1:id}) -endsnippet - -snippet fine "find_each" -find_each(${1::conditions => {:${2:field} => ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}| - $0 -end -endsnippet - -snippet finb "find_in_batches" -find_in_batches(${1::conditions => {:${2:field} => ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}s| - $4s.each do |$4| - $0 - end -end -endsnippet - -snippet habtm "has_and_belongs_to_many (habtm)" -has_and_belongs_to_many :${1:object}${2:, :join_table => "${3:table_name}", :foreign_key => "${4:${1}_id}"} -endsnippet - -snippet hm "has_many (hm)" -has_many :${1:object}s${2:, :class_name => "${1}", :foreign_key => "${4:reference}_id"} -endsnippet - -snippet hmt "has_many (through)" -has_many :${1:objects}, :through => :${2:join_association}${3:, :source => :${4:${2}_table_foreign_key_to_${1}_table}} -endsnippet - -snippet hmd "has_many :dependent => :destroy" -has_many :${1:object}s${2:, :class_name => "${1}", :foreign_key => "${4:reference}_id"}, :dependent => :destroy$0 -endsnippet - -snippet ho "has_one (ho)" -has_one :${1:object}${2:, :class_name => "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"} -endsnippet - -snippet logd "logger.debug" -${1:Rails.}logger.debug { "${1:message}" }$0 -endsnippet - -snippet loge "logger.error" -logger.error { "${1:message}" }$0 -endsnippet - -snippet logf "logger.fatal" -logger.fatal { "${1:message}" }$0 -endsnippet - -snippet logi "logger.info" -logger.info { "${1:message}" }$0 -endsnippet - -snippet logw "logger.warn" -logger.warn { "${1:message}" }$0 -endsnippet - -snippet mp "map(&:sym_proc)" -map(&:${1:id}) -endsnippet - -snippet mapca "map.catch_all" -${1:map}.catch_all "*${2:anything}", :controller => "${3:default}", :action => "${4:error}" - -endsnippet - -snippet map "map.named_route" -${1:map}.${2:connect} '${3::controller/:action/:id}' -endsnippet - -snippet mapr "map.resource" -${1:map}.resource :${2:resource}${10: do |${11:$2}| - $0 -end} -endsnippet - -snippet maprs "map.resources" -${1:map}.resources :${2:resource}${10: do |${11:$2}| - $0 -end} -endsnippet - -snippet mapwo "map.with_options" -${1:map}.with_options :${2:controller} => '${3:thing}' do |${4:$3}| - $0 -end - -endsnippet - -snippet mrw "mattr_accessor" -mattr_accessor :${0:attr_names} -endsnippet - -snippet ncl "named_scope lambda" -named_scope :name, lambda { |${1:param}| { :conditions => ${3:['${4:${5:field} = ?}', ${6:$1}]} } } - -endsnippet - -snippet nc "named_scope" -named_scope :name${1:, :joins => :${2:table}}, :conditions => ${3:['${4:${5:field} = ?}', ${6:true}]} - -endsnippet - -snippet dscope "default_scope" -default_scope ${1:order(${2:'${3:created_at DESC}'})} -endsnippet - -snippet flash "flash[...]" -flash[:${1:notice}] = "${2:Successfully created...}"$0 -endsnippet - -snippet rea "redirect_to (action)" -redirect_to :action => "${1:index}" -endsnippet - -snippet reai "redirect_to (action, id)" -redirect_to :action => "${1:show}", :id => ${0:@item} -endsnippet - -snippet rec "redirect_to (controller)" -redirect_to :controller => "${1:items}" -endsnippet - -snippet reca "redirect_to (controller, action)" -redirect_to :controller => "${1:items}", :action => "${2:list}" -endsnippet - -snippet recai "redirect_to (controller, action, id)" -redirect_to :controller => "${1:items}", :action => "${2:show}", :id => ${0:@item} -endsnippet - -snippet renpp "redirect_to (nested path plural)" -redirect_to(${2:${10:parent}_${11:child}_path(${12:@}${13:${10}})}) -endsnippet - -snippet renp "redirect_to (nested path)" -redirect_to(${2:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})}) -endsnippet - -snippet repp "redirect_to (path plural)" -redirect_to(${2:${10:model}s_path}) -endsnippet - -snippet rep "redirect_to (path)" -redirect_to(${2:${12:model}_path(${13:@}${14:${12}})}) -endsnippet - -snippet reb "redirect_to :back" -redirect_to :back -endsnippet - -snippet ra "render (action)... (ra)" -render :action => "${1:action}" -endsnippet - -snippet ral "render (action,layout) (ral)" -render :action => "${1:action}", :layout => "${2:layoutname}" -endsnippet - -snippet rf "render (file) (rf)" -render :file => "${1:filepath}" -endsnippet - -snippet rfu "render (file,use_full_path) (rfu)" -render :file => "${1:filepath}", :use_full_path => ${2:false} -endsnippet - -snippet ri "render (inline) (ri)" -render :inline => "${1:<%= 'hello' %>}" -endsnippet - -snippet ril "render (inline,locals) (ril)" -render :inline => "${1:<%= 'hello' %>}", :locals => { ${2::name} => "${3:value}"$4 } -endsnippet - -snippet rit "render (inline,type) (rit)" -render :inline => "${1:<%= 'hello' %>}", :type => ${2::rxml} -endsnippet - -snippet rl "render (layout) (rl)" -render :layout => "${1:layoutname}" -endsnippet - -snippet rn "render (nothing) (rn)" -render :nothing => ${1:true} -endsnippet - -snippet rns "render (nothing,status) (rns)" -render :nothing => ${1:true}, :status => ${2:401} -endsnippet - -snippet rt "render (text) (rt)" -render :text => "${1:text to render...}" -endsnippet - -snippet rtl "render (text,layout) (rtl)" -render :text => "${1:text to render...}", :layout => "${2:layoutname}" -endsnippet - -snippet rtlt "render (text,layout => true) (rtlt)" -render :text => "${1:text to render...}", :layout => ${2:true} -endsnippet - -snippet rts "render (text,status) (rts)" -render :text => "${1:text to render...}", :status => ${2:401} -endsnippet - -snippet ru "render (update)" -render :update do |${2:page}| - $2.$0 -end -endsnippet - -snippet rest "respond_to" -respond_to do |wants| - wants.${1:html}${2: { $0 \}} -end -endsnippet - -snippet resw "respond_with" -respond_with(${1:@${2:model}})${3: do |format| - format.${4:html} { $0 \} -end} -endsnippet - -# FIXME -snippet returning "returning do |variable| ... end" -returning ${1:variable} do${2/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1: |)/}${2:v}${2/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:|)/} - $0 -end -endsnippet - -snippet t. "t.binary (tcbi)" -t.binary :${1:title}${2:, :limit => ${3:2}.megabytes} -t.$0 -endsnippet - -snippet t. "t.boolean (tcb)" -t.boolean :${1:title} -t.$0 -endsnippet - -snippet t. "t.date (tcda)" -t.date :${1:title} -t.$0 -endsnippet - -snippet t. "t.datetime (tcdt)" -t.datetime :${1:title} -t.$0 -endsnippet - -snippet t. "t.decimal (tcd)" -t.decimal :${1:title}${2:${3:, :precision => ${4:10}}${5:, :scale => ${6:2}}} -t.$0 -endsnippet - -snippet t. "t.float (tcf)" -t.float :${1:title} -t.$0 -endsnippet - -snippet t. "t.integer (tci)" -t.integer :${1:title} -t.$0 -endsnippet - -snippet t. "t.lock_version (tcl)" -t.integer :lock_version, :null => false, :default => 0 -t.$0 -endsnippet - -snippet t. "t.references (tcr)" -t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}} -t.$0 -endsnippet - -snippet t. "t.rename (tre)" -t.rename(:${1:old_column_name}, :${2:new_column_name}) -t.$0 -endsnippet - -snippet t. "t.string (tcs)" -t.string :${1:title} -t.$0 -endsnippet - -snippet t. "t.text (tct)" -t.text :${1:title} -t.$0 -endsnippet - -snippet t. "t.time (tcti)" -t.time :${1:title} -t.$0 -endsnippet - -snippet t. "t.timestamp (tcts)" -t.timestamp :${1:title} -t.$0 -endsnippet - -snippet t. "t.timestamps (tctss)" -t.timestamps -t.$0 -endsnippet - -snippet vaoif "validates_acceptance_of if" -validates_acceptance_of :${1:terms}${2:${3:, :accept => "${4:1}"}${5:, :message => "${6:You must accept the terms of service}"}}, :if => proc { |obj| ${7:obj.condition?} }} -endsnippet - -snippet vao "validates_acceptance_of" -validates_acceptance_of :${1:terms}${2:${3:, :accept => "${4:1}"}${5:, :message => "${6:You must accept the terms of service}"}} -endsnippet - -snippet va "validates_associated (va)" -validates_associated :${1:attribute}${2:, :on => :${3:create}} -endsnippet - -snippet vaif "validates_associated if (vaif)" -validates_associated :${1:attribute}${2:, :on => :${3:create}, :if => proc { |obj| ${5:obj.condition?} }} -endsnippet - -snippet vc "validates_confirmation_of (vc)" -validates_confirmation_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:should match confirmation}"} -endsnippet - -snippet vcif "validates_confirmation_of if (vcif)" -validates_confirmation_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:should match confirmation}", :if => proc { |obj| ${5:obj.condition?} }} -endsnippet - -snippet ve "validates_exclusion_of (ve)" -validates_exclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not allowed}"} -endsnippet - -snippet veif "validates_exclusion_of if (veif)" -validates_exclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not allowed}"}, :if => proc { |obj| ${7:obj.condition?} }} -endsnippet - -snippet vfif "validates_format_of if" -validates_format_of :${1:attribute}, :with => /${2:^[${3:\w\d}]+\$}/${4:, :on => :${5:create}, :message => "${6:is invalid}"}, :if => proc { |obj| ${7:obj.condition?} }} -endsnippet - -snippet vf "validates_format_of" -validates_format_of :${1:attribute}, :with => /${2:^[${3:\w\d}]+\$}/${4:, :on => :${5:create}, :message => "${6:is invalid}"} -endsnippet - -snippet viif "validates_inclusion_of if" -validates_inclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not included in the list}"}, :if => proc { |obj| ${7:obj.condition?} }} -endsnippet - -snippet vi "validates_inclusion_of" -validates_inclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not included in the list}"} -endsnippet - -snippet vl "validates_length_of (vl)" -validates_length_of :${1:attribute}, :within => ${2:3..20}${3:, :on => :${4:create}, :message => "${5:must be present}"} -endsnippet - -snippet vlif "validates_length_of if" -validates_length_of :${1:attribute}, :within => ${2:3..20}${3:, :on => :${4:create}, :message => "${5:must be present}"}, :if => proc { |obj| ${6:obj.condition?} }} -endsnippet - -snippet vnif "validates_numericality_of if" -validates_numericality_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:is not a number}"}, :if => proc { |obj| ${5:obj.condition?} }} -endsnippet - -snippet vn "validates_numericality_of" -validates_numericality_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:is not a number}"} -endsnippet - -snippet vp "validates_presence_of (vp)" -validates_presence_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:can't be blank}"} -endsnippet - -snippet vpif "validates_presence_of if (vpif) 2" -validates_presence_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:can't be blank}"}, :if => proc { |obj| ${5:obj.condition?} }} -endsnippet - -snippet vu "validates_uniqueness_of (vu)" -validates_uniqueness_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:must be unique}"} -endsnippet - -snippet vuif "validates_uniqueness_of if (vuif)" -validates_uniqueness_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:must be unique}", :if => proc { |obj| ${6:obj.condition?} }} -endsnippet - -snippet verify "verify -- render" -verify :only => [:$1], :method => :post, :render => {:status => 500, :text => "use HTTP-POST"} - -endsnippet - -snippet verify "verify -- redirect" -verify :only => [:$1], :session => :user, :params => :id, :redirect_to => {:action => '${2:index}'} - -endsnippet - -snippet wants "wants_format" -wants.${1:js|xml|html}${2: { $0 \}} -endsnippet - -snippet xdelete "xhr delete" -xhr :delete, :${1:destroy}, :id => ${2:1}$0 -endsnippet - -snippet xget "xhr get" -xhr :get, :${1:show}${2:, :id => ${3:1}}$0 -endsnippet - -snippet xpost "xhr post" -xhr :post, :${1:create}, :${2:object} => { $3 } -endsnippet - -snippet xput "xhr put" -xhr :put, :${1:update}, :id => ${2:1}, :${3:object} => { $4 }$0 -endsnippet - -snippet finl "find(:last)" -find(:last${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]}) -endsnippet - -snippet sweeper "Create sweeper class" -class ${1:Model}Sweeper < ActionController::Caching::Sweeper - observe ${1:Model} - - def after_save(${1/./\l$0/}) - expire_cache(${1/./\l$0/}) - end - - def after_destroy(${1/./\l$0/}) - expire_cache(${1/./\l$0/}) - end - - private - - def expire_cache(${1/./\l$0/}) - ${0:expire_page ${1/./\l$0/}s_path - expire_page ${1/./\l$0/}_path(${1/./\l$0/})} - end - -end -endsnippet - -snippet col "collection routes" -collection do - ${1:get :${2:action}} - ${3:put :${4:action}} - ${5:post :${6:action}} - ${7:delete :${8:action}} -end -endsnippet - -snippet format "format (respond_with)" -format.${1:html|xml|json|js|any} { $0 } -endsnippet - -snippet gem "gem" -gem '${1:name}'${2:${3:, "${4:1.0}"}${5:${6:, :require => ${7:"${8:$1}"}}${9:, :group => :${10:test}}}} -endsnippet - -snippet gemg "gem :git" -gem '${1:paperclip}', :git => "${2:git://github.com/thoughtbot/paperclip.git}"${3:, :branch => "${4:rails3}"} -endsnippet - -snippet match "match" -match '${1:${2::controller}${3:/${4::action}${5:/${6::id}${7:(.:format)}}}}'${8: => '${9:$2}#${10:$4}'${11:, :as => :${12:$10}}} -endsnippet - -snippet member "member routes" -member do - ${1:get :${2:action}} - ${3:put :${4:action}} - ${5:post :${6:action}} - ${7:delete :${8:action}} -end -endsnippet - -snippet res "resources" -resources :${1:posts}${2: do - $3 -end} -endsnippet - -snippet scope "scope" -scope :${1:name}, ${2:joins(:${3:table}).}where(${4:'${5:$3.${6:field}} = ?', ${7:'${8:value}'}}) -endsnippet - -snippet scopel "scope lambda" -scope :${1:name}, lambda { |${2:param}| ${3:where(${4::${5:field} => ${6:"${7:value}"}})} } -endsnippet - -snippet scopee "scope with extension" -scope :${1:name}, ${2:where(${3::${4:field} => ${5:'${6:value}'}})} do - def ${7:method_name} - $0 - end -end -endsnippet - -snippet sb "scoped_by" -scoped_by_${1:attribute}(${2:id}) -endsnippet - -snippet setup "setup do..end" -setup do - $0 -end -endsnippet - -snippet trans "Translation snippet" -I18n.t('`!v substitute(substitute(substitute(@%, substitute(getcwd() . "/", "\/", "\\\\/", "g"), "", ""), "\\(\\.\\(html\\|js\\)\\.\\(haml\\|erb\\)\\|\\(_controller\\)\\?\\.rb\\)$", "", ""), "/", ".", "g")`.${2:${1/[^\w]/_/g}}${3}', :default => "${1:some_text}"${4})${5:$0} -endsnippet - -snippet route_spec -it 'routes to #${1:action}' do - ${2:get}('/${3:url}').should route_to('`!v substitute(expand('%:t:r'), '_routing_spec$', '', '')`#$1'${4:, ${5:params}})${6} -end -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/rst.snippets b/vim/bundle/ultisnips/UltiSnips/rst.snippets deleted file mode 100644 index 0894ef3..0000000 --- a/vim/bundle/ultisnips/UltiSnips/rst.snippets +++ /dev/null @@ -1,61 +0,0 @@ -priority -50 - -########################################################################### -# General Stuff # -########################################################################### -snippet part "Part" b -`!p snip.rv = len(t[1])*'#'` -${1:Part name} -`!p snip.rv = len(t[1])*'#'` - -$0 -endsnippet - -snippet sec "Section" b -${1:Section name} -`!p snip.rv = len(t[1])*'='` - -$0 -endsnippet - -snippet ssec "Subsection" b -${1:Section name} -`!p snip.rv = len(t[1])*'-'` - -$0 -endsnippet - -snippet sssec "Subsubsection" b -${1:Section name} -`!p snip.rv = len(t[1])*'^'` - -$0 -endsnippet - -snippet chap "Chapter" b -`!p snip.rv = len(t[1])*'*'` -${1:Chapter name} -`!p snip.rv = len(t[1])*'*'` - -$0 -endsnippet - -snippet para "Paragraph" b -${1:Paragraph name} -`!p snip.rv = len(t[1])*'"'` - -$0 -endsnippet - -########################################################################### -# More Specialized Stuff. # -########################################################################### -snippet cb "Code Block" b -.. code-block:: ${1:lua} - - ${2:code} - -$0 -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/ruby.snippets b/vim/bundle/ultisnips/UltiSnips/ruby.snippets deleted file mode 100644 index 09a114f..0000000 --- a/vim/bundle/ultisnips/UltiSnips/ruby.snippets +++ /dev/null @@ -1,570 +0,0 @@ -priority -50 - -snippet "^#!" "#!/usr/bin/env ruby" r -#!/usr/bin/env ruby -$0 -endsnippet - - -snippet "^# ?[uU][tT][fF]-?8" "# encoding: UTF-8" r -# encoding: UTF-8 -$0 -endsnippet - - - -snippet If " if " -${1:command} if ${0:expression} -endsnippet - - - -snippet Unless " unless " -${1:command} unless ${0:expression} -endsnippet - - - -snippet if "if ... end" -if ${1:condition} - ${2:# TODO} -end -endsnippet - - - -snippet ife "if ... else ... end" -if ${1:condition} - ${2:# TODO} -else - ${3:# TODO} -end -endsnippet - - - -snippet ifee "if ... elseif ... else ... end" -if ${1:condition} - ${2:# TODO} -elsif ${3:condition} - ${4:# TODO} -else - ${0:# TODO} -end -endsnippet - - - -snippet unless "unless ... end" -unless ${1:condition} - ${0:# TODO} -end -endsnippet - - - -snippet unlesse "unless ... else ... end" -unless ${1:condition} - ${2:# TODO} -else - ${0:# TODO} -end -endsnippet - - - -snippet unlesee "unless ... elseif ... else ... end" -unless ${1:condition} - ${2:# TODO} -elsif ${3:condition} - ${4:# TODO} -else - ${0:# TODO} -end -endsnippet - - - -snippet "\b(de)?f" "def ..." r -def ${1:function_name}${2: ${3:*args}} - ${0:# TODO} -end -endsnippet - - - -snippet defi "def initialize ..." -def initialize${1: ${2:*args}} - ${0:# TODO} -end -endsnippet - - - -snippet defr "def ... rescue ..." -def ${1:function_name}${2: ${3:*args}} - ${4:# TODO} -rescue - ${0:# TODO} -end -endsnippet - - - -snippet For "(..).each { || }" -(${1:from}..${2:to}).each { |${3:i}| ${4:# TODO} } -endsnippet - - - -snippet for "(..).each do || end" -(${1:from}..${2:to}).each do |${3:i}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Merge!" ".merge!() { |,,| }" r -`!p snip.rv=match.group(1)`.merge!(${1:other_hash}) { |${2:key},${3:oldval},${4:newval}| ${5:block} } -endsnippet - - - -snippet "(\S+)\.merge!" ".merge!() do |,,| end" r -`!p snip.rv=match.group(1)`.merge!(${1:other_hash}) do |${2:key},${3:oldval},${4:newval}| - ${0:block} -end -endsnippet - - - -snippet "(\S+)\.Del(ete)?_?if" ".delete_if { |,| }" r -`!p snip.rv=match.group(1)`.delete_if { |${1:key},${2:value}| ${3:# TODO} } -endsnippet - - - -snippet "(\S+)\.del(ete)?_?if" ".delete_if do |,| end" r -`!p snip.rv=match.group(1)`.delete_if do |${1:key},${2:value}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Keep_?if" ".keep_if { |,| }" r -`!p snip.rv=match.group(1)`.keep_if { |${1:key},${2:value}| ${3:# TODO} } -endsnippet - - - -snippet "(\S+)\.keep_?if" ".keep_if do ,| end" r -`!p snip.rv=match.group(1)`.keep_if do |${1:key},${2:value}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Reject" ".reject { |,| }" r -`!p snip.rv=match.group(1)`.reject { |${1:key},${2:value}| ${3:# TODO} } -endsnippet - - - -snippet "(\S+)\.reject" ".reject do ,| end" r -`!p snip.rv=match.group(1)`.reject do |${1:key},${2:value}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Select" ".select { || }" r -`!p snip.rv=match.group(1)`.select { |${1:item}| ${2:block} } -endsnippet - - - -snippet "(\S+)\.select" ".select do || end" r -`!p snip.rv=match.group(1)`.select do |${1:item}| - ${0:block} -end -endsnippet - - - -snippet "(\S+)\.Sort" ".sort { |
    ,| }" r -`!p snip.rv=match.group(1)`.sort { |${1:a},${2:b}| ${3:# TODO} } -endsnippet - - - -snippet "(\S+)\.sort" ".sort do |,| end" r -`!p snip.rv=match.group(1)`.sort do |${1:a},${2:b}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Each_?k(ey)?" ".each_key { || }" r -`!p snip.rv=match.group(1)`.each_key { |${1:key}| ${2:# TODO} } -endsnippet - - - -snippet "(\S+)\.each_?k(ey)?" ".each_key do |key| end" r -`!p snip.rv=match.group(1)`.each_key do |${1:key}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Each_?val(ue)?" ".each_value { || }" r -`!p snip.rv=match.group(1)`.each_value { |${1:value}| ${2:# TODO} } -endsnippet - - - -snippet "(\S+)\.each_?val(ue)?" ".each_value do || end" r -`!p snip.rv=match.group(1)`.each_value do |${1:value}| - ${0:# TODO} -end -endsnippet - - - -snippet Each ".each { || }" -${1:elements}.each { |${2:${1/s$//}}| ${3:# TODO} } -endsnippet - - - -snippet each ".each do || end" -${1:elements}.each do |${2:${1/s$//}}| - ${0:# TODO} -end -endsnippet - - - -snippet "each_?s(lice)?" ".each_slice(n) do |slice| end" r -${1:elements}.each_slice(${2:2}) do |${3:slice}| - ${0:# TODO} -end -endsnippet - - - -snippet "Each_?s(lice)?" ".each_slice(n) { |slice| }" r -${1:elements}.each_slice(${2:2}) { |${3:slice}| ${0:# TODO} } -endsnippet - - - - -snippet "(\S+)\.Map" ".map { || }" r -`!p snip.rv=match.group(1)`.map { |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| ${2:# TODO} } -endsnippet - - - -snippet "(\S+)\.map" ".map do || end" r -`!p snip.rv=match.group(1)`.map do |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Rev(erse)?_?each" ".reverse_each { || }" r -`!p snip.rv=match.group(1)`.reverse_each { |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| ${2:# TODO} } -endsnippet - - - -snippet "(\S+)\.rev(erse)?_?each" ".reverse_each do || end" r -`!p snip.rv=match.group(1)`.reverse_each do |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.Each" ".each { || }" r -`!p snip.rv=match.group(1)`.each { |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| ${2:# TODO} } -endsnippet - - - -snippet "(\S+)\.each" ".each do || end" r -`!p snip.rv=match.group(1)`.each do |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`}| - ${0:# TODO} -end -endsnippet - - - - -snippet "(\S+)\.Each_?w(ith)?_?i(ndex)?" ".each_with_index { |,| }" r -`!p snip.rv=match.group(1)`.each_with_index { |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`},${2:i}| ${3:# TODO} }$0 -endsnippet - - - -snippet "(\S+)\.each_?w(ith)?_?i(ndex)?" ".each_with_index do |,| end" r -`!p snip.rv=match.group(1)`.each_with_index do |${1:`!p -element_name = match.group(1).lstrip('$@') -ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) -try: - wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) - snip.rv = wmatch.group(1).lower() -except: - snip.rv = 'element' -`},${2:i}| - ${0:# TODO} -end -endsnippet - - - - -snippet "(\S+)\.Each_?p(air)?" ".each_pair { |,| }" r -`!p snip.rv=match.group(1)`.each_pair { |${1:key},${2:value}| ${3:# TODO} } -endsnippet - - - -snippet "(\S+)\.each_?p(air)?" ".each_pair do |,| end" r -`!p snip.rv=match.group(1)`.each_pair do |${1:key},${2:value}| - ${0:# TODO} -end -endsnippet - - - -snippet "(\S+)\.sub" ".sub() { }" r -`!p snip.rv=match.group(1)`.sub(${1:expression}) { ${2:"replace_with"} } -endsnippet - - - -snippet "(\S+)\.gsub" ".gsub() { }" r -`!p snip.rv=match.group(1)`.gsub(${1:expression}) { ${2:"replace_with"} } -endsnippet - - - -snippet "(\S+)\.index" ".index { |item| }" r -`!p snip.rv=match.group(1)`.index { |${1:item}| ${2:block} } -endsnippet - - - -snippet "(\S+)\.Index" ".index do |item| ... end" r -`!p snip.rv=match.group(1)`.index do |${1:item}| - ${0:block} -end -endsnippet - - - -snippet do "do || ... end" i -do |${1:args}| - $0 -end -endsnippet - - - -snippet Do "do ... end" i -do - $0 -end -endsnippet - - -snippet until "until ... end" -until ${1:expression} - ${0:# TODO} -end -endsnippet - - - -snippet Until "begin ... end until " -begin - ${0:# TODO} -end until ${1:expression} -endsnippet - - - -snippet while "while ... end" -while ${1:expression} - ${0:# TODO} -end -endsnippet - - - -snippet While "begin ... end while " -begin - ${0:# TODO} -end while ${1:expression} -endsnippet - - - -snippet "\b(r|attr)" "attr_reader :" r -attr_reader :${0:attr_names} -endsnippet - - - -snippet "\b(w|attr)" "attr_writer :" r -attr_writer :${0:attr_names} -endsnippet - - - -snippet "\b(rw|attr)" "attr_accessor :" r -attr_accessor :${0:attr_names} -endsnippet - - - -snippet begin "begin ... rescue ... end" -begin - ${1:# TODO} -rescue - ${0:# TODO} -end -endsnippet - - - -snippet begin "begin ... rescue ... else ... ensure ... end" -begin - ${1:# Raise exception} -rescue Exception => e - puts e.message - puts e.backtrace.inspect - ${2:# Rescue} -else - ${3:# other exception} -ensure - ${0:# always excute} -end -endsnippet - - - -snippet rescue -rescue Exception => e - puts e.message - puts e.backtrace.inspect - ${0:# Rescue} -endsnippet - - - -snippet "\b(case|sw(itch)?)" "case when ... end" r -case ${1:variable} -when ${2:expression} -$0 -end -endsnippet - - - -snippet alias "alias : :" -alias :${1:new_name} :${2:old_name} -endsnippet - - - -snippet class "class def initialize ... end end" -class ${1:class_name} - def initialize ${2:*args} - $0 - end -end -endsnippet - - - -snippet module "module" -module ${1:module_name} - $0 -end -endsnippet - - - -snippet ### -=begin - $0 -=end -endsnippet - -# vim: set ts=2 sw=2 expandtab: diff --git a/vim/bundle/ultisnips/UltiSnips/scss.snippets b/vim/bundle/ultisnips/UltiSnips/scss.snippets deleted file mode 100644 index 70a44a0..0000000 --- a/vim/bundle/ultisnips/UltiSnips/scss.snippets +++ /dev/null @@ -1,55 +0,0 @@ -priority -50 - -snippet /@?imp/ "@import '...';" br -@import '${1:file}'; -endsnippet - -snippet /@?inc/ "@include mixin(...);" br -@include ${1:mixin}(${2:arguments}); -endsnippet - -snippet /@?ext?/ "@extend %placeholder;" br -@extend %${1:placeholder}; -endsnippet - -snippet /@?mixin/ "@mixin (...) { ... }" br -@mixin ${1:name}(${2:arguments}) { - ${VISUAL}$0 -} -endsnippet - -snippet /@?fun/ "@function (...) { ... }" br -@function ${1:name}(${2:arguments}) { - ${VISUAL}$0 -} -endsnippet - -snippet /@?if/ "@if (...) { ... }" br -@if ${1:condition} { - ${VISUAL}$0 -} -endsnippet - -snippet /(} )?@?else/ "@else { ... }" br -@else ${1:condition} { - ${VISUAL}$0 -} -endsnippet - -snippet /@?for/ "@for loop" br -@for ${1:$i} from ${2:1} through ${3:3} { - ${VISUAL}$0 -} -endsnippet - -snippet /@?each/ "@each loop" br -@each ${1:$item} in ${2:item, item, item} { - ${VISUAL}$0 -} -endsnippet - -snippet /@?while/ "@while loop" br -@while ${1:$i} ${2:>} ${3:0} { - ${VISUAL}$0 -} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/sh.snippets b/vim/bundle/ultisnips/UltiSnips/sh.snippets deleted file mode 100644 index 9cc4577..0000000 --- a/vim/bundle/ultisnips/UltiSnips/sh.snippets +++ /dev/null @@ -1,92 +0,0 @@ -priority -50 - -global !p -import vim - -# Tests for the existence of a variable declared by Vim's filetype detection -# suggesting the type of shell script of the current file -def testShell(scope, shell): - return vim.eval("exists('" + scope + ":is_" + shell + "')") - -# Loops over the possible variables, checking for global variables -# first since they indicate an override by the user. -def getShell(): - for scope in ["g", "b"]: - for shell in ["bash", "posix", "sh", "kornshell"]: - if testShell(scope, shell) == "1": - if shell == "kornshell": - return "ksh" - if shell == "posix": - return "sh" - return shell - return "sh" -endglobal - -########################################################################### -# TextMate Snippets # -########################################################################### -snippet #! -`!p snip.rv = '#!/bin/' + getShell() + "\n\n" ` -endsnippet - -snippet !env "#!/usr/bin/env (!env)" -`!p snip.rv = '#!/usr/bin/env ' + getShell() + "\n\n" ` -endsnippet - -snippet temp "Tempfile" -${1:TMPFILE}="$(mktemp -t ${2:`!p -snip.rv = re.sub(r'[^a-zA-Z]', '_', snip.fn) or "untitled" -`})" -${3:${4/(.+)/trap "/}${4:rm -f '$${1/.*\s//}'}${4/(.+)/" 0 # EXIT\n/}${5/(.+)/trap "/}${5:rm -f '$${1/.*\s//}'; exit 1}${5/(.+)/" 2 # INT\n/}${6/(.+)/trap "/}${6:rm -f '$${1/.*\s//}'; exit 1}${6/(.+)/" 1 15 # HUP TERM\n/}} - -endsnippet - -snippet case "case .. esac (case)" -case ${1:word} in - ${2:pattern} ) - $0;; -esac -endsnippet - -snippet elif "elif .. (elif)" -elif ${2:[[ ${1:condition} ]]}; then - ${0:#statements} -endsnippet - -snippet for "for ... done (for)" -for (( i = 0; i < ${1:10}; i++ )); do - ${0:#statements} -done -endsnippet - -snippet forin "for ... in ... done (forin)" -for ${1:i}${2/.+/ in /}${2:words}; do - ${0:#statements} -done -endsnippet - -snippet here "here document (here)" -<<-${2:'${1:TOKEN}'} - $0 -${1/['"`](.+)['"`]/$1/} -endsnippet - -snippet if "if ... then (if)" -if ${2:[[ ${1:condition} ]]}; then - ${0:#statements} -fi -endsnippet - -snippet until "until ... (done)" -until ${2:[[ ${1:condition} ]]}; do - ${0:#statements} -done -endsnippet - -snippet while "while ... (done)" -while ${2:[[ ${1:condition} ]]}; do - ${0:#statements} -done -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/snippets.snippets b/vim/bundle/ultisnips/UltiSnips/snippets.snippets deleted file mode 100644 index ee0c8c7..0000000 --- a/vim/bundle/ultisnips/UltiSnips/snippets.snippets +++ /dev/null @@ -1,21 +0,0 @@ -priority -50 - -# We use a little hack so that the snippet is expanded -# and parsed correctly -snippet snip "Snippet definition" b -`!p snip.rv = "snippet"` ${1:Tab_trigger} "${2:Description}" ${3:b} -$0 -`!p snip.rv = "endsnippet"` -endsnippet - -snippet global "Global snippet" b -`!p snip.rv = "global"` !p -$0 -`!p snip.rv = "endglobal"` -endsnippet - -snippet vis "${VISUAL}" i -\$\{VISUAL${1:${2:default}${3:/transform/}}\} -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/tcl.snippets b/vim/bundle/ultisnips/UltiSnips/tcl.snippets deleted file mode 100644 index 6584915..0000000 --- a/vim/bundle/ultisnips/UltiSnips/tcl.snippets +++ /dev/null @@ -1,52 +0,0 @@ -priority -50 - -########################################################################### -# TEXTMATE SNIPPETS # -########################################################################### -snippet for "for... (for)" b -for {${1:set i 0}} {${2:\$i < \$n}} {${3:incr i}} { - ${4} -} - -endsnippet - -snippet foreach "foreach... (foreach)" -foreach ${1:var} ${2:\$list} { - ${3} -} - -endsnippet - -snippet if "if... (if)" b -if {${1:condition}} { - ${2} -} - -endsnippet - -snippet proc "proc... (proc)" b -proc ${1:name} {${2:args}} \ -{ - ${3} -} - -endsnippet - -snippet switch "switch... (switch)" b -switch ${1:-exact} -- ${2:\$var} { - ${3:match} { - ${4} - } - default {${5}} -} - -endsnippet - -snippet while "while... (while)" b -while {${1:condition}} { - ${2} -} - -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/tex.snippets b/vim/bundle/ultisnips/UltiSnips/tex.snippets deleted file mode 100644 index c32d21f..0000000 --- a/vim/bundle/ultisnips/UltiSnips/tex.snippets +++ /dev/null @@ -1,110 +0,0 @@ -priority -50 - -extends texmath - -snippet "b(egin)?" "begin{} / end{}" br -\begin{${1:something}} - ${0:${VISUAL}} -\end{$1} -endsnippet - -snippet tab -\begin{${1:t}${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}{${2:c}} -$0${2/((?<=.)c|l|r)|./(?1: & )/g} -\end{$1${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}} -endsnippet - -snippet fig "Figure environment" b -\begin{figure}${2:[htpb]} - \centering - \includegraphics[width=${3:0.8}\linewidth]{${4:name.ext}} - \caption{${4/(\w+)\.\w+/\u$1/}$0} - \label{fig:${4/(\w+)\.\w+/$1/}} -\end{figure} -endsnippet - -snippet enum "Enumerate" b -\begin{enumerate} - \item $0 -\end{enumerate} -endsnippet - -snippet item "Itemize" b -\begin{itemize} - \item $0 -\end{itemize} -endsnippet - -snippet desc "Description" b -\begin{description} - \item[$1] $0 -\end{description} -endsnippet - -snippet it "Individual item" b -\item ${1} -$0 -endsnippet - -snippet part "Part" b -\part{${1:part name}} -\label{prt:${2:${1/(\w+)|\W+/(?1:\L$0\E:_)/ga}}} - -${0} -endsnippet - -snippet cha "Chapter" b -\chapter{${1:chapter name}} -\label{cha:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet sec "Section" b -\section{${1:section name}} -\label{sec:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet sub "Subsection" b -\subsection{${1:subsection name}} -\label{sub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet ssub "Subsubsection" b -\subsubsection{${1:subsubsection name}} -\label{ssub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet par "Paragraph" b -\paragraph{${1:paragraph name}} -\label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet subp "Subparagraph" b -\subparagraph{${1:subparagraph name}} -\label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} - -${0} -endsnippet - -snippet ni "Non-indented paragraph" b -\noindent -${0} -endsnippet - -snippet pac "Package" b -\usepackage[${1:options}]{${2:package}}$0 -endsnippet - -snippet lp "Long parenthesis" -\left(${1:${VISUAL:contents}}\right)$0 -endsnippet -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/texmath.snippets b/vim/bundle/ultisnips/UltiSnips/texmath.snippets deleted file mode 100644 index d0a25e9..0000000 --- a/vim/bundle/ultisnips/UltiSnips/texmath.snippets +++ /dev/null @@ -1,56 +0,0 @@ -priority -50 - -############## -# MATH STUFF # -############## -snippet eq "Equation" b -\begin{equation} - $0 -\end{equation} -endsnippet - -snippet eqnn "Equation without number" b -\begin{equation*} - $0 -\end{equation*} -endsnippet - -snippet eqa "Equation array" b -\begin{eqnarray} - $1 & $2 & $0 -\end{eqnarray} -endsnippet - -snippet eqann "Equation array without numbers" b -\begin{eqnarray*} - $1 & $2 & $0 -\end{eqnarray*} - -endsnippet -snippet frac "Fraction" w -\frac{${1:${VISUAL:nom}}}{${2:denom}} -endsnippet - -snippet mat "Smart Matrix" -\begin{${1:p/b/v/V/B/small}matrix} - $0 -\end{$1matrix} -endsnippet - -snippet lr( "left( right)" w -\left( ${1:${VISUAL}} \right) -endsnippet - -snippet lr| "left| right|" w -\left| ${1:${VISUAL}} \right| -endsnippet - -snippet lr{ "left\{ right\}" w -\left\\{ ${1:${VISUAL}} \right\\} -endsnippet - -snippet lr[ "left[ right]" w -\left[ ${1:${VISUAL}} \right] -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/vim.snippets b/vim/bundle/ultisnips/UltiSnips/vim.snippets deleted file mode 100644 index 5ff22d2..0000000 --- a/vim/bundle/ultisnips/UltiSnips/vim.snippets +++ /dev/null @@ -1,60 +0,0 @@ -priority -50 - -########################################################################### -# SnipMate Snippets # -########################################################################### -snippet header -" File: ${1:`!v expand('%:t')`} -" Author: ${2:`!v g:snips_author`} -" Description: ${3} -${4:" Last Modified: `!v strftime("%B %d, %Y")`} - -$0 -endsnippet - -snippet gvar "Global / configuration variable" -if !exists("g:${1:MyUltraImportantVar}") - let g:$1 = ${2:"${3:}"} -endif -endsnippet - -snippet guard -if exists('${1:did_`!p snip.rv = snip.fn.replace('.','_')`}') || &cp${2: || version < 700} - finish -endif -let $1 = 1${3} -endsnippet - -snippet f -fun ${1:function_name}(${2}) - ${3:" code} -endf -endsnippet - -snippet for -for ${1:needle} in ${2:haystack} - ${3:" code} -endfor -endsnippet - -snippet wh -while ${1:condition} - ${2:" code} -endw -endsnippet - -snippet if -if ${1:condition} - ${2:" code} -endif -endsnippet - -snippet ife -if ${1:condition} - ${2} -else - ${3} -endif -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/UltiSnips/xhtml.snippets b/vim/bundle/ultisnips/UltiSnips/xhtml.snippets deleted file mode 100644 index a9c5a29..0000000 --- a/vim/bundle/ultisnips/UltiSnips/xhtml.snippets +++ /dev/null @@ -1,3 +0,0 @@ -priority -50 - -extends html diff --git a/vim/bundle/ultisnips/UltiSnips/xml.snippets b/vim/bundle/ultisnips/UltiSnips/xml.snippets deleted file mode 100644 index 92dfb6e..0000000 --- a/vim/bundle/ultisnips/UltiSnips/xml.snippets +++ /dev/null @@ -1,16 +0,0 @@ -priority -50 - -snippet xml "XML declaration" b - - -endsnippet - -snippet t "Simple tag" b -<${1:tag}> - ${2:content} - -endsnippet - -snippet ti "Inline tag" b -<${1:tag}>${2:content} -endsnippet diff --git a/vim/bundle/ultisnips/UltiSnips/zsh.snippets b/vim/bundle/ultisnips/UltiSnips/zsh.snippets deleted file mode 100644 index f7986ea..0000000 --- a/vim/bundle/ultisnips/UltiSnips/zsh.snippets +++ /dev/null @@ -1,17 +0,0 @@ -priority -50 - -extends sh - -priority -49 - -snippet #! "shebang" b -#!/bin/zsh - -endsnippet - -snippet !env "#!/usr/bin/env (!env)" b -#!/usr/bin/env zsh - -endsnippet - -# vim:ft=snippets: diff --git a/vim/bundle/ultisnips/after/plugin/UltiSnips_after.vim b/vim/bundle/ultisnips/after/plugin/UltiSnips_after.vim index ca885a6..33ad9e0 100644 --- a/vim/bundle/ultisnips/after/plugin/UltiSnips_after.vim +++ b/vim/bundle/ultisnips/after/plugin/UltiSnips_after.vim @@ -1,13 +1,8 @@ -" File: UltiSnips_after.vim -" Author: Holger Rapp -" Description: Called after everything else to reclaim keys (Needed for -" Supertab) -" Last Modified: July 27, 2009 +" Called after everything else to reclaim keys (Needed for Supertab) -if exists('did_UltiSnips_after') || &cp || version < 700 - finish +if exists("b:did_after_plugin_ultisnips_after") || !exists("g:_uspy") + finish endif +let b:did_after_plugin_ultisnips_after = 1 call UltiSnips#map_keys#MapKeys() - -let did_UltiSnips_after=1 diff --git a/vim/bundle/ultisnips/autoload/UltiSnips.vim b/vim/bundle/ultisnips/autoload/UltiSnips.vim index c09d5c3..6000ff0 100644 --- a/vim/bundle/ultisnips/autoload/UltiSnips.vim +++ b/vim/bundle/ultisnips/autoload/UltiSnips.vim @@ -1,40 +1,19 @@ -" File: UltiSnips.vim -" Author: Holger Rapp -" Description: The Ultimate Snippets solution for Vim +if exists("b:did_autoload_ultisnips") || !exists("g:_uspy") + " Define no-op function, called via ftdetect/UltiSnips.vim. + " TODO(sirver): Add a test for that using a bad g:UltiSnipsPythonVersion + " setting. Without this fix moving the cursor will spam errors, with this + " it should not. + function! UltiSnips#FileTypeChanged() + endfunction -if exists('did_UltiSnips_autoload') || &cp || version < 700 finish endif +let b:did_autoload_ultisnips = 1 -" Define dummy version of function called by autocommand setup in -" ftdetect/UltiSnips.vim. If the function isn't defined (probably due to -" using a copy of vim without python support) it will cause an error anytime a -" new file is opened. -function! UltiSnips#FileTypeChanged() -endfunction - -if !exists("g:UltiSnipsUsePythonVersion") - let g:_uspy=":py3 " - if !has("python3") - if !has("python") - if !exists("g:UltiSnipsNoPythonWarning") - echo "UltiSnips requires py >= 2.6 or any py3" - endif - finish - endif - let g:_uspy=":py " - endif - let g:UltiSnipsUsePythonVersion = "" -else - if g:UltiSnipsUsePythonVersion == 2 - let g:_uspy=":py " - else - let g:_uspy=":py3 " - endif -endif - +" Also import vim as we expect it to be imported in many places. +exec g:_uspy "import vim" +exec g:_uspy "from UltiSnips import UltiSnips_Manager" -" FUNCTIONS {{{ function! s:compensate_for_pum() """ The CursorMovedI event is not triggered while the popup-menu is visible, """ and it's by this event that UltiSnips updates its vim-state. The fix is @@ -45,13 +24,17 @@ function! s:compensate_for_pum() endif endfunction -function! UltiSnips#Edit(...) +function! UltiSnips#Edit(bang, ...) if a:0 == 1 && a:1 != '' let type = a:1 else - exec g:_uspy "vim.command(\"let type = '%s'\" % UltiSnips_Manager._primary_filetype)" + let type = "" + endif + exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager._file_to_edit(vim.eval(\"type\"), vim.eval('a:bang')))" + + if !len(file) + return endif - exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager._file_to_edit(vim.eval(\"type\")))" let mode = 'e' if exists('g:UltiSnipsEditSplit') @@ -59,9 +42,14 @@ function! UltiSnips#Edit(...) let mode = 'vs' elseif g:UltiSnipsEditSplit == 'horizontal' let mode = 'sp' + elseif g:UltiSnipsEditSplit == 'context' + let mode = 'vs' + if winwidth(0) <= 2 * (&tw ? &tw : 80) + let mode = 'sp' + endif endif endif - exe ':'.mode.' '.file + exe ':'.mode.' '.escape(file, ' ') endfunction function! UltiSnips#AddFiletypes(filetypes) @@ -101,9 +89,13 @@ function! UltiSnips#ListSnippets() return "" endfunction -function! UltiSnips#SnippetsInCurrentScope() +function! UltiSnips#SnippetsInCurrentScope(...) let g:current_ulti_dict = {} - exec g:_uspy "UltiSnips_Manager.snippets_in_current_scope()" + let all = get(a:, 1, 0) + if all + let g:current_ulti_dict_info = {} + endif + exec g:_uspy "UltiSnips_Manager.snippets_in_current_scope(" . all . ")" return g:current_ulti_dict endfunction @@ -131,18 +123,6 @@ function! UltiSnips#FileTypeChanged() endfunction -function! UltiSnips#AddSnippet(trigger, value, description, options, ...) - " Takes the same arguments as SnippetManager.add_snippet. - echoerr "Deprecated UltiSnips#AddSnippet called. Please use UltiSnips#AddSnippetWithPriority." | sleep 1 - exec g:_uspy "args = vim.eval(\"a:000\")" - exec g:_uspy "trigger = vim.eval(\"a:trigger\")" - exec g:_uspy "value = vim.eval(\"a:value\")" - exec g:_uspy "description = vim.eval(\"a:description\")" - exec g:_uspy "options = vim.eval(\"a:options\")" - exec g:_uspy "UltiSnips_Manager.add_snippet(trigger, value, description, options, *args)" - return "" -endfunction - function! UltiSnips#AddSnippetWithPriority(trigger, value, description, options, filetype, priority) exec g:_uspy "trigger = vim.eval(\"a:trigger\")" exec g:_uspy "value = vim.eval(\"a:value\")" @@ -175,14 +155,8 @@ endf function! UltiSnips#LeavingInsertMode() exec g:_uspy "UltiSnips_Manager._leaving_insert_mode()" endfunction -" }}} -" Expand our path -exec g:_uspy "import vim, os, sys" -exec g:_uspy "new_path = os.path.abspath(os.path.join( - \ vim.eval('expand(\":h\")'), '..', 'pythonx'))" -exec g:_uspy "vim.command(\"let g:UltiSnipsPythonPath = '%s'\" % new_path)" -exec g:_uspy "if not hasattr(vim, 'VIM_SPECIAL_PATH'): sys.path.append(new_path)" -exec g:_uspy "from UltiSnips import UltiSnips_Manager" - -let did_UltiSnips_autoload=1 +function! UltiSnips#TrackChange() + exec g:_uspy "UltiSnips_Manager._track_change()" +endfunction +" }}} diff --git a/vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim b/vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim index aa0bce9..218b507 100644 --- a/vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim +++ b/vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim @@ -1,38 +1,72 @@ -call UltiSnips#variables#WasRun() +if exists("b:did_autoload_ultisnips_map_keys") || !exists("g:_uspy") + finish +endif +let b:did_autoload_ultisnips_map_keys = 1 + +" The trigger used to expand a snippet. +" NOTE: expansion and forward jumping can, but needn't be the same trigger +if !exists("g:UltiSnipsExpandTrigger") + let g:UltiSnipsExpandTrigger = "" +endif + +" The trigger used to display all triggers that could possible +" match in the current position. +if !exists("g:UltiSnipsListSnippets") + let g:UltiSnipsListSnippets = "" +endif + +" The trigger used to jump forward to the next placeholder. +" NOTE: expansion and forward jumping can be the same trigger. +if !exists("g:UltiSnipsJumpForwardTrigger") + let g:UltiSnipsJumpForwardTrigger = "" +endif + +" The trigger to jump backward inside a snippet +if !exists("g:UltiSnipsJumpBackwardTrigger") + let g:UltiSnipsJumpBackwardTrigger = "" +endif + +" Should UltiSnips unmap select mode mappings automagically? +if !exists("g:UltiSnipsRemoveSelectModeMappings") + let g:UltiSnipsRemoveSelectModeMappings = 1 +end + +" If UltiSnips should remove Mappings, which should be ignored +if !exists("g:UltiSnipsMappingsToIgnore") + let g:UltiSnipsMappingsToIgnore = [] +endif + +" UltiSnipsEdit will use this variable to decide if a new window +" is opened when editing. default is "normal", allowed are also +" "vertical", "horizontal", and "context". +if !exists("g:UltiSnipsEditSplit") + let g:UltiSnipsEditSplit = 'normal' +endif + +" A list of directory names that are searched for snippets. +if !exists("g:UltiSnipsSnippetDirectories") + let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ] +endif + +" Enable or Disable snipmate snippet expansion. +if !exists("g:UltiSnipsEnableSnipMate") + let g:UltiSnipsEnableSnipMate = 1 +endif function! UltiSnips#map_keys#MapKeys() - " Map the keys correctly if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger - exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippetOrJump()" exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippetOrJump()" else exec "inoremap " . g:UltiSnipsExpandTrigger . " =UltiSnips#ExpandSnippet()" exec "snoremap " . g:UltiSnipsExpandTrigger . " :call UltiSnips#ExpandSnippet()" endif - exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips#SaveLastVisualSelection()gvs' + exec "xnoremap " . g:UltiSnipsExpandTrigger. " :call UltiSnips#SaveLastVisualSelection()gvs" exec "inoremap " . g:UltiSnipsListSnippets . " =UltiSnips#ListSnippets()" exec "snoremap " . g:UltiSnipsListSnippets . " :call UltiSnips#ListSnippets()" snoremap c snoremap c snoremap c -endf - -function! UltiSnips#map_keys#MapInnerKeys() - if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger - exec "inoremap " . g:UltiSnipsJumpForwardTrigger . " =UltiSnips#JumpForwards()" - exec "snoremap " . g:UltiSnipsJumpForwardTrigger . " :call UltiSnips#JumpForwards()" - endif - exec "inoremap " . g:UltiSnipsJumpBackwardTrigger . " =UltiSnips#JumpBackwards()" - exec "snoremap " . g:UltiSnipsJumpBackwardTrigger . " :call UltiSnips#JumpBackwards()" -endf - -function! UltiSnips#map_keys#RestoreInnerKeys() - if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger - exec "iunmap " . g:UltiSnipsJumpForwardTrigger - exec "sunmap " . g:UltiSnipsJumpForwardTrigger - endif - exec "iunmap " . g:UltiSnipsJumpBackwardTrigger - exec "sunmap " . g:UltiSnipsJumpBackwardTrigger + snoremap "_c endf diff --git a/vim/bundle/ultisnips/autoload/UltiSnips/variables.vim b/vim/bundle/ultisnips/autoload/UltiSnips/variables.vim deleted file mode 100644 index d5555c9..0000000 --- a/vim/bundle/ultisnips/autoload/UltiSnips/variables.vim +++ /dev/null @@ -1,48 +0,0 @@ -" Kludge to make sure that this file is really run. -function! UltiSnips#variables#WasRun() -endfunction - -" The trigger used to expand a snippet. -" NOTE: expansion and forward jumping can, but needn't be the same trigger -if !exists("g:UltiSnipsExpandTrigger") - let g:UltiSnipsExpandTrigger = "" -endif - -" The trigger used to display all triggers that could possible -" match in the current position. -if !exists("g:UltiSnipsListSnippets") - let g:UltiSnipsListSnippets = "" -endif - -" The trigger used to jump forward to the next placeholder. -" NOTE: expansion and forward jumping can, but needn't be the same trigger -if !exists("g:UltiSnipsJumpForwardTrigger") - let g:UltiSnipsJumpForwardTrigger = "" -endif - -" The trigger to jump backward inside a snippet -if !exists("g:UltiSnipsJumpBackwardTrigger") - let g:UltiSnipsJumpBackwardTrigger = "" -endif - -" Should UltiSnips unmap select mode mappings automagically? -if !exists("g:UltiSnipsRemoveSelectModeMappings") - let g:UltiSnipsRemoveSelectModeMappings = 1 -end - -" If UltiSnips should remove Mappings, which should be ignored -if !exists("g:UltiSnipsMappingsToIgnore") - let g:UltiSnipsMappingsToIgnore = [] -endif - -" UltiSnipsEdit will use this variable to decide if a new window -" is opened when editing. default is "normal", allowed are also -" "vertical", "horizontal" -if !exists("g:UltiSnipsEditSplit") - let g:UltiSnipsEditSplit = 'normal' -endif - -" A list of directory names that are searched for snippets. -if !exists("g:UltiSnipsSnippetDirectories") - let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ] -endif diff --git a/vim/bundle/ultisnips/autoload/neocomplete/sources/ultisnips.vim b/vim/bundle/ultisnips/autoload/neocomplete/sources/ultisnips.vim new file mode 100644 index 0000000..5f45e5e --- /dev/null +++ b/vim/bundle/ultisnips/autoload/neocomplete/sources/ultisnips.vim @@ -0,0 +1,32 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:source = { + \ 'name' : 'ultisnips', + \ 'kind' : 'keyword', + \ 'mark' : '[US]', + \ 'rank' : 8, + \ 'matchers' : + \ (g:neocomplete#enable_fuzzy_completion ? + \ ['matcher_fuzzy'] : ['matcher_head']), + \ } + +function! s:source.gather_candidates(context) + let suggestions = [] + let snippets = UltiSnips#SnippetsInCurrentScope() + for trigger in keys(snippets) + let description = get(snippets, trigger) + call add(suggestions, { + \ 'word' : trigger, + \ 'menu' : self.mark . ' '. description + \ }) + endfor + return suggestions +endfunction + +function! neocomplete#sources#ultisnips#define() + return s:source +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/vim/bundle/ultisnips/autoload/unite/sources/ultisnips.vim b/vim/bundle/ultisnips/autoload/unite/sources/ultisnips.vim new file mode 100644 index 0000000..1ded37f --- /dev/null +++ b/vim/bundle/ultisnips/autoload/unite/sources/ultisnips.vim @@ -0,0 +1,82 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:unite_source = { + \ 'name': 'ultisnips', + \ 'hooks': {}, + \ 'action_table': {}, + \ 'syntax' : 'uniteSource__Ultisnips', + \ 'default_action': 'expand', + \ } + +let s:unite_source.action_table.preview = { + \ 'description' : 'ultisnips snippets', + \ 'is_quit' : 0, + \ } + +function! s:unite_source.hooks.on_syntax(args, context) abort + syntax case ignore + syntax match uniteSource__UltisnipsHeader /^.*$/ + \ containedin=uniteSource__Ultisnips + syntax match uniteSource__UltisnipsTrigger /\v^\s.{-}\ze\s/ contained + \ containedin=uniteSource__UltisnipsHeader + \ nextgroup=uniteSource__UltisnipsDescription + syntax match uniteSource__UltisnipsDescription /\v.{3}\s\zs\w.*$/ contained + \ containedin=uniteSource__UltisnipsHeader + + highlight default link uniteSource__UltisnipsTrigger Identifier + highlight default link uniteSource__UltisnipsDescription Statement +endfunction + +function! s:unite_source.action_table.preview.func(candidate) + " no nice preview at this point, cannot get snippet text + let snippet_preview = a:candidate['word'] + echo snippet_preview +endfunction + +let s:unite_source.action_table.expand = { + \ 'description': 'expand the current snippet', + \ 'is_quit': 1 + \} + +function! s:unite_source.action_table.expand.func(candidate) + let delCurrWord = (getline(".")[col(".")-1] == " ") ? "" : "diw" + exe "normal " . delCurrWord . "a" . a:candidate['trigger'] . " " + call UltiSnips#ExpandSnippet() + return '' +endfunction + +function! s:unite_source.get_longest_snippet_len(snippet_list) + let longest = 0 + for snip in items(a:snippet_list) + if strlen(snip['word']) > longest + let longest = strlen(snip['word']) + endif + endfor + return longest +endfunction + +function! s:unite_source.gather_candidates(args, context) + let default_val = {'word': '', 'unite__abbr': '', 'is_dummy': 0, 'source': + \ 'ultisnips', 'unite__is_marked': 0, 'kind': 'command', 'is_matched': 1, + \ 'is_multiline': 0} + let snippet_list = UltiSnips#SnippetsInCurrentScope() + let max_len = s:unite_source.get_longest_snippet_len(snippet_list) + let canditates = [] + for snip in items(snippet_list) + let curr_val = copy(default_val) + let curr_val['word'] = printf('%-*s', max_len, snip[0]) . " " . snip[1] + let curr_val['trigger'] = snip[0] + call add(canditates, curr_val) + endfor + return canditates +endfunction + +function! unite#sources#ultisnips#define() + return s:unite_source +endfunction + +"unlet s:unite_source + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/vim/bundle/ultisnips/ctags/UltiSnips.cnf b/vim/bundle/ultisnips/ctags/UltiSnips.cnf new file mode 100644 index 0000000..c30aa8b --- /dev/null +++ b/vim/bundle/ultisnips/ctags/UltiSnips.cnf @@ -0,0 +1,3 @@ +--langdef=UltiSnips +--langmap=UltiSnips:.snippets +--regex-UltiSnips=/^snippet (.*)/\1/s,snippet/ diff --git a/vim/bundle/ultisnips/doc/UltiSnips.txt b/vim/bundle/ultisnips/doc/UltiSnips.txt index b29d79c..45c1fd5 100644 --- a/vim/bundle/ultisnips/doc/UltiSnips.txt +++ b/vim/bundle/ultisnips/doc/UltiSnips.txt @@ -12,7 +12,8 @@ UltiSnips *snippet* *snippets* *UltiSnips* 3.1 Commands |UltiSnips-commands| 3.2 Triggers |UltiSnips-triggers| 3.2.1 Using your own trigger functions |UltiSnips-trigger-functions| - 3.2.2 Path to Python Module |UltiSnips-python-module-path| + 3.2.2 Custom autocommands |UltiSnips-custom-autocommands| + 3.2.3 Path to Python Module |UltiSnips-python-module-path| 3.3 Snippet Search Path |UltiSnips-snippet-search-path| 3.4 Warning About Select Mode Mappings |UltiSnips-warning-smappings| 3.5 Functions |UltiSnips-functions| @@ -36,12 +37,17 @@ UltiSnips *snippet* *snippets* *UltiSnips* 4.7.1 Replacement String |UltiSnips-replacement-string| 4.7.2 Demos |UltiSnips-demos| 4.8 Clearing snippets |UltiSnips-clearing-snippets| -5. Support for other plugins |UltiSnips-other-plugins| + 4.9 Context snippets |UltiSnips-context-snippets| + 4.10 Snippet actions |UltiSnips-snippet-actions| + 4.10.1 Pre-expand actions |UltiSnips-pre-expand-actions| + 4.10.2 Post-expand actions |UltiSnips-post-expand-actions| + 4.10.3 Post-jump actions |UltiSnips-post-jump-actions| + 4.11 Autotrigger |UltiSnips-autotrigger| +5. UltiSnips and Other Plugins |UltiSnips-other-plugins| + 5.1 Existing Integrations |UltiSnips-integrations| + 5.2 Extending UltiSnips |UltiSnips-extending| 6. Helping Out |UltiSnips-helping| -7. Contact |UltiSnips-contact| -8. Contributors |UltiSnips-contributors| - 8.1 Patches & Coding |UltiSnips-contricoding| - 8.2 Snippets |UltiSnips-contrisnippets| +7. Contributors |UltiSnips-contributors| This plugin only works if 'compatible' is not set. {Vi does not have any of these features} @@ -58,28 +64,29 @@ Snippets are common in structured text like source code but can also be used for general editing like, for example, inserting a signature in an email or inserting the current date in a text file. -UltiSnips was developed using the TDD (Test-driven development) philosophy. -This ensures that features do not disappear and bugs do not reappear after -they have been fixed. - -On my blog, http://www.sirver.net, I posted several short screencasts, which -make a great introduction to UltiSnips, illustrating its features and usage. +@SirVer posted several short screencasts which make a great introduction to +UltiSnips, illustrating its features and usage. http://www.sirver.net/blog/2011/12/30/first-episode-of-ultisnips-screencast/ http://www.sirver.net/blog/2012/01/08/second-episode-of-ultisnips-screencast/ http://www.sirver.net/blog/2012/02/05/third-episode-of-ultisnips-screencast/ http://www.sirver.net/blog/2012/03/31/fourth-episode-of-ultisnips-screencast/ +Also the excellent [Vimcasts](http://vimcasts.org) dedicated three episodes to +UltiSnips: + +http://vimcasts.org/episodes/meet-ultisnips/ +http://vimcasts.org/episodes/ultisnips-python-interpolation/ +http://vimcasts.org/episodes/ultisnips-visual-placeholder/ 1.1 Requirements *UltiSnips-requirements* ---------------- -This plugin works with Vim version 7.0 or later. It only works if the +This plugin works with Vim version 7.4 or later. It only works if the 'compatible' setting is not set. -This plugin requires python >= 2.6. It has been specifically tested using -python 2.7 and python 3.2 but should theoretically work on all versions of -python >= 2.6. +This plugin is tested against Python 2.7, 3.3 or 3.4. All other versions are +unsupported, but might work. The Python 2.x or Python 3.x interface must be available. In other words, Vim must be compiled with either the |+python| feature or the |+python3| feature. @@ -124,7 +131,7 @@ permission to use his snippets. ============================================================================= 2. Installation and Updating *UltiSnips-installnupdate* -The recommended way of getting ultisnips is to track SirVer/ultisnips on +The recommended way of getting UltiSnips is to track SirVer/ultisnips on github. The master branch is always stable. Using Pathogen: *UltiSnips-using-pathogen* @@ -132,8 +139,11 @@ Using Pathogen: *UltiSnips-using-pathogen* If you are a pathogen user, you can track the official mirror of UltiSnips on github: > - $ cd ~/.vim/ - $ git submodule add git://github.com/SirVer/ultisnips.git bundle/ultisnips + $ cd ~/.vim/bundle && git clone git://github.com/SirVer/ultisnips.git + +If you also want the default snippets, also track > + + $ cd ~/.vim/bundle && git clone git://github.com/honza/vim-snippets.git See the pathogen documentation for more details on how to update a bundle. @@ -154,16 +164,19 @@ Restart Vim and UltiSnips should work. To access the help, use > :helptags ~/.vim/ultisnips_rep/doc :help UltiSnips +UltiSnips comes without snippets. The default snippets can be found here: +https://github.com/honza/vim-snippets + ============================================================================= 3. Settings & Commands *UltiSnips-settings* 3.1 Commands *UltiSnips-commands* ------------ *:UltiSnipsEdit* -The UltiSnipsEdit command opens the private snippet definition file for the -current filetype for editing. If a definition file does not exist, a new file -is opened with the appropriate name. Snippet definition files are standard -text files and can be edited directly. UltiSnipsEdit makes it easier. +The UltiSnipsEdit command opens a private snippet definition file for the +current filetype. If no snippet file exists, a new file is created. If used as +UltiSnipsEdit! all public snippet files are taken into account too. If +multiple files match the search, the user gets to choose the file. There are several variables associated with the UltiSnipsEdit command. @@ -173,6 +186,8 @@ g:UltiSnipsEditSplit Defines how the edit window is opened. Possible |normal| Default. Opens in the current window. |horizontal| Splits the window horizontally. |vertical| Splits the window vertically. + |context| Splits the window vertically or + horizontally depending on context. *g:UltiSnipsSnippetsDir* g:UltiSnipsSnippetsDir @@ -180,7 +195,25 @@ g:UltiSnipsSnippetsDir files are stored in. For example, if the variable is set to "~/.vim/mydir/UltiSnips" and the current 'filetype' is "cpp", then :UltiSnipsEdit will open - "~/.vim/mydir/UltiSnips/cpp.snippets". + "~/.vim/mydir/UltiSnips/cpp.snippets". Note that + directories named "snippets" are reserved for + snipMate snippets and cannot be used. + + *g:UltiSnipsSnippetDirectories* +g:UltiSnipsSnippetDirectories + Defines the directories for looking for snippets. + Do not mix up this variable with previous one. + More information about that variable can + be found at section |UltiSnips-snippet-search-path|. + + *g:UltiSnipsEnableSnipMate* +g:UltiSnipsEnableSnipMate + Enable looking for SnipMate snippets in + &runtimepath. UltiSnips will search only for + directories named 'snippets' while looking for + SnipMate snippets. Defaults to "1", so UltiSnips + will look for SnipMate snippets. + *:UltiSnipsAddFiletypes* The UltiSnipsAddFiletypes command allows for explicit merging of other snippet @@ -209,24 +242,20 @@ The priority will then be rails -> ruby -> programming -> all. 3.2 Triggers *UltiSnips-triggers* ------------ + *g:UltiSnipsExpandTrigger* *g:UltiSnipsListSnippets* + *g:UltiSnipsJumpForwardTrigger* *g:UltiSnipsJumpBackwardTrigger* You can define the keys used to trigger UltiSnips actions by setting global variables. Variables define the keys used to expand a snippet, jump forward and jump backwards within a snippet, and list all available snippets in the -current expand context. The variables with their default values are: > +current expand context. Be advised, that some terminal emulators don't send + to the running program. The variables with their default values are: > g:UltiSnipsExpandTrigger g:UltiSnipsListSnippets g:UltiSnipsJumpForwardTrigger g:UltiSnipsJumpBackwardTrigger -The g:UltiSnipsExpandTrigger and g:UltiSnipsJumpForwardTrigger can be set to -the same value. To simulate TextMate behavior, add the following lines to your -vimrc file. > - let g:UltiSnipsExpandTrigger="" - let g:UltiSnipsJumpForwardTrigger="" - let g:UltiSnipsJumpBackwardTrigger="" - UltiSnips will only map the jump triggers while a snippet is active to -interfer as little as possible with other mappings. +interfere as little as possible with other mappings. The default value for g:UltiSnipsJumpBackwardTrigger interferes with the built-in complete function: |i_CTRL-X_CTRL-K|. A workaround is to add the @@ -248,9 +277,9 @@ to the same value then the function you are actually going to use is UltiSnips#ExpandSnippetOrJump. Each time any of the functions UltiSnips#ExpandSnippet, -UltiSnips#ExpandSnippet, UltiSnips#JumpBackwards or UltiSnips#JumpBackwards is -called a global variable is set that contains the return value of the -corresponding function. +UltiSnips#ExpandSnippetOrJump, UltiSnips#JumpForwards or +UltiSnips#JumpBackwards is called a global variable is set that contains the +return value of the corresponding function. The corresponding variables and functions are: UltiSnips#ExpandSnippet --> g:ulti_expand_res (0: fail, 1: success) @@ -279,7 +308,39 @@ then you define your mapping as > and if the you can't expand or jump from the current location then the alternative function IMAP_Jumpfunc('', 0) is called. -3.2.2 Path to Python module *UltiSnips-python-module-path* +3.2.2 Custom autocommands *UltiSnips-custom-autocommands* +------------------------- + +Note Autocommands must *not* change the buffer in any way. If lines are added, +deleted, or modified it will confuse UltiSnips which might scramble your +snippets contents. + + *UltiSnipsEnterFirstSnippet* *UltiSnipsExitLastSnippet* +For maximum compatibility with other plug-ins, UltiSnips sets up some special +state, include mappings and autocommands, when a snippet starts being +expanded, and tears them down once the last snippet has been exited. In order +to make it possible to override these "inner" settings, it fires the following +"User" autocommands: + +UltiSnipsEnterFirstSnippet +UltiSnipsExitLastSnippet + +For example, to call a pair of custom functions in response to these events, +you might do: > + + autocmd! User UltiSnipsEnterFirstSnippet + autocmd User UltiSnipsEnterFirstSnippet call CustomInnerKeyMapper() + autocmd! User UltiSnipsExitLastSnippet + autocmd User UltiSnipsExitLastSnippet call CustomInnerKeyUnmapper() + +Note that snippet expansion may be nested, in which case +|UltiSnipsEnterFirstSnippet| will fire only as the first (outermost) snippet +is entered, and |UltiSnipsExitLastSnippet| will only fire once the last +(outermost) snippet have been exited. + + + +3.2.3 Path to Python module *UltiSnips-python-module-path* --------------------------- For even more advanced usage, you can directly write python functions using @@ -306,9 +367,10 @@ how UltiSnips loads snippets. Snippet definition files are stored in snippet directories. A snippet directory must be a subdirectory of a directory defined in the 'runtimepath' option. The variable g:UltiSnipsSnippetDirectories defines a list of names -used for snippet directories. The default is shown below. > +used for snippet directories. Note that "snippets" is reserved for snipMate +snippets and cannot be used. The default is shown below. > - g:UltiSnipsSnippetDirectories ["UltiSnips"] + let g:UltiSnipsSnippetDirectories=["UltiSnips"] UltiSnips will search each 'runtimepath' directory for the subdirectory names defined in g:UltiSnipsSnippetDirectories in the order they are defined. For @@ -316,8 +378,8 @@ example, if you keep your snippets in a .vim subdirectory called "mycoolsnippets" and you want to make use of the default snippets that come with UltiSnips, add the following to your vimrc file. > let g:UltiSnipsSnippetDirectories=["UltiSnips", "mycoolsnippets"] -If you do not want to use the snippets that come with UltiSnips, define the -variable accordingly. > +If you do not want to use the third party snippets that come with plugins, +define the variable accordingly: > let g:UltiSnipsSnippetDirectories=["mycoolsnippets"] You can also redefine the search path on a buffer by buffer basis by setting @@ -326,6 +388,15 @@ over the global variable. |UltiSnips-adding-snippets| explains which files are parsed for a given filetype. +If only one directory is specified in this variable and this directory is +specified by absolute path, UltiSnips will not look for snippets in +&runtimepath, which can lead to significant speedup. So, the common case is: + + let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/UltiSnips'] + +However, you will not able to use snippets that are shipped with third party +plugins out of the box. You'll need to copy them into your chosen directory. + 3.4 Warning About Select Mode Mappings *UltiSnips-warning-smappings* -------------------------------------- @@ -381,8 +452,9 @@ snippets, so they cannot be expanded a second time unless the function is called again. The function takes three optional arguments, in order: trigger, description, options. Arguments coincide with the arguments of the |UltiSnips#AddSnippetWithPriority| function of the same name. The trigger and -options arguments can change the way the snippet expands. The description is -unused at this point. +options arguments can change the way the snippet expands. Same options +can be specified as in the snippet definition. See full list of options at +|UltiSnips-snippet-options|. The description is unused at this point. An example use case might be this line from a reStructuredText plugin file: @@ -398,8 +470,13 @@ typed so it can determine if the trigger matches or not. A third function is UltiSnips#SnippetsInCurrentScope which is the equivalent of snipmate GetSnipsInCurrentScope function. + This function simply returns a vim dictionary with the snippets whose trigger -matches the current word. +matches the current word. If you need all snippets information of current +buffer, you can simply pass 1 (which means all) as first argument of this +function, and use a global variable g:current_ulti_dict_info to get the +result (see example below). + This function does not add any new functionality to ultisnips directly but allows to use third party plugins to integrate the current available snippets. @@ -439,6 +516,27 @@ If the trigger for your snippet is lorem, you type lor, and you have no other snippets whose trigger matches lor then hitting will expand to whatever lorem expands to. +A third example on how to use this function to extract all snippets of +current buffer: > + +function! GetAllSnippets() + call UltiSnips#SnippetsInCurrentScope(1) + let list = [] + for [key, info] in items(g:current_ulti_dict_info) + let parts = split(info.location, ':') + call add(list, { + \"key": key, + \"path": parts[0], + \"linenr": parts[1], + \"description": info.description, + \}) + endfor + return list +endfunction + +The new variable g:current_ulti_dict_info is made to avoid confilct with +exists third party plugins. The definition location contains file path and +line number is also included in this variable. 3.6 Warning about missing python support *UltiSnips-python-warning* ---------------------------------------- @@ -516,7 +614,7 @@ permitted in a snippet file, and they can be included anywhere in the file. A line beginning with the keyword 'priority' sets the priority for all snippets defined in the current file after this line. The default priority for a file is always 0. When a snippet should be expanded, UltiSnips will collect -all snippet definitons from all sources that match the trigger and keep only +all snippet definitions from all sources that match the trigger and keep only the ones with the highest priority. For example, all shipped snippets have a priority < 0, so that user defined snippets always overwrite shipped snippets. @@ -564,6 +662,8 @@ same tab trigger. When a snippet is activated and more than one tab trigger match, UltiSnips displays a list of the matching snippets with their descriptions. The user then selects the snippet they want. + *UltiSnips-snippet-options* + The 'options' control the behavior of the snippet. Options are indicated by single characters. The 'options' characters for a snippet are combined into a word without spaces. @@ -609,6 +709,19 @@ The options currently supported are: > before jumping to the next tabstop. This is useful if there is a tabstop with optional text at the end of a line. + m Trim all whitespaces from right side of snippet lines. Useful when + snippet contains empty lines which should remain empty after expanding. + Without this option empty lines in snippets definition will have + indentation too. + + e Context snippets - With this option expansion of snippet can be + controlled not only by previous characters in line, but by any given + python expression. This option can be specified along with other + options, like 'b'. See |UltiSnips-context-snippets| for more info. + + A Snippet will be triggered automatically, when condition matches. + See |UltiSnips-autotrigger| for more info. + The end line is the 'endsnippet' keyword on a line by itself. > endsnippet @@ -619,9 +732,9 @@ from the 'endsnippet' end line. 4.1.1 Character Escaping: *UltiSnips-character-escaping* -In snippet definitions, the characters '`', '{', '$', '\' and "'" (single -quote) have special meaning. If you want to insert one of these characters -literally, escape them with a backslash, '\'. +In snippet definitions, the characters '`', '{', '$' and '\' have special +meaning. If you want to insert one of these characters literally, escape them +with a backslash, '\'. 4.2 Plaintext Snippets *UltiSnips-plaintext-snippets* @@ -769,11 +882,12 @@ output is ignored. The variables automatically defined in python code are: > - fn - The current filename - path - The complete path to the current file - t - The values of the placeholders, t[1] is the text of ${1}, and so on - snip - UltiSnips.TextObjects.SnippetUtil object instance. Has methods that - simplify indentation handling. + fn - The current filename + path - The complete path to the current file + t - The values of the placeholders, t[1] is the text of ${1}, etc. + snip - UltiSnips.TextObjects.SnippetUtil object instance. Has methods + that simplify indentation handling. + context - Result of context condition. See |UltiSnips-context-snippets|. The 'snip' object provides the following methods: > @@ -825,6 +939,14 @@ The 'snip' object provides some properties as well: > snip.ft: The current filetype. + snip.p: + Last selected placeholder. Will contain placeholder object with + following properties: + + 'current_text' - text in the placeholder on the moment of selection; + 'start' - placeholder start on the moment of selection; + 'end' - placeholder end on the moment of selection; + For your convenience, the 'snip' object also provides the following operators: > @@ -915,10 +1037,10 @@ directly inside your snippets. For example to use global !p from my_snippet_helpers import * - endglobals + endglobal -4.4 Tabstops and Placeholders *UltiSnips-tabstops* *UltiSnips-placeholders* +4.5 Tabstops and Placeholders *UltiSnips-tabstops* *UltiSnips-placeholders* ----------------------------- Snippets are used to quickly insert reused text into a document. Often the @@ -931,7 +1053,8 @@ until all the variable components are complete. The syntax for a tabstop is the dollar sign followed by a number, for example, '$1'. Tabstops start at number 1 and are followed in sequential order. The '$0' tabstop is a special tabstop. It is always the last tabstop in the -snippet no matter how many tabstops are defined. +snippet no matter how many tabstops are defined. If there is no '$0' defined, +'$0' tabstop will be defined at the end of snippet. Here is a simple example. @@ -1120,6 +1243,13 @@ The options can be any combination of > i - case insensitive By default, regular expression matching is case sensitive. With this option, matching is done without regard to case. + m - multiline + By default, the '^' and '$' special characters only apply to the + start and end of the entire string; so if you select multiple lines, + transformations are made on them entirely as a whole single line + string. With this option, '^' and '$' special characters match the + start or end of any line within a string ( separated by newline + character - '\n' ). a - ascii conversion By default, transformation are made on the raw utf-8 string. With this option, matching is done on the corresponding ASCII string @@ -1226,94 +1356,432 @@ directive. clearsnippets ------------------- SNAP ------------------- -Without arguments, 'clearsnippets' removes all snippets defined up to that -point far for the current file type. Just a reminder, by default UltiSnips -traverses 'runtimepath' in reverse order, so 'clearsnippets' removes snippet -definitions appearing in files in 'runtimepath' after the '.snippets' file in -which it is encountered. +'clearsnippets' removes all snippets with a priority lower than the current +one. For example, the following cleares all snippets that have priority <= 1, +even though the example snippet is defined after the 'clearsnippets'. -To clear one or more specific snippet, provide the names of the snippets as -arguments to the 'clearsnippets' command. The following example will clear -the snippets 'trigger1' and 'trigger2'. +------------------- SNIP ------------------- +priority 1 +clearsnippets + +priority -1 +snippet example "Cleared example" + This will never be expanded. +endsnippet +------------------- SNAP ------------------- +To clear one or more specific snippet, provide the triggers of the snippets as +arguments to the 'clearsnippets' command. The following example will clear the +snippets 'trigger1' and 'trigger2'. ------------------- SNIP ------------------- clearsnippets trigger1 trigger2 ------------------- SNAP ------------------- -UltiSnips comes with a set of default snippets for many file types. If you -would rather not have some of them defined, you can use 'clearsnippets' in -your personal snippets files to remove them. Note: you do not need to remove -snippets if you wish to replace them. Simply use the '!' option. (See -|UltiSnips-adding-snippets| for the options). +4.9 Context snippets *UltiSnips-context-snippets* + +Context snippets can be enabled by using 'e' option in snippet definition. + +In that case snippet should be defined using this syntax: > + + snippet tab_trigger "description" "expression" options + +The 'expression' can be any python expression. If 'expression' evaluates to +'True', then this snippet will be chosen for expansion. The 'expression' must +be wrapped with double-quotes. + +The following python modules are automatically imported into the scope before +'expression' is evaluated: 're', 'os', 'vim', 'string', 'random'. + +Global variable `snip` will be available with following properties: + 'snip.window' - alias for 'vim.current.window' + 'snip.buffer' - alias for 'vim.current.window.buffer' + 'snip.cursor' - cursor object, which behaves like + 'vim.current.window.cursor', but zero-indexed and with following + additional methods: + - 'preserve()' - special method for executing pre/post/jump actions; + - 'set(line, column)' - sets cursor to specified line and column; + - 'to_vim_cursor()' - returns 1-indexed cursor, suitable for assigning + to 'vim.current.window.cursor'; + 'snip.line' and 'snip.column' - aliases for cursor position (zero-indexed); + 'snip.visual_mode' - ('v', 'V', '^V', see |visual-mode|); + 'snip.visual_text' - last visually-selected text; + 'snip.last_placeholder' - last active placeholder from previous snippet + with following properties: + + - 'current_text' - text in the placeholder on the moment of selection; + - 'start' - placeholder start on the moment of selection; + - 'end' - placeholder end on the moment of selection; + + + +------------------- SNIP ------------------- +snippet r "return" "re.match('^\s+if err ', snip.buffer[snip.line-1])" be +return err +endsnippet +------------------- SNAP ------------------- + +That snippet will expand to 'return err' only if the previous line is starting +from 'if err' prefix. + +Note: context snippets prioritized over non-context ones. It makes possible to +use non-context snippets as fallback, if no context matched: + +------------------- SNIP ------------------- +snippet i "if ..." b +if $1 { + $2 +} +endsnippet + +snippet i "if err != nil" "re.match('^\s+[^=]*err\s*:?=', snip.buffer[snip.line-1])" be +if err != nil { + $1 +} +endsnippet +------------------- SNAP ------------------- + +That snippet will expand into 'if err != nil' if previous line will +match 'err :=' prefix, otherwise the default 'if' snippet will be expanded. + +It's a good idea to move context conditions to a separate module, so it can be +used by other UltiSnips users. In that case, module should be imported +using 'global' keyword, like this: + +------------------- SNIP ------------------- +global !p +import my_utils +endglobal + +snippet , "return ..., nil/err" "my_utils.is_return_argument(snip)" ie +, `!p if my_utils.is_in_err_condition(): + snip.rv = "err" +else: + snip.rv = "nil"` +endsnippet +------------------- SNAP ------------------- + +That snippet will expand only if the cursor is located in the return statement, +and then it will expand either to 'err' or to 'nil' depending on which 'if' +statement it's located. 'is_return_argument' and 'is_in_err_condition' are +part of custom python module which is called 'my_utils' in this example. + +Context condition can return any value which python can use as condition in +it's 'if' statement, and if it's considered 'True', then snippet will be +expanded. The evaluated value of 'condition' is available in the 'snip.context' +variable inside the snippet: + +------------------- SNIP ------------------- +snippet + "var +=" "re.match('\s*(.*?)\s*:?=', snip.buffer[snip.line-1])" ie +`!p snip.rv = snip.context.group(1)` += $1 +endsnippet +------------------- SNAP ------------------- + +That snippet will expand to 'var1 +=' after line, which begins from 'var1 :='. + + *UltiSnips-capture-placeholder* + +You can capture placeholder text from previous snippet by using following +trick: +------------------- SNIP ------------------- +snippet = "desc" "snip.last_placeholder" Ae +`!p snip.rv = snip.context.current_text` == nil +endsnippet +------------------- SNAP ------------------- + +That snippet will be expanded only if you will replace selected tabstop in +other snippet (like, as in 'if ${1:var}') and will replace that tabstop by +tabstop value following by ' == nil'. + + +4.10 Snippets actions *UltiSnips-snippet-actions* +--------------------- + +Snippet actions is an arbitrary python code which can be executed at specific +points in lifetime of the snippet. + +There are three types of actions: + +* Pre-expand - invoked just after trigger condition was matched, but before + snippet actually expanded; +* Post-expand - invoked after snippet was expanded and interpolations + was applied for the first time, but before jump on the first placeholder. +* Jump - invoked just after jump to the next/prev placeholder. + +Specified code will be evaluated at stages defined above and same global +variables and modules will be available that are stated in +the |UltiSnips-context-snippets| section. + + *UltiSnips-buffer-proxy* + +Note: special variable called 'snip.buffer' should be used for all buffer +modifications. Not 'vim.current.buffer' and not 'vim.command("...")', because +of in that case UltiSnips will not be able to track changes in buffer from +actions. + +'snip.buffer' has the same interface as 'vim.current.window.buffer'. + +4.10.1 Pre-expand actions *UltiSnips-pre-expand-actions* + +Pre-expand actions can be used to match snippet in one location and then +expand it in the different location. Some useful cases are: correcting +indentation for snippet; expanding snippet for function declaration in another +function body with moving expansion point beyond initial function; performing +extract method refactoring via expanding snippet in different place. + +Pre-expand action declared as follows: > + pre_expand "python code here" + snippet ... + endsnippet + +Buffer can be modified in pre-expand action code through variable called +'snip.buffer', snippet expansion position will be automatically adjusted. + +If cursor line (where trigger was matched) need to be modified, then special +variable method 'snip.cursor.set(line, column)' must be called with the +desired cursor position. In that case UltiSnips will not remove any matched +trigger text and it should be done manually in action code. + +To addition to the scope variables defined above 'snip.visual_content' will be +also declared and will contain text that was selected before snippet expansion +(similar to $VISUAL placeholder). + +Following snippet will be expanded at 4 spaces indentation level no matter +where it was triggered. + +------------------- SNIP ------------------- +pre_expand "snip.buffer[snip.line] = ' '*4; snip.cursor.set(line, 4)" +snippet d +def $1(): + $0 +endsnippet +------------------- SNAP ------------------- + +Following snippet will move the selected code to the end of file and create +new method definition for it: + +------------------- SNIP ------------------- +pre_expand "del snip.buffer[snip.line]; snip.buffer.append(''); snip.cursor.set(len(snip.buffer)-1, 0)" +snippet x +def $1(): + ${2:${VISUAL}} +endsnippet +------------------- SNAP ------------------- + +4.10.2 Post-expand actions *UltiSnips-post-expand-actions* + +Post-expand actions can be used to perform some actions based on the expanded +snippet text. Some cases are: code style formatting (e.g. inserting newlines +before and after method declaration), apply actions depending on python +interpolation result. + +Post-expand action declared as follows: > + post_expand "python code here" + snippet ... + endsnippet + +Buffer can be modified in post-expand action code through variable called +'snip.buffer', snippet expansion position will be automatically adjusted. + +Variables 'snip.snippet_start' and 'snip.snippet_end' will be defined at the +action code scope and will point to positions of the start and end of expanded +snippet accordingly in the form '(line, column)'. + +Note: 'snip.snippet_start' and 'snip.snippet_end' will automatically adjust to +the correct positions if post-action will insert or delete lines before +expansion. + +Following snippet will expand to method definition and automatically insert +additional newline after end of the snippet. It's very useful to create a +function that will insert as many newlines as required in specific context. + +------------------- SNIP ------------------- +post_expand "snip.buffer[snip.snippet_end[0]+1:snip.snippet_end[0]+1] = ['']" +snippet d "Description" b +def $1(): + $2 +endsnippet +------------------- SNAP ------------------- + +4.10.3 Post-jump actions *UltiSnips-post-jump-actions* + +Post-jump actions can be used to trigger some code based on user input into +the placeholders. Notable use cases: expand another snippet after jump or +anonymous snippet after last jump (e.g. perform move method refactoring and +then insert new method invokation); insert heading into TOC after last jump. + +Jump-expand action declared as follows: > + post_jump "python code here" + snippet ... + endsnippet + +Buffer can be modified in post-jump action code through variable called +'snip.buffer', snippet expansion position will be automatically adjusted. + +Next variables and methods will be also defined in the action code scope: +* 'snip.tabstop' - number of tabstop jumped onto; +* 'snip.jump_direction' - '1' if jumped forward and '-1' otherwise; +* 'snip.tabstops' - list with tabstop objects, see above; +* 'snip.snippet_start' - (line, column) of start of the expanded snippet; +* 'snip.snippet_end' - (line, column) of end of the expanded snippet; +* 'snip.expand_anon()' - alias for 'UltiSnips_Manager.expand_anon()'; + +Tabstop object has several useful properties: +* 'start' - (line, column) of the starting position of the tabstop (also + accessible as 'tabstop.line' and 'tabstop.col'). +* 'end' - (line, column) of the ending position; +* 'current_text' - text inside the tabstop. + +Following snippet will insert section in the Table of Contents in the vim-help +file: + +------------------- SNIP ------------------- +post_jump "if snip.tabstop == 0: insert_toc_item(snip.tabstops[1], snip.buffer)" +snippet s "section" b +`!p insert_delimiter_0(snip, t)`$1`!p insert_section_title(snip, t)` +`!p insert_delimiter_1(snip, t)` +$0 +endsnippet +------------------- SNAP ------------------- + +'insert_toc_item' will be called after first jump and will add newly entered +section into the TOC for current file. + +Note: It is also possible to trigger snippet expansion from the jump action. +In that case method 'snip.cursor.preserve()' should be called, so UltiSnips +will know that cursor is already at the required position. + +Following example will insert method call at the end of file after user jump +out of method declaration snippet. + +------------------- SNIP ------------------- +global !p +def insert_method_call(name): + vim.command('normal G') + snip.expand_anon(name + '($1)\n') +endglobal + +post_jump "if snip.tabstop == 0: insert_method_call(snip.tabstops[1].current_text)" +snippet d "method declaration" b +def $1(): + $2 +endsnippet +------------------- SNAP ------------------- + +4.11 Autotrigger *UltiSnips-autotrigger* +---------------- + +Note: vim should be newer than 7.4.214 to support this feature. + +Many language constructs can occur only at specific places, so it's +possible to use snippets without manually triggering them. + +Snippet can be marked as autotriggered by specifying 'A' option in the snippet +definition. + +After snippet is defined as being autotriggered, snippet condition will be +checked on every typed character and if condition matches, then snippet will +be triggered. + +*Warning:* using of this feature can lead to significant vim slowdown. If you +discovered that, report an issue to the github.com/SirVer/UltiSnips. + +Consider following snippets, that can be usefull in Go programming: +------------------- SNIP ------------------- +snippet "^p" "package" rbA +package ${1:main} +endsnippet + +snippet "^m" "func main" rbA +func main() { + $1 +} +endsnippet +------------------- SNAP ------------------- + +When "p" character will occur in the beginning of the line, it will be +automatically expanded into "package main". Same with "m" character. There is +no need to press trigger key after "m"" ============================================================================== -5. Support for other plugins *UltiSnips-other-plugins* +5. UltiSnips and Other Plugins *UltiSnips-other-plugins* + +5.1 Existing Integrations *UltiSnips-integrations* +------------------------- UltiSnips has built-in support for some common plugins and there are others that are aware of UltiSnips and use it to improve the user experience. This is -an incomplete list - if you want to have your plugin listed here, just sent me -a pull request. +an incomplete list - if you want to have your plugin listed here, just send a +pull request. + + *UltiSnips-snipMate* + +snipMate - UltiSnips is a drop-in replacement for snipMate. It has many more +features, so porting snippets is still a good idea, but switching has low +friction now. UltiSnips is trying hard to truly emulate snipMate, for example +recursive tabstops are not supported in snipMate snippets (but of course in +UltiSnips snippets). YouCompleteMe - comes with out of the box completion support for UltiSnips. It offers a really nice completion dialogue for snippets. +neocomplete - UltiSnips ships with a source for neocomplete and therefore +offers out of the box completion dialogue support for it too. + +unite - UltiSnips has a source for unite. As an example of how you can use +it add the following function and mappings to your vimrc: > + + function! UltiSnipsCallUnite() + Unite -start-insert -winheight=100 -immediately -no-empty ultisnips + return '' + endfunction + + inoremap =(pumvisible()? "\C-E>":"")=UltiSnipsCallUnite() + nnoremap a=(pumvisible()? "\C-E>":"")=UltiSnipsCallUnite() + +When typing in either insert or normal mode you will get the unite +interface with matching snippets. Pressing enter will expand the corresponding +snippet. If only one snippet matches the text in front of the cursor will be +expanded when you press the key. + Supertab - UltiSnips has built-in support for Supertab. Just use a recent enough version of both plugins and will either expand a snippet or defer to Supertab for expansion. -neocomplcache - Stanislav Golovanov (JazzCore) has made an integration plugin -to use UltiSnips as engine inside of neocomplcache. You can find his work at -https://github.com/JazzCore/neocomplcache-ultisnips. +5.2 Extending UltiSnips *UltiSnips-extending* +------------------------- +UltiSnips allows other plugins to add new snippets on the fly. Since UltiSnips +is written in python, the integration is also on a python basis. A small +example can be found in `test.py`, search for AddNewSnippetSource. Please +contact us on github if you integrate UltiSnips with your plugin so it can be +listed in the docs. ============================================================================= 6. Helping Out *UltiSnips-helping* UltiSnips needs the help of the Vim community to keep improving. Please -consider joining this effort by providing new snippets, new features or bug -reports. - -You can contribute snippets or patches in various ways. The methods are listed -below in order of convenience for me. Please be as convenient as you -can be :) +consider joining this effort by providing new features or bug reports. * Clone the repository on GitHub (git clone git@github.com:SirVer/ultisnips.git), make your changes and send a pull request on GitHub. * Make a patch, report a bug/feature request (see below) and attach the patch to it. -* Send me an Email with a patch (see Contact section below). -* Send me an Email with the changed files only. You can contribute by fixing or reporting bugs in our issue tracker: https://github.com/sirver/ultisnips/issues -If you like this plugin, please vote for it on its Vim script page > - http://www.vim.org/scripts/script.php?script_id=2715 -It is life-changing for me. Maybe it is for you too. - - -============================================================================= -7. Contact *UltiSnips-contact* - -You can reach me at SirVer -AT- gmx -ADOT- de. - -This project aims to be the one-for-all solution for Snippets for Vim. If you -miss a feature or find a bug, please contact me or add an issues to our issues -tracker. - ============================================================================= -8. Contributors *UltiSnips-contributors* +7. Contributors *UltiSnips-contributors* -The primary developer of UltiSnips is SirVer (Holger Rapp). The following -individuals have contributed to UltiSnips. +UltiSnips has been started and maintained from Jun 2009 - Dec 2015 by Holger +Rapp (@SirVer, SirVer@gmx.de). It is now maintained by Stanislav Seletskiy +(@seletskiy). - -8.1 Patches & Coding *UltiSnips-contricoding* --------------------- - -Contributors listed in chronological order: +This is the list of contributors pre-git in chronological order. For a full +list of contributors take the union of this set and the authors according to +git log. JCEB - Jan Christoph Ebersbach Michael Henry @@ -1357,61 +1825,21 @@ Contributors listed in chronological order: Brian Mock - saikobee Gernot Höflechner - LFDM Marcelo D Montu - mMontu - - -8.2 Snippets *UltiSnips-contrisnippets* ------------- - -Contributors listed in chronological order: - - Alec Thomas - Ryan Wooden - Ches Martin - Gordin (g0rdin) - Jan Mollowitz (phux) - Georgi Valkov (gvalkov) - Miek Gieben (miek) - Aldis Berjoza (graudeejs) - Jorge Rodrigues (skeept) - Martin Grenfell (scrooloose) - Laughedelic - Anthony Wilson (anthonywilson) - Nick Anderson (nickanderson) - Timothy Mellor (mellort) - Chris Lasher (gotgenes) - Chen Houwu (chenhouwu) - Harry Zhxu (harryzhxu) - Pavel Puchkin (neoascetic) - Jacek Wysocki (exu) - Alexander Kondratskiy (KholdStare) - Martin Krauskopf (martin-krauskopf) - Theocrite (theocrite) - Ferdinand Majerech (kiith-sa) - Vivien Didelot - Øystein Walle (osse) - Pedro Algarvio (s0undt3ch) - Steven Humphrey (shumphrey) - Björn Winckler (b4winckler) - David Brown (Nali4Freedom) - Harry Xu (harryxu) - Tom Cammann (takac) - Paolo Cretaro (melko) - Sergey Alexandrov (taketwo) - Jaromír Hradílek (jhradilek) - Vangelis Tsoumenis (kioopi) - Rudi Grinberg (rgrinberg) - javipolo - Matthew Strawbridge (pxc) - Josh Strater (jstrater) - jinzhu - Rene Vergara (ravl1084) - Johan Haals (JHaals) - Danilo Bargen (dbrgn) - Bernhard Vallant (lazerscience) - Von Welch (von) - Nikola Petrov (nikolavp) - Maarten Slagter (slagtermaarten) - -Thank you for your support. + Karl Yngve Lervåg - lervag + Pedro Ferrari - petobens + Ches Martin - ches + Christian - Oberon00 + Andrew Ruder - aeruder + Mathias Fußenegger - mfussenegger + Kevin Ballard - kballard + Ahbong Chang - cwahbong + Glenn Griffin - ggriffiniii + Michael - Pyrohh + Stanislav Seletskiy - seletskiy + Pawel Palucki - ppalucki + Dettorer - dettorer + Zhao Jiarong - kawing-chiu + Ye Ding - dyng + Greg Hurrell - wincent vim:tw=78:ts=8:ft=help:norl: diff --git a/vim/bundle/ultisnips/doc/demo.gif b/vim/bundle/ultisnips/doc/demo.gif new file mode 100644 index 0000000..32affe4 Binary files /dev/null and b/vim/bundle/ultisnips/doc/demo.gif differ diff --git a/vim/bundle/ultisnips/ftdetect/UltiSnips.vim b/vim/bundle/ultisnips/ftdetect/UltiSnips.vim index 9ec5b7b..81af3a1 100644 --- a/vim/bundle/ultisnips/ftdetect/UltiSnips.vim +++ b/vim/bundle/ultisnips/ftdetect/UltiSnips.vim @@ -1,5 +1,17 @@ " This has to be called before ftplugins are loaded. Therefore " it is here in ftdetect though it maybe shouldn't -if has("autocmd") - autocmd FileType * call UltiSnips#FileTypeChanged() + +" This is necessary to prevent errors when using vim as a pager. +if exists("vimpager") + finish +endif + +if has("autocmd") && &loadplugins + augroup UltiSnipsFileType + autocmd! + autocmd FileType * call UltiSnips#FileTypeChanged() + augroup END + + " restore 'filetypedetect' group declaration + augroup filetypedetect endif diff --git a/vim/bundle/ultisnips/ftplugin/snippets.vim b/vim/bundle/ultisnips/ftplugin/snippets.vim index 134fe01..8479a45 100644 --- a/vim/bundle/ultisnips/ftplugin/snippets.vim +++ b/vim/bundle/ultisnips/ftplugin/snippets.vim @@ -1,5 +1,13 @@ " Set some sane defaults for snippet files +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +let s:save_cpo = &cpo +set cpo&vim + " Fold by syntax, but open all folds by default setlocal foldmethod=syntax setlocal foldlevel=99 @@ -7,10 +15,33 @@ setlocal foldlevel=99 setlocal commentstring=#%s setlocal noexpandtab +setlocal autoindent nosmartindent nocindent " Define match words for use with matchit plugin " http://www.vim.org/scripts/script.php?script_id=39 if exists("loaded_matchit") && !exists("b:match_words") let b:match_ignorecase = 0 let b:match_words = '^snippet\>:^endsnippet\>,^global\>:^endglobal\>,\${:}' + let s:set_match_words = 1 endif + +" Add TagBar support +let g:tagbar_type_snippets = { + \ 'ctagstype': 'UltiSnips', + \ 'kinds': [ + \ 's:snippets', + \ ], + \ 'deffile': expand(':p:h:h') . '/ctags/UltiSnips.cnf', + \ } + +" don't unset g:tagbar_type_snippets, it serves no purpose +let b:undo_ftplugin = " + \ setlocal foldmethod< foldlevel< commentstring< + \|setlocal expandtab< autoindent< smartindent< cindent< + \|if get(s:, 'set_match_words') + \|unlet! b:match_ignorecase b:match_words s:set_match_words + \|endif + \" + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/vim/bundle/ultisnips/plugin/UltiSnips.vim b/vim/bundle/ultisnips/plugin/UltiSnips.vim index 0f9617f..f7be308 100644 --- a/vim/bundle/ultisnips/plugin/UltiSnips.vim +++ b/vim/bundle/ultisnips/plugin/UltiSnips.vim @@ -1,69 +1,57 @@ -" File: UltiSnips.vim -" Author: Holger Rapp -" Description: The Ultimate Snippets solution for Vim -" -" Testing Info: -" See directions at the top of the test.py script located one -" directory above this file. - -if exists('did_UltiSnips_plugin') || &cp || version < 700 +if exists('did_plugin_ultisnips') || &cp finish endif +let did_plugin_ultisnips=1 -" The Commands we define. -command! -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit - \ :call UltiSnips#Edit() - -command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnips#AddFiletypes() - -" Backwards compatible functions. Prefer the ones in autoload/. -function! UltiSnips_FileTypeChanged() - echoerr "Deprecated UltiSnips_FileTypeChanged called. Please use UltiSnips#FileTypeChanged." | sleep 1 - return UltiSnips#FileTypeChanged() -endfunction - -function! UltiSnips_ExpandSnippet() - echoerr "Deprecated UltiSnips_ExpandSnippet called. Please use UltiSnips#ExpandSnippet." | sleep 1 - return UltiSnips#ExpandSnippet() -endfunction - -function! UltiSnips_ExpandSnippetOrJump() - echoerr "Deprecated UltiSnips_ExpandSnippetOrJump called. Please use UltiSnips#ExpandSnippetOrJump." | sleep 1 - return UltiSnips#ExpandSnippetOrJump() -endfunction - -function! UltiSnips_SnippetsInCurrentScope() - echoerr "Deprecated UltiSnips_SnippetsInCurrentScope called. Please use UltiSnips#SnippetsInCurrentScope." | sleep 1 - return UltiSnips#SnippetsInCurrentScope() -endfunction - -function! UltiSnips_JumpBackwards() - echoerr "Deprecated UltiSnips_JumpBackwards called. Please use UltiSnips#JumpBackwards." | sleep 1 - return UltiSnips#JumpBackwards() -endfunction +if version < 704 + echohl WarningMsg + echom "UltiSnips requires Vim >= 7.4" + echohl None + finish +endif -function! UltiSnips_JumpForwards() - echoerr "Deprecated UltiSnips_JumpForwards called. Please use UltiSnips#JumpForwards." | sleep 1 - return UltiSnips#JumpForwards() -endfunction +if !exists("g:UltiSnipsUsePythonVersion") + let g:_uspy=":py3 " + if !has("python3") + if !has("python") + if !exists("g:UltiSnipsNoPythonWarning") + echohl WarningMsg + echom "UltiSnips requires py >= 2.7 or py3" + echohl None + endif + unlet g:_uspy + finish + endif + let g:_uspy=":py " + endif +else + " Use user-provided value, but check if it's available. + " This uses `has()`, because e.g. `exists(":python3")` is always 2. + if g:UltiSnipsUsePythonVersion == 2 && has('python') + let g:_uspy=":python " + elseif g:UltiSnipsUsePythonVersion == 3 && has('python3') + let g:_uspy=":python3 " + endif + if !exists('g:_uspy') + echohl WarningMsg + echom "UltiSnips: the Python version from g:UltiSnipsUsePythonVersion (".g:UltiSnipsUsePythonVersion.") is not available." + echohl None + finish + endif +endif -function! UltiSnips_AddSnippet(...) - echoerr "Deprecated UltiSnips_AddSnippet called. Please use UltiSnips#AddSnippetWithPriority." | sleep 1 - return call(function('UltiSnips#AddSnippet'), a:000) -endfunction +" The Commands we define. +command! -bang -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit + \ :call UltiSnips#Edit(, ) -function! UltiSnips_Anon(...) - echoerr "Deprecated UltiSnips_Anon called. Please use UltiSnips#Anon." | sleep 1 - return call(function('UltiSnips#Anon'), a:000) -endfunction +command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnips#AddFiletypes() -au CursorMovedI * call UltiSnips#CursorMoved() -au CursorMoved * call UltiSnips#CursorMoved() -au BufLeave * call UltiSnips#LeavingBuffer() -au InsertLeave * call UltiSnips#LeavingInsertMode() +augroup UltiSnips_AutoTrigger + au! + au InsertCharPre * call UltiSnips#TrackChange() + au TextChangedI * call UltiSnips#TrackChange() +augroup END call UltiSnips#map_keys#MapKeys() -let did_UltiSnips_plugin=1 - " vim: ts=8 sts=4 sw=4 diff --git a/vim/bundle/ultisnips/plugin/snipMate_compatibility.vim b/vim/bundle/ultisnips/plugin/snipMate_compatibility.vim deleted file mode 100644 index f88c25b..0000000 --- a/vim/bundle/ultisnips/plugin/snipMate_compatibility.vim +++ /dev/null @@ -1,28 +0,0 @@ -" File: snipMate_compatibility.vim -" Author: Phillip Berndt -" Description: Snipmate compatibility helper functions for UltiSnips -" -" Snipmate defines a function named Filename and a variable called -" g:snips_author for use in snippet subtitutions. See -" https://github.com/msanders/snipmate.vim/blob/master/doc/snipMate.txt -" for details. -" - -if exists('did_UltiSnips_snipmate_compatibility') - finish -endif -let did_UltiSnips_snipmate_compatibility = 1 - -" Define g:snips_author; some snipmate snippets use this -if ! exists('g:snips_author') - let g:snips_author = "John Doe" -endif - -" Filename function, taken from snipMate.vim {{{ -fun! Filename(...) - let filename = expand('%:t:r') - if filename == '' | return a:0 == 2 ? a:2 : '' | endif - return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g') -endf -" }}} - diff --git a/vim/bundle/ultisnips/pylintrc b/vim/bundle/ultisnips/pylintrc index 5790281..9d986cf 100644 --- a/vim/bundle/ultisnips/pylintrc +++ b/vim/bundle/ultisnips/pylintrc @@ -44,6 +44,7 @@ disable= too-many-public-methods, too-many-return-statements, too-many-statements, + bad-continuation, [REPORTS] diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/__init__.py index 9566f08..dfd3f48 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/__init__.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/__init__.py @@ -3,11 +3,4 @@ """Entry point for all thinks UltiSnips.""" -import vim # pylint:disable=import-error - -from UltiSnips.snippet_manager import SnippetManager - -UltiSnips_Manager = SnippetManager( # pylint:disable=invalid-name - vim.eval('g:UltiSnipsExpandTrigger'), - vim.eval('g:UltiSnipsJumpForwardTrigger'), - vim.eval('g:UltiSnipsJumpBackwardTrigger')) +from UltiSnips.snippet_manager import UltiSnips_Manager diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/_diff.py b/vim/bundle/ultisnips/pythonx/UltiSnips/_diff.py index f2a030b..42a5383 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/_diff.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/_diff.py @@ -10,39 +10,45 @@ import sys from UltiSnips import _vim from UltiSnips.position import Position + def is_complete_edit(initial_line, original, wanted, cmds): """Returns true if 'original' is changed to 'wanted' with the edit commands - in 'cmds'. Initial line is to change the line numbers in 'cmds'.""" + in 'cmds'. + + Initial line is to change the line numbers in 'cmds'. + + """ buf = original[:] for cmd in cmds: ctype, line, col, char = cmd line -= initial_line - if ctype == "D": + if ctype == 'D': if char != '\n': - buf[line] = buf[line][:col] + buf[line][col+len(char):] + buf[line] = buf[line][:col] + buf[line][col + len(char):] else: if line + 1 < len(buf): - buf[line] = buf[line] + buf[line+1] - del buf[line+1] + buf[line] = buf[line] + buf[line + 1] + del buf[line + 1] else: del buf[line] - elif ctype == "I": + elif ctype == 'I': buf[line] = buf[line][:col] + char + buf[line][col:] buf = '\n'.join(buf).split('\n') return (len(buf) == len(wanted) and all(j == k for j, k in zip(buf, wanted))) + def guess_edit(initial_line, last_text, current_text, vim_state): - """ - Try to guess what the user might have done by heuristically looking at + """Try to guess what the user might have done by heuristically looking at cursor movement, number of changed lines and if they got longer or shorter. This will detect most simple movements like insertion, deletion of a line or carriage return. 'initial_text' is the index of where the comparison starts, 'last_text' is the last text of the snippet, 'current_text' is the current text of the snippet and 'vim_state' is the cached vim state. - Returns (True, edit_cmds) when the edit could be guessed, (False, None) - otherwise. + Returns (True, edit_cmds) when the edit could be guessed, (False, + None) otherwise. + """ if not len(last_text) and not len(current_text): return True, () @@ -53,83 +59,84 @@ def guess_edit(initial_line, last_text, current_text, vim_state): if (len(last_text) and (not current_text or (len(current_text) == 1 and not current_text[0])) - ): + ): es = [] if not current_text: current_text = [''] for i in last_text: - es.append(("D", initial_line, 0, i)) - es.append(("D", initial_line, 0, "\n")) - es.pop() # Remove final \n because it is not really removed + es.append(('D', initial_line, 0, i)) + es.append(('D', initial_line, 0, '\n')) + es.pop() # Remove final \n because it is not really removed if is_complete_edit(initial_line, last_text, current_text, es): return True, es - if ppos.mode == 'v': # Maybe selectmode? + if ppos.mode == 'v': # Maybe selectmode? sv = list(map(int, _vim.eval("""getpos("'<")"""))) - sv = Position(sv[1]-1, sv[2]-1) + sv = Position(sv[1] - 1, sv[2] - 1) ev = list(map(int, _vim.eval("""getpos("'>")"""))) - ev = Position(ev[1]-1, ev[2]-1) - if "exclusive" in _vim.eval("&selection"): - ppos.col -= 1 # We want to be inclusive, sorry. + ev = Position(ev[1] - 1, ev[2] - 1) + if 'exclusive' in _vim.eval('&selection'): + ppos.col -= 1 # We want to be inclusive, sorry. ev.col -= 1 es = [] if sv.line == ev.line: - es.append(("D", sv.line, sv.col, - last_text[sv.line - initial_line][sv.col:ev.col+1])) + es.append(('D', sv.line, sv.col, + last_text[sv.line - initial_line][sv.col:ev.col + 1])) if sv != pos and sv.line == pos.line: - es.append(("I", sv.line, sv.col, - current_text[sv.line - initial_line][sv.col:pos.col+1])) + es.append(('I', sv.line, sv.col, + current_text[sv.line - initial_line][sv.col:pos.col + 1])) if is_complete_edit(initial_line, last_text, current_text, es): return True, es if pos.line == ppos.line: - if len(last_text) == len(current_text): # Movement only in one line + if len(last_text) == len(current_text): # Movement only in one line llen = len(last_text[ppos.line - initial_line]) clen = len(current_text[pos.line - initial_line]) - if ppos < pos and clen > llen: # maybe only chars have been added + if ppos < pos and clen > llen: # maybe only chars have been added es = ( - ("I", ppos.line, ppos.col, + ('I', ppos.line, ppos.col, current_text[ppos.line - initial_line] - [ppos.col:pos.col]), + [ppos.col:pos.col]), ) if is_complete_edit(initial_line, last_text, current_text, es): return True, es if clen < llen: - if ppos == pos: # 'x' or DEL or dt or something + if ppos == pos: # 'x' or DEL or dt or something es = ( - ("D", pos.line, pos.col, + ('D', pos.line, pos.col, last_text[ppos.line - initial_line] - [ppos.col:ppos.col + (llen - clen)]), + [ppos.col:ppos.col + (llen - clen)]), ) if is_complete_edit(initial_line, last_text, - current_text, es): + current_text, es): return True, es - if pos < ppos: # Backspacing or dT dF? + if pos < ppos: # Backspacing or dT dF? es = ( - ("D", pos.line, pos.col, + ('D', pos.line, pos.col, last_text[pos.line - initial_line] - [pos.col:pos.col + llen - clen]), + [pos.col:pos.col + llen - clen]), ) if is_complete_edit(initial_line, last_text, - current_text, es): + current_text, es): return True, es elif len(current_text) < len(last_text): # where some lines deleted? (dd or so) es = [] - for i in range(len(last_text)-len(current_text)): - es.append(("D", pos.line, 0, - last_text[pos.line - initial_line + i])) - es.append(("D", pos.line, 0, '\n')) + for i in range(len(last_text) - len(current_text)): + es.append(('D', pos.line, 0, + last_text[pos.line - initial_line + i])) + es.append(('D', pos.line, 0, '\n')) if is_complete_edit(initial_line, last_text, - current_text, es): + current_text, es): return True, es else: # Movement in more than one line - if ppos.line + 1 == pos.line and pos.col == 0: # Carriage return? - es = (("I", ppos.line, ppos.col, "\n"),) + if ppos.line + 1 == pos.line and pos.col == 0: # Carriage return? + es = (('I', ppos.line, ppos.col, '\n'),) if is_complete_edit(initial_line, last_text, - current_text, es): + current_text, es): return True, es return False, None + def diff(a, b, sline=0): """ Return a list of deletions and insertions that will turn 'a' into 'b'. This @@ -154,8 +161,8 @@ def diff(a, b, sline=0): d[0] = [(0, 0, sline, 0, ())] cost = 0 - deletion_cost = len(a)+len(b) - insertion_cost = len(a)+len(b) + deletion_cost = len(a) + len(b) + insertion_cost = len(a) + len(b) while True: while len(d[cost]): x, y, line, col, what = d[cost].pop() @@ -170,50 +177,50 @@ def diff(a, b, sline=0): ncol = 0 nline += 1 lcost = cost + 1 - if (what and what[-1][0] == "D" and what[-1][1] == line and + if (what and what[-1][0] == 'D' and what[-1][1] == line and what[-1][2] == col and a[x] != '\n'): # Matching directly after a deletion should be as costly as # DELETE + INSERT + a bit - lcost = (deletion_cost + insertion_cost)*1.5 - if seen[x+1, y+1] > lcost: - d[lcost].append((x+1, y+1, nline, ncol, what)) - seen[x+1, y+1] = lcost - if y < len(b): # INSERT + lcost = (deletion_cost + insertion_cost) * 1.5 + if seen[x + 1, y + 1] > lcost: + d[lcost].append((x + 1, y + 1, nline, ncol, what)) + seen[x + 1, y + 1] = lcost + if y < len(b): # INSERT ncol = col + 1 nline = line if b[y] == '\n': ncol = 0 nline += 1 - if (what and what[-1][0] == "I" and what[-1][1] == nline and - what[-1][2]+len(what[-1][-1]) == col and b[y] != '\n' and - seen[x, y+1] > cost + (insertion_cost + ncol) // 2 - ): - seen[x, y+1] = cost + (insertion_cost + ncol) // 2 + if (what and what[-1][0] == 'I' and what[-1][1] == nline and + what[-1][2] + len(what[-1][-1]) == col and b[y] != '\n' and + seen[x, y + 1] > cost + (insertion_cost + ncol) // 2 + ): + seen[x, y + 1] = cost + (insertion_cost + ncol) // 2 d[cost + (insertion_cost + ncol) // 2].append( - (x, y+1, line, ncol, what[:-1] + ( - ("I", what[-1][1], what[-1][2], + (x, y + 1, line, ncol, what[:-1] + ( + ('I', what[-1][1], what[-1][2], what[-1][-1] + b[y]),) - ) + ) ) - elif seen[x, y+1] > cost + insertion_cost + ncol: - seen[x, y+1] = cost + insertion_cost + ncol - d[cost + ncol + insertion_cost].append((x, y+1, nline, ncol, - what + (("I", line, col, b[y]),)) - ) - if x < len(a): # DELETE - if (what and what[-1][0] == "D" and what[-1][1] == line and - what[-1][2] == col and a[x] != '\n' and - what[-1][-1] != '\n' and - seen[x+1, y] > cost + deletion_cost // 2 - ): - seen[x+1, y] = cost + deletion_cost // 2 + elif seen[x, y + 1] > cost + insertion_cost + ncol: + seen[x, y + 1] = cost + insertion_cost + ncol + d[cost + ncol + insertion_cost].append((x, y + 1, nline, ncol, + what + (('I', line, col, b[y]),)) + ) + if x < len(a): # DELETE + if (what and what[-1][0] == 'D' and what[-1][1] == line and + what[-1][2] == col and a[x] != '\n' and + what[-1][-1] != '\n' and + seen[x + 1, y] > cost + deletion_cost // 2 + ): + seen[x + 1, y] = cost + deletion_cost // 2 d[cost + deletion_cost // 2].append( - (x+1, y, line, col, what[:-1] + ( - ("D", line, col, what[-1][-1] + a[x]),)) - ) - elif seen[x+1, y] > cost + deletion_cost: - seen[x+1, y] = cost + deletion_cost - d[cost + deletion_cost].append((x+1, y, line, col, what + - (("D", line, col, a[x]),)) + (x + 1, y, line, col, what[:-1] + ( + ('D', line, col, what[-1][-1] + a[x]),)) ) + elif seen[x + 1, y] > cost + deletion_cost: + seen[x + 1, y] = cost + deletion_cost + d[cost + deletion_cost].append((x + 1, y, line, col, what + + (('D', line, col, a[x]),)) + ) cost += 1 diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/_vim.py b/vim/bundle/ultisnips/pythonx/UltiSnips/_vim.py index 579de1d..568da3a 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/_vim.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/_vim.py @@ -9,64 +9,87 @@ import vim # pylint:disable=import-error from vim import error # pylint:disable=import-error,unused-import from UltiSnips.compatibility import col2byte, byte2col, \ - as_unicode, as_vimencoding + as_unicode, as_vimencoding from UltiSnips.position import Position +from contextlib import contextmanager + + class VimBuffer(object): + """Wrapper around the current Vim buffer.""" def __getitem__(self, idx): - if isinstance(idx, slice): # Py3 + if isinstance(idx, slice): # Py3 return self.__getslice__(idx.start, idx.stop) rv = vim.current.buffer[idx] return as_unicode(rv) - def __getslice__(self, i, j): # pylint:disable=no-self-use + def __getslice__(self, i, j): # pylint:disable=no-self-use rv = vim.current.buffer[i:j] return [as_unicode(l) for l in rv] def __setitem__(self, idx, text): - if isinstance(idx, slice): # Py3 + if isinstance(idx, slice): # Py3 return self.__setslice__(idx.start, idx.stop, text) vim.current.buffer[idx] = as_vimencoding(text) - def __setslice__(self, i, j, text): # pylint:disable=no-self-use + def __setslice__(self, i, j, text): # pylint:disable=no-self-use vim.current.buffer[i:j] = [as_vimencoding(l) for l in text] def __len__(self): return len(vim.current.buffer) @property - def line_till_cursor(self): # pylint:disable=no-self-use + def line_till_cursor(self): # pylint:disable=no-self-use """Returns the text before the cursor.""" - # Note: we want byte position here - _, col = vim.current.window.cursor - line = vim.current.line - before = as_unicode(line[:col]) - return before + _, col = self.cursor + return as_unicode(vim.current.line)[:col] @property - def number(self): # pylint:disable=no-self-use - """The bufnr() of this buffer.""" - return int(eval("bufnr('%')")) + def number(self): # pylint:disable=no-self-use + """The bufnr() of the current buffer.""" + return vim.current.buffer.number @property - def cursor(self): # pylint:disable=no-self-use - """ - The current windows cursor. Note that this is 0 based in col and 0 - based in line which is different from Vim's cursor. + def cursor(self): # pylint:disable=no-self-use + """The current windows cursor. + + Note that this is 0 based in col and 0 based in line which is + different from Vim's cursor. + """ line, nbyte = vim.current.window.cursor col = byte2col(line, nbyte) return Position(line - 1, col) @cursor.setter - def cursor(self, pos): # pylint:disable=no-self-use + def cursor(self, pos): # pylint:disable=no-self-use """See getter.""" nbyte = col2byte(pos.line + 1, pos.col) vim.current.window.cursor = pos.line + 1, nbyte buf = VimBuffer() # pylint:disable=invalid-name +@contextmanager +def toggle_opt(name, new_value): + old_value = eval('&' + name) + command('set {0}={1}'.format(name, new_value)) + try: + yield + finally: + command('set {0}={1}'.format(name, old_value)) + +@contextmanager +def save_mark(name): + old_pos = get_mark_pos(name) + try: + yield + finally: + if _is_pos_zero(old_pos): + delete_mark(name) + else: + set_mark_from_pos(name, old_pos) + def escape(inp): """Creates a vim-friendly string from a group of dicts, lists and strings.""" @@ -76,17 +99,19 @@ def escape(inp): rv = as_unicode('[' + ','.join(conv(o) for o in obj) + ']') elif isinstance(obj, dict): rv = as_unicode('{' + ','.join([ - "%s:%s" % (conv(key), conv(value)) + '%s:%s' % (conv(key), conv(value)) for key, value in obj.iteritems()]) + '}') else: rv = as_unicode('"%s"') % as_unicode(obj).replace('"', '\\"') return rv return conv(inp) + def command(cmd): """Wraps vim.command.""" return as_unicode(vim.command(as_vimencoding(cmd))) + def eval(text): """Wraps vim.eval.""" rv = vim.eval(as_vimencoding(text)) @@ -94,105 +119,127 @@ def eval(text): return as_unicode(rv) return rv + def feedkeys(keys, mode='n'): - """Wrapper around vim's feedkeys function. Mainly for convenience.""" - command(as_unicode(r'call feedkeys("%s", "%s")') % (keys, mode)) + """Wrapper around vim's feedkeys function. + + Mainly for convenience. + + """ + if eval('mode()') == 'n': + if keys == 'a': + cursor_pos = get_cursor_pos() + cursor_pos[2] = int(cursor_pos[2]) + 1 + set_cursor_from_pos(cursor_pos) + if keys in 'ai': + keys = 'startinsert' + + if keys == 'startinsert': + command('startinsert') + else: + command(as_unicode(r'call feedkeys("%s", "%s")') % (keys, mode)) + def new_scratch_buffer(text): - """Create a new scratch buffer with the text given""" - vim.command("botright new") - vim.command("set ft=") - vim.command("set buftype=nofile") + """Create a new scratch buffer with the text given.""" + vim.command('botright new') + vim.command('set ft=') + vim.command('set buftype=nofile') vim.current.buffer[:] = text.splitlines() feedkeys(r"\") -def select(start, end): - """Select the span in Select mode""" +def virtual_position(line, col): + """Runs the position through virtcol() and returns the result.""" + nbytes = col2byte(line, col) + return line, int(eval('virtcol([%d, %d])' % (line, nbytes))) + + +def select(start, end): + """Select the span in Select mode.""" _unmap_select_mode_mapping() - delta = end - start - lineno, col = start.line, start.col + selection = eval('&selection') + + col = col2byte(start.line + 1, start.col) + vim.current.window.cursor = start.line + 1, col - col = col2byte(lineno + 1, col) - vim.current.window.cursor = lineno + 1, col + mode = eval('mode()') - move_cmd = "" - if eval("mode()") != 'n': + move_cmd = '' + if mode != 'n': move_cmd += r"\" - # Case 1: Zero Length Tabstops - if delta.line == delta.col == 0: - if col == 0 or eval("mode()") not in 'i' and \ - col < len(buf[lineno]): - move_cmd += "i" + if start == end: + # Zero Length Tabstops, use 'i' or 'a'. + if col == 0 or mode not in 'i' and \ + col < len(buf[start.line]): + move_cmd += 'i' else: - move_cmd += "a" + move_cmd += 'a' else: - # Case 2a: Non zero length - # If a tabstop immediately starts with a newline, the selection must - # start after the last character in the current line. But if we are in - # insert mode and out of it, we cannot go past the last character - # with move_one_right and therefore cannot visual-select this newline. - # We have to hack around this by adding an extra space which we can - # select. Note that this problem could be circumvent by selecting the - # tab backwards (that is starting at the end); one would not need to - # modify the line for this. This creates other trouble though - if col >= len(buf[lineno]): - buf[lineno] += " " - - if delta.line: - move_lines = "%ij" % delta.line - else: - move_lines = "" - # Depending on the current mode and position, we - # might need to move escape out of the mode and this - # will move our cursor one left - if col != 0 and eval("mode()") == 'i': - move_one_right = "l" - else: - move_one_right = "" - - # After moving to the correct line, we go back to column 0 - # and select right from there. Note that the we have to select - # one column less since Vim's visual selection is including the - # ending while Python slicing is excluding the ending. - inclusive = "inclusive" in eval("&selection") - if end.col == 0: - # Selecting should end at beginning of line -> Select the - # previous line till its end - do_select = "k$" - if not inclusive: - do_select += "j0" - elif end.col > 1: - do_select = "0%il" % (end.col-1 if inclusive else end.col) + # Non zero length, use Visual selection. + move_cmd += 'v' + if 'inclusive' in selection: + if end.col == 0: + move_cmd += '%iG$' % end.line + else: + move_cmd += '%iG%i|' % virtual_position(end.line + 1, end.col) + elif 'old' in selection: + move_cmd += '%iG%i|' % virtual_position(end.line + 1, end.col) else: - do_select = "0" if inclusive else "0l" + move_cmd += '%iG%i|' % virtual_position(end.line + 1, end.col + 1) + move_cmd += 'o%iG%i|o\\' % virtual_position( + start.line + 1, start.col + 1) + feedkeys(move_cmd) - move_cmd += _LangMapTranslator().translate( - r"%sv%s%s\" % (move_one_right, move_lines, do_select) - ) +def set_mark_from_pos(name, pos): + return _set_pos("'" + name, pos) - feedkeys(move_cmd) +def get_mark_pos(name): + return _get_pos("'" + name) + +def set_cursor_from_pos(pos): + return _set_pos('.', pos) + +def get_cursor_pos(): + return _get_pos('.') + +def delete_mark(name): + try: + return command('delma ' + name) + except: + return False + +def _set_pos(name, pos): + return eval("setpos(\"{0}\", {1})".format(name, pos)) + +def _get_pos(name): + return eval("getpos(\"{0}\")".format(name)) + +def _is_pos_zero(pos): + return ['0'] * 4 == pos or [0] == pos def _unmap_select_mode_mapping(): """This function unmaps select mode mappings if so wished by the user. + Removes select mode mappings that can actually be typed by the user (ie, ignores things like ). + """ - if int(eval("g:UltiSnipsRemoveSelectModeMappings")): - ignores = eval("g:UltiSnipsMappingsToIgnore") + ['UltiSnips'] + if int(eval('g:UltiSnipsRemoveSelectModeMappings')): + ignores = eval('g:UltiSnipsMappingsToIgnore') + ['UltiSnips'] - for option in ("", ""): + for option in ('', ''): # Put all smaps into a var, and then read the var command(r"redir => _tmp_smaps | silent smap %s " % option + - "| redir END") + '| redir END') # Check if any mappings where found all_maps = list(filter(len, eval(r"_tmp_smaps").splitlines())) - if len(all_maps) == 1 and all_maps[0][0] not in " sv": + if len(all_maps) == 1 and all_maps[0][0] not in ' sv': # "No maps found". String could be localized. Hopefully # it doesn't start with any of these letters in any # language @@ -200,37 +247,38 @@ def _unmap_select_mode_mapping(): # Only keep mappings that should not be ignored maps = [m for m in all_maps if - not any(i in m for i in ignores) and len(m.strip())] + not any(i in m for i in ignores) and len(m.strip())] for map in maps: # The first three chars are the modes, that might be listed. # We are not interested in them here. - trig = map[3:].split()[0] if len(map[3:].split()) != 0 else None + trig = map[3:].split()[0] if len( + map[3:].split()) != 0 else None if trig is None: continue # The bar separates commands - if trig[-1] == "|": - trig = trig[:-1] + "" + if trig[-1] == '|': + trig = trig[:-1] + '' # Special ones - if trig[0] == "<": + if trig[0] == '<': add = False # Only allow these - for valid in ["Tab", "NL", "CR", "C-Tab", "BS"]: - if trig == "<%s>" % valid: + for valid in ['Tab', 'NL', 'CR', 'C-Tab', 'BS']: + if trig == '<%s>' % valid: add = True if not add: continue # UltiSnips remaps . Keep this around. - if trig == "": + if trig == '': continue # Actually unmap it try: - command("silent! sunmap %s %s" % (option, trig)) + command('silent! sunmap %s %s' % (option, trig)) except: # pylint:disable=bare-except # Bug 908139: ignore unmaps that fail because of # unprintable characters. This is not ideal because we @@ -241,54 +289,3 @@ def _unmap_select_mode_mapping(): # This case should be rare enough to not bother us # though. pass - -class _RealLangMapTranslator(object): - """This cares for the Vim langmap option and basically reverses the - mappings. This was the only solution to get UltiSnips to work nicely with - langmap; other stuff I tried was using inoremap movement commands and - caching and restoring the langmap option. - - Note that this will not work if the langmap overwrites a character - completely, for example if 'j' is remapped, but nothing is mapped back to - 'j', then moving one line down is no longer possible and UltiSnips will - fail. - """ - _maps = {} - _SEMICOLONS = re.compile(r"(? 1: - from_char, to_char = [a.replace("\\;", ";") for a in res] - from_chars += from_char - to_chars += to_char - else: - from_chars += char[::2] - to_chars += char[1::2] - self._maps[langmap] = (from_chars, to_chars) - - def translate(self, text): - """Inverse map 'text' through langmap.""" - langmap = eval("&langmap").strip() - if langmap == "": - return text - text = as_unicode(text) - if langmap not in self._maps: - self._create_translation(langmap) - for before, after in zip(*self._maps[langmap]): - text = text.replace(before, after) - return text - -class _DummyLangMapTranslator(object): - """If vim hasn't got the langmap compiled in, we never have to do anything. - Then this class is used. """ - translate = lambda self, s: s - -_LangMapTranslator = _RealLangMapTranslator -if not int(eval('has("langmap")')): - _LangMapTranslator = _DummyLangMapTranslator diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/buffer_proxy.py b/vim/bundle/ultisnips/pythonx/UltiSnips/buffer_proxy.py new file mode 100644 index 0000000..6c5bb4a --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/buffer_proxy.py @@ -0,0 +1,224 @@ +# coding=utf8 + +import vim +import UltiSnips._vim +from UltiSnips.compatibility import as_unicode, as_vimencoding +from UltiSnips.position import Position +from UltiSnips._diff import diff +from UltiSnips import _vim + +from contextlib import contextmanager + + +@contextmanager +def use_proxy_buffer(snippets_stack, vstate): + """ + Forward all changes made in the buffer to the current snippet stack while + function call. + """ + buffer_proxy = VimBufferProxy(snippets_stack, vstate) + old_buffer = _vim.buf + try: + _vim.buf = buffer_proxy + yield + finally: + _vim.buf = old_buffer + buffer_proxy.validate_buffer() + + +@contextmanager +def suspend_proxy_edits(): + """ + Prevents changes being applied to the snippet stack while function call. + """ + if not isinstance(_vim.buf, VimBufferProxy): + yield + else: + try: + _vim.buf._disable_edits() + yield + finally: + _vim.buf._enable_edits() + + +class VimBufferProxy(_vim.VimBuffer): + """ + Proxy object used for tracking changes that made from snippet actions. + + Unfortunately, vim by itself lacks of the API for changing text in + trackable maner. + + Vim marks offers limited functionality for tracking line additions and + deletions, but nothing offered for tracking changes withing single line. + + Instance of this class is passed to all snippet actions and behaves as + internal vim.current.window.buffer. + + All changes that are made by user passed to diff algorithm, and resulting + diff applied to internal snippet structures to ensure they are in sync with + actual buffer contents. + """ + + def __init__(self, snippets_stack, vstate): + """ + Instantiate new object. + + snippets_stack is a slice of currently active snippets. + """ + self._snippets_stack = snippets_stack + self._buffer = vim.current.buffer + self._change_tick = int(vim.eval("b:changedtick")) + self._forward_edits = True + self._vstate = vstate + + def is_buffer_changed_outside(self): + """ + Returns true, if buffer was changed without using proxy object, like + with vim.command() or through internal vim.current.window.buffer. + """ + return self._change_tick < int(vim.eval("b:changedtick")) + + def validate_buffer(self): + """ + Raises exception if buffer is changes beyound proxy object. + """ + if self.is_buffer_changed_outside(): + raise RuntimeError('buffer was modified using vim.command or ' + + 'vim.current.buffer; that changes are untrackable and leads to ' + + 'errors in snippet expansion; use special variable `snip.buffer` ' + 'for buffer modifications.\n\n' + + 'See :help UltiSnips-buffer-proxy for more info.') + + def __setitem__(self, key, value): + """ + Behaves as vim.current.window.buffer.__setitem__ except it tracks + changes and applies them to the current snippet stack. + """ + if isinstance(key, slice): + value = [as_vimencoding(line) for line in value] + changes = list(self._get_diff(key.start, key.stop, value)) + self._buffer[key.start:key.stop] = [ + line.strip('\n') for line in value + ] + else: + value = as_vimencoding(value) + changes = list(self._get_line_diff(key, self._buffer[key], value)) + self._buffer[key] = value + + self._change_tick += 1 + + if self._forward_edits: + for change in changes: + self._apply_change(change) + if self._snippets_stack: + self._vstate.remember_buffer(self._snippets_stack[0]) + + def __setslice__(self, i, j, text): + """ + Same as __setitem__. + """ + self.__setitem__(slice(i, j), text) + + def __getitem__(self, key): + """ + Just passing call to the vim.current.window.buffer.__getitem__. + """ + if isinstance(key, slice): + return [as_unicode(l) for l in self._buffer[key.start:key.stop]] + else: + return as_unicode(self._buffer[key]) + + def __getslice__(self, i, j): + """ + Same as __getitem__. + """ + return self.__getitem__(slice(i, j)) + + def __len__(self): + """ + Same as len(vim.current.window.buffer). + """ + return len(self._buffer) + + def append(self, line, line_number=-1): + """ + Same as vim.current.window.buffer.append(), but with tracking changes. + """ + if line_number < 0: + line_number = len(self) + if not isinstance(line, list): + line = [line] + self[line_number:line_number] = [as_vimencoding(l) for l in line] + + def __delitem__(self, key): + if isinstance(key, slice): + self.__setitem__(key, []) + else: + self.__setitem__(slice(key, key+1), []) + + def _get_diff(self, start, end, new_value): + """ + Very fast diffing algorithm when changes are across many lines. + """ + for line_number in range(start, end): + if line_number < 0: + line_number = len(self._buffer) + line_number + yield ('D', line_number, 0, self._buffer[line_number]) + + if start < 0: + start = len(self._buffer) + start + for line_number in range(0, len(new_value)): + yield ('I', start+line_number, 0, new_value[line_number]) + + def _get_line_diff(self, line_number, before, after): + """ + Use precise diffing for tracking changes in single line. + """ + if before == '': + for change in self._get_diff(line_number, line_number+1, [after]): + yield change + else: + for change in diff(before, after): + yield (change[0], line_number, change[2], change[3]) + + def _apply_change(self, change): + """ + Apply changeset to current snippets stack, correctly moving around + snippet itself or its child. + """ + if not self._snippets_stack: + return + + line_number = change[1] + column_number = change[2] + line_before = line_number <= self._snippets_stack[0]._start.line + column_before = column_number <= self._snippets_stack[0]._start.col + if line_before and column_before: + direction = 1 + if change[0] == 'D': + direction = -1 + + self._snippets_stack[0]._move( + Position(line_number, 0), + Position(direction, 0) + ) + else: + if line_number > self._snippets_stack[0]._end.line: + return + if column_number >= self._snippets_stack[0]._end.col: + return + self._snippets_stack[0]._do_edit(change) + + def _disable_edits(self): + """ + Temporary disable applying changes to snippets stack. Should be done + while expanding anonymous snippet in the middle of jump to prevent + double tracking. + """ + self._forward_edits = False + + def _enable_edits(self): + """ + Enables changes forwarding back. + """ + self._forward_edits = True diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/compatibility.py b/vim/bundle/ultisnips/pythonx/UltiSnips/compatibility.py index 7e14123..b8781bb 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/compatibility.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/compatibility.py @@ -1,45 +1,43 @@ #!/usr/bin/env python # encoding: utf-8 -""" -This file contains compatibility code to stay compatible with -as many python versions as possible. -""" +"""This file contains compatibility code to stay compatible with as many python +versions as possible.""" import sys import vim # pylint:disable=import-error -def _vim_dec(string): - """Decode 'string' using &encoding.""" - try: - return string.decode(vim.eval("&encoding")) - except UnicodeDecodeError: - # At least we tried. There might be some problems down the road now - return string +if sys.version_info >= (3, 0): + def _vim_dec(string): + """Decode 'string' using &encoding.""" + # We don't have the luxury here of failing, everything + # falls apart if we don't return a bytearray from the + # passed in string + return string.decode(vim.eval('&encoding'), 'replace') -def _vim_enc(string): - """Encode 'string' using &encoding.""" - try: - return string.encode(vim.eval("&encoding")) - except UnicodeEncodeError: - return string + def _vim_enc(bytearray): + """Encode 'string' using &encoding.""" + # We don't have the luxury here of failing, everything + # falls apart if we don't return a string from the passed + # in bytearray + return bytearray.encode(vim.eval('&encoding'), 'replace') + + def open_ascii_file(filename, mode): + """Opens a file in "r" mode.""" + return open(filename, mode, encoding='utf-8') -if sys.version_info >= (3, 0): def col2byte(line, col): - """ - Convert a valid column index into a byte index inside - of vims buffer. - """ - pre_chars = vim.current.buffer[line-1][:col] + """Convert a valid column index into a byte index inside of vims + buffer.""" + # We pad the line so that selecting the +1 st column still works. + pre_chars = (vim.current.buffer[line - 1] + ' ')[:col] return len(_vim_enc(pre_chars)) def byte2col(line, nbyte): - """ - Convert a column into a byteidx suitable for a mark or cursor - position inside of vim - """ - line = vim.current.buffer[line-1] + """Convert a column into a byteidx suitable for a mark or cursor + position inside of vim.""" + line = vim.current.buffer[line - 1] raw_bytes = _vim_enc(line)[:nbyte] return len(_vim_dec(raw_bytes)) @@ -54,23 +52,41 @@ if sys.version_info >= (3, 0): return string else: import warnings - warnings.filterwarnings("ignore", category=DeprecationWarning) + warnings.filterwarnings('ignore', category=DeprecationWarning) + + def _vim_dec(string): + """Decode 'string' using &encoding.""" + try: + return string.decode(vim.eval('&encoding')) + except UnicodeDecodeError: + # At least we tried. There might be some problems down the road now + return string + + def _vim_enc(string): + """Encode 'string' using &encoding.""" + try: + return string.encode(vim.eval('&encoding')) + except UnicodeDecodeError: + return string + except UnicodeEncodeError: + return string + + def open_ascii_file(filename, mode): + """Opens a file in "r" mode.""" + return open(filename, mode) def col2byte(line, col): - """ - Convert a valid column index into a byte index inside - of vims buffer. - """ - pre_chars = _vim_dec(vim.current.buffer[line-1])[:col] + """Convert a valid column index into a byte index inside of vims + buffer.""" + # We pad the line so that selecting the +1 st column still works. + pre_chars = _vim_dec(vim.current.buffer[line - 1] + ' ')[:col] return len(_vim_enc(pre_chars)) def byte2col(line, nbyte): - """ - Convert a column into a byteidx suitable for a mark or cursor - position inside of vim - """ - line = vim.current.buffer[line-1] - if nbyte >= len(line): # This is beyond end of line + """Convert a column into a byteidx suitable for a mark or cursor + position inside of vim.""" + line = vim.current.buffer[line - 1] + if nbyte >= len(line): # This is beyond end of line return nbyte return len(_vim_dec(line[:nbyte])) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/debug.py b/vim/bundle/ultisnips/pythonx/UltiSnips/debug.py index 10c34ec..e37f54e 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/debug.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/debug.py @@ -1,17 +1,21 @@ #!/usr/bin/env python # encoding: utf-8 -"""Convenience methods that help with debugging. They should never be used in -production code.""" +"""Convenience methods that help with debugging. + +They should never be used in production code. + +""" import sys from UltiSnips.compatibility import as_unicode -DUMP_FILENAME = "/tmp/file.txt" if not sys.platform.lower().startswith("win") \ - else "C:/windows/temp/ultisnips.txt" -with open(DUMP_FILENAME, "w"): - pass # clears the file +DUMP_FILENAME = '/tmp/file.txt' if not sys.platform.lower().startswith('win') \ + else 'C:/windows/temp/ultisnips.txt' +with open(DUMP_FILENAME, 'w'): + pass # clears the file + def echo_to_hierarchy(text_object): """Outputs the given 'text_object' and its children hierarchically.""" @@ -20,24 +24,26 @@ def echo_to_hierarchy(text_object): while parent._parent: parent = parent._parent - def _do_print(text_object, indent=""): + def _do_print(text_object, indent=''): """prints recursively.""" debug(indent + as_unicode(text_object)) try: for child in text_object._children: - _do_print(child, indent=indent + " ") + _do_print(child, indent=indent + ' ') except AttributeError: pass _do_print(parent) + def debug(msg): """Dumb 'msg' into the debug file.""" msg = as_unicode(msg) - with open(DUMP_FILENAME, "ab") as dump_file: - dump_file.write((msg + '\n').encode("utf-8")) + with open(DUMP_FILENAME, 'ab') as dump_file: + dump_file.write((msg + '\n').encode('utf-8')) + def print_stack(): """Dump a stack trace into the debug file.""" import traceback - with open(DUMP_FILENAME, "ab") as dump_file: + with open(DUMP_FILENAME, 'ab') as dump_file: traceback.print_stack(file=dump_file) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/escaping.py b/vim/bundle/ultisnips/pythonx/UltiSnips/escaping.py deleted file mode 100644 index 7cfbdc8..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/escaping.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Utilities to deal with text escaping.""" - -def unescape(text): - """Removes '\\' escaping from 'text'.""" - rv = "" - i = 0 - while i < len(text): - if i+1 < len(text) and text[i] == '\\': - rv += text[i+1] - i += 1 - else: - rv += text[i] - i += 1 - return rv - -def fill_in_whitespace(text): - """Returns 'text' with escaped whitespace replaced through whitespaces.""" - text = text.replace(r"\n", "\n") - text = text.replace(r"\t", "\t") - text = text.replace(r"\r", "\r") - text = text.replace(r"\a", "\a") - text = text.replace(r"\b", "\b") - return text diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/indent_util.py b/vim/bundle/ultisnips/pythonx/UltiSnips/indent_util.py index 769af7e..55525d6 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/indent_util.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/indent_util.py @@ -3,37 +3,40 @@ """See module doc.""" -import UltiSnips._vim as _vim +from UltiSnips import _vim + class IndentUtil(object): - """Utility class for dealing properly with indentation. """ + + """Utility class for dealing properly with indentation.""" def __init__(self): self.reset() def reset(self): - """ Gets the spacing properties from Vim. """ - self.shiftwidth = int(_vim.eval("&shiftwidth")) - self._expandtab = (_vim.eval("&expandtab") == "1") - self._tabstop = int(_vim.eval("&tabstop")) + """Gets the spacing properties from Vim.""" + self.shiftwidth = int( + _vim.eval("exists('*shiftwidth') ? shiftwidth() : &shiftwidth")) + self._expandtab = (_vim.eval('&expandtab') == '1') + self._tabstop = int(_vim.eval('&tabstop')) def ntabs_to_proper_indent(self, ntabs): """Convert 'ntabs' number of tabs to the proper indent prefix.""" - line_ind = ntabs * self.shiftwidth * " " + line_ind = ntabs * self.shiftwidth * ' ' line_ind = self.indent_to_spaces(line_ind) line_ind = self.spaces_to_indent(line_ind) return line_ind def indent_to_spaces(self, indent): - """ Converts indentation to spaces respecting Vim settings. """ + """Converts indentation to spaces respecting Vim settings.""" indent = indent.expandtabs(self._tabstop) - right = (len(indent) - len(indent.rstrip(" "))) * " " - indent = indent.replace(" ", "") - indent = indent.replace('\t', " " * self._tabstop) + right = (len(indent) - len(indent.rstrip(' '))) * ' ' + indent = indent.replace(' ', '') + indent = indent.replace('\t', ' ' * self._tabstop) return indent + right def spaces_to_indent(self, indent): - """ Converts spaces to proper indentation respecting Vim settings """ + """Converts spaces to proper indentation respecting Vim settings.""" if not self._expandtab: - indent = indent.replace(" " * self._tabstop, '\t') + indent = indent.replace(' ' * self._tabstop, '\t') return indent diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/position.py b/vim/bundle/ultisnips/pythonx/UltiSnips/position.py index d22d04f..3c9d2a5 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/position.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/position.py @@ -4,7 +4,9 @@ """Represents a Position in a text file: (0 based line index, 0 based column index) and provides methods for moving them around.""" + class Position(object): + """See module docstring.""" def __init__(self, line, col): @@ -13,7 +15,7 @@ class Position(object): def move(self, pivot, delta): """'pivot' is the position of the first changed character, 'delta' is - how text after it moved""" + how text after it moved.""" if self < pivot: return if delta.line == 0: @@ -62,4 +64,14 @@ class Position(object): return (self.line, self.col) <= (other.line, other.col) def __repr__(self): - return "(%i,%i)" % (self.line, self.col) + return '(%i,%i)' % (self.line, self.col) + + def __getitem__(self, index): + if index > 1: + raise IndexError( + 'position can be indexed only 0 (line) and 1 (column)' + ) + if index == 0: + return self.line + else: + return self.col diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/providers/__init__.py deleted file mode 100644 index b6f2ce5..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Sources of snippet definitions.""" - -# TODO(sirver): these should register themselves with the Manager, so that -# other plugins can extend them more easily. -from UltiSnips.providers.snippet_file import UltiSnipsFileProvider, \ - base_snippet_files_for -from UltiSnips.providers.added_snippets_provider import AddedSnippetsProvider diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_base.py deleted file mode 100644 index d94efff..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_base.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Base class for snippet providers.""" - -from collections import defaultdict - -from UltiSnips.providers._snippet_dictionary import SnippetDictionary - -class SnippetProvider(object): - """See module docstring.""" - - def __init__(self): - self._snippets = defaultdict(SnippetDictionary) - - def get_snippets(self, filetypes, before, possible): - """Returns the snippets for all 'filetypes' (in order) and their - parents matching the text 'before'. If 'possible' is true, a partial - match is enough.""" - found_snippets = [] - for ft in filetypes: - found_snippets += self._find_snippets(ft, before, possible) - return found_snippets - - def _find_snippets(self, ft, trigger, potentially=False, seen=None): - """Find snippets matching 'trigger' for 'ft'. If 'potentially' is True, - partial matches are enough.""" - snips = self._snippets.get(ft, None) - if not snips: - return [] - if not seen: - seen = set() - seen.add(ft) - parent_results = [] - # TODO(sirver): extends information is not bound to one - # provider. It should be tracked further up. - for parent_ft in snips.extends: - if parent_ft not in seen: - seen.add(parent_ft) - parent_results += self._find_snippets(parent_ft, trigger, - potentially, seen) - return parent_results + snips.get_matching_snippets( - trigger, potentially) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_snippet_dictionary.py b/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_snippet_dictionary.py deleted file mode 100644 index a74be8b..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/_snippet_dictionary.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Implements a container for parsed snippets.""" - -import hashlib -import os - -def _hash_file(path): - """Returns a hashdigest of 'path'""" - if not os.path.isfile(path): - return False - return hashlib.sha1(open(path, "rb").read()).hexdigest() - -# TODO(sirver): This class should not hash any files nor keep track of extends. -class SnippetDictionary(object): - """See module docstring.""" - - def __init__(self): - self._added = [] - self._extends = [] - self._files = {} - self._snippets = [] - - def add_snippet(self, snippet, filename): - """Add 'snippet' to this dictionary. If 'filename' is given, also watch - the original file for changes.""" - if filename: - self._snippets.append(snippet) - if filename not in self.files: - self.addfile(filename) - else: - self._added.append(snippet) - - def get_matching_snippets(self, trigger, potentially): - """Returns all snippets matching the given trigger. If 'potentially' is - true, returns all that could_match().""" - all_snippets = self._added + self._snippets - if not potentially: - return [s for s in all_snippets if s.matches(trigger)] - else: - return [s for s in all_snippets if s.could_match(trigger)] - - def clear_snippets(self, triggers=None): - """Remove all snippets that match each trigger in 'triggers'. When - 'triggers' is None, empties this dictionary completely.""" - if triggers is None: - triggers = [] - if triggers: - for trigger in triggers: - for snippet in self.get_matching_snippets(trigger, False): - if snippet in self._snippets: - self._snippets.remove(snippet) - if snippet in self._added: - self._added.remove(snippet) - else: - self._snippets = [] - self._added = [] - - def addfile(self, path): - """Add this file to the files we read triggers from.""" - self.files[path] = _hash_file(path) - - def has_any_file_changed(self): - """Returns True if any of our watched files has changed since we read - it last.""" - for path, hash in self.files.items(): - if not hash or hash != _hash_file(path): - return True - return False - - @property - def files(self): - """All files we have read snippets from.""" - return self._files - - @property - def extends(self): - """The list of filetypes this filetype extends.""" - return self._extends diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/snippet_file.py b/vim/bundle/ultisnips/pythonx/UltiSnips/providers/snippet_file.py deleted file mode 100644 index e65c313..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/snippet_file.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Code to provide access to UltiSnips files from disk.""" - -import glob -import os - -from UltiSnips.providers._base import SnippetProvider -from UltiSnips.providers.ultisnips_file import parse_snippets_file -from UltiSnips.snippet_definition import SnippetDefinition -import UltiSnips._vim as _vim - -def _plugin_dir(): - """Calculates the plugin directory for UltiSnips.""" - directory = __file__ - for _ in range(10): - directory = os.path.dirname(directory) - if (os.path.isdir(os.path.join(directory, "plugin")) and - os.path.isdir(os.path.join(directory, "doc"))): - return directory - raise Exception("Unable to find the plugin directory.") - -def base_snippet_files_for(ft, default=True): - """Returns a list of snippet files matching the given filetype (ft). - If default is set to false, it doesn't include shipped files. - - Searches through each path in 'runtimepath' in reverse order, - in each of these, it searches each directory name listed in - 'g:UltiSnipsSnippetDirectories' in order, then looks for files in these - directories called 'ft.snippets' or '*_ft.snippets' replacing ft with - the filetype. - """ - if _vim.eval("exists('b:UltiSnipsSnippetDirectories')") == "1": - snippet_dirs = _vim.eval("b:UltiSnipsSnippetDirectories") - else: - snippet_dirs = _vim.eval("g:UltiSnipsSnippetDirectories") - - paths = _vim.eval("&runtimepath").split(',') - base_snippets = os.path.realpath(os.path.join(_plugin_dir(), "UltiSnips")) - ret = [] - for rtp in paths: - for snippet_dir in snippet_dirs: - pth = os.path.realpath(os.path.expanduser( - os.path.join(rtp, snippet_dir))) - patterns = ["%s.snippets", "%s_*.snippets", os.path.join("%s", "*")] - if not default and pth == base_snippets: - patterns.remove("%s.snippets") - - for pattern in patterns: - for fn in glob.glob(os.path.join(pth, pattern % ft)): - if fn not in ret: - ret.append(fn) - return ret - -class SnippetSyntaxError(RuntimeError): - """Thrown when a syntax error is found in a file.""" - def __init__(self, filename, line_index, msg): - RuntimeError.__init__(self, "%s in %s:%d" % ( - msg, filename, line_index)) - -class UltiSnipsFileProvider(SnippetProvider): - """Manages all snippets definitions found in rtp.""" - - def get_snippets(self, filetypes, before, possible): - for ft in filetypes: - self._ensure_loaded(ft) - - return SnippetProvider.get_snippets(self, filetypes, before, possible) - - def _ensure_loaded(self, ft, already_loaded=None): - """Make sure that the snippets for 'ft' and everything it extends are - loaded.""" - if not already_loaded: - already_loaded = set() - - if ft in already_loaded: - return - already_loaded.add(ft) - - if self._needs_update(ft): - self._load_snippets_for(ft) - - for parent in self._snippets[ft].extends: - self._ensure_loaded(parent, already_loaded) - - def _needs_update(self, ft): - """Returns true if any files for 'ft' have changed and must be - reloaded.""" - if ft not in self._snippets: - return True - elif self._snippets[ft].has_any_file_changed(): - return True - else: - cur_snips = set(base_snippet_files_for(ft)) - old_snips = set(self._snippets[ft].files) - if cur_snips - old_snips: - return True - return False - - def _load_snippets_for(self, ft): - """Load all snippets for the given 'ft'.""" - if ft in self._snippets: - del self._snippets[ft] - for fn in base_snippet_files_for(ft): - self._parse_snippets(ft, fn) - # Now load for the parents - for parent_ft in self._snippets[ft].extends: - if parent_ft not in self._snippets: - self._load_snippets_for(parent_ft) - - def _parse_snippets(self, ft, filename): - """Parse the file 'filename' for the given 'ft' and watch it for - changes in the future. 'file_data' can be injected in tests.""" - current_snippet_priority = 0 - self._snippets[ft].addfile(filename) - file_data = open(filename, "r").read() - for event, data in parse_snippets_file(file_data): - if event == "error": - msg, line_index = data - filename = _vim.eval("""fnamemodify(%s, ":~:.")""" % - _vim.escape(filename)) - raise SnippetSyntaxError(filename, line_index, msg) - elif event == "clearsnippets": - # TODO(sirver): clear snippets should clear for - # more providers, not only ultisnips files. - triggers, = data - self._snippets[ft].clear_snippets(triggers) - elif event == "extends": - # TODO(sirver): extends information is more global - # than one snippet provider. - filetypes, = data - self._add_extending_info(ft, filetypes) - elif event == "snippet": - trigger, value, description, options, global_pythons = data - self._snippets[ft].add_snippet( - SnippetDefinition(current_snippet_priority, trigger, value, - description, options, global_pythons), filename - ) - elif event == "priority": - priority, = data - current_snippet_priority = priority - else: - assert False, "Unhandled %s: %r" % (event, data) - - def _add_extending_info(self, ft, parents): - """Add the list of 'parents' as being extended by the 'ft'.""" - sd = self._snippets[ft] - for parent in parents: - if parent in sd.extends: - continue - sd.extends.append(parent) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/ultisnips_file.py b/vim/bundle/ultisnips/pythonx/UltiSnips/providers/ultisnips_file.py deleted file mode 100644 index c8a4b48..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/ultisnips_file.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Parsing of snippet files.""" - -from collections import defaultdict - -class _LineIterator(object): - """Convenience class that keeps track of line numbers.""" - - def __init__(self, text): - self._line_index = None - self._lines = enumerate(text.splitlines(True), 1) - - def __iter__(self): - return self - - def __next__(self): - """Returns the next line.""" - self._line_index, line = next(self._lines) - return line - next = __next__ # for python2 - - @property - def line_index(self): - """The 1 based line index in the current file.""" - return self._line_index - -def _handle_snippet_or_global(line, lines, globals): - """Parses the snippet that begins at the current line.""" - - descr = "" - opts = "" - - # Ensure this is a snippet - snip = line.split()[0] - - # Get and strip options if they exist - remain = line[len(snip):].strip() - words = remain.split() - if len(words) > 2: - # second to last word ends with a quote - if '"' not in words[-1] and words[-2][-1] == '"': - opts = words[-1] - remain = remain[:-len(opts) - 1].rstrip() - - # Get and strip description if it exists - remain = remain.strip() - if len(remain.split()) > 1 and remain[-1] == '"': - left = remain[:-1].rfind('"') - if left != -1 and left != 0: - descr, remain = remain[left:], remain[:left] - - # The rest is the trigger - trig = remain.strip() - if len(trig.split()) > 1 or "r" in opts: - if trig[0] != trig[-1]: - return "error", ("Invalid multiword trigger: '%s'" % trig, - lines.line_index) - trig = trig[1:-1] - end = "end" + snip - content = "" - - found_end = False - for line in lines: - if line.rstrip() == end: - content = content[:-1] # Chomp the last newline - found_end = True - break - content += line - - if not found_end: - return "error", ("Missing 'endsnippet' for %r" % trig, lines.line_index) - - if snip == "global": - globals[trig].append(content) - elif snip == "snippet": - return "snippet", (trig, content, descr, opts, globals) - else: - return "error", ("Invalid snippet type: '%s'" % snip, lines.line_index) - -def _head_tail(line): - """Returns the first word in 'line' and the rest of 'line' or None if the - line is too short.""" - generator = (t.strip() for t in line.split(None, 1)) - head = next(generator).strip() - tail = '' - try: - tail = next(generator).strip() - except StopIteration: - pass - return head, tail - - -def parse_snippets_file(data): - """Parse 'data' assuming it is a snippet file. Yields events in the - file.""" - - globals = defaultdict(list) - lines = _LineIterator(data) - for line in lines: - if not line.strip(): - continue - - head, tail = _head_tail(line) - if head == "extends": - if tail: - yield "extends", ([p.strip() for p in tail.split(',')],) - else: - yield "error", ("'extends' without file types", - lines.line_index) - elif head in ("snippet", "global"): - snippet = _handle_snippet_or_global(line, lines, globals) - if snippet is not None: - yield snippet - elif head == "clearsnippets": - yield "clearsnippets", (tail.split(),) - elif head == "priority": - try: - priority = int(tail.split()[0]) - yield "priority", (priority,) - except (ValueError, IndexError): - yield "error", ("Invalid priority %r" % tail, lines.line_index) - elif head and not head.startswith('#'): - yield "error", ("Invalid line %r" % line.rstrip(), lines.line_index) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/__init__.py new file mode 100644 index 0000000..0128940 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/__init__.py @@ -0,0 +1 @@ +"""Code related to snippets.""" diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/__init__.py new file mode 100644 index 0000000..fb08801 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/__init__.py @@ -0,0 +1,4 @@ +"""In memory representation of snippet definitions.""" + +from UltiSnips.snippet.definition.ultisnips import UltiSnipsSnippetDefinition +from UltiSnips.snippet.definition.snipmate import SnipMateSnippetDefinition diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/_base.py new file mode 100644 index 0000000..6d7b13f --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/_base.py @@ -0,0 +1,433 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Snippet representation after parsing.""" + +import re + +import vim +import textwrap + +from UltiSnips import _vim +from UltiSnips.compatibility import as_unicode +from UltiSnips.indent_util import IndentUtil +from UltiSnips.position import Position +from UltiSnips.text import escape +from UltiSnips.text_objects import SnippetInstance +from UltiSnips.text_objects._python_code import SnippetUtilCursor, SnippetUtilForAction + +__WHITESPACE_SPLIT = re.compile(r"\s") +def split_at_whitespace(string): + """Like string.split(), but keeps empty words as empty words.""" + return re.split(__WHITESPACE_SPLIT, string) + +def _words_for_line(trigger, before, num_words=None): + """Gets the final 'num_words' words from 'before'. + + If num_words is None, then use the number of words in 'trigger'. + + """ + if num_words is None: + num_words = len(split_at_whitespace(trigger)) + + word_list = split_at_whitespace(before) + if len(word_list) <= num_words: + return before.strip() + else: + before_words = before + for i in range(-1, -(num_words + 1), -1): + left = before_words.rfind(word_list[i]) + before_words = before_words[:left] + return before[len(before_words):].strip() + + +class SnippetDefinition(object): + + """Represents a snippet as parsed from a file.""" + + _INDENT = re.compile(r"^[ \t]*") + _TABS = re.compile(r"^\t*") + + def __init__(self, priority, trigger, value, description, + options, globals, location, context, actions): + self._priority = int(priority) + self._trigger = as_unicode(trigger) + self._value = as_unicode(value) + self._description = as_unicode(description) + self._opts = options + self._matched = '' + self._last_re = None + self._globals = globals + self._location = location + self._context_code = context + self._context = None + self._actions = actions + + # Make sure that we actually match our trigger in case we are + # immediately expanded. + self.matches(self._trigger) + + def __repr__(self): + return '_SnippetDefinition(%r,%s,%s,%s)' % ( + self._priority, self._trigger, self._description, self._opts) + + def _re_match(self, trigger): + """Test if a the current regex trigger matches `trigger`. + + If so, set _last_re and _matched. + + """ + for match in re.finditer(self._trigger, trigger): + if match.end() != len(trigger): + continue + else: + self._matched = trigger[match.start():match.end()] + + self._last_re = match + return match + return False + + def _context_match(self, visual_content): + # skip on empty buffer + if len(vim.current.buffer) == 1 and vim.current.buffer[0] == "": + return + + locals = { + 'context': None, + 'visual_mode': '', + 'visual_text': '', + 'last_placeholder': None + } + + if visual_content: + locals['visual_mode'] = visual_content.mode + locals['visual_text'] = visual_content.text + locals['last_placeholder'] = visual_content.placeholder + + return self._eval_code('snip.context = ' + self._context_code, + locals).context + + def _eval_code(self, code, additional_locals={}): + code = "\n".join([ + 'import re, os, vim, string, random', + '\n'.join(self._globals.get('!p', [])).replace('\r\n', '\n'), + code + ]) + + current = vim.current + + locals = { + 'window': current.window, + 'buffer': current.buffer, + 'line': current.window.cursor[0]-1, + 'column': current.window.cursor[1]-1, + 'cursor': SnippetUtilCursor(current.window.cursor), + } + + locals.update(additional_locals) + + snip = SnippetUtilForAction(locals) + + try: + exec(code, {'snip': snip}) + except Exception as e: + e.snippet_info = textwrap.dedent(""" + Defined in: {} + Trigger: {} + Description: {} + Context: {} + Pre-expand: {} + Post-expand: {} + """).format( + self._location, + self._trigger, + self._description, + self._context_code if self._context_code else '', + self._actions['pre_expand'] if 'pre_expand' in self._actions + else '', + self._actions['post_expand'] if 'post_expand' in self._actions + else '', + code, + ) + + e.snippet_code = code + + raise + + return snip + + def _execute_action( + self, + action, + context, + additional_locals={} + ): + mark_to_use = '`' + with _vim.save_mark(mark_to_use): + _vim.set_mark_from_pos(mark_to_use, _vim.get_cursor_pos()) + + cursor_line_before = _vim.buf.line_till_cursor + + locals = { + 'context': context, + } + + locals.update(additional_locals) + + snip = self._eval_code(action, locals) + + if snip.cursor.is_set(): + vim.current.window.cursor = snip.cursor.to_vim_cursor() + else: + new_mark_pos = _vim.get_mark_pos(mark_to_use) + + cursor_invalid = False + + if _vim._is_pos_zero(new_mark_pos): + cursor_invalid = True + else: + _vim.set_cursor_from_pos(new_mark_pos) + if cursor_line_before != _vim.buf.line_till_cursor: + cursor_invalid = True + + if cursor_invalid: + raise RuntimeError( + 'line under the cursor was modified, but ' + + '"snip.cursor" variable is not set; either set set ' + + '"snip.cursor" to new cursor position, or do not ' + + 'modify cursor line' + ) + + return snip + + def has_option(self, opt): + """Check if the named option is set.""" + return opt in self._opts + + @property + def description(self): + """Descriptive text for this snippet.""" + return ('(%s) %s' % (self._trigger, self._description)).strip() + + @property + def priority(self): + """The snippets priority, which defines which snippet will be preferred + over others with the same trigger.""" + return self._priority + + @property + def trigger(self): + """The trigger text for the snippet.""" + return self._trigger + + @property + def matched(self): + """The last text that matched this snippet in match() or + could_match().""" + return self._matched + + @property + def location(self): + """Where this snippet was defined.""" + return self._location + + @property + def context(self): + """The matched context.""" + return self._context + + def matches(self, before, visual_content=None): + """Returns True if this snippet matches 'before'.""" + # If user supplies both "w" and "i", it should perhaps be an + # error, but if permitted it seems that "w" should take precedence + # (since matching at word boundary and within a word == matching at word + # boundary). + self._matched = '' + + words = _words_for_line(self._trigger, before) + + if 'r' in self._opts: + match = self._re_match(before) + elif 'w' in self._opts: + words_len = len(self._trigger) + words_prefix = words[:-words_len] + words_suffix = words[-words_len:] + match = (words_suffix == self._trigger) + if match and words_prefix: + # Require a word boundary between prefix and suffix. + boundary_chars = escape(words_prefix[-1:] + + words_suffix[:1], r'\"') + match = _vim.eval( + '"%s" =~# "\\\\v.<."' % + boundary_chars) != '0' + elif 'i' in self._opts: + match = words.endswith(self._trigger) + else: + match = (words == self._trigger) + + # By default, we match the whole trigger + if match and not self._matched: + self._matched = self._trigger + + # Ensure the match was on a word boundry if needed + if 'b' in self._opts and match: + text_before = before.rstrip()[:-len(self._matched)] + if text_before.strip(' \t') != '': + self._matched = '' + return False + + self._context = None + if match and self._context_code: + self._context = self._context_match(visual_content) + if not self.context: + match = False + + return match + + def could_match(self, before): + """Return True if this snippet could match the (partial) 'before'.""" + self._matched = '' + + # List all on whitespace. + if before and before[-1] in (' ', '\t'): + before = '' + if before and before.rstrip() is not before: + return False + + words = _words_for_line(self._trigger, before) + + if 'r' in self._opts: + # Test for full match only + match = self._re_match(before) + elif 'w' in self._opts: + # Trim non-empty prefix up to word boundary, if present. + qwords = escape(words, r'\"') + words_suffix = _vim.eval( + 'substitute("%s", "\\\\v^.+<(.+)", "\\\\1", "")' % qwords) + match = self._trigger.startswith(words_suffix) + self._matched = words_suffix + + # TODO: list_snippets() function cannot handle partial-trigger + # matches yet, so for now fail if we trimmed the prefix. + if words_suffix != words: + match = False + elif 'i' in self._opts: + # TODO: It is hard to define when a inword snippet could match, + # therefore we check only for full-word trigger. + match = self._trigger.startswith(words) + else: + match = self._trigger.startswith(words) + + # By default, we match the words from the trigger + if match and not self._matched: + self._matched = words + + # Ensure the match was on a word boundry if needed + if 'b' in self._opts and match: + text_before = before.rstrip()[:-len(self._matched)] + if text_before.strip(' \t') != '': + self._matched = '' + return False + + return match + + def instantiate(self, snippet_instance, initial_text, indent): + """Parses the content of this snippet and brings the corresponding text + objects alive inside of Vim.""" + raise NotImplementedError() + + def do_pre_expand(self, visual_content, snippets_stack): + if 'pre_expand' in self._actions: + locals = {'buffer': _vim.buf, 'visual_content': visual_content} + + snip = self._execute_action( + self._actions['pre_expand'], self._context, locals + ) + + self._context = snip.context + + return snip.cursor.is_set() + else: + return False + + def do_post_expand(self, start, end, snippets_stack): + if 'post_expand' in self._actions: + locals = { + 'snippet_start': start, + 'snippet_end': end, + 'buffer': _vim.buf + } + + snip = self._execute_action( + self._actions['post_expand'], snippets_stack[-1].context, locals + ) + + snippets_stack[-1].context = snip.context + + return snip.cursor.is_set() + else: + return False + + def do_post_jump( + self, tabstop_number, jump_direction, snippets_stack, current_snippet + ): + if 'post_jump' in self._actions: + start = current_snippet.start + end = current_snippet.end + + locals = { + 'tabstop': tabstop_number, + 'jump_direction': jump_direction, + 'tabstops': current_snippet.get_tabstops(), + 'snippet_start': start, + 'snippet_end': end, + 'buffer': _vim.buf + } + + snip = self._execute_action( + self._actions['post_jump'], current_snippet.context, locals + ) + + current_snippet.context = snip.context + + return snip.cursor.is_set() + else: + return False + + + def launch(self, text_before, visual_content, parent, start, end): + """Launch this snippet, overwriting the text 'start' to 'end' and + keeping the 'text_before' on the launch line. + + 'Parent' is the parent snippet instance if any. + + """ + indent = self._INDENT.match(text_before).group(0) + lines = (self._value + '\n').splitlines() + ind_util = IndentUtil() + + # Replace leading tabs in the snippet definition via proper indenting + initial_text = [] + for line_num, line in enumerate(lines): + if 't' in self._opts: + tabs = 0 + else: + tabs = len(self._TABS.match(line).group(0)) + line_ind = ind_util.ntabs_to_proper_indent(tabs) + if line_num != 0: + line_ind = indent + line_ind + + result_line = line_ind + line[tabs:] + if 'm' in self._opts: + result_line = result_line.rstrip() + initial_text.append(result_line) + initial_text = '\n'.join(initial_text) + + snippet_instance = SnippetInstance( + self, parent, initial_text, start, end, visual_content, + last_re=self._last_re, globals=self._globals, + context=self._context) + self.instantiate(snippet_instance, initial_text, indent) + + snippet_instance.update_textobjects() + return snippet_instance diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/snipmate.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/snipmate.py new file mode 100644 index 0000000..8ab1e2a --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/snipmate.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""A snipMate snippet after parsing.""" + +from UltiSnips.snippet.definition._base import SnippetDefinition +from UltiSnips.snippet.parsing.snipmate import parse_and_instantiate + + +class SnipMateSnippetDefinition(SnippetDefinition): + + """See module doc.""" + + SNIPMATE_SNIPPET_PRIORITY = -1000 + + def __init__(self, trigger, value, description, location): + SnippetDefinition.__init__(self, self.SNIPMATE_SNIPPET_PRIORITY, + trigger, value, description, '', {}, location, + None, {}) + + def instantiate(self, snippet_instance, initial_text, indent): + parse_and_instantiate(snippet_instance, initial_text, indent) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/ultisnips.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/ultisnips.py new file mode 100644 index 0000000..5338a6a --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/definition/ultisnips.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""A UltiSnips snippet after parsing.""" + +from UltiSnips.snippet.definition._base import SnippetDefinition +from UltiSnips.snippet.parsing.ultisnips import parse_and_instantiate + + +class UltiSnipsSnippetDefinition(SnippetDefinition): + + """See module doc.""" + + def instantiate(self, snippet_instance, initial_text, indent): + return parse_and_instantiate(snippet_instance, initial_text, indent) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/__init__.py new file mode 100644 index 0000000..ea46beb --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/__init__.py @@ -0,0 +1 @@ +"""Code related to turning text into snippets.""" diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_base.py new file mode 100644 index 0000000..8c7f342 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_base.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Common functionality of the snippet parsing codes.""" + +from UltiSnips.position import Position +from UltiSnips.snippet.parsing._lexer import tokenize, TabStopToken +from UltiSnips.text_objects import TabStop + +from UltiSnips.text_objects import Mirror +from UltiSnips.snippet.parsing._lexer import MirrorToken + + +def resolve_ambiguity(all_tokens, seen_ts): + """$1 could be a Mirror or a TabStop. + + This figures this out. + + """ + for parent, token in all_tokens: + if isinstance(token, MirrorToken): + if token.number not in seen_ts: + seen_ts[token.number] = TabStop(parent, token) + else: + Mirror(parent, seen_ts[token.number], token) + + +def tokenize_snippet_text(snippet_instance, text, indent, + allowed_tokens_in_text, allowed_tokens_in_tabstops, + token_to_textobject): + """Turns 'text' into a stream of tokens and creates the text objects from + those tokens that are mentioned in 'token_to_textobject' assuming the + current 'indent'. + + The 'allowed_tokens_in_text' define which tokens will be recognized + in 'text' while 'allowed_tokens_in_tabstops' are the tokens that + will be recognized in TabStop placeholder text. + + """ + seen_ts = {} + all_tokens = [] + + def _do_parse(parent, text, allowed_tokens): + """Recursive function that actually creates the objects.""" + tokens = list(tokenize(text, indent, parent.start, allowed_tokens)) + for token in tokens: + all_tokens.append((parent, token)) + if isinstance(token, TabStopToken): + ts = TabStop(parent, token) + seen_ts[token.number] = ts + _do_parse(ts, token.initial_text, + allowed_tokens_in_tabstops) + else: + klass = token_to_textobject.get(token.__class__, None) + if klass is not None: + klass(parent, token) + _do_parse(snippet_instance, text, allowed_tokens_in_text) + return all_tokens, seen_ts + + +def finalize(all_tokens, seen_ts, snippet_instance): + """Adds a tabstop 0 if non is in 'seen_ts' and brings the text of the + snippet instance into Vim.""" + if 0 not in seen_ts: + mark = all_tokens[-1][1].end # Last token is always EndOfText + m1 = Position(mark.line, mark.col) + TabStop(snippet_instance, 0, mark, m1) + snippet_instance.replace_initial_text() diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_lexer.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_lexer.py similarity index 84% rename from vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_lexer.py rename to vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_lexer.py index 3703726..60859fe 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_lexer.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/_lexer.py @@ -1,19 +1,19 @@ #!/usr/bin/env python # encoding: utf-8 -""" -Not really a lexer in the classical sense, but code to convert snippet -definitions into logical units called Tokens. -""" +"""Not really a lexer in the classical sense, but code to convert snippet +definitions into logical units called Tokens.""" import string import re from UltiSnips.compatibility import as_unicode from UltiSnips.position import Position -from UltiSnips.escaping import unescape +from UltiSnips.text import unescape + class _TextIterator(object): + """Helper class to make iterating over text easier.""" def __init__(self, text, offset): @@ -44,7 +44,7 @@ class _TextIterator(object): def peek(self, count=1): """Returns the next 'count' characters without advancing the stream.""" - if count > 1: # This might return '' if nothing is found + if count > 1: # This might return '' if nothing is found return self._text[self._idx:self._idx + count] try: return self._text[self._idx] @@ -56,17 +56,17 @@ class _TextIterator(object): """Current position in the text.""" return Position(self._line, self._col) + def _parse_number(stream): - """ - Expects the stream to contain a number next, returns the number - without consuming any more bytes - """ - rv = "" + """Expects the stream to contain a number next, returns the number without + consuming any more bytes.""" + rv = '' while stream.peek() and stream.peek() in string.digits: rv += next(stream) return int(rv) + def _parse_till_closing_brace(stream): """ Returns all chars till a non-escaped } is found. Other @@ -74,7 +74,7 @@ def _parse_till_closing_brace(stream): Will also consume the closing }, but not return it """ - rv = "" + rv = '' in_braces = 1 while True: if EscapeCharToken.starts_here(stream, '{}'): @@ -90,6 +90,7 @@ def _parse_till_closing_brace(stream): rv += char return rv + def _parse_till_unescaped_char(stream, chars): """ Returns all chars till a non-escaped char is found. @@ -97,7 +98,7 @@ def _parse_till_unescaped_char(stream, chars): Will also consume the closing char, but and return it as second return value """ - rv = "" + rv = '' while True: escaped = False for char in chars: @@ -111,20 +112,24 @@ def _parse_till_unescaped_char(stream, chars): rv += char return rv, char + class Token(object): + """Represents a Token as parsed from a snippet definition.""" def __init__(self, gen, indent): - self.initial_text = as_unicode("") + self.initial_text = as_unicode('') self.start = gen.pos self._parse(gen, indent) self.end = gen.pos def _parse(self, stream, indent): """Parses the token from 'stream' with the current 'indent'.""" - pass # Does nothing + pass # Does nothing + class TabStopToken(Token): + """${1:blub}""" CHECK = re.compile(r'^\${\d+[:}]') @@ -135,21 +140,23 @@ class TabStopToken(Token): return cls.CHECK.match(stream.peek(10)) is not None def _parse(self, stream, indent): - next(stream) # $ - next(stream) # { + next(stream) # $ + next(stream) # { self.number = _parse_number(stream) - if stream.peek() == ":": + if stream.peek() == ':': next(stream) self.initial_text = _parse_till_closing_brace(stream) def __repr__(self): - return "TabStopToken(%r,%r,%r,%r)" % ( + return 'TabStopToken(%r,%r,%r,%r)' % ( self.start, self.end, self.number, self.initial_text ) + class VisualToken(Token): + """${VISUAL}""" CHECK = re.compile(r"^\${VISUAL[:}/]") @@ -160,15 +167,15 @@ class VisualToken(Token): return cls.CHECK.match(stream.peek(10)) is not None def _parse(self, stream, indent): - for _ in range(8): # ${VISUAL + for _ in range(8): # ${VISUAL next(stream) - if stream.peek() == ":": + if stream.peek() == ':': next(stream) self.alternative_text, char = _parse_till_unescaped_char(stream, '/}') self.alternative_text = unescape(self.alternative_text) - if char == '/': # Transformation going on + if char == '/': # Transformation going on try: self.search = _parse_till_unescaped_char(stream, '/')[0] self.replace = _parse_till_unescaped_char(stream, '/')[0] @@ -182,11 +189,13 @@ class VisualToken(Token): self.options = None def __repr__(self): - return "VisualToken(%r,%r)" % ( + return 'VisualToken(%r,%r)' % ( self.start, self.end ) + class TransformationToken(Token): + """${1/match/replace/options}""" CHECK = re.compile(r'^\${\d+\/') @@ -198,24 +207,26 @@ class TransformationToken(Token): return cls.CHECK.match(stream.peek(10)) is not None def _parse(self, stream, indent): - next(stream) # $ - next(stream) # { + next(stream) # $ + next(stream) # { self.number = _parse_number(stream) - next(stream) # / + next(stream) # / self.search = _parse_till_unescaped_char(stream, '/')[0] self.replace = _parse_till_unescaped_char(stream, '/')[0] self.options = _parse_till_closing_brace(stream) def __repr__(self): - return "TransformationToken(%r,%r,%r,%r,%r)" % ( + return 'TransformationToken(%r,%r,%r,%r,%r)' % ( self.start, self.end, self.number, self.search, self.replace ) + class MirrorToken(Token): - """$1""" + + """$1.""" CHECK = re.compile(r'^\$\d+') @classmethod @@ -225,16 +236,18 @@ class MirrorToken(Token): return cls.CHECK.match(stream.peek(10)) is not None def _parse(self, stream, indent): - next(stream) # $ + next(stream) # $ self.number = _parse_number(stream) def __repr__(self): - return "MirrorToken(%r,%r,%r)" % ( + return 'MirrorToken(%r,%r,%r)' % ( self.start, self.end, self.number ) + class EscapeCharToken(Token): - """\\n""" + + """\\n.""" @classmethod def starts_here(cls, stream, chars=r'{}\$`'): """Returns true if this token starts at the current position in @@ -244,16 +257,18 @@ class EscapeCharToken(Token): return True def _parse(self, stream, indent): - next(stream) # \ + next(stream) # \ self.initial_text = next(stream) def __repr__(self): - return "EscapeCharToken(%r,%r,%r)" % ( + return 'EscapeCharToken(%r,%r,%r)' % ( self.start, self.end, self.initial_text ) + class ShellCodeToken(Token): - """`! echo "hi"`""" + + """`echo "hi"`""" @classmethod def starts_here(cls, stream): """Returns true if this token starts at the current position in @@ -261,15 +276,17 @@ class ShellCodeToken(Token): return stream.peek(1) == '`' def _parse(self, stream, indent): - next(stream) # ` + next(stream) # ` self.code = _parse_till_unescaped_char(stream, '`')[0] def __repr__(self): - return "ShellCodeToken(%r,%r,%r)" % ( + return 'ShellCodeToken(%r,%r,%r)' % ( self.start, self.end, self.code ) + class PythonCodeToken(Token): + """`!p snip.rv = "Hi"`""" CHECK = re.compile(r'^`!p\s') @@ -281,7 +298,7 @@ class PythonCodeToken(Token): def _parse(self, stream, indent): for _ in range(3): - next(stream) # `!p + next(stream) # `!p if stream.peek() in '\t ': next(stream) @@ -292,17 +309,19 @@ class PythonCodeToken(Token): lines = code.splitlines() self.code = lines[0] + '\n' self.code += '\n'.join([l[len(indent):] - for l in lines[1:]]) + for l in lines[1:]]) else: self.code = code self.indent = indent def __repr__(self): - return "PythonCodeToken(%r,%r,%r)" % ( + return 'PythonCodeToken(%r,%r,%r)' % ( self.start, self.end, self.code ) + class VimLCodeToken(Token): + """`!v g:hi`""" CHECK = re.compile(r'^`!v\s') @@ -314,31 +333,32 @@ class VimLCodeToken(Token): def _parse(self, stream, indent): for _ in range(4): - next(stream) # `!v + next(stream) # `!v self.code = _parse_till_unescaped_char(stream, '`')[0] def __repr__(self): - return "VimLCodeToken(%r,%r,%r)" % ( + return 'VimLCodeToken(%r,%r,%r)' % ( self.start, self.end, self.code ) + class EndOfTextToken(Token): + """Appears at the end of the text.""" + def __repr__(self): - return "EndOfText(%r)" % self.end + return 'EndOfText(%r)' % self.end + -__ALLOWED_TOKENS = [ - EscapeCharToken, VisualToken, TransformationToken, TabStopToken, - MirrorToken, PythonCodeToken, VimLCodeToken, ShellCodeToken -] -def tokenize(text, indent, offset): +def tokenize(text, indent, offset, allowed_tokens): """Returns an iterator of tokens of 'text'['offset':] which is assumed to - have 'indent' as the whitespace of the begging of the lines.""" + have 'indent' as the whitespace of the begging of the lines. Only + 'allowed_tokens' are considered to be valid tokens.""" stream = _TextIterator(text, offset) try: while True: done_something = False - for token in __ALLOWED_TOKENS: + for token in allowed_tokens: if token.starts_here(stream): yield token(stream, indent) done_something = True diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/snipmate.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/snipmate.py new file mode 100644 index 0000000..8aaed53 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/snipmate.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Parses a snipMate snippet definition and launches it into Vim.""" + +from UltiSnips.snippet.parsing._base import tokenize_snippet_text, finalize, resolve_ambiguity +from UltiSnips.snippet.parsing._lexer import EscapeCharToken, \ + VisualToken, TabStopToken, MirrorToken, ShellCodeToken +from UltiSnips.text_objects import EscapedChar, Mirror, VimLCode, Visual + +_TOKEN_TO_TEXTOBJECT = { + EscapeCharToken: EscapedChar, + VisualToken: Visual, + ShellCodeToken: VimLCode, # `` is VimL in snipMate +} + +__ALLOWED_TOKENS = [ + EscapeCharToken, VisualToken, TabStopToken, MirrorToken, ShellCodeToken +] + +__ALLOWED_TOKENS_IN_TABSTOPS = [ + EscapeCharToken, VisualToken, MirrorToken, ShellCodeToken +] + + +def parse_and_instantiate(parent_to, text, indent): + """Parses a snippet definition in snipMate format from 'text' assuming the + current 'indent'. + + Will instantiate all the objects and link them as children to + parent_to. Will also put the initial text into Vim. + + """ + all_tokens, seen_ts = tokenize_snippet_text(parent_to, text, indent, + __ALLOWED_TOKENS, __ALLOWED_TOKENS_IN_TABSTOPS, + _TOKEN_TO_TEXTOBJECT) + resolve_ambiguity(all_tokens, seen_ts) + finalize(all_tokens, seen_ts, parent_to) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/ultisnips.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/ultisnips.py new file mode 100644 index 0000000..9bb6068 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/parsing/ultisnips.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Parses a UltiSnips snippet definition and launches it into Vim.""" + +from UltiSnips.snippet.parsing._base import tokenize_snippet_text, finalize, resolve_ambiguity +from UltiSnips.snippet.parsing._lexer import EscapeCharToken, \ + VisualToken, TransformationToken, TabStopToken, MirrorToken, \ + PythonCodeToken, VimLCodeToken, ShellCodeToken +from UltiSnips.text_objects import EscapedChar, Mirror, PythonCode, \ + ShellCode, TabStop, Transformation, VimLCode, Visual + +_TOKEN_TO_TEXTOBJECT = { + EscapeCharToken: EscapedChar, + VisualToken: Visual, + ShellCodeToken: ShellCode, + PythonCodeToken: PythonCode, + VimLCodeToken: VimLCode, +} + +__ALLOWED_TOKENS = [ + EscapeCharToken, VisualToken, TransformationToken, TabStopToken, + MirrorToken, PythonCodeToken, VimLCodeToken, ShellCodeToken +] + + +def _create_transformations(all_tokens, seen_ts): + """Create the objects that need to know about tabstops.""" + for parent, token in all_tokens: + if isinstance(token, TransformationToken): + if token.number not in seen_ts: + raise RuntimeError( + 'Tabstop %i is not known but is used by a Transformation' + % token.number) + Transformation(parent, seen_ts[token.number], token) + + +def parse_and_instantiate(parent_to, text, indent): + """Parses a snippet definition in UltiSnips format from 'text' assuming the + current 'indent'. + + Will instantiate all the objects and link them as children to + parent_to. Will also put the initial text into Vim. + + """ + all_tokens, seen_ts = tokenize_snippet_text(parent_to, text, indent, + __ALLOWED_TOKENS, __ALLOWED_TOKENS, _TOKEN_TO_TEXTOBJECT) + resolve_ambiguity(all_tokens, seen_ts) + _create_transformations(all_tokens, seen_ts) + finalize(all_tokens, seen_ts, parent_to) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/__init__.py new file mode 100644 index 0000000..08c20ac --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/__init__.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Sources of snippet definitions.""" + +from UltiSnips.snippet.source._base import SnippetSource +from UltiSnips.snippet.source.added import AddedSnippetsSource +from UltiSnips.snippet.source.file.snipmate import SnipMateFileSource +from UltiSnips.snippet.source.file.ultisnips import UltiSnipsFileSource, \ + find_all_snippet_files, find_snippet_files diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_base.py new file mode 100644 index 0000000..93ba5b0 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_base.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Base class for snippet sources.""" + +from collections import defaultdict + +from UltiSnips.snippet.source._snippet_dictionary import SnippetDictionary + + +class SnippetSource(object): + + """See module docstring.""" + + def __init__(self): + self._snippets = defaultdict(SnippetDictionary) + self._extends = defaultdict(set) + + def ensure(self, filetypes, cached): + """Update/reload the snippets in the source when needed. + + It makes sure that the snippets are not outdated. + + """ + + def loaded(self, filetypes): + return len(self._snippets) > 0 + + def _get_existing_deep_extends(self, base_filetypes): + """Helper for get all existing filetypes extended by base filetypes.""" + deep_extends = self.get_deep_extends(base_filetypes) + return [ft for ft in deep_extends if ft in self._snippets] + + def get_snippets(self, filetypes, before, possible, autotrigger_only, + visual_content): + """Returns the snippets for all 'filetypes' (in order) and their + parents matching the text 'before'. If 'possible' is true, a partial + match is enough. Base classes can override this method to provide means + of creating snippets on the fly. + + Returns a list of SnippetDefinition s. + + """ + result = [] + for ft in self._get_existing_deep_extends(filetypes): + snips = self._snippets[ft] + result.extend(snips.get_matching_snippets(before, possible, + autotrigger_only, + visual_content)) + return result + + def get_clear_priority(self, filetypes): + """Get maximum clearsnippets priority without arguments for specified + filetypes, if any. + + It returns None if there are no clearsnippets. + + """ + pri = None + for ft in self._get_existing_deep_extends(filetypes): + snippets = self._snippets[ft] + if pri is None or snippets._clear_priority > pri: + pri = snippets._clear_priority + return pri + + def get_cleared(self, filetypes): + """Get a set of cleared snippets marked by clearsnippets with arguments + for specified filetypes.""" + cleared = {} + for ft in self._get_existing_deep_extends(filetypes): + snippets = self._snippets[ft] + for key, value in snippets._cleared.items(): + if key not in cleared or value > cleared[key]: + cleared[key] = value + return cleared + + def update_extends(self, child_ft, parent_fts): + """Update the extending relation by given child filetype and its parent + filetypes.""" + self._extends[child_ft].update(parent_fts) + + def get_deep_extends(self, base_filetypes): + """Get a list of filetypes that is either directed or indirected + extended by given base filetypes. + + Note that the returned list include the root filetype itself. + + """ + seen = set(base_filetypes) + todo_fts = list(set(base_filetypes)) + while todo_fts: + todo_ft = todo_fts.pop() + unseen_extends = set( + ft for ft in self._extends[todo_ft] if ft not in seen) + seen.update(unseen_extends) + todo_fts.extend(unseen_extends) + return seen diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_snippet_dictionary.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_snippet_dictionary.py new file mode 100644 index 0000000..d695902 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/_snippet_dictionary.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Implements a container for parsed snippets.""" + +class SnippetDictionary(object): + + """See module docstring.""" + + def __init__(self): + self._snippets = [] + self._cleared = {} + self._clear_priority = float("-inf") + + def add_snippet(self, snippet): + """Add 'snippet' to this dictionary.""" + self._snippets.append(snippet) + + def get_matching_snippets(self, trigger, potentially, autotrigger_only, + visual_content): + """Returns all snippets matching the given trigger. + + If 'potentially' is true, returns all that could_match(). + + If 'autotrigger_only' is true, function will return only snippets which + are marked with flag 'A' (should be automatically expanded without + trigger key press). + It's handled specially to avoid walking down the list of all snippets, + which can be very slow, because function will be called on each change + made in insert mode. + + """ + all_snippets = self._snippets + if autotrigger_only: + all_snippets = [s for s in all_snippets if s.has_option('A')] + + if not potentially: + return [s for s in all_snippets if s.matches(trigger, + visual_content)] + else: + return [s for s in all_snippets if s.could_match(trigger)] + + def clear_snippets(self, priority, triggers): + """Clear the snippets by mark them as cleared. + + If trigger is None, it updates the value of clear priority + instead. + + """ + if not triggers: + if self._clear_priority is None or priority > self._clear_priority: + self._clear_priority = priority + else: + for trigger in triggers: + if (trigger not in self._cleared or + priority > self._cleared[trigger]): + self._cleared[trigger] = priority + + def __len__(self): + return len(self._snippets) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/added_snippets_provider.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/added.py similarity index 60% rename from vim/bundle/ultisnips/pythonx/UltiSnips/providers/added_snippets_provider.py rename to vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/added.py index 068bd38..c410946 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/providers/added_snippets_provider.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/added.py @@ -3,11 +3,13 @@ """Handles manually added snippets UltiSnips_Manager.add_snippet().""" -from UltiSnips.providers._base import SnippetProvider +from UltiSnips.snippet.source._base import SnippetSource + + +class AddedSnippetsSource(SnippetSource): -class AddedSnippetsProvider(SnippetProvider): """See module docstring.""" def add_snippet(self, ft, snippet): """Adds the given 'snippet' for 'ft'.""" - self._snippets[ft].add_snippet(snippet, None) + self._snippets[ft].add_snippet(snippet) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/__init__.py new file mode 100644 index 0000000..6abf472 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/__init__.py @@ -0,0 +1 @@ +"""Snippet sources that are file based.""" diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_base.py new file mode 100644 index 0000000..daa3f1d --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_base.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Code to provide access to UltiSnips files from disk.""" + +from collections import defaultdict +import hashlib +import os + +from UltiSnips import _vim +from UltiSnips import compatibility +from UltiSnips.snippet.source._base import SnippetSource + + +def _hash_file(path): + """Returns a hashdigest of 'path'.""" + if not os.path.isfile(path): + return False + return hashlib.sha1(open(path, 'rb').read()).hexdigest() + + +class SnippetSyntaxError(RuntimeError): + + """Thrown when a syntax error is found in a file.""" + + def __init__(self, filename, line_index, msg): + RuntimeError.__init__(self, '%s in %s:%d' % ( + msg, filename, line_index)) + + +class SnippetFileSource(SnippetSource): + + """Base class that abstracts away 'extends' info and file hashes.""" + + def __init__(self): + SnippetSource.__init__(self) + self._files_for_ft = defaultdict(set) + self._file_hashes = defaultdict(lambda: None) + self._ensure_cached = False + + def ensure(self, filetypes, cached): + if cached and self._ensure_cached: + return + + for ft in self.get_deep_extends(filetypes): + if self._needs_update(ft): + self._load_snippets_for(ft) + + self._ensure_cached = True + + def _get_all_snippet_files_for(self, ft): + """Returns a set of all files that define snippets for 'ft'.""" + raise NotImplementedError() + + def _parse_snippet_file(self, filedata, filename): + """Parses 'filedata' as a snippet file and yields events.""" + raise NotImplementedError() + + def _needs_update(self, ft): + """Returns true if any files for 'ft' have changed and must be + reloaded.""" + existing_files = self._get_all_snippet_files_for(ft) + if existing_files != self._files_for_ft[ft]: + self._files_for_ft[ft] = existing_files + return True + + for filename in self._files_for_ft[ft]: + if _hash_file(filename) != self._file_hashes[filename]: + return True + + return False + + def _load_snippets_for(self, ft): + """Load all snippets for the given 'ft'.""" + if ft in self._snippets: + del self._snippets[ft] + del self._extends[ft] + try: + for fn in self._files_for_ft[ft]: + self._parse_snippets(ft, fn) + except: + del self._files_for_ft[ft] + raise + # Now load for the parents + for parent_ft in self.get_deep_extends([ft]): + if parent_ft != ft and self._needs_update(parent_ft): + self._load_snippets_for(parent_ft) + + def _parse_snippets(self, ft, filename): + """Parse the 'filename' for the given 'ft' and watch it for changes in + the future.""" + self._file_hashes[filename] = _hash_file(filename) + file_data = compatibility.open_ascii_file(filename, 'r').read() + for event, data in self._parse_snippet_file(file_data, filename): + if event == 'error': + msg, line_index = data + filename = _vim.eval("""fnamemodify(%s, ":~:.")""" % + _vim.escape(filename)) + raise SnippetSyntaxError(filename, line_index, msg) + elif event == 'clearsnippets': + priority, triggers = data + self._snippets[ft].clear_snippets(priority, triggers) + elif event == 'extends': + # TODO(sirver): extends information is more global + # than one snippet source. + filetypes, = data + self.update_extends(ft, filetypes) + elif event == 'snippet': + snippet, = data + self._snippets[ft].add_snippet(snippet) + else: + assert False, 'Unhandled %s: %r' % (event, data) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_common.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_common.py new file mode 100644 index 0000000..ec4be60 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/_common.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Common code for snipMate and UltiSnips snippet files.""" + + +def handle_extends(tail, line_index): + """Handles an extends line in a snippet.""" + if tail: + return 'extends', ([p.strip() for p in tail.split(',')],) + else: + return 'error', ("'extends' without file types", line_index) + + +def handle_action(head, tail, line_index): + if tail: + action = tail.strip('"').replace(r'\"', '"').replace(r'\\\\', r'\\') + return head, (action,) + else: + return 'error', ("'{}' without specified action".format(head), + line_index) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/snipmate.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/snipmate.py new file mode 100644 index 0000000..1791243 --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/snipmate.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Parses snipMate files.""" + +import os +import glob + +from UltiSnips import _vim +from UltiSnips.snippet.definition import SnipMateSnippetDefinition +from UltiSnips.snippet.source.file._base import SnippetFileSource +from UltiSnips.snippet.source.file._common import handle_extends +from UltiSnips.text import LineIterator, head_tail + + +def _splitall(path): + """Split 'path' into all its components.""" + # From http://my.safaribooksonline.com/book/programming/ + # python/0596001673/files/pythoncook-chp-4-sect-16 + allparts = [] + while True: + parts = os.path.split(path) + if parts[0] == path: # sentinel for absolute paths + allparts.insert(0, parts[0]) + break + elif parts[1] == path: # sentinel for relative paths + allparts.insert(0, parts[1]) + break + else: + path = parts[0] + allparts.insert(0, parts[1]) + return allparts + + +def snipmate_files_for(ft): + """Returns all snipMate files we need to look at for 'ft'.""" + if ft == 'all': + ft = '_' + patterns = [ + '%s.snippets' % ft, + os.path.join(ft, '*.snippets'), + os.path.join(ft, '*.snippet'), + os.path.join(ft, '*/*.snippet'), + ] + ret = set() + for rtp in _vim.eval('&runtimepath').split(','): + path = os.path.realpath(os.path.expanduser( + os.path.join(rtp, 'snippets'))) + for pattern in patterns: + for fn in glob.glob(os.path.join(path, pattern)): + ret.add(fn) + return ret + + +def _parse_snippet_file(content, full_filename): + """Parses 'content' assuming it is a .snippet file and yields events.""" + filename = full_filename[:-len('.snippet')] # strip extension + segments = _splitall(filename) + segments = segments[segments.index('snippets') + 1:] + assert len(segments) in (2, 3) + + trigger = segments[1] + description = segments[2] if 2 < len(segments) else '' + + # Chomp \n if any. + if content and content.endswith(os.linesep): + content = content[:-len(os.linesep)] + yield 'snippet', (SnipMateSnippetDefinition(trigger, content, + description, full_filename),) + + +def _parse_snippet(line, lines, filename): + """Parse a snippet defintions.""" + start_line_index = lines.line_index + trigger, description = head_tail(line[len('snippet'):].lstrip()) + content = '' + while True: + next_line = lines.peek() + if next_line is None: + break + if next_line.strip() and not next_line.startswith('\t'): + break + line = next(lines) + if line[0] == '\t': + line = line[1:] + content += line + content = content[:-1] # Chomp the last newline + return 'snippet', (SnipMateSnippetDefinition( + trigger, content, description, '%s:%i' % (filename, start_line_index)),) + + +def _parse_snippets_file(data, filename): + """Parse 'data' assuming it is a .snippets file. + + Yields events in the file. + + """ + lines = LineIterator(data) + for line in lines: + if not line.strip(): + continue + + head, tail = head_tail(line) + if head == 'extends': + yield handle_extends(tail, lines.line_index) + elif head in 'snippet': + snippet = _parse_snippet(line, lines, filename) + if snippet is not None: + yield snippet + elif head and not head.startswith('#'): + yield 'error', ('Invalid line %r' % line.rstrip(), lines.line_index) + + +class SnipMateFileSource(SnippetFileSource): + + """Manages all snipMate snippet definitions found in rtp.""" + + def _get_all_snippet_files_for(self, ft): + return snipmate_files_for(ft) + + def _parse_snippet_file(self, filedata, filename): + if filename.lower().endswith('snippet'): + for event, data in _parse_snippet_file(filedata, filename): + yield event, data + else: + for event, data in _parse_snippets_file(filedata, filename): + yield event, data diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/ultisnips.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/ultisnips.py new file mode 100644 index 0000000..2005ebd --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet/source/file/ultisnips.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Parsing of snippet files.""" + +from collections import defaultdict +import glob +import os + +from UltiSnips import _vim +from UltiSnips.snippet.definition import UltiSnipsSnippetDefinition +from UltiSnips.snippet.source.file._base import SnippetFileSource +from UltiSnips.snippet.source.file._common import handle_extends, \ + handle_action +from UltiSnips.text import LineIterator, head_tail + + +def find_snippet_files(ft, directory): + """Returns all matching snippet files for 'ft' in 'directory'.""" + patterns = ['%s.snippets', '%s_*.snippets', os.path.join('%s', '*')] + ret = set() + directory = os.path.expanduser(directory) + for pattern in patterns: + for fn in glob.glob(os.path.join(directory, pattern % ft)): + ret.add(os.path.realpath(fn)) + return ret + + +def find_all_snippet_files(ft): + """Returns all snippet files matching 'ft' in the given runtime path + directory.""" + if _vim.eval("exists('b:UltiSnipsSnippetDirectories')") == '1': + snippet_dirs = _vim.eval('b:UltiSnipsSnippetDirectories') + else: + snippet_dirs = _vim.eval('g:UltiSnipsSnippetDirectories') + if len(snippet_dirs) == 1 and os.path.isabs(snippet_dirs[0]): + check_dirs = [''] + else: + check_dirs = _vim.eval('&runtimepath').split(',') + patterns = ['%s.snippets', '%s_*.snippets', os.path.join('%s', '*')] + ret = set() + for rtp in check_dirs: + for snippet_dir in snippet_dirs: + if snippet_dir == 'snippets': + raise RuntimeError( + "You have 'snippets' in UltiSnipsSnippetDirectories. This " + 'directory is reserved for snipMate snippets. Use another ' + 'directory for UltiSnips snippets.') + pth = os.path.realpath(os.path.expanduser( + os.path.join(rtp, snippet_dir))) + for pattern in patterns: + for fn in glob.glob(os.path.join(pth, pattern % ft)): + ret.add(fn) + return ret + + +def _handle_snippet_or_global( + filename, line, lines, python_globals, priority, pre_expand +): + """Parses the snippet that begins at the current line.""" + start_line_index = lines.line_index + descr = '' + opts = '' + + # Ensure this is a snippet + snip = line.split()[0] + + # Get and strip options if they exist + remain = line[len(snip):].strip() + words = remain.split() + + if len(words) > 2: + # second to last word ends with a quote + if '"' not in words[-1] and words[-2][-1] == '"': + opts = words[-1] + remain = remain[:-len(opts) - 1].rstrip() + + context = None + if 'e' in opts: + left = remain[:-1].rfind('"') + if left != -1 and left != 0: + context, remain = remain[left:].strip('"'), remain[:left] + + # Get and strip description if it exists + remain = remain.strip() + if len(remain.split()) > 1 and remain[-1] == '"': + left = remain[:-1].rfind('"') + if left != -1 and left != 0: + descr, remain = remain[left:], remain[:left] + + # The rest is the trigger + trig = remain.strip() + if len(trig.split()) > 1 or 'r' in opts: + if trig[0] != trig[-1]: + return 'error', ("Invalid multiword trigger: '%s'" % trig, + lines.line_index) + trig = trig[1:-1] + end = 'end' + snip + content = '' + + found_end = False + for line in lines: + if line.rstrip() == end: + content = content[:-1] # Chomp the last newline + found_end = True + break + content += line + + if not found_end: + return 'error', ("Missing 'endsnippet' for %r" % + trig, lines.line_index) + + if snip == 'global': + python_globals[trig].append(content) + elif snip == 'snippet': + definition = UltiSnipsSnippetDefinition( + priority, trig, content, + descr, opts, python_globals, + '%s:%i' % (filename, start_line_index), + context, pre_expand) + return 'snippet', (definition,) + else: + return 'error', ("Invalid snippet type: '%s'" % snip, lines.line_index) + + +def _parse_snippets_file(data, filename): + """Parse 'data' assuming it is a snippet file. + + Yields events in the file. + + """ + + python_globals = defaultdict(list) + lines = LineIterator(data) + current_priority = 0 + actions = {} + for line in lines: + if not line.strip(): + continue + + head, tail = head_tail(line) + if head in ('snippet', 'global'): + snippet = _handle_snippet_or_global( + filename, line, lines, + python_globals, + current_priority, + actions + ) + + actions = {} + if snippet is not None: + yield snippet + elif head == 'extends': + yield handle_extends(tail, lines.line_index) + elif head == 'clearsnippets': + yield 'clearsnippets', (current_priority, tail.split()) + elif head == 'priority': + try: + current_priority = int(tail.split()[0]) + except (ValueError, IndexError): + yield 'error', ('Invalid priority %r' % tail, lines.line_index) + elif head in ['pre_expand', 'post_expand', 'post_jump']: + head, tail = handle_action(head, tail, lines.line_index) + if head == 'error': + yield (head, tail) + else: + actions[head], = tail + elif head and not head.startswith('#'): + yield 'error', ('Invalid line %r' % line.rstrip(), lines.line_index) + + +class UltiSnipsFileSource(SnippetFileSource): + + """Manages all snippets definitions found in rtp for ultisnips.""" + + def _get_all_snippet_files_for(self, ft): + return find_all_snippet_files(ft) + + def _parse_snippet_file(self, filedata, filename): + for event, data in _parse_snippets_file(filedata, filename): + yield event, data diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_definition.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_definition.py deleted file mode 100644 index a46a759..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_definition.py +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Snippet representation after parsing.""" - -import re - -from UltiSnips.compatibility import as_unicode -from UltiSnips.text_objects import SnippetInstance -from UltiSnips.indent_util import IndentUtil -import UltiSnips._vim as _vim - - -def _words_for_line(trigger, before, num_words=None): - """ Gets the final 'num_words' words from 'before'. - If num_words is None, then use the number of words in - 'trigger'. - """ - if not len(before): - return '' - - if num_words is None: - num_words = len(trigger.split()) - - word_list = before.split() - if len(word_list) <= num_words: - return before.strip() - else: - before_words = before - for i in range(-1, -(num_words + 1), -1): - left = before_words.rfind(word_list[i]) - before_words = before_words[:left] - return before[len(before_words):].strip() - - -class SnippetDefinition(object): - """Represents a snippet as parsed from a file.""" - - _INDENT = re.compile(r"^[ \t]*") - _TABS = re.compile(r"^\t*") - - def __init__(self, priority, trigger, value, description, options, globals): - self._priority = priority - self._trigger = as_unicode(trigger) - self._value = as_unicode(value) - self._description = as_unicode(description) - self._opts = options - self._matched = "" - self._last_re = None - self._globals = globals - - def __repr__(self): - return "SnippetDefinition(%r,%s,%s,%s)" % ( - self._priority, self._trigger, self._description, self._opts) - - def _re_match(self, trigger): - """ Test if a the current regex trigger matches - `trigger`. If so, set _last_re and _matched. - """ - for match in re.finditer(self._trigger, trigger): - if match.end() != len(trigger): - continue - else: - self._matched = trigger[match.start():match.end()] - - self._last_re = match - return match - return False - - def has_option(self, opt): - """ Check if the named option is set """ - return opt in self._opts - - def matches(self, trigger): - """Returns True if this snippet matches 'trigger'.""" - # If user supplies both "w" and "i", it should perhaps be an - # error, but if permitted it seems that "w" should take precedence - # (since matching at word boundary and within a word == matching at word - # boundary). - self._matched = "" - - # Don't expand on whitespace - if trigger and trigger.rstrip() != trigger: - return False - - words = _words_for_line(self._trigger, trigger) - - if "r" in self._opts: - match = self._re_match(trigger) - elif "w" in self._opts: - words_len = len(self._trigger) - words_prefix = words[:-words_len] - words_suffix = words[-words_len:] - match = (words_suffix == self._trigger) - if match and words_prefix: - # Require a word boundary between prefix and suffix. - boundary_chars = words_prefix[-1:] + words_suffix[:1] - boundary_chars = boundary_chars.replace('"', '\\"') - match = _vim.eval('"%s" =~# "\\\\v.<."' % boundary_chars) != '0' - elif "i" in self._opts: - match = words.endswith(self._trigger) - else: - match = (words == self._trigger) - - # By default, we match the whole trigger - if match and not self._matched: - self._matched = self._trigger - - # Ensure the match was on a word boundry if needed - if "b" in self._opts and match: - text_before = trigger.rstrip()[:-len(self._matched)] - if text_before.strip(" \t") != '': - self._matched = "" - return False - return match - - def could_match(self, trigger): - """Return True if this snippet could match the (partial) 'trigger'.""" - self._matched = "" - - # List all on whitespace. - if trigger and trigger[-1] in (" ", "\t"): - trigger = "" - if trigger and trigger.rstrip() is not trigger: - return False - - words = _words_for_line(self._trigger, trigger) - - if "r" in self._opts: - # Test for full match only - match = self._re_match(trigger) - elif "w" in self._opts: - # Trim non-empty prefix up to word boundary, if present. - qwords = words.replace('"', '\\"') - words_suffix = _vim.eval( - 'substitute("%s", "\\\\v^.+<(.+)", "\\\\1", "")' % qwords) - match = self._trigger.startswith(words_suffix) - self._matched = words_suffix - - # TODO: list_snippets() function cannot handle partial-trigger - # matches yet, so for now fail if we trimmed the prefix. - if words_suffix != words: - match = False - elif "i" in self._opts: - # TODO: It is hard to define when a inword snippet could match, - # therefore we check only for full-word trigger. - match = self._trigger.startswith(words) - else: - match = self._trigger.startswith(words) - - # By default, we match the words from the trigger - if match and not self._matched: - self._matched = words - - # Ensure the match was on a word boundry if needed - if "b" in self._opts and match: - text_before = trigger.rstrip()[:-len(self._matched)] - if text_before.strip(" \t") != '': - self._matched = "" - return False - - return match - - @property - def description(self): - """Descriptive text for this snippet.""" - return ("(%s) %s" % (self._trigger, self._description)).strip() - - @property - def priority(self): - """The snippets priority, which defines which snippet will be preferred - over others with the same trigger.""" - return self._priority - - @property - def trigger(self): - """The trigger text for the snippet.""" - return self._trigger - - @property - def matched(self): - """The last text that matched this snippet in match() or - could_match().""" - return self._matched - - def launch(self, text_before, visual_content, parent, start, end): - """Launch this snippet, overwriting the text 'start' to 'end' and - keeping the 'text_before' on the launch line. 'Parent' is the parent - snippet instance if any.""" - indent = self._INDENT.match(text_before).group(0) - lines = (self._value + "\n").splitlines() - ind_util = IndentUtil() - - # Replace leading tabs in the snippet definition via proper indenting - snippet_definition = [] - for line_num, line in enumerate(lines): - if "t" in self._opts: - tabs = 0 - else: - tabs = len(self._TABS.match(line).group(0)) - - line_ind = ind_util.ntabs_to_proper_indent(tabs) - - if line_num != 0: - line_ind = indent + line_ind - - snippet_definition.append(line_ind + line[tabs:]) - snippet_definition = '\n'.join(snippet_definition) - - si = SnippetInstance(self, parent, indent, snippet_definition, start, - end, visual_content, last_re=self._last_re, - globals=self._globals) - - return si diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_manager.py b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_manager.py index c803094..9cc82e9 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_manager.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/snippet_manager.py @@ -6,31 +6,36 @@ from collections import defaultdict from functools import wraps import os +import platform import traceback +import sys +import vim +import re +from contextlib import contextmanager +from UltiSnips import _vim from UltiSnips._diff import diff, guess_edit from UltiSnips.compatibility import as_unicode from UltiSnips.position import Position -from UltiSnips.providers import UltiSnipsFileProvider, \ - base_snippet_files_for, AddedSnippetsProvider -from UltiSnips.snippet_definition import SnippetDefinition +from UltiSnips.snippet.definition import UltiSnipsSnippetDefinition +from UltiSnips.snippet.source import UltiSnipsFileSource, SnipMateFileSource, \ + find_all_snippet_files, find_snippet_files, AddedSnippetsSource +from UltiSnips.text import escape from UltiSnips.vim_state import VimState, VisualContentPreserver -import UltiSnips._vim as _vim +from UltiSnips.buffer_proxy import use_proxy_buffer, suspend_proxy_edits -def _ask_snippets(snippets): - """ Given a list of snippets, ask the user which one they - want to use, and return it. - """ - display = [as_unicode("%i: %s") % (i+1, s.description) for - i, s in enumerate(snippets)] + +def _ask_user(a, formatted): + """Asks the user using inputlist() and returns the selected element or + None.""" try: - rv = _vim.eval("inputlist(%s)" % _vim.escape(display)) + rv = _vim.eval('inputlist(%s)' % _vim.escape(formatted)) if rv is None or rv == '0': return None rv = int(rv) - if rv > len(snippets): - rv = len(snippets) - return snippets[rv-1] + if rv > len(a): + rv = len(a) + return a[rv - 1] except _vim.error: # Likely "invalid expression", but might be translated. We have no way # of knowing the exact error, therefore, we ignore all errors silently. @@ -39,6 +44,14 @@ def _ask_snippets(snippets): return None +def _ask_snippets(snippets): + """Given a list of snippets, ask the user which one they want to use, and + return it.""" + display = [as_unicode('%i: %s (%s)') % (i + 1, escape(s.description, '\\'), + escape(s.location, '\\')) for i, s in enumerate(snippets)] + return _ask_user(snippets, display) + + def err_to_scratch_buffer(func): """Decorator that will catch any Exception that 'func' throws and displays it in a new Vim scratch buffer.""" @@ -46,15 +59,36 @@ def err_to_scratch_buffer(func): def wrapper(self, *args, **kwds): try: return func(self, *args, **kwds) - except: # pylint: disable=bare-except + except Exception as e: # pylint: disable=bare-except msg = \ -"""An error occured. This is either a bug in UltiSnips or a bug in a + """An error occured. This is either a bug in UltiSnips or a bug in a snippet definition. If you think this is a bug, please report it to https://github.com/SirVer/ultisnips/issues/new. Following is the full stack trace: """ + msg += traceback.format_exc() + if hasattr(e, 'snippet_info'): + msg += "\nSnippet, caused error:\n" + msg += re.sub( + '^(?=\S)', ' ', e.snippet_info, flags=re.MULTILINE + ) + # snippet_code comes from _python_code.py, it's set manually for + # providing error message with stacktrace of failed python code + # inside of the snippet. + if hasattr(e, 'snippet_code'): + _, _, tb = sys.exc_info() + tb_top = traceback.extract_tb(tb)[-1] + msg += "\nExecuted snippet code:\n" + lines = e.snippet_code.split("\n") + for number, line in enumerate(lines, 1): + msg += str(number).rjust(3) + prefix = " " if line else "" + if tb_top[1] == number: + prefix = " > " + msg += prefix + line + "\n" + # Vim sends no WinLeave msg here. self._leaving_buffer() # pylint:disable=protected-access _vim.new_scratch_buffer(msg) @@ -64,47 +98,83 @@ Following is the full stack trace: # TODO(sirver): This class is still too long. It should only contain public # facing methods, most of the private methods should be moved outside of it. class SnippetManager(object): - """The main entry point for all UltiSnips functionality. All Vim functions - call methods in this class.""" + + """The main entry point for all UltiSnips functionality. + + All Vim functions call methods in this class. + + """ def __init__(self, expand_trigger, forward_trigger, backward_trigger): self.expand_trigger = expand_trigger self.forward_trigger = forward_trigger self.backward_trigger = backward_trigger + self._inner_state_up = False self._supertab_keys = None + self._csnippets = [] - self._reset() + self._buffer_filetypes = defaultdict(lambda: ['all']) + + self._vstate = VimState() + self._visual_content = VisualContentPreserver() + + self._snippet_sources = [] + + self._snip_expanded_in_action = False + self._inside_action = False + + self._last_inserted_char = '' + + self._added_snippets_source = AddedSnippetsSource() + self.register_snippet_source('ultisnips_files', UltiSnipsFileSource()) + self.register_snippet_source('added', self._added_snippets_source) + + enable_snipmate = '1' + if _vim.eval("exists('g:UltiSnipsEnableSnipMate')") == '1': + enable_snipmate = _vim.eval('g:UltiSnipsEnableSnipMate') + if enable_snipmate == '1': + self.register_snippet_source('snipmate_files', + SnipMateFileSource()) + + self._should_update_textobjects = False + self._should_reset_visual = False + + self._reinit() @err_to_scratch_buffer def jump_forwards(self): """Jumps to the next tabstop.""" - _vim.command("let g:ulti_jump_forwards_res = 1") + _vim.command('let g:ulti_jump_forwards_res = 1') + _vim.command('let &undolevels = &undolevels') if not self._jump(): - _vim.command("let g:ulti_jump_forwards_res = 0") + _vim.command('let g:ulti_jump_forwards_res = 0') return self._handle_failure(self.forward_trigger) @err_to_scratch_buffer def jump_backwards(self): """Jumps to the previous tabstop.""" - _vim.command("let g:ulti_jump_backwards_res = 1") + _vim.command('let g:ulti_jump_backwards_res = 1') + _vim.command('let &undolevels = &undolevels') if not self._jump(True): - _vim.command("let g:ulti_jump_backwards_res = 0") + _vim.command('let g:ulti_jump_backwards_res = 0') return self._handle_failure(self.backward_trigger) @err_to_scratch_buffer def expand(self): """Try to expand a snippet at the current position.""" - _vim.command("let g:ulti_expand_res = 1") + _vim.command('let g:ulti_expand_res = 1') if not self._try_expand(): - _vim.command("let g:ulti_expand_res = 0") + _vim.command('let g:ulti_expand_res = 0') self._handle_failure(self.expand_trigger) @err_to_scratch_buffer def expand_or_jump(self): - """ - This function is used for people who wants to have the same trigger for - expansion and forward jumping. It first tries to expand a snippet, if - this fails, it tries to jump forward. + """This function is used for people who wants to have the same trigger + for expansion and forward jumping. + + It first tries to expand a snippet, if this fails, it tries to + jump forward. + """ _vim.command('let g:ulti_expand_or_jump_res = 1') rv = self._try_expand() @@ -116,17 +186,19 @@ class SnippetManager(object): self._handle_failure(self.expand_trigger) @err_to_scratch_buffer - def snippets_in_current_scope(self): + def snippets_in_current_scope(self, searchAll): """Returns the snippets that could be expanded to Vim as a global variable.""" - before = _vim.buf.line_till_cursor + before = '' if searchAll else _vim.buf.line_till_cursor snippets = self._snips(before, True) # Sort snippets alphabetically snippets.sort(key=lambda x: x.trigger) for snip in snippets: description = snip.description[snip.description.find(snip.trigger) + - len(snip.trigger) + 2:] + len(snip.trigger) + 2:] + + location = snip.location if snip.location else '' key = as_unicode(snip.trigger) description = as_unicode(description) @@ -142,6 +214,18 @@ class SnippetManager(object): key=key.replace("'", "''"), val=description.replace("'", "''"))) + if searchAll: + _vim.command(as_unicode( + ("let g:current_ulti_dict_info['{key}'] = {{" + "'description': '{description}'," + "'location': '{location}'," + "}}")).format( + key=key.replace("'", "''"), + location=location.replace("'", "''"), + description=description.replace("'", "''"))) + + + @err_to_scratch_buffer def list_snippets(self): """Shows the snippets that could be expanded to the User and let her @@ -169,51 +253,82 @@ class SnippetManager(object): @err_to_scratch_buffer def add_snippet(self, trigger, value, description, - options, ft="all", priority=0): + options, ft='all', priority=0, context=None, actions={}): """Add a snippet to the list of known snippets of the given 'ft'.""" - self._added_snippets_provider.add_snippet(ft, SnippetDefinition( - priority, trigger, value, description, options, {}) - ) + self._added_snippets_source.add_snippet(ft, + UltiSnipsSnippetDefinition(priority, trigger, value, + description, options, {}, 'added', + context, actions)) @err_to_scratch_buffer - def expand_anon(self, value, trigger="", description="", options=""): + def expand_anon( + self, value, trigger='', description='', options='', + context=None, actions={} + ): """Expand an anonymous snippet right here.""" before = _vim.buf.line_till_cursor - snip = SnippetDefinition(0, trigger, value, description, options, {}) + snip = UltiSnipsSnippetDefinition(0, trigger, value, description, + options, {}, '', context, actions) - if not trigger or snip.matches(before): + if not trigger or snip.matches(before, self._visual_content): self._do_snippet(snip, before) return True else: return False + def register_snippet_source(self, name, snippet_source): + """Registers a new 'snippet_source' with the given 'name'. + + The given class must be an instance of SnippetSource. This + source will be queried for snippets. + + """ + self._snippet_sources.append((name, snippet_source)) + + def unregister_snippet_source(self, name): + """Unregister the source with the given 'name'. + + Does nothing if it is not registered. + + """ + for index, (source_name, _) in enumerate(self._snippet_sources): + if name == source_name: + self._snippet_sources = self._snippet_sources[:index] + \ + self._snippet_sources[index + 1:] + break + def reset_buffer_filetypes(self): """Reset the filetypes for the current buffer.""" - if _vim.buf.number in self._filetypes: - del self._filetypes[_vim.buf.number] + if _vim.buf.number in self._buffer_filetypes: + del self._buffer_filetypes[_vim.buf.number] def add_buffer_filetypes(self, ft): """Checks for changes in the list of snippet files or the contents of - the snippet files and reloads them if necessary. """ - buf_fts = self._filetypes[_vim.buf.number] + the snippet files and reloads them if necessary.""" + buf_fts = self._buffer_filetypes[_vim.buf.number] idx = -1 - for ft in ft.split("."): + for ft in ft.split('.'): ft = ft.strip() if not ft: continue try: idx = buf_fts.index(ft) except ValueError: - self._filetypes[_vim.buf.number].insert(idx + 1, ft) + self._buffer_filetypes[_vim.buf.number].insert(idx + 1, ft) idx += 1 @err_to_scratch_buffer def _cursor_moved(self): """Called whenever the cursor moved.""" + self._should_update_textobjects = False + + if not self._csnippets and self._inner_state_up: + self._teardown_inner_state() self._vstate.remember_position() - if _vim.eval("mode()") not in 'in': + if _vim.eval('mode()') not in 'in': return + if self._ignore_movements: self._ignore_movements = False return @@ -221,7 +336,7 @@ class SnippetManager(object): if self._csnippets: cstart = self._csnippets[0].start.line cend = self._csnippets[0].end.line + \ - self._vstate.diff_in_buffer_length + self._vstate.diff_in_buffer_length ct = _vim.buf[cstart:cend + 1] lt = self._vstate.remembered_buffer pos = _vim.buf.cursor @@ -233,9 +348,9 @@ class SnippetManager(object): # Cut down on lines searched for changes. Start from behind and # remove all equal lines. Then do the same from the front. if lt and ct: - while (lt[lt_span[1]-1] == ct[ct_span[1]-1] and - self._vstate.ppos.line < initial_line + lt_span[1]-1 and - pos.line < initial_line + ct_span[1]-1 and + while (lt[lt_span[1] - 1] == ct[ct_span[1] - 1] and + self._vstate.ppos.line < initial_line + lt_span[1] - 1 and + pos.line < initial_line + ct_span[1] - 1 and (lt_span[0] < lt_span[1]) and (ct_span[0] < ct_span[1])): ct_span[1] -= 1 @@ -261,7 +376,7 @@ class SnippetManager(object): lt = '\n'.join(lt) ct = '\n'.join(ct) es = diff(lt, ct, initial_line) - self._csnippets[0].replay_user_edits(es) + self._csnippets[0].replay_user_edits(es, self._ctab) except IndexError: # Rather do nothing than throwing an error. It will be correct # most of the time @@ -272,36 +387,82 @@ class SnippetManager(object): self._csnippets[0].update_textobjects() self._vstate.remember_buffer(self._csnippets[0]) - @err_to_scratch_buffer - def _reset(self): - """Reset the class to the state it had directly after creation.""" - self._vstate = VimState() - self._filetypes = defaultdict(lambda: ['all']) - self._visual_content = VisualContentPreserver() - self._snippet_providers = [ - AddedSnippetsProvider(), - UltiSnipsFileProvider() - ] - self._added_snippets_provider = self._snippet_providers[0] - - while len(self._csnippets): - self._current_snippet_is_done() - - self._reinit() + def _setup_inner_state(self): + """Map keys and create autocommands that should only be defined when a + snippet is active.""" + if self._inner_state_up: + return + if self.expand_trigger != self.forward_trigger: + _vim.command('inoremap ' + self.forward_trigger + + ' =UltiSnips#JumpForwards()') + _vim.command('snoremap ' + self.forward_trigger + + ' :call UltiSnips#JumpForwards()') + _vim.command('inoremap ' + self.backward_trigger + + ' =UltiSnips#JumpBackwards()') + _vim.command('snoremap ' + self.backward_trigger + + ' :call UltiSnips#JumpBackwards()') + + # Setup the autogroups. + _vim.command('augroup UltiSnips') + _vim.command('autocmd!') + _vim.command('autocmd CursorMovedI * call UltiSnips#CursorMoved()') + _vim.command('autocmd CursorMoved * call UltiSnips#CursorMoved()') + + _vim.command( + 'autocmd InsertLeave * call UltiSnips#LeavingInsertMode()') + + _vim.command('autocmd BufLeave * call UltiSnips#LeavingBuffer()') + _vim.command( + 'autocmd CmdwinEnter * call UltiSnips#LeavingBuffer()') + _vim.command( + 'autocmd CmdwinLeave * call UltiSnips#LeavingBuffer()') + + # Also exit the snippet when we enter a unite complete buffer. + _vim.command('autocmd Filetype unite call UltiSnips#LeavingBuffer()') + + _vim.command('augroup END') + + _vim.command('silent doautocmd User UltiSnipsEnterFirstSnippet') + self._inner_state_up = True + + def _teardown_inner_state(self): + """Reverse _setup_inner_state.""" + if not self._inner_state_up: + return + try: + _vim.command('silent doautocmd User UltiSnipsExitLastSnippet') + if self.expand_trigger != self.forward_trigger: + _vim.command('iunmap %s' % self.forward_trigger) + _vim.command('sunmap %s' % self.forward_trigger) + _vim.command('iunmap %s' % self.backward_trigger) + _vim.command('sunmap %s' % self.backward_trigger) + _vim.command('augroup UltiSnips') + _vim.command('autocmd!') + _vim.command('augroup END') + self._inner_state_up = False + except _vim.error: + # This happens when a preview window was opened. This issues + # CursorMoved, but not BufLeave. We have no way to unmap, until we + # are back in our buffer + pass @err_to_scratch_buffer def _save_last_visual_selection(self): - """ - This is called when the expand trigger is pressed in visual mode. - Our job is to remember everything between '< and '> and pass it on to + """This is called when the expand trigger is pressed in visual mode. + Our job is to remember everything between '< and '> and pass it on to. + ${VISUAL} in case it will be needed. + """ self._visual_content.conserve() - def _leaving_buffer(self): - """Called when the user switches tabs/windows/buffers. It basically - means that all snippets must be properly terminated.""" + """Called when the user switches tabs/windows/buffers. + + It basically means that all snippets must be properly + terminated. + + """ while len(self._csnippets): self._current_snippet_is_done() self._reinit() @@ -324,31 +485,86 @@ class SnippetManager(object): """The current snippet should be terminated.""" self._csnippets.pop() if not self._csnippets: - _vim.command("call UltiSnips#map_keys#RestoreInnerKeys()") + self._teardown_inner_state() def _jump(self, backwards=False): """Helper method that does the actual jump.""" - jumped = False - if self._cs: - self._ctab = self._cs.select_next_tab(backwards) - if self._ctab: - if self._cs.snippet.has_option("s"): - lineno = _vim.buf.cursor.line - _vim.buf[lineno] = _vim.buf[lineno].rstrip() - _vim.select(self._ctab.start, self._ctab.end) - jumped = True - if self._ctab.number == 0: - self._current_snippet_is_done() + if self._should_update_textobjects: + self._should_reset_visual = False + self._cursor_moved() + + # we need to set 'onemore' there, because of limitations of the vim + # API regarding cursor movements; without that test + # 'CanExpandAnonSnippetInJumpActionWhileSelected' will fail + with _vim.toggle_opt('ve', 'onemore'): + jumped = False + + # We need to remember current snippets stack here because of + # post-jump action on the last tabstop should be able to access + # snippet instance which is ended just now. + stack_for_post_jump = self._csnippets[:] + + # If next tab has length 1 and the distance between itself and + # self._ctab is 1 then there is 1 less CursorMove events. We + # cannot ignore next movement in such case. + ntab_short_and_near = False + + if self._cs: + snippet_for_action = self._cs + elif stack_for_post_jump: + snippet_for_action = stack_for_post_jump[-1] else: - # This really shouldn't happen, because a snippet should - # have been popped when its final tabstop was used. - # Cleanup by removing current snippet and recursing. - self._current_snippet_is_done() - jumped = self._jump(backwards) - if jumped: - self._vstate.remember_position() - self._vstate.remember_unnamed_register(self._ctab.current_text) - self._ignore_movements = True + snippet_for_action = None + + if self._cs: + ntab = self._cs.select_next_tab(backwards) + if ntab: + if self._cs.snippet.has_option('s'): + lineno = _vim.buf.cursor.line + _vim.buf[lineno] = _vim.buf[lineno].rstrip() + _vim.select(ntab.start, ntab.end) + jumped = True + if (self._ctab is not None + and ntab.start - self._ctab.end == Position(0, 1) + and ntab.end - ntab.start == Position(0, 1)): + ntab_short_and_near = True + + self._ctab = ntab + + # Run interpolations again to update new placeholder + # values, binded to currently newly jumped placeholder. + self._visual_content.conserve_placeholder(self._ctab) + self._cs.current_placeholder = \ + self._visual_content.placeholder + self._should_reset_visual = False + self._csnippets[0].update_textobjects() + self._vstate.remember_buffer(self._csnippets[0]) + + if ntab.number == 0 and self._csnippets: + self._current_snippet_is_done() + else: + # This really shouldn't happen, because a snippet should + # have been popped when its final tabstop was used. + # Cleanup by removing current snippet and recursing. + self._current_snippet_is_done() + jumped = self._jump(backwards) + + if jumped: + if self._ctab: + self._vstate.remember_position() + self._vstate.remember_unnamed_register(self._ctab.current_text) + if not ntab_short_and_near: + self._ignore_movements = True + + if len(stack_for_post_jump) > 0 and ntab is not None: + with use_proxy_buffer(stack_for_post_jump, self._vstate): + snippet_for_action.snippet.do_post_jump( + ntab.number, + -1 if backwards else 1, + stack_for_post_jump, + snippet_for_action + ) + return jumped def _leaving_insert_mode(self): @@ -357,18 +573,18 @@ class SnippetManager(object): def _handle_failure(self, trigger): """Mainly make sure that we play well with SuperTab.""" - if trigger.lower() == "": - feedkey = "\\" + trigger - elif trigger.lower() == "": - feedkey = "\\" + trigger + if trigger.lower() == '': + feedkey = '\\' + trigger + elif trigger.lower() == '': + feedkey = '\\' + trigger else: feedkey = None - mode = "n" + mode = 'n' if not self._supertab_keys: - if _vim.eval("exists('g:SuperTabMappingForward')") != "0": + if _vim.eval("exists('g:SuperTabMappingForward')") != '0': self._supertab_keys = ( - _vim.eval("g:SuperTabMappingForward"), - _vim.eval("g:SuperTabMappingBackward"), + _vim.eval('g:SuperTabMappingForward'), + _vim.eval('g:SuperTabMappingBackward'), ) else: self._supertab_keys = ['', ''] @@ -377,98 +593,175 @@ class SnippetManager(object): if trigger.lower() == sttrig.lower(): if idx == 0: feedkey = r"\SuperTabForward" - mode = "n" + mode = 'n' elif idx == 1: feedkey = r"\SuperTabBackward" - mode = "p" + mode = 'p' # Use remap mode so SuperTab mappings will be invoked. break if (feedkey == r"\SuperTabForward" or feedkey == r"\SuperTabBackward"): - _vim.command("return SuperTab(%s)" % _vim.escape(mode)) + _vim.command('return SuperTab(%s)' % _vim.escape(mode)) elif feedkey: - _vim.command("return %s" % _vim.escape(feedkey)) + _vim.command('return %s' % _vim.escape(feedkey)) + + def _snips(self, before, partial, autotrigger_only=False): + """Returns all the snippets for the given text before the cursor. + + If partial is True, then get also return partial matches. - def _snips(self, before, possible): - """ Returns all the snippets for the given text - before the cursor. If possible is True, then get all - possible matches. """ - filetypes = self._filetypes[_vim.buf.number][::-1] + filetypes = self._buffer_filetypes[_vim.buf.number][::-1] matching_snippets = defaultdict(list) - for provider in self._snippet_providers: - for snippet in provider.get_snippets(filetypes, before, possible): - matching_snippets[snippet.trigger].append(snippet) + clear_priority = None + cleared = {} + for _, source in self._snippet_sources: + source.ensure(filetypes, cached=autotrigger_only) + + # Collect cleared information from sources. + for _, source in self._snippet_sources: + sclear_priority = source.get_clear_priority(filetypes) + if sclear_priority is not None and (clear_priority is None + or sclear_priority > clear_priority): + clear_priority = sclear_priority + for key, value in source.get_cleared(filetypes).items(): + if key not in cleared or value > cleared[key]: + cleared[key] = value + + for _, source in self._snippet_sources: + possible_snippets = source.get_snippets( + filetypes, + before, + partial, + autotrigger_only, + self._visual_content + ) + + for snippet in possible_snippets: + if ((clear_priority is None or snippet.priority > clear_priority) + and (snippet.trigger not in cleared or + snippet.priority > cleared[snippet.trigger])): + matching_snippets[snippet.trigger].append(snippet) if not matching_snippets: return [] # Now filter duplicates and only keep the one with the highest - # priority. Only keep the snippets with the highest priority. + # priority. snippets = [] for snippets_with_trigger in matching_snippets.values(): highest_priority = max(s.priority for s in snippets_with_trigger) snippets.extend(s for s in snippets_with_trigger - if s.priority == highest_priority) - return snippets + if s.priority == highest_priority) + + # For partial matches we are done, but if we want to expand a snippet, + # we have to go over them again and only keep those with the maximum + # priority. + if partial: + return snippets + + highest_priority = max(s.priority for s in snippets) + return [s for s in snippets if s.priority == highest_priority] def _do_snippet(self, snippet, before): - """Expands the given snippet, and handles everything - that needs to be done with it.""" - _vim.command("call UltiSnips#map_keys#MapInnerKeys()") + """Expands the given snippet, and handles everything that needs to be + done with it.""" + self._setup_inner_state() + + self._snip_expanded_in_action = False + self._should_update_textobjects = False # Adjust before, maybe the trigger is not the complete word text_before = before if snippet.matched: text_before = before[:-len(snippet.matched)] - if self._cs: - start = Position(_vim.buf.cursor.line, len(text_before)) - end = Position(_vim.buf.cursor.line, len(before)) - - # It could be that our trigger contains the content of TextObjects - # in our containing snippet. If this is indeed the case, we have to - # make sure that those are properly killed. We do this by - # pretending that the user deleted and retyped the text that our - # trigger matched. - edit_actions = [ - ("D", start.line, start.col, snippet.matched), - ("I", start.line, start.col, snippet.matched), - ] - self._csnippets[0].replay_user_edits(edit_actions) - - si = snippet.launch(text_before, self._visual_content, - self._cs.find_parent_for_new_to(start), start, end) - else: - start = Position(_vim.buf.cursor.line, len(text_before)) - end = Position(_vim.buf.cursor.line, len(before)) - si = snippet.launch(text_before, self._visual_content, - None, start, end) + with use_proxy_buffer(self._csnippets, self._vstate): + with self._action_context(): + cursor_set_in_action = snippet.do_pre_expand( + self._visual_content.text, + self._csnippets + ) + + if cursor_set_in_action: + text_before = _vim.buf.line_till_cursor + before = _vim.buf.line_till_cursor + + with suspend_proxy_edits(): + if self._cs: + start = Position(_vim.buf.cursor.line, len(text_before)) + end = Position(_vim.buf.cursor.line, len(before)) + + # If cursor is set in pre-action, then action was modified + # cursor line, in that case we do not need to do any edits, it + # can break snippet + if not cursor_set_in_action: + # It could be that our trigger contains the content of + # TextObjects in our containing snippet. If this is indeed + # the case, we have to make sure that those are properly + # killed. We do this by pretending that the user deleted + # and retyped the text that our trigger matched. + edit_actions = [ + ('D', start.line, start.col, snippet.matched), + ('I', start.line, start.col, snippet.matched), + ] + self._csnippets[0].replay_user_edits(edit_actions) + + si = snippet.launch(text_before, self._visual_content, + self._cs.find_parent_for_new_to(start), + start, end + ) + else: + start = Position(_vim.buf.cursor.line, len(text_before)) + end = Position(_vim.buf.cursor.line, len(before)) + si = snippet.launch(text_before, self._visual_content, + None, start, end) + + self._visual_content.reset() + self._csnippets.append(si) - self._visual_content.reset() - self._csnippets.append(si) + si.update_textobjects() - self._ignore_movements = True - self._vstate.remember_buffer(self._csnippets[0]) + with use_proxy_buffer(self._csnippets, self._vstate): + with self._action_context(): + snippet.do_post_expand( + si._start, si._end, self._csnippets + ) - self._jump() + self._vstate.remember_buffer(self._csnippets[0]) - def _try_expand(self): + if not self._snip_expanded_in_action: + self._jump() + elif self._cs.current_text != '': + self._jump() + else: + self._current_snippet_is_done() + + if self._inside_action: + self._snip_expanded_in_action = True + + + def _try_expand(self, autotrigger_only=False): """Try to expand a snippet in the current place.""" before = _vim.buf.line_till_cursor - if not before: - return False - snippets = self._snips(before, False) + snippets = self._snips(before, False, autotrigger_only) + if snippets: + # prefer snippets with context if any + snippets_with_context = [s for s in snippets if s.context] + if snippets_with_context: + snippets = snippets_with_context if not snippets: # No snippet found return False - elif len(snippets) == 1: + _vim.command('let &undolevels = &undolevels') + if len(snippets) == 1: snippet = snippets[0] else: snippet = _ask_snippets(snippets) if not snippet: return True self._do_snippet(snippet, before) + _vim.command('let &undolevels = &undolevels') return True @property @@ -478,49 +771,93 @@ class SnippetManager(object): return None return self._csnippets[-1] + def _file_to_edit(self, requested_ft, bang): # pylint: disable=no-self-use + """Returns a file to be edited for the given requested_ft. + + If 'bang' is + empty only private files in g:UltiSnipsSnippetsDir are considered, + otherwise all files are considered and the user gets to choose. - @property - def _primary_filetype(self): - """This filetype will be edited when UltiSnipsEdit is called without - any arguments.""" - return self._filetypes[_vim.buf.number][0] - - # TODO(sirver): this should talk directly to the UltiSnipsFileProvider. - def _file_to_edit(self, ft): # pylint: disable=no-self-use - """ Gets a file to edit based on the given filetype. - If no filetype is given, uses the current filetype from Vim. - - Checks 'g:UltiSnipsSnippetsDir' and uses it if it exists - If a non-shipped file already exists, it uses it. - Otherwise uses a file in ~/.vim/ or ~/vimfiles """ # This method is not using self, but is called by UltiSnips.vim and is # therefore in this class because it is the facade to Vim. - edit = None - existing = base_snippet_files_for(ft, False) - filename = ft + ".snippets" - - if _vim.eval("exists('g:UltiSnipsSnippetsDir')") == "1": - snipdir = _vim.eval("g:UltiSnipsSnippetsDir") - edit = os.path.join(snipdir, filename) - elif existing: - edit = existing[-1] # last sourced/highest priority + potentials = set() + + if _vim.eval("exists('g:UltiSnipsSnippetsDir')") == '1': + snippet_dir = _vim.eval('g:UltiSnipsSnippetsDir') + else: + home = _vim.eval('$HOME') + if platform.system() == 'Windows': + snippet_dir = os.path.join(home, 'vimfiles', 'UltiSnips') + elif _vim.eval("has('nvim')") == '1': + xdg_home_config = _vim.eval('$XDG_CONFIG_HOME') or os.path.join(home, ".config") + snippet_dir = os.path.join(xdg_home_config, 'nvim', 'UltiSnips') + else: + snippet_dir = os.path.join(home, '.vim', 'UltiSnips') + + filetypes = [] + if requested_ft: + filetypes.append(requested_ft) else: - home = _vim.eval("$HOME") - rtp = [os.path.realpath(os.path.expanduser(p)) - for p in _vim.eval("&rtp").split(",")] - snippet_dirs = ["UltiSnips"] + \ - _vim.eval("g:UltiSnipsSnippetDirectories") - us = snippet_dirs[-1] - - path = os.path.join(home, ".vim", us) - for dirname in [".vim", "vimfiles"]: - pth = os.path.join(home, dirname) - if pth in rtp: - path = os.path.join(pth, us) - - if not os.path.isdir(path): - os.mkdir(path) - - edit = os.path.join(path, filename) - return edit + if bang: + filetypes.extend(self._buffer_filetypes[_vim.buf.number]) + else: + filetypes.append(self._buffer_filetypes[_vim.buf.number][0]) + + for ft in filetypes: + potentials.update(find_snippet_files(ft, snippet_dir)) + potentials.add(os.path.join(snippet_dir, + ft + '.snippets')) + if bang: + potentials.update(find_all_snippet_files(ft)) + + potentials = set(os.path.realpath(os.path.expanduser(p)) + for p in potentials) + + if len(potentials) > 1: + files = sorted(potentials) + formatted = [as_unicode('%i: %s') % (i, escape(fn, '\\')) for + i, fn in enumerate(files, 1)] + file_to_edit = _ask_user(files, formatted) + if file_to_edit is None: + return '' + else: + file_to_edit = potentials.pop() + + dirname = os.path.dirname(file_to_edit) + if not os.path.exists(dirname): + os.makedirs(dirname) + return file_to_edit + + @contextmanager + def _action_context(self): + try: + old_flag = self._inside_action + self._inside_action = True + yield + finally: + self._inside_action = old_flag + + @err_to_scratch_buffer + def _track_change(self): + self._should_update_textobjects = True + + inserted_char = _vim.eval('v:char') + try: + if inserted_char == '': + before = _vim.buf.line_till_cursor + if before and before[-1] == self._last_inserted_char: + self._try_expand(autotrigger_only=True) + finally: + self._last_inserted_char = inserted_char + + if self._should_reset_visual and self._visual_content.mode == '': + self._visual_content.reset() + + self._should_reset_visual = True + + +UltiSnips_Manager = SnippetManager( # pylint:disable=invalid-name + vim.eval('g:UltiSnipsExpandTrigger'), + vim.eval('g:UltiSnipsJumpForwardTrigger'), + vim.eval('g:UltiSnipsJumpBackwardTrigger')) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/test_diff.py b/vim/bundle/ultisnips/pythonx/UltiSnips/test_diff.py index 6e13e73..6d1d4f4 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/test_diff.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/test_diff.py @@ -10,17 +10,17 @@ from position import Position def transform(a, cmds): - buf = a.split("\n") + buf = a.split('\n') for cmd in cmds: ctype, line, col, char = cmd - if ctype == "D": + if ctype == 'D': if char != '\n': - buf[line] = buf[line][:col] + buf[line][col+len(char):] + buf[line] = buf[line][:col] + buf[line][col + len(char):] else: - buf[line] = buf[line] + buf[line+1] - del buf[line+1] - elif ctype == "I": + buf[line] = buf[line] + buf[line + 1] + del buf[line + 1] + elif ctype == 'I': buf[line] = buf[line][:col] + char + buf[line][col:] buf = '\n'.join(buf).split('\n') return '\n'.join(buf) @@ -29,106 +29,127 @@ def transform(a, cmds): import unittest # Test Guessing {{{ + + class _BaseGuessing(object): + def runTest(self): - rv, es = guess_edit(self.initial_line, self.a, self.b, Position(*self.ppos), Position(*self.pos)) + rv, es = guess_edit( + self.initial_line, self.a, self.b, Position(*self.ppos), Position(*self.pos)) self.assertEqual(rv, True) self.assertEqual(self.wanted, es) + class TestGuessing_Noop0(_BaseGuessing, unittest.TestCase): a, b = [], [] initial_line = 0 ppos, pos = (0, 6), (0, 7) wanted = () + class TestGuessing_InsertOneChar(_BaseGuessing, unittest.TestCase): - a, b = ["Hello World"], ["Hello World"] + a, b = ['Hello World'], ['Hello World'] initial_line = 0 ppos, pos = (0, 6), (0, 7) wanted = ( - ("I", 0, 6, " "), + ('I', 0, 6, ' '), ) + + class TestGuessing_InsertOneChar1(_BaseGuessing, unittest.TestCase): - a, b = ["Hello World"], ["Hello World"] + a, b = ['Hello World'], ['Hello World'] initial_line = 0 ppos, pos = (0, 7), (0, 8) wanted = ( - ("I", 0, 7, " "), + ('I', 0, 7, ' '), ) + + class TestGuessing_BackspaceOneChar(_BaseGuessing, unittest.TestCase): - a, b = ["Hello World"], ["Hello World"] + a, b = ['Hello World'], ['Hello World'] initial_line = 0 ppos, pos = (0, 7), (0, 6) wanted = ( - ("D", 0, 6, " "), + ('D', 0, 6, ' '), ) + + class TestGuessing_DeleteOneChar(_BaseGuessing, unittest.TestCase): - a, b = ["Hello World"], ["Hello World"] + a, b = ['Hello World'], ['Hello World'] initial_line = 0 ppos, pos = (0, 5), (0, 5) wanted = ( - ("D", 0, 5, " "), + ('D', 0, 5, ' '), ) # End: Test Guessing }}} + class _Base(object): + def runTest(self): es = diff(self.a, self.b) tr = transform(self.a, es) self.assertEqual(self.b, tr) self.assertEqual(self.wanted, es) + class TestEmptyString(_Base, unittest.TestCase): - a, b = "", "" + a, b = '', '' wanted = () + class TestAllMatch(_Base, unittest.TestCase): - a, b = "abcdef", "abcdef" + a, b = 'abcdef', 'abcdef' wanted = () + class TestLotsaNewlines(_Base, unittest.TestCase): - a, b = "Hello", "Hello\nWorld\nWorld\nWorld" + a, b = 'Hello', 'Hello\nWorld\nWorld\nWorld' wanted = ( - ("I", 0, 5, "\n"), - ("I", 1, 0, "World"), - ("I", 1, 5, "\n"), - ("I", 2, 0, "World"), - ("I", 2, 5, "\n"), - ("I", 3, 0, "World"), + ('I', 0, 5, '\n'), + ('I', 1, 0, 'World'), + ('I', 1, 5, '\n'), + ('I', 2, 0, 'World'), + ('I', 2, 5, '\n'), + ('I', 3, 0, 'World'), ) + class TestCrash(_Base, unittest.TestCase): a = 'hallo Blah mitte=sdfdsfsd\nhallo kjsdhfjksdhfkjhsdfkh mittekjshdkfhkhsdfdsf' b = 'hallo Blah mitte=sdfdsfsd\nhallo b mittekjshdkfhkhsdfdsf' wanted = ( - ("D", 1, 6, "kjsdhfjksdhfkjhsdfkh"), - ("I", 1, 6, "b"), + ('D', 1, 6, 'kjsdhfjksdhfkjhsdfkh'), + ('I', 1, 6, 'b'), ) + class TestRealLife(_Base, unittest.TestCase): a = 'hallo End Beginning' b = 'hallo End t' wanted = ( - ("D", 0, 10, "Beginning"), - ("I", 0, 10, "t"), + ('D', 0, 10, 'Beginning'), + ('I', 0, 10, 't'), ) + class TestRealLife1(_Base, unittest.TestCase): a = 'Vorne hallo Hinten' b = 'Vorne hallo Hinten' wanted = ( - ("I", 0, 11, " "), + ('I', 0, 11, ' '), ) + class TestWithNewline(_Base, unittest.TestCase): a = 'First Line\nSecond Line' b = 'n' wanted = ( - ("D", 0, 0, "First Line"), - ("D", 0, 0, "\n"), - ("D", 0, 0, "Second Line"), - ("I", 0, 0, "n"), + ('D', 0, 0, 'First Line'), + ('D', 0, 0, '\n'), + ('D', 0, 0, 'Second Line'), + ('I', 0, 0, 'n'), ) @@ -136,51 +157,56 @@ class TestCheapDelete(_Base, unittest.TestCase): a = 'Vorne hallo Hinten' b = 'Vorne Hinten' wanted = ( - ("D", 0, 5, " hallo"), + ('D', 0, 5, ' hallo'), ) + class TestNoSubstring(_Base, unittest.TestCase): - a,b = "abc", "def" + a, b = 'abc', 'def' wanted = ( - ("D", 0, 0, "abc"), - ("I", 0, 0, "def"), + ('D', 0, 0, 'abc'), + ('I', 0, 0, 'def'), ) + class TestCommonCharacters(_Base, unittest.TestCase): - a,b = "hasomelongertextbl", "hol" + a, b = 'hasomelongertextbl', 'hol' wanted = ( - ("D", 0, 1, "asomelongertextb"), - ("I", 0, 1, "o"), + ('D', 0, 1, 'asomelongertextb'), + ('I', 0, 1, 'o'), ) + class TestUltiSnipsProblem(_Base, unittest.TestCase): - a = "this is it this is it this is it" - b = "this is it a this is it" + a = 'this is it this is it this is it' + b = 'this is it a this is it' wanted = ( - ("D", 0, 11, "this is it"), - ("I", 0, 11, "a"), + ('D', 0, 11, 'this is it'), + ('I', 0, 11, 'a'), ) + class MatchIsTooCheap(_Base, unittest.TestCase): - a = "stdin.h" - b = "s" + a = 'stdin.h' + b = 's' wanted = ( - ("D", 0, 1, "tdin.h"), + ('D', 0, 1, 'tdin.h'), ) + class MultiLine(_Base, unittest.TestCase): - a = "hi first line\nsecond line first line\nsecond line world" - b = "hi first line\nsecond line k world" + a = 'hi first line\nsecond line first line\nsecond line world' + b = 'hi first line\nsecond line k world' wanted = ( - ("D", 1, 12, "first line"), - ("D", 1, 12, "\n"), - ("D", 1, 12, "second line"), - ("I", 1, 12, "k"), + ('D', 1, 12, 'first line'), + ('D', 1, 12, '\n'), + ('D', 1, 12, 'second line'), + ('I', 1, 12, 'k'), ) if __name__ == '__main__': - unittest.main() - # k = TestEditScript() - # unittest.TextTestRunner().run(k) + unittest.main() + # k = TestEditScript() + # unittest.TextTestRunner().run(k) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/test_position.py b/vim/bundle/ultisnips/pythonx/UltiSnips/test_position.py index 7c209a3..f980f4b 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/test_position.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/test_position.py @@ -7,13 +7,16 @@ import unittest from position import Position + class _MPBase(object): + def runTest(self): obj = Position(*self.obj) for pivot, delta, wanted in self.steps: obj.move(Position(*pivot), Position(*delta)) self.assertEqual(Position(*wanted), obj) + class MovePosition_DelSameLine(_MPBase, unittest.TestCase): # hello wor*ld -> h*ld -> hl*ld obj = (0, 9) @@ -21,13 +24,17 @@ class MovePosition_DelSameLine(_MPBase, unittest.TestCase): ((0, 1), (0, -8), (0, 1)), ((0, 1), (0, 1), (0, 2)), ) + + class MovePosition_DelSameLine1(_MPBase, unittest.TestCase): # hel*lo world -> hel*world -> hel*worl - obj = (0,3) + obj = (0, 3) steps = ( - ((0, 4), (0, -3), (0,3)), - ((0, 8), (0, -1), (0,3)), + ((0, 4), (0, -3), (0, 3)), + ((0, 8), (0, -1), (0, 3)), ) + + class MovePosition_InsSameLine1(_MPBase, unittest.TestCase): # hel*lo world -> hel*woresld obj = (0, 3) @@ -36,6 +43,8 @@ class MovePosition_InsSameLine1(_MPBase, unittest.TestCase): ((0, 6), (0, 2), (0, 3)), ((0, 8), (0, -1), (0, 3)) ) + + class MovePosition_InsSameLine2(_MPBase, unittest.TestCase): # hello wor*ld -> helesdlo wor*ld obj = (0, 9) @@ -43,6 +52,7 @@ class MovePosition_InsSameLine2(_MPBase, unittest.TestCase): ((0, 3), (0, 3), (0, 12)), ) + class MovePosition_DelSecondLine(_MPBase, unittest.TestCase): # hello world. sup hello world.*a, was # *a, was ach nix @@ -52,6 +62,8 @@ class MovePosition_DelSecondLine(_MPBase, unittest.TestCase): ((0, 12), (0, -4), (1, 0)), ((0, 12), (-1, 0), (0, 12)), ) + + class MovePosition_DelSecondLine1(_MPBase, unittest.TestCase): # hello world. sup # a, *was @@ -63,7 +75,7 @@ class MovePosition_DelSecondLine1(_MPBase, unittest.TestCase): ((0, 12), (0, -4), (1, 3)), ((0, 12), (-1, 0), (0, 15)), ((0, 12), (0, -3), (0, 12)), - ((0, 12), (0, 1), (0, 13)), + ((0, 12), (0, 1), (0, 13)), ) if __name__ == '__main__': diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text.py new file mode 100644 index 0000000..165cddd --- /dev/null +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# encoding: utf-8 + +"""Utilities to deal with text.""" + + +def unescape(text): + """Removes '\\' escaping from 'text'.""" + rv = '' + i = 0 + while i < len(text): + if i + 1 < len(text) and text[i] == '\\': + rv += text[i + 1] + i += 1 + else: + rv += text[i] + i += 1 + return rv + + +def escape(text, chars): + """Escapes all characters in 'chars' in text using backspaces.""" + rv = '' + for char in text: + if char in chars: + rv += '\\' + rv += char + return rv + + +def fill_in_whitespace(text): + """Returns 'text' with escaped whitespace replaced through whitespaces.""" + text = text.replace(r"\n", '\n') + text = text.replace(r"\t", '\t') + text = text.replace(r"\r", '\r') + text = text.replace(r"\a", '\a') + text = text.replace(r"\b", '\b') + return text + + +def head_tail(line): + """Returns the first word in 'line' and the rest of 'line' or None if the + line is too short.""" + generator = (t.strip() for t in line.split(None, 1)) + head = next(generator).strip() + tail = '' + try: + tail = next(generator).strip() + except StopIteration: + pass + return head, tail + + +class LineIterator(object): + + """Convenience class that keeps track of line numbers in files.""" + + def __init__(self, text): + self._line_index = -1 + self._lines = list(text.splitlines(True)) + + def __iter__(self): + return self + + def __next__(self): + """Returns the next line.""" + if self._line_index + 1 < len(self._lines): + self._line_index += 1 + return self._lines[self._line_index] + raise StopIteration() + next = __next__ # for python2 + + @property + def line_index(self): + """The 1 based line index in the current file.""" + return self._line_index + 1 + + def peek(self): + """Returns the next line (if there is any, otherwise None) without + advancing the iterator.""" + try: + return self._lines[self._line_index + 1] + except IndexError: + return None diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/__init__.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/__init__.py index d9f89ba..97e2252 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/__init__.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/__init__.py @@ -3,4 +3,12 @@ """Public facing classes for TextObjects.""" -from ._snippet_instance import SnippetInstance +from UltiSnips.text_objects._escaped_char import EscapedChar +from UltiSnips.text_objects._mirror import Mirror +from UltiSnips.text_objects._python_code import PythonCode +from UltiSnips.text_objects._shell_code import ShellCode +from UltiSnips.text_objects._snippet_instance import SnippetInstance +from UltiSnips.text_objects._tabstop import TabStop +from UltiSnips.text_objects._transformation import Transformation +from UltiSnips.text_objects._viml_code import VimLCode +from UltiSnips.text_objects._visual import Visual diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_base.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_base.py index 8ddc103..6ee1745 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_base.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_base.py @@ -3,17 +3,19 @@ """Base classes for all text objects.""" -import UltiSnips._vim as _vim +from UltiSnips import _vim from UltiSnips.position import Position + def _calc_end(text, start): """Calculate the end position of the 'text' starting at 'start.""" if len(text) == 1: new_end = start + Position(0, len(text[0])) else: - new_end = Position(start.line + len(text)-1, len(text[-1])) + new_end = Position(start.line + len(text) - 1, len(text[-1])) return new_end + def _text_to_vim(start, end, text): """Copy the given text to the current buffer, overwriting the span 'start' to 'end'.""" @@ -33,30 +35,33 @@ def _text_to_vim(start, end, text): # Open any folds this might have created _vim.buf.cursor = start - _vim.command("normal! zv") + _vim.command('normal! zv') return new_end # These classes use their subclasses a lot and we really do not want to expose # their functions more globally. # pylint: disable=protected-access + + class TextObject(object): + """Represents any object in the text that has a span in any ways.""" - def __init__(self, parent, token, end=None, - initial_text="", tiebreaker=None): + def __init__(self, parent, token_or_start, end=None, + initial_text='', tiebreaker=None): self._parent = parent - if end is not None: # Took 4 arguments - self._start = token + if end is not None: # Took 4 arguments + self._start = token_or_start self._end = end self._initial_text = initial_text - else: # Initialize from token - self._start = token.start - self._end = token.end - self._initial_text = token.initial_text + else: # Initialize from token + self._start = token_or_start.start + self._end = token_or_start.end + self._initial_text = token_or_start.initial_text self._tiebreaker = tiebreaker or Position( - self._start.line, self._end.line) + self._start.line, self._end.line) if parent is not None: parent._add_child(self) @@ -67,27 +72,27 @@ class TextObject(object): def __lt__(self, other): me_tuple = (self.start.line, self.start.col, - self._tiebreaker.line, self._tiebreaker.col) + self._tiebreaker.line, self._tiebreaker.col) other_tuple = (other._start.line, other._start.col, - other._tiebreaker.line, other._tiebreaker.col) + other._tiebreaker.line, other._tiebreaker.col) return me_tuple < other_tuple def __le__(self, other): me_tuple = (self._start.line, self._start.col, - self._tiebreaker.line, self._tiebreaker.col) + self._tiebreaker.line, self._tiebreaker.col) other_tuple = (other._start.line, other._start.col, - other._tiebreaker.line, other._tiebreaker.col) + other._tiebreaker.line, other._tiebreaker.col) return me_tuple <= other_tuple def __repr__(self): - ct = "" + ct = '' try: ct = self.current_text except IndexError: - ct = "" + ct = '' - return "%s(%r->%r,%r)" % (self.__class__.__name__, - self._start, self._end, ct) + return '%s(%r->%r,%r)' % (self.__class__.__name__, + self._start, self._end, ct) @property def current_text(self): @@ -96,7 +101,7 @@ class TextObject(object): return _vim.buf[self._start.line][self._start.col:self._end.col] else: lines = [_vim.buf[self._start.line][self._start.col:]] - lines.extend(_vim.buf[self._start.line+1:self._end.line]) + lines.extend(_vim.buf[self._start.line + 1:self._end.line]) lines.append(_vim.buf[self._end.line][:self._end.col]) return '\n'.join(lines) @@ -112,8 +117,10 @@ class TextObject(object): def overwrite(self, gtext=None): """Overwrite the text of this object in the Vim Buffer and update its - length information. If 'gtext' is None use the initial text of this - object. + length information. + + If 'gtext' is None use the initial text of this object. + """ # We explicitly do not want to move our children around here as we # either have non or we are replacing text initially which means we do @@ -122,7 +129,7 @@ class TextObject(object): return old_end = self._end self._end = _text_to_vim( - self._start, self._end, gtext or self._initial_text) + self._start, self._end, gtext or self._initial_text) if self._parent: self._parent._child_has_moved( self._parent._children.index(self), min(old_end, self._end), @@ -134,14 +141,16 @@ class TextObject(object): Return False if you need to be called again for this edit cycle. Otherwise return True. + """ - raise NotImplementedError("Must be implemented by subclasses.") + raise NotImplementedError('Must be implemented by subclasses.') + class EditableTextObject(TextObject): - """ - This base class represents any object in the text - that can be changed by the user - """ + + """This base class represents any object in the text that can be changed by + the user.""" + def __init__(self, *args, **kwargs): TextObject.__init__(self, *args, **kwargs) self._children = [] @@ -157,7 +166,7 @@ class EditableTextObject(TextObject): @property def _editable_children(self): - """List of all children that are EditableTextObjects""" + """List of all children that are EditableTextObjects.""" return [child for child in self._children if isinstance(child, EditableTextObject)] @@ -169,21 +178,23 @@ class EditableTextObject(TextObject): for children in self._editable_children: if children._start <= pos < children._end: return children.find_parent_for_new_to(pos) + if children._start == pos and pos == children._end: + return children.find_parent_for_new_to(pos) return self ############################### # Private/Protected functions # ############################### - def _do_edit(self, cmd): + def _do_edit(self, cmd, ctab=None): """Apply the edit 'cmd' to this object.""" ctype, line, col, text = cmd - assert ('\n' not in text) or (text == "\n") + assert ('\n' not in text) or (text == '\n') pos = Position(line, col) to_kill = set() new_cmds = [] for child in self._children: - if ctype == "I": # Insertion + if ctype == 'I': # Insertion if (child._start < pos < Position(child._end.line, child._end.col) and isinstance(child, NoneditableTextObject)): @@ -192,11 +203,17 @@ class EditableTextObject(TextObject): break elif ((child._start <= pos <= child._end) and isinstance(child, EditableTextObject)): - child._do_edit(cmd) + if pos == child.end and not child.children: + try: + if ctab.number != child.number: + continue + except AttributeError: + pass + child._do_edit(cmd, ctab) return - else: # Deletion - delend = pos + Position(0, len(text)) if text != "\n" \ - else Position(line + 1, 0) + else: # Deletion + delend = pos + Position(0, len(text)) if text != '\n' \ + else Position(line + 1, 0) if ((child._start <= pos < child._end) and (child._start < delend <= child._end)): # this edit command is completely for the child @@ -205,9 +222,10 @@ class EditableTextObject(TextObject): new_cmds.append(cmd) break else: - child._do_edit(cmd) + child._do_edit(cmd, ctab) return - elif ((pos < child._start and child._end <= delend) or + elif ((pos < child._start and child._end <= delend and + child.start < delend) or (pos <= child._start and child._end < delend)): # Case: this deletion removes the child to_kill.add(child) @@ -216,16 +234,16 @@ class EditableTextObject(TextObject): elif (pos < child._start and (child._start < delend <= child._end)): # Case: partially for us, partially for the child - my_text = text[:(child._start-pos).col] - c_text = text[(child._start-pos).col:] + my_text = text[:(child._start - pos).col] + c_text = text[(child._start - pos).col:] new_cmds.append((ctype, line, col, my_text)) new_cmds.append((ctype, line, col, c_text)) break elif (delend >= child._end and ( child._start <= pos < child._end)): # Case: partially for us, partially for the child - c_text = text[(child._end-pos).col:] - my_text = text[:(child._end-pos).col] + c_text = text[(child._end - pos).col:] + my_text = text[:(child._end - pos).col] new_cmds.append((ctype, line, col, c_text)) new_cmds.append((ctype, line, col, my_text)) break @@ -238,8 +256,8 @@ class EditableTextObject(TextObject): return # We have to handle this ourselves - delta = Position(1, 0) if text == "\n" else Position(0, len(text)) - if ctype == "D": + delta = Position(1, 0) if text == '\n' else Position(0, len(text)) + if ctype == 'D': # Makes no sense to delete in empty textobject if self._start == self._end: return @@ -263,7 +281,7 @@ class EditableTextObject(TextObject): 'diff'.""" self._end.move(pivot, diff) - for child in self._children[idx+1:]: + for child in self._children[idx + 1:]: child._move(pivot, diff) if self._parent: @@ -295,7 +313,6 @@ class EditableTextObject(TextObject): return min(possible_sol) - def _get_prev_tab(self, number): """Returns the previous tabstop before 'number'.""" if not len(self._tabstops.keys()): @@ -321,8 +338,11 @@ class EditableTextObject(TextObject): return max(possible_sol) def _get_tabstop(self, requester, number): - """Returns the tabstop 'number'. 'requester' is the class that is - interested in this.""" + """Returns the tabstop 'number'. + + 'requester' is the class that is interested in this. + + """ if number in self._tabstops: return self._tabstops[number] for child in self._editable_children: @@ -350,13 +370,17 @@ class EditableTextObject(TextObject): child._parent = None self._children.remove(child) - # If this is a tabstop, delete it + # If this is a tabstop, delete it. Might have been deleted already if + # it was nested. try: del self._tabstops[child.number] - except AttributeError: + except (AttributeError, KeyError): pass + class NoneditableTextObject(TextObject): + """All passive text objects that the user can't edit by hand.""" + def _update(self, done): return True diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_escaped_char.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_escaped_char.py index c197abd..3301a26 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_escaped_char.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_escaped_char.py @@ -5,11 +5,12 @@ from UltiSnips.text_objects._base import NoneditableTextObject + class EscapedChar(NoneditableTextObject): + r""" This class is a escape char like \$. It is handled in a text object to make sure that siblings are correctly moved after replacing the text. This is a base class without functionality just to mark it in the code. """ - pass diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_mirror.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_mirror.py index b4e512c..7f8c961 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_mirror.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_mirror.py @@ -5,17 +5,18 @@ from UltiSnips.text_objects._base import NoneditableTextObject + class Mirror(NoneditableTextObject): + """See module docstring.""" def __init__(self, parent, tabstop, token): NoneditableTextObject.__init__(self, parent, token) - self._ts = tabstop def _update(self, done): if self._ts.is_killed: - self.overwrite("") + self.overwrite('') self._parent._del_child(self) # pylint:disable=protected-access return True @@ -26,5 +27,9 @@ class Mirror(NoneditableTextObject): return True def _get_text(self): - """Returns the text used for mirroring. Overwritten by base classes.""" + """Returns the text used for mirroring. + + Overwritten by base classes. + + """ return self._ts.current_text diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_parser.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_parser.py deleted file mode 100644 index bc76e8b..0000000 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_parser.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -"""Parses tokens into text objects.""" - -from UltiSnips.text_objects._lexer import tokenize, EscapeCharToken, \ - VisualToken, TransformationToken, TabStopToken, MirrorToken, \ - PythonCodeToken, VimLCodeToken, ShellCodeToken -from UltiSnips.position import Position -from UltiSnips.text_objects._escaped_char import EscapedChar -from UltiSnips.text_objects._mirror import Mirror -from UltiSnips.text_objects._python_code import PythonCode -from UltiSnips.text_objects._shell_code import ShellCode -from UltiSnips.text_objects._tabstop import TabStop -from UltiSnips.text_objects._transformation import Transformation -from UltiSnips.text_objects._viml_code import VimLCode -from UltiSnips.text_objects._visual import Visual - -_TOKEN_TO_TEXTOBJECT = { - EscapeCharToken: EscapedChar, - VisualToken: Visual, - ShellCodeToken: ShellCode, - PythonCodeToken: PythonCode, - VimLCodeToken: VimLCode, -} - -def _resolve_ambiguity(all_tokens, seen_ts): - """$1 could be a Mirror or a TabStop. This figures this out.""" - for parent, token in all_tokens: - if isinstance(token, MirrorToken): - if token.number not in seen_ts: - seen_ts[token.number] = TabStop(parent, token) - else: - Mirror(parent, seen_ts[token.number], token) - -def _create_transformations(all_tokens, seen_ts): - """Create the objects that need to know about tabstops.""" - for parent, token in all_tokens: - if isinstance(token, TransformationToken): - if token.number not in seen_ts: - raise RuntimeError( - "Tabstop %i is not known but is used by a Transformation" - % token.number) - Transformation(parent, seen_ts[token.number], token) - -def _do_parse(all_tokens, seen_ts, parent_to, text, indent): - """Recursive function that actually creates the objects.""" - tokens = list(tokenize(text, indent, parent_to.start)) - for token in tokens: - all_tokens.append((parent_to, token)) - if isinstance(token, TabStopToken): - ts = TabStop(parent_to, token) - seen_ts[token.number] = ts - - _do_parse(all_tokens, seen_ts, ts, token.initial_text, indent) - else: - klass = _TOKEN_TO_TEXTOBJECT.get(token.__class__, None) - if klass is not None: - klass(parent_to, token) - -def parse_text_object(parent_to, text, indent): - """Parses a text object from 'text' assuming the current 'indent'. Will - instantiate all the objects and link them as children to parent_to. Will - also put the initial text into Vim.""" - seen_ts = {} - all_tokens = [] - - _do_parse(all_tokens, seen_ts, parent_to, text, indent) - _resolve_ambiguity(all_tokens, seen_ts) - _create_transformations(all_tokens, seen_ts) - - if 0 not in seen_ts: - mark = all_tokens[-1][1].end # Last token is always EndOfText - m1 = Position(mark.line, mark.col) - TabStop(parent_to, 0, mark, m1) - parent_to.replace_initial_text() diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_python_code.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_python_code.py index c9c3e66..5404dca 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_python_code.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_python_code.py @@ -6,73 +6,147 @@ import os from collections import namedtuple +from UltiSnips import _vim from UltiSnips.compatibility import as_unicode from UltiSnips.indent_util import IndentUtil from UltiSnips.text_objects._base import NoneditableTextObject -import UltiSnips._vim as _vim +from UltiSnips.vim_state import _Placeholder +import UltiSnips.snippet_manager class _Tabs(object): + """Allows access to tabstop content via t[] inside of python code.""" + def __init__(self, to): self._to = to def __getitem__(self, no): - ts = self._to._get_tabstop(self._to, int(no)) # pylint:disable=protected-access + ts = self._to._get_tabstop( + self._to, + int(no)) # pylint:disable=protected-access if ts is None: - return "" + return '' return ts.current_text + def __setitem__(self, no, value): + ts = self._to._get_tabstop( + self._to, + int(no)) # pylint:disable=protected-access + if ts is None: + return + ts.overwrite(value) + _VisualContent = namedtuple('_VisualContent', ['mode', 'text']) + +class SnippetUtilForAction(dict): + def __init__(self, *args, **kwargs): + super(SnippetUtilForAction, self).__init__(*args, **kwargs) + self.__dict__ = self + + def expand_anon(self, *args, **kwargs): + UltiSnips.snippet_manager.UltiSnips_Manager.expand_anon( + *args, **kwargs + ) + self.cursor.preserve() + + +class SnippetUtilCursor(object): + def __init__(self, cursor): + self._cursor = [cursor[0] - 1, cursor[1]] + self._set = False + + def preserve(self): + self._set = True + self._cursor = [ + _vim.buf.cursor[0], + _vim.buf.cursor[1], + ] + + def is_set(self): + return self._set + + def set(self, line, column): + self.__setitem__(0, line) + self.__setitem__(1, column) + + def to_vim_cursor(self): + return (self._cursor[0] + 1, self._cursor[1]) + + def __getitem__(self, index): + return self._cursor[index] + + def __setitem__(self, index, value): + self._set = True + self._cursor[index] = value + + def __len__(self): + return 2 + + def __str__(self): + return str((self._cursor[0], self._cursor[1])) + + class SnippetUtil(object): - """Provides easy access to indentation, etc. This is the 'snip' object in - python code.""" - def __init__(self, initial_indent, vmode, vtext): + """Provides easy access to indentation, etc. + + This is the 'snip' object in python code. + + """ + + def __init__(self, initial_indent, vmode, vtext, context, parent): self._ind = IndentUtil() self._visual = _VisualContent(vmode, vtext) self._initial_indent = self._ind.indent_to_spaces(initial_indent) - self._reset("") + self._reset('') + self._context = context + self._start = parent.start + self._end = parent.end + self._parent = parent def _reset(self, cur): """Gets the snippet ready for another update. + :cur: the new value for c. + """ self._ind.reset() self._cur = cur - self._rv = "" + self._rv = '' self._changed = False self.reset_indent() def shift(self, amount=1): - """Shifts the indentation level. - Note that this uses the shiftwidth because thats what code - formatters use. + """Shifts the indentation level. Note that this uses the shiftwidth + because thats what code formatters use. :amount: the amount by which to shift. + """ - self.indent += " " * self._ind.shiftwidth * amount + self.indent += ' ' * self._ind.shiftwidth * amount def unshift(self, amount=1): - """Unshift the indentation level. - Note that this uses the shiftwidth because thats what code - formatters use. + """Unshift the indentation level. Note that this uses the shiftwidth + because thats what code formatters use. :amount: the amount by which to unshift. + """ by = -self._ind.shiftwidth * amount try: self.indent = self.indent[:by] except IndexError: - self.indent = "" + self.indent = '' - def mkline(self, line="", indent=None): + def mkline(self, line='', indent=None): """Creates a properly set up line. :line: the text to add :indent: the indentation to have at the beginning if None, it uses the default amount + """ if indent is None: indent = self.indent @@ -82,7 +156,7 @@ class SnippetUtil(object): try: indent = indent[len(self._initial_indent):] except IndexError: - indent = "" + indent = '' indent = self._ind.spaces_to_indent(indent) return indent + line @@ -95,22 +169,25 @@ class SnippetUtil(object): @property def fn(self): # pylint:disable=no-self-use,invalid-name """The filename.""" - return _vim.eval('expand("%:t")') or "" + return _vim.eval('expand("%:t")') or '' @property def basename(self): # pylint:disable=no-self-use """The filename without extension.""" - return _vim.eval('expand("%:t:r")') or "" + return _vim.eval('expand("%:t:r")') or '' @property def ft(self): # pylint:disable=invalid-name """The filetype.""" - return self.opt("&filetype", "") + return self.opt('&filetype', '') @property def rv(self): # pylint:disable=invalid-name - """The return value. The text to insert at the location of the - placeholder.""" + """The return value. + + The text to insert at the location of the placeholder. + + """ return self._rv @rv.setter @@ -131,12 +208,23 @@ class SnippetUtil(object): @property def v(self): # pylint:disable=invalid-name - """Content of visual expansions""" + """Content of visual expansions.""" return self._visual + @property + def p(self): + if self._parent.current_placeholder: + return self._parent.current_placeholder + else: + return _Placeholder('', 0, 0) + + @property + def context(self): + return self._context + def opt(self, option, default=None): # pylint:disable=no-self-use """Gets a Vim variable.""" - if _vim.eval("exists('%s')" % option) == "1": + if _vim.eval("exists('%s')" % option) == '1': try: return _vim.eval(option) except _vim.error: @@ -157,8 +245,27 @@ class SnippetUtil(object): """Same as shift.""" self.shift(other) + @property + def snippet_start(self): + """ + Returns start of the snippet in format (line, column). + """ + return self._start + + @property + def snippet_end(self): + """ + Returns end of the snippet in format (line, column). + """ + return self._end + + @property + def buffer(self): + return _vim.buf + class PythonCode(NoneditableTextObject): + """See module docstring.""" def __init__(self, parent, token): @@ -170,20 +277,21 @@ class PythonCode(NoneditableTextObject): self._locals = snippet.locals text = snippet.visual_content.text mode = snippet.visual_content.mode + context = snippet.context break - except AttributeError: + except AttributeError as e: snippet = snippet._parent # pylint:disable=protected-access - self._snip = SnippetUtil(token.indent, mode, text) + self._snip = SnippetUtil(token.indent, mode, text, context, snippet) self._codes = (( - "import re, os, vim, string, random", - "\n".join(snippet.globals.get("!p", [])).replace("\r\n", "\n"), - token.code.replace("\\`", "`") + 'import re, os, vim, string, random', + '\n'.join(snippet.globals.get('!p', [])).replace('\r\n', '\n'), + token.code.replace('\\`', '`') )) NoneditableTextObject.__init__(self, parent, token) def _update(self, done): - path = _vim.eval('expand("%")') or "" + path = _vim.eval('expand("%")') or '' ct = self.current_text self._locals.update({ 't': _Tabs(self._parent), @@ -196,7 +304,11 @@ class PythonCode(NoneditableTextObject): self._snip._reset(ct) # pylint:disable=protected-access for code in self._codes: - exec(code, self._locals) # pylint:disable=exec-used + try: + exec(code, self._locals) # pylint:disable=exec-used + except Exception as e: + e.snippet_code = code + raise rv = as_unicode( self._snip.rv if self._snip._rv_changed # pylint:disable=protected-access diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_shell_code.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_shell_code.py index 3e9099a..a7ad964 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_shell_code.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_shell_code.py @@ -12,6 +12,7 @@ import tempfile from UltiSnips.compatibility import as_unicode from UltiSnips.text_objects._base import NoneditableTextObject + def _chomp(string): """Rather than rstrip(), remove only the last newline and preserve purposeful whitespace.""" @@ -21,8 +22,9 @@ def _chomp(string): string = string[:-1] return string + def _run_shell_command(cmd, tmpdir): - """Write the code to a temporary file""" + """Write the code to a temporary file.""" cmdsuf = '' if platform.system() == 'Windows': # suffix required to run command on windows @@ -30,7 +32,7 @@ def _run_shell_command(cmd, tmpdir): # turn echo off cmd = '@echo off\r\n' + cmd handle, path = tempfile.mkstemp(text=True, dir=tmpdir, suffix=cmdsuf) - os.write(handle, cmd.encode("utf-8")) + os.write(handle, cmd.encode('utf-8')) os.close(handle) os.chmod(path, stat.S_IRWXU) @@ -41,29 +43,32 @@ def _run_shell_command(cmd, tmpdir): os.unlink(path) return _chomp(as_unicode(stdout)) + def _get_tmp(): """Find an executable tmp directory.""" - userdir = os.path.expanduser("~") + userdir = os.path.expanduser('~') for testdir in [tempfile.gettempdir(), os.path.join(userdir, '.cache'), - os.path.join(userdir, '.tmp'), userdir]: + os.path.join(userdir, '.tmp'), userdir]: if (not os.path.exists(testdir) or not _run_shell_command('echo success', testdir) == 'success'): continue return testdir return '' + class ShellCode(NoneditableTextObject): + """See module docstring.""" def __init__(self, parent, token): NoneditableTextObject.__init__(self, parent, token) - self._code = token.code.replace("\\`", "`") + self._code = token.code.replace('\\`', '`') self._tmpdir = _get_tmp() def _update(self, done): if not self._tmpdir: output = \ - "Unable to find executable tmp directory, check noexec on /tmp" + 'Unable to find executable tmp directory, check noexec on /tmp' else: output = _run_shell_command(self._code, self._tmpdir) self.overwrite(output) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_snippet_instance.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_snippet_instance.py index a9c12a6..60c1db1 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_snippet_instance.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_snippet_instance.py @@ -1,22 +1,28 @@ #!/usr/bin/env python # encoding: utf-8 -"""A Snippet instance is an instance of a Snippet Definition. That is, when the -user expands a snippet, a SnippetInstance is created to keep track of the -corresponding TextObjects. The Snippet itself is also a TextObject. """ +"""A Snippet instance is an instance of a Snippet Definition. +That is, when the user expands a snippet, a SnippetInstance is created +to keep track of the corresponding TextObjects. The Snippet itself is +also a TextObject. + +""" + +from UltiSnips import _vim from UltiSnips.position import Position -import UltiSnips._vim as _vim from UltiSnips.text_objects._base import EditableTextObject, \ - NoneditableTextObject -from UltiSnips.text_objects._parser import parse_text_object + NoneditableTextObject +from UltiSnips.text_objects._tabstop import TabStop + class SnippetInstance(EditableTextObject): + """See module docstring.""" # pylint:disable=protected-access - def __init__(self, snippet, parent, indent, initial_text, - start, end, visual_content, last_re, globals): + def __init__(self, snippet, parent, initial_text, + start, end, visual_content, last_re, globals, context): if start is None: start = Position(0, 0) if end is None: @@ -24,16 +30,14 @@ class SnippetInstance(EditableTextObject): self.snippet = snippet self._cts = 0 - self.locals = {"match" : last_re} + self.context = context + self.locals = {'match': last_re, 'context': context} self.globals = globals self.visual_content = visual_content + self.current_placeholder = None EditableTextObject.__init__(self, parent, start, end, initial_text) - parse_text_object(self, initial_text, indent) - - self.update_textobjects() - def replace_initial_text(self): """Puts the initial text of all text elements into Vim.""" def _place_initial_text(obj): @@ -44,19 +48,23 @@ class SnippetInstance(EditableTextObject): _place_initial_text(child) _place_initial_text(self) - def replay_user_edits(self, cmds): - """Replay the edits the user has done to keep endings of our - Text objects in sync with reality""" + def replay_user_edits(self, cmds, ctab=None): + """Replay the edits the user has done to keep endings of our Text + objects in sync with reality.""" for cmd in cmds: - self._do_edit(cmd) + self._do_edit(cmd, ctab) def update_textobjects(self): - """Update the text objects that should change automagically after - the users edits have been replayed. This might also move the Cursor + """Update the text objects that should change automagically after the + users edits have been replayed. + + This might also move the Cursor + """ vc = _VimCursor(self) done = set() not_done = set() + def _find_recursive(obj): """Finds all text objects and puts them into 'not_done'.""" if isinstance(obj, EditableTextObject): @@ -74,10 +82,10 @@ class SnippetInstance(EditableTextObject): counter -= 1 if not counter: raise RuntimeError( - "The snippets content did not converge: Check for Cyclic " - "dependencies or random strings in your snippet. You can use " + 'The snippets content did not converge: Check for Cyclic ' + 'dependencies or random strings in your snippet. You can use ' "'if not snip.c' to make sure to only expand random output " - "once.") + 'once.') vc.to_vim() self._del_child(vc) @@ -99,7 +107,16 @@ class SnippetInstance(EditableTextObject): res = self._get_next_tab(self._cts) if res is None: self._cts = None - return self._tabstops.get(0, None) + + ts = self._get_tabstop(self, 0) + if ts: + return ts + + # TabStop 0 was deleted. It was probably killed through some + # edit action. Recreate it at the end of us. + start = Position(self.end.line, self.end.col) + end = Position(self.end.line, self.end.col) + return TabStop(self, 0, start, end) else: self._cts, ts = res return ts @@ -115,8 +132,12 @@ class SnippetInstance(EditableTextObject): self._parent = cached_parent return rv + def get_tabstops(self): + return self._tabstops + class _VimCursor(NoneditableTextObject): + """Helper class to keep track of the Vim Cursor when text objects expand and move.""" diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_tabstop.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_tabstop.py index 4eff6af..f113f75 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_tabstop.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_tabstop.py @@ -1,12 +1,18 @@ #!/usr/bin/env python # encoding: utf-8 -"""This is the most important TextObject. A TabStop is were the cursor -comes to rest when the user taps through the Snippet.""" +"""This is the most important TextObject. + +A TabStop is were the cursor comes to rest when the user taps through +the Snippet. + +""" from UltiSnips.text_objects._base import EditableTextObject + class TabStop(EditableTextObject): + """See module docstring.""" def __init__(self, parent, token, start=None, end=None): @@ -16,7 +22,8 @@ class TabStop(EditableTextObject): else: self._number = token.number EditableTextObject.__init__(self, parent, token) - parent._tabstops[self._number] = self # pylint:disable=protected-access + parent._tabstops[ + self._number] = self # pylint:disable=protected-access @property def number(self): @@ -28,3 +35,11 @@ class TabStop(EditableTextObject): """True if this tabstop has been typed over and the user therefore can no longer jump to it.""" return self._parent is None + + def __repr__(self): + try: + text = self.current_text + except IndexError: + text = '' + return 'TabStop(%s,%r->%r,%r)' % (self.number, self._start, + self._end, text) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_transformation.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_transformation.py index bf8f495..b9da88f 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_transformation.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_transformation.py @@ -5,50 +5,65 @@ import re import sys + +from UltiSnips.text import unescape, fill_in_whitespace from UltiSnips.text_objects._mirror import Mirror -from UltiSnips.escaping import unescape, fill_in_whitespace + def _find_closing_brace(string, start_pos): """Finds the corresponding closing brace after start_pos.""" bracks_open = 1 + escaped = False for idx, char in enumerate(string[start_pos:]): if char == '(': - if string[idx+start_pos-1] != '\\': + if not escaped: bracks_open += 1 elif char == ')': - if string[idx+start_pos-1] != '\\': + if not escaped: bracks_open -= 1 if not bracks_open: - return start_pos+idx+1 + return start_pos + idx + 1 + if char == '\\': + escaped = not escaped + else: + escaped = False + def _split_conditional(string): """Split the given conditional 'string' into its arguments.""" bracks_open = 0 args = [] - carg = "" + carg = '' + escaped = False for idx, char in enumerate(string): if char == '(': - if string[idx-1] != '\\': + if not escaped: bracks_open += 1 elif char == ')': - if string[idx-1] != '\\': + if not escaped: bracks_open -= 1 - elif char == ':' and not bracks_open and not string[idx-1] == '\\': + elif char == ':' and not bracks_open and not escaped: args.append(carg) - carg = "" + carg = '' + escaped = False continue carg += char + if char == '\\': + escaped = not escaped + else: + escaped = False args.append(carg) return args + def _replace_conditional(match, string): """Replaces a conditional match in a transformation.""" conditional_match = _CONDITIONAL.search(string) while conditional_match: start = conditional_match.start() - end = _find_closing_brace(string, start+4) - args = _split_conditional(string[start+4:end-1]) - rv = "" + end = _find_closing_brace(string, start + 4) + args = _split_conditional(string[start + 4:end - 1]) + rv = '' if match.group(int(conditional_match.group(1))): rv = unescape(_replace_conditional(match, args[0])) elif len(args) > 1: @@ -61,7 +76,10 @@ _ONE_CHAR_CASE_SWITCH = re.compile(r"\\([ul].)", re.DOTALL) _LONG_CASEFOLDINGS = re.compile(r"\\([UL].*?)\\E", re.DOTALL) _DOLLAR = re.compile(r"\$(\d+)", re.DOTALL) _CONDITIONAL = re.compile(r"\(\?(\d+):", re.DOTALL) + + class _CleverReplace(object): + """Mimics TextMates replace syntax.""" def __init__(self, expression): @@ -72,7 +90,7 @@ class _CleverReplace(object): transformed = self._expression # Replace all $? with capture groups transformed = _DOLLAR.subn( - lambda m: match.group(int(m.group(1))), transformed)[0] + lambda m: match.group(int(m.group(1))), transformed)[0] # Replace Case switches def _one_char_case_change(match): @@ -82,7 +100,7 @@ class _CleverReplace(object): else: return match.group(1)[-1].lower() transformed = _ONE_CHAR_CASE_SWITCH.subn( - _one_char_case_change, transformed)[0] + _one_char_case_change, transformed)[0] def _multi_char_case_change(match): """Replaces multi character case changes.""" @@ -91,13 +109,16 @@ class _CleverReplace(object): else: return match.group(1)[1:].lower() transformed = _LONG_CASEFOLDINGS.subn( - _multi_char_case_change, transformed)[0] + _multi_char_case_change, transformed)[0] transformed = _replace_conditional(match, transformed) return unescape(fill_in_whitespace(transformed)) # flag used to display only one time the lack of unidecode UNIDECODE_ALERT_RAISED = False + + class TextObjectTransformation(object): + """Base class for Transformations and ${VISUAL}.""" def __init__(self, token): @@ -110,11 +131,13 @@ class TextObjectTransformation(object): flags = 0 self._match_this_many = 1 if token.options: - if "g" in token.options: + if 'g' in token.options: self._match_this_many = 0 - if "i" in token.options: + if 'i' in token.options: flags |= re.IGNORECASE - if "a" in token.options: + if 'm' in token.options: + flags |= re.MULTILINE + if 'a' in token.options: self._convert_to_ascii = True self._find = re.compile(token.search, flags | re.DOTALL) @@ -131,14 +154,16 @@ class TextObjectTransformation(object): if UNIDECODE_ALERT_RAISED == False: UNIDECODE_ALERT_RAISED = True sys.stderr.write( - "Please install unidecode python package in order to " - "be able to make ascii conversions.\n") + 'Please install unidecode python package in order to ' + 'be able to make ascii conversions.\n') if self._find is None: return text return self._find.subn( - self._replace.replace, text, self._match_this_many)[0] + self._replace.replace, text, self._match_this_many)[0] + class Transformation(Mirror, TextObjectTransformation): + """See module docstring.""" def __init__(self, parent, ts, token): diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_viml_code.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_viml_code.py index 18ffd85..86329bf 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_viml_code.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_viml_code.py @@ -3,13 +3,16 @@ """Implements `!v ` VimL interpolation.""" -import UltiSnips._vim as _vim +from UltiSnips import _vim from UltiSnips.text_objects._base import NoneditableTextObject + class VimLCode(NoneditableTextObject): + """See module docstring.""" + def __init__(self, parent, token): - self._code = token.code.replace("\\`", "`").strip() + self._code = token.code.replace('\\`', '`').strip() NoneditableTextObject.__init__(self, parent, token) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_visual.py b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_visual.py index af5ca4e..0be64b3 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_visual.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/text_objects/_visual.py @@ -2,19 +2,25 @@ # encoding: utf-8 """A ${VISUAL} placeholder that will use the text that was last visually -selected and insert it here. If there was no text visually selected, this will -be the empty string. """ +selected and insert it here. + +If there was no text visually selected, this will be the empty string. + +""" import re import textwrap -import UltiSnips._vim as _vim +from UltiSnips import _vim from UltiSnips.indent_util import IndentUtil from UltiSnips.text_objects._transformation import TextObjectTransformation from UltiSnips.text_objects._base import NoneditableTextObject _REPLACE_NON_WS = re.compile(r"[^ \t]") + + class Visual(NoneditableTextObject, TextObjectTransformation): + """See module docstring.""" def __init__(self, parent, token): @@ -29,27 +35,27 @@ class Visual(NoneditableTextObject, TextObjectTransformation): snippet = snippet._parent # pylint:disable=protected-access if not self._text: self._text = token.alternative_text - self._mode = "v" + self._mode = 'v' NoneditableTextObject.__init__(self, parent, token) TextObjectTransformation.__init__(self, token) def _update(self, done): - if self._mode == "v": # Normal selection. + if self._mode == 'v': # Normal selection. text = self._text else: # Block selection or line selection. text_before = _vim.buf[self.start.line][:self.start.col] - indent = _REPLACE_NON_WS.sub(" ", text_before) + indent = _REPLACE_NON_WS.sub(' ', text_before) iu = IndentUtil() indent = iu.indent_to_spaces(indent) indent = iu.spaces_to_indent(indent) - text = "" + text = '' for idx, line in enumerate(textwrap.dedent( self._text).splitlines(True)): if idx != 0: text += indent text += line - text = text[:-1] # Strip final '\n' + text = text[:-1] # Strip final '\n' text = self._transform(text) self.overwrite(text) diff --git a/vim/bundle/ultisnips/pythonx/UltiSnips/vim_state.py b/vim/bundle/ultisnips/pythonx/UltiSnips/vim_state.py index ccaded8..18914ee 100644 --- a/vim/bundle/ultisnips/pythonx/UltiSnips/vim_state.py +++ b/vim/bundle/ultisnips/pythonx/UltiSnips/vim_state.py @@ -3,19 +3,22 @@ """Some classes to conserve Vim's state for comparing over time.""" -from collections import deque +from collections import deque, namedtuple +from UltiSnips import _vim from UltiSnips.compatibility import as_unicode, byte2col from UltiSnips.position import Position -import UltiSnips._vim as _vim + +_Placeholder = namedtuple('_FrozenPlaceholder', ['current_text', 'start', 'end']) class VimPosition(Position): + """Represents the current position in the buffer, together with some status variables that might change our decisions down the line.""" def __init__(self): pos = _vim.buf.cursor - self._mode = _vim.eval("mode()") + self._mode = _vim.eval('mode()') Position.__init__(self, pos.line, pos.col) @property @@ -23,7 +26,9 @@ class VimPosition(Position): """Returns the mode() this position was created.""" return self._mode + class VimState(object): + """Caches some state information from Vim to better guess what editing tasks the user might have done in the last step.""" @@ -31,27 +36,38 @@ class VimState(object): self._poss = deque(maxlen=5) self._lvb = None - self._text_to_expect = None - self._unnamed_reg_cache = None + self._text_to_expect = '' self._unnamed_reg_cached = False + # We store the cached value of the unnamed register in Vim directly to + # avoid any Unicode issues with saving and restoring the unnamed + # register across the Python bindings. The unnamed register can contain + # data that cannot be coerced to Unicode, and so a simple vim.eval('@"') + # fails badly. Keeping the cached value in Vim directly, sidesteps the + # problem. + _vim.command('let g:_ultisnips_unnamed_reg_cache = ""') + def remember_unnamed_register(self, text_to_expect): - """Save the unnamed register. 'text_to_expect' is text that we expect + """Save the unnamed register. + + 'text_to_expect' is text that we expect to be contained in the register the next time this method is called - this could be text from the tabstop that was selected and might have - been overwritten. We will not cash that then.""" + been overwritten. We will not cache that then. + + """ self._unnamed_reg_cached = True - unnamed_reg = _vim.eval('@"') - if unnamed_reg != self._text_to_expect: - self._unnamed_reg_cache = unnamed_reg + escaped_text = self._text_to_expect.replace("'", "''") + res = int(_vim.eval('@" != ' + "'" + escaped_text + "'")) + if res: + _vim.command('let g:_ultisnips_unnamed_reg_cache = @"') self._text_to_expect = text_to_expect def restore_unnamed_register(self): """Restores the unnamed register and forgets what we cached.""" if not self._unnamed_reg_cached: return - escaped_cache = self._unnamed_reg_cache.replace("'", "''") - _vim.command("let @\"='%s'" % escaped_cache) + _vim.command('let @" = g:_ultisnips_unnamed_reg_cache') self._unnamed_reg_cached = False def remember_position(self): @@ -60,7 +76,7 @@ class VimState(object): def remember_buffer(self, to): """Remember the content of the buffer and the position.""" - self._lvb = _vim.buf[to.start.line:to.end.line+1] + self._lvb = _vim.buf[to.start.line:to.end.line + 1] self._lvb_len = len(_vim.buf) self.remember_position() @@ -85,7 +101,9 @@ class VimState(object): """The content of the remembered buffer.""" return self._lvb[:] + class VisualContentPreserver(object): + """Saves the current visual selection and the selection mode it was done in (e.g. line selection, block selection or regular selection.)""" @@ -94,30 +112,41 @@ class VisualContentPreserver(object): def reset(self): """Forget the preserved state.""" - self._mode = "" - self._text = as_unicode("") + self._mode = '' + self._text = as_unicode('') + self._placeholder = None def conserve(self): """Save the last visual selection ond the mode it was made in.""" sl, sbyte = map(int, - (_vim.eval("""line("'<")"""), _vim.eval("""col("'<")"""))) + (_vim.eval("""line("'<")"""), _vim.eval("""col("'<")"""))) el, ebyte = map(int, - (_vim.eval("""line("'>")"""), _vim.eval("""col("'>")"""))) + (_vim.eval("""line("'>")"""), _vim.eval("""col("'>")"""))) sc = byte2col(sl, sbyte - 1) ec = byte2col(el, ebyte - 1) - self._mode = _vim.eval("visualmode()") + self._mode = _vim.eval('visualmode()') _vim_line_with_eol = lambda ln: _vim.buf[ln] + '\n' if sl == el: - text = _vim_line_with_eol(sl-1)[sc:ec+1] + text = _vim_line_with_eol(sl - 1)[sc:ec + 1] else: - text = _vim_line_with_eol(sl-1)[sc:] - for cl in range(sl, el-1): + text = _vim_line_with_eol(sl - 1)[sc:] + for cl in range(sl, el - 1): text += _vim_line_with_eol(cl) - text += _vim_line_with_eol(el-1)[:ec+1] + text += _vim_line_with_eol(el - 1)[:ec + 1] self._text = text + def conserve_placeholder(self, placeholder): + if placeholder: + self._placeholder = _Placeholder( + placeholder.current_text, + placeholder.start, + placeholder.end + ) + else: + self._placeholder = None + @property def text(self): """The conserved text.""" @@ -127,3 +156,8 @@ class VisualContentPreserver(object): def mode(self): """The conserved visualmode().""" return self._mode + + @property + def placeholder(self): + """Returns latest selected placeholder.""" + return self._placeholder diff --git a/vim/bundle/ultisnips/rplugin/python3/deoplete/sources/ultisnips.py b/vim/bundle/ultisnips/rplugin/python3/deoplete/sources/ultisnips.py new file mode 100644 index 0000000..ba35dfc --- /dev/null +++ b/vim/bundle/ultisnips/rplugin/python3/deoplete/sources/ultisnips.py @@ -0,0 +1,21 @@ +from .base import Base + +class Source(Base): + def __init__(self, vim): + Base.__init__(self, vim) + + self.name = 'ultisnips' + self.mark = '[US]' + self.rank = 8 + + def gather_candidates(self, context): + suggestions = [] + snippets = self.vim.eval( + 'UltiSnips#SnippetsInCurrentScope()') + for trigger in snippets: + suggestions.append({ + 'word': trigger, + 'menu': self.mark + ' ' + snippets.get(trigger, ''), + 'dup': 1 + }) + return suggestions diff --git a/vim/bundle/ultisnips/syntax/snippets.vim b/vim/bundle/ultisnips/syntax/snippets.vim index 085b408..f7782fb 100644 --- a/vim/bundle/ultisnips/syntax/snippets.vim +++ b/vim/bundle/ultisnips/syntax/snippets.vim @@ -5,68 +5,220 @@ if exists("b:current_syntax") finish endif -syntax include @Python syntax/python.vim -syntax include @Viml syntax/vim.vim - -" global matches -syn match snipComment "^#.*" contains=snipTODO -syn keyword snipTODO FIXME NOTE NOTES TODO XXX contained - -syn match snipDocString '"[^"]*"$' -syn match snipString '"[^"]*"' -syn match snipTabsOnly "^\t\+$" -syn match snipLeadingSpaces "^\t* \+" - -syn match snipKeyword "\(\<\(end\)\?\(snippet\|global\)\>\)\|extends\|clearsnippets\|priority" contained - -" extends definitions -syn match snipExtends "^extends.*" contains=snipKeyword - -" snippet definitions -syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString -syn match snipEnd "^endsnippet" contained contains=snipKeyword -syn region snipCommand contained keepend start="`" end="`" contains=snipPythonCommand,snipVimLCommand -syn region snipPythonCommand contained keepend start="`!p" end="`" contained contains=@Python -syn region snipVimLCommand contained keepend start="`!v" end="`" contained contains=@Viml -syn match snipVar "\$\d*" contained -syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained -syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand -syn region snippet fold keepend start="^snippet" end="^endsnippet" contains=snipStart,snipEnd,snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual - -" global definitions -syn match snipGlobalStart "^global.*" contained contains=snipKeyword,snipString -syn match snipGlobalEnd "^endglobal" contained contains=snipKeyword -syn region snipGlobal fold keepend start="^global" end="^endglobal" contains=snipGlobalStart,snipGlobalEnd,snipLeadingSpaces,snipTabsOnly,snipCommand,snipVarExpansion,snipVar,@Python - -" snippet clearing -syn match snipClear "^clearsnippets" -syn match snipPriority "^priority" - -" highlighting rules - -hi link snipComment Comment -hi link snipLeadingSpaces Error -hi link snipString String -hi link snipDocString String -hi link snipTabsOnly Error - -hi link snipKeyword Keyword - -hi link snipExtends Statement - -hi link snipStart Statement -hi link snipEnd Statement -hi link snipCommand Special -hi link snipVar StorageClass -hi link snipVarExpansion Normal -hi link snipVisual Normal -hi link snippet Normal - -hi link snipGlobalStart Statement -hi link snipGlobalEnd Statement -hi link snipGlobal Normal - -hi link snipClear Statement -hi link snipPriority Statement - -let b:current_syntax = "snippet" +if expand("%:p:h:t") == "snippets" && search("^endsnippet", "nw") == 0 + \ && !exists("b:ultisnips_override_snipmate") + " this appears to be a snipmate file + " It's in a directory called snippets/ and there's no endsnippet keyword + " anywhere in the file. + source :h/snippets_snipmate.vim + finish +endif + +" Embedded Syntaxes {{{1 + +try + syntax include @Python syntax/python.vim + unlet b:current_syntax + syntax include @Viml syntax/vim.vim + unlet b:current_syntax + syntax include @Shell syntax/sh.vim + unlet b:current_syntax +catch /E403/ + " Ignore errors about syntax files that can't be loaded more than once +endtry + +" Syntax definitions {{{1 + +" Comments {{{2 + +syn match snipComment "^#.*" contains=snipTODO display +syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX + +" Errors {{{2 + +syn match snipLeadingSpaces "^\t* \+" contained + +" Extends {{{2 + +syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display +syn match snipExtendsKeyword "^extends" contained display + +" Definitions {{{2 + +" snippet {{{3 + +syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend +syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword +syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite +syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained nextgroup=snipSnippetFooter contains=snipLeadingSpaces,@snipTokens +syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword +syn match snipSnippetFooterKeyword "^endsnippet" contained + +" The current parser is a bit lax about parsing. For example, given this: +" snippet foo"bar" +" it treats `foo"bar"` as the trigger. But with this: +" snippet foo"bar baz" +" it treats `foo` as the trigger and "bar baz" as the description. +" I think this is an accident. Instead, we'll assume the description must +" be surrounded by spaces. That means we'll treat +" snippet foo"bar" +" as a trigger `foo"bar"` and +" snippet foo"bar baz" +" as an attempted multiword snippet `foo"bar baz"` that is invalid. +" NB: UltiSnips parses right-to-left, which Vim doesn't support, so that makes +" the following patterns very complicated. +syn match snipSnippetTrigger "\S\+" contained nextgroup=snipSnippetDocString,snipSnippetTriggerInvalid skipwhite +" We want to match a trailing " as the start of a doc comment, but we also +" want to allow for using " as the delimiter in a multiword/pattern snippet. +" So we have to define this twice, once in the general case that matches a +" trailing " as the doc comment, and once for the case of the multiword +" delimiter using " that has more constraints +syn match snipSnippetTrigger ,".\{-}"\ze\%(\s\+"\%(\s*\S\)\@=[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite +syn match snipSnippetTrigger ,\%(\(\S\).\{-}\1\|\S\+\)\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocContextString skipwhite +syn match snipSnippetTrigger ,\([^"[:space:]]\).\{-}\1\%(\s*$\)\@!\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\|[^"[:space:]]\+\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite +syn match snipSnippetTriggerInvalid ,\S\@=.\{-}\S\ze\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\s*\|"\s*\)\=\|\s*\)$, contained nextgroup=snipSnippetDocString skipwhite +syn match snipSnippetDocString ,"[^"]*", contained nextgroup=snipSnippetOptions skipwhite +syn match snipSnippetDocContextString ,"[^"]*", contained nextgroup=snipSnippetContext skipwhite +syn match snipSnippetContext ,"[^"]\+", contained skipwhite contains=snipSnippetContextP +syn region snipSnippetContextP start=,"\@<=., end=,\ze", contained contains=@Python nextgroup=snipSnippetOptions skipwhite keepend +syn match snipSnippetOptions ,\S\+, contained contains=snipSnippetOptionFlag +syn match snipSnippetOptionFlag ,[biwrtsmxAe], contained + +" Command substitution {{{4 + +syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride +syn region snipShellCommand start="\ze\_." skip="\\[{}\\$`]" end="\ze`" contained contains=@Shell +syn region snipPythonCommand matchgroup=snipPythonCommandP start="`\@<=!p\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Python +syn region snipVimLCommand matchgroup=snipVimLCommandV start="`\@<=!v\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Viml +syn cluster snipTokens add=snipCommand +syn cluster snipTabStopTokens add=snipCommand + +" unfortunately due to the balanced braces parsing of commands, if a { occurs +" in the command, we need to prevent the embedded syntax highlighting. +" Otherwise, we can't track the balanced braces properly. + +syn region snipCommandSyntaxOverride start="\%(\\[{}\\$`]\|\_[^`"{]\)*\ze{" skip="\\[{}\\$`]" end="\ze`" contained contains=snipBalancedBraces transparent + +" Tab Stops {{{4 + +syn match snipEscape "\\[{}\\$`]" contained +syn cluster snipTokens add=snipEscape +syn cluster snipTabStopTokens add=snipEscape + +syn match snipMirror "\$\d\+" contained +syn cluster snipTokens add=snipMirror +syn cluster snipTabStopTokens add=snipMirror + +syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault extend +syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTabStopTokens keepend +syn match snipTabStopEscape "\\[{}]" contained +syn region snipBalancedBraces start="{" end="}" contained transparent extend +syn cluster snipTokens add=snipTabStop +syn cluster snipTabStopTokens add=snipTabStop + +syn region snipVisual matchgroup=snipVisual start="\${VISUAL[:}/]\@=" end="}" contained contains=snipVisualDefault,snipTransformationPattern extend +syn region snipVisualDefault matchgroup=snipVisual start=":" end="\ze[}/]" contained contains=snipTabStopEscape nextgroup=snipTransformationPattern +syn cluster snipTokens add=snipVisual +syn cluster snipTabStopTokens add=snipVisual + +syn region snipTransformation matchgroup=snipTransformation start="\${\d\/\@=" end="}" contained contains=snipTransformationPattern +syn region snipTransformationPattern matchgroup=snipTransformationPatternDelim start="/" end="\ze/" contained contains=snipTransformationEscape nextgroup=snipTransformationReplace skipnl +syn region snipTransformationReplace matchgroup=snipTransformationPatternDelim start="/" end="/" contained contains=snipTransformationEscape nextgroup=snipTransformationOptions skipnl +syn region snipTransformationOptions start="\ze[^}]" end="\ze}" contained contains=snipTabStopEscape +syn match snipTransformationEscape "\\/" contained +syn cluster snipTokens add=snipTransformation +syn cluster snipTabStopTokens add=snipTransformation + +" global {{{3 + +" Generic (non-Python) {{{4 + +syn region snipGlobal start="^global\_s" end="^\zeendglobal\s*$" contains=snipGlobalHeader nextgroup=snipGlobalFooter fold keepend +syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword +syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces + +" Python (!p) {{{4 + +syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^\zeendglobal\s*$, contains=snipGlobalPHeader nextgroup=snipGlobalFooter fold keepend +syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword +syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite +syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python + +" Common {{{4 + +syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword +syn match snipGlobalFooterKeyword "^endglobal" contained + +" priority {{{3 + +syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display +syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite display +syn match snipPriorityValue "-\?\d\+" contained display + +" Actions {{{3 + +syn match snipAction "^\%(pre_expand\|post_expand\|post_jump\).*$" contains=snipActionKeyword display skipwhite +syn match snipActionKeyword "\%(pre_expand\|post_expand\|post_jump\)" contained nextgroup=snipActionValue skipwhite display +syn match snipActionValue '"[^"]*"' contained contains=snipActionValueP +syn region snipActionValueP start=,"\@<=., end=,\ze", contained contains=@Python skipwhite keepend + +" Snippt Clearing {{{2 + +syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword display +syn match snipClearKeyword "^clearsnippets" contained display + +" Highlight groups {{{1 + +hi def link snipComment Comment +hi def link snipTODO Todo +hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f + +hi def link snipKeyword Keyword + +hi def link snipExtendsKeyword snipKeyword + +hi def link snipSnippetHeaderKeyword snipKeyword +hi def link snipSnippetFooterKeyword snipKeyword + +hi def link snipSnippetTrigger Identifier +hi def link snipSnippetTriggerInvalid Error +hi def link snipSnippetDocString String +hi def link snipSnippetDocContextString String +hi def link snipSnippetOptionFlag Special + +hi def link snipGlobalHeaderKeyword snipKeyword +hi def link snipGlobalFooterKeyword snipKeyword + +hi def link snipCommand Special +hi def link snipCommandDelim snipCommand +hi def link snipShellCommand snipCommand +hi def link snipVimLCommand snipCommand +hi def link snipPythonCommandP PreProc +hi def link snipVimLCommandV PreProc +hi def link snipSnippetContext String +hi def link snipAction String + +hi def link snipEscape Special +hi def link snipMirror StorageClass +hi def link snipTabStop Define +hi def link snipTabStopDefault String +hi def link snipTabStopEscape Special +hi def link snipVisual snipTabStop +hi def link snipVisualDefault snipTabStopDefault +hi def link snipTransformation snipTabStop +hi def link snipTransformationPattern String +hi def link snipTransformationPatternDelim Operator +hi def link snipTransformationReplace String +hi def link snipTransformationEscape snipEscape +hi def link snipTransformationOptions Operator + +hi def link snipPriorityKeyword Keyword +hi def link snipPriorityValue Number + +hi def link snipActionKeyword Keyword + +hi def link snipClearKeyword Keyword + +" }}}1 + +let b:current_syntax = "snippets" diff --git a/vim/bundle/ultisnips/syntax/snippets_snipmate.vim b/vim/bundle/ultisnips/syntax/snippets_snipmate.vim new file mode 100644 index 0000000..aa55c1f --- /dev/null +++ b/vim/bundle/ultisnips/syntax/snippets_snipmate.vim @@ -0,0 +1,47 @@ +" Syntax highlighting variant used for snipmate snippets files +" The snippets.vim file sources this if it wants snipmate mode + +if exists("b:current_syntax") + finish +endif + +" Embedded syntaxes {{{1 + +" Re-include the original file so we can share some of its definitions +let b:ultisnips_override_snipmate = 1 +syn include :h/snippets.vim +unlet b:current_syntax +unlet b:ultisnips_override_snipmate + +syn cluster snipTokens contains=snipEscape,snipVisual,snipTabStop,snipMirror,snipmateCommand +syn cluster snipTabStopTokens contains=snipVisual,snipMirror,snipEscape,snipmateCommand + +" Syntax definitions {{{1 + +syn match snipmateComment "^#.*" + +syn match snipmateExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display + +syn region snipmateSnippet start="^snippet\ze\%(\s\|$\)" end="^\ze[^[:tab:]]" contains=snipmateSnippetHeader keepend +syn match snipmateSnippetHeader "^.*" contained contains=snipmateKeyword nextgroup=snipmateSnippetBody skipnl skipempty +syn match snipmateKeyword "^snippet\ze\%(\s\|$\)" contained nextgroup=snipmateTrigger skipwhite +syn match snipmateTrigger "\S\+" contained nextgroup=snipmateDescription skipwhite +syn match snipmateDescription "\S.*" contained +syn region snipmateSnippetBody start="^\t" end="^\ze[^[:tab:]]" contained contains=@snipTokens + +syn region snipmateCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipCommandSyntaxOverride,@Viml + +" Highlight groups {{{1 + +hi def link snipmateComment snipComment + +hi def link snipmateSnippet snipSnippet +hi def link snipmateKeyword snipKeyword +hi def link snipmateTrigger snipSnippetTrigger +hi def link snipmateDescription snipSnippetDocString + +hi def link snipmateCommand snipCommand + +" }}}1 + +let b:current_syntax = "snippets" diff --git a/vim/bundle/ultisnips/test.py b/vim/bundle/ultisnips/test.py deleted file mode 100755 index 26e8628..0000000 --- a/vim/bundle/ultisnips/test.py +++ /dev/null @@ -1,3300 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 -# -# To execute this test requires two terminals, one for running Vim and one -# for executing the test script. Both terminals should have their current -# working directories set to this directory (the one containing this test.py -# script). -# -# In one terminal, launch a GNU ``screen`` session named ``vim``: -# $ screen -S vim -# -# Within this new session, launch Vim with the absolute bare minimum settings -# to ensure a consistent test environment: -# $ vim -u NONE -# -# The '-u NONE' disables normal .vimrc and .gvimrc processing (note -# that '-u NONE' implies '-U NONE'). -# -# All other settings are configured by the test script. -# -# Now, from another terminal, launch the testsuite: -# $ ./test.py -# -# The testsuite will use ``screen`` to inject commands into the Vim under test, -# and will compare the resulting output to expected results. -# -# Under windows, COM's SendKeys is used to send keystrokes to the gvim window. -# Note that Gvim must use english keyboard input (choose in windows registry) -# for this to work properly as SendKeys is a piece of chunk. (i.e. it sends -# when you send a | symbol while using german key mappings) - -# pylint: skip-file - -from textwrap import dedent -import os -import platform -import random -import re -import shutil -import string -import subprocess -import sys -import tempfile -import time -import unittest - -try: - import unidecode - UNIDECODE_IMPORTED = True -except ImportError: - UNIDECODE_IMPORTED = False - -# Some constants for better reading -BS = '\x7f' -ESC = '\x1b' -ARR_L = '\x1bOD' -ARR_R = '\x1bOC' -ARR_U = '\x1bOA' -ARR_D = '\x1bOB' - -# multi-key sequences generating a single key press -SEQUENCES = [ARR_L, ARR_R, ARR_U, ARR_D] - -# Defined Constants -JF = "?" # Jump forwards -JB = "+" # Jump backwards -LS = "@" # List snippets -EX = "\t" # EXPAND -EA = "#" # Expand anonymous - -COMPL_KW = chr(24)+chr(14) -COMPL_ACCEPT = chr(25) - -def running_on_windows(): - if platform.system() == "Windows": - return "Does not work on Windows." - -def no_unidecode_available(): - if not UNIDECODE_IMPORTED: - return "unidecode is not available." - -def random_string(n): - return ''.join(random.choice(string.ascii_lowercase) for x in range(n)) - -def silent_call(cmd): - """Calls 'cmd' and returns the exit value.""" - return subprocess.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - -class VimInterface: - def focus(title=None): - pass - - def get_buffer_data(self): - handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt") - os.close(handle) - os.unlink(fn) - - self.send(ESC + ":w! %s\n" % fn) - - # Read the output, chop the trailing newline - tries = 50 - while tries: - if os.path.exists(fn): - if sys.version_info >= (3,0): - return open(fn,"r", encoding="utf-8").read()[:-1] - else: - return open(fn,"r").read()[:-1] - time.sleep(.05) - tries -= 1 - -class VimInterfaceScreen(VimInterface): - def __init__(self, session): - self.session = session - self.need_screen_escapes = 0 - self.detect_parsing() - - def send(self, s): - if self.need_screen_escapes: - # escape characters that are special to some versions of screen - repl = lambda m: '\\' + m.group(0) - s = re.sub( r"[$^#\\']", repl, s ) - - if sys.version_info >= (3,0): - s = s.encode("utf-8") - - while True: - rv = 0 - if len(s) > 30: - rv |= silent_call(["screen", "-x", self.session, "-X", "register", "S", s]) - rv |= silent_call(["screen", "-x", self.session, "-X", "paste", "S"]) - else: - rv |= silent_call(["screen", "-x", self.session, "-X", "stuff", s]) - if not rv: break - time.sleep(.2) - - def detect_parsing(self): - # Clear the buffer - self.send("bggVGd") - - # Send a string where the interpretation will depend on version of screen - string = "$TERM" - self.send("i" + string + ESC) - output = self.get_buffer_data() - - # If the output doesn't match the input, need to do additional escaping - if output != string: - self.need_screen_escapes = 1 - -class VimInterfaceTmux(VimInterface): - def __init__(self, session): - self.session = session - self._check_version() - - def send(self, s): - # I did not find any documentation on what needs escaping when sending - # to tmux, but it seems like this is all that is needed for now. - s = s.replace(';', r'\;') - - if sys.version_info >= (3,0): - s = s.encode("utf-8") - silent_call(["tmux", "send-keys", "-t", self.session, "-l", s]) - - def _check_version(self): - stdout, _ = subprocess.Popen(["tmux", "-V"], - stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - if sys.version_info >= (3,0): - stdout = stdout.decode("utf-8") - m = re.match(r"tmux (\d+).(\d+)", stdout) - if not m or not (int(m.group(1)), int(m.group(2))) >= (1, 9): - raise RuntimeError("Need at least tmux 1.9, you have %s." % stdout.strip()) - -class VimInterfaceWindows(VimInterface): - BRACES = re.compile("([}{])") - WIN_ESCAPES = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"] - WIN_REPLACES = [ - (BS, "{BS}"), - (ARR_L, "{LEFT}"), - (ARR_R, "{RIGHT}"), - (ARR_U, "{UP}"), - (ARR_D, "{DOWN}"), - ("\t", "{TAB}"), - ("\n", "~"), - (ESC, "{ESC}"), - - # On my system ` waits for a second keystroke, so `+SPACE = "`". On - # most systems, `+Space = "` ". I work around this, by sending the host - # ` as `+_+BS. Awkward, but the only way I found to get this working. - ("`", "`_{BS}"), - ("´", "´_{BS}"), - ("{^}", "{^}_{BS}"), - ] - - def __init__(self): - self.seq_buf = [] - # import windows specific modules - import win32com.client, win32gui - self.win32gui = win32gui - self.shell = win32com.client.Dispatch("WScript.Shell") - - def is_focused(self, title=None): - cur_title = self.win32gui.GetWindowText(self.win32gui.GetForegroundWindow()) - if (title or "- GVIM") in cur_title: - return True - return False - - def focus(self, title=None): - if not self.shell.AppActivate(title or "- GVIM"): - raise Exception("Failed to switch to GVim window") - time.sleep(1) - - def convert_keys(self, keys): - keys = self.BRACES.sub(r"{\1}", keys) - for k in self.WIN_ESCAPES: - keys = keys.replace(k, "{%s}" % k) - for f, r in self.WIN_REPLACES: - keys = keys.replace(f, r) - return keys - - def send(self, keys): - self.seq_buf.append(keys) - seq = "".join(self.seq_buf) - - for f in SEQUENCES: - if f.startswith(seq) and f != seq: - return - self.seq_buf = [] - - seq = self.convert_keys(seq) - - if not self.is_focused(): - time.sleep(2) - self.focus() - if not self.is_focused(): - # This is the only way I can find to stop test execution - raise KeyboardInterrupt("Failed to focus GVIM") - - self.shell.SendKeys(seq) - -class _VimTest(unittest.TestCase): - snippets = ("dummy", "donotdefine") - snippets_test_file = ("", "") # filetype, file content - text_before = " --- some text before --- \n\n" - text_after = "\n\n --- some text after --- " - expected_error = "" - wanted = "" - keys = "" - sleeptime = 0.00 - output = None - # Skip this test for the given reason or None for not skipping it. - skip_if = lambda self: None - - def send(self,s): - self.vim.send(s) - - def send_py(self,s): - # Do not delete the file so that Vim can safely read it. - with tempfile.NamedTemporaryFile( - prefix="UltiSnips_Python", suffix=".py", delete=False - ) as temporary_file: - if sys.version_info >= (3,0): - s = s.encode("utf-8") - - temporary_file.write(s) - temporary_file.close() - - if sys.version_info < (3,0): - self.send(":pyfile %s\n" % temporary_file.name) - else: - self.send(":py3file %s\n" % temporary_file.name) - - def check_output(self): - wanted = self.text_before + self.wanted + self.text_after - if self.expected_error: - self.assertRegexpMatches(self.output, self.expected_error) - return - for i in range(self.retries): - if self.output != wanted: - # Redo this, but slower - self.sleeptime += 0.02 - self.send(ESC) - self.setUp() - self.assertEqual(self.output, wanted) - - def runTest(self): self.check_output() - - def _options_on(self): - pass - - def _options_off(self): - pass - - def _create_snippet_file(self, ft, content): - """Create a snippet file and makes sure that it is found on the - runtimepath to be parsed.""" - self._temporary_directory = tempfile.mkdtemp(prefix="UltiSnips_Test") - snippet_dir = random_string(20) - abs_snippet_dir = os.path.join(self._temporary_directory, snippet_dir) - os.mkdir(abs_snippet_dir) - with open(os.path.join(abs_snippet_dir, "%s.snippets" % ft), "w") as snippet_file: - snippet_file.write(dedent(content + "\n")) - self.vim.send(":let g:UltiSnipsSnippetDirectories=['%s']\n" % snippet_dir) - self.vim.send(""":set runtimepath=$VIMRUNTIME,%s,.\n""" % self._temporary_directory) - - def setUp(self): - reason_for_skipping = self.skip_if() - if reason_for_skipping is not None: - return self.skipTest(reason_for_skipping) - - # Escape for good measure - self.send(ESC + ESC + ESC) - - # Close all scratch buffers - self.send(":silent! close\n") - - # Reset UltiSnips - self.send_py("UltiSnips_Manager._reset()") - - # Make it unlikely that we do parse any shipped snippets. - self.send(":let g:UltiSnipsSnippetDirectories=['']\n") - - # Clear the buffer - self.send("bggVGd") - - if len(self.snippets) and not isinstance(self.snippets[0],tuple): - self.snippets = ( self.snippets, ) - - for s in self.snippets: - sv, content = s[:2] - description = "" - options = "" - priority = 0 - if len(s) > 2: - description = s[2] - if len(s) > 3: - options = s[3] - if len(s) > 4: - priority = s[4] - - self.send_py("UltiSnips_Manager.add_snippet(%r, %r, %r, %r, priority=%i)" % - (sv, content, description, options, priority)) - - ft, file_data = self.snippets_test_file - self._temporary_directory = "" - if ft: - self._create_snippet_file(ft, file_data) - - if not self.interrupt: - # Enter insert mode - self.send("i") - - self.send(self.text_before) - self.send(self.text_after) - - # Go to the middle of the buffer - self.send(ESC + "ggjj") - - self._options_on() - - self.send("i") - - # Execute the command, but leave Vim some time to react. - for c in self.keys: - self.vim.send(c) - time.sleep(self.sleeptime) - - self.send(ESC) - - self._options_off() - - self.output = self.vim.get_buffer_data() - - def tearDown(self): - if self._temporary_directory: - self.vim.send(""":set runtimepath=$VIMRUNTIME,.\n""") - shutil.rmtree(self._temporary_directory) - -########################################################################### -# BEGINNING OF TEST # -########################################################################### -# Snippet Definition Parsing {{{# -class ParseSnippets_SimpleSnippet(_VimTest): - snippets_test_file = ("all", r""" - snippet testsnip "Test Snippet" b! - This is a test snippet! - endsnippet - """) - keys = "testsnip" + EX - wanted = "This is a test snippet!" - -class ParseSnippets_MissingEndSnippet(_VimTest): - snippets_test_file = ("all", r""" - snippet testsnip "Test Snippet" b! - This is a test snippet! - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - expected_error = r"Missing 'endsnippet' for 'testsnip' in \S+:4" - -class ParseSnippets_UnknownDirective(_VimTest): - snippets_test_file = ("all", r""" - unknown directive - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - expected_error = r"Invalid line 'unknown directive' in \S+:2" - -class ParseSnippets_InvalidPriorityLine(_VimTest): - snippets_test_file = ("all", r""" - priority - 50 - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - expected_error = r"Invalid priority '- 50' in \S+:2" - -class ParseSnippets_InvalidPriorityLine1(_VimTest): - snippets_test_file = ("all", r""" - priority - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - expected_error = r"Invalid priority '' in \S+:2" - -class ParseSnippets_ExtendsWithoutFiletype(_VimTest): - snippets_test_file = ("all", r""" - extends - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - expected_error = r"'extends' without file types in \S+:2" - -class ParseSnippets_ClearAll(_VimTest): - snippets_test_file = ("all", r""" - snippet testsnip "Test snippet" - This is a test. - endsnippet - - clearsnippets - """) - keys = "testsnip" + EX - wanted = "testsnip" + EX - -class ParseSnippets_ClearOne(_VimTest): - snippets_test_file = ("all", r""" - snippet testsnip "Test snippet" - This is a test. - endsnippet - - snippet toclear "Snippet to clear" - Do not expand. - endsnippet - - clearsnippets toclear - """) - keys = "toclear" + EX + "\n" + "testsnip" + EX - wanted = "toclear" + EX + "\n" + "This is a test." - -class ParseSnippets_ClearTwo(_VimTest): - snippets_test_file = ("all", r""" - snippet testsnip "Test snippet" - This is a test. - endsnippet - - snippet toclear "Snippet to clear" - Do not expand. - endsnippet - - clearsnippets testsnip toclear - """) - keys = "toclear" + EX + "\n" + "testsnip" + EX - wanted = "toclear" + EX + "\n" + "testsnip" + EX - - -class _ParseSnippets_MultiWord(_VimTest): - snippets_test_file = ("all", r""" - snippet /test snip/ - This is a test. - endsnippet - - snippet !snip test! "Another snippet" - This is another test. - endsnippet - - snippet "snippet test" "Another snippet" b - This is yet another test. - endsnippet - """) -class ParseSnippets_MultiWord_Simple(_ParseSnippets_MultiWord): - keys = "test snip" + EX - wanted = "This is a test." -class ParseSnippets_MultiWord_Description(_ParseSnippets_MultiWord): - keys = "snip test" + EX - wanted = "This is another test." -class ParseSnippets_MultiWord_Description_Option(_ParseSnippets_MultiWord): - keys = "snippet test" + EX - wanted = "This is yet another test." - -class _ParseSnippets_MultiWord_RE(_VimTest): - snippets_test_file = ("all", r""" - snippet /[d-f]+/ "" r - az test - endsnippet - - snippet !^(foo|bar)$! "" r - foo-bar test - endsnippet - - snippet "(test ?)+" "" r - re-test - endsnippet - """) -class ParseSnippets_MultiWord_RE1(_ParseSnippets_MultiWord_RE): - keys = "abc def" + EX - wanted = "abc az test" -class ParseSnippets_MultiWord_RE2(_ParseSnippets_MultiWord_RE): - keys = "foo" + EX + " bar" + EX + "\nbar" + EX - wanted = "foo-bar test bar\t\nfoo-bar test" -class ParseSnippets_MultiWord_RE3(_ParseSnippets_MultiWord_RE): - keys = "test test test" + EX - wanted = "re-test" - -class ParseSnippets_MultiWord_Quotes(_VimTest): - snippets_test_file = ("all", r""" - snippet "test snip" - This is a test. - endsnippet - """) - keys = "test snip" + EX - wanted = "This is a test." -class ParseSnippets_MultiWord_WithQuotes(_VimTest): - snippets_test_file = ("all", r""" - snippet !"test snip"! - This is a test. - endsnippet - """) - keys = '"test snip"' + EX - wanted = "This is a test." - -class ParseSnippets_MultiWord_NoContainer(_VimTest): - snippets_test_file = ("all", r""" - snippet test snip - This is a test. - endsnippet - """) - keys = "test snip" + EX - wanted = keys - expected_error = "Invalid multiword trigger: 'test snip' in \S+:2" - -class ParseSnippets_MultiWord_UnmatchedContainer(_VimTest): - snippets_test_file = ("all", r""" - snippet !inv snip/ - This is a test. - endsnippet - """) - keys = "inv snip" + EX - wanted = keys - expected_error = "Invalid multiword trigger: '!inv snip/' in \S+:2" - -class ParseSnippets_Global_Python(_VimTest): - snippets_test_file = ("all", r""" - global !p - def tex(ins): - return "a " + ins + " b" - endglobal - - snippet ab - x `!p snip.rv = tex("bob")` y - endsnippet - - snippet ac - x `!p snip.rv = tex("jon")` y - endsnippet - """) - keys = "ab" + EX + "\nac" + EX - wanted = "x a bob b y\nx a jon b y" - -class ParseSnippets_Global_Local_Python(_VimTest): - snippets_test_file = ("all", r""" -global !p -def tex(ins): - return "a " + ins + " b" -endglobal - -snippet ab -x `!p first = tex("bob") -snip.rv = "first"` `!p snip.rv = first` y -endsnippet - """) - keys = "ab" + EX - wanted = "x first a bob b y" -# End: Snippet Definition Parsing #}}} - -# Simple Expands {{{# -class _SimpleExpands(_VimTest): - snippets = ("hallo", "Hallo Welt!") - -class SimpleExpand_ExceptCorrectResult(_SimpleExpands): - keys = "hallo" + EX - wanted = "Hallo Welt!" -class SimpleExpandTwice_ExceptCorrectResult(_SimpleExpands): - keys = "hallo" + EX + '\nhallo' + EX - wanted = "Hallo Welt!\nHallo Welt!" - -class SimpleExpandNewLineAndBackspae_ExceptCorrectResult(_SimpleExpands): - keys = "hallo" + EX + "\nHallo Welt!\n\n\b\b\b\b\b" - wanted = "Hallo Welt!\nHallo We" - def _options_on(self): - self.send(":set backspace=eol,start\n") - def _options_off(self): - self.send(":set backspace=\n") - -class SimpleExpandTypeAfterExpand_ExceptCorrectResult(_SimpleExpands): - keys = "hallo" + EX + "and again" - wanted = "Hallo Welt!and again" - -class SimpleExpandTypeAndDelete_ExceptCorrectResult(_SimpleExpands): - keys = "na du hallo" + EX + "and again\b\b\b\b\bblub" - wanted = "na du Hallo Welt!and blub" - -class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands): - keys = "hallo " + EX - wanted = "hallo " + EX - -class ExitSnippetModeAfterTabstopZero(_VimTest): - snippets = ("test", "SimpleText") - keys = "test" + EX + EX - wanted = "SimpleText" + EX - -class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands): - keys = "Wie hallo gehts" + ESC + "bhi" + EX - wanted = "Wie Hallo Welt! gehts" -class MultilineExpand_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts") - keys = "Wie hallo gehts" + ESC + "bhi" + EX - wanted = "Wie Hallo Welt!\nUnd Wie gehts gehts" -class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "Hallo Welt!\nUnd Wie gehts") - wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" - keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" -class SimpleExpandEndingWithNewline_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "Hallo Welt\n") - keys = "hallo" + EX + "\nAnd more" - wanted = "Hallo Welt\n\nAnd more" - - -# End: Simple Expands #}}} -# TabStop Tests {{{# -class TabStopSimpleReplace_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo ${0:End} ${1:Beginning}") - keys = "hallo" + EX + "na" + JF + "Du Nase" - wanted = "hallo Du Nase na" -class TabStopSimpleReplaceReversed_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo ${1:End} ${0:Beginning}") - keys = "hallo" + EX + "na" + JF + "Du Nase" - wanted = "hallo na Du Nase" -class TabStopSimpleReplaceSurrounded_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo ${0:End} a small feed") - keys = "hallo" + EX + "Nase" - wanted = "hallo Nase a small feed" -class TabStopSimpleReplaceSurrounded1_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo $0 a small feed") - keys = "hallo" + EX + "Nase" - wanted = "hallo Nase a small feed" -class TabStop_Exit_ExceptCorrectResult(_VimTest): - snippets = ("echo", "$0 run") - keys = "echo" + EX + "test" - wanted = "test run" - -class TabStopNoReplace_ExceptCorrectResult(_VimTest): - snippets = ("echo", "echo ${1:Hallo}") - keys = "echo" + EX - wanted = "echo Hallo" - -class TabStop_EscapingCharsBackticks(_VimTest): - snippets = ("test", r"snip \` literal") - keys = "test" + EX - wanted = "snip ` literal" -class TabStop_EscapingCharsDollars(_VimTest): - snippets = ("test", r"snip \$0 $$0 end") - keys = "test" + EX + "hi" - wanted = "snip $0 $hi end" -class TabStop_EscapingCharsDollars1(_VimTest): - snippets = ("test", r"a\${1:literal}") - keys = "test" + EX - wanted = "a${1:literal}" -class TabStop_EscapingCharsDollars_BeginningOfLine(_VimTest): - snippets = ("test", "\n\\${1:literal}") - keys = "test" + EX - wanted = "\n${1:literal}" -class TabStop_EscapingCharsDollars_BeginningOfDefinitionText(_VimTest): - snippets = ("test", "\\${1:literal}") - keys = "test" + EX - wanted = "${1:literal}" -class TabStop_EscapingChars_Backslash(_VimTest): - snippets = ("test", r"This \ is a backslash!") - keys = "test" + EX - wanted = "This \\ is a backslash!" -class TabStop_EscapingChars_Backslash2(_VimTest): - snippets = ("test", r"This is a backslash \\ done") - keys = "test" + EX - wanted = r"This is a backslash \ done" -class TabStop_EscapingChars_Backslash3(_VimTest): - snippets = ("test", r"These are two backslashes \\\\ done") - keys = "test" + EX - wanted = r"These are two backslashes \\ done" -class TabStop_EscapingChars_Backslash4(_VimTest): - # Test for bug 746446 - snippets = ("test", r"\\$1{$2}") - keys = "test" + EX + "hello" + JF + "world" - wanted = r"\hello{world}" -class TabStop_EscapingChars_RealLife(_VimTest): - snippets = ("test", r"usage: \`basename \$0\` ${1:args}") - keys = "test" + EX + "[ -u -v -d ]" - wanted = "usage: `basename $0` [ -u -v -d ]" - -class TabStopEscapingWhenSelected_ECR(_VimTest): - snippets = ("test", "snip ${1:default}") - keys = "test" + EX + ESC + "0ihi" - wanted = "hisnip default" -class TabStopEscapingWhenSelectedSingleCharTS_ECR(_VimTest): - snippets = ("test", "snip ${1:i}") - keys = "test" + EX + ESC + "0ihi" - wanted = "hisnip i" -class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest): - snippets = ("test", "snip $1") - keys = "test" + EX + ESC + "0ihi" - wanted = "hisnip " - -class TabStopWithOneChar_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "nothing ${1:i} hups") - keys = "hallo" + EX + "ship" - wanted = "nothing ship hups" - -class TabStopTestJumping_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo ${2:End} mitte ${1:Beginning}") - keys = "hallo" + EX + JF + "Test" + JF + "Hi" - wanted = "hallo Test mitte BeginningHi" -class TabStopTestJumping2_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo $2 $1") - keys = "hallo" + EX + JF + "Test" + JF + "Hi" - wanted = "hallo Test Hi" -class TabStopTestJumpingRLExampleWithZeroTab_ExceptCorrectResult(_VimTest): - snippets = ("test", "each_byte { |${1:byte}| $0 }") - keys = "test" + EX + JF + "Blah" - wanted = "each_byte { |byte| Blah }" - -class TabStopTestJumpingDontJumpToEndIfThereIsTabZero_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo $0 $1") - keys = "hallo" + EX + "Test" + JF + "Hi" + JF + JF + "du" - wanted = "hallo Hi" + 2*JF + "du Test" - -class TabStopTestBackwardJumping_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo ${2:End} mitte${1:Beginning}") - keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \ - "Lets replace it again" + JF + "Blah" + JF + JB*2 + JF - wanted = "hallo Blah mitteLets replace it again" + JB*2 + JF -class TabStopTestBackwardJumping2_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo $2 $1") - keys = "hallo" + EX + "Somelengthy Text" + JF + "Hi" + JB + \ - "Lets replace it again" + JF + "Blah" + JF + JB*2 + JF - wanted = "hallo Blah Lets replace it again" + JB*2 + JF - -class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "hallo $0\nnice $1 work\n$3 $2\nSeem to work") - keys ="test hallo World" + ESC + "02f i" + EX + "world" + JF + "try" + \ - JF + "test" + JF + "one more" + JF - wanted = "test hallo one more" + JF + "\nnice world work\n" \ - "test try\nSeem to work World" - -class TabStop_TSInDefaultTextRLExample_OverwriteNone_ECR(_VimTest): - snippets = ("test", """\n $0\n""") - keys = "test" + EX - wanted = """
    \n \n
    """ -class TabStop_TSInDefaultTextRLExample_OverwriteFirst_NoJumpBack(_VimTest): - snippets = ("test", """\n $0\n""") - keys = "test" + EX + " blah" + JF + "Hallo" - wanted = """
    \n Hallo\n
    """ -class TabStop_TSInDefaultTextRLExample_DeleteFirst(_VimTest): - snippets = ("test", """\n $0\n""") - keys = "test" + EX + BS + JF + "Hallo" - wanted = """
    \n Hallo\n
    """ -class TabStop_TSInDefaultTextRLExample_OverwriteFirstJumpBack(_VimTest): - snippets = ("test", """\n $3 $0\n""") - keys = "test" + EX + "Hi" + JF + "Hallo" + JB + "SomethingElse" + JF + \ - "Nupl" + JF + "Nox" - wanted = """\n Nupl Nox\n""" -class TabStop_TSInDefaultTextRLExample_OverwriteSecond(_VimTest): - snippets = ("test", """\n $0\n""") - keys = "test" + EX + JF + "no" + JF + "End" - wanted = """
    \n End\n
    """ -class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBack(_VimTest): - snippets = ("test", """\n $3 $0\n""") - keys = "test" + EX + JF + "no" + JF + "End" + JB + "yes" + JF + "Begin" \ - + JF + "Hi" - wanted = """
    \n Begin Hi\n
    """ -class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBackTwice(_VimTest): - snippets = ("test", """\n $3 $0\n""") - keys = "test" + EX + JF + "no" + JF + "End" + JB + "yes" + JB + \ - " allaway" + JF + "Third" + JF + "Last" - wanted = """
    \n Third Last\n
    """ - -class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecond(_VimTest): - snippets = ("test", """h${1:a$2b}l""") - keys = "test" + EX + JF + "ups" + JF + "End" - wanted = """haupsblEnd""" -class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteFirst(_VimTest): - snippets = ("test", """h${1:a$2b}l""") - keys = "test" + EX + "ups" + JF + "End" - wanted = """hupslEnd""" -class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackOverwrite(_VimTest): - snippets = ("test", """h${1:a$2b}l""") - keys = "test" + EX + JF + "longertext" + JB + "overwrite" + JF + "End" - wanted = """hoverwritelEnd""" -class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward0(_VimTest): - snippets = ("test", """h${1:a$2b}l""") - keys = "test" + EX + JF + "longertext" + JB + JF + "overwrite" + JF + "End" - wanted = """haoverwriteblEnd""" -class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward1(_VimTest): - snippets = ("test", """h${1:a$2b}l""") - keys = "test" + EX + JF + "longertext" + JB + JF + JF + "End" - wanted = """halongertextblEnd""" - -class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest): - snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4") - keys = "test" + EX + JF + "Hallo" + JF + "Ende" - wanted = "hi this Hallo Ende" -class TabStop_TSInDefaultNested_OverwriteOneJumpToThird(_VimTest): - snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4") - keys = "test" + EX + JF + JF + "Hallo" + JF + "Ende" - wanted = "hi this second Hallo Ende" -class TabStop_TSInDefaultNested_OverwriteOneJumpAround(_VimTest): - snippets = ("test", "hi ${1:this ${2:second ${3:third}}} $4") - keys = "test" + EX + JF + JF + "Hallo" + JB+JB + "Blah" + JF + "Ende" - wanted = "hi Blah Ende" - -class TabStop_TSInDefault_MirrorsOutside_DoNothing(_VimTest): - snippets = ("test", "hi ${1:this ${2:second}} $2") - keys = "test" + EX - wanted = "hi this second second" -class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond(_VimTest): - snippets = ("test", "hi ${1:this ${2:second}} $2") - keys = "test" + EX + JF + "Hallo" - wanted = "hi this Hallo Hallo" -class TabStop_TSInDefault_MirrorsOutside_Overwrite0(_VimTest): - snippets = ("test", "hi ${1:this ${2:second}} $2") - keys = "test" + EX + "Hallo" - wanted = "hi Hallo " -class TabStop_TSInDefault_MirrorsOutside_Overwrite1(_VimTest): - snippets = ("test", "$1: ${1:'${2:second}'} $2") - keys = "test" + EX + "Hallo" - wanted = "Hallo: Hallo " -class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond1(_VimTest): - snippets = ("test", "$1: ${1:'${2:second}'} $2") - keys = "test" + EX + JF + "Hallo" - wanted = "'Hallo': 'Hallo' Hallo" -class TabStop_TSInDefault_MirrorsOutside_OverwriteFirstSwitchNumbers(_VimTest): - snippets = ("test", "$2: ${2:'${1:second}'} $1") - keys = "test" + EX + "Hallo" - wanted = "'Hallo': 'Hallo' Hallo" -class TabStop_TSInDefault_MirrorsOutside_OverwriteFirst_RLExample(_VimTest): - snippets = ("test", """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""") - keys = "test" + EX + "WORLD" + JF + "End" - wanted = "world = require(WORLD)End" -class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond_RLExample(_VimTest): - snippets = ("test", """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""") - keys = "test" + EX + JF + "WORLD" + JF + "End" - wanted = "world = require('WORLD')End" - -class TabStop_Multiline_Leave(_VimTest): - snippets = ("test", "hi ${1:first line\nsecond line} world" ) - keys = "test" + EX - wanted = "hi first line\nsecond line world" -class TabStop_Multiline_Overwrite(_VimTest): - snippets = ("test", "hi ${1:first line\nsecond line} world" ) - keys = "test" + EX + "Nothing" - wanted = "hi Nothing world" -class TabStop_Multiline_MirrorInFront_Leave(_VimTest): - snippets = ("test", "hi $1 ${1:first line\nsecond line} world" ) - keys = "test" + EX - wanted = "hi first line\nsecond line first line\nsecond line world" -class TabStop_Multiline_MirrorInFront_Overwrite(_VimTest): - snippets = ("test", "hi $1 ${1:first line\nsecond line} world" ) - keys = "test" + EX + "Nothing" - wanted = "hi Nothing Nothing world" -class TabStop_Multiline_DelFirstOverwriteSecond_Overwrite(_VimTest): - snippets = ("test", "hi $1 $2 ${1:first line\nsecond line} ${2:Hi} world" ) - keys = "test" + EX + BS + JF + "Nothing" - wanted = "hi Nothing Nothing world" - -class TabStopNavigatingInInsertModeSimple_ExceptCorrectResult(_VimTest): - snippets = ("hallo", "Hallo ${1:WELT} ups") - keys = "hallo" + EX + "haselnut" + 2*ARR_L + "hips" + JF + "end" - wanted = "Hallo haselnhipsut upsend" -# End: TabStop Tests #}}} -# ShellCode Interpolation {{{# -class TabStop_Shell_SimpleExample(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", "hi `echo hallo` you!") - keys = "test" + EX + "and more" - wanted = "hi hallo you!and more" -class TabStop_Shell_WithUmlauts(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", "hi `echo höüäh` you!") - keys = "test" + EX + "and more" - wanted = "hi höüäh you!and more" -class TabStop_Shell_TextInNextLine(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", "hi `echo hallo`\nWeiter") - keys = "test" + EX + "and more" - wanted = "hi hallo\nWeiterand more" -class TabStop_Shell_InDefValue_Leave(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", "Hallo ${1:now `echo fromecho`} end") - keys = "test" + EX + JF + "and more" - wanted = "Hallo now fromecho endand more" -class TabStop_Shell_InDefValue_Overwrite(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", "Hallo ${1:now `echo fromecho`} end") - keys = "test" + EX + "overwrite" + JF + "and more" - wanted = "Hallo overwrite endand more" -class TabStop_Shell_TestEscapedChars_Overwrite(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", r"""`echo \`echo "\\$hi"\``""") - keys = "test" + EX - wanted = "$hi" -class TabStop_Shell_TestEscapedCharsAndShellVars_Overwrite(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", r"""`hi="blah"; echo \`echo "$hi"\``""") - keys = "test" + EX - wanted = "blah" - -class TabStop_Shell_ShebangPython(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = ("test", """Hallo ${1:now `#!/usr/bin/env python -print "Hallo Welt" -`} end""") - keys = "test" + EX + JF + "and more" - wanted = "Hallo now Hallo Welt endand more" -# End: ShellCode Interpolation #}}} -# VimScript Interpolation {{{# -class TabStop_VimScriptInterpolation_SimpleExample(_VimTest): - snippets = ("test", """hi `!v indent(".")` End""") - keys = " test" + EX - wanted = " hi 4 End" -# End: VimScript Interpolation #}}} -# PythonCode Interpolation {{{# -# Deprecated Implementation {{{# -class PythonCodeOld_SimpleExample(_VimTest): - snippets = ("test", """hi `!p res = "Hallo"` End""") - keys = "test" + EX - wanted = "hi Hallo End" -class PythonCodeOld_ReferencePlaceholderAfter(_VimTest): - snippets = ("test", """${1:hi} `!p res = t[1]+".blah"` End""") - keys = "test" + EX + "ho" - wanted = "ho ho.blah End" -class PythonCodeOld_ReferencePlaceholderBefore(_VimTest): - snippets = ("test", """`!p res = len(t[1])*"#"`\n${1:some text}""") - keys = "test" + EX + "Hallo Welt" - wanted = "##########\nHallo Welt" -class PythonCodeOld_TransformedBeforeMultiLine(_VimTest): - snippets = ("test", """${1/.+/egal/m} ${1:`!p -res = "Hallo"`} End""") - keys = "test" + EX - wanted = "egal Hallo End" -class PythonCodeOld_IndentedMultiline(_VimTest): - snippets = ("test", """start `!p a = 1 -b = 2 -if b > a: - res = "b isbigger a" -else: - res = "a isbigger b"` end""") - keys = " test" + EX - wanted = " start b isbigger a end" -# End: Deprecated Implementation #}}} -# New Implementation {{{# -class PythonCode_UseNewOverOld(_VimTest): - snippets = ("test", """hi `!p res = "Old" -snip.rv = "New"` End""") - keys = "test" + EX - wanted = "hi New End" - -class PythonCode_SimpleExample(_VimTest): - snippets = ("test", """hi `!p snip.rv = "Hallo"` End""") - keys = "test" + EX - wanted = "hi Hallo End" - -class PythonCode_SimpleExample_ReturnValueIsEmptyString(_VimTest): - snippets = ("test", """hi`!p snip.rv = ""`End""") - keys = "test" + EX - wanted = "hiEnd" - -class PythonCode_ReferencePlaceholder(_VimTest): - snippets = ("test", """${1:hi} `!p snip.rv = t[1]+".blah"` End""") - keys = "test" + EX + "ho" - wanted = "ho ho.blah End" - -class PythonCode_ReferencePlaceholderBefore(_VimTest): - snippets = ("test", """`!p snip.rv = len(t[1])*"#"`\n${1:some text}""") - keys = "test" + EX + "Hallo Welt" - wanted = "##########\nHallo Welt" -class PythonCode_TransformedBeforeMultiLine(_VimTest): - snippets = ("test", """${1/.+/egal/m} ${1:`!p -snip.rv = "Hallo"`} End""") - keys = "test" + EX - wanted = "egal Hallo End" -class PythonCode_MultilineIndented(_VimTest): - snippets = ("test", """start `!p a = 1 -b = 2 -if b > a: - snip.rv = "b isbigger a" -else: - snip.rv = "a isbigger b"` end""") - keys = " test" + EX - wanted = " start b isbigger a end" - -class PythonCode_SimpleAppend(_VimTest): - snippets = ("test", """hi `!p snip.rv = "Hallo1" -snip += "Hallo2"` End""") - keys = "test" + EX - wanted = "hi Hallo1\nHallo2 End" - -class PythonCode_MultiAppend(_VimTest): - snippets = ("test", """hi `!p snip.rv = "Hallo1" -snip += "Hallo2" -snip += "Hallo3"` End""") - keys = "test" + EX - wanted = "hi Hallo1\nHallo2\nHallo3 End" - -class PythonCode_MultiAppendSimpleIndent(_VimTest): - snippets = ("test", """hi -`!p snip.rv="Hallo1" -snip += "Hallo2" -snip += "Hallo3"` -End""") - keys = """ - test""" + EX - wanted = """ - hi - Hallo1 - Hallo2 - Hallo3 - End""" - -class PythonCode_SimpleMkline(_VimTest): - snippets = ("test", r"""hi -`!p snip.rv="Hallo1\n" -snip.rv += snip.mkline("Hallo2") + "\n" -snip.rv += snip.mkline("Hallo3")` -End""") - keys = """ - test""" + EX - wanted = """ - hi - Hallo1 - Hallo2 - Hallo3 - End""" - -class PythonCode_MultiAppendShift(_VimTest): - snippets = ("test", r"""hi -`!p snip.rv="i1" -snip += "i1" -snip >> 1 -snip += "i2" -snip << 2 -snip += "i0" -snip >> 3 -snip += "i3"` -End""") - keys = """ - test""" + EX - wanted = """ - hi - i1 - i1 - i2 -i0 - i3 - End""" - -class PythonCode_MultiAppendShiftMethods(_VimTest): - snippets = ("test", r"""hi -`!p snip.rv="i1\n" -snip.rv += snip.mkline("i1\n") -snip.shift(1) -snip.rv += snip.mkline("i2\n") -snip.unshift(2) -snip.rv += snip.mkline("i0\n") -snip.shift(3) -snip.rv += snip.mkline("i3")` -End""") - keys = """ - test""" + EX - wanted = """ - hi - i1 - i1 - i2 -i0 - i3 - End""" - - -class PythonCode_ResetIndent(_VimTest): - snippets = ("test", r"""hi -`!p snip.rv="i1" -snip >> 1 -snip += "i2" -snip.reset_indent() -snip += "i1" -snip << 1 -snip += "i0" -snip.reset_indent() -snip += "i1"` -End""") - keys = """ - test""" + EX - wanted = """ - hi - i1 - i2 - i1 -i0 - i1 - End""" - -class PythonCode_IndentEtSw(_VimTest): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - snippets = ("test", r"""hi -`!p snip.rv = "i1" -snip >> 1 -snip += "i2" -snip << 2 -snip += "i0" -snip >> 1 -snip += "i1" -` -End""") - keys = """ test""" + EX - wanted = """ hi - i1 - i2 -i0 - i1 - End""" - -class PythonCode_IndentEtSwOffset(_VimTest): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - snippets = ("test", r"""hi -`!p snip.rv = "i1" -snip >> 1 -snip += "i2" -snip << 2 -snip += "i0" -snip >> 1 -snip += "i1" -` -End""") - keys = """ test""" + EX - wanted = """ hi - i1 - i2 - i0 - i1 - End""" - -class PythonCode_IndentNoetSwTs(_VimTest): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set ts=4\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set ts=8\n") - snippets = ("test", r"""hi -`!p snip.rv = "i1" -snip >> 1 -snip += "i2" -snip << 2 -snip += "i0" -snip >> 1 -snip += "i1" -` -End""") - keys = """ test""" + EX - wanted = """ hi - i1 -\t i2 -i0 - i1 - End""" - -# Test using 'opt' -class PythonCode_OptExists(_VimTest): - def _options_on(self): - self.send(':let g:UStest="yes"\n') - def _options_off(self): - self.send(":unlet g:UStest\n") - snippets = ("test", r"""hi `!p snip.rv = snip.opt("g:UStest") or "no"` End""") - keys = """test""" + EX - wanted = """hi yes End""" - -class PythonCode_OptNoExists(_VimTest): - snippets = ("test", r"""hi `!p snip.rv = snip.opt("g:UStest") or "no"` End""") - keys = """test""" + EX - wanted = """hi no End""" - -class PythonCode_IndentProblem(_VimTest): - # A test case which is likely related to bug 719649 - snippets = ("test", r"""hi `!p -snip.rv = "World" -` End""") - keys = " " * 8 + "test" + EX # < 8 works. - wanted = """ hi World End""" - -class PythonCode_TrickyReferences(_VimTest): - snippets = ("test", r"""${2:${1/.+/egal/}} ${1:$3} ${3:`!p snip.rv = "hi"`}""") - keys = "ups test" + EX - wanted = "ups egal hi hi" -# locals -class PythonCode_Locals(_VimTest): - snippets = ("test", r"""hi `!p a = "test" -snip.rv = "nothing"` `!p snip.rv = a -` End""") - keys = """test""" + EX - wanted = """hi nothing test End""" - -class PythonCode_LongerTextThanSource_Chars(_VimTest): - snippets = ("test", r"""hi`!p snip.rv = "a" * 100`end""") - keys = """test""" + EX + "ups" - wanted = "hi" + 100*"a" + "endups" - -class PythonCode_LongerTextThanSource_MultiLine(_VimTest): - snippets = ("test", r"""hi`!p snip.rv = "a" * 100 + '\n'*100 + "a"*100`end""") - keys = """test""" + EX + "ups" - wanted = "hi" + 100*"a" + 100*"\n" + 100*"a" + "endups" - -class PythonCode_AccessKilledTabstop_OverwriteSecond(_VimTest): - snippets = ("test", r"`!p snip.rv = t[2].upper()`${1:h${2:welt}o}`!p snip.rv = t[2].upper()`") - keys = "test" + EX + JF + "okay" - wanted = "OKAYhokayoOKAY" -class PythonCode_AccessKilledTabstop_OverwriteFirst(_VimTest): - snippets = ("test", r"`!p snip.rv = t[2].upper()`${1:h${2:welt}o}`!p snip.rv = t[2].upper()`") - keys = "test" + EX + "aaa" - wanted = "aaa" - -class PythonVisual_NoVisualSelection_Ignore(_VimTest): - snippets = ("test", "h`!p snip.rv = snip.v.mode + snip.v.text`b") - keys = "test" + EX + "abc" - wanted = "hbabc" -class PythonVisual_SelectOneWord(_VimTest): - snippets = ("test", "h`!p snip.rv = snip.v.mode + snip.v.text`b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hvblablubb" -class PythonVisual_LineSelect_Simple(_VimTest): - snippets = ("test", "h`!p snip.rv = snip.v.mode + snip.v.text`b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "hVhello\nnice\nworld\nb" - -# Tests for https://bugs.launchpad.net/bugs/1259349 -class Python_WeirdScoping_Error(_VimTest): - snippets = ("test", "h`!p import re; snip.rv = '%i' % len([re.search for i in 'aiiia'])`b") - keys = "test" + EX - wanted = "h5b" -# End: New Implementation #}}} -# End: PythonCode Interpolation #}}} -# Mirrors {{{# -class TextTabStopTextAfterTab_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 Hinten\n$1") - keys = "test" + EX + "hallo" - wanted = "hallo Hinten\nhallo" -class TextTabStopTextBeforeTab_ExceptCorrectResult(_VimTest): - snippets = ("test", "Vorne $1\n$1") - keys = "test" + EX + "hallo" - wanted = "Vorne hallo\nhallo" -class TextTabStopTextSurroundedTab_ExceptCorrectResult(_VimTest): - snippets = ("test", "Vorne $1 Hinten\n$1") - keys = "test" + EX + "hallo test" - wanted = "Vorne hallo test Hinten\nhallo test" - -class TextTabStopTextBeforeMirror_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\nVorne $1") - keys = "test" + EX + "hallo" - wanted = "hallo\nVorne hallo" -class TextTabStopAfterMirror_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1 Hinten") - keys = "test" + EX + "hallo" - wanted = "hallo\nhallo Hinten" -class TextTabStopSurroundMirror_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\nVorne $1 Hinten") - keys = "test" + EX + "hallo welt" - wanted = "hallo welt\nVorne hallo welt Hinten" -class TextTabStopAllSurrounded_ExceptCorrectResult(_VimTest): - snippets = ("test", "ObenVorne $1 ObenHinten\nVorne $1 Hinten") - keys = "test" + EX + "hallo welt" - wanted = "ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten" - -class MirrorBeforeTabstopLeave_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1:this is it} $1") - keys = "test" + EX - wanted = "this is it this is it this is it" -class MirrorBeforeTabstopOverwrite_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1:this is it} $1") - keys = "test" + EX + "a" - wanted = "a a a" - -class TextTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1") - keys = "test" + EX + "hallo" - wanted = "hallo\nhallo" -class SimpleMirrorMultilineMany_ExceptCorrectResult(_VimTest): - snippets = ("test", " $1\n$1\na$1b\n$1\ntest $1 mich") - keys = "test" + EX + "hallo" - wanted = " hallo\nhallo\nahallob\nhallo\ntest hallo mich" -class MultilineTabStopSimpleMirrorMultiline_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n\n$1\n\n$1") - keys = "test" + EX + "hallo Du\nHi" - wanted = "hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi" -class MultilineTabStopSimpleMirrorMultiline1_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1\n$1") - keys = "test" + EX + "hallo Du\nHi" - wanted = "hallo Du\nHi\nhallo Du\nHi\nhallo Du\nHi" -class MultilineTabStopSimpleMirrorDeleteInLine_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1\n$1") - keys = "test" + EX + "hallo Du\nHi\b\bAch Blah" - wanted = "hallo Du\nAch Blah\nhallo Du\nAch Blah\nhallo Du\nAch Blah" -class TextTabStopSimpleMirrorMultilineMirrorInFront_ECR(_VimTest): - snippets = ("test", "$1\n${1:sometext}") - keys = "test" + EX + "hallo\nagain" - wanted = "hallo\nagain\nhallo\nagain" - -class SimpleMirrorDelete_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1") - keys = "test" + EX + "hallo\b\b" - wanted = "hal\nhal" - -class SimpleMirrorSameLine_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 $1") - keys = "test" + EX + "hallo" - wanted = "hallo hallo" -class SimpleMirrorSameLine_InText_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 $1") - keys = "ups test blah" + ESC + "02f i" + EX + "hallo" - wanted = "ups hallo hallo blah" -class SimpleMirrorSameLineBeforeTabDefVal_ECR(_VimTest): - snippets = ("test", "$1 ${1:replace me}") - keys = "test" + EX + "hallo foo" - wanted = "hallo foo hallo foo" -class SimpleMirrorSameLineBeforeTabDefVal_DelB4Typing_ECR(_VimTest): - snippets = ("test", "$1 ${1:replace me}") - keys = "test" + EX + BS + "hallo foo" - wanted = "hallo foo hallo foo" -class SimpleMirrorSameLineMany_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 $1 $1 $1") - keys = "test" + EX + "hallo du" - wanted = "hallo du hallo du hallo du hallo du" -class SimpleMirrorSameLineManyMultiline_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 $1 $1 $1") - keys = "test" + EX + "hallo du\nwie gehts" - wanted = "hallo du\nwie gehts hallo du\nwie gehts hallo du\nwie gehts" \ - " hallo du\nwie gehts" -class SimpleMirrorDeleteSomeEnterSome_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1\n$1") - keys = "test" + EX + "hallo\b\bhups" - wanted = "halhups\nhalhups" - -class SimpleTabstopWithDefaultSimpelType_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:defa}\n$1") - keys = "test" + EX + "world" - wanted = "ha world\nworld" -class SimpleTabstopWithDefaultComplexType_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror") - keys = "test" + EX + "world" - wanted = "ha world world\nanother: world mirror" -class SimpleTabstopWithDefaultSimpelKeep_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:defa}\n$1") - keys = "test" + EX - wanted = "ha defa\ndefa" -class SimpleTabstopWithDefaultComplexKeep_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:default value} $1\nanother: $1 mirror") - keys = "test" + EX - wanted = "ha default value default value\nanother: default value mirror" - -class TabstopWithMirrorManyFromAll_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $5 ${1:blub} $4 $0 ${2:$1.h} $1 $3 ${4:More}") - keys = "test" + EX + "hi" + JF + "hu" + JF + "hub" + JF + "hulla" + \ - JF + "blah" + JF + "end" - wanted = "ha blah hi hulla end hu hi hub hulla" -class TabstopWithMirrorInDefaultNoType_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:blub} ${2:$1.h}") - keys = "test" + EX - wanted = "ha blub blub.h" -class TabstopWithMirrorInDefaultNoType1_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha ${1:blub} ${2:$1}") - keys = "test" + EX - wanted = "ha blub blub" -class TabstopWithMirrorInDefaultTwiceAndExtra_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:$1.h $1.c}\ntest $1") - keys = "test" + EX + "stdin" - wanted = "ha stdin stdin.h stdin.c\ntest stdin" -class TabstopWithMirrorInDefaultMultipleLeave_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:snip} ${3:$1.h $2}") - keys = "test" + EX + "stdin" - wanted = "ha stdin snip stdin.h snip" -class TabstopWithMirrorInDefaultMultipleOverwrite_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:snip} ${3:$1.h $2}") - keys = "test" + EX + "stdin" + JF + "do snap" - wanted = "ha stdin do snap stdin.h do snap" -class TabstopWithMirrorInDefaultOverwrite_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:$1.h}") - keys = "test" + EX + "stdin" + JF + "overwritten" - wanted = "ha stdin overwritten" -class TabstopWithMirrorInDefaultOverwrite1_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:$1}") - keys = "test" + EX + "stdin" + JF + "overwritten" - wanted = "ha stdin overwritten" -class TabstopWithMirrorInDefaultNoOverwrite1_ExceptCorrectResult(_VimTest): - snippets = ("test", "ha $1 ${2:$1}") - keys = "test" + EX + "stdin" + JF + JF + "end" - wanted = "ha stdin stdinend" - -class MirrorRealLifeExample_ExceptCorrectResult(_VimTest): - snippets = ( - ("for", "for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2})" \ - "\n{\n\t${0:/* code */}\n}"), - ) - keys ="for" + EX + "100" + JF + "avar\b\b\b\ba_variable" + JF + \ - "a_variable *= 2" + JF + "// do nothing" - wanted = """for(size_t a_variable = 0; a_variable < 100; a_variable *= 2) -{ -\t// do nothing -}""" - -class Mirror_TestKill_InsertBefore_NoKill(_VimTest): - snippets = "test", "$1 $1_" - keys = "hallo test" + EX + "auch" + ESC + "wihi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noauch hinoauch_end" -class Mirror_TestKill_InsertAfter_NoKill(_VimTest): - snippets = "test", "$1 $1_" - keys = "hallo test" + EX + "auch" + ESC + "eiab" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noauch noauchab_end" -class Mirror_TestKill_InsertBeginning_Kill(_VimTest): - snippets = "test", "$1 $1_" - keys = "hallo test" + EX + "auch" + ESC + "wahi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noauch ahiuch_end" -class Mirror_TestKill_InsertEnd_Kill(_VimTest): - snippets = "test", "$1 $1_" - keys = "hallo test" + EX + "auch" + ESC + "ehihi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noauch auchih_end" -class Mirror_TestKillTabstop_Kill(_VimTest): - snippets = "test", "welt${1:welt${2:welt}welt} $2" - keys = "hallo test" + EX + "elt" - wanted = "hallo weltelt " - -# End: Mirrors #}}} -# Transformations {{{# -class Transformation_SimpleCase_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/foo/batzl/}") - keys = "test" + EX + "hallo foo boy" - wanted = "hallo foo boy hallo batzl boy" -class Transformation_SimpleCaseNoTransform_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/foo/batzl/}") - keys = "test" + EX + "hallo" - wanted = "hallo hallo" -class Transformation_SimpleCaseTransformInFront_ExceptCorrectResult(_VimTest): - snippets = ("test", "${1/foo/batzl/} $1") - keys = "test" + EX + "hallo foo" - wanted = "hallo batzl hallo foo" -class Transformation_SimpleCaseTransformInFrontDefVal_ECR(_VimTest): - snippets = ("test", "${1/foo/batzl/} ${1:replace me}") - keys = "test" + EX + "hallo foo" - wanted = "hallo batzl hallo foo" -class Transformation_MultipleTransformations_ECR(_VimTest): - snippets = ("test", "${1:Some Text}${1/.+/\\U$0\E/}\n${1/.+/\L$0\E/}") - keys = "test" + EX + "SomE tExt " - wanted = "SomE tExt SOME TEXT \nsome text " -class Transformation_TabIsAtEndAndDeleted_ECR(_VimTest): - snippets = ("test", "${1/.+/is something/}${1:some}") - keys = "hallo test" + EX + "some\b\b\b\b\b" - wanted = "hallo " -class Transformation_TabIsAtEndAndDeleted1_ECR(_VimTest): - snippets = ("test", "${1/.+/is something/}${1:some}") - keys = "hallo test" + EX + "some\b\b\b\bmore" - wanted = "hallo is somethingmore" -class Transformation_TabIsAtEndNoTextLeave_ECR(_VimTest): - snippets = ("test", "${1/.+/is something/}${1}") - keys = "hallo test" + EX - wanted = "hallo " -class Transformation_TabIsAtEndNoTextType_ECR(_VimTest): - snippets = ("test", "${1/.+/is something/}${1}") - keys = "hallo test" + EX + "b" - wanted = "hallo is somethingb" -class Transformation_InsideTabLeaveAtDefault_ECR(_VimTest): - snippets = ("test", r"$1 ${2:${1/.+/(?0:defined $0)/}}") - keys = "test" + EX + "sometext" + JF - wanted = "sometext defined sometext" -class Transformation_InsideTabOvertype_ECR(_VimTest): - snippets = ("test", r"$1 ${2:${1/.+/(?0:defined $0)/}}") - keys = "test" + EX + "sometext" + JF + "overwrite" - wanted = "sometext overwrite" - - -class Transformation_Backreference_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/([ab])oo/$1ull/}") - keys = "test" + EX + "foo boo aoo" - wanted = "foo boo aoo foo bull aoo" -class Transformation_BackreferenceTwice_ExceptCorrectResult(_VimTest): - snippets = ("test", r"$1 ${1/(dead) (par[^ ]*)/this $2 is a bit $1/}") - keys = "test" + EX + "dead parrot" - wanted = "dead parrot this parrot is a bit dead" - -class Transformation_CleverTransformUpercaseChar_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(.)/\\u$1/}") - keys = "test" + EX + "hallo" - wanted = "hallo Hallo" -class Transformation_CleverTransformLowercaseChar_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(.*)/\l$1/}") - keys = "test" + EX + "Hallo" - wanted = "Hallo hallo" -class Transformation_CleverTransformLongUpper_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(.*)/\\U$1\E/}") - keys = "test" + EX + "hallo" - wanted = "hallo HALLO" -class Transformation_CleverTransformLongLower_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(.*)/\L$1\E/}") - keys = "test" + EX + "HALLO" - wanted = "HALLO hallo" - -class Transformation_SimpleCaseAsciiResult(_VimTest): - skip_if = lambda self: no_unidecode_available() - snippets = ("ascii", "$1 ${1/(.*)/$1/a}") - keys = "ascii" + EX + "éèàçôïÉÈÀÇÔÏ€" - wanted = "éèàçôïÉÈÀÇÔÏ€ eeacoiEEACOIEU" -class Transformation_LowerCaseAsciiResult(_VimTest): - skip_if = lambda self: no_unidecode_available() - snippets = ("ascii", "$1 ${1/(.*)/\L$1\E/a}") - keys = "ascii" + EX + "éèàçôïÉÈÀÇÔÏ€" - wanted = "éèàçôïÉÈÀÇÔÏ€ eeacoieeacoieu" - -class Transformation_ConditionalInsertionSimple_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(^a).*/(?0:began with an a)/}") - keys = "test" + EX + "a some more text" - wanted = "a some more text began with an a" -class Transformation_CIBothDefinedNegative_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}") - keys = "test" + EX + "b some" - wanted = "b some no" -class Transformation_CIBothDefinedPositive_ExceptCorrectResult(_VimTest): - snippets = ("test", "$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}") - keys = "test" + EX + "a some" - wanted = "a some yes" -class Transformation_ConditionalInsertRWEllipsis_ECR(_VimTest): - snippets = ("test", r"$1 ${1/(\w+(?:\W+\w+){,7})\W*(.+)?/$1(?2:...)/}") - keys = "test" + EX + "a b c d e f ghhh h oha" - wanted = "a b c d e f ghhh h oha a b c d e f ghhh h..." -class Transformation_ConditionalInConditional_ECR(_VimTest): - snippets = ("test", r"$1 ${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}") - keys = "test" + EX + "hallo" + ESC + "$a\n" + \ - "test" + EX + "hallo-" + ESC + "$a\n" + \ - "test" + EX + "hallo->" - wanted = "hallo .\nhallo- >\nhallo-> " - -class Transformation_CINewlines_ECR(_VimTest): - snippets = ("test", r"$1 ${1/, */\n/}") - keys = "test" + EX + "test, hallo" - wanted = "test, hallo test\nhallo" -class Transformation_CITabstop_ECR(_VimTest): - snippets = ("test", r"$1 ${1/, */\t/}") - keys = "test" + EX + "test, hallo" - wanted = "test, hallo test\thallo" -class Transformation_CIEscapedParensinReplace_ECR(_VimTest): - snippets = ("test", r"$1 ${1/hal((?:lo)|(?:ul))/(?1:ha\($1\))/}") - keys = "test" + EX + "test, halul" - wanted = "test, halul test, ha(ul)" - -class Transformation_OptionIgnoreCase_ECR(_VimTest): - snippets = ("test", r"$1 ${1/test/blah/i}") - keys = "test" + EX + "TEST" - wanted = "TEST blah" -class Transformation_OptionReplaceGlobal_ECR(_VimTest): - snippets = ("test", r"$1 ${1/, */-/g}") - keys = "test" + EX + "a, nice, building" - wanted = "a, nice, building a-nice-building" -class Transformation_OptionReplaceGlobalMatchInReplace_ECR(_VimTest): - snippets = ("test", r"$1 ${1/, */, /g}") - keys = "test" + EX + "a, nice, building" - wanted = "a, nice, building a, nice, building" -class TransformationUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest): - snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} " - "${1:default} ${2:def}") - keys = "test" + EX + BS + JF + "hi" - wanted = "snip m2 hi" -class TransformationUsingBackspaceToDeleteDefaultValueInSecondTab_ECR(_VimTest): - snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} " - "${1:default} ${2:def}") - keys = "test" + EX + "hi" + JF + BS - wanted = "snip m1 hi " -class TransformationUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest): - snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}") - keys = "test" + EX + BS + "hallo" - wanted = "snip matched hallo" -class TransformationUsingBackspaceToDeleteDefaultValue_ECR(_VimTest): - snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}") - keys = "test" + EX + BS - wanted = "snip " -class Transformation_TestKill_InsertBefore_NoKill(_VimTest): - snippets = "test", r"$1 ${1/.*/\L$0$0\E/}_" - keys = "hallo test" + EX + "AUCH" + ESC + "wihi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noAUCH hinoauchnoauch_end" -class Transformation_TestKill_InsertAfter_NoKill(_VimTest): - snippets = "test", r"$1 ${1/.*/\L$0$0\E/}_" - keys = "hallo test" + EX + "AUCH" + ESC + "eiab" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noAUCH noauchnoauchab_end" -class Transformation_TestKill_InsertBeginning_Kill(_VimTest): - snippets = "test", r"$1 ${1/.*/\L$0$0\E/}_" - keys = "hallo test" + EX + "AUCH" + ESC + "wahi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noAUCH ahiuchauch_end" -class Transformation_TestKill_InsertEnd_Kill(_VimTest): - snippets = "test", r"$1 ${1/.*/\L$0$0\E/}_" - keys = "hallo test" + EX + "AUCH" + ESC + "ehihi" + ESC + "bb" + "ino" + JF + "end" - wanted = "hallo noAUCH auchauchih_end" -# End: Transformations #}}} -# ${VISUAL} {{{# -class Visual_NoVisualSelection_Ignore(_VimTest): - snippets = ("test", "h${VISUAL}b") - keys = "test" + EX + "abc" - wanted = "hbabc" -class Visual_SelectOneWord(_VimTest): - snippets = ("test", "h${VISUAL}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hblablubb" -class Visual_SelectOneWord_ProblemAfterTab(_VimTest): - snippets = ("test", "h${VISUAL}b", "", "i") - keys = "\tblablub" + ESC + "5hv3l" + EX + "test" + EX - wanted = "\tbhlablbub" -class VisualWithDefault_ExpandWithoutVisual(_VimTest): - snippets = ("test", "h${VISUAL:world}b") - keys = "test" + EX + "hi" - wanted = "hworldbhi" -class VisualWithDefaultWithSlashes_ExpandWithoutVisual(_VimTest): - snippets = ("test", r"h${VISUAL:\/\/ body}b") - keys = "test" + EX + "hi" - wanted = "h// bodybhi" -class VisualWithDefault_ExpandWithVisual(_VimTest): - snippets = ("test", "h${VISUAL:world}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hblablubb" - -class Visual_ExpandTwice(_VimTest): - snippets = ("test", "h${VISUAL}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX + "\ntest" + EX - wanted = "hblablubb\nhb" - -class Visual_SelectOneWord_TwiceVisual(_VimTest): - snippets = ("test", "h${VISUAL}b${VISUAL}a") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hblablubbblabluba" -class Visual_SelectOneWord_Inword(_VimTest): - snippets = ("test", "h${VISUAL}b", "Description", "i") - keys = "blablub" + ESC + "0lv4l" + EX + "test" + EX - wanted = "bhlablubb" -class Visual_SelectOneWord_TillEndOfLine(_VimTest): - snippets = ("test", "h${VISUAL}b", "Description", "i") - keys = "blablub" + ESC + "0v$" + EX + "test" + EX + ESC + "o" - wanted = "hblablub\nb" -class Visual_SelectOneWordWithTabstop_TillEndOfLine(_VimTest): - snippets = ("test", "h${2:ahh}${VISUAL}${1:ups}b", "Description", "i") - keys = "blablub" + ESC + "0v$" + EX + "test" + EX + "mmm" + JF + "n" + JF + "done" + ESC + "o" - wanted = "hnblablub\nmmmbdone" -class Visual_InDefaultText_SelectOneWord_NoOverwrite(_VimTest): - snippets = ("test", "h${1:${VISUAL}}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX + JF + "hello" - wanted = "hblablubbhello" -class Visual_InDefaultText_SelectOneWord(_VimTest): - snippets = ("test", "h${1:${VISUAL}}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX + "hello" - wanted = "hhellob" - -class Visual_CrossOneLine(_VimTest): - snippets = ("test", "h${VISUAL}b") - keys = "bla blub\n helloi" + ESC + "0k4lvjll" + EX + "test" + EX - wanted = "bla hblub\n hellobi" - -class Visual_LineSelect_Simple(_VimTest): - snippets = ("test", "h${VISUAL}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "hhello\n nice\n worldb" -class Visual_InDefaultText_LineSelect_NoOverwrite(_VimTest): - snippets = ("test", "h${1:bef${VISUAL}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + JF + "hi" - wanted = "hbefhello\n nice\n worldaftbhi" -class Visual_InDefaultText_LineSelect_Overwrite(_VimTest): - snippets = ("test", "h${1:bef${VISUAL}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + "jup" + JF + "hi" - wanted = "hjupbhi" -class Visual_LineSelect_CheckIndentSimple(_VimTest): - snippets = ("test", "beg\n\t${VISUAL}\nend") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "beg\n\thello\n\tnice\n\tworld\nend" -class Visual_LineSelect_CheckIndentTwice(_VimTest): - snippets = ("test", "beg\n\t${VISUAL}\nend") - keys = " hello\n nice\n\tworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "beg\n\t hello\n\t nice\n\t\tworld\nend" -class Visual_InDefaultText_IndentSpacesToTabstop_NoOverwrite(_VimTest): - snippets = ("test", "h${1:beforea${VISUAL}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + JF + "hi" - wanted = "hbeforeahello\n\tnice\n\tworldaftbhi" -class Visual_InDefaultText_IndentSpacesToTabstop_Overwrite(_VimTest): - snippets = ("test", "h${1:beforea${VISUAL}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + "ups" + JF + "hi" - wanted = "hupsbhi" -class Visual_InDefaultText_IndentSpacesToTabstop_NoOverwrite1(_VimTest): - snippets = ("test", "h${1:beforeaaa${VISUAL}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + JF + "hi" - wanted = "hbeforeaaahello\n\t nice\n\t worldaftbhi" -class Visual_InDefaultText_IndentBeforeTabstop_NoOverwrite(_VimTest): - snippets = ("test", "hello\n\t ${1:${VISUAL}}\nend") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + JF + "hi" - wanted = "hello\n\t hello\n\t nice\n\t world\nendhi" - -class Visual_LineSelect_WithTabStop(_VimTest): - snippets = ("test", "beg\n\t${VISUAL}\n\t${1:here_we_go}\nend") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + "super" + JF + "done" - wanted = "beg\n\thello\n\tnice\n\tworld\n\tsuper\nenddone" -class Visual_LineSelect_CheckIndentWithTS_NoOverwrite(_VimTest): - snippets = ("test", "beg\n\t${0:${VISUAL}}\nend") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "beg\n\thello\n\tnice\n\tworld\nend" -class Visual_LineSelect_DedentLine(_VimTest): - snippets = ("if", "if {\n\t${VISUAL}$0\n}") - keys = "if" + EX + "one\n\ttwo\n\tthree" + ESC + ARR_U*2 + "V" + ARR_D + EX + "\tif" + EX - wanted = "if {\n\tif {\n\t\tone\n\t\ttwo\n\t}\n\tthree\n}" - -class VisualTransformation_SelectOneWord(_VimTest): - snippets = ("test", r"h${VISUAL/./\U$0\E/g}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hBLABLUBb" -class VisualTransformationWithDefault_ExpandWithoutVisual(_VimTest): - snippets = ("test", r"h${VISUAL:world/./\U$0\E/g}b") - keys = "test" + EX + "hi" - wanted = "hWORLDbhi" -class VisualTransformationWithDefault_ExpandWithVisual(_VimTest): - snippets = ("test", r"h${VISUAL:world/./\U$0\E/g}b") - keys = "blablub" + ESC + "0v6l" + EX + "test" + EX - wanted = "hBLABLUBb" -class VisualTransformation_LineSelect_Simple(_VimTest): - snippets = ("test", r"h${VISUAL/./\U$0\E/g}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX - wanted = "hHELLO\n NICE\n WORLDb" -class VisualTransformation_InDefaultText_LineSelect_NoOverwrite(_VimTest): - snippets = ("test", r"h${1:bef${VISUAL/./\U$0\E/g}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + JF + "hi" - wanted = "hbefHELLO\n NICE\n WORLDaftbhi" -class VisualTransformation_InDefaultText_LineSelect_Overwrite(_VimTest): - snippets = ("test", r"h${1:bef${VISUAL/./\U$0\E/g}aft}b") - keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX + "jup" + JF + "hi" - wanted = "hjupbhi" - -# End: ${VISUAL} #}}} - -# Recursive (Nested) Snippets {{{# -class RecTabStops_SimpleCase_ExceptCorrectResult(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "m" + EX + "hello" + JF + "world" + JF + "ups" + JF + "end" - wanted = "[ [ hello world ]ups end ]" -class RecTabStops_SimpleCaseLeaveSecondSecond_ExceptCorrectResult(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "m" + EX + "hello" + JF + "world" + JF + JF + JF + "end" - wanted = "[ [ hello world ] sec ]end" -class RecTabStops_SimpleCaseLeaveFirstSecond_ExceptCorrectResult(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "m" + EX + "hello" + JF + JF + JF + "world" + JF + "end" - wanted = "[ [ hello sec ] world ]end" - -class RecTabStops_InnerWOTabStop_ECR(_VimTest): - snippets = ( - ("m1", "Just some Text"), - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m1" + EX + "hi" + JF + "two" + JF + "end" - wanted = "[ Just some Texthi two ]end" -class RecTabStops_InnerWOTabStopTwiceDirectly_ECR(_VimTest): - snippets = ( - ("m1", "JST"), - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m1" + EX + " m1" + EX + "hi" + JF + "two" + JF + "end" - wanted = "[ JST JSThi two ]end" -class RecTabStops_InnerWOTabStopTwice_ECR(_VimTest): - snippets = ( - ("m1", "JST"), - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m1" + EX + JF + "m1" + EX + "hi" + JF + "end" - wanted = "[ JST JSThi ]end" -class RecTabStops_OuterOnlyWithZeroTS_ECR(_VimTest): - snippets = ( - ("m", "A $0 B"), - ("m1", "C $1 D $0 E"), - ) - keys = "m" + EX + "m1" + EX + "CD" + JF + "DE" - wanted = "A C CD D DE E B" -class RecTabStops_OuterOnlyWithZero_ECR(_VimTest): - snippets = ( - ("m", "A $0 B"), - ("m1", "C $1 D $0 E"), - ) - keys = "m" + EX + "m1" + EX + "CD" + JF + "DE" - wanted = "A C CD D DE E B" -class RecTabStops_ExpandedInZeroTS_ECR(_VimTest): - snippets = ( - ("m", "A $0 B $1"), - ("m1", "C $1 D $0 E"), - ) - keys = "m" + EX + "hi" + JF + "m1" + EX + "CD" + JF + "DE" - wanted = "A C CD D DE E B hi" -class RecTabStops_ExpandedInZeroTSTwice_ECR(_VimTest): - snippets = ( - ("m", "A $0 B $1"), - ("m1", "C $1 D $0 E"), - ) - keys = "m" + EX + "hi" + JF + "m" + EX + "again" + JF + "m1" + \ - EX + "CD" + JF + "DE" - wanted = "A A C CD D DE E B again B hi" -class RecTabStops_ExpandedInZeroTSSecondTime_ECR(_VimTest): - snippets = ( - ("m", "A $0 B $1"), - ("m1", "C $1 D $0 E"), - ) - keys = "m" + EX + "hi" + JF + "m" + EX + "m1" + EX + "CD" + JF + "DE" + JF + "AB" - wanted = "A A AB B C CD D DE E B hi" -class RecTabsStops_TypeInZero_ECR(_VimTest): - snippets = ( - ("v", r"\vec{$1}", "Vector", "w"), - ("frac", r"\frac{${1:one}}${0:zero}{${2:two}}", "Fractio", "w"), - ) - keys = "v" + EX + "frac" + EX + "a" + JF + "b" + JF + "frac" + EX + "aa" + JF + JF + "cc" + JF + \ - "hello frac" + EX + JF + JF + "world" - wanted = r"\vec{\frac{a}\frac{aa}cc{two}{b}}hello \frac{one}world{two}" -class RecTabsStops_TypeInZero2_ECR(_VimTest): - snippets = ( - ("m", r"_${0:explicit zero}", "snip", "i"), - ) - keys = "m" + EX + "hello m" + EX + "world m" + EX + "end" - wanted = r"_hello _world _end" -class RecTabsStops_BackspaceZero_ECR(_VimTest): - snippets = ( - ("m", r"${1:one}${0:explicit zero}${2:two}", "snip", "i"), - ) - keys = "m" + EX + JF + JF + BS + "m" + EX - wanted = r"oneoneexplicit zerotwotwo" - - -class RecTabStops_MirrorInnerSnippet_ECR(_VimTest): - snippets = ( - ("m", "[ $1 $2 ] $1"), - ("m1", "ASnip $1 ASnip $2 ASnip"), - ) - keys = "m" + EX + "m1" + EX + "Hallo" + JF + "Hi" + JF + "endone" + JF + "two" + JF + "totalend" - wanted = "[ ASnip Hallo ASnip Hi ASnipendone two ] ASnip Hallo ASnip Hi ASnipendonetotalend" - -class RecTabStops_NotAtBeginningOfTS_ExceptCorrectResult(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "hello m" + EX + "hi" + JF + "two" + JF + "ups" + JF + "three" + \ - JF + "end" - wanted = "[ hello [ hi two ]ups three ]end" -class RecTabStops_InNewlineInTabstop_ExceptCorrectResult(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "hello\nm" + EX + "hi" + JF + "two" + JF + "ups" + JF + "three" + \ - JF + "end" - wanted = "[ hello\n[ hi two ]ups three ]end" -class RecTabStops_InNewlineInTabstopNotAtBeginOfLine_ECR(_VimTest): - snippets = ("m", "[ ${1:first} ${2:sec} ]") - keys = "m" + EX + "hello\nhello again m" + EX + "hi" + JF + "two" + \ - JF + "ups" + JF + "three" + JF + "end" - wanted = "[ hello\nhello again [ hi two ]ups three ]end" - -class RecTabStops_InNewlineMultiline_ECR(_VimTest): - snippets = ("m", "M START\n$0\nM END") - keys = "m" + EX + "m" + EX - wanted = "M START\nM START\n\nM END\nM END" -class RecTabStops_InNewlineManualIndent_ECR(_VimTest): - snippets = ("m", "M START\n$0\nM END") - keys = "m" + EX + " m" + EX + "hi" - wanted = "M START\n M START\n hi\n M END\nM END" -class RecTabStops_InNewlineManualIndentTextInFront_ECR(_VimTest): - snippets = ("m", "M START\n$0\nM END") - keys = "m" + EX + " hallo m" + EX + "hi" - wanted = "M START\n hallo M START\n hi\n M END\nM END" -class RecTabStops_InNewlineMultilineWithIndent_ECR(_VimTest): - snippets = ("m", "M START\n $0\nM END") - keys = "m" + EX + "m" + EX + "hi" - wanted = "M START\n M START\n hi\n M END\nM END" -class RecTabStops_InNewlineMultilineWithNonZeroTS_ECR(_VimTest): - snippets = ("m", "M START\n $1\nM END -> $0") - keys = "m" + EX + "m" + EX + "hi" + JF + "hallo" + JF + "end" - wanted = "M START\n M START\n hi\n M END -> hallo\n" \ - "M END -> end" - -class RecTabStops_BarelyNotLeavingInner_ECR(_VimTest): - snippets = ( - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m" + EX + "a" + 3*ARR_L + JF + "hallo" + \ - JF + "ups" + JF + "world" + JF + "end" - wanted = "[ [ a hallo ]ups world ]end" -class RecTabStops_LeavingInner_ECR(_VimTest): - snippets = ( - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \ - JF + "world" - wanted = "[ [ a sec ] hallo ]world" -class RecTabStops_LeavingInnerInner_ECR(_VimTest): - snippets = ( - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \ - JF + "ups" + JF + "world" + JF + "end" - wanted = "[ [ [ a sec ] hallo ]ups world ]end" -class RecTabStops_LeavingInnerInnerTwo_ECR(_VimTest): - snippets = ( - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m" + EX + "m" + EX + "a" + 6*ARR_L + JF + "hallo" + \ - JF + "end" - wanted = "[ [ [ a sec ] sec ] hallo ]end" - - -class RecTabStops_ZeroTSisNothingSpecial_ECR(_VimTest): - snippets = ( - ("m1", "[ ${1:first} $0 ${2:sec} ]"), - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m1" + EX + "one" + JF + "two" + \ - JF + "three" + JF + "four" + JF + "end" - wanted = "[ [ one three two ] four ]end" -class RecTabStops_MirroredZeroTS_ECR(_VimTest): - snippets = ( - ("m1", "[ ${1:first} ${0:Year, some default text} $0 ${2:sec} ]"), - ("m", "[ ${1:first} ${2:sec} ]"), - ) - keys = "m" + EX + "m1" + EX + "one" + JF + "two" + \ - JF + "three" + JF + "four" + JF + "end" - wanted = "[ [ one three three two ] four ]end" -class RecTabStops_ChildTriggerContainsParentTextObjects(_VimTest): - # https://bugs.launchpad.net/bugs/1191617 - snippets_test_file = ("all", r""" -global !p -def complete(t, opts): - if t: - opts = [ q[len(t):] for q in opts if q.startswith(t) ] - if len(opts) == 0: - return '' - return opts[0] if len(opts) == 1 else "(" + '|'.join(opts) + ')' -def autocomplete_options(t, string, attr=None): - return complete(t[1], [opt for opt in attr if opt not in string]) -endglobal -snippet /form_for(.*){([^|]*)/ "form_for html options" rw! -`!p -auto = autocomplete_options(t, match.group(2), attr=["id: ", "class: ", "title: "]) -snip.rv = "form_for" + match.group(1) + "{"`$1`!p if (snip.c != auto) : snip.rv=auto` -endsnippet -""") - keys = "form_for user, namespace: some_namespace, html: {i" + EX + "i" + EX - wanted = "form_for user, namespace: some_namespace, html: {(id: |class: |title: )d: " -# End: Recursive (Nested) Snippets #}}} -# List Snippets {{{# -class _ListAllSnippets(_VimTest): - snippets = ( ("testblah", "BLAAH", "Say BLAH"), - ("test", "TEST ONE", "Say tst one"), - ("aloha", "OHEEEE", "Say OHEE"), - ) - -class ListAllAvailable_NothingTyped_ExceptCorrectResult(_ListAllSnippets): - keys = "" + LS + "3\n" - wanted = "BLAAH" -class ListAllAvailable_SpaceInFront_ExceptCorrectResult(_ListAllSnippets): - keys = " " + LS + "3\n" - wanted = " BLAAH" -class ListAllAvailable_BraceInFront_ExceptCorrectResult(_ListAllSnippets): - keys = "} " + LS + "3\n" - wanted = "} BLAAH" -class ListAllAvailable_testtyped_ExceptCorrectResult(_ListAllSnippets): - keys = "hallo test" + LS + "2\n" - wanted = "hallo BLAAH" -class ListAllAvailable_testtypedSecondOpt_ExceptCorrectResult(_ListAllSnippets): - keys = "hallo test" + LS + "1\n" - wanted = "hallo TEST ONE" - -class ListAllAvailable_NonDefined_NoExceptionShouldBeRaised(_ListAllSnippets): - keys = "hallo qualle" + LS + "Hi" - wanted = "hallo qualleHi" -# End: List Snippets #}}} -# Selecting Between Same Triggers {{{# -class _MultipleMatches(_VimTest): - snippets = ( ("test", "Case1", "This is Case 1"), - ("test", "Case2", "This is Case 2") ) -class Multiple_SimpleCaseSelectFirst_ECR(_MultipleMatches): - keys = "test" + EX + "1\n" - wanted = "Case1" -class Multiple_SimpleCaseSelectSecond_ECR(_MultipleMatches): - keys = "test" + EX + "2\n" - wanted = "Case2" -class Multiple_SimpleCaseSelectTooHigh_ESelectLast(_MultipleMatches): - keys = "test" + EX + "5\n" - wanted = "Case2" -class Multiple_SimpleCaseSelectZero_EEscape(_MultipleMatches): - keys = "test" + EX + "0\n" + "hi" - wanted = "testhi" -class Multiple_SimpleCaseEscapeOut_ECR(_MultipleMatches): - keys = "test" + EX + ESC + "hi" - wanted = "testhi" -class Multiple_ManySnippetsOneTrigger_ECR(_VimTest): - # Snippet definition {{{# - snippets = ( - ("test", "Case1", "This is Case 1"), - ("test", "Case2", "This is Case 2"), - ("test", "Case3", "This is Case 3"), - ("test", "Case4", "This is Case 4"), - ("test", "Case5", "This is Case 5"), - ("test", "Case6", "This is Case 6"), - ("test", "Case7", "This is Case 7"), - ("test", "Case8", "This is Case 8"), - ("test", "Case9", "This is Case 9"), - ("test", "Case10", "This is Case 10"), - ("test", "Case11", "This is Case 11"), - ("test", "Case12", "This is Case 12"), - ("test", "Case13", "This is Case 13"), - ("test", "Case14", "This is Case 14"), - ("test", "Case15", "This is Case 15"), - ("test", "Case16", "This is Case 16"), - ("test", "Case17", "This is Case 17"), - ("test", "Case18", "This is Case 18"), - ("test", "Case19", "This is Case 19"), - ("test", "Case20", "This is Case 20"), - ("test", "Case21", "This is Case 21"), - ("test", "Case22", "This is Case 22"), - ("test", "Case23", "This is Case 23"), - ("test", "Case24", "This is Case 24"), - ("test", "Case25", "This is Case 25"), - ("test", "Case26", "This is Case 26"), - ("test", "Case27", "This is Case 27"), - ("test", "Case28", "This is Case 28"), - ("test", "Case29", "This is Case 29"), - ) #}}} - keys = "test" + EX + " " + ESC + ESC + "ahi" - wanted = "testhi" -# End: Selecting Between Same Triggers #}}} -# Snippet Priority {{{# -class SnippetPriorities_MultiWordTriggerOverwriteExisting(_VimTest): - snippets = ( - ("test me", "${1:Hallo}", "Types Hallo"), - ("test me", "${1:World}", "Types World"), - ("test me", "We overwrite", "Overwrite the two", "", 1), - ) - keys = "test me" + EX - wanted = "We overwrite" -class SnippetPriorities_DoNotCareAboutNonMatchings(_VimTest): - snippets = ( - ("test1", "Hallo", "Types Hallo"), - ("test2", "We overwrite", "Overwrite the two", "", 1), - ) - keys = "test1" + EX - wanted = "Hallo" -class SnippetPriorities_OverwriteExisting(_VimTest): - snippets = ( - ("test", "${1:Hallo}", "Types Hallo"), - ("test", "${1:World}", "Types World"), - ("test", "We overwrite", "Overwrite the two", "", 1), - ) - keys = "test" + EX - wanted = "We overwrite" -class SnippetPriorities_OverwriteTwice_ECR(_VimTest): - snippets = ( - ("test", "${1:Hallo}", "Types Hallo"), - ("test", "${1:World}", "Types World"), - ("test", "We overwrite", "Overwrite the two", "", 1), - ("test", "again", "Overwrite again", "", 2), - ) - keys = "test" + EX - wanted = "again" -class SnippetPriorities_OverwriteThenChoose_ECR(_VimTest): - snippets = ( - ("test", "${1:Hallo}", "Types Hallo"), - ("test", "${1:World}", "Types World"), - ("test", "We overwrite", "Overwrite the two", "", 1), - ("test", "No overwrite", "Not overwritten", "", 1), - ) - keys = "test" + EX + "1\n\n" + "test" + EX + "2\n" - wanted = "We overwrite\nNo overwrite" -class SnippetPriorities_AddedHasHigherThanFile(_VimTest): - snippets_test_file = ("all", r""" - snippet test "Test Snippet" b - This is a test snippet - endsnippet - """) - snippets = ( - ("test", "We overwrite", "Overwrite the two", "", 1), - ) - keys = "test" + EX - wanted = "We overwrite" -class SnippetPriorities_FileHasHigherThanAdded(_VimTest): - snippets_test_file = ("all", r""" - snippet test "Test Snippet" b - This is a test snippet - endsnippet - """) - snippets = ( - ("test", "We do not overwrite", "Overwrite the two", "", -1), - ) - keys = "test" + EX - wanted = "This is a test snippet" -class SnippetPriorities_FileHasHigherThanAdded(_VimTest): - snippets_test_file = ("all", r""" - priority -3 - snippet test "Test Snippet" b - This is a test snippet - endsnippet - """) - snippets = ( - ("test", "We overwrite", "Overwrite the two", "", -5), - ) - keys = "test" + EX - wanted = "This is a test snippet" -# End: Snippet Priority #}}} - - -# Snippet Options {{{# -class SnippetOptions_OnlyExpandWhenWSInFront_Expand(_VimTest): - snippets = ("test", "Expand me!", "", "b") - keys = "test" + EX - wanted = "Expand me!" -class SnippetOptions_OnlyExpandWhenWSInFront_Expand2(_VimTest): - snippets = ("test", "Expand me!", "", "b") - keys = " test" + EX - wanted = " Expand me!" -class SnippetOptions_OnlyExpandWhenWSInFront_DontExpand(_VimTest): - snippets = ("test", "Expand me!", "", "b") - keys = "a test" + EX - wanted = "a test" + EX -class SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWO(_VimTest): - snippets = ( - ("test", "Expand me!", "", "b"), - ("test", "not at beginning", "", ""), - ) - keys = "a test" + EX - wanted = "a not at beginning" -class SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWOChoose(_VimTest): - snippets = ( - ("test", "Expand me!", "", "b"), - ("test", "not at beginning", "", ""), - ) - keys = " test" + EX + "1\n" - wanted = " Expand me!" - - -class SnippetOptions_ExpandInwordSnippets_SimpleExpand(_VimTest): - snippets = (("test", "Expand me!", "", "i"), ) - keys = "atest" + EX - wanted = "aExpand me!" -class SnippetOptions_ExpandInwordSnippets_ExpandSingle(_VimTest): - snippets = (("test", "Expand me!", "", "i"), ) - keys = "test" + EX - wanted = "Expand me!" -class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand(_VimTest): - snippets = (("test", "Expand me!", "", "i"), ) - keys = "$test" + EX - wanted = "$Expand me!" -class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand2(_VimTest): - snippets = (("test", "Expand me!", "", "i"), ) - keys = "-test" + EX - wanted = "-Expand me!" -class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand3(_VimTest): - skip_if = lambda self: running_on_windows() - snippets = (("test", "Expand me!", "", "i"), ) - keys = "ßßtest" + EX - wanted = "ßßExpand me!" - -class _SnippetOptions_ExpandWordSnippets(_VimTest): - snippets = (("test", "Expand me!", "", "w"), ) -class SnippetOptions_ExpandWordSnippets_NormalExpand( - _SnippetOptions_ExpandWordSnippets): - keys = "test" + EX - wanted = "Expand me!" -class SnippetOptions_ExpandWordSnippets_NoExpand( - _SnippetOptions_ExpandWordSnippets): - keys = "atest" + EX - wanted = "atest" + EX -class SnippetOptions_ExpandWordSnippets_ExpandSuffix( - _SnippetOptions_ExpandWordSnippets): - keys = "a-test" + EX - wanted = "a-Expand me!" -class SnippetOptions_ExpandWordSnippets_ExpandSuffix2( - _SnippetOptions_ExpandWordSnippets): - keys = "a(test" + EX - wanted = "a(Expand me!" -class SnippetOptions_ExpandWordSnippets_ExpandSuffix3( - _SnippetOptions_ExpandWordSnippets): - keys = "[[test" + EX - wanted = "[[Expand me!" - -class _No_Tab_Expand(_VimTest): - snippets = ("test", "\t\tExpand\tme!\t", "", "t") -class No_Tab_Expand_Simple(_No_Tab_Expand): - keys = "test" + EX - wanted = "\t\tExpand\tme!\t" -class No_Tab_Expand_Leading_Spaces(_No_Tab_Expand): - keys = " test" + EX - wanted = " \t\tExpand\tme!\t" -class No_Tab_Expand_Leading_Tabs(_No_Tab_Expand): - keys = "\ttest" + EX - wanted = "\t\t\tExpand\tme!\t" -class No_Tab_Expand_No_TS(_No_Tab_Expand): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set sts=3\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set sts=0\n") - keys = "test" + EX - wanted = "\t\tExpand\tme!\t" -class No_Tab_Expand_ET(_No_Tab_Expand): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - keys = "test" + EX - wanted = "\t\tExpand\tme!\t" -class No_Tab_Expand_ET_Leading_Spaces(_No_Tab_Expand): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - keys = " test" + EX - wanted = " \t\tExpand\tme!\t" -class No_Tab_Expand_ET_SW(_No_Tab_Expand): - def _options_on(self): - self.send(":set sw=8\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - keys = "test" + EX - wanted = "\t\tExpand\tme!\t" -class No_Tab_Expand_ET_SW_TS(_No_Tab_Expand): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set sts=3\n") - self.send(":set ts=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set ts=8\n") - self.send(":set sts=0\n") - self.send(":set noexpandtab\n") - keys = "test" + EX - wanted = "\t\tExpand\tme!\t" - -class _TabExpand_RealWorld(object): - snippets = ("hi", -r"""hi -`!p snip.rv="i1\n" -snip.rv += snip.mkline("i1\n") -snip.shift(1) -snip.rv += snip.mkline("i2\n") -snip.unshift(2) -snip.rv += snip.mkline("i0\n") -snip.shift(3) -snip.rv += snip.mkline("i3")` -snip.rv = repr(snip.rv) -End""") - -class No_Tab_Expand_RealWorld(_TabExpand_RealWorld,_VimTest): - def _options_on(self): - self.send(":set noexpandtab\n") - def _options_off(self): - self.send(":set noexpandtab\n") - keys = "\t\thi" + EX - wanted = """\t\thi -\t\ti1 -\t\ti1 -\t\t\ti2 -\ti0 -\t\t\t\ti3 -\t\tsnip.rv = repr(snip.rv) -\t\tEnd""" - - -class SnippetOptions_Regex_Expand(_VimTest): - snippets = ("(test)", "Expand me!", "", "r") - keys = "test" + EX - wanted = "Expand me!" -class SnippetOptions_Regex_Multiple(_VimTest): - snippets = ("(test *)+", "Expand me!", "", "r") - keys = "test test test" + EX - wanted = "Expand me!" - -class _Regex_Self(_VimTest): - snippets = ("((?<=\W)|^)(\.)", "self.", "", "r") -class SnippetOptions_Regex_Self_Start(_Regex_Self): - keys = "." + EX - wanted = "self." -class SnippetOptions_Regex_Self_Space(_Regex_Self): - keys = " ." + EX - wanted = " self." -class SnippetOptions_Regex_Self_TextAfter(_Regex_Self): - keys = " .a" + EX - wanted = " .a" + EX -class SnippetOptions_Regex_Self_TextBefore(_Regex_Self): - keys = "a." + EX - wanted = "a." + EX -class SnippetOptions_Regex_PythonBlockMatch(_VimTest): - snippets = (r"([abc]+)([def]+)", r"""`!p m = match -snip.rv += m.group(2) -snip.rv += m.group(1) -`""", "", "r") - keys = "test cabfed" + EX - wanted = "test fedcab" -class SnippetOptions_Regex_PythonBlockNoMatch(_VimTest): - snippets = (r"cabfed", r"""`!p snip.rv = match or "No match"`""") - keys = "test cabfed" + EX - wanted = "test No match" -# Tests for Bug #691575 -class SnippetOptions_Regex_SameLine_Long_End(_VimTest): - snippets = ("(test.*)", "Expand me!", "", "r") - keys = "test test abc" + EX - wanted = "Expand me!" -class SnippetOptions_Regex_SameLine_Long_Start(_VimTest): - snippets = ("(.*test)", "Expand me!", "", "r") - keys = "abc test test" + EX - wanted = "Expand me!" -class SnippetOptions_Regex_SameLine_Simple(_VimTest): - snippets = ("(test)", "Expand me!", "", "r") - keys = "abc test test" + EX - wanted = "abc test Expand me!" - - -class MultiWordSnippet_Simple(_VimTest): - snippets = ("test me", "Expand me!") - keys = "test me" + EX - wanted = "Expand me!" -class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_Expand(_VimTest): - snippets = ("test it", "Expand me!", "", "b") - keys = "test it" + EX - wanted = "Expand me!" -class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_Expand2(_VimTest): - snippets = ("test it", "Expand me!", "", "b") - keys = " test it" + EX - wanted = " Expand me!" -class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_DontExpand(_VimTest): - snippets = ("test it", "Expand me!", "", "b") - keys = "a test it" + EX - wanted = "a test it" + EX -class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWO(_VimTest): - snippets = ( - ("test it", "Expand me!", "", "b"), - ("test it", "not at beginning", "", ""), - ) - keys = "a test it" + EX - wanted = "a not at beginning" -class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWOChoose(_VimTest): - snippets = ( - ("test it", "Expand me!", "", "b"), - ("test it", "not at beginning", "", ""), - ) - keys = " test it" + EX + "1\n" - wanted = " Expand me!" - -class MultiWord_SnippetOptions_ExpandInwordSnippets_SimpleExpand(_VimTest): - snippets = (("test it", "Expand me!", "", "i"), ) - keys = "atest it" + EX - wanted = "aExpand me!" -class MultiWord_SnippetOptions_ExpandInwordSnippets_ExpandSingle(_VimTest): - snippets = (("test it", "Expand me!", "", "i"), ) - keys = "test it" + EX - wanted = "Expand me!" - -class _MultiWord_SnippetOptions_ExpandWordSnippets(_VimTest): - snippets = (("test it", "Expand me!", "", "w"), ) -class MultiWord_SnippetOptions_ExpandWordSnippets_NormalExpand( - _MultiWord_SnippetOptions_ExpandWordSnippets): - keys = "test it" + EX - wanted = "Expand me!" -class MultiWord_SnippetOptions_ExpandWordSnippets_NoExpand( - _MultiWord_SnippetOptions_ExpandWordSnippets): - keys = "atest it" + EX - wanted = "atest it" + EX -class MultiWord_SnippetOptions_ExpandWordSnippets_ExpandSuffix( - _MultiWord_SnippetOptions_ExpandWordSnippets): - keys = "a-test it" + EX - wanted = "a-Expand me!" -# Snippet Options #}}} - -# Anonymous Expansion {{{# -class _AnonBase(_VimTest): - args = "" - def _options_on(self): - self.send(":inoremap " + EA + ' =UltiSnips#Anon(' - + self.args + ')\n') - def _options_off(self): - self.send(":iunmap " + EA + '\n') - -class Anon_NoTrigger_Simple(_AnonBase): - args = '"simple expand"' - keys = "abc" + EA - wanted = "abcsimple expand" - -class Anon_NoTrigger_AfterSpace(_AnonBase): - args = '"simple expand"' - keys = "abc " + EA - wanted = "abc simple expand" - -class Anon_NoTrigger_BeginningOfLine(_AnonBase): - args = r"':latex:\`$1\`$0'" - keys = EA + "Hello" + JF + "World" - wanted = ":latex:`Hello`World" -class Anon_NoTrigger_FirstCharOfLine(_AnonBase): - args = r"':latex:\`$1\`$0'" - keys = " " + EA + "Hello" + JF + "World" - wanted = " :latex:`Hello`World" - -class Anon_NoTrigger_Multi(_AnonBase): - args = '"simple $1 expand $1 $0"' - keys = "abc" + EA + "123" + JF + "456" - wanted = "abcsimple 123 expand 123 456" - -class Anon_Trigger_Multi(_AnonBase): - args = '"simple $1 expand $1 $0", "abc"' - keys = "123 abc" + EA + "123" + JF + "456" - wanted = "123 simple 123 expand 123 456" - -class Anon_Trigger_Simple(_AnonBase): - args = '"simple expand", "abc"' - keys = "abc" + EA - wanted = "simple expand" - -class Anon_Trigger_Twice(_AnonBase): - args = '"simple expand", "abc"' - keys = "abc" + EA + "\nabc" + EX - wanted = "simple expand\nabc" + EX - -class Anon_Trigger_Opts(_AnonBase): - args = '"simple expand", ".*abc", "desc", "r"' - keys = "blah blah abc" + EA - wanted = "simple expand" -# End: Anonymous Expansion #}}} -# AddSnippet Function {{{# -class _AddFuncBase(_VimTest): - args = "" - def _options_on(self): - self.send(":call UltiSnips#AddSnippetWithPriority(" - + self.args + ')\n') - -class AddFunc_Simple(_AddFuncBase): - args = '"test", "simple expand", "desc", "", "all", 0' - keys = "abc test" + EX - wanted = "abc simple expand" - -class AddFunc_Opt(_AddFuncBase): - args = '".*test", "simple expand", "desc", "r", "all", 0' - keys = "abc test" + EX - wanted = "simple expand" -# End: AddSnippet Function #}}} - -# ExpandTab {{{# -class _ExpandTabs(_VimTest): - def _options_on(self): - self.send(":set sw=3\n") - self.send(":set expandtab\n") - def _options_off(self): - self.send(":set sw=8\n") - self.send(":set noexpandtab\n") - -class RecTabStopsWithExpandtab_SimpleExample_ECR(_ExpandTabs): - snippets = ("m", "\tBlaahblah \t\t ") - keys = "m" + EX - wanted = " Blaahblah \t\t " - -class RecTabStopsWithExpandtab_SpecialIndentProblem_ECR(_ExpandTabs): - # Windows indents the Something line after pressing return, though it - # shouldn't because it contains a manual indent. All other vim versions do - # not do this. Windows vim does not interpret the changes made by :py as - # changes made 'manually', while the other vim version seem to do so. Since - # the fault is not with UltiSnips, we simply skip this test on windows - # completely. - skip_if = lambda self: running_on_windows() - snippets = ( - ("m1", "Something"), - ("m", "\t$0"), - ) - keys = "m" + EX + "m1" + EX + '\nHallo' - wanted = " Something\n Hallo" - def _options_on(self): - _ExpandTabs._options_on(self) - self.send(":set indentkeys=o,O,*,<>>,{,}\n") - self.send(":set indentexpr=8\n") - def _options_off(self): - _ExpandTabs._options_off(self) - self.send(":set indentkeys=\n") - self.send(":set indentexpr=\n") -# End: ExpandTab #}}} -# Proper Indenting {{{# -class ProperIndenting_SimpleCase_ECR(_VimTest): - snippets = ("test", "for\n blah") - keys = " test" + EX + "Hui" - wanted = " for\n blahHui" -class ProperIndenting_SingleLineNoReindenting_ECR(_VimTest): - snippets = ("test", "hui") - keys = " test" + EX + "blah" - wanted = " huiblah" -class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest): - snippets = ("test", "hui") - keys = " test" + EX + "\n"+ "blah" - wanted = " hui\n blah" - def _options_on(self): - self.send(":set autoindent\n") - def _options_off(self): - self.send(":set noautoindent\n") -# Test for bug 1073816 -class ProperIndenting_FirstLineInFile_ECR(_VimTest): - text_before = "" - text_after = "" - snippets_test_file = ("all", r""" -global !p -def complete(t, opts): - if t: - opts = [ m[len(t):] for m in opts if m.startswith(t) ] - if len(opts) == 1: - return opts[0] - elif len(opts) > 1: - return "(" + "|".join(opts) + ")" - else: - return "" -endglobal - -snippet '^#?inc' "#include <>" !r -#include <$1`!p snip.rv = complete(t[1], ['cassert', 'cstdio', 'cstdlib', 'cstring', 'fstream', 'iostream', 'sstream'])`> -endsnippet - """) - keys = "inc" + EX + "foo" - wanted = "#include " -class ProperIndenting_FirstLineInFileComplete_ECR(ProperIndenting_FirstLineInFile_ECR): - keys = "inc" + EX + "cstdl" - wanted = "#include " -# End: Proper Indenting #}}} -# Format options tests {{{# -class _FormatoptionsBase(_VimTest): - def _options_on(self): - self.send(":set tw=20\n") - self.send(":set fo=lrqntc\n") - def _options_off(self): - self.send(":set tw=0\n") - self.send(":set fo=tcq\n") - -class FOSimple_Break_ExceptCorrectResult(_FormatoptionsBase): - snippets = ("test", "${1:longer expand}\n$1\n$0", "", "f") - keys = "test" + EX + "This is a longer text that should wrap as formatoptions are enabled" + JF + "end" - wanted = "This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n" + \ - "This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n" + "end" - - -class FOTextBeforeAndAfter_ExceptCorrectResult(_FormatoptionsBase): - snippets = ("test", "Before${1:longer expand}After\nstart$1end") - keys = "test" + EX + "This is a longer text that should wrap" - wanted = \ -"""BeforeThis is a -longer text that -should wrapAfter -startThis is a -longer text that -should wrapend""" - - -# Tests for https://bugs.launchpad.net/bugs/719998 -class FOTextAfter_ExceptCorrectResult(_FormatoptionsBase): - snippets = ("test", "${1:longer expand}after\nstart$1end") - keys = ("test" + EX + "This is a longer snippet that should wrap properly " - "and the mirror below should work as well") - wanted = \ -"""This is a longer -snippet that should -wrap properly and -the mirror below -should work as wellafter -startThis is a longer -snippet that should -wrap properly and -the mirror below -should work as wellend""" - -class FOWrapOnLongWord_ExceptCorrectResult(_FormatoptionsBase): - snippets = ("test", "${1:longer expand}after\nstart$1end") - keys = ("test" + EX + "This is a longersnippet that should wrap properly") - wanted = \ -"""This is a -longersnippet that -should wrap properlyafter -startThis is a -longersnippet that -should wrap properlyend""" -# End: Format options tests #}}} -# Langmap Handling {{{# -# Test for bug 501727 # -class TestNonEmptyLangmap_ExceptCorrectResult(_VimTest): - snippets = ("testme", -"""my snipped ${1:some_default} -and a mirror: $1 -$2...$3 -$0""") - keys = "testme" + EX + "hi1" + JF + "hi2" + JF + "hi3" + JF + "hi4" - wanted ="""my snipped hi1 -and a mirror: hi1 -hi2...hi3 -hi4""" - - def _options_on(self): - self.send(":set langmap=dj,rk,nl,ln,jd,kr,DJ,RK,NL,LN,JD,KR\n") - def _options_off(self): - self.send(":set langmap=\n") - -# Test for https://bugs.launchpad.net/bugs/501727 # -class TestNonEmptyLangmapWithSemi_ExceptCorrectResult(_VimTest): - snippets = ("testme", -"""my snipped ${1:some_default} -and a mirror: $1 -$2...$3 -$0""") - keys = "testme" + EX + "hi;" + JF + "hi2" + JF + "hi3" + JF + "hi4" + ESC + ";Hello" - wanted ="""my snipped hi; -and a mirror: hi; -hi2...hi3 -hi4Hello""" - - def _options_on(self): - self.send(":set langmap=\\\\;;A\n") - def _options_off(self): - self.send(":set langmap=\n") - -# Test for bug 871357 # -class TestLangmapWithUtf8_ExceptCorrectResult(_VimTest): - skip_if = lambda self: running_on_windows() # SendKeys can't send UTF characters - snippets = ("testme", -"""my snipped ${1:some_default} -and a mirror: $1 -$2...$3 -$0""") - keys = "testme" + EX + "hi1" + JF + "hi2" + JF + "hi3" + JF + "hi4" - wanted ="""my snipped hi1 -and a mirror: hi1 -hi2...hi3 -hi4""" - - def _options_on(self): - self.send(":set langmap=йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',яz,чx,сc,мv,иb,тn,ьm,ю.,ё',ЙQ,ЦW,УE,КR,ЕT,НY,ГU,ШI,ЩO,ЗP,Х\{,Ъ\},ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж\:,Э\",ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б\<,Ю\>\n") - - def _options_off(self): - self.send(":set langmap=\n") -# End: Langmap Handling #}}} -# Unmap SelectMode Mappings {{{# -# Test for bug 427298 # -class _SelectModeMappings(_VimTest): - snippets = ("test", "${1:World}") - keys = "test" + EX + "Hello" - wanted = "Hello" - maps = ("", "") - buffer_maps = ("", "") - do_unmapping = True - ignores = [] - - def _options_on(self): - self.send(":let g:UltiSnipsRemoveSelectModeMappings=%i\n" % - int(self.do_unmapping)) - self.send(":let g:UltiSnipsMappingsToIgnore=%s\n" % - repr(self.ignores)) - - if not isinstance(self.maps[0], tuple): - self.maps = (self.maps,) - if not isinstance(self.buffer_maps[0], tuple): - self.buffer_maps = (self.buffer_maps,) - - for key, m in self.maps: - if not len(key): continue - self.send(":smap %s %s\n" % (key,m)) - for key, m in self.buffer_maps: - if not len(key): continue - self.send(":smap %s %s\n" % (key,m)) - - def _options_off(self): - for key, m in self.maps: - if not len(key): continue - self.send(":silent! sunmap %s\n" % key) - for key, m in self.buffer_maps: - if not len(key): continue - self.send(":silent! sunmap %s\n" % key) - - self.send(":let g:UltiSnipsRemoveSelectModeMappings=1\n") - self.send(":let g:UltiSnipsMappingsToIgnore= []\n") - -class SelectModeMappings_RemoveBeforeSelecting_ECR(_SelectModeMappings): - maps = ("H", "x") - wanted = "Hello" -class SelectModeMappings_DisableRemoveBeforeSelecting_ECR(_SelectModeMappings): - do_unmapping = False - maps = ("H", "x") - wanted = "xello" -class SelectModeMappings_IgnoreMappings_ECR(_SelectModeMappings): - ignores = ["e"] - maps = ("H", "x"), ("e", "l") - wanted = "Hello" -class SelectModeMappings_IgnoreMappings1_ECR(_SelectModeMappings): - ignores = ["H"] - maps = ("H", "x"), ("e", "l") - wanted = "xello" -class SelectModeMappings_IgnoreMappings2_ECR(_SelectModeMappings): - ignores = ["e", "H"] - maps = ("e", "l"), ("H", "x") - wanted = "xello" -class SelectModeMappings_BufferLocalMappings_ECR(_SelectModeMappings): - buffer_maps = ("H", "blah") - wanted = "Hello" - -# End: Unmap SelectMode Mappings #}}} -# Folding Interaction {{{# -class FoldingEnabled_SnippetWithFold_ExpectNoFolding(_VimTest): - def _options_on(self): - self.send(":set foldlevel=0\n") - self.send(":set foldmethod=marker\n") - def _options_off(self): - self.send(":set foldlevel=0\n") - self.send(":set foldmethod=manual\n") - - snippets = ("test", r"""Hello {{{ -${1:Welt} }}}""") - keys = "test" + EX + "Ball" - wanted = """Hello {{{ -Ball }}}""" -class FoldOverwrite_Simple_ECR(_VimTest): - snippets = ("fold", -"""# ${1:Description} `!p snip.rv = vim.eval("&foldmarker").split(",")[0]` - -# End: $1 `!p snip.rv = vim.eval("&foldmarker").split(",")[1]`""") - keys = "fold" + EX + "hi" - wanted = "# hi {{{\n\n# End: hi }}}" -class Fold_DeleteMiddleLine_ECR(_VimTest): - snippets = ("fold", -"""# ${1:Description} `!p snip.rv = vim.eval("&foldmarker").split(",")[0]` - - -# End: $1 `!p snip.rv = vim.eval("&foldmarker").split(",")[1]`""") - keys = "fold" + EX + "hi" + ESC + "jdd" - wanted = "# hi {{{\n\n# End: hi }}}" - -class PerlSyntaxFold(_VimTest): - def _options_on(self): - self.send(":set foldlevel=0\n") - self.send(":syntax enable\n") - self.send(":set foldmethod=syntax\n") - self.send(":let g:perl_fold = 1\n") - self.send(":so $VIMRUNTIME/syntax/perl.vim\n") - def _options_off(self): - self.send(":set foldmethod=manual\n") - self.send(":syntax clear\n") - - snippets = ("test", r"""package ${1:`!v printf('c%02d', 3)`}; -${0} -1;""") - keys = "test" + EX + JF + "sub junk {}" - wanted = "package c03;\nsub junk {}\n1;" -# End: Folding Interaction #}}} -# Trailing whitespace {{{# -class RemoveTrailingWhitespace(_VimTest): - snippets = ("test", """Hello\t ${1:default}\n$2""", "", "s") - wanted = """Hello\nGoodbye""" - keys = "test" + EX + BS + JF + "Goodbye" -class LeaveTrailingWhitespace(_VimTest): - snippets = ("test", """Hello \t ${1:default}\n$2""") - wanted = """Hello \t \nGoodbye""" - keys = "test" + EX + BS + JF + "Goodbye" -# End: Trailing whitespace #}}} - -# Cursor Movement {{{# -class CursorMovement_Multiline_ECR(_VimTest): - snippets = ("test", r"$1 ${1:a tab}") - keys = "test" + EX + "this is something\nvery nice\nnot" + JF + "more text" - wanted = "this is something\nvery nice\nnot " \ - "this is something\nvery nice\nnotmore text" -class CursorMovement_BS_InEditMode(_VimTest): - def _options_on(self): - self.send(":set backspace=eol,indent,start\n") - - def _options_off(self): - self.send(":set backspace=\n") - snippets = ("\n\t$1\n\t$2\n\n$3") - keys = "2 different words with identical starts to create the -# popup-menu: -COMPLETION_OPTIONS = "completion1\ncompletion2\n" - -class Completion_ForwardsJumpWithoutCOMPL_ACCEPT(_VimTest): - # completions should not be truncated when JF is activated without having - # pressed COMPL_ACCEPT (Bug #598903) - snippets = ("test", "$1 $2") - keys = COMPLETION_OPTIONS + "test" + EX + "com" + COMPL_KW + JF + "foo" - wanted = COMPLETION_OPTIONS + "completion1 foo" - -class Completion_BackwardsJumpWithoutCOMPL_ACCEPT(_VimTest): - # completions should not be truncated when JB is activated without having - # pressed COMPL_ACCEPT (Bug #598903) - snippets = ("test", "$1 $2") - keys = COMPLETION_OPTIONS + "test" + EX + "foo" + JF + "com" + COMPL_KW + \ - JB + "foo" - wanted = COMPLETION_OPTIONS + "foo completion1" -# End: Tab Completion of Words #}}} -# Pressing BS in TabStop {{{# -# Test for Bug #774917 -class Backspace_TabStop_Zero(_VimTest): - snippets = ("test", "A${1:C} ${0:DDD}", "This is Case 1") - keys = "test" + EX + "A" + JF + BS + "BBB" - wanted = "AA BBB" - -class Backspace_TabStop_NotZero(_VimTest): - snippets = ("test", "A${1:C} ${2:DDD}", "This is Case 1") - keys = "test" + EX + "A" + JF + BS + "BBB" - wanted = "AA BBB" -# End: Pressing BS in TabStop #}}} -# Newline in default text {{{# -# Tests for bug 616315 # -class TrailingNewline_TabStop_NLInsideStuffBehind(_VimTest): - snippets = ("test", r""" -x${1: -}<-behind1 -$2<-behind2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj<-behind1 -k<-behind2""" - -class TrailingNewline_TabStop_JustNL(_VimTest): - snippets = ("test", r""" -x${1: -} -$2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k""" - -class TrailingNewline_TabStop_EndNL(_VimTest): - snippets = ("test", r""" -x${1:a -} -$2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k""" - -class TrailingNewline_TabStop_StartNL(_VimTest): - snippets = ("test", r""" -x${1: -a} -$2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k""" - -class TrailingNewline_TabStop_EndStartNL(_VimTest): - snippets = ("test", r""" -x${1: -a -} -$2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k""" - -class TrailingNewline_TabStop_NotEndStartNL(_VimTest): - snippets = ("test", r""" -x${1:a -a} -$2""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k""" - -class TrailingNewline_TabStop_ExtraNL_ECR(_VimTest): - snippets = ("test", r""" -x${1:a -a} -$2 -""") - keys = "test" + EX + "j" + JF + "k" - wanted = """ -xj -k -""" - -class _MultiLineDefault(_VimTest): - snippets = ("test", r""" -x${1:a -b -c -d -e -f} -$2""") - -class MultiLineDefault_Jump(_MultiLineDefault): - keys = "test" + EX + JF + "y" - wanted = """ -xa -b -c -d -e -f -y""" - -class MultiLineDefault_Type(_MultiLineDefault): - keys = "test" + EX + "z" + JF + "y" - wanted = """ -xz -y""" - -class MultiLineDefault_BS(_MultiLineDefault): - keys = "test" + EX + BS + JF + "y" - wanted = """ -x -y""" - - - -# End: Newline in default text #}}} -# Quotes in Snippets {{{# -# Test for Bug #774917 -def _snip_quote(qt): - return ( - ("te" + qt + "st", "Expand me" + qt + "!", "test: "+qt), - ("te", "Bad", ""), - ) - -class Snippet_With_SingleQuote(_VimTest): - snippets = _snip_quote("'") - keys = "te'st" + EX - wanted = "Expand me'!" - -class Snippet_With_SingleQuote_List(_VimTest): - snippets = _snip_quote("'") - keys = "te" + LS + "2\n" - wanted = "Expand me'!" - -class Snippet_With_DoubleQuote(_VimTest): - snippets = _snip_quote('"') - keys = 'te"st' + EX - wanted = "Expand me\"!" - -class Snippet_With_DoubleQuote_List(_VimTest): - snippets = _snip_quote('"') - keys = "te" + LS + "2\n" - wanted = "Expand me\"!" -# End: Quotes in Snippets #}}} -# Umlauts and Special Chars {{{# -class _UmlautsBase(_VimTest): - skip_if = lambda self: running_on_windows() # SendKeys can't send UTF characters - -class Snippet_With_Umlauts_List(_UmlautsBase): - snippets = _snip_quote('ü') - keys = 'te' + LS + "2\n" - wanted = "Expand meü!" - -class Snippet_With_Umlauts(_UmlautsBase): - snippets = _snip_quote('ü') - keys = 'teüst' + EX - wanted = "Expand meü!" - -class Snippet_With_Umlauts_TypeOn(_UmlautsBase): - snippets = ('ül', 'üüüüüßßßß') - keys = 'te ül' + EX + "more text" - wanted = "te üüüüüßßßßmore text" -class Snippet_With_Umlauts_OverwriteFirst(_UmlautsBase): - snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') - keys = 'te ül' + EX + "more text" + JF + JF + "end" - wanted = "te üü more text üü helloßß\nüüüüend" -class Snippet_With_Umlauts_OverwriteSecond(_UmlautsBase): - snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') - keys = 'te ül' + EX + JF + "more text" + JF + "end" - wanted = "te üü world üü more textßß\nüüüüend" -class Snippet_With_Umlauts_OverwriteNone(_UmlautsBase): - snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') - keys = 'te ül' + EX + JF + JF + "end" - wanted = "te üü world üü helloßß\nüüüüend" -class Snippet_With_Umlauts_Mirrors(_UmlautsBase): - snippets = ('ül', 'üü ${1:world} üü $1') - keys = 'te ül' + EX + "hello" - wanted = "te üü hello üü hello" -class Snippet_With_Umlauts_Python(_UmlautsBase): - snippets = ('ül', 'üü ${1:world} üü `!p snip.rv = len(t[1])*"a"`') - keys = 'te ül' + EX + "hüüll" - wanted = "te üü hüüll üü aaaaa" -# End: Umlauts and Special Chars #}}} -# Exclusive Selection {{{# -class _ES_Base(_VimTest): - def _options_on(self): - self.send(":set selection=exclusive\n") - def _options_off(self): - self.send(":set selection=inclusive\n") - -class ExclusiveSelection_SimpleTabstop_Test(_ES_Base): - snippets = ("test", "h${1:blah}w $1") - keys = "test" + EX + "ui" + JF - wanted = "huiw ui" - -class ExclusiveSelection_RealWorldCase_Test(_ES_Base): - snippets = ("for", -"""for ($${1:i} = ${2:0}; $$1 < ${3:count}; $$1${4:++}) { - ${5:// code} -}""") - keys = "for" + EX + "k" + JF - wanted = """for ($k = 0; $k < count; $k++) { - // code -}""" -# End: Exclusive Selection #}}} -# Normal mode editing {{{# -# Test for bug #927844 -class DeleteLastTwoLinesInSnippet(_VimTest): - snippets = ("test", "$1hello\nnice\nworld") - keys = "test" + EX + ESC + "j2dd" - wanted = "hello" -class DeleteCurrentTabStop1_JumpBack(_VimTest): - snippets = ("test", "${1:hi}\nend") - keys = "test" + EX + ESC + "ddi" + JB - wanted = "end" -class DeleteCurrentTabStop2_JumpBack(_VimTest): - snippets = ("test", "${1:hi}\n${2:world}\nend") - keys = "test" + EX + JF + ESC + "ddi" + JB + "hello" - wanted = "hello\nend" -class DeleteCurrentTabStop3_JumpAround(_VimTest): - snippets = ("test", "${1:hi}\n${2:world}\nend") - keys = "test" + EX + JF + ESC + "ddkji" + JB + "hello" + JF + "world" - wanted = "hello\nendworld" - -# End: Normal mode editing #}}} - -# 1251994 {{{# -# Test for bug #1251994 -class Bug1251994(_VimTest): - snippets = ("test", "${2:#2} ${1:#1};$0") - keys = " test" + EX + "hello" + JF + "world" + JF + "blub" - wanted = " world hello;blub" -# End: 1251994 #}}} - -# Test for Github Pull Request #134 - Retain unnamed register {{{# -class RetainsTheUnnamedRegister(_VimTest): - snippets = ("test", "${1:hello} ${2:world} ${0}") - keys = "yank" + ESC + "by4lea test" + EX + "HELLO" + JF + JF + ESC + "p" - wanted = "yank HELLO world yank" -class RetainsTheUnnamedRegister_ButOnlyOnce(_VimTest): - snippets = ("test", "${1:hello} ${2:world} ${0}") - keys = "blahfasel" + ESC + "v" + 4*ARR_L + "xotest" + EX + ESC + ARR_U + "v0xo" + ESC + "p" - wanted = "\nblah\nhello world " -# End: Github Pull Request # 134 #}}} - -class VerifyVimDict1(_VimTest): - """check: - correct type (4 means vim dictionary) - correct length of dictionary (in this case we have on element if the use same prefix, dictionary should have 1 element) - correct description (including the apostrophe) - if the prefix is mismatched no resulting dict should have 0 elements - """ - - snippets = ('testâ', 'abc123ά', '123\'êabc') - keys = ('test=(type(UltiSnips#SnippetsInCurrentScope()) . len(UltiSnips#SnippetsInCurrentScope()) . ' + - 'UltiSnips#SnippetsInCurrentScope()["testâ"]' + ')\n' + - '=len(UltiSnips#SnippetsInCurrentScope())\n') - - wanted = 'test41123\'êabc0' - -class VerifyVimDict2(_VimTest): - """check: - can use " in trigger - """ - - snippets = ('te"stâ', 'abc123ά', '123êabc') - akey = "'te{}stâ'".format('"') - keys = ('te"=(UltiSnips#SnippetsInCurrentScope()[{}]'.format(akey) + ')\n') - wanted = 'te"123êabc' - -class VerifyVimDict3(_VimTest): - """check: - can use ' in trigger - """ - - snippets = ("te'stâ", 'abc123ά', '123êabc') - akey = '"te{}stâ"'.format("'") - keys = ("te'=(UltiSnips#SnippetsInCurrentScope()[{}]".format(akey) + ')\n') - wanted = "te'123êabc" - -########################################################################### -# END OF TEST # -########################################################################### - - -if __name__ == '__main__': - import sys - import optparse - - def parse_args(): - p = optparse.OptionParser("%prog [OPTIONS] ") - - p.set_defaults(session="vim", interrupt=False, - verbose=False, interface="screen", retries=4) - - p.add_option("-v", "--verbose", dest="verbose", action="store_true", - help="print name of tests as they are executed") - p.add_option("--interface", type=str, - help="interface to vim to use on Mac and or Linux [screen|tmux].") - p.add_option("-s", "--session", dest="session", metavar="SESSION", - help="session parameters for the terminal multiplexer SESSION [%default]") - p.add_option("-i", "--interrupt", dest="interrupt", - action="store_true", - help="Stop after defining the snippet. This allows the user " \ - "to interactively test the snippet in vim. You must give " \ - "exactly one test case on the cmdline. The test will always fail." - ) - p.add_option("-r", "--retries", dest="retries", type=int, - help="How often should each test be retried before it is " - "considered failed. Works around flakyness in the terminal " - "multiplexer and race conditions in writing to the file system.") - - o, args = p.parse_args() - if o.interface not in ("screen", "tmux"): - p.error("--interface must be [screen|tmux].") - - return o, args - - options,selected_tests = parse_args() - - # The next line doesn't work in python 2.3 - test_loader = unittest.TestLoader() - all_test_suites = test_loader.loadTestsFromModule(__import__("test")) - - if platform.system() == "Windows": - vim = VimInterfaceWindows() - else: - if options.interface == "screen": - vim = VimInterfaceScreen(options.session) - elif options.interface == "tmux": - vim = VimInterfaceTmux(options.session) - - vim.focus() - - vim.send(ESC) - - # Ensure we are not running in VI-compatible mode. - vim.send(""":set nocompatible\n""") - - # Do not mess with the X clipboard - vim.send(""":set clipboard=""\n""") - - # Set encoding and fileencodings - vim.send(""":set encoding=utf-8\n""") - vim.send(""":set fileencoding=utf-8\n""") - - # Tell vim not to complain about quitting without writing - vim.send(""":set buftype=nofile\n""") - - # Ensure runtimepath includes only Vim's own runtime files - # and those of the UltiSnips directory under test ('.'). - vim.send(""":set runtimepath=$VIMRUNTIME,.\n""") - - # Set the options - vim.send(""":let g:UltiSnipsExpandTrigger=""\n""") - vim.send(""":let g:UltiSnipsJumpForwardTrigger="?"\n""") - vim.send(""":let g:UltiSnipsJumpBackwardTrigger="+"\n""") - vim.send(""":let g:UltiSnipsListSnippets="@"\n""") - if sys.version_info >= (3,0): - vim.send(""":let g:UltiSnipsUsePythonVersion="3"\n""") - else: - vim.send(""":let g:UltiSnipsUsePythonVersion="2"\n""") - - # Now, source our runtime - vim.send(":so plugin/UltiSnips.vim\n") - time.sleep(2) # Parsing and initializing UltiSnips takes a while. - - # Inform all test case which screen session to use - suite = unittest.TestSuite() - for s in all_test_suites: - for test in s: - test.vim = vim - test.interrupt = options.interrupt - test.retries = options.retries - if len(selected_tests): - id = test.id().split('.')[1] - if not any([ id.startswith(t) for t in selected_tests ]): - continue - suite.addTest(test) - - if options.verbose: - v = 2 - else: - v = 1 - res = unittest.TextTestRunner(verbosity=v).run(suite) - -# vim:fileencoding=utf-8:foldmarker={{{#,#}}}: diff --git a/vim/bundle/ultisnips/test/__init__.py b/vim/bundle/ultisnips/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vim/bundle/ultisnips/test/constant.py b/vim/bundle/ultisnips/test/constant.py new file mode 100644 index 0000000..0e795e0 --- /dev/null +++ b/vim/bundle/ultisnips/test/constant.py @@ -0,0 +1,24 @@ +import sys + +# Some constants for better reading +BS = '\x7f' +ESC = '\x1b' +ARR_L = '\x1bOD' +ARR_R = '\x1bOC' +ARR_U = '\x1bOA' +ARR_D = '\x1bOB' + +# multi-key sequences generating a single key press +SEQUENCES = [ARR_L, ARR_R, ARR_U, ARR_D] + +# Defined Constants +JF = '?' # Jump forwards +JB = '+' # Jump backwards +LS = '@' # List snippets +EX = '\t' # EXPAND +EA = '#' # Expand anonymous + +COMPL_KW = chr(24) + chr(14) +COMPL_ACCEPT = chr(25) + +PYTHON3 = sys.version_info >= (3, 0) diff --git a/vim/bundle/ultisnips/test/test_AnonymousExpansion.py b/vim/bundle/ultisnips/test/test_AnonymousExpansion.py new file mode 100644 index 0000000..f74d3ff --- /dev/null +++ b/vim/bundle/ultisnips/test/test_AnonymousExpansion.py @@ -0,0 +1,67 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Anonymous Expansion {{{# + + +class _AnonBase(_VimTest): + args = '' + + def _extra_vim_config(self, vim_config): + vim_config.append('inoremap %s =UltiSnips#Anon(%s)' + % (EA, self.args)) + + +class Anon_NoTrigger_Simple(_AnonBase): + args = '"simple expand"' + keys = 'abc' + EA + wanted = 'abcsimple expand' + + +class Anon_NoTrigger_AfterSpace(_AnonBase): + args = '"simple expand"' + keys = 'abc ' + EA + wanted = 'abc simple expand' + + +class Anon_NoTrigger_BeginningOfLine(_AnonBase): + args = r"':latex:\`$1\`$0'" + keys = EA + 'Hello' + JF + 'World' + wanted = ':latex:`Hello`World' + + +class Anon_NoTrigger_FirstCharOfLine(_AnonBase): + args = r"':latex:\`$1\`$0'" + keys = ' ' + EA + 'Hello' + JF + 'World' + wanted = ' :latex:`Hello`World' + + +class Anon_NoTrigger_Multi(_AnonBase): + args = '"simple $1 expand $1 $0"' + keys = 'abc' + EA + '123' + JF + '456' + wanted = 'abcsimple 123 expand 123 456' + + +class Anon_Trigger_Multi(_AnonBase): + args = '"simple $1 expand $1 $0", "abc"' + keys = '123 abc' + EA + '123' + JF + '456' + wanted = '123 simple 123 expand 123 456' + + +class Anon_Trigger_Simple(_AnonBase): + args = '"simple expand", "abc"' + keys = 'abc' + EA + wanted = 'simple expand' + + +class Anon_Trigger_Twice(_AnonBase): + args = '"simple expand", "abc"' + keys = 'abc' + EA + '\nabc' + EX + wanted = 'simple expand\nabc' + EX + + +class Anon_Trigger_Opts(_AnonBase): + args = '"simple expand", ".*abc", "desc", "r"' + keys = 'blah blah abc' + EA + wanted = 'simple expand' +# End: Anonymous Expansion #}}} diff --git a/vim/bundle/ultisnips/test/test_Autocommands.py b/vim/bundle/ultisnips/test/test_Autocommands.py new file mode 100644 index 0000000..bcb6a56 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Autocommands.py @@ -0,0 +1,31 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Autocommands {{{# + +class Autocommands(_VimTest): + snippets = ('test', '[ ${1:foo} ]') + args = '' + keys = 'test' + EX + 'test' + EX + 'bar' + JF + JF + ' done ' + ESC + \ + ':execute "normal aM" . g:mapper_call_count . "\"' + "\n" + \ + ':execute "normal aU" . g:unmapper_call_count . "\"' + "\n" + wanted = '[ [ bar ] ] done M1U1' + + def _extra_vim_config(self, vim_config): + vim_config.append('let g:mapper_call_count = 0') + vim_config.append('function! CustomMapper()') + vim_config.append(' let g:mapper_call_count += 1') + vim_config.append('endfunction') + + vim_config.append('let g:unmapper_call_count = 0') + vim_config.append('function! CustomUnmapper()') + vim_config.append(' let g:unmapper_call_count += 1') + vim_config.append('endfunction') + + vim_config.append('autocmd! User UltiSnipsEnterFirstSnippet') + vim_config.append('autocmd User UltiSnipsEnterFirstSnippet call CustomMapper()') + vim_config.append('autocmd! User UltiSnipsExitLastSnippet') + vim_config.append('autocmd User UltiSnipsExitLastSnippet call CustomUnmapper()') + +# end: Autocommands #}}} diff --git a/vim/bundle/ultisnips/test/test_Autotrigger.py b/vim/bundle/ultisnips/test/test_Autotrigger.py new file mode 100644 index 0000000..8fd23b8 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Autotrigger.py @@ -0,0 +1,74 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +def check_required_vim_version(test): + if test.vim_flavor == 'neovim': + return None + if not test.vim.has_patch(214): + return 'Vim newer than 7.4.214 is required' + else: + return None + + +class Autotrigger_CanMatchSimpleTrigger(_VimTest): + skip_if = check_required_vim_version + files = { 'us/all.snippets': r""" + snippet a "desc" A + autotriggered + endsnippet + """} + keys = 'a' + wanted = 'autotriggered' + + +class Autotrigger_CanMatchContext(_VimTest): + skip_if = check_required_vim_version + files = { 'us/all.snippets': r""" + snippet a "desc" "snip.line == 2" Ae + autotriggered + endsnippet + """} + keys = 'a\na' + wanted = 'autotriggered\na' + + +class Autotrigger_CanExpandOnTriggerWithLengthMoreThanOne(_VimTest): + skip_if = check_required_vim_version + files = { 'us/all.snippets': r""" + snippet abc "desc" A + autotriggered + endsnippet + """} + keys = 'abc' + wanted = 'autotriggered' + + +class Autotrigger_WillProduceNoExceptionWithVimLowerThan214(_VimTest): + skip_if = lambda self: 'Vim older than 7.4.214 is required' \ + if self.vim.has_patch(214) else None + + files = { 'us/all.snippets': r""" + snippet abc "desc" A + autotriggered + endsnippet + """} + keys = 'abc' + wanted = 'abc' + + +class Autotrigger_CanMatchPreviouslySelectedPlaceholder(_VimTest): + if not test.vim.has_patch(214): + return 'Vim newer than 7.4.214 is required' + else: + return None + + files = { 'us/all.snippets': r""" + snippet if "desc" + if ${1:var}: pass + endsnippet + snippet = "desc" "snip.last_placeholder" Ae + `!p snip.rv = snip.context.current_text` == nil + endsnippet + """} + keys = 'if' + EX + '=' + ESC + 'o=' + wanted = 'if var == nil: pass\n=' diff --git a/vim/bundle/ultisnips/test/test_Chars.py b/vim/bundle/ultisnips/test/test_Chars.py new file mode 100644 index 0000000..93d81ba --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Chars.py @@ -0,0 +1,254 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * +from test.util import running_on_windows + +# Quotes in Snippets {{{# +# Test for Bug #774917 + + +def _snip_quote(qt): + return ( + ('te' + qt + 'st', 'Expand me' + qt + '!', 'test: ' + qt), + ('te', 'Bad', ''), + ) + + +class Snippet_With_SingleQuote(_VimTest): + snippets = _snip_quote("'") + keys = "te'st" + EX + wanted = "Expand me'!" + + +class Snippet_With_SingleQuote_List(_VimTest): + snippets = _snip_quote("'") + keys = 'te' + LS + '2\n' + wanted = "Expand me'!" + + +class Snippet_With_DoubleQuote(_VimTest): + snippets = _snip_quote('"') + keys = 'te"st' + EX + wanted = "Expand me\"!" + + +class Snippet_With_DoubleQuote_List(_VimTest): + snippets = _snip_quote('"') + keys = 'te' + LS + '2\n' + wanted = "Expand me\"!" + +# End: Quotes in Snippets #}}} + +# Trailing whitespace {{{# + + +class RemoveTrailingWhitespace(_VimTest): + snippets = ('test', """Hello\t ${1:default}\n$2""", '', 's') + wanted = """Hello\nGoodbye""" + keys = 'test' + EX + BS + JF + 'Goodbye' + +class TrimSpacesAtEndOfLines(_VimTest): + snippets = ('test', """next line\n\nshould be empty""", '', 'm') + wanted = """\tnext line\n\n\tshould be empty""" + keys = '\ttest' + EX + +class DoNotTrimSpacesAtEndOfLinesByDefault(_VimTest): + snippets = ('test', """next line\n\nshould be empty""", '', '') + wanted = """\tnext line\n\t\n\tshould be empty""" + keys = '\ttest' + EX + + +class LeaveTrailingWhitespace(_VimTest): + snippets = ('test', """Hello \t ${1:default}\n$2""") + wanted = """Hello \t \nGoodbye""" + keys = 'test' + EX + BS + JF + 'Goodbye' +# End: Trailing whitespace #}}} + +# Newline in default text {{{# +# Tests for bug 616315 # + + +class TrailingNewline_TabStop_NLInsideStuffBehind(_VimTest): + snippets = ('test', r""" +x${1: +}<-behind1 +$2<-behind2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj<-behind1 +k<-behind2""" + + +class TrailingNewline_TabStop_JustNL(_VimTest): + snippets = ('test', r""" +x${1: +} +$2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k""" + + +class TrailingNewline_TabStop_EndNL(_VimTest): + snippets = ('test', r""" +x${1:a +} +$2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k""" + + +class TrailingNewline_TabStop_StartNL(_VimTest): + snippets = ('test', r""" +x${1: +a} +$2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k""" + + +class TrailingNewline_TabStop_EndStartNL(_VimTest): + snippets = ('test', r""" +x${1: +a +} +$2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k""" + + +class TrailingNewline_TabStop_NotEndStartNL(_VimTest): + snippets = ('test', r""" +x${1:a +a} +$2""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k""" + + +class TrailingNewline_TabStop_ExtraNL_ECR(_VimTest): + snippets = ('test', r""" +x${1:a +a} +$2 +""") + keys = 'test' + EX + 'j' + JF + 'k' + wanted = """ +xj +k +""" + + +class _MultiLineDefault(_VimTest): + snippets = ('test', r""" +x${1:a +b +c +d +e +f} +$2""") + + +class MultiLineDefault_Jump(_MultiLineDefault): + keys = 'test' + EX + JF + 'y' + wanted = """ +xa +b +c +d +e +f +y""" + + +class MultiLineDefault_Type(_MultiLineDefault): + keys = 'test' + EX + 'z' + JF + 'y' + wanted = """ +xz +y""" + + +class MultiLineDefault_BS(_MultiLineDefault): + keys = 'test' + EX + BS + JF + 'y' + wanted = """ +x +y""" + +# End: Newline in default text #}}} + +# Umlauts and Special Chars {{{# + + +class _UmlautsBase(_VimTest): + # SendKeys can't send UTF characters + skip_if = lambda self: running_on_windows() + + +class Snippet_With_Umlauts_List(_UmlautsBase): + snippets = _snip_quote('ü') + keys = 'te' + LS + '2\n' + wanted = 'Expand meü!' + + +class Snippet_With_Umlauts(_UmlautsBase): + snippets = _snip_quote('ü') + keys = 'teüst' + EX + wanted = 'Expand meü!' + + +class Snippet_With_Umlauts_TypeOn(_UmlautsBase): + snippets = ('ül', 'üüüüüßßßß') + keys = 'te ül' + EX + 'more text' + wanted = 'te üüüüüßßßßmore text' + + +class Snippet_With_Umlauts_OverwriteFirst(_UmlautsBase): + snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') + keys = 'te ül' + EX + 'more text' + JF + JF + 'end' + wanted = 'te üü more text üü helloßß\nüüüüend' + + +class Snippet_With_Umlauts_OverwriteSecond(_UmlautsBase): + snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') + keys = 'te ül' + EX + JF + 'more text' + JF + 'end' + wanted = 'te üü world üü more textßß\nüüüüend' + + +class Snippet_With_Umlauts_OverwriteNone(_UmlautsBase): + snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') + keys = 'te ül' + EX + JF + JF + 'end' + wanted = 'te üü world üü helloßß\nüüüüend' + + +class Snippet_With_Umlauts_Mirrors(_UmlautsBase): + snippets = ('ül', 'üü ${1:world} üü $1') + keys = 'te ül' + EX + 'hello' + wanted = 'te üü hello üü hello' + + +class Snippet_With_Umlauts_Python(_UmlautsBase): + snippets = ('ül', 'üü ${1:world} üü `!p snip.rv = len(t[1])*"a"`') + keys = 'te ül' + EX + 'hüüll' + wanted = 'te üü hüüll üü aaaaa' + +class UmlautsBeforeTriggerAndCharsAfter(_UmlautsBase): + snippets = ('trig', 'success') + keys = 'ööuu trig b' + 2 * ARR_L + EX + wanted = 'ööuu success b' + +class NoUmlautsBeforeTriggerAndCharsAfter(_UmlautsBase): + snippets = ('trig', 'success') + keys = 'oouu trig b' + 2 * ARR_L + EX + wanted = 'oouu success b' + +# End: Umlauts and Special Chars #}}} diff --git a/vim/bundle/ultisnips/test/test_Completion.py b/vim/bundle/ultisnips/test/test_Completion.py new file mode 100644 index 0000000..0d95c61 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Completion.py @@ -0,0 +1,34 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Tab Completion of Words {{{# + + +class Completion_SimpleExample_ECR(_VimTest): + snippets = ('test', '$1 ${1:blah}') + keys = 'superkallifragilistik\ntest' + EX + 'sup' + COMPL_KW + \ + COMPL_ACCEPT + ' some more' + wanted = 'superkallifragilistik\nsuperkallifragilistik some more ' \ + 'superkallifragilistik some more' + +# We need >2 different words with identical starts to create the +# popup-menu: +COMPLETION_OPTIONS = 'completion1\ncompletion2\n' + + +class Completion_ForwardsJumpWithoutCOMPL_ACCEPT(_VimTest): + # completions should not be truncated when JF is activated without having + # pressed COMPL_ACCEPT (Bug #598903) + snippets = ('test', '$1 $2') + keys = COMPLETION_OPTIONS + 'test' + EX + 'com' + COMPL_KW + JF + 'foo' + wanted = COMPLETION_OPTIONS + 'completion1 foo' + + +class Completion_BackwardsJumpWithoutCOMPL_ACCEPT(_VimTest): + # completions should not be truncated when JB is activated without having + # pressed COMPL_ACCEPT (Bug #598903) + snippets = ('test', '$1 $2') + keys = COMPLETION_OPTIONS + 'test' + EX + 'foo' + JF + 'com' + COMPL_KW + \ + JB + 'foo' + wanted = COMPLETION_OPTIONS + 'foo completion1' +# End: Tab Completion of Words #}}} diff --git a/vim/bundle/ultisnips/test/test_ContextSnippets.py b/vim/bundle/ultisnips/test/test_ContextSnippets.py new file mode 100644 index 0000000..14e048a --- /dev/null +++ b/vim/bundle/ultisnips/test/test_ContextSnippets.py @@ -0,0 +1,166 @@ +from test.constant import * +from test.vim_test_case import VimTestCase as _VimTest + + +class ContextSnippets_SimpleSnippet(_VimTest): + files = { 'us/all.snippets': r""" + snippet a "desc" "True" e + abc + endsnippet + """} + keys = 'a' + EX + wanted = 'abc' + + +class ContextSnippets_ExpandOnTrue(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def check_context(): + return True + endglobal + + snippet a "desc" "check_context()" e + abc + endsnippet + """} + keys = 'a' + EX + wanted = 'abc' + + +class ContextSnippets_DoNotExpandOnFalse(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def check_context(): + return False + endglobal + + snippet a "desc" "check_context()" e + abc + endsnippet + """} + keys = 'a' + EX + wanted = keys + + +class ContextSnippets_UseContext(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def wrap(ins): + return "< " + ins + " >" + endglobal + + snippet a "desc" "wrap(snip.buffer[snip.line])" e + { `!p snip.rv = context` } + endsnippet + """} + keys = 'a' + EX + wanted = '{ < a > }' + + +class ContextSnippets_SnippetPriority(_VimTest): + files = { 'us/all.snippets': r""" + snippet i "desc" "re.search('err :=', snip.buffer[snip.line-1])" e + if err != nil { + ${1:// pass} + } + endsnippet + + snippet i + if ${1:true} { + ${2:// pass} + } + endsnippet + """} + + keys = r""" + err := some_call() + i""" + EX + JF + """ + i""" + EX + wanted = r""" + err := some_call() + if err != nil { + // pass + } + if true { + // pass + }""" + + +class ContextSnippets_PriorityKeyword(_VimTest): + files = { 'us/all.snippets': r""" + snippet i "desc" "True" e + a + endsnippet + + priority 100 + snippet i + b + endsnippet + """} + + keys = 'i' + EX + wanted = 'b' + + +class ContextSnippets_ReportError(_VimTest): + files = { 'us/all.snippets': r""" + snippet e "desc" "Tru" e + error + endsnippet + """} + + keys = 'e' + EX + wanted = 'e' + EX + expected_error = r"NameError: name 'Tru' is not defined" + + +class ContextSnippets_ReportErrorOnIndexOutOfRange(_VimTest): + # Working around: https://github.com/neovim/python-client/issues/128. + skip_if = lambda self: 'Bug in Neovim.' \ + if self.vim_flavor == 'neovim' else None + files = { 'us/all.snippets': r""" + snippet e "desc" "snip.buffer[123]" e + error + endsnippet + """} + + keys = 'e' + EX + wanted = 'e' + EX + expected_error = r"IndexError: line number out of range" + + +class ContextSnippets_CursorIsZeroBased(_VimTest): + files = { 'us/all.snippets': r""" + snippet e "desc" "snip.cursor" e + `!p snip.rv = str(snip.context)` + endsnippet + """} + + keys = "e" + EX + wanted = "(2, 1)" + +class ContextSnippets_ContextIsClearedBeforeExpand(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.context = 1 if snip.context is None else 2" + snippet e "desc" w + `!p snip.rv = str(snip.context)` + endsnippet + """} + + keys = "e" + EX + " " + "e" + EX + wanted = "1 1" + +class ContextSnippets_ContextHasAccessToVisual(_VimTest): + files = { 'us/all.snippets': r""" + snippet test "desc" "snip.visual_text == '123'" we + Yes + endsnippet + + snippet test "desc" w + No + endsnippet + """} + + keys = "123" + ESC + "vhh" + EX + "test" + EX + " zzz" + ESC + \ + "vhh" + EX + "test" + EX + wanted = "Yes No" diff --git a/vim/bundle/ultisnips/test/test_Editing.py b/vim/bundle/ultisnips/test/test_Editing.py new file mode 100644 index 0000000..e200f0b --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Editing.py @@ -0,0 +1,152 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + + +def check_required_vim_version(test): + if test.vim_flavor == 'neovim': + return None + if not test.vim.has_patch(1): + return 'Vim newer than 7.4.1 is required' + else: + return None + + +# Undo of Snippet insertion {{{# + + +class Undo_RemoveMultilineSnippet(_VimTest): + snippets = ('test', 'Hello\naaa ${1} bbb\nWorld') + keys = 'test' + EX + ESC + 'u' + wanted = 'test' + + +class Undo_RemoveEditInTabstop(_VimTest): + snippets = ('test', '$1 Hello\naaa ${1} bbb\nWorld') + keys = 'hello test' + EX + 'upsi' + ESC + 'hh' + 'iabcdef' + ESC + 'u' + wanted = 'hello upsi Hello\naaa upsi bbb\nWorld' + + +class Undo_RemoveWholeSnippet(_VimTest): + snippets = ('test', 'Hello\n${1:Hello}World') + keys = 'first line\n\n\n\n\n\nthird line' + \ + ESC + '3k0itest' + EX + ESC + 'u6j' + wanted = 'first line\n\n\ntest\n\n\nthird line' + + +class Undo_RemoveOneSnippetByTime(_VimTest): + snippets = ('i', 'if:\n\t$1') + keys = 'i' + EX + 'i' + EX + ESC + 'u' + wanted = 'if:\n\ti' + + +class Undo_RemoveOneSnippetByTime2(_VimTest): + snippets = ('i', 'if:\n\t$1') + keys = 'i' + EX + 'i' + EX + ESC + 'uu' + wanted = 'if:\n\t' + + +class Undo_ChangesInPlaceholder(_VimTest): + snippets = ('i', 'if $1:\n\t$2') + keys = 'i' + EX + 'asd' + JF + ESC + 'u' + wanted = 'if :\n\t' + + +class Undo_CompletelyUndoSnippet(_VimTest): + snippets = ('i', 'if $1:\n\t$2') + # undo 'feh' + # undo 'asd' + # undo snippet expansion + # undo entering of 'i' + keys = 'i' + EX + 'asd' + JF + 'feh' + ESC + 'uuuu' + wanted = '' + + +class JumpForward_DefSnippet(_VimTest): + snippets = ( + 'test', + "${1}\n`!p snip.rv = '\\n'.join(t[1].split())`\n\n${0:pass}") + keys = 'test' + EX+ 'a b c' + JF + 'shallnot' + wanted = 'a b c\na\nb\nc\n\nshallnot' + + +class DeleteSnippetInsertion0(_VimTest): + snippets = ('test', '${1:hello} $1') + keys = 'test' + EX + ESC + 'Vkx' + 'i\nworld\n' + wanted = 'world' + + +class DeleteSnippetInsertion1(_VimTest): + snippets = ('test', r"$1${1/(.*)/(?0::.)/}") + keys = 'test' + EX + ESC + 'u' + wanted = 'test' + +class DoNotCrashOnUndoAndJumpInNestedSnippet(_VimTest): + snippets = ('test', r"if $1: $2") + keys = 'test' + EX + 'a' + JF + 'test' + EX + ESC + 'u' + JF + wanted = 'if a: test' +# End: Undo of Snippet insertion #}}} + +# Normal mode editing {{{# +# Test for bug #927844 + + +class DeleteLastTwoLinesInSnippet(_VimTest): + snippets = ('test', '$1hello\nnice\nworld') + keys = 'test' + EX + ESC + 'j2dd' + wanted = 'hello' + + +class DeleteCurrentTabStop1_JumpBack(_VimTest): + snippets = ('test', '${1:hi}\nend') + keys = 'test' + EX + ESC + 'ddi' + JB + wanted = 'end' + + +class DeleteCurrentTabStop2_JumpBack(_VimTest): + snippets = ('test', '${1:hi}\n${2:world}\nend') + keys = 'test' + EX + JF + ESC + 'ddi' + JB + 'hello' + wanted = 'hello\nend' + + +class DeleteCurrentTabStop3_JumpAround(_VimTest): + snippets = ('test', '${1:hi}\n${2:world}\nend') + keys = 'test' + EX + JF + ESC + 'ddkji' + JB + 'hello' + JF + 'world' + wanted = 'hello\nendworld' + +# End: Normal mode editing #}}} + +# Pressing BS in TabStop {{{# +# Test for Bug #774917 + + +class Backspace_TabStop_Zero(_VimTest): + snippets = ('test', 'A${1:C} ${0:DDD}', 'This is Case 1') + keys = 'test' + EX + 'A' + JF + BS + 'BBB' + wanted = 'AA BBB' + + +class Backspace_TabStop_NotZero(_VimTest): + snippets = ('test', 'A${1:C} ${2:DDD}', 'This is Case 1') + keys = 'test' + EX + 'A' + JF + BS + 'BBB' + wanted = 'AA BBB' +# End: Pressing BS in TabStop #}}} + +class UpdateModifiedSnippetWithoutCursorMove(_VimTest): + skip_if = check_required_vim_version + snippets = ('test', '${1:one}(${2:xxx})${3:three}') + keys = 'test' + EX + 'aaaaa' + JF + BS + JF + '3333' + wanted = 'aaaaa()3333' + +class UpdateModifiedSnippetWithoutCursorMove2(_VimTest): + skip_if = check_required_vim_version + snippets = ('test', '''\ +private function ${1:functionName}(${2:arguments}):${3:Void} +{ + ${VISUAL}$0 +}''') + keys = 'test' + EX + 'a' + JF + BS + JF + 'Int' + JF + 'body' + wanted = '''\ +private function a():Int +{ + body +}''' diff --git a/vim/bundle/ultisnips/test/test_Expand.py b/vim/bundle/ultisnips/test/test_Expand.py new file mode 100644 index 0000000..d231838 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Expand.py @@ -0,0 +1,73 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Simple Expands {{{# + + +class _SimpleExpands(_VimTest): + snippets = ('hallo', 'Hallo Welt!') + + +class SimpleExpand_ExpectCorrectResult(_SimpleExpands): + keys = 'hallo' + EX + wanted = 'Hallo Welt!' + + +class SimpleExpandTwice_ExpectCorrectResult(_SimpleExpands): + keys = 'hallo' + EX + '\nhallo' + EX + wanted = 'Hallo Welt!\nHallo Welt!' + + +class SimpleExpandNewLineAndBackspae_ExpectCorrectResult(_SimpleExpands): + keys = 'hallo' + EX + '\nHallo Welt!\n\n\b\b\b\b\b' + wanted = 'Hallo Welt!\nHallo We' + + def _extra_vim_config(self, vim_config): + vim_config.append('set backspace=eol,start') + + +class SimpleExpandTypeAfterExpand_ExpectCorrectResult(_SimpleExpands): + keys = 'hallo' + EX + 'and again' + wanted = 'Hallo Welt!and again' + + +class SimpleExpandTypeAndDelete_ExpectCorrectResult(_SimpleExpands): + keys = 'na du hallo' + EX + 'and again\b\b\b\b\bblub' + wanted = 'na du Hallo Welt!and blub' + + +class DoNotExpandAfterSpace_ExpectCorrectResult(_SimpleExpands): + keys = 'hallo ' + EX + wanted = 'hallo ' + EX + + +class ExitSnippetModeAfterTabstopZero(_VimTest): + snippets = ('test', 'SimpleText') + keys = 'test' + EX + EX + wanted = 'SimpleText' + EX + + +class ExpandInTheMiddleOfLine_ExpectCorrectResult(_SimpleExpands): + keys = 'Wie hallo gehts' + ESC + 'bhi' + EX + wanted = 'Wie Hallo Welt! gehts' + + +class MultilineExpand_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'Hallo Welt!\nUnd Wie gehts') + keys = 'Wie hallo gehts' + ESC + 'bhi' + EX + wanted = 'Wie Hallo Welt!\nUnd Wie gehts gehts' + + +class MultilineExpandTestTyping_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'Hallo Welt!\nUnd Wie gehts') + wanted = 'Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts' + keys = 'Wie hallo gehts' + ESC + 'bhi' + EX + 'Huiui!' + + +class SimpleExpandEndingWithNewline_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'Hallo Welt\n') + keys = 'hallo' + EX + '\nAnd more' + wanted = 'Hallo Welt\n\nAnd more' + + +# End: Simple Expands #}}} diff --git a/vim/bundle/ultisnips/test/test_Fixes.py b/vim/bundle/ultisnips/test/test_Fixes.py new file mode 100644 index 0000000..5ceef5d --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Fixes.py @@ -0,0 +1,84 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Test for bug 1251994 {{{# + + +class Bug1251994(_VimTest): + snippets = ('test', '${2:#2} ${1:#1};$0') + keys = ' test' + EX + 'hello' + JF + 'world' + JF + 'blub' + wanted = ' world hello;blub' +# End: 1251994 #}}} + +# Test for https://github.com/SirVer/ultisnips/issues/157 (virtualedit) {{{# + + +class VirtualEdit(_VimTest): + snippets = ('pd', 'padding: ${1:0}px') + keys = '\t\t\tpd' + EX + '2' + wanted = '\t\t\tpadding: 2px' + + def _extra_vim_config(self, vim_config): + vim_config.append('set virtualedit=all') + vim_config.append('set noexpandtab') +# End: 1251994 #}}} + +# Test for Github Pull Request #134 - Retain unnamed register {{{# + + +class RetainsTheUnnamedRegister(_VimTest): + snippets = ('test', '${1:hello} ${2:world} ${0}') + keys = 'yank' + ESC + 'by4lea test' + EX + 'HELLO' + JF + JF + ESC + 'p' + wanted = 'yank HELLO world yank' + + +class RetainsTheUnnamedRegister_ButOnlyOnce(_VimTest): + snippets = ('test', '${1:hello} ${2:world} ${0}') + keys = 'blahfasel' + ESC + 'v' + 4 * ARR_L + \ + 'xotest' + EX + ESC + ARR_U + 'v0xo' + ESC + 'p' + wanted = '\nblah\nhello world ' +# End: Github Pull Request # 134 #}}} + +# Test to ensure that shiftwidth follows tabstop when it's set to zero post +# version 7.3.693. Prior to that version a shiftwidth of zero effectively +# removes tabs. + + +class ShiftWidthZero(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config += [ + "if exists('*shiftwidth')", + ' set shiftwidth=0', + 'endif', + ] + snippets = ('test', '\t${1}${0}') + keys = 'test' + EX + 'foo' + wanted = '\tfoo' + +# Test for https://github.com/SirVer/ultisnips/issues/171 {{{# +# Make sure that we don't crash when trying to save and restore the clipboard +# when it contains data that we can't coerce into Unicode. + + +class NonUnicodeDataInUnnamedRegister(_VimTest): + snippets = ('test', 'hello') + keys = 'test' + EX + ESC + \ + '\n'.join([':redir @a', + ':messages', + ':redir END', + (":if match(@a, 'Error') != -1 | " + + "call setline('.', 'error detected') | " + + '3put a | ' + + 'endif'), + '']) + wanted = 'hello' + + def _before_test(self): + # The string below was the one a user had on their clipboard when + # encountering the UnicodeDecodeError and could not be coerced into + # unicode. + self.vim.send_to_vim( + ':let @" = "\\x80kdI{\\x80@7 1},' + + '\\x80kh\\x80kh\\x80kd\\x80kdq\\x80kb\\x1b"\n') +# End: #171 #}}} diff --git a/vim/bundle/ultisnips/test/test_Folding.py b/vim/bundle/ultisnips/test/test_Folding.py new file mode 100644 index 0000000..3a31f77 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Folding.py @@ -0,0 +1,51 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Folding Interaction {{{# + + +class FoldingEnabled_SnippetWithFold_ExpectNoFolding(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set foldlevel=0') + vim_config.append('set foldmethod=marker') + snippets = ('test', r"""Hello {{{ +${1:Welt} }}}""") + keys = 'test' + EX + 'Ball' + wanted = """Hello {{{ +Ball }}}""" + + +class FoldOverwrite_Simple_ECR(_VimTest): + snippets = ('fold', + """# ${1:Description} `!p snip.rv = vim.eval("&foldmarker").split(",")[0]` + +# End: $1 `!p snip.rv = vim.eval("&foldmarker").split(",")[1]`""") + keys = 'fold' + EX + 'hi' + wanted = '# hi {{{\n\n# End: hi }}}' + + +class Fold_DeleteMiddleLine_ECR(_VimTest): + snippets = ('fold', + """# ${1:Description} `!p snip.rv = vim.eval("&foldmarker").split(",")[0]` + + +# End: $1 `!p snip.rv = vim.eval("&foldmarker").split(",")[1]`""") + keys = 'fold' + EX + 'hi' + ESC + 'jdd' + wanted = '# hi {{{\n\n# End: hi }}}' + + +class PerlSyntaxFold(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set foldlevel=0') + vim_config.append('syntax enable') + vim_config.append('set foldmethod=syntax') + vim_config.append('let g:perl_fold = 1') + vim_config.append('so $VIMRUNTIME/syntax/perl.vim') + snippets = ('test', r"""package ${1:`!v printf('c%02d', 3)`}; +${0} +1;""") + keys = 'test' + EX + JF + 'sub junk {}' + wanted = 'package c03;\nsub junk {}\n1;' +# End: Folding Interaction #}}} diff --git a/vim/bundle/ultisnips/test/test_Format.py b/vim/bundle/ultisnips/test/test_Format.py new file mode 100644 index 0000000..905e77e --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Format.py @@ -0,0 +1,157 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * +from test.util import running_on_windows + +# ExpandTab {{{# + + +class _ExpandTabs(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set expandtab') + + +class RecTabStopsWithExpandtab_SimpleExample_ECR(_ExpandTabs): + snippets = ('m', '\tBlaahblah \t\t ') + keys = 'm' + EX + wanted = ' Blaahblah \t\t ' + + +class RecTabStopsWithExpandtab_SpecialIndentProblem_ECR(_ExpandTabs): + # Windows indents the Something line after pressing return, though it + # shouldn't because it contains a manual indent. All other vim versions do + # not do this. Windows vim does not interpret the changes made by :py as + # changes made 'manually', while the other vim version seem to do so. Since + # the fault is not with UltiSnips, we simply skip this test on windows + # completely. + skip_if = lambda self: running_on_windows() + snippets = ( + ('m1', 'Something'), + ('m', '\t$0'), + ) + keys = 'm' + EX + 'm1' + EX + '\nHallo' + wanted = ' Something\n Hallo' + + def _extra_vim_config(self, vim_config): + _ExpandTabs._extra_vim_config(self, vim_config) + vim_config.append('set indentkeys=o,O,*,<>>,{,}') + vim_config.append('set indentexpr=8') +# End: ExpandTab #}}} + +# Proper Indenting {{{# + + +class ProperIndenting_SimpleCase_ECR(_VimTest): + snippets = ('test', 'for\n blah') + keys = ' test' + EX + 'Hui' + wanted = ' for\n blahHui' + + +class ProperIndenting_SingleLineNoReindenting_ECR(_VimTest): + snippets = ('test', 'hui') + keys = ' test' + EX + 'blah' + wanted = ' huiblah' + + +class ProperIndenting_AutoIndentAndNewline_ECR(_VimTest): + snippets = ('test', 'hui') + keys = ' test' + EX + '\n' + 'blah' + wanted = ' hui\n blah' + + def _extra_vim_config(self, vim_config): + vim_config.append('set autoindent') +# Test for bug 1073816 + + +class ProperIndenting_FirstLineInFile_ECR(_VimTest): + text_before = '' + text_after = '' + files = { 'us/all.snippets': r""" +global !p +def complete(t, opts): + if t: + opts = [ m[len(t):] for m in opts if m.startswith(t) ] + if len(opts) == 1: + return opts[0] + elif len(opts) > 1: + return "(" + "|".join(opts) + ")" + else: + return "" +endglobal + +snippet '^#?inc' "#include <>" !r +#include <$1`!p snip.rv = complete(t[1], ['cassert', 'cstdio', 'cstdlib', 'cstring', 'fstream', 'iostream', 'sstream'])`> +endsnippet + """} + keys = 'inc' + EX + 'foo' + wanted = '#include ' + + +class ProperIndenting_FirstLineInFileComplete_ECR( + ProperIndenting_FirstLineInFile_ECR): + keys = 'inc' + EX + 'cstdl' + wanted = '#include ' +# End: Proper Indenting #}}} + +# Format options tests {{{# + + +class _FormatoptionsBase(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set tw=20') + vim_config.append('set fo=lrqntc') + + +class FOSimple_Break_ExpectCorrectResult(_FormatoptionsBase): + snippets = ('test', '${1:longer expand}\n$1\n$0', '', 'f') + keys = 'test' + EX + \ + 'This is a longer text that should wrap as formatoptions are enabled' + \ + JF + 'end' + wanted = 'This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n' + \ + 'This is a longer\ntext that should\nwrap as\nformatoptions are\nenabled\n' + \ + 'end' + + +class FOTextBeforeAndAfter_ExpectCorrectResult(_FormatoptionsBase): + snippets = ('test', 'Before${1:longer expand}After\nstart$1end') + keys = 'test' + EX + 'This is a longer text that should wrap' + wanted = \ + """BeforeThis is a +longer text that +should wrapAfter +startThis is a +longer text that +should wrapend""" + + +# Tests for https://bugs.launchpad.net/bugs/719998 +class FOTextAfter_ExpectCorrectResult(_FormatoptionsBase): + snippets = ('test', '${1:longer expand}after\nstart$1end') + keys = ('test' + EX + 'This is a longer snippet that should wrap properly ' + 'and the mirror below should work as well') + wanted = \ + """This is a longer +snippet that should +wrap properly and +the mirror below +should work as wellafter +startThis is a longer +snippet that should +wrap properly and +the mirror below +should work as wellend""" + + +class FOWrapOnLongWord_ExpectCorrectResult(_FormatoptionsBase): + snippets = ('test', '${1:longer expand}after\nstart$1end') + keys = ('test' + EX + 'This is a longersnippet that should wrap properly') + wanted = \ + """This is a +longersnippet that +should wrap properlyafter +startThis is a +longersnippet that +should wrap properlyend""" +# End: Format options tests #}}} diff --git a/vim/bundle/ultisnips/test/test_Interpolation.py b/vim/bundle/ultisnips/test/test_Interpolation.py new file mode 100644 index 0000000..f51935b --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Interpolation.py @@ -0,0 +1,491 @@ +# encoding: utf-8 +import os + +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import EX, JF, ESC +from test.util import running_on_windows + +# ShellCode Interpolation {{{# + + +class TabStop_Shell_SimpleExample(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', 'hi `echo hallo` you!') + keys = 'test' + EX + 'and more' + wanted = 'hi hallo you!and more' + + +class TabStop_Shell_WithUmlauts(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', 'hi `echo höüäh` you!') + keys = 'test' + EX + 'and more' + wanted = 'hi höüäh you!and more' + + +class TabStop_Shell_TextInNextLine(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', 'hi `echo hallo`\nWeiter') + keys = 'test' + EX + 'and more' + wanted = 'hi hallo\nWeiterand more' + + +class TabStop_Shell_InDefValue_Leave(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', 'Hallo ${1:now `echo fromecho`} end') + keys = 'test' + EX + JF + 'and more' + wanted = 'Hallo now fromecho endand more' + + +class TabStop_Shell_InDefValue_Overwrite(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', 'Hallo ${1:now `echo fromecho`} end') + keys = 'test' + EX + 'overwrite' + JF + 'and more' + wanted = 'Hallo overwrite endand more' + + +class TabStop_Shell_TestEscapedChars_Overwrite(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', r"""`echo \`echo "\\$hi"\``""") + keys = 'test' + EX + wanted = '$hi' + + +class TabStop_Shell_TestEscapedCharsAndShellVars_Overwrite(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', r"""`hi="blah"; echo \`echo "$hi"\``""") + keys = 'test' + EX + wanted = 'blah' + + +class TabStop_Shell_ShebangPython(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = ('test', """Hallo ${1:now `#!/usr/bin/env %s +print "Hallo Welt" +`} end""" % (os.environ.get('PYTHON', 'python2'),)) + keys = 'test' + EX + JF + 'and more' + wanted = 'Hallo now Hallo Welt endand more' +# End: ShellCode Interpolation #}}} +# VimScript Interpolation {{{# + + +class TabStop_VimScriptInterpolation_SimpleExample(_VimTest): + snippets = ('test', """hi `!v indent(".")` End""") + keys = ' test' + EX + wanted = ' hi 4 End' +# End: VimScript Interpolation #}}} +# PythonCode Interpolation {{{# +# Deprecated Implementation {{{# + + +class PythonCodeOld_SimpleExample(_VimTest): + snippets = ('test', """hi `!p res = "Hallo"` End""") + keys = 'test' + EX + wanted = 'hi Hallo End' + + +class PythonCodeOld_ReferencePlaceholderAfter(_VimTest): + snippets = ('test', """${1:hi} `!p res = t[1]+".blah"` End""") + keys = 'test' + EX + 'ho' + wanted = 'ho ho.blah End' + + +class PythonCodeOld_ReferencePlaceholderBefore(_VimTest): + snippets = ('test', """`!p res = len(t[1])*"#"`\n${1:some text}""") + keys = 'test' + EX + 'Hallo Welt' + wanted = '##########\nHallo Welt' + + +class PythonCodeOld_TransformedBeforeMultiLine(_VimTest): + snippets = ('test', """${1/.+/egal/m} ${1:`!p +res = "Hallo"`} End""") + keys = 'test' + EX + wanted = 'egal Hallo End' + + +class PythonCodeOld_IndentedMultiline(_VimTest): + snippets = ('test', """start `!p a = 1 +b = 2 +if b > a: + res = "b isbigger a" +else: + res = "a isbigger b"` end""") + keys = ' test' + EX + wanted = ' start b isbigger a end' +# End: Deprecated Implementation #}}} +# New Implementation {{{# + + +class PythonCode_UseNewOverOld(_VimTest): + snippets = ('test', """hi `!p res = "Old" +snip.rv = "New"` End""") + keys = 'test' + EX + wanted = 'hi New End' + + +class PythonCode_SimpleExample(_VimTest): + snippets = ('test', """hi `!p snip.rv = "Hallo"` End""") + keys = 'test' + EX + wanted = 'hi Hallo End' + + +class PythonCode_SimpleExample_ReturnValueIsEmptyString(_VimTest): + snippets = ('test', """hi`!p snip.rv = ""`End""") + keys = 'test' + EX + wanted = 'hiEnd' + + +class PythonCode_ReferencePlaceholder(_VimTest): + snippets = ('test', """${1:hi} `!p snip.rv = t[1]+".blah"` End""") + keys = 'test' + EX + 'ho' + wanted = 'ho ho.blah End' + + +class PythonCode_ReferencePlaceholderBefore(_VimTest): + snippets = ('test', """`!p snip.rv = len(t[1])*"#"`\n${1:some text}""") + keys = 'test' + EX + 'Hallo Welt' + wanted = '##########\nHallo Welt' + + +class PythonCode_TransformedBeforeMultiLine(_VimTest): + snippets = ('test', """${1/.+/egal/m} ${1:`!p +snip.rv = "Hallo"`} End""") + keys = 'test' + EX + wanted = 'egal Hallo End' + + +class PythonCode_MultilineIndented(_VimTest): + snippets = ('test', """start `!p a = 1 +b = 2 +if b > a: + snip.rv = "b isbigger a" +else: + snip.rv = "a isbigger b"` end""") + keys = ' test' + EX + wanted = ' start b isbigger a end' + + +class PythonCode_SimpleAppend(_VimTest): + snippets = ('test', """hi `!p snip.rv = "Hallo1" +snip += "Hallo2"` End""") + keys = 'test' + EX + wanted = 'hi Hallo1\nHallo2 End' + + +class PythonCode_MultiAppend(_VimTest): + snippets = ('test', """hi `!p snip.rv = "Hallo1" +snip += "Hallo2" +snip += "Hallo3"` End""") + keys = 'test' + EX + wanted = 'hi Hallo1\nHallo2\nHallo3 End' + + +class PythonCode_MultiAppendSimpleIndent(_VimTest): + snippets = ('test', """hi +`!p snip.rv="Hallo1" +snip += "Hallo2" +snip += "Hallo3"` +End""") + keys = """ + test""" + EX + wanted = """ + hi + Hallo1 + Hallo2 + Hallo3 + End""" + + +class PythonCode_SimpleMkline(_VimTest): + snippets = ('test', r"""hi +`!p snip.rv="Hallo1\n" +snip.rv += snip.mkline("Hallo2") + "\n" +snip.rv += snip.mkline("Hallo3")` +End""") + keys = """ + test""" + EX + wanted = """ + hi + Hallo1 + Hallo2 + Hallo3 + End""" + + +class PythonCode_MultiAppendShift(_VimTest): + snippets = ('test', r"""hi +`!p snip.rv="i1" +snip += "i1" +snip >> 1 +snip += "i2" +snip << 2 +snip += "i0" +snip >> 3 +snip += "i3"` +End""") + keys = """ + test""" + EX + wanted = """ + hi + i1 + i1 + i2 +i0 + i3 + End""" + + +class PythonCode_MultiAppendShiftMethods(_VimTest): + snippets = ('test', r"""hi +`!p snip.rv="i1\n" +snip.rv += snip.mkline("i1\n") +snip.shift(1) +snip.rv += snip.mkline("i2\n") +snip.unshift(2) +snip.rv += snip.mkline("i0\n") +snip.shift(3) +snip.rv += snip.mkline("i3")` +End""") + keys = """ + test""" + EX + wanted = """ + hi + i1 + i1 + i2 +i0 + i3 + End""" + + +class PythonCode_ResetIndent(_VimTest): + snippets = ('test', r"""hi +`!p snip.rv="i1" +snip >> 1 +snip += "i2" +snip.reset_indent() +snip += "i1" +snip << 1 +snip += "i0" +snip.reset_indent() +snip += "i1"` +End""") + keys = """ + test""" + EX + wanted = """ + hi + i1 + i2 + i1 +i0 + i1 + End""" + + +class PythonCode_IndentEtSw(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set expandtab') + snippets = ('test', r"""hi +`!p snip.rv = "i1" +snip >> 1 +snip += "i2" +snip << 2 +snip += "i0" +snip >> 1 +snip += "i1" +` +End""") + keys = """ test""" + EX + wanted = """ hi + i1 + i2 +i0 + i1 + End""" + + +class PythonCode_IndentEtSwOffset(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set expandtab') + snippets = ('test', r"""hi +`!p snip.rv = "i1" +snip >> 1 +snip += "i2" +snip << 2 +snip += "i0" +snip >> 1 +snip += "i1" +` +End""") + keys = """ test""" + EX + wanted = """ hi + i1 + i2 + i0 + i1 + End""" + + +class PythonCode_IndentNoetSwTs(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set ts=4') + snippets = ('test', r"""hi +`!p snip.rv = "i1" +snip >> 1 +snip += "i2" +snip << 2 +snip += "i0" +snip >> 1 +snip += "i1" +` +End""") + keys = """ test""" + EX + wanted = """ hi + i1 +\t i2 +i0 + i1 + End""" + +# Test using 'opt' + + +class PythonCode_OptExists(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('let g:UStest="yes"') + snippets = ( + 'test', + r"""hi `!p snip.rv = snip.opt("g:UStest") or "no"` End""") + keys = """test""" + EX + wanted = """hi yes End""" + + +class PythonCode_OptNoExists(_VimTest): + snippets = ( + 'test', + r"""hi `!p snip.rv = snip.opt("g:UStest") or "no"` End""") + keys = """test""" + EX + wanted = """hi no End""" + + +class PythonCode_IndentProblem(_VimTest): + # A test case which is likely related to bug 719649 + snippets = ('test', r"""hi `!p +snip.rv = "World" +` End""") + keys = ' ' * 8 + 'test' + EX # < 8 works. + wanted = """ hi World End""" + + +class PythonCode_TrickyReferences(_VimTest): + snippets = ( + 'test', + r"""${2:${1/.+/egal/}} ${1:$3} ${3:`!p snip.rv = "hi"`}""") + keys = 'ups test' + EX + wanted = 'ups egal hi hi' +# locals + + +class PythonCode_Locals(_VimTest): + snippets = ('test', r"""hi `!p a = "test" +snip.rv = "nothing"` `!p snip.rv = a +` End""") + keys = """test""" + EX + wanted = """hi nothing test End""" + + +class PythonCode_LongerTextThanSource_Chars(_VimTest): + snippets = ('test', r"""hi`!p snip.rv = "a" * 100`end""") + keys = """test""" + EX + 'ups' + wanted = 'hi' + 100 * 'a' + 'endups' + + +class PythonCode_LongerTextThanSource_MultiLine(_VimTest): + snippets = ( + 'test', + r"""hi`!p snip.rv = "a" * 100 + '\n'*100 + "a"*100`end""") + keys = """test""" + EX + 'ups' + wanted = 'hi' + 100 * 'a' + 100 * '\n' + 100 * 'a' + 'endups' + + +class PythonCode_AccessKilledTabstop_OverwriteSecond(_VimTest): + snippets = ( + 'test', + r"`!p snip.rv = t[2].upper()`${1:h${2:welt}o}`!p snip.rv = t[2].upper()`") + keys = 'test' + EX + JF + 'okay' + wanted = 'OKAYhokayoOKAY' + + +class PythonCode_AccessKilledTabstop_OverwriteFirst(_VimTest): + snippets = ( + 'test', + r"`!p snip.rv = t[2].upper()`${1:h${2:welt}o}`!p snip.rv = t[2].upper()`") + keys = 'test' + EX + 'aaa' + wanted = 'aaa' + +class PythonCode_CanOverwriteTabstop(_VimTest): + snippets = ( + 'test', + """$1`!p if len(t[1]) > 3 and len(t[2]) == 0: + t[2] = t[1][2:]; + t[1] = t[1][:2] + '-\\n\\t'; + vim.command('call feedkeys("\", "n")'); + `$2""") + keys = 'test' + EX + 'blah' + ', bah' + wanted = "bl-\n\tah, bah" + + +class PythonVisual_NoVisualSelection_Ignore(_VimTest): + snippets = ('test', 'h`!p snip.rv = snip.v.mode + snip.v.text`b') + keys = 'test' + EX + 'abc' + wanted = 'hbabc' + + +class PythonVisual_SelectOneWord(_VimTest): + snippets = ('test', 'h`!p snip.rv = snip.v.mode + snip.v.text`b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hvblablubb' + + +class PythonVisual_LineSelect_Simple(_VimTest): + snippets = ('test', 'h`!p snip.rv = snip.v.mode + snip.v.text`b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'hVhello\nnice\nworld\nb' + +class PythonVisual_HasAccessToSelectedPlaceholders(_VimTest): + snippets = ( + 'test', + """${1:first} ${2:second} (`!p +snip.rv = "placeholder: " + snip.p.current_text`)""" + ) + keys = 'test' + EX + ESC + "otest" + EX + JF + ESC + wanted = """first second (placeholder: first) +first second (placeholder: second)""" + +class PythonVisual_HasAccessToZeroPlaceholders(_VimTest): + snippets = ( + 'test', + """${1:first} ${2:second} (`!p +snip.rv = "placeholder: " + snip.p.current_text`)""" + ) + keys = 'test' + EX + ESC + "otest" + EX + JF + JF + JF + JF + wanted = """first second (placeholder: first second (placeholder: )) +first second (placeholder: )""" + +# Tests for https://bugs.launchpad.net/bugs/1259349 + + +class Python_WeirdScoping_Error(_VimTest): + snippets = ( + 'test', + "h`!p import re; snip.rv = '%i' % len([re.search for i in 'aiiia'])`b") + keys = 'test' + EX + wanted = 'h5b' +# End: New Implementation #}}} +# End: PythonCode Interpolation #}}} diff --git a/vim/bundle/ultisnips/test/test_ListSnippets.py b/vim/bundle/ultisnips/test/test_ListSnippets.py new file mode 100644 index 0000000..4b54631 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_ListSnippets.py @@ -0,0 +1,43 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# List Snippets {{{# + + +class _ListAllSnippets(_VimTest): + snippets = (('testblah', 'BLAAH', 'Say BLAH'), + ('test', 'TEST ONE', 'Say tst one'), + ('aloha', 'OHEEEE', 'Say OHEE'), + ) + + +class ListAllAvailable_NothingTyped_ExpectCorrectResult(_ListAllSnippets): + keys = '' + LS + '3\n' + wanted = 'BLAAH' + + +class ListAllAvailable_SpaceInFront_ExpectCorrectResult(_ListAllSnippets): + keys = ' ' + LS + '3\n' + wanted = ' BLAAH' + + +class ListAllAvailable_BraceInFront_ExpectCorrectResult(_ListAllSnippets): + keys = '} ' + LS + '3\n' + wanted = '} BLAAH' + + +class ListAllAvailable_testtyped_ExpectCorrectResult(_ListAllSnippets): + keys = 'hallo test' + LS + '2\n' + wanted = 'hallo BLAAH' + + +class ListAllAvailable_testtypedSecondOpt_ExpectCorrectResult( + _ListAllSnippets): + keys = 'hallo test' + LS + '1\n' + wanted = 'hallo TEST ONE' + + +class ListAllAvailable_NonDefined_NoExpectionShouldBeRaised(_ListAllSnippets): + keys = 'hallo qualle' + LS + 'Hi' + wanted = 'hallo qualleHi' +# End: List Snippets #}}} diff --git a/vim/bundle/ultisnips/test/test_Mirror.py b/vim/bundle/ultisnips/test/test_Mirror.py new file mode 100644 index 0000000..a6076bf --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Mirror.py @@ -0,0 +1,272 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Mirrors {{{# + + +class TextTabStopTextAfterTab_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 Hinten\n$1') + keys = 'test' + EX + 'hallo' + wanted = 'hallo Hinten\nhallo' + + +class TextTabStopTextBeforeTab_ExpectCorrectResult(_VimTest): + snippets = ('test', 'Vorne $1\n$1') + keys = 'test' + EX + 'hallo' + wanted = 'Vorne hallo\nhallo' + + +class TextTabStopTextSurroundedTab_ExpectCorrectResult(_VimTest): + snippets = ('test', 'Vorne $1 Hinten\n$1') + keys = 'test' + EX + 'hallo test' + wanted = 'Vorne hallo test Hinten\nhallo test' + + +class TextTabStopTextBeforeMirror_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\nVorne $1') + keys = 'test' + EX + 'hallo' + wanted = 'hallo\nVorne hallo' + + +class TextTabStopAfterMirror_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1 Hinten') + keys = 'test' + EX + 'hallo' + wanted = 'hallo\nhallo Hinten' + + +class TextTabStopSurroundMirror_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\nVorne $1 Hinten') + keys = 'test' + EX + 'hallo welt' + wanted = 'hallo welt\nVorne hallo welt Hinten' + + +class TextTabStopAllSurrounded_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ObenVorne $1 ObenHinten\nVorne $1 Hinten') + keys = 'test' + EX + 'hallo welt' + wanted = 'ObenVorne hallo welt ObenHinten\nVorne hallo welt Hinten' + + +class MirrorBeforeTabstopLeave_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1:this is it} $1') + keys = 'test' + EX + wanted = 'this is it this is it this is it' + + +class MirrorBeforeTabstopOverwrite_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1:this is it} $1') + keys = 'test' + EX + 'a' + wanted = 'a a a' + + +class TextTabStopSimpleMirrorMultiline_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1') + keys = 'test' + EX + 'hallo' + wanted = 'hallo\nhallo' + + +class SimpleMirrorMultilineMany_ExpectCorrectResult(_VimTest): + snippets = ('test', ' $1\n$1\na$1b\n$1\ntest $1 mich') + keys = 'test' + EX + 'hallo' + wanted = ' hallo\nhallo\nahallob\nhallo\ntest hallo mich' + + +class MultilineTabStopSimpleMirrorMultiline_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n\n$1\n\n$1') + keys = 'test' + EX + 'hallo Du\nHi' + wanted = 'hallo Du\nHi\n\nhallo Du\nHi\n\nhallo Du\nHi' + + +class MultilineTabStopSimpleMirrorMultiline1_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1\n$1') + keys = 'test' + EX + 'hallo Du\nHi' + wanted = 'hallo Du\nHi\nhallo Du\nHi\nhallo Du\nHi' + + +class MultilineTabStopSimpleMirrorDeleteInLine_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1\n$1') + keys = 'test' + EX + 'hallo Du\nHi\b\bAch Blah' + wanted = 'hallo Du\nAch Blah\nhallo Du\nAch Blah\nhallo Du\nAch Blah' + + +class TextTabStopSimpleMirrorMultilineMirrorInFront_ECR(_VimTest): + snippets = ('test', '$1\n${1:sometext}') + keys = 'test' + EX + 'hallo\nagain' + wanted = 'hallo\nagain\nhallo\nagain' + + +class SimpleMirrorDelete_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1') + keys = 'test' + EX + 'hallo\b\b' + wanted = 'hal\nhal' + + +class SimpleMirrorSameLine_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 $1') + keys = 'test' + EX + 'hallo' + wanted = 'hallo hallo' + + +class SimpleMirrorSameLine_InText_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 $1') + keys = 'ups test blah' + ESC + '02f i' + EX + 'hallo' + wanted = 'ups hallo hallo blah' + + +class SimpleMirrorSameLineBeforeTabDefVal_ECR(_VimTest): + snippets = ('test', '$1 ${1:replace me}') + keys = 'test' + EX + 'hallo foo' + wanted = 'hallo foo hallo foo' + + +class SimpleMirrorSameLineBeforeTabDefVal_DelB4Typing_ECR(_VimTest): + snippets = ('test', '$1 ${1:replace me}') + keys = 'test' + EX + BS + 'hallo foo' + wanted = 'hallo foo hallo foo' + + +class SimpleMirrorSameLineMany_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 $1 $1 $1') + keys = 'test' + EX + 'hallo du' + wanted = 'hallo du hallo du hallo du hallo du' + + +class SimpleMirrorSameLineManyMultiline_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 $1 $1 $1') + keys = 'test' + EX + 'hallo du\nwie gehts' + wanted = 'hallo du\nwie gehts hallo du\nwie gehts hallo du\nwie gehts' \ + ' hallo du\nwie gehts' + + +class SimpleMirrorDeleteSomeEnterSome_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1\n$1') + keys = 'test' + EX + 'hallo\b\bhups' + wanted = 'halhups\nhalhups' + + +class SimpleTabstopWithDefaultSimpelType_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:defa}\n$1') + keys = 'test' + EX + 'world' + wanted = 'ha world\nworld' + + +class SimpleTabstopWithDefaultComplexType_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:default value} $1\nanother: $1 mirror') + keys = 'test' + EX + 'world' + wanted = 'ha world world\nanother: world mirror' + + +class SimpleTabstopWithDefaultSimpelKeep_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:defa}\n$1') + keys = 'test' + EX + wanted = 'ha defa\ndefa' + + +class SimpleTabstopWithDefaultComplexKeep_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:default value} $1\nanother: $1 mirror') + keys = 'test' + EX + wanted = 'ha default value default value\nanother: default value mirror' + + +class TabstopWithMirrorManyFromAll_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $5 ${1:blub} $4 $0 ${2:$1.h} $1 $3 ${4:More}') + keys = 'test' + EX + 'hi' + JF + 'hu' + JF + 'hub' + JF + 'hulla' + \ + JF + 'blah' + JF + 'end' + wanted = 'ha blah hi hulla end hu hi hub hulla' + + +class TabstopWithMirrorInDefaultNoType_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:blub} ${2:$1.h}') + keys = 'test' + EX + wanted = 'ha blub blub.h' + + +class TabstopWithMirrorInDefaultNoType1_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha ${1:blub} ${2:$1}') + keys = 'test' + EX + wanted = 'ha blub blub' + + +class TabstopWithMirrorInDefaultTwiceAndExtra_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $1 ${2:$1.h $1.c}\ntest $1') + keys = 'test' + EX + 'stdin' + wanted = 'ha stdin stdin.h stdin.c\ntest stdin' + + +class TabstopWithMirrorInDefaultMultipleLeave_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $1 ${2:snip} ${3:$1.h $2}') + keys = 'test' + EX + 'stdin' + wanted = 'ha stdin snip stdin.h snip' + + +class TabstopWithMirrorInDefaultMultipleOverwrite_ExpectCorrectResult( + _VimTest): + snippets = ('test', 'ha $1 ${2:snip} ${3:$1.h $2}') + keys = 'test' + EX + 'stdin' + JF + 'do snap' + wanted = 'ha stdin do snap stdin.h do snap' + + +class TabstopWithMirrorInDefaultOverwrite_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $1 ${2:$1.h}') + keys = 'test' + EX + 'stdin' + JF + 'overwritten' + wanted = 'ha stdin overwritten' + + +class TabstopWithMirrorInDefaultOverwrite1_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $1 ${2:$1}') + keys = 'test' + EX + 'stdin' + JF + 'overwritten' + wanted = 'ha stdin overwritten' + + +class TabstopWithMirrorInDefaultNoOverwrite1_ExpectCorrectResult(_VimTest): + snippets = ('test', 'ha $1 ${2:$1}') + keys = 'test' + EX + 'stdin' + JF + JF + 'end' + wanted = 'ha stdin stdinend' + + +class MirrorRealLifeExample_ExpectCorrectResult(_VimTest): + snippets = ( + ('for', 'for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2})' + '\n{\n\t${0:/* code */}\n}'), + ) + keys = 'for' + EX + '100' + JF + 'avar\b\b\b\ba_variable' + JF + \ + 'a_variable *= 2' + JF + '// do nothing' + wanted = """for(size_t a_variable = 0; a_variable < 100; a_variable *= 2) +{ +\t// do nothing +}""" + + +class Mirror_TestKill_InsertBefore_NoKill(_VimTest): + snippets = 'test', '$1 $1_' + keys = 'hallo test' + EX + 'auch' + ESC + \ + 'wihi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noauch hinoauch_end' + + +class Mirror_TestKill_InsertAfter_NoKill(_VimTest): + snippets = 'test', '$1 $1_' + keys = 'hallo test' + EX + 'auch' + ESC + \ + 'eiab' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noauch noauchab_end' + + +class Mirror_TestKill_InsertBeginning_Kill(_VimTest): + snippets = 'test', '$1 $1_' + keys = 'hallo test' + EX + 'auch' + ESC + \ + 'wahi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noauch ahiuch_end' + + +class Mirror_TestKill_InsertEnd_Kill(_VimTest): + snippets = 'test', '$1 $1_' + keys = 'hallo test' + EX + 'auch' + ESC + \ + 'ehihi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noauch auchih_end' + + +class Mirror_TestKillTabstop_Kill(_VimTest): + snippets = 'test', 'welt${1:welt${2:welt}welt} $2' + keys = 'hallo test' + EX + 'elt' + wanted = 'hallo weltelt ' + +# End: Mirrors #}}} diff --git a/vim/bundle/ultisnips/test/test_Movement.py b/vim/bundle/ultisnips/test/test_Movement.py new file mode 100644 index 0000000..51b0c10 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Movement.py @@ -0,0 +1,83 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Cursor Movement {{{# + + +class CursorMovement_Multiline_ECR(_VimTest): + snippets = ('test', r"$1 ${1:a tab}") + keys = 'test' + EX + 'this is something\nvery nice\nnot' + JF + 'more text' + wanted = 'this is something\nvery nice\nnot ' \ + 'this is something\nvery nice\nnotmore text' + + +class CursorMovement_BS_InEditMode(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set backspace=eol,indent,start') + snippets = ('\n\t$1\n\t$2\n\n$3') + keys = '= (3, 0) + + +def python3(): + if PYTHON3: + return 'Test does not work on python3.' + +# Plugin: YouCompleteMe {{{# +# TODO(sirver): disabled because it fails right now. +# class Plugin_YouCompleteMe_IntegrationTest(_VimTest): + # def skip_if(self): + # r = python3() + # if r: + # return r + # if "7.4" not in self.version: + # return "Needs Vim 7.4." + # plugins = ["Valloric/YouCompleteMe"] + # snippets = ("superlongtrigger", "Hello") + # keys = "superlo\ty" + # wanted = "Hello" + + # def _extra_vim_config(self, vim_config): + # # Not sure why, but I need to make a new tab for this to work. + # vim_config.append('let g:UltiSnipsExpandTrigger="y"') + # vim_config.append('tabnew') + + # def _before_test(self): + # self.vim.send(":set ft=python\n") + # # Give ycm a chance to catch up. + # time.sleep(1) +# End: Plugin: YouCompleteMe #}}} +# Plugin: Neocomplete {{{# +# TODO(sirver): disabled because it fails right now. +# class Plugin_Neocomplete_BugTest(_VimTest): + # Test for https://github.com/SirVer/ultisnips/issues/228 + + # def skip_if(self): + # if '+lua' not in self.version: + # return 'Needs +lua' + # plugins = ['Shougo/neocomplete.vim'] + # snippets = ('t', 'Hello', '', 'w') + # keys = 'iab\\ t' + EX + # wanted = 'iab\\ Hello' + + # def _extra_vim_config(self, vim_config): + # vim_config.append(r'set iskeyword+=\\ ') + # vim_config.append('let g:neocomplete#enable_at_startup = 1') + # vim_config.append('let g:neocomplete#enable_smart_case = 1') + # vim_config.append('let g:neocomplete#enable_camel_case = 1') + # vim_config.append('let g:neocomplete#enable_auto_delimiter = 1') + # vim_config.append('let g:neocomplete#enable_refresh_always = 1') +# End: Plugin: Neocomplete #}}} +# Plugin: unite {{{# + +# TODO(sirver): Disable since it is flaky. +# class Plugin_unite_BugTest(_VimTest): + # plugins = ['Shougo/unite.vim'] + # snippets = ('t', 'Hello', '', 'w') + # keys = 'iab\\ t=UltiSnipsCallUnite()\n' + # wanted = 'iab\\ Hello ' + + # def _extra_vim_config(self, vim_config): + # vim_config.append(r'set iskeyword+=\\ ') + # vim_config.append('function! UltiSnipsCallUnite()') + # vim_config.append( + # ' Unite -start-insert -winheight=100 -immediately -no-empty ultisnips') + # vim_config.append(' return ""') + # vim_config.append('endfunction') +# End: Plugin: unite #}}} +# Plugin: Supertab {{{# + + +class Plugin_SuperTab_SimpleTest(_VimTest): + plugins = ['ervandew/supertab'] + snippets = ('long', 'Hello', '', 'w') + keys = ('longtextlongtext\n' + + 'longt' + EX + '\n' + # Should complete word + 'long' + EX) # Should expand + wanted = 'longtextlongtext\nlongtextlongtext\nHello' + + def _before_test(self): + # Make sure that UltiSnips has the keymap + self.vim.send_to_vim(':call UltiSnips#map_keys#MapKeys()\n') + + def _extra_vim_config(self, vim_config): + assert EX == '\t' # Otherwise this test needs changing. + vim_config.append('let g:SuperTabDefaultCompletionType = ""') + vim_config.append('let g:SuperTabRetainCompletionDuration = "insert"') + vim_config.append('let g:SuperTabLongestHighlight = 1') + vim_config.append('let g:SuperTabCrMapping = 0') +# End: Plugin: Supertab #}}} diff --git a/vim/bundle/ultisnips/test/test_Recursive.py b/vim/bundle/ultisnips/test/test_Recursive.py new file mode 100644 index 0000000..5e93594 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Recursive.py @@ -0,0 +1,265 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Recursive (Nested) Snippets {{{# + + +class RecTabStops_SimpleCase_ExpectCorrectResult(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'm' + EX + 'hello' + \ + JF + 'world' + JF + 'ups' + JF + 'end' + wanted = '[ [ hello world ]ups end ]' + + +class RecTabStops_SimpleCaseLeaveSecondSecond_ExpectCorrectResult(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'm' + EX + 'hello' + JF + 'world' + JF + JF + JF + 'end' + wanted = '[ [ hello world ] sec ]end' + + +class RecTabStops_SimpleCaseLeaveFirstSecond_ExpectCorrectResult(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'm' + EX + 'hello' + JF + JF + JF + 'world' + JF + 'end' + wanted = '[ [ hello sec ] world ]end' + + +class RecTabStops_InnerWOTabStop_ECR(_VimTest): + snippets = ( + ('m1', 'Just some Text'), + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm1' + EX + 'hi' + JF + 'two' + JF + 'end' + wanted = '[ Just some Texthi two ]end' + + +class RecTabStops_InnerWOTabStopTwiceDirectly_ECR(_VimTest): + snippets = ( + ('m1', 'JST'), + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm1' + EX + ' m1' + EX + 'hi' + JF + 'two' + JF + 'end' + wanted = '[ JST JSThi two ]end' + + +class RecTabStops_InnerWOTabStopTwice_ECR(_VimTest): + snippets = ( + ('m1', 'JST'), + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm1' + EX + JF + 'm1' + EX + 'hi' + JF + 'end' + wanted = '[ JST JSThi ]end' + + +class RecTabStops_OuterOnlyWithZeroTS_ECR(_VimTest): + snippets = ( + ('m', 'A $0 B'), + ('m1', 'C $1 D $0 E'), + ) + keys = 'm' + EX + 'm1' + EX + 'CD' + JF + 'DE' + wanted = 'A C CD D DE E B' + + +class RecTabStops_OuterOnlyWithZero_ECR(_VimTest): + snippets = ( + ('m', 'A $0 B'), + ('m1', 'C $1 D $0 E'), + ) + keys = 'm' + EX + 'm1' + EX + 'CD' + JF + 'DE' + wanted = 'A C CD D DE E B' + + +class RecTabStops_ExpandedInZeroTS_ECR(_VimTest): + snippets = ( + ('m', 'A $0 B $1'), + ('m1', 'C $1 D $0 E'), + ) + keys = 'm' + EX + 'hi' + JF + 'm1' + EX + 'CD' + JF + 'DE' + wanted = 'A C CD D DE E B hi' + + +class RecTabStops_ExpandedInZeroTSTwice_ECR(_VimTest): + snippets = ( + ('m', 'A $0 B $1'), + ('m1', 'C $1 D $0 E'), + ) + keys = 'm' + EX + 'hi' + JF + 'm' + EX + 'again' + JF + 'm1' + \ + EX + 'CD' + JF + 'DE' + wanted = 'A A C CD D DE E B again B hi' + + +class RecTabStops_ExpandedInZeroTSSecondTime_ECR(_VimTest): + snippets = ( + ('m', 'A $0 B $1'), + ('m1', 'C $1 D $0 E'), + ) + keys = 'm' + EX + 'hi' + JF + 'm' + EX + \ + 'm1' + EX + 'CD' + JF + 'DE' + JF + 'AB' + wanted = 'A A AB B C CD D DE E B hi' + + +class RecTabsStops_TypeInZero_ECR(_VimTest): + snippets = ( + ('v', r"\vec{$1}", 'Vector', 'w'), + ('frac', r"\frac{${1:one}}${0:zero}{${2:two}}", 'Fractio', 'w'), + ) + keys = 'v' + EX + 'frac' + EX + 'a' + JF + 'b' + JF + 'frac' + EX + 'aa' + JF + JF + 'cc' + JF + \ + 'hello frac' + EX + JF + JF + 'world' + wanted = r"\vec{\frac{a}\frac{aa}cc{two}{b}}hello \frac{one}world{two}" + + +class RecTabsStops_TypeInZero2_ECR(_VimTest): + snippets = ( + ('m', r"_${0:explicit zero}", 'snip', 'i'), + ) + keys = 'm' + EX + 'hello m' + EX + 'world m' + EX + 'end' + wanted = r"_hello _world _end" + + +class RecTabsStops_BackspaceZero_ECR(_VimTest): + snippets = ( + ('m', r"${1:one}${0:explicit zero}${2:two}", 'snip', 'i'), + ) + keys = 'm' + EX + JF + JF + BS + 'm' + EX + wanted = r"oneoneexplicit zerotwotwo" + + +class RecTabStops_MirrorInnerSnippet_ECR(_VimTest): + snippets = ( + ('m', '[ $1 $2 ] $1'), + ('m1', 'ASnip $1 ASnip $2 ASnip'), + ) + keys = 'm' + EX + 'm1' + EX + 'Hallo' + JF + 'Hi' + \ + JF + 'endone' + JF + 'two' + JF + 'totalend' + wanted = '[ ASnip Hallo ASnip Hi ASnipendone two ] ASnip Hallo ASnip Hi ASnipendonetotalend' + + +class RecTabStops_NotAtBeginningOfTS_ExpectCorrectResult(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'hello m' + EX + 'hi' + JF + 'two' + JF + 'ups' + JF + 'three' + \ + JF + 'end' + wanted = '[ hello [ hi two ]ups three ]end' + + +class RecTabStops_InNewlineInTabstop_ExpectCorrectResult(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'hello\nm' + EX + 'hi' + JF + 'two' + JF + 'ups' + JF + 'three' + \ + JF + 'end' + wanted = '[ hello\n[ hi two ]ups three ]end' + + +class RecTabStops_InNewlineInTabstopNotAtBeginOfLine_ECR(_VimTest): + snippets = ('m', '[ ${1:first} ${2:sec} ]') + keys = 'm' + EX + 'hello\nhello again m' + EX + 'hi' + JF + 'two' + \ + JF + 'ups' + JF + 'three' + JF + 'end' + wanted = '[ hello\nhello again [ hi two ]ups three ]end' + + +class RecTabStops_InNewlineMultiline_ECR(_VimTest): + snippets = ('m', 'M START\n$0\nM END') + keys = 'm' + EX + 'm' + EX + wanted = 'M START\nM START\n\nM END\nM END' + + +class RecTabStops_InNewlineManualIndent_ECR(_VimTest): + snippets = ('m', 'M START\n$0\nM END') + keys = 'm' + EX + ' m' + EX + 'hi' + wanted = 'M START\n M START\n hi\n M END\nM END' + + +class RecTabStops_InNewlineManualIndentTextInFront_ECR(_VimTest): + snippets = ('m', 'M START\n$0\nM END') + keys = 'm' + EX + ' hallo m' + EX + 'hi' + wanted = 'M START\n hallo M START\n hi\n M END\nM END' + + +class RecTabStops_InNewlineMultilineWithIndent_ECR(_VimTest): + snippets = ('m', 'M START\n $0\nM END') + keys = 'm' + EX + 'm' + EX + 'hi' + wanted = 'M START\n M START\n hi\n M END\nM END' + + +class RecTabStops_InNewlineMultilineWithNonZeroTS_ECR(_VimTest): + snippets = ('m', 'M START\n $1\nM END -> $0') + keys = 'm' + EX + 'm' + EX + 'hi' + JF + 'hallo' + JF + 'end' + wanted = 'M START\n M START\n hi\n M END -> hallo\n' \ + 'M END -> end' + + +class RecTabStops_BarelyNotLeavingInner_ECR(_VimTest): + snippets = ( + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm' + EX + 'a' + 3 * ARR_L + JF + 'hallo' + \ + JF + 'ups' + JF + 'world' + JF + 'end' + wanted = '[ [ a hallo ]ups world ]end' + + +class RecTabStops_LeavingInner_ECR(_VimTest): + snippets = ( + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm' + EX + 'a' + 4 * ARR_L + JF + 'hallo' + \ + JF + 'world' + wanted = '[ [ a sec ] hallo ]world' + + +class RecTabStops_LeavingInnerInner_ECR(_VimTest): + snippets = ( + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm' + EX + 'm' + EX + 'a' + 4 * ARR_L + JF + 'hallo' + \ + JF + 'ups' + JF + 'world' + JF + 'end' + wanted = '[ [ [ a sec ] hallo ]ups world ]end' + + +class RecTabStops_LeavingInnerInnerTwo_ECR(_VimTest): + snippets = ( + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm' + EX + 'm' + EX + 'a' + 6 * ARR_L + JF + 'hallo' + \ + JF + 'end' + wanted = '[ [ [ a sec ] sec ] hallo ]end' + + +class RecTabStops_ZeroTSisNothingSpecial_ECR(_VimTest): + snippets = ( + ('m1', '[ ${1:first} $0 ${2:sec} ]'), + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm1' + EX + 'one' + JF + 'two' + \ + JF + 'three' + JF + 'four' + JF + 'end' + wanted = '[ [ one three two ] four ]end' + + +class RecTabStops_MirroredZeroTS_ECR(_VimTest): + snippets = ( + ('m1', '[ ${1:first} ${0:Year, some default text} $0 ${2:sec} ]'), + ('m', '[ ${1:first} ${2:sec} ]'), + ) + keys = 'm' + EX + 'm1' + EX + 'one' + JF + 'two' + \ + JF + 'three' + JF + 'four' + JF + 'end' + wanted = '[ [ one three three two ] four ]end' + + +class RecTabStops_ChildTriggerContainsParentTextObjects(_VimTest): + # https://bugs.launchpad.net/bugs/1191617 + files = { 'us/all.snippets': r""" +global !p +def complete(t, opts): + if t: + opts = [ q[len(t):] for q in opts if q.startswith(t) ] + if len(opts) == 0: + return '' + return opts[0] if len(opts) == 1 else "(" + '|'.join(opts) + ')' +def autocomplete_options(t, string, attr=None): + return complete(t[1], [opt for opt in attr if opt not in string]) +endglobal +snippet /form_for(.*){([^|]*)/ "form_for html options" rw! +`!p +auto = autocomplete_options(t, match.group(2), attr=["id: ", "class: ", "title: "]) +snip.rv = "form_for" + match.group(1) + "{"`$1`!p if (snip.c != auto) : snip.rv=auto` +endsnippet +"""} + keys = 'form_for user, namespace: some_namespace, html: {i' + EX + 'i' + EX + wanted = 'form_for user, namespace: some_namespace, html: {(id: |class: |title: )d: ' +# End: Recursive (Nested) Snippets #}}} diff --git a/vim/bundle/ultisnips/test/test_Selection.py b/vim/bundle/ultisnips/test/test_Selection.py new file mode 100644 index 0000000..6eeb3a9 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Selection.py @@ -0,0 +1,125 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# Unmap SelectMode Mappings {{{# +# Test for bug 427298 # + + +class _SelectModeMappings(_VimTest): + snippets = ('test', '${1:World}') + keys = 'test' + EX + 'Hello' + wanted = 'Hello' + maps = ('', '') + buffer_maps = ('', '') + do_unmapping = True + ignores = [] + + def _extra_vim_config(self, vim_config): + vim_config.append( + ':let g:UltiSnipsRemoveSelectModeMappings=%i' % int( + self.do_unmapping)) + vim_config.append( + ':let g:UltiSnipsMappingsToIgnore=%s' % + repr( + self.ignores)) + + if not isinstance(self.maps[0], tuple): + self.maps = (self.maps,) + if not isinstance(self.buffer_maps[0], tuple): + self.buffer_maps = (self.buffer_maps,) + + for key, m in self.maps: + if not len(key): + continue + vim_config.append(':smap %s %s' % (key, m)) + for key, m in self.buffer_maps: + if not len(key): + continue + vim_config.append(':smap %s %s' % (key, m)) + + +class SelectModeMappings_RemoveBeforeSelecting_ECR(_SelectModeMappings): + maps = ('H', 'x') + wanted = 'Hello' + + +class SelectModeMappings_DisableRemoveBeforeSelecting_ECR(_SelectModeMappings): + do_unmapping = False + maps = ('H', 'x') + wanted = 'xello' + + +class SelectModeMappings_IgnoreMappings_ECR(_SelectModeMappings): + ignores = ['e'] + maps = ('H', 'x'), ('e', 'l') + wanted = 'Hello' + + +class SelectModeMappings_IgnoreMappings1_ECR(_SelectModeMappings): + ignores = ['H'] + maps = ('H', 'x'), ('e', 'l') + wanted = 'xello' + + +class SelectModeMappings_IgnoreMappings2_ECR(_SelectModeMappings): + ignores = ['e', 'H'] + maps = ('e', 'l'), ('H', 'x') + wanted = 'xello' + + +class SelectModeMappings_BufferLocalMappings_ECR(_SelectModeMappings): + buffer_maps = ('H', 'blah') + wanted = 'Hello' +# End: Unmap SelectMode Mappings #}}} + +# Exclusive Selection {{{# + + +class _ES_Base(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set selection=exclusive') + + +class ExclusiveSelection_SimpleTabstop_Test(_ES_Base): + snippets = ('test', 'h${1:blah}w $1') + keys = 'test' + EX + 'ui' + JF + wanted = 'huiw ui' + + +class ExclusiveSelection_RealWorldCase_Test(_ES_Base): + snippets = ('for', + """for ($${1:i} = ${2:0}; $$1 < ${3:count}; $$1${4:++}) { + ${5:// code} +}""") + keys = 'for' + EX + 'k' + JF + wanted = """for ($k = 0; $k < count; $k++) { + // code +}""" +# End: Exclusive Selection #}}} + +# Old Selection {{{# + + +class _OS_Base(_VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set selection=old') + + +class OldSelection_SimpleTabstop_Test(_OS_Base): + snippets = ('test', 'h${1:blah}w $1') + keys = 'test' + EX + 'ui' + JF + wanted = 'huiw ui' + + +class OldSelection_RealWorldCase_Test(_OS_Base): + snippets = ('for', + """for ($${1:i} = ${2:0}; $$1 < ${3:count}; $$1${4:++}) { + ${5:// code} +}""") + keys = 'for' + EX + 'k' + JF + wanted = """for ($k = 0; $k < count; $k++) { + // code +}""" +# End: Old Selection #}}} diff --git a/vim/bundle/ultisnips/test/test_SnipMate.py b/vim/bundle/ultisnips/test/test_SnipMate.py new file mode 100644 index 0000000..c730354 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_SnipMate.py @@ -0,0 +1,191 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# snipMate support {{{# + + +class snipMate_SimpleSnippet(_VimTest): + files = { 'snippets/_.snippets': """ +snippet hello +\tThis is a test snippet +\t# With a comment"""} + keys = 'hello' + EX + wanted = 'This is a test snippet\n# With a comment' + +class snipMate_Disabled(_VimTest): + files = { 'snippets/_.snippets': """ +snippet hello +\tThis is a test snippet +\t# With a comment"""} + keys = 'hello' + EX + wanted = 'hello' + EX + + def _extra_vim_config(self, vim_config): + vim_config.append("let g:UltiSnipsEnableSnipMate=0"); + + +class snipMate_OtherFiletype(_VimTest): + files = { 'snippets/blubi.snippets': """ +snippet hello +\tworked"""} + keys = 'hello' + EX + ESC + ':set ft=blubi\nohello' + EX + wanted = 'hello' + EX + '\nworked' + + +class snipMate_MultiMatches(_VimTest): + files = { 'snippets/_.snippets': """ +snippet hello The first snippet." +\tone +snippet hello The second snippet. +\ttwo"""} + keys = 'hello' + EX + '2\n' + wanted = 'two' + + +class snipMate_SimpleSnippetSubDirectory(_VimTest): + files = { 'snippets/_/blub.snippets': """ +snippet hello +\tThis is a test snippet"""} + keys = 'hello' + EX + wanted = 'This is a test snippet' + + +class snipMate_SimpleSnippetInSnippetFile(_VimTest): + files = { + 'snippets/_/hello.snippet': """This is a stand alone snippet""", + 'snippets/_/hello1.snippet': """This is two stand alone snippet""", + 'snippets/_/hello2/this_is_my_cool_snippet.snippet': """Three""", + } + keys = 'hello' + EX + '\nhello1' + EX + '\nhello2' + EX + wanted = 'This is a stand alone snippet\nThis is two stand alone snippet\nThree' + + +class snipMate_Interpolation(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\tla`printf('c%02d', 3)`lu"""} + keys = 'test' + EX + wanted = 'lac03lu' + + +class snipMate_InterpolationWithSystem(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\tla`system('echo -ne öäü')`lu"""} + keys = 'test' + EX + wanted = 'laöäülu' + + +class snipMate_TestMirrors(_VimTest): + files = { 'snippets/_.snippets': """ +snippet for +\tfor (${2:i}; $2 < ${1:count}; $1++) { +\t\t${4} +\t}"""} + keys = 'for' + EX + 'blub' + JF + 'j' + JF + 'hi' + wanted = 'for (j; j < blub; blub++) {\n\thi\n}' + + +class snipMate_TestNoBraceTabstops(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\t$1 is $2"""} + keys = 'test' + EX + 'blub' + JF + 'blah' + wanted = 'blub is blah' + + +class snipMate_TestNoBraceTabstopsAndMirrors(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\t$1 is $1, $2 is ${2}"""} + keys = 'test' + EX + 'blub' + JF + 'blah' + wanted = 'blub is blub, blah is blah' + + +class snipMate_TestMirrorsInPlaceholders(_VimTest): + files = { 'snippets/_.snippets': """ +snippet opt +\t"""} + keys = 'opt' + EX + 'some' + JF + JF + 'ende' + wanted = """ende""" + + +class snipMate_TestMirrorsInPlaceholders_Overwrite(_VimTest): + files = { 'snippets/_.snippets': """ +snippet opt +\t"""} + keys = 'opt' + EX + 'some' + JF + 'not' + JF + 'ende' + wanted = """ende""" + + +class snipMate_Visual_Simple(_VimTest): + files = { 'snippets/_.snippets': """ +snippet v +\th${VISUAL}b"""} + keys = 'blablub' + ESC + '0v6l' + EX + 'v' + EX + wanted = 'hblablubb' + + +class snipMate_NoNestedTabstops(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\th$${1:${2:blub}}$$"""} + keys = 'test' + EX + JF + 'hi' + wanted = 'h$${2:blub}$$hi' + + +class snipMate_Extends(_VimTest): + files = { 'snippets/a.snippets': """ +extends b +snippet test +\tblub""", 'snippets/b.snippets': """ +snippet test1 +\tblah""" + } + keys = ESC + ':set ft=a\n' + 'itest1' + EX + wanted = 'blah' + + +class snipMate_EmptyLinesContinueSnippets(_VimTest): + files = { 'snippets/_.snippets': """ +snippet test +\tblub + +\tblah + +snippet test1 +\ta""" + } + keys = 'test' + EX + wanted = 'blub\n\nblah\n' + + +class snipMate_OverwrittenByRegExpTrigger(_VimTest): + files = { 'snippets/_.snippets': """ +snippet def +\tsnipmate +""", + 'us/all.snippets': r""" +snippet "(de)?f" "blub" r +ultisnips +endsnippet +""" } + keys = 'def' + EX + wanted = 'ultisnips' +# End: snipMate support #}}} + +class snipMate_Issue658(_VimTest): + files = { 'snippets/_.snippets': """ +snippet /* +\t/* +\t * ${0} +\t */ +"""} + keys = ESC + ':set fo=r\n' + 'i/*' + EX + '1\n2' + wanted = """/* + * 1 + * 2 + */ +"""; +# End: snipMate support #}}} diff --git a/vim/bundle/ultisnips/test/test_SnippetActions.py b/vim/bundle/ultisnips/test/test_SnippetActions.py new file mode 100644 index 0000000..403e234 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_SnippetActions.py @@ -0,0 +1,370 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + + +class SnippetActions_PreActionModifiesBuffer(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line:snip.line] = ['\n']" + snippet a "desc" "True" e + abc + endsnippet + """} + keys = 'a' + EX + wanted = '\nabc' + + +class SnippetActions_PostActionModifiesBuffer(_VimTest): + files = { 'us/all.snippets': r""" + post_expand "snip.buffer[snip.line+1:snip.line+1] = ['\n']" + snippet a "desc" "True" e + abc + endsnippet + """} + keys = 'a' + EX + wanted = 'abc\n' + +class SnippetActions_ErrorOnBufferModificationThroughCommand(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "vim.command('normal O')" + snippet a "desc" "True" e + abc + endsnippet + """} + keys = 'a' + EX + expected_error = 'changes are untrackable' + + +class SnippetActions_ErrorOnModificationSnippetLine(_VimTest): + files = { 'us/all.snippets': r""" + post_expand "vim.command('normal dd')" + snippet i "desc" "True" e + if: + $1 + endsnippet + """} + keys = 'i' + EX + expected_error = 'line under the cursor was modified' + + +class SnippetActions_EnsureIndent(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line] = ' '*4; snip.cursor[1] = 4" + snippet i "desc" "True" e + if: + $1 + endsnippet + """} + keys = '\ni' + EX + 'i' + EX + 'x' + wanted = """ + if: + if: + x""" + + +class SnippetActions_PostActionCanUseSnippetRange(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def ensure_newlines(start, end): + snip.buffer[start[0]:start[0]] = ['\n'] * 2 + snip.buffer[end[0]+1:end[0]+1] = ['\n'] * 1 + endglobal + + post_expand "ensure_newlines(snip.snippet_start, snip.snippet_end)" + snippet i "desc" + if + $1 + else + $2 + end + endsnippet + """} + keys = '\ni' + EX + 'x' + JF + 'y' + wanted = """ + + +if + x +else + y +end +""" + + +class SnippetActions_CanModifyParentBody(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def ensure_newlines(start, end): + snip.buffer[start[0]:start[0]] = ['\n'] * 2 + endglobal + + post_expand "ensure_newlines(snip.snippet_start, snip.snippet_end)" + snippet i "desc" + if + $1 + else + $2 + end + endsnippet + """} + keys = '\ni' + EX + 'i' + EX + 'x' + JF + 'y' + JF + JF + 'z' + wanted = """ + + +if + + + if + x + else + y + end +else + z +end""" + + +class SnippetActions_MoveParentSnippetFromChildInPreAction(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def insert_import(): + snip.buffer[2:2] = ['import smthing', ''] + endglobal + + pre_expand "insert_import()" + snippet p "desc" + print(smthing.traceback()) + endsnippet + + snippet i "desc" + if + $1 + else + $2 + end + endsnippet + """} + keys = 'i' + EX + 'p' + EX + JF + 'z' + wanted = """import smthing + +if + print(smthing.traceback()) +else + z +end""" + + +class SnippetActions_CanExpandSnippetInDifferentPlace(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def expand_after_if(snip): + snip.buffer[snip.line] = snip.buffer[snip.line][:snip.column] + \ + snip.buffer[snip.line][snip.column+1:] + snip.cursor[1] = snip.buffer[snip.line].index('if ')+3 + endglobal + + pre_expand "expand_after_if(snip)" + snippet n "append not to if" w + not $0 + endsnippet + + snippet i "if cond" w + if $1: $2 + endsnippet + """} + keys = 'i' + EX + 'blah' + JF + 'n' + EX + JF + 'pass' + wanted = """if not blah: pass""" + + +class SnippetActions_MoveVisual(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def extract_method(snip): + del snip.buffer[snip.line] + snip.buffer[len(snip.buffer)-1:len(snip.buffer)-1] = [''] + snip.cursor.set(len(snip.buffer)-2, 0) + endglobal + + pre_expand "extract_method(snip)" + snippet n "append not to if" w + def $1: + ${VISUAL} + + endsnippet + """} + + keys = """ +def a: + x() + y() + z()""" + ESC + 'kVk' + EX + 'n' + EX + 'b' + + wanted = """ +def a: + z() + +def b: + x() + y()""" + + +class SnippetActions_CanMirrorTabStopsOutsideOfSnippet(_VimTest): + files = { 'us/all.snippets': r""" + post_jump "snip.buffer[2] = 'debug({})'.format(snip.tabstops[1].current_text)" + snippet i "desc" + if $1: + $2 + endsnippet + """} + keys = """ +--- +i""" + EX + "test(some(complex(cond(a))))" + JF + "x" + wanted = """debug(test(some(complex(cond(a))))) +--- +if test(some(complex(cond(a)))): + x""" + + +class SnippetActions_CanExpandAnonSnippetInJumpAction(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def expand_anon(snip): + if snip.tabstop == 0: + snip.expand_anon("a($2, $1)") + endglobal + + post_jump "expand_anon(snip)" + snippet i "desc" + if ${1:cond}: + $0 + endsnippet + """} + keys = "i" + EX + "x" + JF + "1" + JF + "2" + JF + ";" + wanted = """if x: + a(2, 1);""" + + +class SnippetActions_CanExpandAnonSnippetInJumpActionWhileSelected(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def expand_anon(snip): + if snip.tabstop == 0: + snip.expand_anon(" // a($2, $1)") + endglobal + + post_jump "expand_anon(snip)" + snippet i "desc" + if ${1:cond}: + ${2:pass} + endsnippet + """} + keys = "i" + EX + "x" + JF + JF + "1" + JF + "2" + JF + ";" + wanted = """if x: + pass // a(2, 1);""" + + +class SnippetActions_CanUseContextFromContextMatch(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line:snip.line] = [snip.context]" + snippet i "desc" "'some context'" e + body + endsnippet + """} + keys = "i" + EX + wanted = """some context +body""" + +class SnippetActions_CanExpandAnonSnippetOnFirstJump(_VimTest): + files = { 'us/all.snippets': r""" + global !p + def expand_new_snippet_on_first_jump(snip): + if snip.tabstop == 1: + snip.expand_anon("some_check($1, $2, $3)") + endglobal + + post_jump "expand_new_snippet_on_first_jump(snip)" + snippet "test" "test new features" "True" bwre + if $1: $2 + endsnippet + """} + keys = "test" + EX + "1" + JF + "2" + JF + "3" + JF + " or 4" + JF + "5" + wanted = """if some_check(1, 2, 3) or 4: 5""" + +class SnippetActions_CanExpandAnonOnPreExpand(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line] = ''; snip.expand_anon('totally_different($2, $1)')" + snippet test "test new features" wb + endsnippet + """} + keys = "test" + EX + "1" + JF + "2" + JF + "3" + wanted = """totally_different(2, 1)3""" + +class SnippetActions_CanEvenWrapSnippetInPreAction(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line] = ''; snip.expand_anon('some_wrapper($1): $2')" + snippet test "test new features" wb + wrapme($2, $1) + endsnippet + """} + keys = "test" + EX + "1" + JF + "2" + JF + "3" + JF + "4" + wanted = """some_wrapper(wrapme(2, 1)3): 4""" + +class SnippetActions_CanVisuallySelectFirstPlaceholderInAnonSnippetInPre(_VimTest): + files = { 'us/all.snippets': r""" + pre_expand "snip.buffer[snip.line] = ''; snip.expand_anon('${1:asd}, ${2:blah}')" + snippet test "test new features" wb + endsnippet + """} + keys = "test" + EX + "1" + JF + "2" + wanted = """1, 2""" + +class SnippetActions_UseCorrectJumpActions(_VimTest): + files = { 'us/all.snippets': r""" + post_jump "snip.buffer[-2:-2]=['a' + str(snip.tabstop)]" + snippet a "a" wb + $1 { + $2 + } + endsnippet + + snippet b "b" wb + bbb + endsnippet + + post_jump "snip.buffer[-2:-2]=['c' + str(snip.tabstop)]" + snippet c "c" w + $1 : $2 : $3 + endsnippet + """} + keys = "a" + EX + "1" + JF + "b" + EX + " c" + EX + "2" + JF + "3" + JF + "4" + JF + JF + wanted = """1 { +bbb 2 : 3 : 4 +} +a1 +a2 +c1 +c2 +c3 +c0 +a0""" + +class SnippetActions_PostActionModifiesCharAfterSnippet(_VimTest): + files = { 'us/all.snippets': r""" + post_expand "snip.buffer[snip.snippet_end[0]] = snip.buffer[snip.snippet_end[0]][:-1]" + snippet a "desc" i + ($1) + endsnippet + """} + keys = '[]' + ARR_L + 'a' + EX + '1' + JF + '2' + wanted = '[(1)2' + + +class SnippetActions_PostActionModifiesLineAfterSnippet(_VimTest): + files = { 'us/all.snippets': r""" + post_expand "snip.buffer[snip.snippet_end[0]+1:snip.snippet_end[0]+2] = []" + snippet a "desc" + 1: $1 + $0 + endsnippet + """} + keys = '\n3' + ARR_U + 'a' + EX + '1' + JF + '2' + wanted = '1: 1\n2' diff --git a/vim/bundle/ultisnips/test/test_SnippetOptions.py b/vim/bundle/ultisnips/test/test_SnippetOptions.py new file mode 100644 index 0000000..cd18b6a --- /dev/null +++ b/vim/bundle/ultisnips/test/test_SnippetOptions.py @@ -0,0 +1,357 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * +from test.util import running_on_windows + +# Snippet Options {{{# + + +class SnippetOptions_OnlyExpandWhenWSInFront_Expand(_VimTest): + snippets = ('test', 'Expand me!', '', 'b') + keys = 'test' + EX + wanted = 'Expand me!' + + +class SnippetOptions_OnlyExpandWhenWSInFront_Expand2(_VimTest): + snippets = ('test', 'Expand me!', '', 'b') + keys = ' test' + EX + wanted = ' Expand me!' + + +class SnippetOptions_OnlyExpandWhenWSInFront_DontExpand(_VimTest): + snippets = ('test', 'Expand me!', '', 'b') + keys = 'a test' + EX + wanted = 'a test' + EX + + +class SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWO(_VimTest): + snippets = ( + ('test', 'Expand me!', '', 'b'), + ('test', 'not at beginning', '', ''), + ) + keys = 'a test' + EX + wanted = 'a not at beginning' + + +class SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWOChoose(_VimTest): + snippets = ( + ('test', 'Expand me!', '', 'b'), + ('test', 'not at beginning', '', ''), + ) + keys = ' test' + EX + '1\n' + wanted = ' Expand me!' + + +class SnippetOptions_ExpandInwordSnippets_SimpleExpand(_VimTest): + snippets = (('test', 'Expand me!', '', 'i'), ) + keys = 'atest' + EX + wanted = 'aExpand me!' + + +class SnippetOptions_ExpandInwordSnippets_ExpandSingle(_VimTest): + snippets = (('test', 'Expand me!', '', 'i'), ) + keys = 'test' + EX + wanted = 'Expand me!' + + +class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand(_VimTest): + snippets = (('test', 'Expand me!', '', 'i'), ) + keys = '$test' + EX + wanted = '$Expand me!' + + +class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand2(_VimTest): + snippets = (('test', 'Expand me!', '', 'i'), ) + keys = '-test' + EX + wanted = '-Expand me!' + + +class SnippetOptions_ExpandInwordSnippetsWithOtherChars_Expand3(_VimTest): + skip_if = lambda self: running_on_windows() + snippets = (('test', 'Expand me!', '', 'i'), ) + keys = 'ßßtest' + EX + wanted = 'ßßExpand me!' + + +class _SnippetOptions_ExpandWordSnippets(_VimTest): + snippets = (('test', 'Expand me!', '', 'w'), ) + + +class SnippetOptions_ExpandWordSnippets_NormalExpand( + _SnippetOptions_ExpandWordSnippets): + keys = 'test' + EX + wanted = 'Expand me!' + + +class SnippetOptions_ExpandWordSnippets_NoExpand( + _SnippetOptions_ExpandWordSnippets): + keys = 'atest' + EX + wanted = 'atest' + EX + + +class SnippetOptions_ExpandWordSnippets_ExpandSuffix( + _SnippetOptions_ExpandWordSnippets): + keys = 'a-test' + EX + wanted = 'a-Expand me!' + + +class SnippetOptions_ExpandWordSnippets_ExpandSuffix2( + _SnippetOptions_ExpandWordSnippets): + keys = 'a(test' + EX + wanted = 'a(Expand me!' + + +class SnippetOptions_ExpandWordSnippets_ExpandSuffix3( + _SnippetOptions_ExpandWordSnippets): + keys = '[[test' + EX + wanted = '[[Expand me!' + + +class _No_Tab_Expand(_VimTest): + snippets = ('test', '\t\tExpand\tme!\t', '', 't') + + +class No_Tab_Expand_Simple(_No_Tab_Expand): + keys = 'test' + EX + wanted = '\t\tExpand\tme!\t' + + +class No_Tab_Expand_Leading_Spaces(_No_Tab_Expand): + keys = ' test' + EX + wanted = ' \t\tExpand\tme!\t' + + +class No_Tab_Expand_Leading_Tabs(_No_Tab_Expand): + keys = '\ttest' + EX + wanted = '\t\t\tExpand\tme!\t' + + +class No_Tab_Expand_No_TS(_No_Tab_Expand): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set sts=3') + keys = 'test' + EX + wanted = '\t\tExpand\tme!\t' + + +class No_Tab_Expand_ET(_No_Tab_Expand): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set expandtab') + keys = 'test' + EX + wanted = '\t\tExpand\tme!\t' + + +class No_Tab_Expand_ET_Leading_Spaces(_No_Tab_Expand): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set expandtab') + keys = ' test' + EX + wanted = ' \t\tExpand\tme!\t' + + +class No_Tab_Expand_ET_SW(_No_Tab_Expand): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=8') + vim_config.append('set expandtab') + keys = 'test' + EX + wanted = '\t\tExpand\tme!\t' + + +class No_Tab_Expand_ET_SW_TS(_No_Tab_Expand): + + def _extra_vim_config(self, vim_config): + vim_config.append('set sw=3') + vim_config.append('set sts=3') + vim_config.append('set ts=3') + vim_config.append('set expandtab') + keys = 'test' + EX + wanted = '\t\tExpand\tme!\t' + + +class _TabExpand_RealWorld(object): + snippets = ('hi', + r"""hi +`!p snip.rv="i1\n" +snip.rv += snip.mkline("i1\n") +snip.shift(1) +snip.rv += snip.mkline("i2\n") +snip.unshift(2) +snip.rv += snip.mkline("i0\n") +snip.shift(3) +snip.rv += snip.mkline("i3")` +snip.rv = repr(snip.rv) +End""") + + +class No_Tab_Expand_RealWorld(_TabExpand_RealWorld, _VimTest): + + def _extra_vim_config(self, vim_config): + vim_config.append('set noexpandtab') + keys = '\t\thi' + EX + wanted = """\t\thi +\t\ti1 +\t\ti1 +\t\t\ti2 +\ti0 +\t\t\t\ti3 +\t\tsnip.rv = repr(snip.rv) +\t\tEnd""" + + +class SnippetOptions_Regex_Expand(_VimTest): + snippets = ('(test)', 'Expand me!', '', 'r') + keys = 'test' + EX + wanted = 'Expand me!' + + +class SnippetOptions_Regex_WithSpace(_VimTest): + snippets = ('test ', 'Expand me!', '', 'r') + keys = 'test ' + EX + wanted = 'Expand me!' + + +class SnippetOptions_Regex_Multiple(_VimTest): + snippets = ('(test *)+', 'Expand me!', '', 'r') + keys = 'test test test' + EX + wanted = 'Expand me!' + + +class _Regex_Self(_VimTest): + snippets = ('((?<=\W)|^)(\.)', 'self.', '', 'r') + + +class SnippetOptions_Regex_Self_Start(_Regex_Self): + keys = '.' + EX + wanted = 'self.' + + +class SnippetOptions_Regex_Self_Space(_Regex_Self): + keys = ' .' + EX + wanted = ' self.' + + +class SnippetOptions_Regex_Self_TextAfter(_Regex_Self): + keys = ' .a' + EX + wanted = ' .a' + EX + + +class SnippetOptions_Regex_Self_TextBefore(_Regex_Self): + keys = 'a.' + EX + wanted = 'a.' + EX + + +class SnippetOptions_Regex_PythonBlockMatch(_VimTest): + snippets = (r"([abc]+)([def]+)", r"""`!p m = match +snip.rv += m.group(2) +snip.rv += m.group(1) +`""", '', 'r') + keys = 'test cabfed' + EX + wanted = 'test fedcab' + + +class SnippetOptions_Regex_PythonBlockNoMatch(_VimTest): + snippets = (r"cabfed", r"""`!p snip.rv = match or "No match"`""") + keys = 'test cabfed' + EX + wanted = 'test No match' +# Tests for Bug #691575 + + +class SnippetOptions_Regex_SameLine_Long_End(_VimTest): + snippets = ('(test.*)', 'Expand me!', '', 'r') + keys = 'test test abc' + EX + wanted = 'Expand me!' + + +class SnippetOptions_Regex_SameLine_Long_Start(_VimTest): + snippets = ('(.*test)', 'Expand me!', '', 'r') + keys = 'abc test test' + EX + wanted = 'Expand me!' + + +class SnippetOptions_Regex_SameLine_Simple(_VimTest): + snippets = ('(test)', 'Expand me!', '', 'r') + keys = 'abc test test' + EX + wanted = 'abc test Expand me!' + + +class MultiWordSnippet_Simple(_VimTest): + snippets = ('test me', 'Expand me!') + keys = 'test me' + EX + wanted = 'Expand me!' + + +class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_Expand(_VimTest): + snippets = ('test it', 'Expand me!', '', 'b') + keys = 'test it' + EX + wanted = 'Expand me!' + + +class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_Expand2(_VimTest): + snippets = ('test it', 'Expand me!', '', 'b') + keys = ' test it' + EX + wanted = ' Expand me!' + + +class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_DontExpand(_VimTest): + snippets = ('test it', 'Expand me!', '', 'b') + keys = 'a test it' + EX + wanted = 'a test it' + EX + + +class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWO(_VimTest): + snippets = ( + ('test it', 'Expand me!', '', 'b'), + ('test it', 'not at beginning', '', ''), + ) + keys = 'a test it' + EX + wanted = 'a not at beginning' + + +class MultiWord_SnippetOptions_OnlyExpandWhenWSInFront_OneWithOneWOChoose( + _VimTest): + snippets = ( + ('test it', 'Expand me!', '', 'b'), + ('test it', 'not at beginning', '', ''), + ) + keys = ' test it' + EX + '1\n' + wanted = ' Expand me!' + + +class MultiWord_SnippetOptions_ExpandInwordSnippets_SimpleExpand(_VimTest): + snippets = (('test it', 'Expand me!', '', 'i'), ) + keys = 'atest it' + EX + wanted = 'aExpand me!' + + +class MultiWord_SnippetOptions_ExpandInwordSnippets_ExpandSingle(_VimTest): + snippets = (('test it', 'Expand me!', '', 'i'), ) + keys = 'test it' + EX + wanted = 'Expand me!' + + +class _MultiWord_SnippetOptions_ExpandWordSnippets(_VimTest): + snippets = (('test it', 'Expand me!', '', 'w'), ) + + +class MultiWord_SnippetOptions_ExpandWordSnippets_NormalExpand( + _MultiWord_SnippetOptions_ExpandWordSnippets): + keys = 'test it' + EX + wanted = 'Expand me!' + + +class MultiWord_SnippetOptions_ExpandWordSnippets_NoExpand( + _MultiWord_SnippetOptions_ExpandWordSnippets): + keys = 'atest it' + EX + wanted = 'atest it' + EX + + +class MultiWord_SnippetOptions_ExpandWordSnippets_ExpandSuffix( + _MultiWord_SnippetOptions_ExpandWordSnippets): + keys = 'a-test it' + EX + wanted = 'a-Expand me!' +# Snippet Options #}}} diff --git a/vim/bundle/ultisnips/test/test_SnippetPriorities.py b/vim/bundle/ultisnips/test/test_SnippetPriorities.py new file mode 100644 index 0000000..be595cc --- /dev/null +++ b/vim/bundle/ultisnips/test/test_SnippetPriorities.py @@ -0,0 +1,158 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import EX, ESC + +# Snippet Priority {{{# + + +class SnippetPriorities_MultiWordTriggerOverwriteExisting(_VimTest): + snippets = ( + ('test me', '${1:Hallo}', 'Types Hallo'), + ('test me', '${1:World}', 'Types World'), + ('test me', 'We overwrite', 'Overwrite the two', '', 1), + ) + keys = 'test me' + EX + wanted = 'We overwrite' + + +class SnippetPriorities_DoNotCareAboutNonMatchings(_VimTest): + snippets = ( + ('test1', 'Hallo', 'Types Hallo'), + ('test2', 'We overwrite', 'Overwrite the two', '', 1), + ) + keys = 'test1' + EX + wanted = 'Hallo' + + +class SnippetPriorities_OverwriteExisting(_VimTest): + snippets = ( + ('test', '${1:Hallo}', 'Types Hallo'), + ('test', '${1:World}', 'Types World'), + ('test', 'We overwrite', 'Overwrite the two', '', 1), + ) + keys = 'test' + EX + wanted = 'We overwrite' + + +class SnippetPriorities_OverwriteTwice_ECR(_VimTest): + snippets = ( + ('test', '${1:Hallo}', 'Types Hallo'), + ('test', '${1:World}', 'Types World'), + ('test', 'We overwrite', 'Overwrite the two', '', 1), + ('test', 'again', 'Overwrite again', '', 2), + ) + keys = 'test' + EX + wanted = 'again' + + +class SnippetPriorities_OverwriteThenChoose_ECR(_VimTest): + snippets = ( + ('test', '${1:Hallo}', 'Types Hallo'), + ('test', '${1:World}', 'Types World'), + ('test', 'We overwrite', 'Overwrite the two', '', 1), + ('test', 'No overwrite', 'Not overwritten', '', 1), + ) + keys = 'test' + EX + '1\n\n' + 'test' + EX + '2\n' + wanted = 'We overwrite\nNo overwrite' + + +class SnippetPriorities_AddedHasHigherThanFile(_VimTest): + files = { 'us/all.snippets': r""" + snippet test "Test Snippet" b + This is a test snippet + endsnippet + """} + snippets = ( + ('test', 'We overwrite', 'Overwrite the two', '', 1), + ) + keys = 'test' + EX + wanted = 'We overwrite' + + +class SnippetPriorities_FileHasHigherThanAdded(_VimTest): + files = { 'us/all.snippets': r""" + snippet test "Test Snippet" b + This is a test snippet + endsnippet + """} + snippets = ( + ('test', 'We do not overwrite', 'Overwrite the two', '', -1), + ) + keys = 'test' + EX + wanted = 'This is a test snippet' + + +class SnippetPriorities_FileHasHigherThanAdded_neg_prio(_VimTest): + files = { 'us/all.snippets': r""" + priority -3 + snippet test "Test Snippet" b + This is a test snippet + endsnippet + """} + snippets = ( + ('test', 'We overwrite', 'Overwrite the two', '', -5), + ) + keys = 'test' + EX + wanted = 'This is a test snippet' + + +class SnippetPriorities_SimpleClear(_VimTest): + files = { + 'us/all.snippets': r""" + priority 1 + clearsnippets + priority -1 + snippet test "Test Snippet" + Should not expand to this. + endsnippet + """ + } + keys = 'test' + EX + wanted = 'test' + EX + + +class SnippetPriorities_SimpleClear2(_VimTest): + files = { + 'us/all.snippets': r""" + clearsnippets + snippet test "Test snippet" + Should not expand to this. + endsnippet + """ + } + keys = 'test' + EX + wanted = 'test' + EX + + +class SnippetPriorities_ClearedByParent(_VimTest): + files = { + 'us/p.snippets': r""" + clearsnippets + """, + 'us/c.snippets': r""" + extends p + snippet test "Test snippets" + Should not expand to this. + endsnippet + """ + } + keys = ESC + ':set ft=c\n' + 'itest' + EX + wanted = 'test' + EX + + +class SnippetPriorities_ClearedByChild(_VimTest): + files = { + 'us/p.snippets': r""" + snippet test "Test snippets" + Should only expand in p. + endsnippet + """, + 'us/c.snippets': r""" + extends p + clearsnippets + """ + } + keys = (ESC + ':set ft=p\n' + 'itest' + EX + '\n' + + ESC + ':set ft=c\n' + 'itest' + EX + ESC + ':set ft=p') + wanted = 'Should only expand in p.\ntest' + EX + +# End: Snippet Priority #}}} diff --git a/vim/bundle/ultisnips/test/test_TabStop.py b/vim/bundle/ultisnips/test/test_TabStop.py new file mode 100644 index 0000000..c9e7648 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_TabStop.py @@ -0,0 +1,408 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + + +class TabStopSimpleReplace_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo ${0:End} ${1:Beginning}') + keys = 'hallo' + EX + 'na' + JF + 'Du Nase' + wanted = 'hallo Du Nase na' + + +class TabStopSimpleReplaceZeroLengthTabstops_ExpectCorrectResult(_VimTest): + snippets = ('test', r":latex:\`$1\`$0") + keys = 'test' + EX + 'Hello' + JF + 'World' + wanted = ':latex:`Hello`World' + + +class TabStopSimpleReplaceReversed_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo ${1:End} ${0:Beginning}') + keys = 'hallo' + EX + 'na' + JF + 'Du Nase' + wanted = 'hallo na Du Nase' + + +class TabStopSimpleReplaceSurrounded_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo ${0:End} a small feed') + keys = 'hallo' + EX + 'Nase' + wanted = 'hallo Nase a small feed' + + +class TabStopSimpleReplaceSurrounded1_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo $0 a small feed') + keys = 'hallo' + EX + 'Nase' + wanted = 'hallo Nase a small feed' + + +class TabStop_Exit_ExpectCorrectResult(_VimTest): + snippets = ('echo', '$0 run') + keys = 'echo' + EX + 'test' + wanted = 'test run' + + +class TabStopNoReplace_ExpectCorrectResult(_VimTest): + snippets = ('echo', 'echo ${1:Hallo}') + keys = 'echo' + EX + wanted = 'echo Hallo' + + +class TabStop_EscapingCharsBackticks(_VimTest): + snippets = ('test', r"snip \` literal") + keys = 'test' + EX + wanted = 'snip ` literal' + + +class TabStop_EscapingCharsDollars(_VimTest): + snippets = ('test', r"snip \$0 $$0 end") + keys = 'test' + EX + 'hi' + wanted = 'snip $0 $hi end' + + +class TabStop_EscapingCharsDollars1(_VimTest): + snippets = ('test', r"a\${1:literal}") + keys = 'test' + EX + wanted = 'a${1:literal}' + + +class TabStop_EscapingCharsDollars_BeginningOfLine(_VimTest): + snippets = ('test', '\n\\${1:literal}') + keys = 'test' + EX + wanted = '\n${1:literal}' + + +class TabStop_EscapingCharsDollars_BeginningOfDefinitionText(_VimTest): + snippets = ('test', '\\${1:literal}') + keys = 'test' + EX + wanted = '${1:literal}' + + +class TabStop_EscapingChars_Backslash(_VimTest): + snippets = ('test', r"This \ is a backslash!") + keys = 'test' + EX + wanted = 'This \\ is a backslash!' + + +class TabStop_EscapingChars_Backslash2(_VimTest): + snippets = ('test', r"This is a backslash \\ done") + keys = 'test' + EX + wanted = r"This is a backslash \ done" + + +class TabStop_EscapingChars_Backslash3(_VimTest): + snippets = ('test', r"These are two backslashes \\\\ done") + keys = 'test' + EX + wanted = r"These are two backslashes \\ done" + + +class TabStop_EscapingChars_Backslash4(_VimTest): + # Test for bug 746446 + snippets = ('test', r"\\$1{$2}") + keys = 'test' + EX + 'hello' + JF + 'world' + wanted = r"\hello{world}" + + +class TabStop_EscapingChars_RealLife(_VimTest): + snippets = ('test', r"usage: \`basename \$0\` ${1:args}") + keys = 'test' + EX + '[ -u -v -d ]' + wanted = 'usage: `basename $0` [ -u -v -d ]' + + +class TabStopEscapingWhenSelected_ECR(_VimTest): + snippets = ('test', 'snip ${1:default}') + keys = 'test' + EX + ESC + '0ihi' + wanted = 'hisnip default' + + +class TabStopEscapingWhenSelectedSingleCharTS_ECR(_VimTest): + snippets = ('test', 'snip ${1:i}') + keys = 'test' + EX + ESC + '0ihi' + wanted = 'hisnip i' + + +class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest): + snippets = ('test', 'snip $1') + keys = 'test' + EX + ESC + '0ihi' + wanted = 'hisnip ' + + +class TabStopWithOneChar_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'nothing ${1:i} hups') + keys = 'hallo' + EX + 'ship' + wanted = 'nothing ship hups' + + +class TabStopTestJumping_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo ${2:End} mitte ${1:Beginning}') + keys = 'hallo' + EX + JF + 'Test' + JF + 'Hi' + wanted = 'hallo Test mitte BeginningHi' + + +class TabStopTestJumping2_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo $2 $1') + keys = 'hallo' + EX + JF + 'Test' + JF + 'Hi' + wanted = 'hallo Test Hi' + + +class TabStopTestJumpingRLExampleWithZeroTab_ExpectCorrectResult(_VimTest): + snippets = ('test', 'each_byte { |${1:byte}| $0 }') + keys = 'test' + EX + JF + 'Blah' + wanted = 'each_byte { |byte| Blah }' + + +class TabStopTestJumpingDontJumpToEndIfThereIsTabZero_ExpectCorrectResult( + _VimTest): + snippets = ('hallo', 'hallo $0 $1') + keys = 'hallo' + EX + 'Test' + JF + 'Hi' + JF + JF + 'du' + wanted = 'hallo Hi' + 2 * JF + 'du Test' + + +class TabStopTestBackwardJumping_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo ${2:End} mitte${1:Beginning}') + keys = 'hallo' + EX + 'Somelengthy Text' + JF + 'Hi' + JB + \ + 'Lets replace it again' + JF + 'Blah' + JF + JB * 2 + JF + wanted = 'hallo Blah mitteLets replace it again' + JB * 2 + JF + + +class TabStopTestBackwardJumping2_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo $2 $1') + keys = 'hallo' + EX + 'Somelengthy Text' + JF + 'Hi' + JB + \ + 'Lets replace it again' + JF + 'Blah' + JF + JB * 2 + JF + wanted = 'hallo Blah Lets replace it again' + JB * 2 + JF + + +class TabStopTestMultilineExpand_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'hallo $0\nnice $1 work\n$3 $2\nSeem to work') + keys = 'test hallo World' + ESC + '02f i' + EX + 'world' + JF + 'try' + \ + JF + 'test' + JF + 'one more' + JF + wanted = 'test hallo one more' + JF + '\nnice world work\n' \ + 'test try\nSeem to work World' + + +class TabStop_TSInDefaultTextRLExample_OverwriteNone_ECR(_VimTest): + snippets = ('test', """\n $0\n""") + keys = 'test' + EX + wanted = """
    \n \n
    """ + + +class TabStop_TSInDefaultTextRLExample_OverwriteFirst_NoJumpBack(_VimTest): + snippets = ('test', """\n $0\n""") + keys = 'test' + EX + ' blah' + JF + 'Hallo' + wanted = """
    \n Hallo\n
    """ + + +class TabStop_TSInDefaultTextRLExample_DeleteFirst(_VimTest): + snippets = ('test', """\n $0\n""") + keys = 'test' + EX + BS + JF + 'Hallo' + wanted = """
    \n Hallo\n
    """ + + +class TabStop_TSInDefaultTextRLExample_OverwriteFirstJumpBack(_VimTest): + snippets = ('test', """\n $3 $0\n""") + keys = 'test' + EX + 'Hi' + JF + 'Hallo' + JB + 'SomethingElse' + JF + \ + 'Nupl' + JF + 'Nox' + wanted = """\n Nupl Nox\n""" + + +class TabStop_TSInDefaultTextRLExample_OverwriteSecond(_VimTest): + snippets = ('test', """\n $0\n""") + keys = 'test' + EX + JF + 'no' + JF + 'End' + wanted = """
    \n End\n
    """ + + +class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBack(_VimTest): + snippets = ('test', """\n $3 $0\n""") + keys = 'test' + EX + JF + 'no' + JF + 'End' + JB + 'yes' + JF + 'Begin' \ + + JF + 'Hi' + wanted = """
    \n Begin Hi\n
    """ + + +class TabStop_TSInDefaultTextRLExample_OverwriteSecondTabBackTwice(_VimTest): + snippets = ('test', """\n $3 $0\n""") + keys = 'test' + EX + JF + 'no' + JF + 'End' + JB + 'yes' + JB + \ + ' allaway' + JF + 'Third' + JF + 'Last' + wanted = """
    \n Third Last\n
    """ + + +class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecond(_VimTest): + snippets = ('test', """h${1:a$2b}l""") + keys = 'test' + EX + JF + 'ups' + JF + 'End' + wanted = """haupsblEnd""" + + +class TabStop_TSInDefaultText_ZeroLengthZerothTabstop(_VimTest): + snippets = ('test', """Test: ${1:snippet start\nNested tabstop: $0\nsnippet end}\nTrailing text""") + keys = 'test' + EX + JF + 'hello' + wanted = "Test: snippet start\nNested tabstop: hello\nsnippet end\nTrailing text" + +class TabStop_TSInDefaultText_ZeroLengthZerothTabstop_Override(_VimTest): + snippets = ('test', """Test: ${1:snippet start\nNested tabstop: $0\nsnippet end}\nTrailing text""") + keys = 'test' + EX + 'blub' + JF + 'hello' + wanted = "Test: blub\nTrailing texthello" + +class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteFirst(_VimTest): + snippets = ('test', """h${1:a$2b}l""") + keys = 'test' + EX + 'ups' + JF + 'End' + wanted = """hupslEnd""" + + +class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackOverwrite( + _VimTest): + snippets = ('test', """h${1:a$2b}l""") + keys = 'test' + EX + JF + 'longertext' + JB + 'overwrite' + JF + 'End' + wanted = """hoverwritelEnd""" + + +class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward0( + _VimTest): + snippets = ('test', """h${1:a$2b}l""") + keys = 'test' + EX + JF + 'longertext' + JB + JF + 'overwrite' + JF + 'End' + wanted = """haoverwriteblEnd""" + + +class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecondJumpBackAndForward1( + _VimTest): + snippets = ('test', """h${1:a$2b}l""") + keys = 'test' + EX + JF + 'longertext' + JB + JF + JF + 'End' + wanted = """halongertextblEnd""" + + +class TabStop_TSInDefaultNested_OverwriteOneJumpBackToOther(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second ${3:third}}} $4') + keys = 'test' + EX + JF + 'Hallo' + JF + 'Ende' + wanted = 'hi this Hallo Ende' + + +class TabStop_TSInDefaultNested_OverwriteOneJumpToThird(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second ${3:third}}} $4') + keys = 'test' + EX + JF + JF + 'Hallo' + JF + 'Ende' + wanted = 'hi this second Hallo Ende' + + +class TabStop_TSInDefaultNested_OverwriteOneJumpAround(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second ${3:third}}} $4') + keys = 'test' + EX + JF + JF + 'Hallo' + JB + JB + 'Blah' + JF + 'Ende' + wanted = 'hi Blah Ende' + + +class TabStop_TSInDefault_MirrorsOutside_DoNothing(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second}} $2') + keys = 'test' + EX + wanted = 'hi this second second' + + +class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second}} $2') + keys = 'test' + EX + JF + 'Hallo' + wanted = 'hi this Hallo Hallo' + + +class TabStop_TSInDefault_MirrorsOutside_Overwrite0(_VimTest): + snippets = ('test', 'hi ${1:this ${2:second}} $2') + keys = 'test' + EX + 'Hallo' + wanted = 'hi Hallo ' + + +class TabStop_TSInDefault_MirrorsOutside_Overwrite1(_VimTest): + snippets = ('test', "$1: ${1:'${2:second}'} $2") + keys = 'test' + EX + 'Hallo' + wanted = 'Hallo: Hallo ' + + +class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond1(_VimTest): + snippets = ('test', "$1: ${1:'${2:second}'} $2") + keys = 'test' + EX + JF + 'Hallo' + wanted = "'Hallo': 'Hallo' Hallo" + + +class TabStop_TSInDefault_MirrorsOutside_OverwriteFirstSwitchNumbers(_VimTest): + snippets = ('test', "$2: ${2:'${1:second}'} $1") + keys = 'test' + EX + 'Hallo' + wanted = "'Hallo': 'Hallo' Hallo" + + +class TabStop_TSInDefault_MirrorsOutside_OverwriteFirst_RLExample(_VimTest): + snippets = ( + 'test', + """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""") + keys = 'test' + EX + 'WORLD' + JF + 'End' + wanted = 'world = require(WORLD)End' + + +class TabStop_TSInDefault_MirrorsOutside_OverwriteSecond_RLExample(_VimTest): + snippets = ( + 'test', + """`!p snip.rv = t[1].split('/')[-1].lower().strip("'")` = require(${1:'${2:sys}'})""") + keys = 'test' + EX + JF + 'WORLD' + JF + 'End' + wanted = "world = require('WORLD')End" + + +class TabStop_Multiline_Leave(_VimTest): + snippets = ('test', 'hi ${1:first line\nsecond line} world') + keys = 'test' + EX + wanted = 'hi first line\nsecond line world' + + +class TabStop_Multiline_Overwrite(_VimTest): + snippets = ('test', 'hi ${1:first line\nsecond line} world') + keys = 'test' + EX + 'Nothing' + wanted = 'hi Nothing world' + + +class TabStop_Multiline_MirrorInFront_Leave(_VimTest): + snippets = ('test', 'hi $1 ${1:first line\nsecond line} world') + keys = 'test' + EX + wanted = 'hi first line\nsecond line first line\nsecond line world' + + +class TabStop_Multiline_MirrorInFront_Overwrite(_VimTest): + snippets = ('test', 'hi $1 ${1:first line\nsecond line} world') + keys = 'test' + EX + 'Nothing' + wanted = 'hi Nothing Nothing world' + + +class TabStop_Multiline_DelFirstOverwriteSecond_Overwrite(_VimTest): + snippets = ('test', 'hi $1 $2 ${1:first line\nsecond line} ${2:Hi} world') + keys = 'test' + EX + BS + JF + 'Nothing' + wanted = 'hi Nothing Nothing world' + + +class TabStopNavigatingInInsertModeSimple_ExpectCorrectResult(_VimTest): + snippets = ('hallo', 'Hallo ${1:WELT} ups') + keys = 'hallo' + EX + 'haselnut' + 2 * ARR_L + 'hips' + JF + 'end' + wanted = 'Hallo haselnhipsut upsend' + + +class TabStop_CROnlyOnSelectedNear(_VimTest): + snippets = ('test', 't$1t${2: }t{\n\t$0\n}') + keys = 'test' + EX + JF + '\n' + JF + 't' + wanted = 'tt\nt{\n\tt\n}' + + +class TabStop_AdjacentTabStopAddText_ExpectCorrectResult(_VimTest): + snippets = ('test', '[ $1$2 ] $1') + keys = 'test' + EX + 'Hello' + JF + 'World' + JF + wanted = '[ HelloWorld ] Hello' + + +class TabStop_KeepCorrectJumpListOnOverwriteOfPartOfSnippet(_VimTest): + files = { 'us/all.snippets': r""" + snippet i + ia$1: $2 + endsnippet + + snippet ia + ia($1, $2) + endsnippet"""} + keys = 'i' + EX + EX + '1' + JF + '2' + JF + ' after' + JF + '3' + wanted = 'ia(1, 2) after: 3' + + +class TabStop_KeepCorrectJumpListOnOverwriteOfPartOfSnippetRE(_VimTest): + files = { 'us/all.snippets': r""" + snippet i + ia$1: $2 + endsnippet + + snippet "^ia" "regexp" r + ia($1, $2) + endsnippet"""} + keys = 'i' + EX + EX + '1' + JF + '2' + JF + ' after' + JF + '3' + wanted = 'ia(1, 2) after: 3' diff --git a/vim/bundle/ultisnips/test/test_Transformation.py b/vim/bundle/ultisnips/test/test_Transformation.py new file mode 100644 index 0000000..433750e --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Transformation.py @@ -0,0 +1,269 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * +from test.util import no_unidecode_available + +# Transformations {{{# + + +class Transformation_SimpleCase_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/foo/batzl/}') + keys = 'test' + EX + 'hallo foo boy' + wanted = 'hallo foo boy hallo batzl boy' + + +class Transformation_SimpleCaseNoTransform_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/foo/batzl/}') + keys = 'test' + EX + 'hallo' + wanted = 'hallo hallo' + + +class Transformation_SimpleCaseTransformInFront_ExpectCorrectResult(_VimTest): + snippets = ('test', '${1/foo/batzl/} $1') + keys = 'test' + EX + 'hallo foo' + wanted = 'hallo batzl hallo foo' + + +class Transformation_SimpleCaseTransformInFrontDefVal_ECR(_VimTest): + snippets = ('test', '${1/foo/batzl/} ${1:replace me}') + keys = 'test' + EX + 'hallo foo' + wanted = 'hallo batzl hallo foo' + + +class Transformation_MultipleTransformations_ECR(_VimTest): + snippets = ('test', '${1:Some Text}${1/.+/\\U$0\E/}\n${1/.+/\L$0\E/}') + keys = 'test' + EX + 'SomE tExt ' + wanted = 'SomE tExt SOME TEXT \nsome text ' + + +class Transformation_TabIsAtEndAndDeleted_ECR(_VimTest): + snippets = ('test', '${1/.+/is something/}${1:some}') + keys = 'hallo test' + EX + 'some\b\b\b\b\b' + wanted = 'hallo ' + + +class Transformation_TabIsAtEndAndDeleted1_ECR(_VimTest): + snippets = ('test', '${1/.+/is something/}${1:some}') + keys = 'hallo test' + EX + 'some\b\b\b\bmore' + wanted = 'hallo is somethingmore' + + +class Transformation_TabIsAtEndNoTextLeave_ECR(_VimTest): + snippets = ('test', '${1/.+/is something/}${1}') + keys = 'hallo test' + EX + wanted = 'hallo ' + + +class Transformation_TabIsAtEndNoTextType_ECR(_VimTest): + snippets = ('test', '${1/.+/is something/}${1}') + keys = 'hallo test' + EX + 'b' + wanted = 'hallo is somethingb' + + +class Transformation_InsideTabLeaveAtDefault_ECR(_VimTest): + snippets = ('test', r"$1 ${2:${1/.+/(?0:defined $0)/}}") + keys = 'test' + EX + 'sometext' + JF + wanted = 'sometext defined sometext' + + +class Transformation_InsideTabOvertype_ECR(_VimTest): + snippets = ('test', r"$1 ${2:${1/.+/(?0:defined $0)/}}") + keys = 'test' + EX + 'sometext' + JF + 'overwrite' + wanted = 'sometext overwrite' + + +class Transformation_Backreference_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/([ab])oo/$1ull/}') + keys = 'test' + EX + 'foo boo aoo' + wanted = 'foo boo aoo foo bull aoo' + + +class Transformation_BackreferenceTwice_ExpectCorrectResult(_VimTest): + snippets = ('test', r"$1 ${1/(dead) (par[^ ]*)/this $2 is a bit $1/}") + keys = 'test' + EX + 'dead parrot' + wanted = 'dead parrot this parrot is a bit dead' + + +class Transformation_CleverTransformUpercaseChar_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(.)/\\u$1/}') + keys = 'test' + EX + 'hallo' + wanted = 'hallo Hallo' + + +class Transformation_CleverTransformLowercaseChar_ExpectCorrectResult( + _VimTest): + snippets = ('test', '$1 ${1/(.*)/\l$1/}') + keys = 'test' + EX + 'Hallo' + wanted = 'Hallo hallo' + + +class Transformation_CleverTransformLongUpper_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(.*)/\\U$1\E/}') + keys = 'test' + EX + 'hallo' + wanted = 'hallo HALLO' + + +class Transformation_CleverTransformLongLower_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(.*)/\L$1\E/}') + keys = 'test' + EX + 'HALLO' + wanted = 'HALLO hallo' + + +class Transformation_SimpleCaseAsciiResult(_VimTest): + skip_if = lambda self: no_unidecode_available() + snippets = ('ascii', '$1 ${1/(.*)/$1/a}') + keys = 'ascii' + EX + 'éèàçôïÉÈÀÇÔÏ€' + wanted = 'éèàçôïÉÈÀÇÔÏ€ eeacoiEEACOIEU' + + +class Transformation_LowerCaseAsciiResult(_VimTest): + skip_if = lambda self: no_unidecode_available() + snippets = ('ascii', '$1 ${1/(.*)/\L$1\E/a}') + keys = 'ascii' + EX + 'éèàçôïÉÈÀÇÔÏ€' + wanted = 'éèàçôïÉÈÀÇÔÏ€ eeacoieeacoieu' + + +class Transformation_ConditionalInsertionSimple_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(^a).*/(?0:began with an a)/}') + keys = 'test' + EX + 'a some more text' + wanted = 'a some more text began with an a' + + +class Transformation_CIBothDefinedNegative_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}') + keys = 'test' + EX + 'b some' + wanted = 'b some no' + + +class Transformation_CIBothDefinedPositive_ExpectCorrectResult(_VimTest): + snippets = ('test', '$1 ${1/(?:(^a)|(^b)).*/(?1:yes:no)/}') + keys = 'test' + EX + 'a some' + wanted = 'a some yes' + + +class Transformation_ConditionalInsertRWEllipsis_ECR(_VimTest): + snippets = ('test', r"$1 ${1/(\w+(?:\W+\w+){,7})\W*(.+)?/$1(?2:...)/}") + keys = 'test' + EX + 'a b c d e f ghhh h oha' + wanted = 'a b c d e f ghhh h oha a b c d e f ghhh h...' + + +class Transformation_ConditionalInConditional_ECR(_VimTest): + snippets = ('test', r"$1 ${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}") + keys = 'test' + EX + 'hallo' + ESC + '$a\n' + \ + 'test' + EX + 'hallo-' + ESC + '$a\n' + \ + 'test' + EX + 'hallo->' + wanted = 'hallo .\nhallo- >\nhallo-> ' + + +class Transformation_CINewlines_ECR(_VimTest): + snippets = ('test', r"$1 ${1/, */\n/}") + keys = 'test' + EX + 'test, hallo' + wanted = 'test, hallo test\nhallo' + + +class Transformation_CITabstop_ECR(_VimTest): + snippets = ('test', r"$1 ${1/, */\t/}") + keys = 'test' + EX + 'test, hallo' + wanted = 'test, hallo test\thallo' + + +class Transformation_CIEscapedParensinReplace_ECR(_VimTest): + snippets = ('test', r"$1 ${1/hal((?:lo)|(?:ul))/(?1:ha\($1\))/}") + keys = 'test' + EX + 'test, halul' + wanted = 'test, halul test, ha(ul)' + + +class Transformation_OptionIgnoreCase_ECR(_VimTest): + snippets = ('test', r"$1 ${1/test/blah/i}") + keys = 'test' + EX + 'TEST' + wanted = 'TEST blah' + + +class Transformation_OptionMultiline_ECR(_VimTest): + snippets = ('test', r"${VISUAL/^/* /mg}") + keys = 'test\ntest\ntest' + ESC + 'V2k' + EX + 'test' + EX + wanted = '* test\n* test\n* test' + + +class Transformation_OptionReplaceGlobal_ECR(_VimTest): + snippets = ('test', r"$1 ${1/, */-/g}") + keys = 'test' + EX + 'a, nice, building' + wanted = 'a, nice, building a-nice-building' + + +class Transformation_OptionReplaceGlobalMatchInReplace_ECR(_VimTest): + snippets = ('test', r"$1 ${1/, */, /g}") + keys = 'test' + EX + 'a, nice, building' + wanted = 'a, nice, building a, nice, building' + + +class TransformationUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest): + snippets = ('test', 'snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} ' + '${1:default} ${2:def}') + keys = 'test' + EX + BS + JF + 'hi' + wanted = 'snip m2 hi' + + +class TransformationUsingBackspaceToDeleteDefaultValueInSecondTab_ECR( + _VimTest): + snippets = ('test', 'snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} ' + '${1:default} ${2:def}') + keys = 'test' + EX + 'hi' + JF + BS + wanted = 'snip m1 hi ' + + +class TransformationUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR( + _VimTest): + snippets = ('test', 'snip ${1/.+/(?0:matched)/} ${1:default}') + keys = 'test' + EX + BS + 'hallo' + wanted = 'snip matched hallo' + + +class TransformationUsingBackspaceToDeleteDefaultValue_ECR(_VimTest): + snippets = ('test', 'snip ${1/.+/(?0:matched)/} ${1:default}') + keys = 'test' + EX + BS + wanted = 'snip ' + + +class Transformation_TestKill_InsertBefore_NoKill(_VimTest): + snippets = 'test', r"$1 ${1/.*/\L$0$0\E/}_" + keys = 'hallo test' + EX + 'AUCH' + ESC + \ + 'wihi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noAUCH hinoauchnoauch_end' + + +class Transformation_TestKill_InsertAfter_NoKill(_VimTest): + snippets = 'test', r"$1 ${1/.*/\L$0$0\E/}_" + keys = 'hallo test' + EX + 'AUCH' + ESC + \ + 'eiab' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noAUCH noauchnoauchab_end' + + +class Transformation_TestKill_InsertBeginning_Kill(_VimTest): + snippets = 'test', r"$1 ${1/.*/\L$0$0\E/}_" + keys = 'hallo test' + EX + 'AUCH' + ESC + \ + 'wahi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noAUCH ahiuchauch_end' + + +class Transformation_TestKill_InsertEnd_Kill(_VimTest): + snippets = 'test', r"$1 ${1/.*/\L$0$0\E/}_" + keys = 'hallo test' + EX + 'AUCH' + ESC + \ + 'ehihi' + ESC + 'bb' + 'ino' + JF + 'end' + wanted = 'hallo noAUCH auchauchih_end' + +class Transformation_ConditionalWithEscapedDelimiter(_VimTest): + snippets = 'test', r"$1 ${1/(aa)|.*/(?1:yes\:no\))/}" + keys = 'test' + EX + 'aa' + wanted = 'aa yes:no)' + +class Transformation_ConditionalWithBackslashBeforeDelimiter(_VimTest): + snippets = 'test', r"$1 ${1/(aa)|.*/(?1:yes\\:no)/}" + keys = 'test' + EX + 'aa' + wanted = 'aa yes\\' + +class Transformation_ConditionalWithBackslashBeforeDelimiter1(_VimTest): + snippets = 'test', r"$1 ${1/(aa)|.*/(?1:yes:no\\)/}" + keys = 'test' + EX + 'ab' + wanted = 'ab no\\' +# End: Transformations #}}} diff --git a/vim/bundle/ultisnips/test/test_UltiSnipFunc.py b/vim/bundle/ultisnips/test/test_UltiSnipFunc.py new file mode 100644 index 0000000..fda3372 --- /dev/null +++ b/vim/bundle/ultisnips/test/test_UltiSnipFunc.py @@ -0,0 +1,171 @@ +# encoding: utf-8 +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * +from test.util import running_on_windows + +# AddSnippet Function {{{# + + +class _AddFuncBase(_VimTest): + args = '' + + def _before_test(self): + self.vim.send_to_vim(':call UltiSnips#AddSnippetWithPriority(%s)\n' % self.args) + + +class AddFunc_Simple(_AddFuncBase): + args = '"test", "simple expand", "desc", "", "all", 0' + keys = 'abc test' + EX + wanted = 'abc simple expand' + + +class AddFunc_Opt(_AddFuncBase): + args = '".*test", "simple expand", "desc", "r", "all", 0' + keys = 'abc test' + EX + wanted = 'simple expand' +# End: AddSnippet Function #}}} + +# Langmap Handling {{{# +# Test for bug 501727 # + + +class TestNonEmptyLangmap_ExpectCorrectResult(_VimTest): + snippets = ('testme', + """my snipped ${1:some_default} +and a mirror: $1 +$2...$3 +$0""") + keys = 'testme' + EX + 'hi1' + JF + 'hi2' + JF + 'hi3' + JF + 'hi4' + wanted = """my snipped hi1 +and a mirror: hi1 +hi2...hi3 +hi4""" + + def _extra_vim_config(self, vim_config): + vim_config.append('set langmap=dj,rk,nl,ln,jd,kr,DJ,RK,NL,LN,JD,KR') + +# Test for https://bugs.launchpad.net/bugs/501727 # + + +class TestNonEmptyLangmapWithSemi_ExpectCorrectResult(_VimTest): + snippets = ('testme', + """my snipped ${1:some_default} +and a mirror: $1 +$2...$3 +$0""") + keys = 'testme' + EX + 'hi;' + JF + 'hi2' + \ + JF + 'hi3' + JF + 'hi4' + ESC + ';Hello' + wanted = """my snipped hi; +and a mirror: hi; +hi2...hi3 +hi4Hello""" + + def _before_test(self): + self.vim.send_to_vim(':set langmap=\\\\;;A\n') + +# Test for bug 871357 # + + +class TestLangmapWithUtf8_ExpectCorrectResult(_VimTest): + # SendKeys can't send UTF characters + skip_if = lambda self: running_on_windows() + snippets = ('testme', + """my snipped ${1:some_default} +and a mirror: $1 +$2...$3 +$0""") + keys = 'testme' + EX + 'hi1' + JF + 'hi2' + JF + 'hi3' + JF + 'hi4' + wanted = """my snipped hi1 +and a mirror: hi1 +hi2...hi3 +hi4""" + + def _before_test(self): + self.vim.send_to_vim( + ":set langmap=йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',яz,чx,сc,мv,иb,тn,ьm,ю.,ё',ЙQ,ЦW,УE,КR,ЕT,НY,ГU,ШI,ЩO,ЗP,Х\{,Ъ\},ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж\:,Э\",ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б\<,Ю\>\n") + +# End: Langmap Handling #}}} + +# SnippetsInCurrentScope {{{# + + +class VerifyVimDict1(_VimTest): + + """check: + correct type (4 means vim dictionary) + correct length of dictionary (in this case we have on element if the use same prefix, dictionary should have 1 element) + correct description (including the apostrophe) + if the prefix is mismatched no resulting dict should have 0 elements + """ + + snippets = ('testâ', 'abc123ά', '123\'êabc') + keys = ('test=(type(UltiSnips#SnippetsInCurrentScope()) . len(UltiSnips#SnippetsInCurrentScope()) . ' + + 'UltiSnips#SnippetsInCurrentScope()["testâ"]' + ')\n' + + '=len(UltiSnips#SnippetsInCurrentScope())\n') + + wanted = 'test41123\'êabc0' + + +class VerifyVimDict2(_VimTest): + + """check: + can use " in trigger + """ + + snippets = ('te"stâ', 'abc123ά', '123êabc') + akey = "'te{}stâ'".format('"') + keys = ( + 'te"=(UltiSnips#SnippetsInCurrentScope()[{}]'.format(akey) + ')\n') + wanted = 'te"123êabc' + + +class VerifyVimDict3(_VimTest): + + """check: + can use ' in trigger + """ + + snippets = ("te'stâ", 'abc123ά', '123êabc') + akey = '"te{}stâ"'.format("'") + keys = ( + "te'=(UltiSnips#SnippetsInCurrentScope()[{}]".format(akey) + ')\n') + wanted = "te'123êabc" +# End: SnippetsInCurrentScope #}}} + +# Snippet Source {{{# + + +class AddNewSnippetSource(_VimTest): + keys = ('blumba' + EX + ESC + + ':%(python)s UltiSnips_Manager.register_snippet_source(' + + "'temp', MySnippetSource())\n" + + 'oblumba' + EX + ESC + + ":%(python)s UltiSnips_Manager.unregister_snippet_source('temp')\n" + + 'oblumba' + EX) % {'python': 'py3' if PYTHON3 else 'py'} + wanted = ( + 'blumba' + EX + '\n' + + 'this is a dynamic snippet' + '\n' + + 'blumba' + EX + ) + + def _extra_vim_config(self, vim_config): + self._create_file('snippet_source.py', """ +from UltiSnips.snippet.source import SnippetSource +from UltiSnips.snippet.definition import UltiSnipsSnippetDefinition + +class MySnippetSource(SnippetSource): + def get_snippets(self, filetypes, before, possible, autotrigger_only, + visual_content): + if before.endswith('blumba') and autotrigger_only == False: + return [ + UltiSnipsSnippetDefinition( + -100, "blumba", "this is a dynamic snippet", "", "", {}, "blub", + None, {}) + ] + return [] +""") + pyfile = 'py3file' if PYTHON3 else 'pyfile' + vim_config.append( + '%s %s' % + (pyfile, self.name_temp('snippet_source.py'))) +# End: Snippet Source #}}} diff --git a/vim/bundle/ultisnips/test/test_Visual.py b/vim/bundle/ultisnips/test/test_Visual.py new file mode 100644 index 0000000..d6d9d8a --- /dev/null +++ b/vim/bundle/ultisnips/test/test_Visual.py @@ -0,0 +1,204 @@ +from test.vim_test_case import VimTestCase as _VimTest +from test.constant import * + +# ${VISUAL} {{{# + + +class Visual_NoVisualSelection_Ignore(_VimTest): + snippets = ('test', 'h${VISUAL}b') + keys = 'test' + EX + 'abc' + wanted = 'hbabc' + + +class Visual_SelectOneWord(_VimTest): + snippets = ('test', 'h${VISUAL}b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hblablubb' + + +class Visual_SelectOneWord_ProblemAfterTab(_VimTest): + snippets = ('test', 'h${VISUAL}b', '', 'i') + keys = '\tblablub' + ESC + '5hv3l' + EX + 'test' + EX + wanted = '\tbhlablbub' + + +class VisualWithDefault_ExpandWithoutVisual(_VimTest): + snippets = ('test', 'h${VISUAL:world}b') + keys = 'test' + EX + 'hi' + wanted = 'hworldbhi' + + +class VisualWithDefaultWithSlashes_ExpandWithoutVisual(_VimTest): + snippets = ('test', r"h${VISUAL:\/\/ body}b") + keys = 'test' + EX + 'hi' + wanted = 'h// bodybhi' + + +class VisualWithDefault_ExpandWithVisual(_VimTest): + snippets = ('test', 'h${VISUAL:world}b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hblablubb' + + +class Visual_ExpandTwice(_VimTest): + snippets = ('test', 'h${VISUAL}b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + '\ntest' + EX + wanted = 'hblablubb\nhb' + + +class Visual_SelectOneWord_TwiceVisual(_VimTest): + snippets = ('test', 'h${VISUAL}b${VISUAL}a') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hblablubbblabluba' + + +class Visual_SelectOneWord_Inword(_VimTest): + snippets = ('test', 'h${VISUAL}b', 'Description', 'i') + keys = 'blablub' + ESC + '0lv4l' + EX + 'test' + EX + wanted = 'bhlablubb' + + +class Visual_SelectOneWord_TillEndOfLine(_VimTest): + snippets = ('test', 'h${VISUAL}b', 'Description', 'i') + keys = 'blablub' + ESC + '0v$' + EX + 'test' + EX + ESC + 'o' + wanted = 'hblablub\nb' + + +class Visual_SelectOneWordWithTabstop_TillEndOfLine(_VimTest): + snippets = ('test', 'h${2:ahh}${VISUAL}${1:ups}b', 'Description', 'i') + keys = 'blablub' + ESC + '0v$' + EX + 'test' + \ + EX + 'mmm' + JF + 'n' + JF + 'done' + ESC + 'o' + wanted = 'hnblablub\nmmmbdone' + + +class Visual_InDefaultText_SelectOneWord_NoOverwrite(_VimTest): + snippets = ('test', 'h${1:${VISUAL}}b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + JF + 'hello' + wanted = 'hblablubbhello' + + +class Visual_InDefaultText_SelectOneWord(_VimTest): + snippets = ('test', 'h${1:${VISUAL}}b') + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + 'hello' + wanted = 'hhellob' + + +class Visual_CrossOneLine(_VimTest): + snippets = ('test', 'h${VISUAL}b') + keys = 'bla blub\n helloi' + ESC + '0k4lvjll' + EX + 'test' + EX + wanted = 'bla hblub\n hellobi' + + +class Visual_LineSelect_Simple(_VimTest): + snippets = ('test', 'h${VISUAL}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'hhello\n nice\n worldb' + + +class Visual_InDefaultText_LineSelect_NoOverwrite(_VimTest): + snippets = ('test', 'h${1:bef${VISUAL}aft}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + JF + 'hi' + wanted = 'hbefhello\n nice\n worldaftbhi' + + +class Visual_InDefaultText_LineSelect_Overwrite(_VimTest): + snippets = ('test', 'h${1:bef${VISUAL}aft}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \ + EX + 'test' + EX + 'jup' + JF + 'hi' + wanted = 'hjupbhi' + + +class Visual_LineSelect_CheckIndentSimple(_VimTest): + snippets = ('test', 'beg\n\t${VISUAL}\nend') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'beg\n\thello\n\tnice\n\tworld\nend' + + +class Visual_LineSelect_CheckIndentTwice(_VimTest): + snippets = ('test', 'beg\n\t${VISUAL}\nend') + keys = ' hello\n nice\n\tworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'beg\n\t hello\n\t nice\n\t\tworld\nend' + + +class Visual_InDefaultText_IndentSpacesToTabstop_NoOverwrite(_VimTest): + snippets = ('test', 'h${1:beforea${VISUAL}aft}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + JF + 'hi' + wanted = 'hbeforeahello\n\tnice\n\tworldaftbhi' + + +class Visual_InDefaultText_IndentSpacesToTabstop_Overwrite(_VimTest): + snippets = ('test', 'h${1:beforea${VISUAL}aft}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \ + EX + 'test' + EX + 'ups' + JF + 'hi' + wanted = 'hupsbhi' + + +class Visual_InDefaultText_IndentSpacesToTabstop_NoOverwrite1(_VimTest): + snippets = ('test', 'h${1:beforeaaa${VISUAL}aft}b') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + JF + 'hi' + wanted = 'hbeforeaaahello\n\t nice\n\t worldaftbhi' + + +class Visual_InDefaultText_IndentBeforeTabstop_NoOverwrite(_VimTest): + snippets = ('test', 'hello\n\t ${1:${VISUAL}}\nend') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + JF + 'hi' + wanted = 'hello\n\t hello\n\t nice\n\t world\nendhi' + + +class Visual_LineSelect_WithTabStop(_VimTest): + snippets = ('test', 'beg\n\t${VISUAL}\n\t${1:here_we_go}\nend') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \ + EX + 'test' + EX + 'super' + JF + 'done' + wanted = 'beg\n\thello\n\tnice\n\tworld\n\tsuper\nenddone' + + +class Visual_LineSelect_CheckIndentWithTS_NoOverwrite(_VimTest): + snippets = ('test', 'beg\n\t${0:${VISUAL}}\nend') + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'beg\n\thello\n\tnice\n\tworld\nend' + + +class Visual_LineSelect_DedentLine(_VimTest): + snippets = ('if', 'if {\n\t${VISUAL}$0\n}') + keys = 'if' + EX + 'one\n\ttwo\n\tthree' + ESC + \ + ARR_U * 2 + 'V' + ARR_D + EX + '\tif' + EX + wanted = 'if {\n\tif {\n\t\tone\n\t\ttwo\n\t}\n\tthree\n}' + + +class VisualTransformation_SelectOneWord(_VimTest): + snippets = ('test', r"h${VISUAL/./\U$0\E/g}b") + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hBLABLUBb' + + +class VisualTransformationWithDefault_ExpandWithoutVisual(_VimTest): + snippets = ('test', r"h${VISUAL:world/./\U$0\E/g}b") + keys = 'test' + EX + 'hi' + wanted = 'hWORLDbhi' + + +class VisualTransformationWithDefault_ExpandWithVisual(_VimTest): + snippets = ('test', r"h${VISUAL:world/./\U$0\E/g}b") + keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX + wanted = 'hBLABLUBb' + + +class VisualTransformation_LineSelect_Simple(_VimTest): + snippets = ('test', r"h${VISUAL/./\U$0\E/g}b") + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + wanted = 'hHELLO\n NICE\n WORLDb' + + +class VisualTransformation_InDefaultText_LineSelect_NoOverwrite(_VimTest): + snippets = ('test', r"h${1:bef${VISUAL/./\U$0\E/g}aft}b") + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + EX + 'test' + EX + JF + 'hi' + wanted = 'hbefHELLO\n NICE\n WORLDaftbhi' + + +class VisualTransformation_InDefaultText_LineSelect_Overwrite(_VimTest): + snippets = ('test', r"h${1:bef${VISUAL/./\U$0\E/g}aft}b") + keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \ + EX + 'test' + EX + 'jup' + JF + 'hi' + wanted = 'hjupbhi' + +# End: ${VISUAL} #}}} diff --git a/vim/bundle/ultisnips/test/util.py b/vim/bundle/ultisnips/test/util.py new file mode 100644 index 0000000..74d8d5b --- /dev/null +++ b/vim/bundle/ultisnips/test/util.py @@ -0,0 +1,17 @@ +import platform + +try: + import unidecode + UNIDECODE_IMPORTED = True +except ImportError: + UNIDECODE_IMPORTED = False + + +def running_on_windows(): + if platform.system() == 'Windows': + return 'Does not work on Windows.' + + +def no_unidecode_available(): + if not UNIDECODE_IMPORTED: + return 'unidecode is not available.' diff --git a/vim/bundle/ultisnips/test/vim_interface.py b/vim/bundle/ultisnips/test/vim_interface.py new file mode 100644 index 0000000..3c3c35a --- /dev/null +++ b/vim/bundle/ultisnips/test/vim_interface.py @@ -0,0 +1,278 @@ +# encoding: utf-8 + +import os +import re +import shutil +import subprocess +import tempfile +import textwrap +import time + +from test.constant import (ARR_D, ARR_L, ARR_R, ARR_U, BS, ESC, PYTHON3, + SEQUENCES) + + +def wait_until_file_exists(file_path, times=None, interval=0.01): + while times is None or times: + if os.path.exists(file_path): + return True + time.sleep(interval) + if times is not None: + times -= 1 + return False + + +def read_text_file(filename): + """Reads the contens of a text file.""" + if PYTHON3: + return open(filename, 'r', encoding='utf-8').read() + else: + return open(filename, 'r').read() + + +def is_process_running(pid): + """Returns true if a process with pid is running, false otherwise.""" + # from + # http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid + try: + os.kill(pid, 0) + except OSError: + return False + else: + return True + + +def silent_call(cmd): + """Calls 'cmd' and returns the exit value.""" + return subprocess.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + + +def create_directory(dirname): + """Creates 'dirname' and its parents if it does not exist.""" + try: + os.makedirs(dirname) + except OSError: + pass + + +class TempFileManager(object): + + def __init__(self, name=''): + self._temp_dir = tempfile.mkdtemp(prefix='UltiSnipsTest_' + name) + + def name_temp(self, file_path): + return os.path.join(self._temp_dir, file_path) + + def write_temp(self, file_path, content): + abs_path = self.name_temp(file_path) + create_directory(os.path.dirname(abs_path)) + if PYTHON3: + with open(abs_path, 'w', encoding='utf-8') as f: + f.write(content) + else: + with open(abs_path, 'w') as f: + f.write(content) + return abs_path + + def unique_name_temp(self, suffix='', prefix=''): + file_handler, abspath = tempfile.mkstemp( + suffix, prefix, self._temp_dir) + os.close(file_handler) + os.remove(abspath) + return abspath + + def clear_temp(self): + shutil.rmtree(self._temp_dir) + create_directory(self._temp_dir) + + +class VimInterface(TempFileManager): + + def __init__(self, vim_executable, name): + TempFileManager.__init__(self, name) + self._vim_executable = vim_executable + self._patch_version = None + + def has_patch(self, version): + if self._patch_version is None: + output = subprocess.check_output([ + self._vim_executable, "--version" + ]) + + self._patch_version = 0 + for line in output.decode('utf-8').split("\n"): + if line.startswith("Included patches:"): + self._patch_version = line.split('-')[1] + + return int(self._patch_version) >= version + + def get_buffer_data(self): + buffer_path = self.unique_name_temp(prefix='buffer_') + self.send_to_vim(ESC + ':w! %s\n' % buffer_path) + if wait_until_file_exists(buffer_path, 50): + return read_text_file(buffer_path)[:-1] + + def send_to_terminal(self, s): + """Types 's' into the terminal.""" + raise NotImplementedError() + + def send_to_vim(self, s): + """Types 's' into the vim instance under test.""" + raise NotImplementedError() + + def launch(self, config=[]): + """Returns the python version in Vim as a string, e.g. '2.7'""" + pid_file = self.name_temp('vim.pid') + done_file = self.name_temp('loading_done') + if os.path.exists(done_file): + os.remove(done_file) + + post_config = [] + post_config.append('%s << EOF' % ('py3' if PYTHON3 else 'py')) + post_config.append('import vim, sys') + post_config.append( + "with open('%s', 'w') as pid_file: pid_file.write(vim.eval('getpid()'))" % + pid_file) + post_config.append("with open('%s', 'w') as done_file:" % done_file) + post_config.append(" done_file.write('%i.%i.%i' % sys.version_info[:3])") + post_config.append('EOF') + + config_path = self.write_temp('vim_config.vim', + textwrap.dedent(os.linesep.join(config + post_config) + '\n')) + + # Note the space to exclude it from shell history. Also we always set + # NVIM_LISTEN_ADDRESS, even when running vanilla Vim, because it will + # just not care. + self.send_to_terminal(""" NVIM_LISTEN_ADDRESS=/tmp/nvim %s -u %s\r\n""" % ( + self._vim_executable, config_path)) + wait_until_file_exists(done_file) + self._vim_pid = int(read_text_file(pid_file)) + return read_text_file(done_file).strip() + + def leave_with_wait(self): + self.send_to_vim(3 * ESC + ':qa!\n') + while is_process_running(self._vim_pid): + time.sleep(.2) + + +class VimInterfaceTmux(VimInterface): + + def __init__(self, vim_executable, session): + VimInterface.__init__(self, vim_executable, 'Tmux') + self.session = session + self._check_version() + + def _send(self, s): + # I did not find any documentation on what needs escaping when sending + # to tmux, but it seems like this is all that is needed for now. + s = s.replace(';', r'\;') + + if PYTHON3: + s = s.encode('utf-8') + silent_call(['tmux', 'send-keys', '-t', self.session, '-l', s]) + + def send_to_terminal(self, s): + return self._send(s) + + def send_to_vim(self, s): + return self._send(s) + + def _check_version(self): + stdout, _ = subprocess.Popen(['tmux', '-V'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + if PYTHON3: + stdout = stdout.decode('utf-8') + m = re.match(r"tmux (\d+).(\d+)", stdout) + if not m or not (int(m.group(1)), int(m.group(2))) >= (1, 8): + raise RuntimeError( + 'Need at least tmux 1.8, you have %s.' % + stdout.strip()) + +class VimInterfaceTmuxNeovim(VimInterfaceTmux): + + def __init__(self, vim_executable, session): + VimInterfaceTmux.__init__(self, vim_executable, session) + self._nvim = None + + def send_to_vim(self, s): + if s == ARR_L: + s = "" + elif s == ARR_R: + s = "" + elif s == ARR_U: + s = "" + elif s == ARR_D: + s = "" + elif s == BS: + s = "" + elif s == ESC: + s = "" + elif s == "<": + s = "" + self._nvim.input(s) + + def launch(self, config=[]): + import neovim + rv = VimInterfaceTmux.launch(self, config) + self._nvim = neovim.attach('socket', path='/tmp/nvim') + return rv + +class VimInterfaceWindows(VimInterface): + BRACES = re.compile('([}{])') + WIN_ESCAPES = ['+', '^', '%', '~', '[', ']', '<', '>', '(', ')'] + WIN_REPLACES = [ + (BS, '{BS}'), + (ARR_L, '{LEFT}'), + (ARR_R, '{RIGHT}'), + (ARR_U, '{UP}'), + (ARR_D, '{DOWN}'), + ('\t', '{TAB}'), + ('\n', '~'), + (ESC, '{ESC}'), + + # On my system ` waits for a second keystroke, so `+SPACE = "`". On + # most systems, `+Space = "` ". I work around this, by sending the host + # ` as `+_+BS. Awkward, but the only way I found to get this working. + ('`', '`_{BS}'), + ('´', '´_{BS}'), + ('{^}', '{^}_{BS}'), + ] + + def __init__(self): + # import windows specific modules + import win32com.client + import win32gui + self.win32gui = win32gui + self.shell = win32com.client.Dispatch('WScript.Shell') + + def is_focused(self, title=None): + cur_title = self.win32gui.GetWindowText( + self.win32gui.GetForegroundWindow()) + if (title or '- GVIM') in cur_title: + return True + return False + + def focus(self, title=None): + if not self.shell.AppActivate(title or '- GVIM'): + raise Exception('Failed to switch to GVim window') + time.sleep(1) + + def convert_keys(self, keys): + keys = self.BRACES.sub(r"{\1}", keys) + for k in self.WIN_ESCAPES: + keys = keys.replace(k, '{%s}' % k) + for f, r in self.WIN_REPLACES: + keys = keys.replace(f, r) + return keys + + def send(self, keys): + keys = self.convert_keys(keys) + + if not self.is_focused(): + time.sleep(2) + self.focus() + if not self.is_focused(): + # This is the only way I can find to stop test execution + raise KeyboardInterrupt('Failed to focus GVIM') + + self.shell.SendKeys(keys) diff --git a/vim/bundle/ultisnips/test/vim_test_case.py b/vim/bundle/ultisnips/test/vim_test_case.py new file mode 100644 index 0000000..f3a6e08 --- /dev/null +++ b/vim/bundle/ultisnips/test/vim_test_case.py @@ -0,0 +1,208 @@ +# encoding: utf-8 + +# pylint: skip-file + +import os +import subprocess +import tempfile +import textwrap +import time +import unittest + +from test.constant import PYTHON3, SEQUENCES, EX +from test.vim_interface import create_directory, TempFileManager + + +def plugin_cache_dir(): + """The directory that we check out our bundles to.""" + return os.path.join(tempfile.gettempdir(), 'UltiSnips_test_vim_plugins') + + +class VimTestCase(unittest.TestCase, TempFileManager): + snippets = () + files = {} + text_before = ' --- some text before --- \n\n' + text_after = '\n\n --- some text after --- ' + expected_error = '' + wanted = '' + keys = '' + sleeptime = 0.00 + output = '' + plugins = [] + # Skip this test for the given reason or None for not skipping it. + skip_if = lambda self: None + version = None # Will be set to vim --version output + maxDiff = None # Show all diff output, always. + vim_flavor = None # will be 'vim' or 'neovim'. + expected_python_version = None # If set, we need to check that our Vim is running this python version. + + def __init__(self, *args, **kwargs): + unittest.TestCase.__init__(self, *args, **kwargs) + TempFileManager.__init__(self, 'Case') + + def runTest(self): + if self.expected_python_version: + self.assertEqual(self.in_vim_python_version, self.expected_python_version) + + # Only checks the output. All work is done in setUp(). + wanted = self.text_before + self.wanted + self.text_after + for i in range(self.retries): + if self.output and self.expected_error: + self.assertRegexpMatches(self.output, self.expected_error) + return + if self.output != wanted or self.output is None: + # Redo this, but slower + self.sleeptime += 0.15 + self.tearDown() + self.setUp() + self.assertMultiLineEqual(self.output, wanted) + + def _extra_vim_config(self, vim_config): + """Adds extra lines to the vim_config list.""" + + def _before_test(self): + """Send these keys before the test runs. + + Used for buffer local variables and other options. + + """ + + def _create_file(self, file_path, content): + """Creates a file in the runtimepath that is created for this test. + + Returns the absolute path to the file. + + """ + return self.write_temp(file_path, textwrap.dedent(content + '\n')) + + def _link_file(self, source, relative_destination): + """Creates a link from 'source' to the 'relative_destination' in our + temp dir.""" + absdir = self.name_temp(relative_destination) + create_directory(absdir) + os.symlink(source, os.path.join(absdir, os.path.basename(source))) + + def setUp(self): + # TODO(sirver): this uses 'vim', but must use --vim from the commandline. + if not VimTestCase.version: + VimTestCase.version, _ = subprocess.Popen(['vim', '--version'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + if PYTHON3: + VimTestCase.version = VimTestCase.version.decode('utf-8') + + if self.plugins and not self.test_plugins: + return self.skipTest('Not testing integration with other plugins.') + reason_for_skipping = self.skip_if() + if reason_for_skipping is not None: + return self.skipTest(reason_for_skipping) + + vim_config = [] + vim_config.append('set nocompatible') + vim_config.append('set runtimepath=$VIMRUNTIME,%s,%s' % ( + os.path.dirname(os.path.dirname(__file__)), self._temp_dir)) + + if self.plugins: + self._link_file( + os.path.join( + plugin_cache_dir(), + 'vim-pathogen', + 'autoload'), + '.') + for plugin in self.plugins: + self._link_file( + os.path.join( + plugin_cache_dir(), + os.path.basename(plugin)), + 'bundle') + vim_config.append('execute pathogen#infect()') + + # Some configurations are unnecessary for vanilla Vim, but Neovim + # defines some defaults differently. + vim_config.append('syntax on') + vim_config.append('filetype plugin indent on') + vim_config.append('set nosmarttab') + vim_config.append('set noautoindent') + vim_config.append('set backspace=""') + vim_config.append('set clipboard=""') + vim_config.append('set encoding=utf-8') + vim_config.append('set fileencoding=utf-8') + vim_config.append('set buftype=nofile') + vim_config.append('set shortmess=at') + vim_config.append('let @" = ""') + assert EX == "\t" # Otherwise you need to change the next line + vim_config.append('let g:UltiSnipsExpandTrigger=""') + vim_config.append('let g:UltiSnipsJumpForwardTrigger="?"') + vim_config.append('let g:UltiSnipsJumpBackwardTrigger="+"') + vim_config.append('let g:UltiSnipsListSnippets="@"') + vim_config.append( + 'let g:UltiSnipsUsePythonVersion="%i"' % + (3 if PYTHON3 else 2)) + vim_config.append('let g:UltiSnipsSnippetDirectories=["us"]') + if self.python_host_prog: + vim_config.append('let g:python_host_prog="%s"' % self.python_host_prog) + if self.python3_host_prog: + vim_config.append('let g:python3_host_prog="%s"' % self.python3_host_prog) + + self._extra_vim_config(vim_config) + + # Finally, add the snippets and some configuration for the test. + vim_config.append('%s << EOF' % ('py3' if PYTHON3 else 'py')) + vim_config.append('from UltiSnips import UltiSnips_Manager\n') + + if len(self.snippets) and not isinstance(self.snippets[0], tuple): + self.snippets = (self.snippets, ) + for s in self.snippets: + sv, content = s[:2] + description = '' + options = '' + priority = 0 + if len(s) > 2: + description = s[2] + if len(s) > 3: + options = s[3] + if len(s) > 4: + priority = s[4] + vim_config.append('UltiSnips_Manager.add_snippet(%r, %r, %r, %r, priority=%i)' % ( + sv, content, description, options, priority)) + + # fill buffer with default text and place cursor in between. + prefilled_text = (self.text_before + self.text_after).splitlines() + vim_config.append('import vim\n') + vim_config.append('vim.current.buffer[:] = %r\n' % prefilled_text) + vim_config.append( + 'vim.current.window.cursor = (max(len(vim.current.buffer)//2, 1), 0)') + + # End of python stuff. + vim_config.append('EOF') + + for name, content in self.files.items(): + self._create_file(name, content) + + self.in_vim_python_version = self.vim.launch(vim_config) + + self._before_test() + + if not self.interrupt: + # Go into insert mode and type the keys but leave Vim some time to + # react. + text = 'i' + self.keys + while text: + to_send = None + for seq in SEQUENCES: + if text.startswith(seq): + to_send = seq + break + to_send = to_send or text[0] + self.vim.send_to_vim(to_send) + time.sleep(self.sleeptime) + text = text[len(to_send):] + self.output = self.vim.get_buffer_data() + + def tearDown(self): + if self.interrupt: + print('Working directory: %s' % (self._temp_dir)) + return + self.vim.leave_with_wait() + self.clear_temp() + +# vim:fileencoding=utf-8:foldmarker={{{#,#}}}: diff --git a/vim/bundle/ultisnips/test_all.py b/vim/bundle/ultisnips/test_all.py new file mode 100755 index 0000000..7819e02 --- /dev/null +++ b/vim/bundle/ultisnips/test_all.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# To execute this test requires two terminals, one for running Vim and one +# for executing the test script. Both terminals should have their current +# working directories set to this directory (the one containing this +# test_all.py script). +# +# In one terminal, launch a tmux session named ``vim``: +# $ tmux new -s vim +# +# Now, from another terminal, launch the testsuite: +# $ ./test_all.py +# +# Note: if you want to use Vim against the Python 3 bindings, you must launch the +# test suite using Python 3. For example: +# $ python3 ./test_all.py +# +# For each test, the test_all.py script will launch vim with a vimrc, run the +# test, compare the output and exit vim again. The keys are send using tmux send-keys. +# +# To limit the tests that are executed, specify a pattern to be used to match +# the beginning of the test name. For instance, the following will execute all +# tests that start with "SimpleExpand": +# $ ./test_all.py SimpleExpand +# +# NOTE: The test suite is not working under Windows right now as I have no +# access to a windows system for fixing it. Volunteers welcome. Here are some +# comments from the last time I got the test suite running under windows. +# +# Under windows, COM's SendKeys is used to send keystrokes to the gvim window. +# Note that Gvim must use english keyboard input (choose in windows registry) +# for this to work properly as SendKeys is a piece of chunk. (i.e. it sends +# when you send a | symbol while using german key mappings) + +# pylint: skip-file + +import os +import platform +import subprocess +import unittest +from test.vim_interface import ( + create_directory, tempfile, VimInterfaceTmux, VimInterfaceTmuxNeovim) + + +def plugin_cache_dir(): + """The directory that we check out our bundles to.""" + return os.path.join(tempfile.gettempdir(), 'UltiSnips_test_vim_plugins') + + +def clone_plugin(plugin): + """Clone the given plugin into our plugin directory.""" + dirname = os.path.join(plugin_cache_dir(), os.path.basename(plugin)) + print('Cloning %s -> %s' % (plugin, dirname)) + if os.path.exists(dirname): + print('Skip cloning of %s. Already there.' % plugin) + return + create_directory(dirname) + subprocess.call(['git', 'clone', '--recursive', + '--depth', '1', 'https://github.com/%s' % plugin, dirname]) + + if plugin == 'Valloric/YouCompleteMe': + # CLUTCH: this plugin needs something extra. + subprocess.call(os.path.join(dirname, './install.sh'), cwd=dirname) + + +def setup_other_plugins(all_plugins): + """Creates /tmp/UltiSnips_test_vim_plugins and clones all plugins into + this.""" + clone_plugin('tpope/vim-pathogen') + for plugin in all_plugins: + clone_plugin(plugin) + +if __name__ == '__main__': + import optparse + import sys + + def parse_args(): + p = optparse.OptionParser('%prog [OPTIONS] ') + + p.set_defaults(session='vim', interrupt=False, + verbose=False, retries=4, plugins=False) + + p.add_option('-v', '--verbose', dest='verbose', action='store_true', + help='print name of tests as they are executed') + p.add_option('--clone-plugins', action='store_true', + help='Only clones dependant plugins and exits the test runner.') + p.add_option('--plugins', action='store_true', + help='Run integration tests with other Vim plugins.') + p.add_option('-s', '--session', dest='session', metavar='SESSION', + help='session parameters for the terminal multiplexer SESSION [%default]') + p.add_option('-i', '--interrupt', dest='interrupt', + action='store_true', + help='Stop after defining the snippet. This allows the user ' + 'to interactively test the snippet in vim. You must give ' + 'exactly one test case on the cmdline. The test will always fail.' + ) + p.add_option('-r', '--retries', dest='retries', type=int, + help='How often should each test be retried before it is ' + 'considered failed. Works around flakyness in the terminal ' + 'multiplexer and race conditions in writing to the file system.') + p.add_option('-x', '--exitfirst', dest='exitfirst', action='store_true', + help='exit instantly on first error or failed test.') + p.add_option('--vim', dest='vim', type=str, default='vim', + help='executable to run when launching vim.') + p.add_option('--interface', dest='interface', type=str, default='tmux', + help="Interface to use. Use 'tmux' with vanilla Vim and 'tmux_nvim' " + 'with Neovim.') + p.add_option('--python-host-prog', dest='python_host_prog', type=str, default='', + help='Neovim needs a variable to tell it which python interpretor to use for ' + 'py blocks. This needs to be set to point to the correct python interpretor. ' + 'It is ignored for vanilla Vim.') + p.add_option('--python3-host-prog', dest='python3_host_prog', type=str, default='', + help='See --python-host-prog.') + p.add_option('--expected-python-version', dest='expected_python_version', type=str, default='', + help='If set, each test will check sys.version inside of vim to ' + 'verify we are testing against the expected Python version.') + + o, args = p.parse_args() + return o, args + + def flatten_test_suite(suite): + flatten = unittest.TestSuite() + for test in suite: + if isinstance(test, unittest.TestSuite): + flatten.addTests(flatten_test_suite(test)) + else: + flatten.addTest(test) + return flatten + + def main(): + options, selected_tests = parse_args() + + all_test_suites = unittest.defaultTestLoader.discover(start_dir='test') + + vim = None + vim_flavor = 'vim' + if options.interface == 'tmux': + vim = VimInterfaceTmux(options.vim, options.session) + vim_flavor = 'vim' + else: + vim = VimInterfaceTmuxNeovim(options.vim, options.session) + vim_flavor = 'neovim' + + if not options.clone_plugins and platform.system() == 'Windows': + raise RuntimeError( + 'TODO: TestSuite is broken under windows. Volunteers wanted!.') + # vim = VimInterfaceWindows() + # vim.focus() + + all_other_plugins = set() + + tests = set() + suite = unittest.TestSuite() + + for test in flatten_test_suite(all_test_suites): + test.interrupt = options.interrupt + test.retries = options.retries + test.test_plugins = options.plugins + test.python_host_prog = options.python_host_prog + test.python3_host_prog = options.python3_host_prog + test.expected_python_version = options.expected_python_version + test.vim = vim + test.vim_flavor = vim_flavor + all_other_plugins.update(test.plugins) + + if len(selected_tests): + id = test.id().split('.')[1] + if not any([id.startswith(t) for t in selected_tests]): + continue + tests.add(test) + suite.addTests(tests) + + if options.plugins or options.clone_plugins: + setup_other_plugins(all_other_plugins) + if options.clone_plugins: + return + + v = 2 if options.verbose else 1 + successfull = unittest.TextTestRunner(verbosity=v, + failfast=options.exitfirst).run(suite).wasSuccessful() + return 0 if successfull else 1 + sys.exit(main()) + +# vim:fileencoding=utf-8:foldmarker={{{#,#}}}: diff --git a/vim/bundle/ultisnips/travis_install.sh b/vim/bundle/ultisnips/travis_install.sh new file mode 100755 index 0000000..d0db077 --- /dev/null +++ b/vim/bundle/ultisnips/travis_install.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +# Installs a known version of vim in the travis test runner. + +set -ex + +PYTHON="python${TRAVIS_PYTHON_VERSION}" + +build_vanilla_vim () { + mkdir ~/vim_build + pushd ~/vim_build + + if [[ $VIM_VERSION == "74" ]]; then + until curl ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2 -o vim.tar.bz2; do sleep 10; done + tar xjf vim.tar.bz2 + cd vim${VIM_VERSION} + elif [[ $VIM_VERSION == "mercurial" ]]; then + hg clone https://vim.googlecode.com/hg/ vim + cd vim + fi + + local PYTHON_CONFIG_DIR=$(dirname $(find $($PYTHON-config --prefix)/lib -iname 'config.c') | grep $TRAVIS_PYTHON_VERSION) + local PYTHON_BUILD_CONFIG="" + if [[ $TRAVIS_PYTHON_VERSION =~ ^2\. ]]; then + PYTHON_BUILD_CONFIG="--enable-pythoninterp --with-python-config-dir=${PYTHON_CONFIG_DIR}" + else + PYTHON_BUILD_CONFIG="--enable-python3interp --with-python3-config-dir=${PYTHON_CONFIG_DIR}" + fi + export LDFLAGS="$($PYTHON-config --ldflags) -L$($PYTHON-config --prefix)/lib" + export CFLAGS="$($PYTHON-config --cflags)" + + # This is needed so that vim finds the shared libraries it was build against + # - they are not on the regular path. + export LD_LIBRARY_PATH="$($PYTHON-config --prefix)/lib" + + echo $LDFLAGS + echo $CFLAGS + ./configure \ + --prefix=${HOME} \ + --disable-nls \ + --disable-sysmouse \ + --disable-gpm \ + --enable-gui=no \ + --enable-multibyte \ + --with-features=huge \ + --with-tlib=ncurses \ + --without-x \ + ${PYTHON_BUILD_CONFIG} || cat $(find . -name 'config.log') + + make install + popd + + rm -rf vim_build +} + +if [[ $VIM_VERSION = "74" || $VIM_VERSION = "mercurial" ]]; then + build_vanilla_vim +elif [[ $VIM_VERSION == "NEOVIM" ]]; then + PIP=$(which pip) + $PIP install neovim +else + echo "Unknown VIM_VERSION: $VIM_VERSION" + exit 1 +fi + +# Clone the dependent plugins we want to use. +PYTHON_CMD="$(which $PYTHON)" +$PYTHON_CMD ./test_all.py --clone-plugins diff --git a/vim/bundle/ultisnips/travis_test.sh b/vim/bundle/ultisnips/travis_test.sh new file mode 100755 index 0000000..1a6a24a --- /dev/null +++ b/vim/bundle/ultisnips/travis_test.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -ex + +PYTHON="python${TRAVIS_PYTHON_VERSION}" +PYTHON_CMD="$(which ${PYTHON})" + +if [[ $VIM_VERSION = "74" || $VIM_VERSION = "mercurial" ]]; then + INTERFACE="--interface tmux" + VIM="${HOME}/bin/vim" + # This is needed so that vim finds the shared libraries it was build against - + # they are not on the regular path. + export LD_LIBRARY_PATH="$($PYTHON-config --prefix)/lib" + +elif [[ $VIM_VERSION == "NEOVIM" ]]; then + VIM="$(which nvim)" + if [[ $TRAVIS_PYTHON_VERSION =~ ^2\. ]]; then + INTERFACE="--interface tmux_nvim --python-host-prog=$PYTHON_CMD" + else + INTERFACE="--interface tmux_nvim --python3-host-prog=$PYTHON_CMD" + fi +else + echo "Unknown VIM_VERSION: $VIM_VERSION" + exit 1 +fi + +PYTHON_VERSION=$($PYTHON_CMD -c 'import sys;print(sys.version.split()[0])') +echo "Using python from: $PYTHON_CMD Version: $PYTHON_VERSION" +echo "Using vim from: $VIM. Version: $($VIMn)" + +tmux new -d -s vim + +$PYTHON_CMD ./test_all.py \ + -v \ + --plugins \ + --session vim \ + --vim $VIM \ + $INTERFACE \ + --expected-python-version $PYTHON_VERSION diff --git a/vim/bundle/ultisnips/utils/convert_snipmate_snippets.py b/vim/bundle/ultisnips/utils/convert_snipmate_snippets.py deleted file mode 100755 index 2d31558..0000000 --- a/vim/bundle/ultisnips/utils/convert_snipmate_snippets.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 -""" -Convert snipmate compatible snippets to UltiSnips compatible snippets -by Phillip Berndt -""" -import sys -import re -import os -import argparse - -def convert_snippet_contents(content): - " If the snippet contains snipmate style substitutions, convert them to ultisnips style " - content = re.sub("`([^`]+`)", "`!v \g<1>", content) - return content - -def convert_snippet_file(source): - " One file per filetype " - retval = "" - state = 0 - for line in open(source).readlines(): - # Ignore empty lines - if line.strip() == "": - continue - # The rest of the handling is stateful - if state == 0: - # Find snippet start. Keep comments. - if line[:8] == "snippet ": - snippet_info = re.match("(\S+)\s*(.*)", line[8:]) - if not snippet_info: - print >> sys.stderr, "Warning: Malformed snippet\n %s\n" % line - continue - retval += 'snippet %s "%s"' % (snippet_info.group(1), snippet_info.group(2) if snippet_info.group(2) else snippet_info.group(1)) + "\n" - state = 1 - snippet = "" - elif line[:1] == "#": - retval += line - state = 0 - elif state == 1: - # First line of snippet: Get indentation - whitespace = re.search("^\s+", line) - if not whitespace: - print >> sys.stderr, "Warning: Malformed snippet, content not indented.\n" - retval += "endsnippet\n\n" - state = 0 - else: - whitespace = whitespace.group(0) - snippet += line[len(whitespace):] - state = 2 - elif state == 2: - # In snippet: If indentation level is the same, add to snippet. Else end snippet. - if line[:len(whitespace)] == whitespace: - snippet += line[len(whitespace):] - else: - retval += convert_snippet_contents(snippet) + "endsnippet\n\n" - #Copy-paste the section from state=0 so that we don't skip every other snippet - if line[:8] == "snippet ": - snippet_info = re.match("(\S+)\s*(.*)", line[8:]) - if not snippet_info: - print >> sys.stderr, "Warning: Malformed snippet\n %s\n" % line - continue - retval += 'snippet %s "%s"' % (snippet_info.group(1), snippet_info.group(2) if snippet_info.group(2) else snippet_info.group(1)) + "\n" - state = 1 - snippet = "" - elif line[:1] == "#": - retval += line - state = 0 - if state == 2: - retval += convert_snippet_contents(snippet) + "endsnippet\n\n" - return retval - -def convert_snippet(source): - " One file per snippet " - name = os.path.basename(source)[:-8] - return 'snippet %s "%s"' % (name, name) + "\n" + \ - convert_snippet_contents(open(source).read()) + \ - "\nendsnippet\n" - -def convert_snippets(source): - if os.path.isdir(source): - return "\n".join((convert_snippet(os.path.join(source, x)) for x in os.listdir(source) if x[-8:] == ".snippet")) - else: - return convert_snippet_file(source) - -if __name__ == '__main__': - # Parse command line - argsp = argparse.ArgumentParser(description="Convert snipmate compatible snippets to UltiSnips' file format", - epilog="example:\n %s drupal/ drupal.snippets\n will convert all drupal specific snippets from snipmate into one file drupal.snippets" % sys.argv[0], - formatter_class=argparse.RawDescriptionHelpFormatter) - argsp.add_argument("source", help="Source directory for one filetype or a snippets file") - argsp.add_argument("target", help="File to write the resulting snippets into. If omitted, the snippets will be written to stdout.", nargs="?", default="-") - args = argsp.parse_args() - - source_file_name = args.source - tmp_file_name = ''.join([args.target,'.tmp']) - try: - tmp = sys.stdout if args.target == "-" else open(tmp_file_name, "w") - except IOError: - print >> sys.stderr, "Error: Failed to open output file %s for writing" % tmp_file_name - sys.exit(1) - - snippets = convert_snippets(source_file_name) - print >> tmp, snippets - - if args.target != "-": - if os.access(args.target, os.F_OK): - os.remove(args.target) - os.rename(tmp_file_name, args.target) diff --git a/vim/bundle/ultisnips/utils/get_tm_snippets.py b/vim/bundle/ultisnips/utils/get_tm_snippets.py index 3684001..eb2481d 100755 --- a/vim/bundle/ultisnips/utils/get_tm_snippets.py +++ b/vim/bundle/ultisnips/utils/get_tm_snippets.py @@ -11,28 +11,37 @@ import glob _UNESCAPE = re.compile(ur'&\w+?;', re.UNICODE) + + def unescape(s): if s is None: - return "" + return '' + def fixup(m): ent = m.group(0)[1:-1] return unichr(htmlentitydefs.name2codepoint[ent]) try: - return _UNESCAPE.sub(fixup,s) + return _UNESCAPE.sub(fixup, s) except: - print "unescape failed: %s" % repr(s) + print 'unescape failed: %s' % repr(s) raise + class UnknownVariable(Exception): pass + class UnsupportedVariableExpression(Exception): pass + def replace_vars(m): - """ Replace vars in 'content' portion. + """Replace vars in 'content' portion. + :m: match object - :returns: string""" + :returns: string + + """ var = m.group(1) default = m.group(2) @@ -40,10 +49,10 @@ def replace_vars(m): raise UnsupportedVariableExpression(var) translate_vars = { - 'TM_PHP_OPEN_TAG_WITH_ECHO': 'g:UltiSnipsOpenTagWithEcho', - 'TM_PHP_OPEN_TAG': 'g:UltiSnipsOpenTag', - 'PHPDOC_AUTHOR': 'g:snips_author', - } + 'TM_PHP_OPEN_TAG_WITH_ECHO': 'g:UltiSnipsOpenTagWithEcho', + 'TM_PHP_OPEN_TAG': 'g:UltiSnipsOpenTag', + 'PHPDOC_AUTHOR': 'g:snips_author', + } # TODO: TM_SELECTED_TEXT/([\t ]*).*/$1/m if var in translate_vars: @@ -54,44 +63,48 @@ def replace_vars(m): return "`!v exists('%s') ? %s : '%s'`" % (newvar, newvar, default) + def parse_content(c): try: data = ElementTree.fromstring(c)[0] rv = {} - for k,v in zip(data[::2], data[1::2]): + for k, v in zip(data[::2], data[1::2]): rv[k.text] = unescape(v.text) - if re.search( r'\$\{\D', rv["content"] ): - rv["content"] = re.sub(r'\$\{([^\d}][^}:]*)(?::([^}]*))?\}', replace_vars, rv["content"]) + if re.search(r'\$\{\D', rv['content']): + rv['content'] = re.sub( + r'\$\{([^\d}][^}:]*)(?::([^}]*))?\}', + replace_vars, + rv['content']) return rv except (ExpatError, ElementTree.ParseError) as detail: - print " Syntax Error: %s" % (detail,) + print ' Syntax Error: %s' % (detail,) print c return None except UnknownVariable as detail: - print " Unknown variable: %s" % (detail,) + print ' Unknown variable: %s' % (detail,) return None except UnsupportedVariableExpression as detail: - print " Unsupported variable expression: %s" % (detail,) + print ' Unsupported variable expression: %s' % (detail,) return None + def fetch_snippets_from_svn(name): - base_url = "http://svn.textmate.org/trunk/Bundles/" + name + ".tmbundle/" - snippet_idx = base_url + "Snippets/" + base_url = 'http://svn.textmate.org/trunk/Bundles/' + name + '.tmbundle/' + snippet_idx = base_url + 'Snippets/' idx_list = urllib.urlopen(snippet_idx).read() - rv = [] - for link in re.findall("
  • (.*?)
  • ", idx_list): + for link in re.findall('
  • (.*?)
  • ', idx_list): m = re.match(r'(.*)
    ', link) link, name = m.groups() - if name == "..": + if name == '..': continue - name = unescape(name.rsplit('.', 1)[0]) # remove Extension + name = unescape(name.rsplit('.', 1)[0]) # remove Extension print "Fetching data for Snippet '%s'" % name content = urllib.urlopen(snippet_idx + link).read() @@ -101,12 +114,13 @@ def fetch_snippets_from_svn(name): return rv + def fetch_snippets_from_dir(path): - """ Fetch snippets from a given path""" + """Fetch snippets from a given path.""" rv = [] for filename in glob.glob(os.path.join(path, '*.tmSnippet')): - print "Reading file %s" % filename + print 'Reading file %s' % filename f = open(filename) content = f.read() @@ -116,20 +130,20 @@ def fetch_snippets_from_dir(path): rv.append((name, cont)) return rv + def write_snippets(snip_descr, f): for name, d in snip_descr: - if "tabTrigger" not in d: + if 'tabTrigger' not in d: continue - if "content" not in d or d["content"] is None: - print "SKIP: %s (no content)" % (d,) + if 'content' not in d or d['content'] is None: + print 'SKIP: %s (no content)' % (d,) continue - f.write('snippet %s "%s"\n' % (d["tabTrigger"], name)) - f.write(d["content"].encode("utf-8") + "\n") - f.write("endsnippet\n\n") - + f.write('snippet %s "%s"\n' % (d['tabTrigger'], name)) + f.write(d['content'].encode('utf-8') + '\n') + f.write('endsnippet\n\n') if __name__ == '__main__': @@ -144,5 +158,4 @@ if __name__ == '__main__': rv = fetch_snippets_from_svn(bundle) name = bundle.lower() - write_snippets(rv, open("tm_" + name + ".snippets","w")) - + write_snippets(rv, open('tm_' + name + '.snippets', 'w'))