|
-- Complete by command for NYAOS 3.x |
|
-- |
|
-- Maintainer: DeaR <[email protected]> |
|
-- Last Change: 13-Aug-2013. |
|
-- License: MIT License {{{ |
|
-- Copyright (c) 2013 DeaR <[email protected]> |
|
-- Copyright (c) 2011 azu_re |
|
-- Copyright (c) 2010 wantora |
|
-- |
|
-- 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. |
|
-- }}} |
|
|
|
nyaos_complete_by = {} |
|
|
|
function nyaos.complete(basestring, pos, misc) |
|
local cl = misc.text:match('[;|]') and misc.text:match('[^;|]+$') or misc.text |
|
local cmd = (cl:match('^%s*\034([^\034]+)\034') or cl:match('^%s*([^%s]+)') or ''):match('[^/\\]+$') |
|
return cmd and nyaos_complete_by[cmd] and nyaos_complete_by[cmd](basestring, pos, misc) or nyaos.default_complete(basestring, pos) |
|
end |
|
|
|
-- _nya_git.lua |
|
local completes_cache = {} |
|
function nyaos_complete_by.hg(basestring, pos, misc) |
|
if not completes_cache['hg'] then |
|
local cmds = nyaos.default_complete(basestring, pos) |
|
local function insert_cmd(str) |
|
for line in (str:match('\nlist of commands:\n\n(.-)\n\n') or ''):gmatch('[^\n]+') do |
|
local name = line:match('^ ([^%s:,]+)') |
|
if name then |
|
table.insert(cmds, name) |
|
end |
|
end |
|
end |
|
local HGPLAIN = os.getenv('HGPLAIN') or '' |
|
nyaos.exec('set HGPLAIN=1') |
|
h = nyaos.eval('hg help -v') |
|
insert_cmd(h) |
|
for line in (h:match('\nenabled extensions:\n\n(.-)\n\n') or ''):gmatch('[^\n]+') do |
|
insert_cmd(nyaos.eval('hg help '..line:match('^ ([^%s]*)')..' -v')) |
|
end |
|
nyaos.exec('set HGPLAIN='..HGPLAIN) |
|
completes_cache['hg'] = cmds |
|
end |
|
return completes_cache['hg'] |
|
end |
|
function nyaos_complete_by.gem(basestring, pos, misc) |
|
if not completes_cache['gem'] then |
|
local cmds = nyaos.default_complete(basestring, pos) |
|
for line in nyaos.eval('gem help commands'):gmatch('[^\n]+') do |
|
local name = line:match('^ ([^%s]*)') |
|
if #cmds > 0 and (not name) then |
|
break |
|
end |
|
if name and #name > 0 then |
|
table.insert(cmds, name) |
|
end |
|
end |
|
completes_cache['gem'] = cmds |
|
end |
|
return completes_cache['gem'] |
|
end |
|
function nyaos_complete_by.git(basestring, pos, misc) |
|
function ArrayUnique(arr) |
|
local key = {}; |
|
local ret = {}; |
|
for k, v in pairs(arr) do |
|
if type(key[v]) == [[nil]] then |
|
key[v] = v; |
|
table.insert(ret,v); |
|
end |
|
end |
|
return ret; |
|
end |
|
if not completes_cache['git'] then |
|
local cmds = nyaos.default_complete(basestring, pos) |
|
for line in nyaos.eval('git help -a'):gmatch('[^\n]+') do |
|
if line:match('^%s') then |
|
for name in line:gmatch('%s+([%w-]*)') do |
|
if #cmds > 0 and (not name) then |
|
break |
|
end |
|
if name and #name > 1 then |
|
table.insert(cmds, name) |
|
end |
|
end |
|
end |
|
end |
|
for line in nyaos.eval('git help'):gmatch('[^\n]+') do |
|
local name = line:match('^ ([%w-]*)') |
|
if name and #name > 0 then |
|
table.insert(cmds, name) |
|
end |
|
end |
|
completes_cache['git'] = ArrayUnique(cmds) |
|
end |
|
return completes_cache['git'] |
|
end |
|
nyaos_complete_by['hg.exe'] = nyaos_complete_by.hg |
|
nyaos_complete_by['gem.exe'] = nyaos_complete_by.gem |
|
nyaos_complete_by['git.exe'] = nyaos_complete_by.git |
|
|
|
-- vim: ft=lua |
_nya_git.lua との違い
z.lua
はbasestring
によって動的に生成している)C:\Program Files\Mercurial\hg.exe
の様なのもhg.exe
として関数を呼ばれる