add personal snippets
This commit is contained in:
parent
1e6db8f032
commit
46046fe90f
@ -3,6 +3,7 @@ call minpac#init()
|
|||||||
" minpac must have {'type': 'opt'} so that it can be loaded with `packadd`.
|
" minpac must have {'type': 'opt'} so that it can be loaded with `packadd`.
|
||||||
call minpac#add('k-takata/minpac', {'type': 'opt'})
|
call minpac#add('k-takata/minpac', {'type': 'opt'})
|
||||||
call minpac#add('honza/vim-snippets', {'type': 'start'})
|
call minpac#add('honza/vim-snippets', {'type': 'start'})
|
||||||
|
call minpac#add('SirVer/ultisnips')
|
||||||
call minpac#add('junegunn/limelight.vim')
|
call minpac#add('junegunn/limelight.vim')
|
||||||
call minpac#add('junegunn/goyo.vim')
|
call minpac#add('junegunn/goyo.vim')
|
||||||
call minpac#add('junegunn/fzf')
|
call minpac#add('junegunn/fzf')
|
||||||
@ -24,10 +25,14 @@ call minpac#add('tpope/vim-eunuch')
|
|||||||
command! PackUpdate call minpac#update()
|
command! PackUpdate call minpac#update()
|
||||||
command! PackClean call minpac#clean()
|
command! PackClean call minpac#clean()
|
||||||
|
|
||||||
|
let g:UltiSnipsSnippetDirectories=["UltiSnips", "mysnippets"]
|
||||||
let g:netrw_dirhistmax = 0
|
let g:netrw_dirhistmax = 0
|
||||||
let g:airline#extensions#tabline#enabled = 1
|
let g:airline#extensions#tabline#enabled = 1
|
||||||
let g:airline_powerline_fonts = 1
|
let g:airline_powerline_fonts = 1
|
||||||
let g:limelight_conceal_ctermfg = 'gray'
|
let g:limelight_conceal_ctermfg = 'gray'
|
||||||
|
let g:snips_author = 'Julien Rabier'
|
||||||
|
let g:name = 'Julien Rabier'
|
||||||
|
let g:nickname = 'taziden'
|
||||||
let mapleader=","
|
let mapleader=","
|
||||||
set backup
|
set backup
|
||||||
set backupdir=$HOME/.vim/backup
|
set backupdir=$HOME/.vim/backup
|
||||||
|
|||||||
259
private_dot_config/nvim/mysnippets/_.snippets
Normal file
259
private_dot_config/nvim/mysnippets/_.snippets
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
# Global snippets
|
||||||
|
|
||||||
|
snippet BUG
|
||||||
|
:BUG:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet DEBUG
|
||||||
|
:DEBUG:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet WARNING
|
||||||
|
:WARNING:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet TODO
|
||||||
|
:TODO:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet KLUDGE
|
||||||
|
:KLUDGE:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet COMMENT
|
||||||
|
:COMMENT:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet TRICKY
|
||||||
|
:TRICKY:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet DOC
|
||||||
|
:DOC:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
snippet EXPIRE
|
||||||
|
:EXPIRE:`g:nickname`:`strftime("%Y%m%d")`: ${1}
|
||||||
|
|
||||||
|
snippet c)
|
||||||
|
Copyright `&enc[:2] == "utf" ? "©" : "(c)"` `strftime("%Y")` ${1:`g:snips_author`}. All Rights Reserved.
|
||||||
|
snippet date
|
||||||
|
`strftime("%Y-%m-%d")`
|
||||||
|
snippet ddate
|
||||||
|
`strftime("%B %d, %Y")`
|
||||||
|
snippet time
|
||||||
|
`strftime("%H:%M")`
|
||||||
|
snippet datetime
|
||||||
|
`strftime("%Y-%m-%d %H:%M")`
|
||||||
|
snippet lorem
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||||
|
snippet GPL2
|
||||||
|
${1:One line to give the program's name and a brief description.}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
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, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet LGPL2
|
||||||
|
${1:One line to give the program's name and a brief description.}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This library 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet GPL3
|
||||||
|
${1:one line to give the program's name and a brief description.}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet LGPL3
|
||||||
|
${1:One line to give the program's name and a brief description.}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This library 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet BSD2
|
||||||
|
${1:one line to give the program's name and a brief description}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
The views and conclusions contained in the software and documentation
|
||||||
|
are those of the authors and should not be interpreted as representing
|
||||||
|
official policies, either expressedor implied, of $2.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet BSD3
|
||||||
|
${1:one line to give the program's name and a brief description}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. Neither the name of the ${3:organization} nor the
|
||||||
|
names of its contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet BSD4
|
||||||
|
${1:one line to give the program's name and a brief description}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this software
|
||||||
|
must display the following acknowledgement:
|
||||||
|
This product includes software developed by the ${3:organization}.
|
||||||
|
4. Neither the name of the $3 nor the
|
||||||
|
names of its contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet MIT
|
||||||
|
${1:one line to give the program's name and a brief description}
|
||||||
|
Copyright (C) `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||||
|
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet APACHE
|
||||||
|
${1:one line to give the program's name and a brief description}
|
||||||
|
Copyright `strftime("%Y")` ${2:copyright holder}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
${0}
|
||||||
|
snippet BEERWARE
|
||||||
|
${2:one line to give the program's name and a brief description}
|
||||||
|
Copyright `strftime("%Y")` ${3:copyright holder}
|
||||||
|
|
||||||
|
Licensed under the "THE BEER-WARE LICENSE" (Revision 42):
|
||||||
|
${1:`g:snips_author`} wrote this file. As long as you retain this notice you
|
||||||
|
can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
this stuff is worth it, you can buy me a beer or coffee in return
|
||||||
|
|
||||||
|
${0}
|
||||||
|
|
||||||
|
snippet WTFPL
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright `strftime("%Y")` ${0:copyright holder}
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
3
private_dot_config/nvim/mysnippets/all.snippets
Normal file
3
private_dot_config/nvim/mysnippets/all.snippets
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
snippet cdt
|
||||||
|
Cordialement,
|
||||||
|
endsnippet
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
# Contributing to UltiSnips
|
||||||
|
|
||||||
|
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||||
|
|
||||||
|
This document will take you through the process of making your change, testing it, documenting it and sending it for review.
|
||||||
|
No new feature will be accepted without good test coverage, passing CI and proper documentation.
|
||||||
|
|
||||||
|
## Before you add a feature
|
||||||
|
|
||||||
|
UltiSnips is so rich on features that it borders on feature creep.
|
||||||
|
It is also an understaffed and undermaintained project.
|
||||||
|
Since every feature needs to be maintained forever, we are very careful about new ones.
|
||||||
|
Please create alignment before putting too much work into a novel idea.
|
||||||
|
There are several ways of doing this:
|
||||||
|
|
||||||
|
1. Open an issue to discuss your idea.
|
||||||
|
2. Open a PR with a hackish or minimal implementation, i.e. no tests and no docs.
|
||||||
|
3. Write a short (<= 1 page) design doc in a Gist or on Google Docs.
|
||||||
|
|
||||||
|
Should there be agreement that your feature idea adds enough value to offset the maintenance burden, you can go ahead and implement it, including tests and documentation.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
UltiSnips has a rigorous test suite and every new feature or bug fix is expected to come with a new test.
|
||||||
|
The overwhelming number of the > 500 test cases are integration tests.
|
||||||
|
Each test case sets up a full on-disk Vim configuration, including `.vimrc`, plugins and snippet definitions.
|
||||||
|
We then simulate a user typing out a test case by programmatically sending keys into a [tmux](https://github.com/tmux/tmux/wiki) terminal that runs Vim.
|
||||||
|
|
||||||
|
A test is a Python class in the `test` directory.
|
||||||
|
Some simple examples are in [test_Expand.py](https://github.com/SirVer/ultisnips/blob/master/test/test_Expand.py).
|
||||||
|
Each class contains at least
|
||||||
|
|
||||||
|
- a `keys` property that defines the key strokes taken,
|
||||||
|
- a `wanted` golden string that defines the expected output of the snippet, and
|
||||||
|
- a `snippets` list that defines the snippet that are in scope for the test case.
|
||||||
|
|
||||||
|
Each test types out a given set of key strokes and compares the resulting text in the Vim buffer to `wanted`.
|
||||||
|
|
||||||
|
### Running the test suite.
|
||||||
|
|
||||||
|
The basic process of running the suite is simple:
|
||||||
|
|
||||||
|
1. open a terminal and start a new tmux session in the current directory named
|
||||||
|
vim: `tmux new -s vim`. Do not type anything into the tmux session.
|
||||||
|
2. In a second terminal, run `./test_all.py`.
|
||||||
|
|
||||||
|
To filter 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
|
||||||
|
|
||||||
|
Currently, the test suite only runs under Linux and Mac, not under Windows.
|
||||||
|
Contributions to make it work under Windows again would be very much appreciated.
|
||||||
|
|
||||||
|
|
||||||
|
#### Running using docker.
|
||||||
|
|
||||||
|
The problem with running tests on the system directly is that the user's environment can bleed into the test execution.
|
||||||
|
To avoid this problem, we strongly suggest running the tests inside of [Docker](https://www.docker.com/).
|
||||||
|
It is useful to think of Docker as a lightweight virtual machine, i.e. a way of running exactly the same OS and userland configuration on any machine.
|
||||||
|
|
||||||
|
UltiSnips comes with a [Makefile](https://github.com/SirVer/ultisnips/blob/master/Makefile) that makes the use of Docker easy.
|
||||||
|
First, build the image of the test environment (Vim 8.0, using Python 3):
|
||||||
|
|
||||||
|
$ make image_repro
|
||||||
|
|
||||||
|
Now we can launch the image in a container and run the tmux session for testing.
|
||||||
|
|
||||||
|
$ make repro
|
||||||
|
... now inside container
|
||||||
|
# tmux new -s vim
|
||||||
|
|
||||||
|
The container will have the current directory mounted under `/src/UltiSnips`.
|
||||||
|
This means all changes you make to UltiSnips' sources will directly be represented inside the container and therefore available for testing.
|
||||||
|
|
||||||
|
In a second terminal we'll use `docker run` to get another shell in the already running container.
|
||||||
|
In this shell we can then trigger the test execution:
|
||||||
|
|
||||||
|
$ make shell_in_repro
|
||||||
|
... now inside container
|
||||||
|
# ./test_all.py
|
||||||
|
|
||||||
|
## Documenting
|
||||||
|
|
||||||
|
User documentation goes into [`doc/UltiSnips.txt`](https://github.com/SirVer/ultisnips/blob/00_contributing/doc/UltiSnips.txt).
|
||||||
|
Developer documentation should go into this file.
|
||||||
|
|
||||||
|
# Reproducing Bugs
|
||||||
|
|
||||||
|
Reproducing bugs is the hardest part of getting them fixed.
|
||||||
|
UltiSnips is usually used in complex interaction with other software and plugins.
|
||||||
|
This makes reproducing issues even harder.
|
||||||
|
|
||||||
|
Here is a process of creating a minimal viable reproduction case for your particular problem.
|
||||||
|
Having this available in a bug report will increase the chances of your issue being fixed tremendously.
|
||||||
|
|
||||||
|
1. Install [Docker](https://docs.docker.com/install/). It is useful to think of Docker as a lightweight virtual machine, i.e. a way of running exactly the same OS and userland configuration on any machine.
|
||||||
|
2. Build the image using `make image_repro`.
|
||||||
|
3. Launch the image using `make repro`. This drops you into a shell where you can run `vim` to get to a vim instance configured for UltiSnips.
|
||||||
|
|
||||||
|
Now try to reproduce your issue.
|
||||||
|
Keep in mind that all your changes to the container are lost once you exit the shell.
|
||||||
|
You must edit the configuration outside the container and rebuild the image.
|
||||||
|
You can add snippets to `docker/snippets/`.
|
||||||
|
You can also copy more and more of your own `.vimrc` into `docker/docker_vimrc.vim` until your issue reproduces.
|
||||||
|
Whenever you have edited `snippets` or `docker_vimrc.vim` you need to rerun `make image_repo && make repro`.
|
||||||
|
|
||||||
|
Once you have a minimal complete repro case ready,
|
||||||
|
|
||||||
|
1. fork UltiSnips,
|
||||||
|
2. commit your changes to the Vim configuration into a branch,
|
||||||
|
3. push the branch,
|
||||||
|
4. link it in the issue.
|
||||||
674
private_dot_config/nvim/pack/minpac/start/ultisnips/COPYING.txt
Normal file
674
private_dot_config/nvim/pack/minpac/start/ultisnips/COPYING.txt
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||||
183
private_dot_config/nvim/pack/minpac/start/ultisnips/ChangeLog
Normal file
183
private_dot_config/nvim/pack/minpac/start/ultisnips/ChangeLog
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
version 3.2 (05-Nov-2019):
|
||||||
|
- This is the first release done again by @SirVer. And this is also posted
|
||||||
|
on vim.org again. `¯\_(ツ)_/¯`
|
||||||
|
- This is the last version to support Python 2.
|
||||||
|
- Syntax highlighting improvements: a new one for unite & tweaks to others.
|
||||||
|
- Support for transformations on multiple lines.
|
||||||
|
- Python interpolation got more powerful, for example tabstops can now be
|
||||||
|
modified in python interpolation, you can access the last changed
|
||||||
|
placeholder text and more.
|
||||||
|
- Support for deoplete.
|
||||||
|
- Snippet files are no longer watched for changes. This increases
|
||||||
|
performance, but also means that if you change your snippet files outside
|
||||||
|
of Vim, UltiSnips will not know about it. You need to run `:call
|
||||||
|
UltiSnips#RefreshSnippets()` or restart Vim.
|
||||||
|
- Text objects for selecting snippets in visual mode: iS, aS
|
||||||
|
|
||||||
|
version 3.1 (07-Dec-2015):
|
||||||
|
- 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.
|
||||||
|
- Various smaller bug fixes.
|
||||||
|
- New command to manually add a filetype to the list for the current
|
||||||
|
buffer. *:UltiSnipsAddFiletypes*
|
||||||
|
- New or improved snippets: all, snippets, haskell, bindzone, python, golang,
|
||||||
|
json, html, coffee, coffee_jasmine, javascript_jasmine, ruby, php,
|
||||||
|
markdown.
|
||||||
|
|
||||||
|
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 (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
|
||||||
|
behave more like Vim *UltiSnips-adding-snippets*
|
||||||
|
- Backwards incompatible change: Zero Tabstop is no longer removed in
|
||||||
|
nested snippets
|
||||||
|
- Support for ${VISUAL:default text} placeholder. *UltiSnips-visual-placeholder*
|
||||||
|
- Improved handling of utf-8 characters in files and snippet definitions.
|
||||||
|
- Full support for :py3. UltiSnips now works with python >= 2.6 or >= 3.2.
|
||||||
|
- New or improved snippets: python, all
|
||||||
|
|
||||||
|
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 (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*
|
||||||
|
- New parser implementation: A little faster, more flexible and less bugged.
|
||||||
|
|
||||||
|
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.
|
||||||
|
- Support for other directory names for snippets beside
|
||||||
|
"UltiSnips" *UltiSnips-snippet-search-path*
|
||||||
|
- Errors are now shown in a scratch window.
|
||||||
|
- Now fully supports Windows with python >= 2.6. UltiSnips should now work
|
||||||
|
on all systems that Vim runs on.
|
||||||
|
- a syntax file was added for snippets files with nice highlighting.
|
||||||
|
- snippets definition files now have the filetype 'snippets'. It used to be
|
||||||
|
'snippet'.
|
||||||
|
|
||||||
|
version 1.3 (14-Feb-2011):
|
||||||
|
- Erlang snippets (g0rdin)
|
||||||
|
- Other VimScripts can now define and immediately expand anonymous snippets
|
||||||
|
( *UltiSnips_Anon* ) (Ryan Wooden)
|
||||||
|
- Other VimScripts can now define new snippets via a function
|
||||||
|
( *UltiSnips_AddSnippet* ) (Ryan Wooden)
|
||||||
|
- New Snippets for eruby and rails (Ches Martin).
|
||||||
|
- A new Option 't' has been added to snippets that avoid expanding tabstops.
|
||||||
|
Be also more consistent with how indenting is handled. (Ryan Wooden)
|
||||||
|
- Added a ftplugin script for .snippets files. Syntax highlighting still
|
||||||
|
missing. (Rupa Deadwyler)
|
||||||
|
- Added UltiSnipsReset and UltiSnipsEdit (Idea by JCEB)
|
||||||
|
|
||||||
|
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*
|
||||||
|
- all shipped snippets are now fully compatible with UltiSnips
|
||||||
|
- added support for global snippets which enhance python interpolation even
|
||||||
|
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*
|
||||||
|
- 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 <c-tab>.
|
||||||
|
- 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.
|
||||||
|
- UltiSnips now adheres to expandtab and tabstop options of vim
|
||||||
|
|
||||||
|
version 1.1 (21-Jul-2009):
|
||||||
|
- Made triggers configurable. You can also use the same trigger for
|
||||||
|
expanding and tabbing. The TextMate configuration <tab> and <s-tab> is now
|
||||||
|
possible.
|
||||||
|
- Conditional Inserts can now be nested
|
||||||
|
- Added support for b option. This only considers a snippet at the beginning
|
||||||
|
of a line ( *UltiSnips-adding-snippets* )
|
||||||
|
- Added support for ! option. This overwrites previously defined snippets
|
||||||
|
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* )
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
ARG PYTHON_IMAGE
|
||||||
|
|
||||||
|
FROM python:${PYTHON_IMAGE}
|
||||||
|
|
||||||
|
ARG VIM_VERSION
|
||||||
|
|
||||||
|
COPY docker/install_packages.sh src/scripts/
|
||||||
|
RUN src/scripts/install_packages.sh
|
||||||
|
COPY docker/download_vim.sh src/scripts/
|
||||||
|
RUN src/scripts/download_vim.sh
|
||||||
|
COPY docker/build_vim.sh src/scripts/
|
||||||
|
RUN src/scripts/build_vim.sh
|
||||||
|
|
||||||
|
RUN pip install unidecode
|
||||||
|
|
||||||
|
COPY . /src/UltiSnips
|
||||||
|
WORKDIR /src/UltiSnips
|
||||||
|
|
||||||
|
RUN ./test_all.py --clone-plugins
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
ARG BASE_IMAGE
|
||||||
|
|
||||||
|
FROM ultisnips:${BASE_IMAGE}
|
||||||
|
|
||||||
|
RUN curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
|
||||||
|
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
||||||
|
|
||||||
|
ADD docker/docker_vimrc.vim /root/.vim/vimrc
|
||||||
|
RUN vim -c 'PlugInstall | qa'
|
||||||
|
|
||||||
|
ADD docker/snippets /root/.vim/UltiSnips
|
||||||
44
private_dot_config/nvim/pack/minpac/start/ultisnips/Makefile
Normal file
44
private_dot_config/nvim/pack/minpac/start/ultisnips/Makefile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||||
|
MAKEFILE_DIR := $(dir ${MAKEFILE_PATH})
|
||||||
|
|
||||||
|
# Test images as run on CI.
|
||||||
|
image_vim_74_py35:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.5-stretch --build-arg VIM_VERSION=7.4 .
|
||||||
|
image_vim_80_py35:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.5-stretch --build-arg VIM_VERSION=8.0 .
|
||||||
|
image_vim_81_py35:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.5-stretch --build-arg VIM_VERSION=8.1 .
|
||||||
|
image_vim_git_py35:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.5-stretch --build-arg VIM_VERSION=git .
|
||||||
|
image_vim_74_py36:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.6-stretch --build-arg VIM_VERSION=7.4 .
|
||||||
|
image_vim_80_py36:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.6-stretch --build-arg VIM_VERSION=8.0 .
|
||||||
|
image_vim_81_py36:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.6-stretch --build-arg VIM_VERSION=8.1 .
|
||||||
|
image_vim_git_py36:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.6-stretch --build-arg VIM_VERSION=git .
|
||||||
|
# 74 and 80 do not build with py37 and py38. The build errors out with "Require native threads".
|
||||||
|
image_vim_81_py37:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.7-stretch --build-arg VIM_VERSION=8.1 .
|
||||||
|
image_vim_git_py37:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.7-stretch --build-arg VIM_VERSION=git .
|
||||||
|
image_vim_81_py38:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.8-buster --build-arg VIM_VERSION=8.1 .
|
||||||
|
image_vim_git_py38:
|
||||||
|
docker build -t ultisnips:$@ --build-arg PYTHON_IMAGE=3.8-buster --build-arg VIM_VERSION=git .
|
||||||
|
|
||||||
|
image_repro: image_vim_80_py36
|
||||||
|
docker build -t ultisnips:repro --build-arg BASE_IMAGE=$< -f Dockerfile.repro .
|
||||||
|
|
||||||
|
# A reproduction image that drops you into a naked environment,
|
||||||
|
# with a Vim having UltiSnips and vim-snippets configured. See
|
||||||
|
# docker/docker_vimrc.vim for the full vimrc. Need to run `make
|
||||||
|
# image_repro` before this will work.
|
||||||
|
repro:
|
||||||
|
docker run -it -v ${MAKEFILE_DIR}:/src/UltiSnips ultisnips:repro /bin/bash
|
||||||
|
|
||||||
|
# This assumes, the repro image is already running and it opens an extra shell
|
||||||
|
# inside the running container
|
||||||
|
shell_in_repro:
|
||||||
|
docker exec -it $(shell docker ps -q) /bin/bash
|
||||||
19
private_dot_config/nvim/pack/minpac/start/ultisnips/Pipfile
Normal file
19
private_dot_config/nvim/pack/minpac/start/ultisnips/Pipfile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[[source]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
black = "*"
|
||||||
|
mypy = "*"
|
||||||
|
pylint = "*"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
mypy = "*"
|
||||||
|
black = "*"
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.7"
|
||||||
|
|
||||||
|
[pipenv]
|
||||||
|
allow_prereleases = true
|
||||||
344
private_dot_config/nvim/pack/minpac/start/ultisnips/Pipfile.lock
generated
Normal file
344
private_dot_config/nvim/pack/minpac/start/ultisnips/Pipfile.lock
generated
Normal file
@ -0,0 +1,344 @@
|
|||||||
|
{
|
||||||
|
"_meta": {
|
||||||
|
"hash": {
|
||||||
|
"sha256": "787a870117eb091d0b70464dda258a97ec6bb9841f3217b608caa94b08f767e2"
|
||||||
|
},
|
||||||
|
"pipfile-spec": 6,
|
||||||
|
"requires": {
|
||||||
|
"python_version": "3.7"
|
||||||
|
},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"name": "pypi",
|
||||||
|
"url": "https://pypi.org/simple",
|
||||||
|
"verify_ssl": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"appdirs": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92",
|
||||||
|
"sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"
|
||||||
|
],
|
||||||
|
"version": "==1.4.3"
|
||||||
|
},
|
||||||
|
"attrs": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
|
||||||
|
"sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"
|
||||||
|
],
|
||||||
|
"version": "==19.3.0"
|
||||||
|
},
|
||||||
|
"black": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b",
|
||||||
|
"sha256:c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==19.10b0"
|
||||||
|
},
|
||||||
|
"click": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
|
||||||
|
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
|
||||||
|
],
|
||||||
|
"version": "==7.0"
|
||||||
|
},
|
||||||
|
"mypy": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0308c35fd16c96a81b8dfc4d09ec63b8fa607cfec087acf5aafb44c2c45197de",
|
||||||
|
"sha256:39f7be2f89668d21b2bbab45ce5aa15e69bf8d6f3b46f9e1cc1a88e4fcc84f3d",
|
||||||
|
"sha256:4223f576813c79a10d0fd14192c86f1b85e3bd235c93792f22ed811a20b5ee4e",
|
||||||
|
"sha256:4c8f812a2fbefa96185933fbe05aa035e9cf791cf3a23bbdb6a219c80b60e0b1",
|
||||||
|
"sha256:4ea9ee847ea5bb38ea275441f3aea7eeba1b96187a3f968ee359d33d9dcc0eda",
|
||||||
|
"sha256:573c68df69f0e399fa57866a0b72989acf0a56c4008eee59c789c2ca5ea9df03",
|
||||||
|
"sha256:588c0e38466306aa7dbe6522ceacf37dde8b13cfa5edde90be2ce382f078875f",
|
||||||
|
"sha256:6d1bd2e675823a19e6bf72149540ab9851bfe698b796aea698fb926ab2bedd02",
|
||||||
|
"sha256:aa8e3bd1540dd5c39ef580ec2146a9c99c45f7c62af890095fec9e87b5ca19fb",
|
||||||
|
"sha256:b978ba1ea90d0abe2fc720ec9a41824b7d3a1304569bd58c9038d8d61dc4dfdb",
|
||||||
|
"sha256:c85c5367c2e8247e06cc0aba84e3633e90f48e8a0677bc51b351e138b5ff80b1",
|
||||||
|
"sha256:ce69577b424058bfa177df27213869f37c1e964c3e1ebd3b3d54f1d10b234c4d",
|
||||||
|
"sha256:ec6eaf98a57624d96d9916352a5bad2d73959f6358fabf43838f7d1a4d2f8389"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==0.760"
|
||||||
|
},
|
||||||
|
"mypy-extensions": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
|
||||||
|
"sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
|
||||||
|
],
|
||||||
|
"version": "==0.4.3"
|
||||||
|
},
|
||||||
|
"pathspec": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:e285ccc8b0785beadd4c18e5708b12bb8fcf529a1e61215b3feff1d1e559ea5c"
|
||||||
|
],
|
||||||
|
"version": "==0.6.0"
|
||||||
|
},
|
||||||
|
"regex": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0472acc4b6319801c1bc681d838c88ba1446f9ae199e01f6e41091c701fb3d42",
|
||||||
|
"sha256:16709434c4e2332ee8ba26ae339aceb8ab0b24b8398ebd0f52ebc943f45c4fc2",
|
||||||
|
"sha256:223fb63ec8dcab20b3318e93dcec4aee89e98b062934090bf29ffc374d2000a2",
|
||||||
|
"sha256:23c3ebf05d1cd3adb26723fd598e75724e0cdb7d6a35185ac0caf061cc6edb49",
|
||||||
|
"sha256:2404a50fb48badaf214b700f08822b68d93d79200e0aefd9569d0332d21fbfcb",
|
||||||
|
"sha256:2af3a7a16fed6eff85c25da106effa36f61cbbe801d00ade349b53ce7619eb15",
|
||||||
|
"sha256:37e018d3746baf159aedfc9773c3cafacbd10d354ba15484f5cfc8ed9da5748b",
|
||||||
|
"sha256:3c9c2988d02a9238a1975c70e87c6ce94e6f36dd8e372b66f468990cfe077434",
|
||||||
|
"sha256:47298bc8b89d1c747f0f5974aa528fc0b6b17396f1694136a224d51461279d83",
|
||||||
|
"sha256:4eeb0fe936797ae00a085f99802642bfc722b3b4ea557e9e7849cb621ea10c91",
|
||||||
|
"sha256:6881be0218b47ed76db033f252bab3f912dfe7ed1fe7baa9daebf51de08546a0",
|
||||||
|
"sha256:7ac08cee5055f548eed3889e9aaef15fd00172d037949496f1f0b34acb8a7c3e",
|
||||||
|
"sha256:7c5e2efcf079c35ff266c3f3a6708834f88f9fd04a3c16b855e036b2b7b1b543",
|
||||||
|
"sha256:8355eaa64724a0fdb010a1654b77cb3e375dc08b7f592cc4a1c05ac606aa481c",
|
||||||
|
"sha256:999a885f7f5194464238ad5d74b05982acee54002f3aa775d8e0e8c5fb74c06c",
|
||||||
|
"sha256:9fd2f4813eaa3e421e82819d38e5b634d900faff7ae5a80cd89ccff407175e69",
|
||||||
|
"sha256:a2e1e53df7dd27943da2b512895125b33fb20f81862c9fed7b3bab2a1de684d1",
|
||||||
|
"sha256:ab43bc0836820b7900dfffc025b996784aec26ec87dc1df4f95a40398760223f",
|
||||||
|
"sha256:ba449b56fa419fb19bf2a2438adbd2433f27087a6fe115917eaf9cfca684d5b6",
|
||||||
|
"sha256:d3f632cefad2cf247bd845794002585e3772288bfcb0dbac59fdecd32cd38b67",
|
||||||
|
"sha256:d51311496061863caae2cfe120cf1ef37900019b86c89c2d75f0918e0b4b8bf3"
|
||||||
|
],
|
||||||
|
"version": "==2019.12.19"
|
||||||
|
},
|
||||||
|
"toml": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c",
|
||||||
|
"sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"
|
||||||
|
],
|
||||||
|
"version": "==0.10.0"
|
||||||
|
},
|
||||||
|
"typed-ast": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161",
|
||||||
|
"sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e",
|
||||||
|
"sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e",
|
||||||
|
"sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0",
|
||||||
|
"sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c",
|
||||||
|
"sha256:48e5b1e71f25cfdef98b013263a88d7145879fbb2d5185f2a0c79fa7ebbeae47",
|
||||||
|
"sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631",
|
||||||
|
"sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4",
|
||||||
|
"sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34",
|
||||||
|
"sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b",
|
||||||
|
"sha256:7954560051331d003b4e2b3eb822d9dd2e376fa4f6d98fee32f452f52dd6ebb2",
|
||||||
|
"sha256:838997f4310012cf2e1ad3803bce2f3402e9ffb71ded61b5ee22617b3a7f6b6e",
|
||||||
|
"sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a",
|
||||||
|
"sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233",
|
||||||
|
"sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1",
|
||||||
|
"sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36",
|
||||||
|
"sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d",
|
||||||
|
"sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a",
|
||||||
|
"sha256:fdc1c9bbf79510b76408840e009ed65958feba92a88833cdceecff93ae8fff66",
|
||||||
|
"sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12"
|
||||||
|
],
|
||||||
|
"version": "==1.4.0"
|
||||||
|
},
|
||||||
|
"typing-extensions": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:091ecc894d5e908ac75209f10d5b4f118fbdb2eb1ede6a63544054bb1edb41f2",
|
||||||
|
"sha256:910f4656f54de5993ad9304959ce9bb903f90aadc7c67a0bef07e678014e892d",
|
||||||
|
"sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575"
|
||||||
|
],
|
||||||
|
"version": "==3.7.4.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"develop": {
|
||||||
|
"appdirs": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92",
|
||||||
|
"sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"
|
||||||
|
],
|
||||||
|
"version": "==1.4.3"
|
||||||
|
},
|
||||||
|
"astroid": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:71ea07f44df9568a75d0f354c49143a4575d90645e9fead6dfb52c26a85ed13a",
|
||||||
|
"sha256:840947ebfa8b58f318d42301cf8c0a20fd794a33b61cc4638e28e9e61ba32f42"
|
||||||
|
],
|
||||||
|
"version": "==2.3.3"
|
||||||
|
},
|
||||||
|
"attrs": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
|
||||||
|
"sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"
|
||||||
|
],
|
||||||
|
"version": "==19.3.0"
|
||||||
|
},
|
||||||
|
"black": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b",
|
||||||
|
"sha256:c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==19.10b0"
|
||||||
|
},
|
||||||
|
"click": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
|
||||||
|
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
|
||||||
|
],
|
||||||
|
"version": "==7.0"
|
||||||
|
},
|
||||||
|
"isort": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1",
|
||||||
|
"sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"
|
||||||
|
],
|
||||||
|
"version": "==4.3.21"
|
||||||
|
},
|
||||||
|
"lazy-object-proxy": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d",
|
||||||
|
"sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449",
|
||||||
|
"sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08",
|
||||||
|
"sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a",
|
||||||
|
"sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50",
|
||||||
|
"sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd",
|
||||||
|
"sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239",
|
||||||
|
"sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb",
|
||||||
|
"sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea",
|
||||||
|
"sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e",
|
||||||
|
"sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156",
|
||||||
|
"sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142",
|
||||||
|
"sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442",
|
||||||
|
"sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62",
|
||||||
|
"sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db",
|
||||||
|
"sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531",
|
||||||
|
"sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383",
|
||||||
|
"sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a",
|
||||||
|
"sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357",
|
||||||
|
"sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4",
|
||||||
|
"sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"
|
||||||
|
],
|
||||||
|
"version": "==1.4.3"
|
||||||
|
},
|
||||||
|
"mccabe": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
|
||||||
|
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
|
||||||
|
],
|
||||||
|
"version": "==0.6.1"
|
||||||
|
},
|
||||||
|
"mypy": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0308c35fd16c96a81b8dfc4d09ec63b8fa607cfec087acf5aafb44c2c45197de",
|
||||||
|
"sha256:39f7be2f89668d21b2bbab45ce5aa15e69bf8d6f3b46f9e1cc1a88e4fcc84f3d",
|
||||||
|
"sha256:4223f576813c79a10d0fd14192c86f1b85e3bd235c93792f22ed811a20b5ee4e",
|
||||||
|
"sha256:4c8f812a2fbefa96185933fbe05aa035e9cf791cf3a23bbdb6a219c80b60e0b1",
|
||||||
|
"sha256:4ea9ee847ea5bb38ea275441f3aea7eeba1b96187a3f968ee359d33d9dcc0eda",
|
||||||
|
"sha256:573c68df69f0e399fa57866a0b72989acf0a56c4008eee59c789c2ca5ea9df03",
|
||||||
|
"sha256:588c0e38466306aa7dbe6522ceacf37dde8b13cfa5edde90be2ce382f078875f",
|
||||||
|
"sha256:6d1bd2e675823a19e6bf72149540ab9851bfe698b796aea698fb926ab2bedd02",
|
||||||
|
"sha256:aa8e3bd1540dd5c39ef580ec2146a9c99c45f7c62af890095fec9e87b5ca19fb",
|
||||||
|
"sha256:b978ba1ea90d0abe2fc720ec9a41824b7d3a1304569bd58c9038d8d61dc4dfdb",
|
||||||
|
"sha256:c85c5367c2e8247e06cc0aba84e3633e90f48e8a0677bc51b351e138b5ff80b1",
|
||||||
|
"sha256:ce69577b424058bfa177df27213869f37c1e964c3e1ebd3b3d54f1d10b234c4d",
|
||||||
|
"sha256:ec6eaf98a57624d96d9916352a5bad2d73959f6358fabf43838f7d1a4d2f8389"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==0.760"
|
||||||
|
},
|
||||||
|
"mypy-extensions": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
|
||||||
|
"sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
|
||||||
|
],
|
||||||
|
"version": "==0.4.3"
|
||||||
|
},
|
||||||
|
"pathspec": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:e285ccc8b0785beadd4c18e5708b12bb8fcf529a1e61215b3feff1d1e559ea5c"
|
||||||
|
],
|
||||||
|
"version": "==0.6.0"
|
||||||
|
},
|
||||||
|
"pylint": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:3db5468ad013380e987410a8d6956226963aed94ecb5f9d3a28acca6d9ac36cd",
|
||||||
|
"sha256:886e6afc935ea2590b462664b161ca9a5e40168ea99e5300935f6591ad467df4"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2.4.4"
|
||||||
|
},
|
||||||
|
"regex": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0472acc4b6319801c1bc681d838c88ba1446f9ae199e01f6e41091c701fb3d42",
|
||||||
|
"sha256:16709434c4e2332ee8ba26ae339aceb8ab0b24b8398ebd0f52ebc943f45c4fc2",
|
||||||
|
"sha256:223fb63ec8dcab20b3318e93dcec4aee89e98b062934090bf29ffc374d2000a2",
|
||||||
|
"sha256:23c3ebf05d1cd3adb26723fd598e75724e0cdb7d6a35185ac0caf061cc6edb49",
|
||||||
|
"sha256:2404a50fb48badaf214b700f08822b68d93d79200e0aefd9569d0332d21fbfcb",
|
||||||
|
"sha256:2af3a7a16fed6eff85c25da106effa36f61cbbe801d00ade349b53ce7619eb15",
|
||||||
|
"sha256:37e018d3746baf159aedfc9773c3cafacbd10d354ba15484f5cfc8ed9da5748b",
|
||||||
|
"sha256:3c9c2988d02a9238a1975c70e87c6ce94e6f36dd8e372b66f468990cfe077434",
|
||||||
|
"sha256:47298bc8b89d1c747f0f5974aa528fc0b6b17396f1694136a224d51461279d83",
|
||||||
|
"sha256:4eeb0fe936797ae00a085f99802642bfc722b3b4ea557e9e7849cb621ea10c91",
|
||||||
|
"sha256:6881be0218b47ed76db033f252bab3f912dfe7ed1fe7baa9daebf51de08546a0",
|
||||||
|
"sha256:7ac08cee5055f548eed3889e9aaef15fd00172d037949496f1f0b34acb8a7c3e",
|
||||||
|
"sha256:7c5e2efcf079c35ff266c3f3a6708834f88f9fd04a3c16b855e036b2b7b1b543",
|
||||||
|
"sha256:8355eaa64724a0fdb010a1654b77cb3e375dc08b7f592cc4a1c05ac606aa481c",
|
||||||
|
"sha256:999a885f7f5194464238ad5d74b05982acee54002f3aa775d8e0e8c5fb74c06c",
|
||||||
|
"sha256:9fd2f4813eaa3e421e82819d38e5b634d900faff7ae5a80cd89ccff407175e69",
|
||||||
|
"sha256:a2e1e53df7dd27943da2b512895125b33fb20f81862c9fed7b3bab2a1de684d1",
|
||||||
|
"sha256:ab43bc0836820b7900dfffc025b996784aec26ec87dc1df4f95a40398760223f",
|
||||||
|
"sha256:ba449b56fa419fb19bf2a2438adbd2433f27087a6fe115917eaf9cfca684d5b6",
|
||||||
|
"sha256:d3f632cefad2cf247bd845794002585e3772288bfcb0dbac59fdecd32cd38b67",
|
||||||
|
"sha256:d51311496061863caae2cfe120cf1ef37900019b86c89c2d75f0918e0b4b8bf3"
|
||||||
|
],
|
||||||
|
"version": "==2019.12.19"
|
||||||
|
},
|
||||||
|
"six": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd",
|
||||||
|
"sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"
|
||||||
|
],
|
||||||
|
"version": "==1.13.0"
|
||||||
|
},
|
||||||
|
"toml": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c",
|
||||||
|
"sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"
|
||||||
|
],
|
||||||
|
"version": "==0.10.0"
|
||||||
|
},
|
||||||
|
"typed-ast": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161",
|
||||||
|
"sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e",
|
||||||
|
"sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e",
|
||||||
|
"sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0",
|
||||||
|
"sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c",
|
||||||
|
"sha256:48e5b1e71f25cfdef98b013263a88d7145879fbb2d5185f2a0c79fa7ebbeae47",
|
||||||
|
"sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631",
|
||||||
|
"sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4",
|
||||||
|
"sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34",
|
||||||
|
"sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b",
|
||||||
|
"sha256:7954560051331d003b4e2b3eb822d9dd2e376fa4f6d98fee32f452f52dd6ebb2",
|
||||||
|
"sha256:838997f4310012cf2e1ad3803bce2f3402e9ffb71ded61b5ee22617b3a7f6b6e",
|
||||||
|
"sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a",
|
||||||
|
"sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233",
|
||||||
|
"sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1",
|
||||||
|
"sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36",
|
||||||
|
"sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d",
|
||||||
|
"sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a",
|
||||||
|
"sha256:fdc1c9bbf79510b76408840e009ed65958feba92a88833cdceecff93ae8fff66",
|
||||||
|
"sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12"
|
||||||
|
],
|
||||||
|
"version": "==1.4.0"
|
||||||
|
},
|
||||||
|
"typing-extensions": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:091ecc894d5e908ac75209f10d5b4f118fbdb2eb1ede6a63544054bb1edb41f2",
|
||||||
|
"sha256:910f4656f54de5993ad9304959ce9bb903f90aadc7c67a0bef07e678014e892d",
|
||||||
|
"sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575"
|
||||||
|
],
|
||||||
|
"version": "==3.7.4.1"
|
||||||
|
},
|
||||||
|
"wrapt": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1"
|
||||||
|
],
|
||||||
|
"version": "==1.11.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
[](https://travis-ci.org/SirVer/ultisnips)
|
||||||
|
[](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 many features,
|
||||||
|
speed being one of them.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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 [deoplete](https://github.com/Shougo/deoplete.nvim). 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 <https://github.com/sirver/ultisnips>.
|
||||||
|
Please add pull requests and issues there.
|
||||||
|
|
||||||
|
UltiSnips was started in Jun 2009 by @SirVer. In Dec 2015, maintenance was
|
||||||
|
handed over to [@seletskiy](https://github.com/seletskiy) who ran out of time
|
||||||
|
in early 2017. Since Jun 2019, @SirVer is maintaining UltiSnips again on a
|
||||||
|
very constraint time budget. If you can help triaging issues it would be
|
||||||
|
greatly appreciated.
|
||||||
|
|
||||||
|
|
||||||
|
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 <tab> if you use https://github.com/Valloric/YouCompleteMe.
|
||||||
|
let g:UltiSnipsExpandTrigger="<tab>"
|
||||||
|
let g:UltiSnipsJumpForwardTrigger="<c-b>"
|
||||||
|
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
|
||||||
|
|
||||||
|
" 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.
|
||||||
|
|
||||||
|
There are example uses for some power user features here:
|
||||||
|
|
||||||
|
* [Snippets Aliases](doc/examples/snippets-aliasing/README.md)
|
||||||
|
* [Dynamic Tabstops/Tabstop Generation](doc/examples/tabstop-generation/README.md)
|
||||||
|
|
||||||
|
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/)
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
" Called after everything else to reclaim keys (Needed for Supertab)
|
||||||
|
|
||||||
|
if exists("b:did_after_plugin_ultisnips_after")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_after_plugin_ultisnips_after = 1
|
||||||
|
|
||||||
|
call UltiSnips#map_keys#MapKeys()
|
||||||
@ -0,0 +1,158 @@
|
|||||||
|
if exists("b:did_autoload_ultisnips")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_autoload_ultisnips = 1
|
||||||
|
|
||||||
|
" Also import vim as we expect it to be imported in many places.
|
||||||
|
py3 import vim
|
||||||
|
py3 from UltiSnips import UltiSnips_Manager
|
||||||
|
|
||||||
|
function! s:compensate_for_pum() abort
|
||||||
|
""" 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
|
||||||
|
""" to explicitly check for the presence of the popup menu, and update
|
||||||
|
""" the vim-state accordingly.
|
||||||
|
if pumvisible()
|
||||||
|
py3 UltiSnips_Manager._cursor_moved()
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#Edit(bang, ...) abort
|
||||||
|
if a:0 == 1 && a:1 != ''
|
||||||
|
let type = a:1
|
||||||
|
else
|
||||||
|
let type = ""
|
||||||
|
endif
|
||||||
|
py3 vim.command("let file = '%s'" % UltiSnips_Manager._file_to_edit(vim.eval("type"), vim.eval('a:bang')))
|
||||||
|
|
||||||
|
if !len(file)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let mode = 'e'
|
||||||
|
if exists('g:UltiSnipsEditSplit')
|
||||||
|
if g:UltiSnipsEditSplit == 'vertical'
|
||||||
|
let mode = 'vs'
|
||||||
|
elseif g:UltiSnipsEditSplit == 'horizontal'
|
||||||
|
let mode = 'sp'
|
||||||
|
elseif g:UltiSnipsEditSplit == 'tabdo'
|
||||||
|
let mode = 'tabedit'
|
||||||
|
elseif g:UltiSnipsEditSplit == 'context'
|
||||||
|
let mode = 'vs'
|
||||||
|
if winwidth(0) <= 2 * (&tw ? &tw : 80)
|
||||||
|
let mode = 'sp'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
exe ':'.mode.' '.escape(file, ' ')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#AddFiletypes(filetypes) abort
|
||||||
|
py3 UltiSnips_Manager.add_buffer_filetypes(vim.eval("a:filetypes"))
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#FileTypeComplete(arglead, cmdline, cursorpos) abort
|
||||||
|
let ret = {}
|
||||||
|
let items = map(
|
||||||
|
\ split(globpath(&runtimepath, 'syntax/*.vim'), '\n'),
|
||||||
|
\ 'fnamemodify(v:val, ":t:r")'
|
||||||
|
\ )
|
||||||
|
call insert(items, 'all')
|
||||||
|
for item in items
|
||||||
|
if !has_key(ret, item) && item =~ '^'.a:arglead
|
||||||
|
let ret[item] = 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return sort(keys(ret))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#ExpandSnippet() abort
|
||||||
|
py3 UltiSnips_Manager.expand()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#ExpandSnippetOrJump() abort
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
py3 UltiSnips_Manager.expand_or_jump()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#ListSnippets() abort
|
||||||
|
py3 UltiSnips_Manager.list_snippets()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#SnippetsInCurrentScope(...) abort
|
||||||
|
let g:current_ulti_dict = {}
|
||||||
|
let all = get(a:, 1, 0)
|
||||||
|
if all
|
||||||
|
let g:current_ulti_dict_info = {}
|
||||||
|
endif
|
||||||
|
py3 UltiSnips_Manager.snippets_in_current_scope(int(vim.eval("all")))
|
||||||
|
return g:current_ulti_dict
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#SaveLastVisualSelection() range abort
|
||||||
|
py3 UltiSnips_Manager._save_last_visual_selection()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#JumpBackwards() abort
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
py3 UltiSnips_Manager.jump_backwards()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#JumpForwards() abort
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
py3 UltiSnips_Manager.jump_forwards()
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#AddSnippetWithPriority(trigger, value, description, options, filetype, priority) abort
|
||||||
|
py3 trigger = vim.eval("a:trigger")
|
||||||
|
py3 value = vim.eval("a:value")
|
||||||
|
py3 description = vim.eval("a:description")
|
||||||
|
py3 options = vim.eval("a:options")
|
||||||
|
py3 filetype = vim.eval("a:filetype")
|
||||||
|
py3 priority = vim.eval("a:priority")
|
||||||
|
py3 UltiSnips_Manager.add_snippet(trigger, value, description, options, filetype, priority)
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#Anon(value, ...) abort
|
||||||
|
" Takes the same arguments as SnippetManager.expand_anon:
|
||||||
|
" (value, trigger="", description="", options="")
|
||||||
|
py3 args = vim.eval("a:000")
|
||||||
|
py3 value = vim.eval("a:value")
|
||||||
|
py3 UltiSnips_Manager.expand_anon(value, *args)
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#CursorMoved() abort
|
||||||
|
py3 UltiSnips_Manager._cursor_moved()
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#LeavingBuffer() abort
|
||||||
|
let from_preview = getwinvar(winnr('#'), '&previewwindow')
|
||||||
|
let to_preview = getwinvar(winnr(), '&previewwindow')
|
||||||
|
|
||||||
|
if !(from_preview || to_preview)
|
||||||
|
py3 UltiSnips_Manager._leaving_buffer()
|
||||||
|
endif
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#LeavingInsertMode() abort
|
||||||
|
py3 UltiSnips_Manager._leaving_insert_mode()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#TrackChange() abort
|
||||||
|
py3 UltiSnips_Manager._track_change()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#RefreshSnippets() abort
|
||||||
|
py3 UltiSnips_Manager._refresh_snippets()
|
||||||
|
endfunction
|
||||||
|
" }}}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
if exists("b:did_autoload_ultisnips_map_keys")
|
||||||
|
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 = "<tab>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The trigger used to display all triggers that could possible
|
||||||
|
" match in the current position. Use empty to disable.
|
||||||
|
if !exists("g:UltiSnipsListSnippets")
|
||||||
|
let g:UltiSnipsListSnippets = "<c-tab>"
|
||||||
|
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 = "<c-j>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The trigger to jump backward inside a snippet
|
||||||
|
if !exists("g:UltiSnipsJumpBackwardTrigger")
|
||||||
|
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
|
||||||
|
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
|
||||||
|
" "tabdo", "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() abort
|
||||||
|
if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippetOrJump()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips#ExpandSnippetOrJump()<cr>"
|
||||||
|
else
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippet()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips#ExpandSnippet()<cr>"
|
||||||
|
endif
|
||||||
|
exec "xnoremap <silent> " . g:UltiSnipsExpandTrigger. " :call UltiSnips#SaveLastVisualSelection()<cr>gvs"
|
||||||
|
if len(g:UltiSnipsListSnippets) > 0
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsListSnippets . " <C-R>=UltiSnips#ListSnippets()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsListSnippets . " <Esc>:call UltiSnips#ListSnippets()<cr>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
snoremap <silent> <BS> <c-g>"_c
|
||||||
|
snoremap <silent> <DEL> <c-g>"_c
|
||||||
|
snoremap <silent> <c-h> <c-g>"_c
|
||||||
|
snoremap <c-r> <c-g>"_c<c-r>
|
||||||
|
endf
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
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) abort
|
||||||
|
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,
|
||||||
|
\ 'kind' : 'snippet'
|
||||||
|
\ })
|
||||||
|
endfor
|
||||||
|
return suggestions
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! neocomplete#sources#ultisnips#define() abort
|
||||||
|
return s:source
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
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) abort
|
||||||
|
" 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) abort
|
||||||
|
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) abort
|
||||||
|
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) abort
|
||||||
|
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]
|
||||||
|
let curr_val['kind'] = 'snippet'
|
||||||
|
call add(canditates, curr_val)
|
||||||
|
endfor
|
||||||
|
return canditates
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! unite#sources#ultisnips#define() abort
|
||||||
|
return s:unite_source
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
"unlet s:unite_source
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
--langdef=UltiSnips
|
||||||
|
--langmap=UltiSnips:.snippets
|
||||||
|
--regex-UltiSnips=/^snippet (.*)/\1/s,snippet/
|
||||||
File diff suppressed because it is too large
Load Diff
BIN
private_dot_config/nvim/pack/minpac/start/ultisnips/doc/demo.gif
Normal file
BIN
private_dot_config/nvim/pack/minpac/start/ultisnips/doc/demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
@ -0,0 +1,66 @@
|
|||||||
|
# Autojump from tabstop when it's empty
|
||||||
|
|
||||||
|
UltiSnips offers enough API to support automatic jump from one tabstop to
|
||||||
|
another when some condition is encountered.
|
||||||
|
|
||||||
|
One example of applying that behaviour is jump on the next placeholder when
|
||||||
|
current becomes empty when user types `<BS>` or another erase sequence when
|
||||||
|
tabstop is active.
|
||||||
|
|
||||||
|
Let's imagine, that we have following snippet:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
First placeholder, surrounded by braces, can be erased by user, but then
|
||||||
|
surrounding quotes will left untouched, and user should remove quotes and
|
||||||
|
one space, and only then jump to next placeholder, that equals to **5** total
|
||||||
|
keypresses: <kbd>BackSpace</kbd> (erase placeholder), <kbd>BackSpace</kbd> and
|
||||||
|
<kbd>Delete</kbd> (erase braces), <kbd>Delete</kbd> (erase space),
|
||||||
|
<kbd>Ctrl+J</kbd> (jump to next placeholder).
|
||||||
|
|
||||||
|
However, with UltiSnips, it can be done via only one keypress:
|
||||||
|
<kbd>BackSpace</kbd>:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
This example uses the [vim-pythonx library](https://github.com/reconquest/vim-pythonx/blob/master/pythonx/px/snippets.py) which provides set of functions to make coding little bit easier.
|
||||||
|
|
||||||
|
```
|
||||||
|
global !p
|
||||||
|
import px.snippets
|
||||||
|
endglobal
|
||||||
|
|
||||||
|
global !p
|
||||||
|
# This function will jump to next placeholder when first is empty.
|
||||||
|
def jump_to_second_when_first_is_empty(snip):
|
||||||
|
if px.snippets.get_jumper_position(snip) == 1:
|
||||||
|
if not px.snippets.get_jumper_text(snip):
|
||||||
|
px.snippets.advance_jumper(snip)
|
||||||
|
|
||||||
|
# This function will clean up first placeholder when this is empty.
|
||||||
|
def clean_first_placeholder(snip):
|
||||||
|
# Jumper is a helper for performing jumps in UltiSnips.
|
||||||
|
px.snippets.make_jumper(snip)
|
||||||
|
|
||||||
|
if snip.tabstop == 2 and not get_jumper_text(snip):
|
||||||
|
line = snip.buffer[snip.cursor[0]]
|
||||||
|
snip.buffer[snip.cursor[0]] = \
|
||||||
|
line[:snip.tabstops[1].start[1]-2] + \
|
||||||
|
line[snip.tabstops[1].end[1]+1:]
|
||||||
|
snip.cursor.set(
|
||||||
|
snip.cursor[0],
|
||||||
|
snip.cursor[1] - 3,
|
||||||
|
)
|
||||||
|
endglobal
|
||||||
|
|
||||||
|
context "px.snippets.make_context(snip)"
|
||||||
|
post_jump "clean_first_placeholder(snip)"
|
||||||
|
snippet x "Description" b
|
||||||
|
`!p jump_to_second_when_first_is_empty(snip)
|
||||||
|
`func (${1:blah}) $2() {
|
||||||
|
$3
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
```
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 97 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 223 KiB |
@ -0,0 +1,54 @@
|
|||||||
|
# Aliases for snippets
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
These examples use thes [vim-pythonx library](https://github.com/reconquest/vim-pythonx/blob/master/pythonx/px/snippets.py) which provides set of functions to make coding little bit easier.
|
||||||
|
|
||||||
|
Let's imagine we're editing a shell file and we need to debug some state.
|
||||||
|
|
||||||
|
We will probably end up with a snippet that will automatically insert the location of the debug statement, the variable name and its content:
|
||||||
|
|
||||||
|
```
|
||||||
|
global !p
|
||||||
|
import px.snippets
|
||||||
|
endglobal
|
||||||
|
|
||||||
|
snippet pr "print debug" bw
|
||||||
|
`!p
|
||||||
|
prefix = t[1] + ": %q\\n' "
|
||||||
|
prefix = "{}:{}: {}".format(
|
||||||
|
os.path.basename(px.buffer.get().name),
|
||||||
|
str(px.cursor.get()[0]),
|
||||||
|
prefix
|
||||||
|
)
|
||||||
|
`printf 'XXXXXX `!p snip.rv=prefix`$1 >&2
|
||||||
|
endsnippet
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, we want to use same debug snippet, but dump output to a file.
|
||||||
|
How can we do it?
|
||||||
|
|
||||||
|
Simple, declare new snippet in that way:
|
||||||
|
|
||||||
|
```
|
||||||
|
post_jump "px.snippets.expand(snip)"
|
||||||
|
snippet pd "Description" b
|
||||||
|
pr$1 >${2:/tmp/debug}
|
||||||
|
endsnippet
|
||||||
|
```
|
||||||
|
|
||||||
|
This snippet will expand the `pr` snippet automatically (note `pr$1` part) after
|
||||||
|
jumping to the first placeholder (jump will be done automatically by UltiSnips
|
||||||
|
engine).
|
||||||
|
|
||||||
|
`px.snippets.expand(snip)` is declared in that way:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def expand(snip, jump_pos=1):
|
||||||
|
if snip.tabstop != jump_pos:
|
||||||
|
return
|
||||||
|
|
||||||
|
vim.eval('feedkeys("\<C-R>=UltiSnips#ExpandSnippet()\<CR>")')
|
||||||
|
```
|
||||||
|
|
||||||
|
`px.buffer.get()` and `px.cursor.get()` are simple helpers for the `vim.current.window.buffer` and `vim.current.window.cursor`.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
@ -0,0 +1,50 @@
|
|||||||
|
# Dynamic tabstop generation
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
UltiSnips at the present day is more than snippet engine. It's more like
|
||||||
|
constructor, where you can implement some complex features without prior
|
||||||
|
feature implementation in the snippet by itself.
|
||||||
|
|
||||||
|
One of that features is dynamic tabstop generation.
|
||||||
|
|
||||||
|
Consider case, where you want set of snippets for inserting latex rows of
|
||||||
|
various lengths. No-brainer solution is just implement snippet for every
|
||||||
|
row length you're possible will want, like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
snippet tr9 "LaTeX table row of length nine"
|
||||||
|
$1 & $2 & $3 & $4 & $5 & $6 & $7 & $8 & $9
|
||||||
|
endsnippet
|
||||||
|
```
|
||||||
|
|
||||||
|
But soon it becomes a burden to maintain that kind of snippets.
|
||||||
|
|
||||||
|
Gladly, tabstops can be generated by using anonymous snippet expansion:
|
||||||
|
|
||||||
|
```
|
||||||
|
global !p
|
||||||
|
def create_row_placeholders(snip):
|
||||||
|
# retrieving singlee line from current string and treat it like tabstops
|
||||||
|
# count
|
||||||
|
placeholders_amount = int(snip.buffer[snip.line].strip())
|
||||||
|
|
||||||
|
# erase current line
|
||||||
|
snip.buffer[snip.line] = ''
|
||||||
|
|
||||||
|
# create anonymous snippet with expected content and number of tabstops
|
||||||
|
anon_snippet_body = ' & '.join(['$' + str(i+1)
|
||||||
|
for i in range(placeholders_amount)])
|
||||||
|
|
||||||
|
# expand anonymous snippet
|
||||||
|
snip.expand_anon(anon_snippet_body)
|
||||||
|
endglobal
|
||||||
|
|
||||||
|
post_jump "create_row_placeholders(snip)"
|
||||||
|
snippet "tr(\d+)" "latex table row variable" br
|
||||||
|
`!p snip.rv = match.group(1)`
|
||||||
|
endsnippet
|
||||||
|
```
|
||||||
|
|
||||||
|
Snippet is declared via regular expression and will expand to any required
|
||||||
|
number of fields in row.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
71
private_dot_config/nvim/pack/minpac/start/ultisnips/doc/tags
Normal file
71
private_dot_config/nvim/pack/minpac/start/ultisnips/doc/tags
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
:UltiSnipsAddFiletypes UltiSnips.txt /*:UltiSnipsAddFiletypes*
|
||||||
|
:UltiSnipsEdit UltiSnips.txt /*:UltiSnipsEdit*
|
||||||
|
UltiSnips UltiSnips.txt /*UltiSnips*
|
||||||
|
UltiSnips#AddSnippetWithPriority UltiSnips.txt /*UltiSnips#AddSnippetWithPriority*
|
||||||
|
UltiSnips#Anon UltiSnips.txt /*UltiSnips#Anon*
|
||||||
|
UltiSnips#SnippetsInCurrentScope UltiSnips.txt /*UltiSnips#SnippetsInCurrentScope*
|
||||||
|
UltiSnips-FAQ UltiSnips.txt /*UltiSnips-FAQ*
|
||||||
|
UltiSnips-acknowledgments UltiSnips.txt /*UltiSnips-acknowledgments*
|
||||||
|
UltiSnips-authoring-snippets UltiSnips.txt /*UltiSnips-authoring-snippets*
|
||||||
|
UltiSnips-autotrigger UltiSnips.txt /*UltiSnips-autotrigger*
|
||||||
|
UltiSnips-basic-syntax UltiSnips.txt /*UltiSnips-basic-syntax*
|
||||||
|
UltiSnips-basics UltiSnips.txt /*UltiSnips-basics*
|
||||||
|
UltiSnips-buffer-proxy UltiSnips.txt /*UltiSnips-buffer-proxy*
|
||||||
|
UltiSnips-capture-placeholder UltiSnips.txt /*UltiSnips-capture-placeholder*
|
||||||
|
UltiSnips-character-escaping UltiSnips.txt /*UltiSnips-character-escaping*
|
||||||
|
UltiSnips-clearing-snippets UltiSnips.txt /*UltiSnips-clearing-snippets*
|
||||||
|
UltiSnips-commands UltiSnips.txt /*UltiSnips-commands*
|
||||||
|
UltiSnips-contributors UltiSnips.txt /*UltiSnips-contributors*
|
||||||
|
UltiSnips-custom-autocommands UltiSnips.txt /*UltiSnips-custom-autocommands*
|
||||||
|
UltiSnips-custom-context-snippets UltiSnips.txt /*UltiSnips-custom-context-snippets*
|
||||||
|
UltiSnips-demos UltiSnips.txt /*UltiSnips-demos*
|
||||||
|
UltiSnips-description UltiSnips.txt /*UltiSnips-description*
|
||||||
|
UltiSnips-extending UltiSnips.txt /*UltiSnips-extending*
|
||||||
|
UltiSnips-functions UltiSnips.txt /*UltiSnips-functions*
|
||||||
|
UltiSnips-globals UltiSnips.txt /*UltiSnips-globals*
|
||||||
|
UltiSnips-helping UltiSnips.txt /*UltiSnips-helping*
|
||||||
|
UltiSnips-how-snippets-are-loaded UltiSnips.txt /*UltiSnips-how-snippets-are-loaded*
|
||||||
|
UltiSnips-install-and-update UltiSnips.txt /*UltiSnips-install-and-update*
|
||||||
|
UltiSnips-integrations UltiSnips.txt /*UltiSnips-integrations*
|
||||||
|
UltiSnips-interpolation UltiSnips.txt /*UltiSnips-interpolation*
|
||||||
|
UltiSnips-mirrors UltiSnips.txt /*UltiSnips-mirrors*
|
||||||
|
UltiSnips-other-plugins UltiSnips.txt /*UltiSnips-other-plugins*
|
||||||
|
UltiSnips-placeholders UltiSnips.txt /*UltiSnips-placeholders*
|
||||||
|
UltiSnips-plaintext-snippets UltiSnips.txt /*UltiSnips-plaintext-snippets*
|
||||||
|
UltiSnips-post-expand-actions UltiSnips.txt /*UltiSnips-post-expand-actions*
|
||||||
|
UltiSnips-post-jump-actions UltiSnips.txt /*UltiSnips-post-jump-actions*
|
||||||
|
UltiSnips-pre-expand-actions UltiSnips.txt /*UltiSnips-pre-expand-actions*
|
||||||
|
UltiSnips-python UltiSnips.txt /*UltiSnips-python*
|
||||||
|
UltiSnips-python-warning UltiSnips.txt /*UltiSnips-python-warning*
|
||||||
|
UltiSnips-replacement-string UltiSnips.txt /*UltiSnips-replacement-string*
|
||||||
|
UltiSnips-requirements UltiSnips.txt /*UltiSnips-requirements*
|
||||||
|
UltiSnips-settings UltiSnips.txt /*UltiSnips-settings*
|
||||||
|
UltiSnips-shellcode UltiSnips.txt /*UltiSnips-shellcode*
|
||||||
|
UltiSnips-snipMate UltiSnips.txt /*UltiSnips-snipMate*
|
||||||
|
UltiSnips-snippet-actions UltiSnips.txt /*UltiSnips-snippet-actions*
|
||||||
|
UltiSnips-snippet-options UltiSnips.txt /*UltiSnips-snippet-options*
|
||||||
|
UltiSnips-snippet-text-objects UltiSnips.txt /*UltiSnips-snippet-text-objects*
|
||||||
|
UltiSnips-tabstops UltiSnips.txt /*UltiSnips-tabstops*
|
||||||
|
UltiSnips-transformations UltiSnips.txt /*UltiSnips-transformations*
|
||||||
|
UltiSnips-trigger-functions UltiSnips.txt /*UltiSnips-trigger-functions*
|
||||||
|
UltiSnips-trigger-key-mappings UltiSnips.txt /*UltiSnips-trigger-key-mappings*
|
||||||
|
UltiSnips-triggers UltiSnips.txt /*UltiSnips-triggers*
|
||||||
|
UltiSnips-use-python-api UltiSnips.txt /*UltiSnips-use-python-api*
|
||||||
|
UltiSnips-using-a-downloaded-packet UltiSnips.txt /*UltiSnips-using-a-downloaded-packet*
|
||||||
|
UltiSnips-using-pathogen UltiSnips.txt /*UltiSnips-using-pathogen*
|
||||||
|
UltiSnips-vimscript UltiSnips.txt /*UltiSnips-vimscript*
|
||||||
|
UltiSnips-visual-placeholder UltiSnips.txt /*UltiSnips-visual-placeholder*
|
||||||
|
UltiSnips-warning-smappings UltiSnips.txt /*UltiSnips-warning-smappings*
|
||||||
|
UltiSnips.txt UltiSnips.txt /*UltiSnips.txt*
|
||||||
|
UltiSnipsEnterFirstSnippet UltiSnips.txt /*UltiSnipsEnterFirstSnippet*
|
||||||
|
UltiSnipsExitLastSnippet UltiSnips.txt /*UltiSnipsExitLastSnippet*
|
||||||
|
Warning: UltiSnips.txt /*Warning:*
|
||||||
|
g:UltiSnipsEditSplit UltiSnips.txt /*g:UltiSnipsEditSplit*
|
||||||
|
g:UltiSnipsEnableSnipMate UltiSnips.txt /*g:UltiSnipsEnableSnipMate*
|
||||||
|
g:UltiSnipsExpandTrigger UltiSnips.txt /*g:UltiSnipsExpandTrigger*
|
||||||
|
g:UltiSnipsJumpBackwardTrigger UltiSnips.txt /*g:UltiSnipsJumpBackwardTrigger*
|
||||||
|
g:UltiSnipsJumpForwardTrigger UltiSnips.txt /*g:UltiSnipsJumpForwardTrigger*
|
||||||
|
g:UltiSnipsListSnippets UltiSnips.txt /*g:UltiSnipsListSnippets*
|
||||||
|
g:UltiSnipsSnippetDirectories UltiSnips.txt /*g:UltiSnipsSnippetDirectories*
|
||||||
|
snippet UltiSnips.txt /*snippet*
|
||||||
|
snippets UltiSnips.txt /*snippets*
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
call plug#begin('~/.vim_plugged')
|
||||||
|
|
||||||
|
Plug '/src/UltiSnips'
|
||||||
|
Plug 'honza/vim-snippets'
|
||||||
|
|
||||||
|
let g:UltiSnipsExpandTrigger="<tab>"
|
||||||
|
|
||||||
|
" Weird choices for triggers, but I wanted something that is rarely typed and
|
||||||
|
" never eaten by the shell.
|
||||||
|
let g:UltiSnipsListSnippets="9"
|
||||||
|
let g:UltiSnipsJumpForwardTrigger="2"
|
||||||
|
let g:UltiSnipsJumpBackwardTrigger="1"
|
||||||
|
|
||||||
|
let g:UltiSnipsEditSplit="vertical"
|
||||||
|
|
||||||
|
call plug#end()
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o verbose
|
||||||
|
|
||||||
|
cd /src/vim
|
||||||
|
|
||||||
|
PYTHON_BUILD_CONFIG="--enable-python3interp"
|
||||||
|
|
||||||
|
export CFLAGS="$(python-config --cflags)"
|
||||||
|
echo $CFLAGS
|
||||||
|
./configure \
|
||||||
|
--disable-gpm \
|
||||||
|
--disable-nls \
|
||||||
|
--disable-sysmouse \
|
||||||
|
--enable-gui=no \
|
||||||
|
--enable-multibyte \
|
||||||
|
--enable-python3interp \
|
||||||
|
--with-features=huge \
|
||||||
|
--with-tlib=ncurses \
|
||||||
|
--without-x \
|
||||||
|
|| cat $(find . -name 'config.log')
|
||||||
|
make install
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o verbose
|
||||||
|
|
||||||
|
mkdir -p /src && cd /src
|
||||||
|
|
||||||
|
if [[ $VIM_VERSION == "git" ]]; then
|
||||||
|
git clone https://github.com/vim/vim
|
||||||
|
else
|
||||||
|
curl http://ftp.vim.org/pub/vim/unix/vim-${VIM_VERSION}.tar.bz2 -o vim.tar.bz2
|
||||||
|
tar xjf vim.tar.bz2
|
||||||
|
mv -v vim?? vim
|
||||||
|
fi
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o verbose
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y \
|
||||||
|
g++ \
|
||||||
|
tmux \
|
||||||
|
git
|
||||||
|
apt-get clean
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PYTHON_CMD="$(which python)"
|
||||||
|
VIM="/usr/local/bin/vim"
|
||||||
|
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"
|
||||||
|
$VIM --version | head -n 3
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
tmux new -d -s vim
|
||||||
|
|
||||||
|
$PYTHON_CMD ./test_all.py \
|
||||||
|
-v \
|
||||||
|
--plugins \
|
||||||
|
--session vim \
|
||||||
|
--vim $VIM \
|
||||||
|
--interface tmux \
|
||||||
|
--expected-python-version $PYTHON_VERSION
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
snippet example "Repro case example"
|
||||||
|
This is a simple snippet example
|
||||||
|
endsnippet
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
<!--
|
||||||
|
Thanks for reporting your issue. Please follow this template closely. Without
|
||||||
|
all essential info the issue may be closed as unreproducible.
|
||||||
|
|
||||||
|
Fill out the table below ----- symbols and keep it at the end of your issue
|
||||||
|
text. Please provide an answer for every line.
|
||||||
|
|
||||||
|
Please provide an explanation of the issue below this line. -->
|
||||||
|
|
||||||
|
**Expected behavior:**
|
||||||
|
|
||||||
|
|
||||||
|
**Actual behavior:**
|
||||||
|
|
||||||
|
|
||||||
|
**Steps to reproduce**
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Provide a minimal viable repro case, ideally following
|
||||||
|
https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs
|
||||||
|
|
||||||
|
If this is not possible, post a minimal, complete `.vimrc`, snippet definition,
|
||||||
|
and set of keystrokes that reproduces your problem.
|
||||||
|
-->
|
||||||
|
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
|
||||||
|
-----
|
||||||
|
<!-- NOTE: contents inside arrows will be ignored. -->
|
||||||
|
- **Operating System**: <!-- e.g. Windows XP / Ubuntu 16.04 / Mac OS 10.5 -->
|
||||||
|
- **Vim Version**: <!-- first two lines of `:version` output -->
|
||||||
|
- **UltiSnips Version**: <!-- e.g. 3.1. If you're using version from git
|
||||||
|
run: `git rev-parse origin/master` -->
|
||||||
|
- **Python inside Vim**: <!-- e.g. 2.7.14 / 3.6.5. If unsure run inside vim:
|
||||||
|
`:py import sys; print(sys.version)` and
|
||||||
|
`:py3 import sys; print(sys.version)' -->
|
||||||
|
- **Docker repo/vimrc**: <!-- link to the branch containing the repro case,
|
||||||
|
or the uploaded minimal vimrc -->
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
doc/tags
|
||||||
|
/.ropeproject/
|
||||||
|
/.mypy_cache/
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
sudo: required
|
||||||
|
services: docker
|
||||||
|
|
||||||
|
env:
|
||||||
|
- VIM_VERSION="7.4" PYTHON_IMAGE=3.5-stretch TAG=vim_74_py35
|
||||||
|
- VIM_VERSION="8.0" PYTHON_IMAGE=3.5-stretch TAG=vim_80_py35
|
||||||
|
- VIM_VERSION="8.1" PYTHON_IMAGE=3.5-stretch TAG=vim_81_py35
|
||||||
|
- VIM_VERSION="git" PYTHON_IMAGE=3.5-stretch TAG=vim_git_py35
|
||||||
|
- VIM_VERSION="7.4" PYTHON_IMAGE=3.6-stretch TAG=vim_74_py36
|
||||||
|
- VIM_VERSION="8.0" PYTHON_IMAGE=3.6-stretch TAG=vim_80_py36
|
||||||
|
- VIM_VERSION="8.1" PYTHON_IMAGE=3.6-stretch TAG=vim_81_py36
|
||||||
|
- VIM_VERSION="git" PYTHON_IMAGE=3.6-stretch TAG=vim_git_py36
|
||||||
|
- VIM_VERSION="8.1" PYTHON_IMAGE=3.7-stretch TAG=vim_81_py37
|
||||||
|
- VIM_VERSION="git" PYTHON_IMAGE=3.7-stretch TAG=vim_git_py37
|
||||||
|
- VIM_VERSION="8.1" PYTHON_IMAGE=3.8-buster TAG=vim_81_py38
|
||||||
|
- VIM_VERSION="git" PYTHON_IMAGE=3.8-buster TAG=vim_git_py38
|
||||||
|
|
||||||
|
install:
|
||||||
|
- docker build -t ultisnips:${TAG} --build-arg PYTHON_IMAGE=${PYTHON_IMAGE} --build-arg VIM_VERSION=${VIM_VERSION} .
|
||||||
|
|
||||||
|
script:
|
||||||
|
- docker run -it ultisnips:${TAG} docker/run_tests.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
|
||||||
@ -0,0 +1,230 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# See CONTRIBUTING.md for an explanation of this file.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
# <F13> 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] <test case names to run>")
|
||||||
|
|
||||||
|
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(
|
||||||
|
"--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.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:
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
" recognize .snippet files
|
||||||
|
if has("autocmd")
|
||||||
|
autocmd BufNewFile,BufRead *.snippets setf snippets
|
||||||
|
endif
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
" 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
|
||||||
|
|
||||||
|
setlocal commentstring=#%s
|
||||||
|
|
||||||
|
setlocal noexpandtab
|
||||||
|
setlocal autoindent nosmartindent nocindent
|
||||||
|
|
||||||
|
" Whenever a snippets file is written, we ask UltiSnips to reload all snippet
|
||||||
|
" files. This feels like auto-updating, but is of course just an
|
||||||
|
" approximation: If files change outside of the current Vim instance, we will
|
||||||
|
" not notice.
|
||||||
|
augroup ultisnips_snippets.vim
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePost <buffer> call UltiSnips#RefreshSnippets()
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
" 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('<sfile>: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
|
||||||
|
\"
|
||||||
|
|
||||||
|
" snippet text object:
|
||||||
|
" iS: inside snippet
|
||||||
|
" aS: around snippet (including empty lines that follow)
|
||||||
|
fun! s:UltiSnippetTextObj(inner) abort
|
||||||
|
normal! 0
|
||||||
|
let start = search('^snippet', 'nbcW')
|
||||||
|
let end = search('^endsnippet', 'ncW')
|
||||||
|
let prev = search('^endsnippet', 'nbW')
|
||||||
|
|
||||||
|
if !start || !end || prev > start
|
||||||
|
return feedkeys("\<Esc>", 'n')
|
||||||
|
endif
|
||||||
|
|
||||||
|
exe end
|
||||||
|
|
||||||
|
if a:inner
|
||||||
|
let start += 1
|
||||||
|
let end -= 1
|
||||||
|
|
||||||
|
else
|
||||||
|
if search('^\S') <= (end + 1)
|
||||||
|
exe end
|
||||||
|
else
|
||||||
|
let end = line('.') - 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
exe start
|
||||||
|
k<
|
||||||
|
exe end
|
||||||
|
normal! $m>gv
|
||||||
|
endfun
|
||||||
|
|
||||||
|
onoremap <silent><buffer> iS :<C-U>call <SID>UltiSnippetTextObj(1)<CR>
|
||||||
|
xnoremap <silent><buffer> iS :<C-U>call <SID>UltiSnippetTextObj(1)<CR>
|
||||||
|
onoremap <silent><buffer> aS :<C-U>call <SID>UltiSnippetTextObj(0)<CR>
|
||||||
|
xnoremap <silent><buffer> aS :<C-U>call <SID>UltiSnippetTextObj(0)<CR>
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
13
private_dot_config/nvim/pack/minpac/start/ultisnips/mypy.ini
Normal file
13
private_dot_config/nvim/pack/minpac/start/ultisnips/mypy.ini
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Global options:
|
||||||
|
|
||||||
|
[mypy]
|
||||||
|
python_version = 3.7
|
||||||
|
warn_return_any = True
|
||||||
|
warn_unused_configs = True
|
||||||
|
mypy_path=pythonx/UltiSnips
|
||||||
|
|
||||||
|
[mypy-vim]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
|
||||||
|
[mypy-unidecode]
|
||||||
|
ignore_missing_imports = True
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
if exists('did_plugin_ultisnips') || &cp
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let did_plugin_ultisnips=1
|
||||||
|
|
||||||
|
if version < 704
|
||||||
|
echohl WarningMsg
|
||||||
|
echom "UltiSnips requires Vim >= 7.4"
|
||||||
|
echohl None
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The Commands we define.
|
||||||
|
command! -bang -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit
|
||||||
|
\ :call UltiSnips#Edit(<q-bang>, <q-args>)
|
||||||
|
|
||||||
|
command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnips#AddFiletypes(<q-args>)
|
||||||
|
|
||||||
|
augroup UltiSnips_AutoTrigger
|
||||||
|
au!
|
||||||
|
au InsertCharPre * call UltiSnips#TrackChange()
|
||||||
|
au TextChangedI * call UltiSnips#TrackChange()
|
||||||
|
if exists('##TextChangedP')
|
||||||
|
au TextChangedP * call UltiSnips#TrackChange()
|
||||||
|
endif
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
call UltiSnips#map_keys#MapKeys()
|
||||||
|
|
||||||
|
" vim: ts=8 sts=4 sw=4
|
||||||
269
private_dot_config/nvim/pack/minpac/start/ultisnips/pylintrc
Normal file
269
private_dot_config/nvim/pack/minpac/start/ultisnips/pylintrc
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
[MASTER]
|
||||||
|
|
||||||
|
# Python code to execute, usually for sys.path manipulation such as
|
||||||
|
# pygtk.require().
|
||||||
|
init-hook='import sys; sys.path.append("pythonx/")'
|
||||||
|
|
||||||
|
# Add files or directories to the blacklist. They should be base names, not
|
||||||
|
# paths.
|
||||||
|
ignore=CVS,compatibility_py3
|
||||||
|
|
||||||
|
# Pickle collected data for later comparisons.
|
||||||
|
persistent=no
|
||||||
|
|
||||||
|
# List of plugins (as comma separated values of python modules names) to load,
|
||||||
|
# usually to register additional checkers.
|
||||||
|
load-plugins=
|
||||||
|
|
||||||
|
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
|
||||||
|
# Enable the message, report, category or checker with the given id(s). You can
|
||||||
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
|
# multiple time. See also the "--disable" option for examples.
|
||||||
|
#enable=
|
||||||
|
|
||||||
|
# Disable the message, report, category or checker with the given id(s). You
|
||||||
|
# can either give multiple identifiers separated by comma (,) or put this
|
||||||
|
# option multiple times (only on the command line, not in the configuration
|
||||||
|
# file where it should appear only once).You can also use "--disable=all" to
|
||||||
|
# disable everything first and then reenable specific checks. For example, if
|
||||||
|
# you want to run only the similarities checker, you can use "--disable=all
|
||||||
|
# --enable=similarities". If you want to run only the classes checker, but have
|
||||||
|
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||||
|
# --disable=W"
|
||||||
|
disable=
|
||||||
|
attribute-defined-outside-init,
|
||||||
|
bad-continuation,
|
||||||
|
fixme,
|
||||||
|
import-error,
|
||||||
|
missing-class-docstring,
|
||||||
|
missing-function-docstring,
|
||||||
|
missing-module-docstring,
|
||||||
|
redefined-builtin,
|
||||||
|
too-few-public-methods,
|
||||||
|
too-many-arguments,
|
||||||
|
too-many-branches,
|
||||||
|
too-many-instance-attributes,
|
||||||
|
too-many-locals,
|
||||||
|
too-many-public-methods,
|
||||||
|
too-many-return-statements,
|
||||||
|
too-many-statements
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[REPORTS]
|
||||||
|
|
||||||
|
# Set the output format. Available formats are text, parseable, colorized, msvs
|
||||||
|
# (visual studio) and html. You can also give a reporter class, eg
|
||||||
|
# mypackage.mymodule.MyReporterClass.
|
||||||
|
output-format=text
|
||||||
|
|
||||||
|
# Tells whether to display a full report or only the messages
|
||||||
|
reports=no
|
||||||
|
|
||||||
|
msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[BASIC]
|
||||||
|
|
||||||
|
# Required attributes for module, separated by a comma
|
||||||
|
required-attributes=
|
||||||
|
|
||||||
|
# List of builtins function names that should not be used, separated by a comma
|
||||||
|
bad-functions=apply,input
|
||||||
|
|
||||||
|
# Regular expression which should only match correct module names
|
||||||
|
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct module level names
|
||||||
|
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct class names
|
||||||
|
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct function names
|
||||||
|
function-rgx=_?[a-z_][a-z0-9_]{2,50}$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct method names
|
||||||
|
method-rgx=[a-z_][a-z0-9_]{2,50}$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct instance attribute names
|
||||||
|
attr-rgx=[a-z_][a-z0-9_]{2,50}$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct argument names
|
||||||
|
argument-rgx=[a-z_][a-z0-9_]{1,50}$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct variable names
|
||||||
|
variable-rgx=[a-z_][a-z0-9_]{1,50}$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct attribute names in class
|
||||||
|
# bodies
|
||||||
|
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||||
|
|
||||||
|
# Regular expression which should only match correct list comprehension /
|
||||||
|
# generator expression variable names
|
||||||
|
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||||
|
|
||||||
|
# Good variable names which should always be accepted, separated by a comma
|
||||||
|
good-names=i,j,a,b,x,y,k,ex,Run,_
|
||||||
|
|
||||||
|
# Bad variable names which should always be refused, separated by a comma
|
||||||
|
bad-names=foo,bar,baz,toto,tutu,tata
|
||||||
|
|
||||||
|
# Regular expression which should only match function or class names that do
|
||||||
|
# not require a docstring.
|
||||||
|
no-docstring-rgx=(__.*__|wrapper)
|
||||||
|
|
||||||
|
# Minimum line length for functions/classes that require docstrings, shorter
|
||||||
|
# ones are exempt.
|
||||||
|
docstring-min-length=-1
|
||||||
|
|
||||||
|
|
||||||
|
[FORMAT]
|
||||||
|
|
||||||
|
# Maximum number of characters on a single line.
|
||||||
|
max-line-length=110
|
||||||
|
|
||||||
|
# Regexp for a line that is allowed to be longer than the limit.
|
||||||
|
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||||
|
|
||||||
|
# Allow the body of an if to be on the same line as the test if there is no
|
||||||
|
# else.
|
||||||
|
single-line-if-stmt=no
|
||||||
|
|
||||||
|
# List of optional constructs for which whitespace checking is disabled
|
||||||
|
no-space-check=trailing-comma,dict-separator
|
||||||
|
|
||||||
|
# Maximum number of lines in a module
|
||||||
|
max-module-lines=1000
|
||||||
|
|
||||||
|
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||||
|
# tab).
|
||||||
|
indent-string=' '
|
||||||
|
|
||||||
|
|
||||||
|
[SIMILARITIES]
|
||||||
|
|
||||||
|
# Minimum lines number of a similarity.
|
||||||
|
min-similarity-lines=4
|
||||||
|
|
||||||
|
# Ignore comments when computing similarities.
|
||||||
|
ignore-comments=yes
|
||||||
|
|
||||||
|
# Ignore docstrings when computing similarities.
|
||||||
|
ignore-docstrings=yes
|
||||||
|
|
||||||
|
# Ignore imports when computing similarities.
|
||||||
|
ignore-imports=no
|
||||||
|
|
||||||
|
|
||||||
|
[TYPECHECK]
|
||||||
|
|
||||||
|
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||||
|
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||||
|
ignore-mixin-members=yes
|
||||||
|
|
||||||
|
# List of classes names for which member attributes should not be checked
|
||||||
|
# (useful for classes with attributes dynamically set).
|
||||||
|
ignored-classes=SQLObject
|
||||||
|
ignored-modules=vim
|
||||||
|
|
||||||
|
# When zope mode is activated, add a predefined set of Zope acquired attributes
|
||||||
|
# to generated-members.
|
||||||
|
zope=no
|
||||||
|
|
||||||
|
# List of members which are set dynamically and missed by pylint inference
|
||||||
|
# system, and so shouldn't trigger E0201 when accessed. Python regular
|
||||||
|
# expressions are accepted.
|
||||||
|
generated-members=REQUEST,acl_users,aq_parent
|
||||||
|
|
||||||
|
|
||||||
|
[VARIABLES]
|
||||||
|
|
||||||
|
# Tells whether we should check for unused import in __init__ files.
|
||||||
|
init-import=no
|
||||||
|
|
||||||
|
# A regular expression matching the beginning of the name of dummy variables
|
||||||
|
# (i.e. not used).
|
||||||
|
dummy-variables-rgx=_$|dummy
|
||||||
|
|
||||||
|
# List of additional names supposed to be defined in builtins. Remember that
|
||||||
|
# you should avoid to define new builtins when possible.
|
||||||
|
additional-builtins=
|
||||||
|
|
||||||
|
|
||||||
|
[CLASSES]
|
||||||
|
|
||||||
|
# List of interface methods to ignore, separated by a comma. This is used for
|
||||||
|
# instance to not check methods defines in Zope's Interface base class.
|
||||||
|
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
|
||||||
|
|
||||||
|
# List of method names used to declare (i.e. assign) instance attributes.
|
||||||
|
defining-attr-methods=__init__,__new__,setUp
|
||||||
|
|
||||||
|
# List of valid names for the first argument in a class method.
|
||||||
|
valid-classmethod-first-arg=cls
|
||||||
|
|
||||||
|
# List of valid names for the first argument in a metaclass class method.
|
||||||
|
valid-metaclass-classmethod-first-arg=mcs
|
||||||
|
|
||||||
|
|
||||||
|
[DESIGN]
|
||||||
|
|
||||||
|
# Maximum number of arguments for function / method
|
||||||
|
max-args=5
|
||||||
|
|
||||||
|
# Argument names that match this expression will be ignored. Default to name
|
||||||
|
# with leading underscore
|
||||||
|
ignored-argument-names=_.*
|
||||||
|
|
||||||
|
# Maximum number of locals for function / method body
|
||||||
|
max-locals=15
|
||||||
|
|
||||||
|
# Maximum number of return / yield for function / method body
|
||||||
|
max-returns=6
|
||||||
|
|
||||||
|
# Maximum number of branch for function / method body
|
||||||
|
max-branches=12
|
||||||
|
|
||||||
|
# Maximum number of statements in function / method body
|
||||||
|
max-statements=50
|
||||||
|
|
||||||
|
# Maximum number of parents for a class (see R0901).
|
||||||
|
max-parents=7
|
||||||
|
|
||||||
|
# Maximum number of attributes for a class (see R0902).
|
||||||
|
max-attributes=7
|
||||||
|
|
||||||
|
# Minimum number of public methods for a class (see R0903).
|
||||||
|
min-public-methods=2
|
||||||
|
|
||||||
|
# Maximum number of public methods for a class (see R0904).
|
||||||
|
max-public-methods=20
|
||||||
|
|
||||||
|
|
||||||
|
[IMPORTS]
|
||||||
|
|
||||||
|
# Deprecated modules which should not be used, separated by a comma
|
||||||
|
deprecated-modules=regsub,TERMIOS,Bastion,rexec
|
||||||
|
|
||||||
|
# Create a graph of every (i.e. internal and external) dependencies in the
|
||||||
|
# given file (report RP0402 must not be disabled)
|
||||||
|
import-graph=
|
||||||
|
|
||||||
|
# Create a graph of external dependencies in the given file (report RP0402 must
|
||||||
|
# not be disabled)
|
||||||
|
ext-import-graph=
|
||||||
|
|
||||||
|
# Create a graph of internal dependencies in the given file (report RP0402 must
|
||||||
|
# not be disabled)
|
||||||
|
int-import-graph=
|
||||||
|
|
||||||
|
|
||||||
|
[EXCEPTIONS]
|
||||||
|
|
||||||
|
# Exceptions that will emit a warning when being caught. Defaults to
|
||||||
|
# "Exception"
|
||||||
|
overgeneral-exceptions=Exception
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Entry point for all things UltiSnips."""
|
||||||
|
|
||||||
|
from UltiSnips.snippet_manager import UltiSnips_Manager
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,220 @@
|
|||||||
|
# coding=utf8
|
||||||
|
|
||||||
|
import vim
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
from UltiSnips.position import Position
|
||||||
|
from UltiSnips.diff import diff
|
||||||
|
|
||||||
|
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_helper.buf
|
||||||
|
try:
|
||||||
|
vim_helper.buf = buffer_proxy
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
vim_helper.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_helper.buf, VimBufferProxy):
|
||||||
|
yield
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
vim_helper.buf._disable_edits()
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
vim_helper.buf._enable_edits()
|
||||||
|
|
||||||
|
|
||||||
|
class VimBufferProxy(vim_helper.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 = [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 = 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__.
|
||||||
|
"""
|
||||||
|
return 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] = [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], True)
|
||||||
|
|
||||||
|
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], True)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
change_type, line_number, column_number, change_text = change[0:4]
|
||||||
|
|
||||||
|
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_type == "D":
|
||||||
|
direction = -1
|
||||||
|
|
||||||
|
diff = Position(direction, 0)
|
||||||
|
if len(change) != 5:
|
||||||
|
diff = Position(0, direction * len(change_text))
|
||||||
|
|
||||||
|
self._snippets_stack[0]._move(Position(line_number, column_number), diff)
|
||||||
|
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[0:4])
|
||||||
|
|
||||||
|
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
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""This file contains compatibility code to stay compatible with as many python
|
||||||
|
versions as possible."""
|
||||||
|
|
||||||
|
import vim
|
||||||
|
|
||||||
|
|
||||||
|
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(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 col2byte(line, 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]
|
||||||
|
raw_bytes = _vim_enc(line)[:nbyte]
|
||||||
|
return len(_vim_dec(raw_bytes))
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Convenience methods that help with debugging.
|
||||||
|
|
||||||
|
They should never be used in production code.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
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."""
|
||||||
|
# pylint:disable=protected-access
|
||||||
|
parent = text_object
|
||||||
|
while parent._parent:
|
||||||
|
parent = parent._parent
|
||||||
|
|
||||||
|
def _do_print(text_object, indent=""):
|
||||||
|
"""prints recursively."""
|
||||||
|
debug(indent + text_object)
|
||||||
|
try:
|
||||||
|
for child in text_object._children:
|
||||||
|
_do_print(child, indent=indent + " ")
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
_do_print(parent)
|
||||||
|
|
||||||
|
|
||||||
|
def debug(msg):
|
||||||
|
"""Dumb 'msg' into the debug file."""
|
||||||
|
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:
|
||||||
|
traceback.print_stack(file=dump_file)
|
||||||
@ -0,0 +1,266 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Commands to compare text objects and to guess how to transform from one to
|
||||||
|
another."""
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
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'.
|
||||||
|
|
||||||
|
"""
|
||||||
|
buf = original[:]
|
||||||
|
for cmd in cmds:
|
||||||
|
ctype, line, col, char = cmd
|
||||||
|
line -= initial_line
|
||||||
|
if ctype == "D":
|
||||||
|
if char != "\n":
|
||||||
|
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]
|
||||||
|
else:
|
||||||
|
del buf[line]
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not len(last_text) and not len(current_text):
|
||||||
|
return True, ()
|
||||||
|
pos = vim_state.pos
|
||||||
|
ppos = vim_state.ppos
|
||||||
|
|
||||||
|
# All text deleted?
|
||||||
|
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
|
||||||
|
if is_complete_edit(initial_line, last_text, current_text, es):
|
||||||
|
return True, es
|
||||||
|
if ppos.mode == "v": # Maybe selectmode?
|
||||||
|
sv = list(map(int, vim_helper.eval("""getpos("'<")""")))
|
||||||
|
sv = Position(sv[1] - 1, sv[2] - 1)
|
||||||
|
ev = list(map(int, vim_helper.eval("""getpos("'>")""")))
|
||||||
|
ev = Position(ev[1] - 1, ev[2] - 1)
|
||||||
|
if "exclusive" in vim_helper.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],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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
|
||||||
|
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
|
||||||
|
es = (
|
||||||
|
(
|
||||||
|
"I",
|
||||||
|
ppos.line,
|
||||||
|
ppos.col,
|
||||||
|
current_text[ppos.line - initial_line][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
|
||||||
|
es = (
|
||||||
|
(
|
||||||
|
"D",
|
||||||
|
pos.line,
|
||||||
|
pos.col,
|
||||||
|
last_text[ppos.line - initial_line][
|
||||||
|
ppos.col : ppos.col + (llen - clen)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if is_complete_edit(initial_line, last_text, current_text, es):
|
||||||
|
return True, es
|
||||||
|
if pos < ppos: # Backspacing or dT dF?
|
||||||
|
es = (
|
||||||
|
(
|
||||||
|
"D",
|
||||||
|
pos.line,
|
||||||
|
pos.col,
|
||||||
|
last_text[pos.line - initial_line][
|
||||||
|
pos.col : pos.col + llen - clen
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if is_complete_edit(initial_line, last_text, 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"))
|
||||||
|
if is_complete_edit(initial_line, last_text, 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 is_complete_edit(initial_line, last_text, 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
|
||||||
|
is done by traversing an implicit edit graph and searching for the shortest
|
||||||
|
route. The basic idea is as follows:
|
||||||
|
|
||||||
|
- Matching a character is free as long as there was no
|
||||||
|
deletion/insertion before. Then, matching will be seen as delete +
|
||||||
|
insert [1].
|
||||||
|
- Deleting one character has the same cost everywhere. Each additional
|
||||||
|
character costs only have of the first deletion.
|
||||||
|
- Insertion is cheaper the earlier it happens. The first character is
|
||||||
|
more expensive that any later [2].
|
||||||
|
|
||||||
|
[1] This is that world -> aolsa will be "D" world + "I" aolsa instead of
|
||||||
|
"D" w , "D" rld, "I" a, "I" lsa
|
||||||
|
[2] This is that "hello\n\n" -> "hello\n\n\n" will insert a newline after
|
||||||
|
hello and not after \n
|
||||||
|
"""
|
||||||
|
d = defaultdict(list) # pylint:disable=invalid-name
|
||||||
|
seen = defaultdict(lambda: sys.maxsize)
|
||||||
|
|
||||||
|
d[0] = [(0, 0, sline, 0, ())]
|
||||||
|
cost = 0
|
||||||
|
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()
|
||||||
|
|
||||||
|
if a[x:] == b[y:]:
|
||||||
|
return what
|
||||||
|
|
||||||
|
if x < len(a) and y < len(b) and a[x] == b[y]:
|
||||||
|
ncol = col + 1
|
||||||
|
nline = line
|
||||||
|
if a[x] == "\n":
|
||||||
|
ncol = 0
|
||||||
|
nline += 1
|
||||||
|
lcost = cost + 1
|
||||||
|
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
|
||||||
|
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
|
||||||
|
d[cost + (insertion_cost + ncol) // 2].append(
|
||||||
|
(
|
||||||
|
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
|
||||||
|
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]),))
|
||||||
|
)
|
||||||
|
cost += 1
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
# coding=utf8
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
import traceback
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
|
||||||
|
|
||||||
|
def wrap(func):
|
||||||
|
"""Decorator that will catch any Exception that 'func' throws and displays
|
||||||
|
it in a new Vim scratch buffer."""
|
||||||
|
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(self, *args, **kwds):
|
||||||
|
try:
|
||||||
|
return func(self, *args, **kwds)
|
||||||
|
except Exception as e: # pylint: disable=bare-except
|
||||||
|
msg = """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
|
||||||
|
Please read and follow:
|
||||||
|
https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs
|
||||||
|
|
||||||
|
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.
|
||||||
|
if hasattr(self, "_leaving_buffer"):
|
||||||
|
self._leaving_buffer() # pylint:disable=protected-access
|
||||||
|
vim_helper.new_scratch_buffer(msg)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
@ -0,0 +1,346 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Wrapper functionality around the functions we need from Vim."""
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
|
from UltiSnips.snippet.source.file.common import normalize_file_path
|
||||||
|
from UltiSnips.compatibility import col2byte, byte2col
|
||||||
|
from UltiSnips.position import Position
|
||||||
|
from vim import error # pylint:disable=import-error,unused-import
|
||||||
|
import vim # pylint:disable=import-error
|
||||||
|
|
||||||
|
|
||||||
|
class VimBuffer:
|
||||||
|
|
||||||
|
"""Wrapper around the current Vim buffer."""
|
||||||
|
|
||||||
|
def __getitem__(self, idx):
|
||||||
|
return vim.current.buffer[idx]
|
||||||
|
|
||||||
|
def __setitem__(self, idx, text):
|
||||||
|
vim.current.buffer[idx] = text
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(vim.current.buffer)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def line_till_cursor(self): # pylint:disable=no-self-use
|
||||||
|
"""Returns the text before the cursor."""
|
||||||
|
_, col = self.cursor
|
||||||
|
return vim.current.line[:col]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def number(self): # pylint:disable=no-self-use
|
||||||
|
"""The bufnr() of the current buffer."""
|
||||||
|
return vim.current.buffer.number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filetypes(self):
|
||||||
|
return [ft for ft in vim.eval("&filetype").split(".") if ft]
|
||||||
|
|
||||||
|
@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.
|
||||||
|
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""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 option_set_to(name, new_value):
|
||||||
|
old_value = vim.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."""
|
||||||
|
|
||||||
|
def conv(obj):
|
||||||
|
"""Convert obj."""
|
||||||
|
if isinstance(obj, list):
|
||||||
|
rv = "[" + ",".join(conv(o) for o in obj) + "]"
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
rv = (
|
||||||
|
"{"
|
||||||
|
+ ",".join(
|
||||||
|
[
|
||||||
|
"%s:%s" % (conv(key), conv(value))
|
||||||
|
for key, value in obj.iteritems()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
+ "}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
rv = '"%s"' % obj.replace('"', '\\"')
|
||||||
|
return rv
|
||||||
|
|
||||||
|
return conv(inp)
|
||||||
|
|
||||||
|
|
||||||
|
def command(cmd):
|
||||||
|
"""Wraps vim.command."""
|
||||||
|
return vim.command(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def eval(text):
|
||||||
|
"""Wraps vim.eval."""
|
||||||
|
return vim.eval(text)
|
||||||
|
|
||||||
|
|
||||||
|
def bindeval(text):
|
||||||
|
"""Wraps vim.bindeval."""
|
||||||
|
rv = vim.bindeval(text)
|
||||||
|
if not isinstance(rv, (dict, list)):
|
||||||
|
return rv.decode(vim.eval("&encoding"), "replace")
|
||||||
|
return rv
|
||||||
|
|
||||||
|
|
||||||
|
def feedkeys(keys, mode="n"):
|
||||||
|
"""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(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")
|
||||||
|
|
||||||
|
vim.current.buffer[:] = text.splitlines()
|
||||||
|
|
||||||
|
feedkeys(r"\<Esc>")
|
||||||
|
|
||||||
|
# Older versions of Vim always jumped the cursor to a new window, no matter
|
||||||
|
# how it was generated. Newer versions of Vim seem to not jump if the
|
||||||
|
# window is generated while in insert mode. Our tests rely that the cursor
|
||||||
|
# jumps when an error is thrown. Instead of doing the right thing of fixing
|
||||||
|
# how our test get the information about an error, we do the quick thing
|
||||||
|
# and make sure we always end up with the cursor in the scratch buffer.
|
||||||
|
feedkeys(r"\<c-w>\<down>")
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
selection = eval("&selection")
|
||||||
|
|
||||||
|
col = col2byte(start.line + 1, start.col)
|
||||||
|
buf.cursor = start
|
||||||
|
|
||||||
|
mode = eval("mode()")
|
||||||
|
|
||||||
|
move_cmd = ""
|
||||||
|
if mode != "n":
|
||||||
|
move_cmd += r"\<Esc>"
|
||||||
|
|
||||||
|
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"
|
||||||
|
else:
|
||||||
|
# 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:
|
||||||
|
move_cmd += "%iG%i|" % virtual_position(end.line + 1, end.col + 1)
|
||||||
|
move_cmd += "o%iG%i|o\\<c-g>" % virtual_position(start.line + 1, start.col + 1)
|
||||||
|
feedkeys(move_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def get_dot_vim():
|
||||||
|
"""Returns the likely place for ~/.vim for the current setup."""
|
||||||
|
home = vim.eval("$HOME")
|
||||||
|
candidates = []
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
candidates.append(os.path.join(home, "vimfiles"))
|
||||||
|
if vim.eval("has('nvim')") == "1":
|
||||||
|
xdg_home_config = vim.eval("$XDG_CONFIG_HOME") or os.path.join(home, ".config")
|
||||||
|
candidates.append(os.path.join(xdg_home_config, "nvim"))
|
||||||
|
|
||||||
|
candidates.append(os.path.join(home, ".vim"))
|
||||||
|
|
||||||
|
if "MYVIMRC" in os.environ:
|
||||||
|
my_vimrc = os.path.expandvars(os.environ["MYVIMRC"])
|
||||||
|
candidates.append(normalize_file_path(os.path.dirname(my_vimrc)))
|
||||||
|
for candidate in candidates:
|
||||||
|
if os.path.isdir(candidate):
|
||||||
|
return normalize_file_path(candidate)
|
||||||
|
raise RuntimeError(
|
||||||
|
"Unable to find user configuration directory. I tried '%s'." % candidates
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def set_mark_from_pos(name, pos):
|
||||||
|
return _set_pos("'" + name, pos)
|
||||||
|
|
||||||
|
|
||||||
|
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 <Plug>).
|
||||||
|
|
||||||
|
"""
|
||||||
|
if int(eval("g:UltiSnipsRemoveSelectModeMappings")):
|
||||||
|
ignores = eval("g:UltiSnipsMappingsToIgnore") + ["UltiSnips"]
|
||||||
|
|
||||||
|
for option in ("<buffer>", ""):
|
||||||
|
# Put all smaps into a var, and then read the var
|
||||||
|
command(r"redir => _tmp_smaps | silent smap %s " % option + "| redir END")
|
||||||
|
|
||||||
|
# Check if any mappings where found
|
||||||
|
if hasattr(vim, "bindeval"):
|
||||||
|
# Safer to use bindeval, if it exists, because it can deal with
|
||||||
|
# non-UTF-8 characters in mappings; see GH #690.
|
||||||
|
all_maps = bindeval(r"_tmp_smaps")
|
||||||
|
else:
|
||||||
|
all_maps = eval(r"_tmp_smaps")
|
||||||
|
all_maps = list(filter(len, all_maps.splitlines()))
|
||||||
|
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
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 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())
|
||||||
|
]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if trig is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# The bar separates commands
|
||||||
|
if trig[-1] == "|":
|
||||||
|
trig = trig[:-1] + "<Bar>"
|
||||||
|
|
||||||
|
# Special ones
|
||||||
|
if trig[0] == "<":
|
||||||
|
add = False
|
||||||
|
# Only allow these
|
||||||
|
for valid in ["Tab", "NL", "CR", "C-Tab", "BS"]:
|
||||||
|
if trig == "<%s>" % valid:
|
||||||
|
add = True
|
||||||
|
if not add:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# UltiSnips remaps <BS>. Keep this around.
|
||||||
|
if trig == "<BS>":
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Actually unmap it
|
||||||
|
try:
|
||||||
|
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
|
||||||
|
# will not be able to unmap lhs with any unprintable
|
||||||
|
# character. If the lhs stats with a printable
|
||||||
|
# character this will leak to the user when he tries to
|
||||||
|
# type this character as a first in a selected tabstop.
|
||||||
|
# This case should be rare enough to not bother us
|
||||||
|
# though.
|
||||||
|
pass
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""See module doc."""
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
|
||||||
|
|
||||||
|
class IndentUtil:
|
||||||
|
|
||||||
|
"""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_helper.eval("exists('*shiftwidth') ? shiftwidth() : &shiftwidth")
|
||||||
|
)
|
||||||
|
self._expandtab = vim_helper.eval("&expandtab") == "1"
|
||||||
|
self._tabstop = int(vim_helper.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 = 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."""
|
||||||
|
indent = indent.expandtabs(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."""
|
||||||
|
if not self._expandtab:
|
||||||
|
indent = indent.replace(" " * self._tabstop, "\t")
|
||||||
|
return indent
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class JumpDirection(Enum):
|
||||||
|
FORWARD = 1
|
||||||
|
BACKWARD = 2
|
||||||
|
|
||||||
|
|
||||||
|
class Position:
|
||||||
|
"""Represents a Position in a text file: (0 based line index, 0 based column
|
||||||
|
index) and provides methods for moving them around."""
|
||||||
|
|
||||||
|
def __init__(self, line, col):
|
||||||
|
self.line = line
|
||||||
|
self.col = col
|
||||||
|
|
||||||
|
def move(self, pivot, delta):
|
||||||
|
"""'pivot' is the position of the first changed character, 'delta' is
|
||||||
|
how text after it moved."""
|
||||||
|
if self < pivot:
|
||||||
|
return
|
||||||
|
if delta.line == 0:
|
||||||
|
if self.line == pivot.line:
|
||||||
|
self.col += delta.col
|
||||||
|
elif delta.line > 0:
|
||||||
|
if self.line == pivot.line:
|
||||||
|
self.col += delta.col - pivot.col
|
||||||
|
self.line += delta.line
|
||||||
|
else:
|
||||||
|
self.line += delta.line
|
||||||
|
if self.line == pivot.line:
|
||||||
|
self.col += -delta.col + pivot.col
|
||||||
|
|
||||||
|
def delta(self, pos):
|
||||||
|
"""Returns the difference that the cursor must move to come from 'pos'
|
||||||
|
to us."""
|
||||||
|
assert isinstance(pos, Position)
|
||||||
|
if self.line == pos.line:
|
||||||
|
return Position(0, self.col - pos.col)
|
||||||
|
if self > pos:
|
||||||
|
return Position(self.line - pos.line, self.col)
|
||||||
|
return Position(self.line - pos.line, pos.col)
|
||||||
|
|
||||||
|
def __add__(self, pos):
|
||||||
|
assert isinstance(pos, Position)
|
||||||
|
return Position(self.line + pos.line, self.col + pos.col)
|
||||||
|
|
||||||
|
def __sub__(self, pos):
|
||||||
|
assert isinstance(pos, Position)
|
||||||
|
return Position(self.line - pos.line, self.col - pos.col)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return (self.line, self.col) == (other.line, other.col)
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return (self.line, self.col) != (other.line, other.col)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return (self.line, self.col) < (other.line, other.col)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return (self.line, self.col) <= (other.line, other.col)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
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
|
||||||
@ -0,0 +1 @@
|
|||||||
|
"""Code related to snippets."""
|
||||||
Binary file not shown.
@ -0,0 +1,4 @@
|
|||||||
|
"""In memory representation of snippet definitions."""
|
||||||
|
|
||||||
|
from UltiSnips.snippet.definition.ulti_snips import UltiSnipsSnippetDefinition
|
||||||
|
from UltiSnips.snippet.definition.snipmate import SnipMateSnippetDefinition
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,489 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Snippet representation after parsing."""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import vim
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
from UltiSnips.indent_util import IndentUtil
|
||||||
|
from UltiSnips.text import escape
|
||||||
|
from UltiSnips.text_objects import SnippetInstance
|
||||||
|
from UltiSnips.position import Position
|
||||||
|
from UltiSnips.text_objects.python_code import SnippetUtilForAction
|
||||||
|
|
||||||
|
__WHITESPACE_SPLIT = re.compile(r"\s")
|
||||||
|
|
||||||
|
|
||||||
|
class _SnippetUtilCursor:
|
||||||
|
def __init__(self, cursor):
|
||||||
|
self._cursor = [cursor[0] - 1, cursor[1]]
|
||||||
|
self._set = False
|
||||||
|
|
||||||
|
def preserve(self):
|
||||||
|
self._set = True
|
||||||
|
self._cursor = [vim_helper.buf.cursor[0], vim_helper.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]))
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
"""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 = trigger
|
||||||
|
self._value = value
|
||||||
|
self._description = 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 or {}
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
self._make_debug_exception(e, code)
|
||||||
|
raise
|
||||||
|
|
||||||
|
return snip
|
||||||
|
|
||||||
|
def _execute_action(self, action, context, additional_locals={}):
|
||||||
|
mark_to_use = "`"
|
||||||
|
with vim_helper.save_mark(mark_to_use):
|
||||||
|
vim_helper.set_mark_from_pos(mark_to_use, vim_helper.get_cursor_pos())
|
||||||
|
|
||||||
|
cursor_line_before = vim_helper.buf.line_till_cursor
|
||||||
|
|
||||||
|
locals = {"context": context}
|
||||||
|
|
||||||
|
locals.update(additional_locals)
|
||||||
|
|
||||||
|
snip = self._eval_code(action, locals)
|
||||||
|
|
||||||
|
if snip.cursor.is_set():
|
||||||
|
vim_helper.buf.cursor = Position(
|
||||||
|
snip.cursor._cursor[0], snip.cursor._cursor[1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
new_mark_pos = vim_helper.get_mark_pos(mark_to_use)
|
||||||
|
|
||||||
|
cursor_invalid = False
|
||||||
|
|
||||||
|
if vim_helper._is_pos_zero(new_mark_pos):
|
||||||
|
cursor_invalid = True
|
||||||
|
else:
|
||||||
|
vim_helper.set_cursor_from_pos(new_mark_pos)
|
||||||
|
if cursor_line_before != vim_helper.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 _make_debug_exception(self, e, code=""):
|
||||||
|
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 "<none>",
|
||||||
|
self._actions["pre_expand"] if "pre_expand" in self._actions else "<none>",
|
||||||
|
self._actions["post_expand"]
|
||||||
|
if "post_expand" in self._actions
|
||||||
|
else "<none>",
|
||||||
|
code,
|
||||||
|
)
|
||||||
|
|
||||||
|
e.snippet_code = code
|
||||||
|
|
||||||
|
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:
|
||||||
|
try:
|
||||||
|
match = self._re_match(before)
|
||||||
|
except Exception as e:
|
||||||
|
self._make_debug_exception(e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
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_helper.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_helper.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_helper.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_helper.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_helper.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.replace_initial_text(vim_helper.buf)
|
||||||
|
snippet_instance.update_textobjects(vim_helper.buf)
|
||||||
|
return snippet_instance
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
#!/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)
|
||||||
@ -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.ulti_snips 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)
|
||||||
@ -0,0 +1 @@
|
|||||||
|
"""Code related to turning text into snippets."""
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,76 @@
|
|||||||
|
#!/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:
|
||||||
|
text_object = klass(parent, token)
|
||||||
|
|
||||||
|
# TabStop has some subclasses (e.g. Choices)
|
||||||
|
if isinstance(text_object, TabStop):
|
||||||
|
seen_ts[text_object.number] = text_object
|
||||||
|
|
||||||
|
_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)
|
||||||
@ -0,0 +1,412 @@
|
|||||||
|
#!/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."""
|
||||||
|
|
||||||
|
import string
|
||||||
|
import re
|
||||||
|
|
||||||
|
from UltiSnips.position import Position
|
||||||
|
from UltiSnips.text import unescape
|
||||||
|
|
||||||
|
|
||||||
|
class _TextIterator:
|
||||||
|
|
||||||
|
"""Helper class to make iterating over text easier."""
|
||||||
|
|
||||||
|
def __init__(self, text, offset):
|
||||||
|
self._text = text
|
||||||
|
self._line = offset.line
|
||||||
|
self._col = offset.col
|
||||||
|
|
||||||
|
self._idx = 0
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
"""Iterator interface."""
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
"""Returns the next character."""
|
||||||
|
if self._idx >= len(self._text):
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
rv = self._text[self._idx]
|
||||||
|
if self._text[self._idx] in ("\n", "\r\n"):
|
||||||
|
self._line += 1
|
||||||
|
self._col = 0
|
||||||
|
else:
|
||||||
|
self._col += 1
|
||||||
|
self._idx += 1
|
||||||
|
return rv
|
||||||
|
|
||||||
|
def peek(self, count=1):
|
||||||
|
"""Returns the next 'count' characters without advancing the stream."""
|
||||||
|
if count > 1: # This might return '' if nothing is found
|
||||||
|
return self._text[self._idx : self._idx + count]
|
||||||
|
try:
|
||||||
|
return self._text[self._idx]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pos(self):
|
||||||
|
"""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 = ""
|
||||||
|
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
|
||||||
|
non escaped { are taken into account and skipped over.
|
||||||
|
|
||||||
|
Will also consume the closing }, but not return it
|
||||||
|
"""
|
||||||
|
rv = ""
|
||||||
|
in_braces = 1
|
||||||
|
while True:
|
||||||
|
if EscapeCharToken.starts_here(stream, "{}"):
|
||||||
|
rv += next(stream) + next(stream)
|
||||||
|
else:
|
||||||
|
char = next(stream)
|
||||||
|
if char == "{":
|
||||||
|
in_braces += 1
|
||||||
|
elif char == "}":
|
||||||
|
in_braces -= 1
|
||||||
|
if in_braces == 0:
|
||||||
|
break
|
||||||
|
rv += char
|
||||||
|
return rv
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_till_unescaped_char(stream, chars):
|
||||||
|
"""
|
||||||
|
Returns all chars till a non-escaped char is found.
|
||||||
|
|
||||||
|
Will also consume the closing char, but and return it as second
|
||||||
|
return value
|
||||||
|
"""
|
||||||
|
rv = ""
|
||||||
|
while True:
|
||||||
|
escaped = False
|
||||||
|
for char in chars:
|
||||||
|
if EscapeCharToken.starts_here(stream, char):
|
||||||
|
rv += next(stream) + next(stream)
|
||||||
|
escaped = True
|
||||||
|
if not escaped:
|
||||||
|
char = next(stream)
|
||||||
|
if char in chars:
|
||||||
|
break
|
||||||
|
rv += char
|
||||||
|
return rv, char
|
||||||
|
|
||||||
|
|
||||||
|
class Token:
|
||||||
|
|
||||||
|
"""Represents a Token as parsed from a snippet definition."""
|
||||||
|
|
||||||
|
def __init__(self, gen, indent):
|
||||||
|
self.initial_text = ""
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
class TabStopToken(Token):
|
||||||
|
|
||||||
|
"""${1:blub}"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^\${\d+[:}]")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(10)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # $
|
||||||
|
next(stream) # {
|
||||||
|
|
||||||
|
self.number = _parse_number(stream)
|
||||||
|
|
||||||
|
if stream.peek() == ":":
|
||||||
|
next(stream)
|
||||||
|
self.initial_text = _parse_till_closing_brace(stream)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "TabStopToken(%r,%r,%r,%r)" % (
|
||||||
|
self.start,
|
||||||
|
self.end,
|
||||||
|
self.number,
|
||||||
|
self.initial_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class VisualToken(Token):
|
||||||
|
|
||||||
|
"""${VISUAL}"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^\${VISUAL[:}/]")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(10)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
for _ in range(8): # ${VISUAL
|
||||||
|
next(stream)
|
||||||
|
|
||||||
|
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
|
||||||
|
try:
|
||||||
|
self.search = _parse_till_unescaped_char(stream, "/")[0]
|
||||||
|
self.replace = _parse_till_unescaped_char(stream, "/")[0]
|
||||||
|
self.options = _parse_till_closing_brace(stream)
|
||||||
|
except StopIteration:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Invalid ${VISUAL} transformation! Forgot to escape a '/'?"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.search = None
|
||||||
|
self.replace = None
|
||||||
|
self.options = None
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "VisualToken(%r,%r)" % (self.start, self.end)
|
||||||
|
|
||||||
|
|
||||||
|
class TransformationToken(Token):
|
||||||
|
|
||||||
|
"""${1/match/replace/options}"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^\${\d+\/")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(10)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # $
|
||||||
|
next(stream) # {
|
||||||
|
|
||||||
|
self.number = _parse_number(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)" % (
|
||||||
|
self.start,
|
||||||
|
self.end,
|
||||||
|
self.number,
|
||||||
|
self.search,
|
||||||
|
self.replace,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MirrorToken(Token):
|
||||||
|
|
||||||
|
"""$1."""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^\$\d+")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(10)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # $
|
||||||
|
self.number = _parse_number(stream)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "MirrorToken(%r,%r,%r)" % (self.start, self.end, self.number)
|
||||||
|
|
||||||
|
|
||||||
|
class ChoicesToken(Token):
|
||||||
|
|
||||||
|
"""${1|o1,o2,o3|}
|
||||||
|
P.S. This is not a subclass of TabStop,
|
||||||
|
so its content will not be parsed recursively.
|
||||||
|
"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^\${\d+\|")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(10)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # $
|
||||||
|
next(stream) # {
|
||||||
|
|
||||||
|
self.number = _parse_number(stream)
|
||||||
|
|
||||||
|
if self.number == 0:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Choices selection is not supported on $0"
|
||||||
|
)
|
||||||
|
|
||||||
|
next(stream) # |
|
||||||
|
|
||||||
|
choices_text = _parse_till_unescaped_char(stream, "|")[0]
|
||||||
|
self.choice_list = choices_text.split(",")
|
||||||
|
self.initial_text = "|{0}|".format(choices_text)
|
||||||
|
|
||||||
|
_parse_till_closing_brace(stream)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "ChoicesToken(%r,%r,%r,|%r|)" % (
|
||||||
|
self.start,
|
||||||
|
self.end,
|
||||||
|
self.number,
|
||||||
|
self.initial_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EscapeCharToken(Token):
|
||||||
|
|
||||||
|
"""\\n."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream, chars=r"{}\$`"):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
cs = stream.peek(2)
|
||||||
|
if len(cs) == 2 and cs[0] == "\\" and cs[1] in chars:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # \
|
||||||
|
self.initial_text = next(stream)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "EscapeCharToken(%r,%r,%r)" % (self.start, self.end, self.initial_text)
|
||||||
|
|
||||||
|
|
||||||
|
class ShellCodeToken(Token):
|
||||||
|
|
||||||
|
"""`echo "hi"`"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return stream.peek(1) == "`"
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
next(stream) # `
|
||||||
|
self.code = _parse_till_unescaped_char(stream, "`")[0]
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "ShellCodeToken(%r,%r,%r)" % (self.start, self.end, self.code)
|
||||||
|
|
||||||
|
|
||||||
|
class PythonCodeToken(Token):
|
||||||
|
|
||||||
|
"""`!p snip.rv = "Hi"`"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^`!p\s")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(4)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
for _ in range(3):
|
||||||
|
next(stream) # `!p
|
||||||
|
if stream.peek() in "\t ":
|
||||||
|
next(stream)
|
||||||
|
|
||||||
|
code = _parse_till_unescaped_char(stream, "`")[0]
|
||||||
|
|
||||||
|
# Strip the indent if any
|
||||||
|
if len(indent):
|
||||||
|
lines = code.splitlines()
|
||||||
|
self.code = lines[0] + "\n"
|
||||||
|
self.code += "\n".join([l[len(indent) :] for l in lines[1:]])
|
||||||
|
else:
|
||||||
|
self.code = code
|
||||||
|
self.indent = indent
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "PythonCodeToken(%r,%r,%r)" % (self.start, self.end, self.code)
|
||||||
|
|
||||||
|
|
||||||
|
class VimLCodeToken(Token):
|
||||||
|
|
||||||
|
"""`!v g:hi`"""
|
||||||
|
|
||||||
|
CHECK = re.compile(r"^`!v\s")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def starts_here(cls, stream):
|
||||||
|
"""Returns true if this token starts at the current position in
|
||||||
|
'stream'."""
|
||||||
|
return cls.CHECK.match(stream.peek(4)) is not None
|
||||||
|
|
||||||
|
def _parse(self, stream, indent):
|
||||||
|
for _ in range(4):
|
||||||
|
next(stream) # `!v
|
||||||
|
self.code = _parse_till_unescaped_char(stream, "`")[0]
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
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. Only
|
||||||
|
'allowed_tokens' are considered to be valid tokens."""
|
||||||
|
stream = _TextIterator(text, offset)
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
done_something = False
|
||||||
|
for token in allowed_tokens:
|
||||||
|
if token.starts_here(stream):
|
||||||
|
yield token(stream, indent)
|
||||||
|
done_something = True
|
||||||
|
break
|
||||||
|
if not done_something:
|
||||||
|
next(stream)
|
||||||
|
except StopIteration:
|
||||||
|
yield EndOfTextToken(stream, indent)
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
#!/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)
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
#!/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,
|
||||||
|
ChoicesToken,
|
||||||
|
TabStopToken,
|
||||||
|
MirrorToken,
|
||||||
|
PythonCodeToken,
|
||||||
|
VimLCodeToken,
|
||||||
|
ShellCodeToken,
|
||||||
|
)
|
||||||
|
from UltiSnips.text_objects import (
|
||||||
|
EscapedChar,
|
||||||
|
Mirror,
|
||||||
|
PythonCode,
|
||||||
|
ShellCode,
|
||||||
|
TabStop,
|
||||||
|
Transformation,
|
||||||
|
VimLCode,
|
||||||
|
Visual,
|
||||||
|
Choices,
|
||||||
|
)
|
||||||
|
|
||||||
|
_TOKEN_TO_TEXTOBJECT = {
|
||||||
|
EscapeCharToken: EscapedChar,
|
||||||
|
VisualToken: Visual,
|
||||||
|
ShellCodeToken: ShellCode,
|
||||||
|
PythonCodeToken: PythonCode,
|
||||||
|
VimLCodeToken: VimLCode,
|
||||||
|
ChoicesToken: Choices,
|
||||||
|
}
|
||||||
|
|
||||||
|
__ALLOWED_TOKENS = [
|
||||||
|
EscapeCharToken,
|
||||||
|
VisualToken,
|
||||||
|
TransformationToken,
|
||||||
|
ChoicesToken,
|
||||||
|
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)
|
||||||
|
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
#!/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.ulti_snips import (
|
||||||
|
UltiSnipsFileSource,
|
||||||
|
find_all_snippet_directories,
|
||||||
|
find_all_snippet_files,
|
||||||
|
find_snippet_files,
|
||||||
|
)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Handles manually added snippets UltiSnips_Manager.add_snippet()."""
|
||||||
|
|
||||||
|
from UltiSnips.snippet.source.base import SnippetSource
|
||||||
|
|
||||||
|
|
||||||
|
class AddedSnippetsSource(SnippetSource):
|
||||||
|
|
||||||
|
"""See module docstring."""
|
||||||
|
|
||||||
|
def add_snippet(self, ft, snippet):
|
||||||
|
"""Adds the given 'snippet' for 'ft'."""
|
||||||
|
self._snippets[ft].add_snippet(snippet)
|
||||||
@ -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:
|
||||||
|
|
||||||
|
"""See module docstring."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._snippets = defaultdict(SnippetDictionary)
|
||||||
|
self._extends = defaultdict(set)
|
||||||
|
|
||||||
|
def ensure(self, filetypes):
|
||||||
|
"""Ensures that snippets are loaded."""
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
"""Resets all snippets, so that they are reloaded on the next call to
|
||||||
|
ensure.
|
||||||
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
@ -0,0 +1 @@
|
|||||||
|
"""Snippet sources that are file based."""
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Code to provide access to UltiSnips files from disk."""
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
import os
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
from UltiSnips import compatibility
|
||||||
|
from UltiSnips.snippet.source.base import SnippetSource
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def ensure(self, filetypes):
|
||||||
|
for ft in self.get_deep_extends(filetypes):
|
||||||
|
if self._needs_update(ft):
|
||||||
|
self._load_snippets_for(ft)
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.__init__()
|
||||||
|
|
||||||
|
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."""
|
||||||
|
return not (ft in self._snippets)
|
||||||
|
|
||||||
|
def _load_snippets_for(self, ft):
|
||||||
|
"""Load all snippets for the given 'ft'."""
|
||||||
|
assert ft not in self._snippets
|
||||||
|
for fn in self._get_all_snippet_files_for(ft):
|
||||||
|
self._parse_snippets(ft, fn)
|
||||||
|
# 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'."""
|
||||||
|
with open(filename, "r", encoding="utf-8") as to_read:
|
||||||
|
file_data = to_read.read()
|
||||||
|
self._snippets[ft] # Make sure the dictionary exists
|
||||||
|
for event, data in self._parse_snippet_file(file_data, filename):
|
||||||
|
if event == "error":
|
||||||
|
msg, line_index = data
|
||||||
|
filename = vim_helper.eval(
|
||||||
|
"""fnamemodify(%s, ":~:.")""" % vim_helper.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)
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Common code for snipMate and UltiSnips snippet files."""
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_file_path(path: str) -> str:
|
||||||
|
"""Calls normpath and normcase on path"""
|
||||||
|
return os.path.normcase(os.path.normpath(path))
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_context(tail, line_index):
|
||||||
|
if tail:
|
||||||
|
return "context", tail.strip('"').replace(r"\"", '"').replace(r"\\\\", r"\\")
|
||||||
|
else:
|
||||||
|
return "error", ("'context' without body", line_index)
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Parses snipMate files."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
from UltiSnips.snippet.definition import SnipMateSnippetDefinition
|
||||||
|
from UltiSnips.snippet.source.file.base import SnippetFileSource
|
||||||
|
from UltiSnips.snippet.source.file.common import handle_extends, normalize_file_path
|
||||||
|
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_helper.eval("&runtimepath").split(","):
|
||||||
|
path = normalize_file_path(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
|
||||||
@ -0,0 +1,216 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
"""Parsing of snippet files."""
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
from UltiSnips import vim_helper
|
||||||
|
from UltiSnips.snippet.definition import UltiSnipsSnippetDefinition
|
||||||
|
from UltiSnips.snippet.source.file.base import SnippetFileSource
|
||||||
|
from UltiSnips.snippet.source.file.common import (
|
||||||
|
handle_action,
|
||||||
|
handle_context,
|
||||||
|
handle_extends,
|
||||||
|
normalize_file_path,
|
||||||
|
)
|
||||||
|
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(str(directory))
|
||||||
|
for pattern in patterns:
|
||||||
|
for fn in glob.glob(os.path.join(directory, pattern % ft)):
|
||||||
|
ret.add(normalize_file_path(fn))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def find_all_snippet_directories():
|
||||||
|
"""Returns a list of the absolute path of all potential snippet
|
||||||
|
directories, no matter if they exist or not."""
|
||||||
|
|
||||||
|
if vim_helper.eval("exists('b:UltiSnipsSnippetDirectories')") == "1":
|
||||||
|
snippet_dirs = vim_helper.eval("b:UltiSnipsSnippetDirectories")
|
||||||
|
else:
|
||||||
|
snippet_dirs = vim_helper.eval("g:UltiSnipsSnippetDirectories")
|
||||||
|
|
||||||
|
if len(snippet_dirs) == 1:
|
||||||
|
# To reduce confusion and increase consistency with
|
||||||
|
# `UltiSnipsSnippetsDir`, we expand ~ here too.
|
||||||
|
full_path = os.path.expanduser(str(snippet_dirs[0]))
|
||||||
|
if os.path.isabs(full_path):
|
||||||
|
return [full_path]
|
||||||
|
|
||||||
|
all_dirs = []
|
||||||
|
check_dirs = vim_helper.eval("&runtimepath").split(",")
|
||||||
|
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 = normalize_file_path(
|
||||||
|
os.path.expanduser(str(os.path.join(rtp, snippet_dir)))
|
||||||
|
)
|
||||||
|
all_dirs.append(pth)
|
||||||
|
return all_dirs
|
||||||
|
|
||||||
|
|
||||||
|
def find_all_snippet_files(ft):
|
||||||
|
"""Returns all snippet files matching 'ft' in the given runtime path
|
||||||
|
directory."""
|
||||||
|
patterns = ["%s.snippets", "%s_*.snippets", os.path.join("%s", "*")]
|
||||||
|
ret = set()
|
||||||
|
for directory in find_all_snippet_directories():
|
||||||
|
if not os.path.isdir(directory):
|
||||||
|
continue
|
||||||
|
for pattern in patterns:
|
||||||
|
for fn in glob.glob(os.path.join(directory, pattern % ft)):
|
||||||
|
ret.add(fn)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def _handle_snippet_or_global(
|
||||||
|
filename, line, lines, python_globals, priority, pre_expand, context
|
||||||
|
):
|
||||||
|
"""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()
|
||||||
|
|
||||||
|
if "e" in opts and not context:
|
||||||
|
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 = {}
|
||||||
|
context = None
|
||||||
|
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,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
actions = {}
|
||||||
|
context = None
|
||||||
|
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 == "context":
|
||||||
|
head, context, = handle_context(tail, lines.line_index)
|
||||||
|
if head == "error":
|
||||||
|
yield (head, tail)
|
||||||
|
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
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user