" in the middle begin with a star.
" If #include and // and /* and ^* and :: is not prepend:
- execute ':%s_\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
+ execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
" If #include and // and :: is not prepend, but */ is, and no further /* or // are found
- execute ':%s_\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
+ execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
endfunction
let id = id +['queue', 'stack', 'priority_queue']
let id = id +['ostream', 'istream', 'sstream']
let id = id +['pair', 'string']
- let id = ['map']
for i in id
call PrependCppNamespaceToIdent("std", i)
execute '%s/^\(.*\)$/"\1"/'
endfunction
+function InsertIncludeGuardsWithoutEndif()
+ let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
+ execute "normal! i#ifndef " . gatename
+ execute "normal! o#define " . gatename
+endfunction
+
+function AddIncludeGuards()
+ execute "normal! Go#endif"
+ execute "normal! gg"
+ call InsertIncludeGuardsWithoutEndif()
+endfunction
+
+autocmd BufNewFile *.{h,hpp} call AddIncludeGuards()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""