From 8ba36fcf86aa25aee3d8761547f4b95c8786d34e Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Fri, 15 Oct 2021 15:58:29 +0200 Subject: [PATCH] macro: Robustify InsertIncludeGuardsWithoutEndif Also replace - by a _ in the include guard. --- macros.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 -- 2.39.5