Skip to content
Snippets Groups Projects
Commit 7aed5dc2 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

vim2html script

allows syntax to be checked
parent d32feeb2
No related branches found
No related tags found
No related merge requests found
#! /bin/bash
VIMFILE="$PLUMED_ROOT"/src/lib/plumed.vim
if [ "$PLUMED_IS_INSTALLED" = yes ] ; then
VIMFILE="$PLUMED_ROOT/vim/syntax/$PLUMED_PROGRAM_NAME".vim
fi
if [ "$1" = --description ] ; then
echo "convert plumed input file to colored html using vim syntax"
exit 0
fi
if [ "$1" = --help ] ; then
cat << EOF
Usage:
plumed vim2html [options] < input > output
plumed vim2html [options] input > output
plumed vim2html [options] input output
(one of the three)
Options can be:
--annotate-syntax Reports annotated syntax on output.
Also reports non-annotated regions on stderr
EOF
exit 0
fi
if [ ! -f "$VIMFILE" ] ; then
echo "Cannot find vimfile at $VIMFILE"
exit 1
fi
annotate_syntax=no
inputfile=""
outputfile=""
for opt
do
case "$opt" in
(--annotate-syntax)
annotate_syntax=yes ;;
(-*)
echo "ERROR: Unknown option $opt. Use -h for help."
exit 1 ;;
(*)
if [ -z "$inputfile" ] ; then
inputfile="$opt"
elif [ -z "$outputfile" ] ; then
outputfile="$opt" ;
else
echo "ERROR: too many arguments"
exit 1
fi
esac
done
temp="$( mktemp -dt plumed.XXXXX)"
{
if [ -n "$inputfile" ] ; then
cat "$inputfile"
else
cat
# this is to remove \r characters
fi | tr '\r' ' '
} | {
cd $temp
{
if [ "$annotate_syntax" = "yes" ]; then
vim - -c ":syntax off" \
-c ":source $VIMFILE" \
-c ":call PlumedAnnotateSyntax()" \
-c ":wq! syntax.log" -c ":q!" 1> /dev/null 2> /dev/null
else
# this is a workaround for a bug in TOhtml
# that does not color properly when there are empty lines
sed "s/^$/ /" |
vim - -c ":syntax off" \
-c ":source $VIMFILE" \
-c ":let g:html_use_css = 0" \
-c ":let g:html_no_progress" \
-c ":let g:html_number_lines = 1" \
-c ":TOhtml" \
-c ":wq! out.html" -c ":q!" 1> /dev/null 2> /dev/null
fi
}
}
if [ "$annotate_syntax" = "yes" ] ; then
output="$(awk '{if($1=="ANNOTATION") print}' $temp/syntax.log 2>/dev/null)"
error="$(awk '{if($1=="ERROR") print}' $temp/syntax.log >&2 2>/dev/null)"
else
output="$(cat $temp/out.html | sed 's|^<title>.*</title>$||' | sed 's|^<meta.*$||')"
fi
if [ -n "$outputfile" ] ; then
echo "$output" > "$outputfile"
else
echo "$output"
fi
echo "$error" >&2
if [ -n "$error" ] ; then
exit 1
fi
......@@ -197,8 +197,49 @@ fun! CompletePlumed(findstart, base)
endfun
set omnifunc=CompletePlumed
" inspect the entire file to find lines containing
" non highlighted characters
fun! PlumedAnnotateSyntax()
" buffer where errors are written
let buffer=[]
let l=1
" loop over lines
while l <= line("$")
let line=getline(l)
let p=0
" line is assumed right a priori
let wrong=0
" position the cursor and redraw the screen
call cursor(l,1)
redraw! "! is required for some reason
while p <len(line)
if line[p] !~ "[ \t]"
let stack=synstack(l,p+1)
if(len(stack)==0)
let wrong=1
elseif(synIDattr(stack[len(stack)-1],"name")=~"^plumedLine.*")
let wrong=1
endif
let annotation=""
for s in stack
let annotation=annotation."+".synIDattr(s,"name")
endfor
call add(buffer,"ANNOTATION ".l." ".p." ".line[p]." ".annotation)
endif
let p=p+1
endwhile
if(wrong)
call add(buffer,"ERROR AT LINE ".l." : ".line)
endif
let l=l+1
endwhile
" dump the buffer on a new window
new
for l in buffer
put=l
endfor
endfun
EOF
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment