]> git.nbdom.net Git - nb.git/commitdiff
etc/vim/source/functions.vim
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 11 Dec 2022 16:31:17 +0000 (17:31 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 11 Dec 2022 16:31:17 +0000 (17:31 +0100)
etc/profile.d/functions
etc/vim/source/functions.vim
etc/vim/source/map.vim

index edc5e7f8ca6a728fd6b2e08b6de766f4e20ac063..84f86adc98ec0274b3ad73a7dfa777ef951a98cc 100755 (executable)
@@ -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' ${@:?$usage}
-               return
-       fi
-
-       perl -ne '
-if (/^(\s*).{1,3}>SHELL_REPLACE (.*)$/ .. /^\s*.{1,3}<SHELL_REPLACE.*/){
- $ch = 1;
- $idt = $1;
- $cmd = "bash -lc \"$2\"";
- $i++;
- if ($i==1) { print; print map{s/^/$idt/;$_} `$cmd`; }
- elsif (/^\s*.{1,3}<SHELL_REPLACE/) { print; }
-} elsif (/^(\s*).{1,3}=SHELL_REPLACE (.*)$/) { $idt=$1; <>; 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]"
index 030e90291dbd676adfc745a041403a2ac53d33ac..3d2ddd11fcab26bab9edb0e41de97263592606bc 100644 (file)
@@ -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."\<cr>\<esc>?foo\<cr>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)
index a47657047935afccacd9906fbdb995514a171ddc..b16374ef2aeeb4c951f1f1e5be040a49b2c023b9 100644 (file)
@@ -22,4 +22,5 @@ map <C-b> :bp<C-M>
 " F5 - Comment
 " map <F5> o<C-R>=FileGet('c').' '.$USER_INITIALS.': '.strftime('%d.%m.%y').': foo '.FileGet('cEnd')<CR><Esc>?foo<CR>cw
 map <F5> o<C-R>=FileGet('c').' '.FileGet('me_now').': foo '.FileGet('cEnd')<CR><Esc>?foo<CR>cw
-vmap <F5> :call FileCommentToggle()<CR>
+vmap <F5> :call CommentToggle()<CR>
+"vmap <F5> :call FileCommentToggle()<CR>