forked from quangnguyen30192/cmp-nvim-ultisnips
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract Python code to separate file
- Loading branch information
Showing
6 changed files
with
56 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import vim | ||
from UltiSnips import UltiSnips_Manager, vim_helper | ||
|
||
# Retrieves additional snippet information that is not directly accessible | ||
# using the UltiSnips API functions. Stores a list of dictionaries (one per | ||
# snippet) with the keys "trigger", "description", "options" and "value" | ||
# in the vim variable g:_cmpu_current_snippets. | ||
# | ||
# If 'expandable_only' is True, only expandable snippets are stored, otherwise | ||
# all snippets for the current filetype are added. | ||
|
||
|
||
cmpu_cur_snippet = None | ||
|
||
|
||
def fetch_current_snippets(expandable_only): | ||
if expandable_only: | ||
before = vim_helper.buf.line_till_cursor | ||
snippets = UltiSnips_Manager._snips(before, True) | ||
else: | ||
snippets = UltiSnips_Manager._snips("", True) | ||
|
||
vim.command("let g:_cmpu_current_snippets = []") | ||
global cmpu_cur_snippet | ||
for snippet in snippets: | ||
cmpu_cur_snippet = snippet | ||
vim.command( | ||
"call add(g:_cmpu_current_snippets, {" | ||
"'trigger': pyxeval('str(cmpu_cur_snippet._trigger)')," | ||
"'description': pyxeval('str(cmpu_cur_snippet._description)')," | ||
"'options': pyxeval('str(cmpu_cur_snippet._opts)')," | ||
"'value': pyxeval('str(cmpu_cur_snippet._value)')," | ||
"})" | ||
) | ||
|
||
|
||
def set_filetype(ft): | ||
class CustomVimBuffer(vim_helper.VimBuffer): | ||
@property | ||
def filetypes(self): | ||
return [ft] | ||
|
||
vim_helper._orig_buf = vim_helper.buf | ||
vim_helper.buf = CustomVimBuffer() | ||
|
||
|
||
def reset_filetype(): | ||
vim_helper.buf = vim_helper._orig_buf |