Added some more comments
This commit is contained in:
parent
db2fde89a1
commit
7dfd213402
1 changed files with 24 additions and 15 deletions
39
c4ctrl.vim
39
c4ctrl.vim
|
@ -40,13 +40,17 @@ endfunction
|
||||||
|
|
||||||
|
|
||||||
function C4ctrl(command, ...)
|
function C4ctrl(command, ...)
|
||||||
" Valid commands are get,open,set,text and write
|
" ********************************************************************* "
|
||||||
|
" Make some functionality of the 'c4ctrl' command line script available "
|
||||||
|
" from within Vim. "
|
||||||
|
" Available commands are 'get', 'open', 'set', 'text' and 'write'. "
|
||||||
|
" ********************************************************************* "
|
||||||
|
|
||||||
" Our name
|
" Name of the executable.
|
||||||
let s:c4ctrl = "c4ctrl"
|
let s:c4ctrl = "c4ctrl"
|
||||||
|
|
||||||
" This function will be called after a preset file has been loaded
|
" This function will be called after a preset file has been loaded
|
||||||
" into the buffer.k
|
" into the buffer.
|
||||||
function s:SynHighlight()
|
function s:SynHighlight()
|
||||||
syn match Identifier "^[ \t]*[0-9a-zA-Z/]*"
|
syn match Identifier "^[ \t]*[0-9a-zA-Z/]*"
|
||||||
" Match values like 03f with optional space between
|
" Match values like 03f with optional space between
|
||||||
|
@ -59,11 +63,12 @@ function C4ctrl(command, ...)
|
||||||
" Check if we can excute c4ctrl or c4ctrl.py and modify the variable
|
" Check if we can excute c4ctrl or c4ctrl.py and modify the variable
|
||||||
" s:c4ctrl accordingly
|
" s:c4ctrl accordingly
|
||||||
if !executable(s:c4ctrl)
|
if !executable(s:c4ctrl)
|
||||||
" Maybe we judt need to add .py to the command?
|
" Maybe we just need to add .py to the command?
|
||||||
if executable(s:c4ctrl.".py")
|
if executable(s:c4ctrl.".py")
|
||||||
let s:c4ctrl = s:c4ctrl.".py"
|
let s:c4ctrl .= ".py"
|
||||||
else
|
else
|
||||||
echoerr "Executable not found! Please put \"".s:c4ctrl."\" into your $PATH."
|
echoerr "Executable not found! Please put \"".s:c4ctrl."\" into your $PATH."
|
||||||
|
unlet s:c4ctrl
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
@ -73,7 +78,7 @@ function C4ctrl(command, ...)
|
||||||
" Read current status into new buffer "
|
" Read current status into new buffer "
|
||||||
" *********************************** "
|
" *********************************** "
|
||||||
if getbufinfo("%")[0].changed
|
if getbufinfo("%")[0].changed
|
||||||
vnew
|
new
|
||||||
endif
|
endif
|
||||||
silent execute "0 read !" s:c4ctrl "-o -"
|
silent execute "0 read !" s:c4ctrl "-o -"
|
||||||
call s:SynHighlight()
|
call s:SynHighlight()
|
||||||
|
@ -91,18 +96,20 @@ function C4ctrl(command, ...)
|
||||||
if s:cfgdir == ""
|
if s:cfgdir == ""
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let s:fn = s:cfgdir . a:1
|
let s:filename = s:cfgdir . a:1
|
||||||
if !filereadable(s:fn)
|
if !filereadable(s:filename)
|
||||||
echoerr "Error: could not open file" s:fn
|
echoerr "Error: could not open file" s:filename
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if getbufinfo("%")[0].changed
|
if getbufinfo("%")[0].changed
|
||||||
vnew
|
new
|
||||||
endif
|
endif
|
||||||
execute "edit" fnameescape(s:fn)
|
execute "edit" fnameescape(s:filename)
|
||||||
call s:SynHighlight()
|
call s:SynHighlight()
|
||||||
|
|
||||||
|
unlet! s:filename
|
||||||
|
|
||||||
elseif stridx("set", a:command) == 0
|
elseif stridx("set", a:command) == 0
|
||||||
" ****************************** "
|
" ****************************** "
|
||||||
" Set preset from current buffer "
|
" Set preset from current buffer "
|
||||||
|
@ -112,7 +119,7 @@ function C4ctrl(command, ...)
|
||||||
let s:command_line = s:c4ctrl
|
let s:command_line = s:c4ctrl
|
||||||
if a:0 == 0
|
if a:0 == 0
|
||||||
" If no room is given, set colors for all rooms
|
" If no room is given, set colors for all rooms
|
||||||
let s:command_line = s:command_line . " -w - -p - -f -"
|
let s:command_line .= " -w - -p - -f -"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for s:i in range(a:0)
|
for s:i in range(a:0)
|
||||||
|
@ -161,15 +168,17 @@ function C4ctrl(command, ...)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:fn = s:cfgdir . a:1
|
let s:filename = s:cfgdir . a:1
|
||||||
|
|
||||||
if strridx(a:command, "!") + 1 == len(a:command)
|
if strridx(a:command, "!") + 1 == len(a:command)
|
||||||
" Force if a '!' was appended to the command
|
" Force if a '!' was appended to the command
|
||||||
execute "saveas!" fnameescape(s:fn)
|
execute "saveas!" fnameescape(s:filename)
|
||||||
else
|
else
|
||||||
execute "saveas" fnameescape(s:fn)
|
execute "saveas" fnameescape(s:filename)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
unlet! s:filename
|
||||||
|
|
||||||
else
|
else
|
||||||
" ****************** "
|
" ****************** "
|
||||||
" Unknown command oO "
|
" Unknown command oO "
|
||||||
|
|
Loading…
Reference in a new issue