Skip to content
This repository was archived by the owner on Mar 21, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions autoload/cmakecomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let s:cmake_properties = []
let s:cmake_modules = []
let s:cmake_variables = []
let s:cmake_command_examples = {}
let s:cmake_major_version = 0

function s:createbuffer()
let counter = 0
Expand All @@ -45,12 +46,27 @@ function s:createbuffer()
return versionedName
endfunction

function! s:getCompletionList(listname)
if index(['commands', 'properties', 'variables', 'modules'], a:listname) == -1
return []
endif
let completion_list = get(s:, 'cmake_' . a:listname, [])
if empty(completion_list)
if cmakecomplete#Version() == 2
call cmakecomplete#Init(a:listname, completion_list, a:listname == 'properties' ? 0 : 1)
else
call cmakecomplete#Init3(a:listname, completion_list, a:listname == 'properties' ? 0 : 1)
endif
endif
return completion_list
endfunction

function cmakecomplete#Help(...)
" create a new buffer and show all of cmake's help there
let output = ""
if a:0 == 1
let arg = tolower(a:1)
let searchlist = [s:cmake_commands, s:cmake_properties, s:cmake_modules, s:cmake_variables]
let searchlist = [s:getCompletionList('commands'), s:getCompletionList('properties'), s:getCompletionList('modules'), s:getCompletionList('variables')]
for sl in searchlist
for m in sl
if m['word'] == arg
Expand Down Expand Up @@ -97,13 +113,14 @@ function cmakecomplete#PrintExamples()
endfunc

function cmakecomplete#Version()
let output = system('cmake --version')
for c in split(output, '\n')
if c =~ 'version'
let components = split(c, ' ')
return components[len(components) - 1]
endif
endfor
if s:cmake_major_version > 0
return s:cmake_major_version
else
let output = systemlist('cmake --version')
let version_number = split(output[0], ' ')[-1]
let s:cmake_major_version = split(version_number, '\.')[0]
return s:cmake_major_version
endif
endfunc

function cmakecomplete#Init3(help, list, ignore_case)
Expand Down Expand Up @@ -310,27 +327,27 @@ function! cmakecomplete#Complete(findstart, base)
endif

let res = []
let list = s:cmake_commands
let list = s:getCompletionList('commands')
let match = '^' . tolower(a:base)
if cmakecomplete#InVariable()
let match = '^' . a:base
let list = s:cmake_variables
let list = s:getCompletionList('variables')
elseif cmakecomplete#InInclude()
" return modules
let match = '^' . a:base
let list = s:cmake_modules
let list = s:getCompletionList('modules')
elseif cmakecomplete#InFunction()
" return completion variables
let match = '^' . a:base
let fname = cmakecomplete#InFunctionName()
if has_key(s:cmake_command_examples, fname)
let list = cmakecomplete#GetArguments(fname)
else
let list = s:cmake_properties
let list = s:getCompletionList('properties')
endif
let prevword = cmakecomplete#PreviousWord()
if prevword == "PROPERTIES"
let list = s:cmake_properties
let list = s:getCompletionList('properties')
endif
endif
" return the completion words
Expand All @@ -346,7 +363,7 @@ endfunction
function cmakecomplete#HelpComplete(ArgLead, CmdLine, CursorPos)
let result = []
let match = '^' . a:ArgLead
for m in s:cmake_commands
for m in s:getCompletionList('commands')
let w = m['word']
if w =~ match
call add(result, w)
Expand All @@ -355,17 +372,5 @@ function cmakecomplete#HelpComplete(ArgLead, CmdLine, CursorPos)
return result
endfunction

if cmakecomplete#Version() =~ "^2\."
call cmakecomplete#Init('commands', s:cmake_commands, 1)
call cmakecomplete#Init('properties', s:cmake_properties, 0)
call cmakecomplete#Init('modules', s:cmake_modules, 1)
call cmakecomplete#Init('variables', s:cmake_variables, 1)
else
call cmakecomplete#Init3('commands', s:cmake_commands, 1)
call cmakecomplete#Init3('properties', s:cmake_properties, 0)
call cmakecomplete#Init3('modules', s:cmake_modules, 1)
call cmakecomplete#Init3('variables', s:cmake_variables, 1)
endif

let &cpo = s:keepcpo
unlet s:keepcpo