From e6625557fc705e86332b17dc11a3908da734c332 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 11 Dec 2022 17:31:17 +0100 Subject: [PATCH] etc/vim/source/functions.vim --- etc/profile.d/functions | 31 ----------------- etc/vim/source/functions.vim | 64 ++++++++++++++++++++++++++++++++---- etc/vim/source/map.vim | 3 +- 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/etc/profile.d/functions b/etc/profile.d/functions index edc5e7f8..84f86adc 100755 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -584,37 +584,6 @@ find_sort_mtime() { # strftime "%a %b %e %H:%M:%S %Y" } -shell_replace() { - - local usage="Usage: shell_replace [-i[.BACKUP_EXTENSION]] [-find PATH]" - if [ -z "$*" -o "$1" = "--help" -o "$1" = "-h" ]; then - echo "$usage" - return - fi - - if [ "$1" = "-find" ]; then - shift - grep -ErlI '^.{1,3}SHELL_REPLACE (.*)$/ .. /^\s*.{1,3}; print; print map{s/^/$idt/;$_} `$cmd`; $ch = 1; -} else {$i=0;print -} -END { - warn $ARGV if 0 and $INPLACE_EDIT and $ch; -} -' $@ -} - # NB 13.04.18: TODO file_to_utf8() { local usage="file_to_utf8 [FILES|DIRS]" diff --git a/etc/vim/source/functions.vim b/etc/vim/source/functions.vim index 030e9029..3d2ddd11 100644 --- a/etc/vim/source/functions.vim +++ b/etc/vim/source/functions.vim @@ -146,20 +146,70 @@ func! MeNow() return $USER_INITIALS . ' ' . strftime('%d.%m.%y') endfunc +function Err(txt) + echo 'ERROR: '.a:txt + return +endfunc + +func! SubSpecialChar(c) + let i = 0 + let val = '' + for val in a:c + let a:c[i] = substitute(val,'\\n',"\n",'') + let i += 1 + endfor +endfunc + +func! CommentNewLine() + if ( g:mimeComment->get(&filetype) == '0') + return Err('No comment defined for filetype '.&filetype) + endif + let c = split(g:mimeComment[&filetype],'\s\+') + call SubSpecialChar(c) + + " Beginning of line + let new_line = c[0].' '.MeNow().': foo ' + + " End of line + if ( len(c)>1 ) + let new_line = new_line . c[1] + endif + + exec "normal! o".new_line."\\?foo\cw " +endfunc + func! CommentToggle() - let curr_line = getline('.') - let c = g:mimeComment[&filetype] + if ( g:mimeComment->get(&filetype) == '0') + return Err('No comment defined for filetype '.&filetype) + endif - " wipe out comment - "let exp = '^'.substitute(c,'\d\d\.\d\d\.\d\d','........','') + let curr_line = getline('.') + let c = split(g:mimeComment[&filetype],'\s\+') + " call SubSpecialChar(c) + " " Wipe out existing comment - let new_line = substitute(curr_line,'^\([\t ]*\)'.c.' .. \d\d\.\d\d\.\d\d ','\1','') + " + " Beginning of line + let new_line = substitute(curr_line,'^\([\t ]*\)'.c[0].' [^ ]\+ \d\d\.\d\d\.\d\d ','\1','') + " End of line + if ( len(c)>1 ) + let new_line = substitute(new_line,'\s*'.c[1].'\s*$','','') + endif if new_line == curr_line + " " Add comment - let v = '' - let new_line = substitute(curr_line,'^\([\t ]*\)','\1'.c.' '.MeNow().' ','') + " + " NB 11.12.22 let v = '' + " NB 11.12.22 let v = '' + " Beginning of line + let new_line = substitute(curr_line,'^\([\t ]*\)','\1'.c[0].' '.MeNow().' ','') + " End of line + if ( len(c)>1 ) + let new_line = substitute(new_line,'\s*$',' '.c[1],'') + endif + " let new_line = substitute(new_line,'\\n',"\n",'') endif call setline('.',new_line) diff --git a/etc/vim/source/map.vim b/etc/vim/source/map.vim index a4765704..b16374ef 100644 --- a/etc/vim/source/map.vim +++ b/etc/vim/source/map.vim @@ -22,4 +22,5 @@ map :bp " F5 - Comment " map o=FileGet('c').' '.$USER_INITIALS.': '.strftime('%d.%m.%y').': foo '.FileGet('cEnd')?foocw map o=FileGet('c').' '.FileGet('me_now').': foo '.FileGet('cEnd')?foocw -vmap :call FileCommentToggle() +vmap :call CommentToggle() +"vmap :call FileCommentToggle() -- 2.47.3