Fix formatting

This commit is contained in:
IdanArye 2018-09-25 02:08:25 +03:00
parent 2f88c8db15
commit 4fac68fb95

View File

@ -1,127 +1,127 @@
"Returns the visually selected text "Returns the visually selected text
function! vebugger#util#get_visual_selection() function! vebugger#util#get_visual_selection()
"Shamefully stolen from http://stackoverflow.com/a/6271254/794380 "Shamefully stolen from http://stackoverflow.com/a/6271254/794380
" Why is this not a built-in Vim script function?! " Why is this not a built-in Vim script function?!
let [lnum1, col1] = getpos("'<")[1:2] let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2] let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2) let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:] let lines[0] = lines[0][col1 - 1:]
return join(lines, "\n") return join(lines, "\n")
endfunction endfunction
"Prompts the user with a filtered list of process, and returns the process id "Prompts the user with a filtered list of process, and returns the process id
"the user selects "the user selects
function! vebugger#util#selectProcessOfFile(ofFile) function! vebugger#util#selectProcessOfFile(ofFile)
let l:fileName=fnamemodify(a:ofFile,':t') let l:fileName=fnamemodify(a:ofFile,':t')
if has('win32') if has('win32')
"Get the process data in CSV format "Get the process data in CSV format
let l:resultLines=split(vimproc#system('tasklist /FO csv /FI "IMAGENAME eq '.l:fileName.'"'),'\r\n\|\n\|\r') let l:resultLines=split(vimproc#system('tasklist /FO csv /FI "IMAGENAME eq '.l:fileName.'"'),'\r\n\|\n\|\r')
if l:resultLines[0]=~'\V\^INFO:' if l:resultLines[0]=~'\V\^INFO:'
throw 'No matching process found' throw 'No matching process found'
endif endif
"Parse(sort of) the CSV: "Parse(sort of) the CSV:
let l:resultLinesParsed=map(l:resultLines,'eval("[".v:val."]")') let l:resultLinesParsed=map(l:resultLines,'eval("[".v:val."]")')
let l:resultLinesParsed[0][2]='Session' let l:resultLinesParsed[0][2]='Session'
"Format for output "Format for output
let l:linesForPrinting=map(copy(l:resultLinesParsed),'v:val[1]."\t".v:val[2]."\t\t".v:val[0]') let l:linesForPrinting=map(copy(l:resultLinesParsed),'v:val[1]."\t".v:val[2]."\t\t".v:val[0]')
else else
let l:resultLines=split(vimproc#system('ps -o pid,user,comm,start,state,tt -C '.fnameescape(l:fileName)),'\r\n\|\n\|\r') let l:resultLines=split(vimproc#system('ps -o pid,user,comm,start,state,tt -C '.fnameescape(l:fileName)),'\r\n\|\n\|\r')
let l:linesForPrinting=copy(l:resultLines) let l:linesForPrinting=copy(l:resultLines)
endif endif
if len(l:linesForPrinting)<=1 if len(l:linesForPrinting)<=1
throw 'No matching process found' throw 'No matching process found'
endif endif
if &lines<len(l:linesForPrinting) if &lines<len(l:linesForPrinting)
throw 'Too many matching processes found' throw 'Too many matching processes found'
endif endif
"Add numbers to the lines "Add numbers to the lines
for l:i in range(1,len(l:linesForPrinting)-1) for l:i in range(1,len(l:linesForPrinting)-1)
let l:linesForPrinting[l:i]=repeat(' ',3-len(l:i)).l:i.') '.(l:linesForPrinting[l:i]) let l:linesForPrinting[l:i]=repeat(' ',3-len(l:i)).l:i.') '.(l:linesForPrinting[l:i])
endfor endfor
"Indent the title line(since it doesn't have a number) "Indent the title line(since it doesn't have a number)
let l:linesForPrinting[0]=' '.l:linesForPrinting[0] let l:linesForPrinting[0]=' '.l:linesForPrinting[0]
"Get the selection "Get the selection
let l:chosenId=inputlist(l:linesForPrinting) let l:chosenId=inputlist(l:linesForPrinting)
if l:chosenId<1 if l:chosenId<1
\|| len(l:resultLines)<=l:chosenId \|| len(l:resultLines)<=l:chosenId
return 0 return 0
endif endif
if has('win32') if has('win32')
return str2nr(l:resultLinesParsed[l:chosenId][1]) return str2nr(l:resultLinesParsed[l:chosenId][1])
else else
let l:chosenLine=l:resultLines[l:chosenId] let l:chosenLine=l:resultLines[l:chosenId]
let g:chosenLine = l:chosenLine let g:chosenLine = l:chosenLine
return str2nr(matchstr(l:chosenLine,'\v^\s*\zs(\d+)\ze\s*')) return str2nr(matchstr(l:chosenLine,'\v^\s*\zs(\d+)\ze\s*'))
endif endif
endfunction endfunction
"Escape args(from a debugger's extra arguments) as a command line arguments "Escape args(from a debugger's extra arguments) as a command line arguments
"string "string
function! vebugger#util#commandLineArgsForProgram(debuggerArgs) function! vebugger#util#commandLineArgsForProgram(debuggerArgs)
if has_key(a:debuggerArgs,'args') if has_key(a:debuggerArgs,'args')
if type(a:debuggerArgs.args)==type([]) if type(a:debuggerArgs.args)==type([])
return join(map(a:debuggerArgs.args,'s:argEscape(v:val)'),' ') return join(map(a:debuggerArgs.args,'s:argEscape(v:val)'),' ')
elseif type(a:debuggerArgs.args)==type('') elseif type(a:debuggerArgs.args)==type('')
return a:debuggerArgs.args return a:debuggerArgs.args
else else
return string(a:debuggerArgs.args) return string(a:debuggerArgs.args)
endif endif
endif endif
endfunction endfunction
"Escape a single argument for the command line "Escape a single argument for the command line
function! s:argEscape(arg) function! s:argEscape(arg)
if has('win32') if has('win32')
return shellescape(a:arg) return shellescape(a:arg)
else else
return '"'.escape(a:arg,'"').'"' return '"'.escape(a:arg,'"').'"'
end end
endfunction endfunction
"Return a tool's(usually debugger) full path, or revert to default if that "Return a tool's(usually debugger) full path, or revert to default if that
"path is not defined "path is not defined
function! vebugger#util#getToolFullPath(toolName,version,default) function! vebugger#util#getToolFullPath(toolName,version,default)
let l:optionName='vebugger_path_'.a:toolName let l:optionName='vebugger_path_'.a:toolName
if !empty(a:version) if !empty(a:version)
let l:optionName=l:optionName.'_'.a:version let l:optionName=l:optionName.'_'.a:version
endif endif
if exists('g:'.l:optionName) if exists('g:'.l:optionName)
return g:[l:optionName] return g:[l:optionName]
else else
if type({})==type(a:default) if type({})==type(a:default)
if !empty(a:version) && has_key(a:default,a:version) if !empty(a:version) && has_key(a:default,a:version)
return a:default[a:version] return a:default[a:version]
else else
return a:default[' '] return a:default[' ']
endif endif
else else
return a:default return a:default
endif endif
endif endif
endfunction endfunction
"Checks if the path is an absolute path "Checks if the path is an absolute path
function! vebugger#util#isPathAbsolute(path) function! vebugger#util#isPathAbsolute(path)
if has('win32') if has('win32')
return a:path=~':' || a:path[0]=='%' "Absolute paths in Windows contain : or start with an environment variable return a:path=~':' || a:path[0]=='%' "Absolute paths in Windows contain : or start with an environment variable
else else
return a:path[0]=~'\v^[/~$]' "Absolute paths in Linux start with ~(home),/(root dir) or $(environment variable) return a:path[0]=~'\v^[/~$]' "Absolute paths in Linux start with ~(home),/(root dir) or $(environment variable)
endif endif
endfunction endfunction
function! vebugger#util#WinShellSlash(path) function! vebugger#util#WinShellSlash(path)
if has('win32') && &shellslash if has('win32') && &shellslash
return substitute(a:path, '\\', '/', 'g') return substitute(a:path, '\\', '/', 'g')
else else
return a:path return a:path
endif endif
endfunction endfunction
function! vebugger#util#listify(stringOrList) function! vebugger#util#listify(stringOrList)
@ -136,24 +136,27 @@ endfunction
" others. " others.
function! vebugger#util#EnglishExecute(command) abort function! vebugger#util#EnglishExecute(command) abort
let l:lang = matchstr(execute('language messages'), '"\zs.*\ze"') let l:lang = matchstr(execute('language messages'), '"\zs.*\ze"')
if l:lang !~ 'en' | language messages en_US.utf8 | endif if l:lang !~ 'en'
language messages en_US.utf8
endif
let l:result = execute(a:command) let l:result = execute(a:command)
if l:lang !~ 'en' | language messages l:lang | endif if l:lang !~ 'en'
language messages l:lang
endif
return l:result return l:result
endfunction endfunction
function! s:listSigns(filter) abort function! s:listSigns(filter) abort
let l:result = [] let l:result = []
for l:line in split(vebugger#util#EnglishExecute('sign place '.a:filter), '\n') for l:line in split(vebugger#util#EnglishExecute('sign place '.a:filter), '\n')
let l:match = matchlist(l:line, '\C\v^\s+line\=(\d+)\s+id\=(\d+)\s+name\=(.+)$') let l:match = matchlist(l:line, '\C\v^\s+line\=(\d+)\s+id\=(\d+)\s+name\=(.+)$')
if !empty(l:match) if !empty(l:match)
call add(l:result, { call add(l:result, {
\ 'line': str2nr(l:match[1]), \ 'line': str2nr(l:match[1]),
\ 'id': str2nr(l:match[2]), \ 'id': str2nr(l:match[2]),
\ 'name': l:match[3], \ 'name': l:match[3],
\ }) \ })
endif endif
endfor endfor
return l:result return l:result
endfunction endfunction