forked from Yggdroot/LeaderF
-
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.
Add comamnd LeaderfFiletype (Yggdroot#454)
* Add feature LeaderF filetype * Update doc, README Add filetype description * Add LeaderfFiletype to selfExpl * Fix help (F1) of LeaderfFiletype * Use getFreshContent()
- Loading branch information
Showing
9 changed files
with
128 additions
and
6 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
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,29 @@ | ||
" ============================================================================ | ||
" File: Filetype.vim | ||
" Description: | ||
" Author: tamago324 <[email protected]> | ||
" Website: https://github.com/tamago324 | ||
" Note: | ||
" License: Apache License, Version 2.0 | ||
" ============================================================================ | ||
|
||
if leaderf#versionCheck() == 0 | ||
finish | ||
endif | ||
|
||
exec g:Lf_py "from leaderf.filetypeExpl import *" | ||
|
||
function! leaderf#Filetype#Maps() | ||
nmapclear <buffer> | ||
nnoremap <buffer> <silent> <CR> :exec g:Lf_py "filetypeExplManager.accept()"<CR> | ||
nnoremap <buffer> <silent> o :exec g:Lf_py "filetypeExplManager.accept()"<CR> | ||
nnoremap <buffer> <silent> <2-LeftMouse> :exec g:Lf_py "filetypeExplManager.accept()"<CR> | ||
nnoremap <buffer> <silent> q :exec g:Lf_py "filetypeExplManager.quit()"<CR> | ||
nnoremap <buffer> <silent> i :exec g:Lf_py "filetypeExplManager.input()"<CR> | ||
nnoremap <buffer> <silent> <F1> :exec g:Lf_py "filetypeExplManager.toggleHelp()"<CR> | ||
if has_key(g:Lf_NormalMap, "Filetype") | ||
for i in g:Lf_NormalMap["Filetype"] | ||
exec 'nnoremap <buffer> <silent> '.i[0].' '.i[1] | ||
endfor | ||
endif | ||
endfunction |
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,81 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import os.path | ||
from leaderf.utils import * | ||
from leaderf.explorer import * | ||
from leaderf.manager import * | ||
|
||
|
||
# ***************************************************** | ||
# FiletypeExplorer | ||
# ***************************************************** | ||
class FiletypeExplorer(Explorer): | ||
def __init__(self): | ||
self._content = [] | ||
|
||
def getContent(self, *args, **kwargs): | ||
if self._content: | ||
return self._content | ||
else: | ||
return self.getFreshContent() | ||
|
||
def getFreshContent(self, *args, **kwargs): | ||
result = [ | ||
os.path.basename(f).replace(".vim", "") | ||
for f in lfEval("globpath(&rtp, 'syntax/*.vim')").split("\n") | ||
] | ||
|
||
# to unique | ||
self._content = sorted(set(x for x in result)) | ||
|
||
return self._content | ||
|
||
def getStlCategory(self): | ||
return "Filetype" | ||
|
||
def getStlCurDir(self): | ||
return escQuote(lfEncode(os.getcwd())) | ||
|
||
|
||
# ***************************************************** | ||
# FiletypeExplManager | ||
# ***************************************************** | ||
class FiletypeExplManager(Manager): | ||
def __init__(self): | ||
super(FiletypeExplManager, self).__init__() | ||
|
||
def _getExplClass(self): | ||
return FiletypeExplorer | ||
|
||
def _defineMaps(self): | ||
lfCmd("call leaderf#Filetype#Maps()") | ||
|
||
def _acceptSelection(self, *args, **kwargs): | ||
if len(args) == 0: | ||
return | ||
lfCmd("set filetype=" + args[0]) | ||
|
||
def _getDigest(self, line, mode): | ||
return line | ||
|
||
def _getDegestStartPos(self, line, mode): | ||
return 0 | ||
|
||
def _createHelp(self): | ||
help = [] | ||
help.append('" <CR>/o : set filetype under cursor') | ||
help.append('" q : quit') | ||
help.append('" i : switch to input mode') | ||
help.append('" <F1> : toggle this help') | ||
help.append('" ---------------------------------------------------------') | ||
return help | ||
|
||
|
||
# ***************************************************** | ||
# filetypeExplManager is a singleton | ||
# ***************************************************** | ||
filetypeExplManager = FiletypeExplManager() | ||
|
||
__all__ = ["filetypeExplManager"] |
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