# 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]"
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)