From: Stefan Huber Date: Fri, 15 Oct 2021 13:58:29 +0000 (+0200) Subject: macro: Robustify InsertIncludeGuardsWithoutEndif X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=8ba36fcf86aa25aee3d8761547f4b95c8786d34e;p=vimconf.git macro: Robustify InsertIncludeGuardsWithoutEndif Also replace - by a _ in the include guard. --- diff --git a/macros.vim b/macros.vim index b33bf4d..d744060 100644 --- a/macros.vim +++ b/macros.vim @@ -78,9 +78,12 @@ 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 + " Build name of guard: Take filename, replace some chars by _ and + " prepend a random sequence to make guard robust against file name + " collisions. + let guardname = substitute(expand("%:t"), "[\\.-]", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16) + execute "normal! i#ifndef " . guardname + execute "normal! o#define " . guardname endfunction