+ SessionMan

This commit is contained in:
Stefan Liebl 2016-10-26 15:22:37 +02:00
parent f21f555b03
commit 2247fbf691
4 changed files with 52 additions and 471 deletions

3
.gitmodules vendored
View File

@ -65,3 +65,6 @@
[submodule "pack/asyncrun/opt/asyncrun"]
path = pack/asyncrun/opt/asyncrun
url = https://github.com/skywind3000/asyncrun.vim.git
[submodule "pack/sessionman/opt/sessionman"]
path = pack/sessionman/opt/sessionman
url = https://github.com/vim-scripts/sessionman.vim.git

@ -0,0 +1 @@
Subproject commit 845d35b84c5c51f631d8bfa4afe3edc126102ba9

View File

@ -4,457 +4,13 @@
" Description: some usefull tools
" ===========================================================================
" ----------------
" Project settings
" ----------------
if !exists("basedir")
let g:basedir = getcwd()
endif
let s:projectFileNames = [
\ 'project.vim',
\ 'makefile',
\ 'Makefile',
\ 'makefile.mak',
\ 'Makefile.mak',
\ 'make.bat',
\ 'make_fsw.bat']
let g:projectsFile = fnamemodify($VIMRUNTIME . '/../projects.txt', ':p')
" ----------
" SetProject
" ----------
command -complete=customlist,GetAllProjectFiles -nargs=? SetProject call s:SetProject('<args>')
"function GetAllProjectFiles(ArgLead, CmdLine, CursorPos)
function GetAllProjectFiles(...)
let makefilePaths = []
" Get Makefiles from g:WA or ArgLead
if exists('g:WA')
let path = g:WA
if a:0 == 3
let ArgLead = a:1
let CmdLine = a:2
let CursorPos = a:3
if ArgLead != ''
let path = expand(ArgLead)
endif
endif
let makefilePaths += s:GetAllProjectFilesInPath(path)
endif
if makefilePaths == []
" Get Projects from project.txt
let projectPaths = s:GetProjectPaths(g:projectsFile)
for projectPath in projectPaths
let makefilePaths += s:GetAllProjectFilesInPath(projectPath)
endfor
endif
return makefilePaths
endfunction
" Get all Makefiles defined in s:projectFileNames contained in path
function s:GetAllProjectFilesInPath(path)
let files = []
if isdirectory(a:path)
let path = a:path
else
let path = a:path . '*'
endif
for makefileName in s:projectFileNames
let pathlist = path . ',' . path . '/*,' . path . '/*/*,' . path . '/*/*/*'
let newfiles = split(globpath(pathlist, makefileName))
let files += newfiles
" echo files
endfor
return files
endfunction
" Get Project-Paths from project.txt
function s:GetProjectPaths(projectsFile)
let paths = []
if filereadable(a:projectsFile)
let paths = split(system('more ' . a:projectsFile))
endif
return paths
endfunction
" Find projectfile and set some options
" -------------------------------------
function s:SetProject(projectfile)
if ((a:projectfile == '') && has('browse'))
" Browse for projectfile
if exists('g:WA')
let l:WA = g:WA
else
let l:WA = ''
endif
let b:browsefilter =
\ "All Project Files\t" . join(s:projectFileNames, ';') . "\n"
\ . "Vim-Files\t*.vim\n"
\ . "Batch-Files\t*.bat\n"
\ . "Makefiles\tmakefile;*.mak\n"
\ . "All\ Files\t*\n"
let projectfilePath = fnamemodify(browse(0, 'Select projectfile', l:WA, ''), ':p')
if !filereadable(projectfilePath)
echoerr 'File not readable: ' . projectfilePath
" Cancel
return
endif
else
" set Workarea and basedir
if filereadable(a:projectfile)
let projectfilePath = fnamemodify(a:projectfile, ':p')
else
echoerr 'No projectfile' a:projectfile
return
endif
endif
" split file name and path
let g:basedir = fnamemodify(projectfilePath, ':p:h')
let projectfileName = fnamemodify(projectfilePath, ':t')
let ext = fnamemodify(projectfileName, ':e')
if ext == 'vim'
" Projectfile is a vimscript. Execute and end
try
execute 'source ' . projectfilePath
catch
echom v:exception
endtry
else
" Projectfile is a makefile or a batchfile
if ext == 'bat'
let g:makeCommand = projectfilePath
else
let g:makeCommand = 'make -f ' . projectfilePath
endif
let &makeprg = g:makeCommand . ' $*'
" set directories
execute 'cd ' . g:basedir
" cd path
let &cdpath = g:basedir
" browse-dir
set browsedir=buffer
" search path
set path&
call s:GetProjectVariables()
call s:EvalProjectVariables()
endif
if exists('g:did_load_sessionfile')
echom 'Sessionfile not loaded again'
else
let g:did_load_sessionfile=1
if exists('g:sessionfile')
" Vim-Session load
try
execute 'source' g:sessionfile
catch /^Vim\%((\a\+)\)\=:E484/ " file not found
catch " other error
echom 'Fehler in' g:sessionfile ':' v:exception
endtry
" Vim-Session autowrite
autocmd VimLeavePre * execute 'mksession!' g:sessionfile
endif
endif
endfunction
" Get Project Specific Variables
function s:GetProjectVariables()
let varnames = [
\ 'VIM_PROJECTFILE',
\]
let s:Variables = GetMakeVars(varnames)
echo 'Reading variables from makefile'
echo '-------------------------------'
for varname in keys(s:Variables)
echo printf('%-15s = %s', varname, s:Variables[varname])
endfor
echo '-------------------------------'
echo ''
endfunction
" Evaluate Project Specific Variables
function s:EvalProjectVariables()
try
" evaluate path variable
if s:Variables['VIM_PROJECTFILE'] != ''
if !filereadable(s:Variables['VIM_PROJECTFILE'])
" try to create config-file
make vim-config
endif
try
execute 'source ' . s:Variables['VIM_PROJECTFILE']
catch
echoerr 'cant source "' . s:Variables['VIM_PROJECTFILE'] . '"'
echoerr 'check the make variable VIM_PROJECTFILE'
endtry
else
echomsg 'set the make-variable VIM_PROJECTFILE to the project-config file for vim'
echomsg 'For old BMSK-Projects try :SetBmskProject'
endif
catch /E716/ " Schlüssel nicht vorhanden
echomsg v:exception
echomsg 'For old BMSK-Projects try :SetBmskProject'
catch
echoerr 'Error while reading make-variables: ' . v:exception
endtry
endfunction
" Get values for a list of variables as dictionary
function GetMakeVars(varNameList)
let varlist = {}
try
let vars = join(a:varNameList, ' ')
let command = g:makeCommand . ' getvar name="' . vars . '"'
"echomsg command
let output = system(command)
let lines = split(output, "\n")
if len(lines) == 1 && len(a:varNameList) == 1 && match(lines[0], '=') < 0
" make output: value
let RE = '\(.*\)'
let SU = "let varlist['" . vars . "']='\\1'"
else
" make output: var=value
let RE = '^\(\w\+\)=\(.*\)\s*'
let SU = "let varlist['\\1']='\\2'"
endif
"echomsg 'getvars:'
for line in lines
"echomsg line
if match(line, RE) >= 0
let command = substitute(line, RE, SU, '')
"echomsg command
execute command
endif
endfor
"echomsg ''
catch
echomsg 'Could not read make variables'
endtry
if varlist == {}
echomsg 'Could not read any variables from makefile'
echo 'Command:' command
echo 'Make output is:'
for line in lines
echo line
endfor
echo '---'
endif
return varlist
endfunction
function GetMakeVar(varName)
let var = GetMakeVars([a:varName])
try
let varValue = var[a:varName]
catch
let varValue = ''
echomsg 'Could not read make-variable "' . a:varName . '"'
endtry
return varValue
endfunction
" ------------------
" Draw Vimsuite-Menu
" ------------------
let s:VimSuiteMenuLocation = 70
let s:VimSuiteMenuName = '&VimSuite.'
function s:AddFileToProjectMenu(makefilePath, submenu, priority)
exec 'anoremenu '
\ . s:VimSuiteMenuLocation
\ . a:priority' '
\ . s:VimSuiteMenuName.'&Project'
\ . a:submenu . '.'
\ . escape(a:makefilePath, '.\') . '<tab>'
\ . ' :SetProject ' . a:makefilePath . '<CR>'
endfunction
"
function s:AddAllKnownProjectsToMenu()
" Projects in project.txt
exec 'anoremenu ..50 '. s:VimSuiteMenuName.
\'&Project.-sep2- :'
let projectPaths = s:GetProjectPaths(g:projectsFile)
let makefilePaths = []
for projectPath in projectPaths
let makefilePaths += s:GetAllProjectFilesInPath(projectPath)
endfor
for makefilePath in makefilePaths
call s:AddFileToProjectMenu(makefilePath, '.Makefiles\ in\ project\.txt', '..60')
endfor
" Projects in g:WA
if exists('g:WA')
for makefilePath in s:GetAllProjectFilesInPath(g:WA)
if fnamemodify(makefilePath, ':e') == 'vim'
let submenu = ''
let prio = '..30'
else
let submenu = '.Makefiles\ in\ WA'
let prio = '..70'
endif
call s:AddFileToProjectMenu(makefilePath, submenu, prio)
endfor
endif
endfunction
"
function s:InitProjectMenu()
exec 'silent! aunmenu '.s:VimSuiteMenuName.'&Project'
exec 'anoremenu '.s:VimSuiteMenuLocation.'.10.10 '.s:VimSuiteMenuName.
\'&Project.&Browse\ for\ projectfile<tab>:SetProject'.
\' :SetProject<CR>'
exec 'anoremenu ..20 '. s:VimSuiteMenuName.
\'&Project.-sep1- :'
endfunction
"
function s:RedrawProjectMenu()
call s:InitProjectMenu()
call s:AddAllKnownProjectsToMenu()
endfunction
" -------
" Session
" -------
command -complete=custom,GetAllSessions -nargs=? SessionLoad call s:SessionLoad('<args>')
function s:SessionLoad(SessionFile)
if ((a:SessionFile == '') && has('browse'))
" Browse for session-file
if exists('b:browsefilter')
let l:browsefilter = b:browsefilter
endif
let b:browsefilter = "Vim Sessions (*.vim)\t*.vim\nAll Files (*.*)\t*.*"
let SessionFile = browse(0, 'Select Session', '.', '')
if exists('l:browsefilter')
let b:browsefilter = l:browsefilter
endif
else
let SessionFile = a:SessionFile
endif
if filereadable(SessionFile)
let g:sessionfile = SessionFile
" load session
execute('source ' . g:sessionfile)
" set autocmd to save session on exit
autocmd VimLeavePre * execute 'mksession!' g:sessionfile
" reset search path to session folder
set path+=./**
else
echo 'No such File:' SessionFile
endif
endfunction
" Load .session.vim, if available in current directory and save on exit
if argc() == 0 " skip, if command-line-parameters were given
if !exists('g:sessionfile') && filereadable('.session.vim')
let g:sessionfile = '.session.vim'
endif
if exists('g:sessionfile') && filereadable(g:sessionfile)
call s:SessionLoad(g:sessionfile)
endif
endif
command -nargs=? SessionSave call s:SessionSave('<args>')
command -nargs=? Exit SessionSave <args>|exit
function s:SessionSave(SessionName)
if (a:SessionName == '')
if ((v:this_session == '') && has('browse'))
" Browse for session-file
if exists('b:browsefilter')
let l:browsefilter = b:browsefilter
endif
let b:browsefilter = "Vim Sessions (*.vim)\t*.vim\nAll Files (*.*)\t*.*"
let SessionName = browse(1, 'Select Session File', '.', '.session.vim')
if exists('l:browsefilter')
let b:browsefilter = l:browsefilter
endif
else
let SessionName = v:this_session
endif
else
let SessionName = a:SessionName
endif
execute('mksession! ' . SessionName)
endfunction
function GetAllSessions(ArgLead, CmdLine, CursorPos)
let sessions_txt = $VIMRUNTIME . '/../sessions.txt'
let sessions = ''
let sessions = sessions . GlobLong($VIMRUNTIME . '/../*.vim')
if filereadable(sessions_txt)
let sessions = sessions . system("cat " . sessions_txt)
endif
return sessions
endfunction
function s:DelSessions()
exec 'silent! aunmenu '.s:VimSuiteMenuName.'&Session'
exec 'anoremenu '.s:VimSuiteMenuLocation.'.10 '.s:VimSuiteMenuName.
\'&Session.&Browse\ for\ Sessionfile<tab>:SessionLoad'.
\' :SessionLoad<CR>'
exec 'anoremenu '.s:VimSuiteMenuLocation.'.20 '.s:VimSuiteMenuName.
\'&Session.&Save<tab>:SessionSave'.
\' :SessionSave<CR>'
exec 'anoremenu '.s:VimSuiteMenuLocation.'.30 '.s:VimSuiteMenuName.
\'&Session.Save\ &As<tab>:SessionSave'.
\' :let v:this_session = ""<CR>:SessionSave<CR>'
endfunction
function s:RedrawSessionMenu()
call s:DelSessions()
call s:AddAllKnownSessionsToMenu()
endfunction
function s:AddAllKnownSessionsToMenu()
" set path from g:WAs
if exists('g:WAs')
for wa in g:WAs
" echom 'wa:' . wa . ':'
execute 'set path+=' . wa
endfor
endif
" search all session files in path
if !exists('g:SessionFileNames')
let g:SessionFileNames = [
\ '.session.vim',
\ 'Session.vim',
\]
endif
" echom 'SessionFileNames:' . join(g:SessionFileNames, ', ') . ':'
let sessionfiles_wa = []
for SessionFileName in g:SessionFileNames
let sessionfiles_wa += findfile('.session.vim', &path, -1)
" echom 'sessions:' . join(sessionfiles_wa, ', ') . ':'
endfor
" Add sessions to Gvim menu
for sessionfile in sessionfiles_wa
let cmd = 'anoremenu '.s:VimSuiteMenuLocation.'.40 '.s:VimSuiteMenuName.
\'Session.Load\ '. escape(sessionfile, '.') . '<tab>:SessionLoad'.
\' :SessionLoad ' . sessionfile . '<CR>'
" echom 'Command:' . cmd . ':'
exec cmd
endfor
endfunction
function s:RedrawMenu()
" Project
call s:RedrawProjectMenu()
" Session
call s:RedrawSessionMenu()
" Compile
exec 'anoremenu '.s:VimSuiteMenuLocation.'.30 '.s:VimSuiteMenuName.
\'&Compile.&Build<tab>:Make'.
@ -627,6 +183,26 @@ func GitGrep(...)
endfun
command -nargs=? GitGrep call GitGrep(<f-args>)
" Remove all buffers which are not found by findfile()
" ----------------------------------------------------
command BuffersCleanup call s:BuffersCleanup()
function s:BuffersCleanup()
let buffers = getbufinfo()
for buffer in buffers
if buffer['listed']
let path = fnamemodify(buffer['name'], ':p')
let name = fnamemodify(path, ':t')
let found = fnamemodify(findfile(name), ':p')
if found != path && buffer['listed']
echo 'delete buffer '.path
execute 'bdelete ' buffer['bufnr']
else
echo 'keep buffer '.path
endif
endif
endfor
endfunction
" Formatting Functions
" --------------------
@ -896,32 +472,6 @@ function FindUglyC()
execute '/' . UglyCstring
endfunction
" ------------
" diff options
" ------------
set diffopt=filler,vertical
" turn diff off
command DiffClose call DiffClose()
function DiffClose()
diffoff!
:quit
endfunction
" options for DirDiff
let g:DirDiffCommand = expand($VIMRUNTIME . '/diff')
let g:DirDiffExcludes = '*.log,*.pyc,.svn,.git*,.asc,_ccmwaid.inf,.static_wa,out,Build,build,tags,cscope.out'
"let g:DirDiffDynamicDiffText = 1
" settings for diff mode
if &diff
" turn off csv ftplugin in diff mode
au! filetypedetect * *.csv,*.dat,*.tsv,*.tab
endif
" options for Vimball
let g:vimball_home = expand(g:vimsuite . '/vimfiles')

View File

@ -114,13 +114,34 @@ set listchars+=precedes:
" special characters for keywords
" set iskeyword+=
" horizontal scrollbar in diff-mode
" ------------
" diff options
" ------------
if &diff
set guioptions+=b
" turn off csv ftplugin in diff mode
au! filetypedetect * *.csv,*.dat,*.tsv,*.tab
endif
" horizontal scrollbar in diff-mode
set diffopt=filler,vertical
" don't switch on DiffChar by default
let g:DiffExpr = ''
" turn diff off
command DiffClose call DiffClose()
function DiffClose()
diffoff!
:quit
endfunction
" options for DirDiff
let g:DirDiffCommand = expand($VIMRUNTIME . '/diff')
let g:DirDiffExcludes = '*.log,*.pyc,.svn,.git*,.asc,_ccmwaid.inf,.static_wa,out,Build,build,tags,cscope.out'
"let g:DirDiffDynamicDiffText = 1
" ------
" Moving
" ------
@ -250,6 +271,11 @@ let g:DoxygenToolkit_authorName = "Stefan Liebl"
" Add sa to Dox if you want
"let g:DoxygenToolkit_dox_sa = "yes"
" -----
" netrw
" -----
"let g:netrw_keepdir = 0
" ---------
" T-Comment
" ---------
@ -279,6 +305,7 @@ packadd linediff
packadd merginal
packadd pyclewn
packadd rtags
packadd sessionman
packadd SrchRplcHiGrp
packadd tagbar
packadd tcomment