Last active
December 11, 2015 06:58
-
-
Save chemzqm/7501f2ba0ccab3e5030c to your computer and use it in GitHub Desktop.
配置 unite-js-func 这些配置实现了通过 :F(a/t/r/e/m) name 快速查找函数的功能
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
#!/usr/bin/env node | |
var fs = require('fs') | |
var path = require('path') | |
var moduleName = process.argv[2] | |
var dir = process.cwd() | |
function exit(msg, code) { | |
console.error(msg) | |
process.exit(1) | |
} | |
function locate(folder, name) { | |
if(folder === '/') return '' | |
var f= path.join(folder, name) | |
if (fs.existsSync(f)) { | |
return f | |
} else { | |
return locate(path.resolve(folder, '..'), name) | |
} | |
} | |
var f = locate(dir, 'package.json') | |
if (!f) exit('package.json not found in ' + dir) | |
var o = require(f) | |
if (o.browser && o.browser[moduleName]) { | |
var str = o.browser[moduleName] | |
if (typeof str === 'string') { | |
moduleName = str | |
} | |
} | |
var deps = Object.keys(o.dependencies) | |
var browsers = Object.keys(o.browser).map(function (key) { | |
return o.browser[key] | |
}) | |
var deps = deps.filter(function (n) { | |
return browsers.indexOf(n) === -1 | |
}) | |
deps = deps.concat(Object.keys(o.browser)) | |
deps.forEach(function (dep) { | |
console.log(dep) | |
}) |
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
function! SetLoadFunctions() | |
command! -nargs=? -bar -buffer F execute 'call LoadFunctions("c", "<args>")' | |
command! -nargs=? -bar -buffer Ft execute 'call LoadFunctions("t", "<args>")' | |
command! -nargs=? -bar -buffer Fr execute 'call LoadFunctions("r", "<args>")' | |
command! -nargs=? -bar -buffer Fa execute 'call LoadFunctions("a", "<args>")' | |
command! -nargs=? -bar -buffer Fe execute 'call LoadFunctions("e", "<args>")' | |
command! -nargs=+ -bar -buffer -complete=custom,ListModules Fm execute 'call LoadFunctions("m", "<args>")' | |
endfunction | |
function! ListModules(A, L, p) | |
let res = system("dependencies") | |
if v:shell_error | echo res | return | endif | |
return res | |
endfunction | |
function! LoadFunctions(type, args) | |
let args = split(a:args, ' ') | |
if !len(args)| let args = [''] |endif | |
let input = args[0] | |
let type = a:type | |
let name ='' | |
if a:type ==# 'a' | |
let type = 'm' | |
endif | |
if a:type ==# 'm' | |
let type = "m" | |
let name = args[0] | |
let input = len(args) > 1 ? args[1] : '' | |
endif | |
if len(name) | |
execute 'Unite func -custom-func-type=' . type . ' -custom-func-name=' . name . ' -input=' . input | |
else | |
execute 'Unite func -custom-func-type=' . type . ' -input=' . input | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies 用于自动补全