From 8b3f090412c2083130a6e743ca02b32364fff730 Mon Sep 17 00:00:00 2001 From: Guy Baconniere Date: Mon, 25 Oct 2021 10:59:04 +0200 Subject: [PATCH] Add various version of stdheader and patches --- vim/stdheader.vim-42lausanne | 195 +++++++++++++++++++++++++++++ vim/stdheader.vim-42lausanne.patch | 165 ++++++++++++++++++++++++ vim/stdheader.vim-42paris | 143 +++++++++++++++++++++ vim/stdheader.vim-42paris.patch | 38 ++++++ 4 files changed, 541 insertions(+) create mode 100644 vim/stdheader.vim-42lausanne create mode 100644 vim/stdheader.vim-42lausanne.patch create mode 100644 vim/stdheader.vim-42paris create mode 100644 vim/stdheader.vim-42paris.patch diff --git a/vim/stdheader.vim-42lausanne b/vim/stdheader.vim-42lausanne new file mode 100644 index 0000000..fee1a3e --- /dev/null +++ b/vim/stdheader.vim-42lausanne @@ -0,0 +1,195 @@ +" **************************************************************************** " +" " +" ::: :::::::: " +" stdheader.vim :+: :+: :+: " +" +:+ +:+ +:+ " +" By: zaz +#+ +:+ +#+ " +" +#+#+#+#+#+ +#+ " +" Created: 2013/06/15 12:45:56 by zaz #+# #+# " +" Updated: 2021/02/01 12:32:13 by xitope ### ########.fr " +" " +" **************************************************************************** " + + +let s:asciiart = [ + \" ::: ::::::::", + \" :+: :+: :+:", + \" +:+ +:+ +:+ ", + \" +#+ +:+ +#+ ", + \"+#+#+#+#+#+ +#+ ", + \" #+# #+# ", + \" ### ########.fr " + \] + +let s:styles = [ + \{ + \'extensions': ['\.c$', '\.h$', '\.cc$', '\.hh$', '\.cpp$', '\.hpp$'], + \'start': '/*', 'end': '*/', 'fill': '*' + \}, + \{ + \'extensions': ['\.htm$', '\.html$', '\.xml$'], + \'start': '', 'fill': '*' + \}, + \{ + \'extensions': ['\.js$'], + \'start': '//', 'end': '//', 'fill': '*' + \}, + \{ + \'extensions': ['\.tex$'], + \'start': '%', 'end': '%', 'fill': '*' + \}, + \{ + \'extensions': ['\.ml$', '\.mli$', '\.mll$', '\.mly$'], + \'start': '(*', 'end': '*)', 'fill': '*' + \}, + \{ + \'extensions': ['\.vim$', 'vimrc$', '\.myvimrc$', 'vimrc$'], + \'start': '"', 'end': '"', 'fill': '*' + \}, + \{ + \'extensions': ['\.el$', '\.emacs$', '\.myemacs$'], + \'start': ';', 'end': ';', 'fill': '*' + \}, + \{ + \'extensions': ['\.f90$', '\.f95$', '\.f03$', '\.f$', '\.for$'], + \'start': '!', 'end': '!', 'fill': '/' + \} + \] + +let s:linelen = 80 +let s:marginlen = 5 +let s:contentlen = s:linelen - (3 * s:marginlen - 1) - strlen(s:asciiart[0]) + +function s:trimlogin () + let l:trimlogin = strpart($USER, 0, 9) + if strlen(l:trimlogin) == 0 + let l:trimlogin = "marvin" + endif + return l:trimlogin +endfunction + +function s:trimemail () + let l:trimemail = strpart($MAIL, 0, s:contentlen - 16) + if strlen(l:trimemail) == 0 + let l:trimemail = "marvin@42lausanne.ch" + endif + return l:trimemail +endfunction + +function s:midgap () + return repeat(' ', s:marginlen - 1) +endfunction + +function s:lmargin () + return repeat(' ', s:marginlen - strlen(s:start)) +endfunction + +function s:rmargin () + return repeat(' ', s:marginlen - strlen(s:end)) +endfunction + +function s:empty_content () + return repeat(' ', s:contentlen) +endfunction + +function s:left () + return s:start . s:lmargin() +endfunction + +function s:right () + return s:rmargin() . s:end +endfunction + +function s:bigline () + return s:start . ' ' . repeat(s:fill, s:linelen - 2 - strlen(s:start) - strlen(s:end)) . ' ' . s:end +endfunction + +function s:logo1 () + return s:left() . s:empty_content() . s:midgap() . s:asciiart[0] . s:right() +endfunction + +function s:fileline () + let l:trimfile = strpart(fnamemodify(bufname('%'), ':t'), 0, s:contentlen) + return s:left() . l:trimfile . repeat(' ', s:contentlen - strlen(l:trimfile)) . s:midgap() . s:asciiart[1] . s:right() +endfunction + +function s:logo2 () + return s:left() . s:empty_content() . s:midgap() .s:asciiart[2] . s:right() +endfunction + +function s:coderline () + let l:contentline = "By: ". s:trimlogin () . ' <' . s:trimemail () . '>' + return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[3] . s:right() +endfunction + +function s:logo3 () + return s:left() . s:empty_content() . s:midgap() .s:asciiart[4] . s:right() +endfunction + +function s:dateline (prefix, logo) + let l:date = strftime("%Y/%m/%d %H:%M:%S") + let l:contentline = a:prefix . ": " . l:date . " by " . s:trimlogin () + return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[a:logo] . s:right() +endfunction + +function s:createline () + return s:dateline("Created", 5) +endfunction + +function s:updateline () + return s:dateline("Updated", 6) +endfunction + +function s:emptyline () + return s:start . repeat(' ', s:linelen - strlen(s:start) - strlen(s:end)) . s:end +endfunction + +function s:filetype () + let l:file = fnamemodify(bufname("%"), ':t') + + let s:start = '#' + let s:end = '#' + let s:fill = '*' + + for l:style in s:styles + for l:ext in l:style['extensions'] + if l:file =~ l:ext + let s:start = l:style['start'] + let s:end = l:style['end'] + let s:fill = l:style['fill'] + endif + endfor + endfor +endfunction + +function s:insert () + call s:filetype () + + call append(0, "") + call append (0, s:bigline()) + call append (0, s:emptyline()) + call append (0, s:updateline()) + call append (0, s:createline()) + call append (0, s:logo3()) + call append (0, s:coderline()) + call append (0, s:logo2()) + call append (0, s:fileline()) + call append (0, s:logo1()) + call append (0, s:emptyline()) + call append (0, s:bigline()) +endfunction + +function s:update () + call s:filetype () + + let l:pattern = s:start . repeat(' ', 5 - strlen(s:start)) . "Updated: [0-9]" + let l:line = getline (9) + + if l:line =~ l:pattern + call setline(9, s:updateline()) + endif +endfunction + +command Stdheader call s:insert () +nmap :Stdheader +autocmd BufWritePre * call s:update () \ No newline at end of file diff --git a/vim/stdheader.vim-42lausanne.patch b/vim/stdheader.vim-42lausanne.patch new file mode 100644 index 0000000..f0db819 --- /dev/null +++ b/vim/stdheader.vim-42lausanne.patch @@ -0,0 +1,165 @@ +--- stdheader.vim 2021-06-10 22:51:40.000000000 +0200 ++++ stdheader.vim 2021-10-25 09:58:04.000000000 +0200 +@@ -3,10 +3,10 @@ + " ::: :::::::: " + " stdheader.vim :+: :+: :+: " + " +:+ +:+ +:+ " +-" By: zaz +#+ +:+ +#+ " ++" By: +#+ +:+ +#+ " + " +#+#+#+#+#+ +#+ " + " Created: 2013/06/15 12:45:56 by zaz #+# #+# " +-" Updated: 2021/02/01 12:32:13 by xitope ### ########.fr " ++" Updated: 2021/10/25 09:58:04 by gbaconni ### lausanne.ch " + " " + " **************************************************************************** " + +@@ -18,7 +18,7 @@ + \" +#+ +:+ +#+ ", + \"+#+#+#+#+#+ +#+ ", + \" #+# #+# ", +- \" ### ########.fr " ++ \" ### lausanne.ch " + \] + + let s:styles = [ +@@ -60,91 +60,91 @@ + let s:marginlen = 5 + let s:contentlen = s:linelen - (3 * s:marginlen - 1) - strlen(s:asciiart[0]) + +-function s:trimlogin () ++function! s:trimlogin () + let l:trimlogin = strpart($USER, 0, 9) + if strlen(l:trimlogin) == 0 +- let l:trimlogin = "marvin" ++ let l:trimlogin = "rfederer" + endif + return l:trimlogin + endfunction + +-function s:trimemail () ++function! s:trimemail () + let l:trimemail = strpart($MAIL, 0, s:contentlen - 16) + if strlen(l:trimemail) == 0 +- let l:trimemail = "marvin@42lausanne.ch" ++ let l:trimemail = "rfederer@student.42lausanne.ch" + endif + return l:trimemail + endfunction + +-function s:midgap () ++function! s:midgap () + return repeat(' ', s:marginlen - 1) + endfunction + +-function s:lmargin () ++function! s:lmargin () + return repeat(' ', s:marginlen - strlen(s:start)) + endfunction + +-function s:rmargin () ++function! s:rmargin () + return repeat(' ', s:marginlen - strlen(s:end)) + endfunction + +-function s:empty_content () ++function! s:empty_content () + return repeat(' ', s:contentlen) + endfunction + +-function s:left () ++function! s:left () + return s:start . s:lmargin() + endfunction + +-function s:right () ++function! s:right () + return s:rmargin() . s:end + endfunction + +-function s:bigline () ++function! s:bigline () + return s:start . ' ' . repeat(s:fill, s:linelen - 2 - strlen(s:start) - strlen(s:end)) . ' ' . s:end + endfunction + +-function s:logo1 () ++function! s:logo1 () + return s:left() . s:empty_content() . s:midgap() . s:asciiart[0] . s:right() + endfunction + +-function s:fileline () ++function! s:fileline () + let l:trimfile = strpart(fnamemodify(bufname('%'), ':t'), 0, s:contentlen) + return s:left() . l:trimfile . repeat(' ', s:contentlen - strlen(l:trimfile)) . s:midgap() . s:asciiart[1] . s:right() + endfunction + +-function s:logo2 () ++function! s:logo2 () + return s:left() . s:empty_content() . s:midgap() .s:asciiart[2] . s:right() + endfunction + +-function s:coderline () ++function! s:coderline () + let l:contentline = "By: ". s:trimlogin () . ' <' . s:trimemail () . '>' + return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[3] . s:right() + endfunction + +-function s:logo3 () ++function! s:logo3 () + return s:left() . s:empty_content() . s:midgap() .s:asciiart[4] . s:right() + endfunction + +-function s:dateline (prefix, logo) ++function! s:dateline (prefix, logo) + let l:date = strftime("%Y/%m/%d %H:%M:%S") + let l:contentline = a:prefix . ": " . l:date . " by " . s:trimlogin () + return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[a:logo] . s:right() + endfunction + +-function s:createline () ++function! s:createline () + return s:dateline("Created", 5) + endfunction + +-function s:updateline () ++function! s:updateline () + return s:dateline("Updated", 6) + endfunction + +-function s:emptyline () ++function! s:emptyline () + return s:start . repeat(' ', s:linelen - strlen(s:start) - strlen(s:end)) . s:end + endfunction + +-function s:filetype () ++function! s:filetype () + let l:file = fnamemodify(bufname("%"), ':t') + + let s:start = '#' +@@ -162,7 +162,7 @@ + endfor + endfunction + +-function s:insert () ++function! s:insert () + call s:filetype () + + call append(0, "") +@@ -179,7 +179,7 @@ + call append (0, s:bigline()) + endfunction + +-function s:update () ++function! s:update () + call s:filetype () + + let l:pattern = s:start . repeat(' ', 5 - strlen(s:start)) . "Updated: [0-9]" +@@ -190,6 +190,6 @@ + endif + endfunction + +-command Stdheader call s:insert () ++command! Stdheader call s:insert () + nmap :Stdheader +-autocmd BufWritePre * call s:update () +\ No newline at end of file ++autocmd BufWritePre * call s:update () diff --git a/vim/stdheader.vim-42paris b/vim/stdheader.vim-42paris new file mode 100644 index 0000000..f759d87 --- /dev/null +++ b/vim/stdheader.vim-42paris @@ -0,0 +1,143 @@ +let s:asciiart = [ + \" ::: ::::::::", + \" :+: :+: :+:", + \" +:+ +:+ +:+ ", + \" +#+ +:+ +#+ ", + \"+#+#+#+#+#+ +#+ ", + \" #+# #+# ", + \" ### ########.fr " + \] + +let s:start = '/*' +let s:end = '*/' +let s:fill = '*' +let s:length = 80 +let s:margin = 5 + +let s:types = { + \'\.c$\|\.h$\|\.cc$\|\.hh$\|\.cpp$\|\.hpp$\|\.php': + \['/*', '*/', '*'], + \'\.htm$\|\.html$\|\.xml$': + \['', '*'], + \'\.js$': + \['//', '//', '*'], + \'\.tex$': + \['%', '%', '*'], + \'\.ml$\|\.mli$\|\.mll$\|\.mly$': + \['(*', '*)', '*'], + \'\.vim$\|\vimrc$': + \['"', '"', '*'], + \'\.el$\|\emacs$': + \[';', ';', '*'], + \'\.f90$\|\.f95$\|\.f03$\|\.f$\|\.for$': + \['!', '!', '/'] + \} + +function! s:filetype() + let l:f = s:filename() + + let s:start = '#' + let s:end = '#' + let s:fill = '*' + + for type in keys(s:types) + if l:f =~ type + let s:start = s:types[type][0] + let s:end = s:types[type][1] + let s:fill = s:types[type][2] + endif + endfor + +endfunction + +function! s:ascii(n) + return s:asciiart[a:n - 3] +endfunction + +function! s:textline(left, right) + let l:left = strpart(a:left, 0, s:length - s:margin * 3 - strlen(a:right) + 1) + + return s:start . repeat(' ', s:margin - strlen(s:start)) . l:left . repeat(' ', s:length - s:margin * 2 - strlen(l:left) - strlen(a:right)) . a:right . repeat(' ', s:margin - strlen(s:end)) . s:end +endfunction + +function! s:line(n) + if a:n == 1 || a:n == 11 " top and bottom line + return s:start . ' ' . repeat(s:fill, s:length - strlen(s:start) - strlen(s:end) - 2) . ' ' . s:end + elseif a:n == 2 || a:n == 10 " blank line + return s:textline('', '') + elseif a:n == 3 || a:n == 5 || a:n == 7 " empty with ascii + return s:textline('', s:ascii(a:n)) + elseif a:n == 4 " filename + return s:textline(s:filename(), s:ascii(a:n)) + elseif a:n == 6 " author + return s:textline("By: " . s:user() . " <" . s:mail() . ">", s:ascii(a:n)) + elseif a:n == 8 " created + return s:textline("Created: " . s:date() . " by " . s:user(), s:ascii(a:n)) + elseif a:n == 9 " updated + return s:textline("Updated: " . s:date() . " by " . s:user(), s:ascii(a:n)) + endif +endfunction + +function! s:user() + let l:user = $USER + if strlen(l:user) == 0 + let l:user = "marvin" + endif + return l:user +endfunction + +function! s:mail() + let l:mail = $MAIL + if strlen(l:mail) == 0 + let l:mail = "marvin@42.fr" + endif + return l:mail +endfunction + +function! s:filename() + let l:filename = expand("%:t") + if strlen(l:filename) == 0 + let l:filename = "< new >" + endif + return l:filename +endfunction + +function! s:date() + return strftime("%Y/%m/%d %H:%M:%S") +endfunction + +function! s:insert() + let l:line = 11 + + " empty line after header + call append(0, "") + + " loop over lines + while l:line > 0 + call append(0, s:line(l:line)) + let l:line = l:line - 1 + endwhile +endfunction + +function! s:update() + call s:filetype() + if getline(9) =~ s:start . repeat(' ', s:margin - strlen(s:start)) . "Updated: " + if &mod + call setline(9, s:line(9)) + endif + call setline(4, s:line(4)) + return 0 + endif + return 1 +endfunction + +function! s:stdheader() + if s:update() + call s:insert() + endif +endfunction + +" Bind command and shortcut +command! Stdheader call s:stdheader () +map :Stdheader +autocmd BufWritePre * call s:update () diff --git a/vim/stdheader.vim-42paris.patch b/vim/stdheader.vim-42paris.patch new file mode 100644 index 0000000..8df0dfc --- /dev/null +++ b/vim/stdheader.vim-42paris.patch @@ -0,0 +1,38 @@ +--- stdheader.vim 2021-10-25 09:45:16.000000000 +0200 ++++ stdheader.vim 2021-10-25 09:28:41.000000000 +0200 +@@ -5,7 +5,7 @@ + \" +#+ +:+ +#+ ", + \"+#+#+#+#+#+ +#+ ", + \" #+# #+# ", +- \" ### ########.fr " ++ \" ### lausanne.ch " + \] + + let s:start = '/*' +@@ -70,7 +70,7 @@ + elseif a:n == 4 " filename + return s:textline(s:filename(), s:ascii(a:n)) + elseif a:n == 6 " author +- return s:textline("By: " . s:user() . " <" . s:mail() . ">", s:ascii(a:n)) ++ return s:textline("By: " . "<" . s:mail() . ">", s:ascii(a:n)) + elseif a:n == 8 " created + return s:textline("Created: " . s:date() . " by " . s:user(), s:ascii(a:n)) + elseif a:n == 9 " updated +@@ -81,7 +81,7 @@ + function! s:user() + let l:user = $USER + if strlen(l:user) == 0 +- let l:user = "marvin" ++ let l:user = "rfederer" + endif + return l:user + endfunction +@@ -89,7 +89,7 @@ + function! s:mail() + let l:mail = $MAIL + if strlen(l:mail) == 0 +- let l:mail = "marvin@42.fr" ++ let l:mail = "rfederer@student.42lausanne.ch" + endif + return l:mail + endfunction