From 111b504e25bdda6d48c508aae25bf155e86ef83c Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Fri, 5 Mar 2021 14:58:51 -0500 Subject: [PATCH] Move vim templates into vimrc --- bin/vim-pull | 1 - bin/vim-push | 1 - vim/templates/c_header_notice | 31 -------- vim/templates/skeleton.plan | 14 ---- vim/templates/skeleton.sh | 49 ------------ vimrc | 135 +++++++++++++++++++++++++++++----- 6 files changed, 115 insertions(+), 116 deletions(-) delete mode 100644 vim/templates/c_header_notice delete mode 100644 vim/templates/skeleton.plan delete mode 100644 vim/templates/skeleton.sh diff --git a/bin/vim-pull b/bin/vim-pull index d5a3904..8ef3bc7 100644 --- a/bin/vim-pull +++ b/bin/vim-pull @@ -11,6 +11,5 @@ if [ -d $src ]; then [ -d "$src/spell" ] && echo "Syncing user dictionary" && cp -r "$src/spell" $dest [ -d "$src/colors" ] && echo "Syncing user colors" && cp -r "$src/colors" $dest [ -d "$src/after" ] && echo "Syncing after directory" && cp -r "$src/after" $dest - [ -d "$src/templates" ] && echo "Syncing templates" && cp -r "$src/templates" $dest [ -d "$src/ftdetect" ] && echo "Syncing ftdetect" && cp -r "$src/ftdetect" $dest fi diff --git a/bin/vim-push b/bin/vim-push index f2952bf..a858095 100644 --- a/bin/vim-push +++ b/bin/vim-push @@ -11,6 +11,5 @@ if [ -d $src ]; then [ -d "$src/spell" ] && echo "Syncing user dictionary" && cp -r "$src/spell" $dest [ -d "$src/colors" ] && echo "Syncing user colors" && cp -r "$src/colors" $dest [ -d "$src/after" ] && echo "Syncing after directory" && cp -r "$src/after" $dest - [ -d "$src/templates" ] && echo "Syncing templates" && cp -r "$src/templates" $dest [ -d "$src/ftdetect" ] && echo "Syncing ftdetect" && cp -r "$src/ftdetect" $dest fi diff --git a/vim/templates/c_header_notice b/vim/templates/c_header_notice deleted file mode 100644 index 6ea4a2f..0000000 --- a/vim/templates/c_header_notice +++ /dev/null @@ -1,31 +0,0 @@ -/*================================================================================================== - File: - Creation Date: - Creator: Michael Campagnaro - Notice: (C) Copyright $year by Jelly Pixel, Inc. All Rights Reserved. - ================================================================================================*/ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Defines -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Globals -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Structs -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Macros -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Private API -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// # Public API -//////////////////////////////////////////////////////////////////////////////////////////////////// - diff --git a/vim/templates/skeleton.plan b/vim/templates/skeleton.plan deleted file mode 100644 index a59c1ec..0000000 --- a/vim/templates/skeleton.plan +++ /dev/null @@ -1,14 +0,0 @@ ---------------------------------------------------------- -Michael Campagnaro's plan for , 2020 ---------------------------------------------------------- - -############## -DO -############## - -+ - -############## -EXTRA -############## - diff --git a/vim/templates/skeleton.sh b/vim/templates/skeleton.sh deleted file mode 100644 index 3798536..0000000 --- a/vim/templates/skeleton.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) -fi -if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then - RED="$(tput setaf 1)" - GREEN="$(tput setaf 2)" - YELLOW="$(tput setaf 3)" - BLUE="$(tput setaf 4)" - MAGENTA="$(tput setaf 5)" - CYAN="$(tput setaf 6)" - BOLD="$(tput bold)" - DIM="\e[2m" - NORMAL="$(tput sgr0)" -else - RED="" - GREEN="" - YELLOW="" - BLUE="" - MAGENTA="" - CYAN="" - BOLD="" - NORMAL="" -fi - -error() { - printf "${BOLD}${RED}$1${NORMAL}\n" -} - -abort() { - error "\nAborting..." - exit 1 -} - -set -e - -cwd=$PWD - -uname_s="$(uname -s)" -case "${uname_s}" in - Linux*) machine=Linux;; - Darwin*) machine=MacOS;; - CYGWIN*) machine=Cygwin;; - MINGW*) machine=MinGw;; - *) machine="UNKNOWN:${uname_s}" -esac - -printf "${YELLOW}Platform: $machine${NORMAL}\n" diff --git a/vimrc b/vimrc index 6bfc8f8..cf1def8 100644 --- a/vimrc +++ b/vimrc @@ -334,6 +334,114 @@ imap " CUSTOM AUTOCMDS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" C/C++ template. +function! s:CFileTemplate() + let s:env = { + \ 'filename': expand('%:t'), + \ 'creation_date': strftime('%Y-%m-%d'), + \ 'year': strftime('%Y'), + \ 'copyright_owner': 'Jelly Pixel, Inc. All Rights Reserved.' + \} + + let l:template =<< trim EOS + /*================================================================================================== + File: ${filename} + Creation Date: ${creation_date} + Creator: Michael Campagnaro + Notice!: (C) Copyright ${year} by ${copyright_owner} + ================================================================================================*/ + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Defines + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Globals + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Structs + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Macros + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Private API + //////////////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////////////////////////// + // # Public API + //////////////////////////////////////////////////////////////////////////////////////////////////// + +EOS + return map(l:template, { _, line -> substitute(line, '${\(.\{-}\)}', '\=get(s:env, submatch(1), submatch(1))', 'g') } ) +endfunction + +function! s:InsertCHeaderGates() + let l:gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") + call append(0, '#ifndef '. l:gatename) + call append(line('$'), '#define '. l:gatename) + call append(line('$'), '#endif') +endfunction + +" sh template +function! s:ShellScriptTemplate() + let l:template =<< trim EOS + #!/usr/bin/env bash + + if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) + fi + if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + BOLD="$(tput bold)" + DIM="\e[2m" + NORMAL="$(tput sgr0)" + else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + BOLD="" + NORMAL="" + fi + + error() { + printf "${BOLD}${RED}$1${NORMAL}\n" + } + + abort() { + error "\nAborting..." + exit 1 + } + + set -e + + cwd=$PWD + + uname_s="$(uname -s)" + case "${uname_s}" in + Linux*) machine=Linux;; + Darwin*) machine=MacOS;; + CYGWIN*) machine=Cygwin;; + MINGW*) machine=MinGw;; + *) machine="UNKNOWN:${uname_s}" + esac + + printf "${YELLOW}Platform: $machine${NORMAL}\n" +EOS + return l:template +endfunction + augroup campoCmds " Clear all autocmds in the group. autocmd! @@ -352,7 +460,7 @@ augroup campoCmds autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif " Properly indent schemes (scheme, racket, etc). - autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt + autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt " Fasm indent; uses the fedorenchik/fasm.vim plugin. autocmd BufReadPre *.asm let g:asmsyntax = "fasm" @@ -375,7 +483,7 @@ augroup campoCmds " Generate ctags on save. " Also Include local variables for C-like languages. - autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h,*.asm silent! :call RunCtags() + autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h,*.asm silent! call s:RunCtags() " Remove trailing whitespace when saving any file. function! s:StripTrailingWhitespaces() @@ -396,31 +504,18 @@ augroup campoCmds %s/\s\+$//e call cursor(l, c) endfun - autocmd BufWritePre * :call StripTrailingWhitespaces() + autocmd BufWritePre * call s:StripTrailingWhitespaces() "//////////////////////////////////////////////////////////////// " FILE TEMPLATES "//////////////////////////////////////////////////////////////// " Shell script template. - autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh - autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan + autocmd BufNewFile *.sh call append(0, s:ShellScriptTemplate()) - " C/C++ template. - autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%") - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d") - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y") - function! s:InsertHeaderGates() - let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") - execute "normal! ggO#ifndef " . gatename - normal! Go - normal! Go - execute "normal! Go#define " . gatename . " " - execute "normal! o#endif" - normal! kkk - endfunction - autocmd bufnewfile *.{h,hpp} call InsertHeaderGates() + " C/C++ file. + autocmd BufNewFile *.{c,cc,cpp,h,hpp} call append(0, s:CFileTemplate()) + autocmd BufNewFile *.{h,hpp} call s:InsertCHeaderGates() augroup END """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""