]> git.nbdom.net Git - nb.git/commitdiff
functions Comment handel default comment /tmp/nico.pm if not exists
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 12 Dec 2022 19:21:48 +0000 (20:21 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 12 Dec 2022 19:21:48 +0000 (20:21 +0100)
etc/vim/source/functions.vim

index 80b11f8c1738e9571560504a030f1dac8b6c20e0..b8259ed0d36744485cd69dcd1efd62e1924a6e17 100644 (file)
@@ -164,17 +164,20 @@ endfunc
 func! CommentNewLine()
 " NB 12.12.22: Create a new line of comment  
        if ( g:mimeComment->get(&filetype) == '0')
-               return Err('No comment defined for filetype '.&filetype)
+         let comment = '#'
+               " NB 12.12.22 return Err('No comment defined for filetype '.&filetype)
+       else
+               let comment = g:mimeComment->get(&filetype)
        endif
-       let c = split(g:mimeComment[&filetype],'\s\+')
-       call SubSpecialChar(c)
+       let comment = split(comment,'\s\+')
+       call SubSpecialChar(comment)
 
   " Beginning of line
-       let new_line = c[0].' '.MeNow().': foo '
+       let new_line = comment[0].' '.MeNow().': foo '
 
   " End of line
-       if ( len(c)>1 )
-         let new_line = new_line . c[1]
+       if ( len(comment)>1 )
+         let new_line = new_line . comment[1]
        endif
 
        exec "normal! o".new_line."\<esc>?foo\<cr>cw "
@@ -185,21 +188,24 @@ endfunc
 func! CommentToggle()
 " NB 12.12.22: Toggle current line between commented / not commented  
        if ( g:mimeComment->get(&filetype) == '0')
-               return Err('No comment defined for filetype '.&filetype)
+         let comment = '#'
+               " NB 12.12.22 return Err('No comment defined for filetype '.&filetype)
+       else
+               let comment = g:mimeComment->get(&filetype)
        endif
 
-       let curr_line = getline('.')
-       let c = split(g:mimeComment[&filetype],'\s\+')
-       " call SubSpecialChar(c)
+       let comment = split(comment,'\s\+')
+       " call SubSpecialChar(comment)
 
+       let curr_line = getline('.')
        "
        " Wipe out existing comment
   "
   " Beginning of line
-       let new_line = substitute(curr_line,'^\([\t ]*\)'.c[0].' [^ ]\+ \d\d\.\d\d\.\d\d ','\1','')
+       let new_line = substitute(curr_line,'^\([\t ]*\)'.comment[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*$','','')
+       if ( len(comment)>1 )
+         let new_line = substitute(new_line,'\s*'.comment[1].'\s*$','','')
        endif
 
        if new_line == curr_line
@@ -209,10 +215,10 @@ func! CommentToggle()
   " 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().' ','')
+         let new_line = substitute(curr_line,'^\([\t ]*\)','\1'.comment[0].' '.MeNow().' ','')
     " End of line
-         if ( len(c)>1 )
-           let new_line = substitute(new_line,'\s*$',' '.c[1],'')
+         if ( len(comment)>1 )
+           let new_line = substitute(new_line,'\s*$',' '.comment[1],'')
          endif
          " let new_line = substitute(new_line,'\\n',"\n",'')
        endif