From c2a479044d0c7039be959896ba2fbdfd54fa61a8 Mon Sep 17 00:00:00 2001 From: Chris MacLeod Date: Wed, 23 Mar 2011 00:00:38 -0400 Subject: [PATCH 1/3] one fix and a couple of enhancements Added a .gitignore file to ignore tags since they are autogenerated. Fixed the substitute section to use a different delimiter that handles commands that return newlines and other things better. A lot of common commands and subs were failing because they had slashes contained and that would throw substitute off. A better approach might be to use substitute() instead. added a global option to allow loose filetype matching so you don't have to include an underscore in the filename to get it to match a sub-filetype skeleton. It's turned off by default. --- .gitignore | 1 + doc/eteSkeleton.txt | 17 +++++++++++++++++ plugin/eteSkeleton.vim | 12 ++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e92f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags diff --git a/doc/eteSkeleton.txt b/doc/eteSkeleton.txt index 4b23fc1..f3469a0 100644 --- a/doc/eteSkeleton.txt +++ b/doc/eteSkeleton.txt @@ -57,6 +57,23 @@ Once the skeleton is loaded, the tags in the "test_script.py" file will be replaced by the tags in eteSskeleton.tags (which are located in the plugin directory). +You can enable loose filename matching by setting g:EteSkeleton_loosefiletype +to true in your ~/.vimrc. This will cause any filename to match against a +skeleton file regardess of the _. + +example > + let g:EteSkeleton_loosefiletype = 1 + + ~/.vim/skeleton/python + ~/.vim/skeleton/test_python + + :e test.py + + In this case, |eteSkeleton| will load "test_python" skeleton file. + + + + ============================================================================== USAGE *eteSkeleton-usage* diff --git a/plugin/eteSkeleton.vim b/plugin/eteSkeleton.vim index b874d69..b0be07e 100644 --- a/plugin/eteSkeleton.vim +++ b/plugin/eteSkeleton.vim @@ -32,6 +32,10 @@ let s:ETES_SKELETONS = "skeleton" let s:ETES_TAGS = globpath(&rtp,"plugin/eteSkeleton.tags") set cpo&vim +if !exists("g:EteSkeleton_loosefiletype") + let g:EteSkeleton_loosefiletype = 0 +endif + command! -nargs=0 EteSkeleton call s:eteSkeleton_get() command! -nargs=0 EteSkelList call s:eteSkeleton_list() command! -nargs=1 EteSkelAdd call s:eteSkeleton_add() @@ -98,14 +102,18 @@ fu! s:eteSkeleton_replace() let l:vals = split(l:riga, "=") for l:idx in range(1,line("$")) if getline(l:idx) =~ "<".l:vals[0].">" - silent! exec l:idx."s/<".l:vals[0].">/".eval(l:vals[1]) + silent! exec l:idx."s#<".l:vals[0].">#".eval(l:vals[1])."#g" endif endfor endif endfor endfu fu! s:eteSkeleton_get() - let l:fname = expand("%:r") + if g:EteSkeleton_loosefiletype + let l:fname = expand("%:t:r") . "_" . &l:filetype + else + let l:fname = expand("%:t:r") + endif let l:rlist = sort(map(split(globpath(&rtp, s:ETES_SKELETONS."/*". \&l:filetype."*"),"\n"),'fnamemodify(v:val,":t")'), "s:msort") for l:item in l:rlist From 623160d47fb40c505fd143daf440284016478efd Mon Sep 17 00:00:00 2001 From: Chris MacLeod Date: Wed, 23 Mar 2011 00:25:14 -0400 Subject: [PATCH 2/3] better location for tags move the tags file to a tags directory under ~/.vim/skeleton this keeps the user defined tags away from plugin tags (allowing the plugin to potentionally set them one day). It also keeps them out of the repo if someone has it cloned to their .vim directory (very common with pathogen). --- doc/eteSkeleton.txt | 2 +- plugin/eteSkeleton.vim | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/eteSkeleton.txt b/doc/eteSkeleton.txt index f3469a0..da5ebdd 100644 --- a/doc/eteSkeleton.txt +++ b/doc/eteSkeleton.txt @@ -123,7 +123,7 @@ COMMANDS *eteSkeleton-commands* TAGS *eteSkeleton-tags* Tags are a simple list of tagname=tagvalue stored in the "eteSkeleton.tags" -file (which is located in the plugin folder). It can be manually edited or +file (which is located in the $VIMRUNTIME/skeleton/tags folder). It can be manually edited or modified by the eteSkeleton commands. Please note that the {tagname} must be written without the <> symbols in the tag list; however, as the {tagvalue} will be evaluated, you must use quotes (i.e. " ") when you write Strings. diff --git a/plugin/eteSkeleton.vim b/plugin/eteSkeleton.vim index b0be07e..a155ea9 100644 --- a/plugin/eteSkeleton.vim +++ b/plugin/eteSkeleton.vim @@ -29,9 +29,13 @@ endif let g:loaded_eteSkeleton = 101 let s:save_cpo = &cpo let s:ETES_SKELETONS = "skeleton" -let s:ETES_TAGS = globpath(&rtp,"plugin/eteSkeleton.tags") +let s:ETES_TAGS = globpath(&rtp,s:ETES_SKELETONS."tags/eteSkeleton.tags") set cpo&vim +if !isdirectory(fnamemodify(s:ETES_TAGS, ":p:h")) + mkdir(fnamemodify(s:ETES_TAGS, ":p:h")) +endif + if !exists("g:EteSkeleton_loosefiletype") let g:EteSkeleton_loosefiletype = 0 endif From 05b07849cabce3bbd729feed2e95dfaac87da7d5 Mon Sep 17 00:00:00 2001 From: Chris MacLeod Date: Wed, 23 Mar 2011 13:47:11 -0400 Subject: [PATCH 3/3] cleanup and fix Cleaned up whitespace from end of lines make it handle a missing tagfile better --- plugin/eteSkeleton.vim | 58 +++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/plugin/eteSkeleton.vim b/plugin/eteSkeleton.vim index a155ea9..04a820e 100644 --- a/plugin/eteSkeleton.vim +++ b/plugin/eteSkeleton.vim @@ -1,5 +1,5 @@ " eteSkeleton -" Autor: ellethee +" Autor: ellethee " Version: 1.0.1 " License: MIT " Last change: 2010 Dec 14 @@ -26,14 +26,14 @@ if exists("g:loaded_eteSkeleton") || &cp finish endif -let g:loaded_eteSkeleton = 101 +let g:loaded_eteSkeleton = 101 let s:save_cpo = &cpo let s:ETES_SKELETONS = "skeleton" -let s:ETES_TAGS = globpath(&rtp,s:ETES_SKELETONS."tags/eteSkeleton.tags") +let s:ETES_TAGS = globpath(&rtp,s:ETES_SKELETONS."/tags/eteSkeleton.tags") set cpo&vim -if !isdirectory(fnamemodify(s:ETES_TAGS, ":p:h")) - mkdir(fnamemodify(s:ETES_TAGS, ":p:h")) +if !exists("s:ETES_TAGS") + echom "Can't find " $HOME."/.vim/".s:ETES_SKELETONS."/tags/eteSkeleton.tags" endif if !exists("g:EteSkeleton_loosefiletype") @@ -59,21 +59,29 @@ fu! s:eteSkeleton_makeskel(...) echo "Creo lo skeletro: ".l:path."/".l:name exec ":w! ".l:path."/".l:name exec ":e! ".l:path."/".l:name -endfu +endfu fu! s:msort(l1, l2) return len(a:l2) - len(a:l1) endfu fu! s:eteSkeleton_list() - for riga in readfile(s:ETES_TAGS) - echo riga - endfor + if exists("s:ETES_TAGS") + for riga in readfile(s:ETES_TAGS) + echo riga + endfor + else + echo "No tags" + endif endfu fu! s:eteSkeleton_addtag() - let l:cword = expand("") - if len(l:cword) - call s:eteSkeleton_add(l:cword) + if exists("s:ETES_TAGS") + let l:cword = expand("") + if len(l:cword) + call s:eteSkeleton_add(l:cword) + else + echoerr "Posizionarsi su di una parola" + endif else - echoerr "Posizionarsi su di una parola" + echoerr "no tagfile found" endif endfu fu! s:eteSkeleton_add(tag) @@ -95,15 +103,17 @@ fu! s:eteSkeleton_add(tag) call writefile(l:lista, s:ETES_TAGS) endfu fu! s:eteSkeleton_del(tag) - let l:tag = substitute(substitute(a:tag,"<","",""),">","","") - let l:lista = readfile(s:ETES_TAGS) - call filter(l:lista,'v:val !~ "^'.l:tag.'="') - call writefile(l:lista, s:ETES_TAGS) + if exists("s:ETES_TAGS") + let l:tag = substitute(substitute(a:tag,"<","",""),">","","") + let l:lista = readfile(s:ETES_TAGS) + call filter(l:lista,'v:val !~ "^'.l:tag.'="') + call writefile(l:lista, s:ETES_TAGS) + endif endfu fu! s:eteSkeleton_replace() for l:riga in readfile(s:ETES_TAGS) if l:riga[0] != '"' && len(l:riga[0]) != 0 - let l:vals = split(l:riga, "=") + let l:vals = split(l:riga, "=") for l:idx in range(1,line("$")) if getline(l:idx) =~ "<".l:vals[0].">" silent! exec l:idx."s#<".l:vals[0].">#".eval(l:vals[1])."#g" @@ -126,16 +136,18 @@ fu! s:eteSkeleton_get() \l:item)) if len(l:pfile) silent keepalt 0 read `=join(l:pfile)` - call s:eteSkeleton_replace() + if exists("s:ETES_TAGS") + call s:eteSkeleton_replace() + endif endif break endif endfor - return -endfu + return +endfu fu! s:eteSkeleton_check() if &l:filetype != "" - execute "EteSkeleton" + execute "EteSkeleton" endif return endfu @@ -147,4 +159,4 @@ augroup END let &cpo= s:save_cpo unlet s:save_cpo -" vim:fdm=marker: +" vim:fdm=marker tw=4 sw=4: