From 76a4d4ce714f943f48eacb29d6494c034f6373a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Neum=C3=A4rker?= Date: Sat, 8 Dec 2018 15:16:42 +0100 Subject: [PATCH] add vim syntax support --- Makefile | 17 ++++++++++ Makefile.inc.in | 2 ++ configure | 17 ++++++++-- contrib/vim/ftdetect/modulefile.vim | 6 ++++ contrib/vim/ftplugin/modulefile.vim | 23 +++++++++++++ contrib/vim/syntax/modulefile.vim | 51 +++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 contrib/vim/ftdetect/modulefile.vim create mode 100644 contrib/vim/ftplugin/modulefile.vim create mode 100644 contrib/vim/syntax/modulefile.vim diff --git a/Makefile b/Makefile index 197ed898..5bb0883e 100644 --- a/Makefile +++ b/Makefile @@ -248,6 +248,14 @@ ifeq ($(compatversion),y) cp $(COMPAT_DIR)/ChangeLog $(DESTDIR)$(docdir)/ChangeLog-compat cp $(COMPAT_DIR)/NEWS $(DESTDIR)$(docdir)/NEWS-compat endif +endif +ifeq ($(vimplugin),y) + mkdir -p $(DESTDIR)$(vimplugindir)/ftdetect + mkdir -p $(DESTDIR)$(vimplugindir)/ftplugin + mkdir -p $(DESTDIR)$(vimplugindir)/syntax + cp contrib/vim/ftdetect/modulefile.vim $(DESTDIR)$(vimplugindir)/ftdetect + cp contrib/vim/ftplugin/modulefile.vim $(DESTDIR)$(vimplugindir)/ftplugin + cp contrib/vim/syntax/modulefile.vim $(DESTDIR)$(vimplugindir)/syntax endif $(MAKE) -C init install DESTDIR=$(DESTDIR) ifeq ($(builddoc),y) @@ -271,6 +279,15 @@ endif rm -f $(DESTDIR)$(bindir)/add.modules rm -f $(DESTDIR)$(bindir)/modulecmd rm -f $(DESTDIR)$(bindir)/mkroot +ifeq ($(vimplugin),y) + rm -f $(DESTDIR)$(vimplugindir)/ftdetect/modulefile.vim + rm -f $(DESTDIR)$(vimplugindir)/ftplugin/modulefile.vim + rm -f $(DESTDIR)$(vimplugindir)/syntax/modulefile.vim + -rmdir $(DESTDIR)$(vimplugindir)/ftdetect + -rmdir $(DESTDIR)$(vimplugindir)/ftplugin + -rmdir $(DESTDIR)$(vimplugindir)/syntax + -rmdir -p $(DESTDIR)$(vimplugindir) +endif ifeq ($(docinstall),y) rm -f $(addprefix $(DESTDIR)$(docdir)/,ChangeLog README COPYING.GPLv2) ifeq ($(compatversion),y) diff --git a/Makefile.inc.in b/Makefile.inc.in index 7ff1547a..35eb8708 100644 --- a/Makefile.inc.in +++ b/Makefile.inc.in @@ -12,6 +12,7 @@ modulefilesdir := @modulefilesdir@ datarootdir := @datarootdir@ mandir := @mandir@ docdir := @docdir@ +vimplugindir := @vimplugindir@ # versioning mode installation versioning := @versioning@ @@ -40,6 +41,7 @@ setbinpath := @setbinpath@ appendbinpath := @appendbinpath@ setdotmodulespath := @setdotmodulespath@ docinstall := @docinstall@ +vimplugin := @vimplugin@ examplemodulefiles := @examplemodulefiles@ # able to build documentation? diff --git a/configure b/configure index a5440247..f459688c 100755 --- a/configure +++ b/configure @@ -27,9 +27,9 @@ targetlist="${progdir}/Makefile.inc ${progdir}/site.exp" # argument list arglist="TCLSH SPHINXBUILD PS BASENAME RMDIR_IGN_NON_EMPTY VERSION \ -baseprefix prefix bindir libexecdir etcdir initdir datarootdir mandir docdir \ +baseprefix prefix bindir libexecdir etcdir initdir datarootdir mandir docdir vimplugindir \ modulefilesdir setmanpath appendmanpath setbinpath appendbinpath \ -setdotmodulespath docinstall examplemodulefiles builddoc gitworktree \ +setdotmodulespath docinstall vimplugin examplemodulefiles builddoc gitworktree \ usemanpath compatversion EXEEXT versioning silentshdbgsupport \ quarantinesupport autohandling pager pageropts modulepath loadedmodules \ quarantinevars" @@ -48,6 +48,7 @@ setbinpath=y appendbinpath=n setdotmodulespath=n docinstall=y +vimplugin=y examplemodulefiles=y compatversion=y EXEEXT= @@ -78,6 +79,7 @@ initdir= datarootdir= mandir= docdir= +vimplugindir= modulefilesdir= modulepath= @@ -125,6 +127,7 @@ Fine tuning of the installation directories: --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc] + --vimplugindir=DIR vim plugin directory [DATAROOTDIR/vim/vimfiles] --modulefilesdir=DIR system modulefiles [PREFIX/modulefiles] Optional Features: @@ -139,6 +142,8 @@ Optional Features: --enable-doc-install install documentation files in the documentation directory defined with \'docdir' (no impact on man pages installation) [yes] + --enable-vimplugin install vim plugin files in the directory + defined with \'vimplugindir' [yes] --enable-example-modulefiles install in 'modulefilesdir' some modulefiles provided as examples [yes] @@ -205,6 +210,8 @@ placed in the following directory structure: man/ man1/ man4/ + vim/ + vimfiles/ modulefiles/" } @@ -296,6 +303,8 @@ for arg in "$@"; do mandir="${arg#*=}" ;; --docdir=*) docdir="${arg#*=}" ;; + --vimplugindir=*) + vimplugindir="${arg#*=}" ;; --modulefilesdir=*) modulefilesdir="${arg#*=}" ;; --enable-set-manpath*|--disable-set-manpath) @@ -312,6 +321,9 @@ for arg in "$@"; do --enable-doc-install*|--disable-doc-install) docinstall=$(get_feature_value "$arg") defdocinstall=0 ;; + --enable-vimplugin*|--disable-vimplugin) + vimplugin=$(get_feature_value "$arg") + defvimplugin=0 ;; --enable-example-modulefiles*|--disable-example-modulefiles) examplemodulefiles=$(get_feature_value "$arg") defexamplemodulefiles=0 ;; @@ -461,6 +473,7 @@ fi [ -z "$datarootdir" ] && datarootdir=$prefix/share [ -z "$mandir" ] && mandir=$datarootdir/man [ -z "$docdir" ] && docdir=$datarootdir/doc +[ -z "$vimplugindir" ] && vimplugindir=$datarootdir/vim/vimfiles [ -z "$modulefilesdir" ] && modulefilesdir=$prefix/modulefiles # default modulepath based on MODULE_VERSION if versioning enabled [ -z "$modulepath" -a "$versioning" = 'y' ] && modulepath=${modulefilesdir/#$prefix/$baseprefix\/\$MODULE_VERSION} diff --git a/contrib/vim/ftdetect/modulefile.vim b/contrib/vim/ftdetect/modulefile.vim new file mode 100644 index 00000000..e4db783a --- /dev/null +++ b/contrib/vim/ftdetect/modulefile.vim @@ -0,0 +1,6 @@ + +au BufNewFile,BufRead * + \ if (getline(1) =~? "^#%Module") | + \ set filetype=modulefile | + \ endif + diff --git a/contrib/vim/ftplugin/modulefile.vim b/contrib/vim/ftplugin/modulefile.vim new file mode 100644 index 00000000..e65b308b --- /dev/null +++ b/contrib/vim/ftplugin/modulefile.vim @@ -0,0 +1,23 @@ + +if exists("b:did_modulefile_ftplugin") + finish +endif +let b:did_modulefile_ftplugin = 1 + +set syntax=modulefile + +" adopted from tcl ftplugin: +let s:cpo_save = &cpo +set cpo-=C + +setlocal comments=:# +setlocal commentstring=#%s +setlocal formatoptions+=croql + +" Undo the stuff we changed. +let b:undo_ftplugin = "setlocal fo< com< cms< inc< inex< def< isf< kp<" . + \ " | unlet! b:browsefilter" + +" Restore the saved compatibility options. +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/contrib/vim/syntax/modulefile.vim b/contrib/vim/syntax/modulefile.vim new file mode 100644 index 00000000..4fe05131 --- /dev/null +++ b/contrib/vim/syntax/modulefile.vim @@ -0,0 +1,51 @@ + +" include tcl syntax +set syntax=tcl + +"Clear tcl keywords to match to avoid priority of keyword +" (e.g append vs append-path) +syn clear tclCommand + +" set again tclCommand with `syn match` +" Basic Tcl commands: http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm +syn match tclCommand "\v<(after|append|array|bgerror|binary|cd|chan|clock|close|concat)>" +syn match tclCommand "\v<(dde|dict|encoding|eof|error|eval|exec|exit|expr|fblocked)>" +syn match tclCommand "\v<(fconfigure|fcopy|file|fileevent|flush|format|gets|glob)>" +syn match tclCommand "\v<(global|history|http|incr|info|interp|join|lappend|lassign)>" +syn match tclCommand "\v<(lindex|linsert|list|llength|lmap|load|lrange|lrepeat)>" +syn match tclCommand "\v<(lreplace|lreverse|lsearch|lset|lsort|memory|my|namespace)>" +syn match tclCommand "\v<(next|nextto|open|package|pid|puts|pwd|read|refchan|regexp)>" +syn match tclCommand "\v<(registry|regsub|rename|scan|seek|self|set|socket|source)>" +syn match tclCommand "\v<(split|string|subst|tell|time|trace|unknown|unload|unset)>" +syn match tclCommand "\v<(update|uplevel|upvar|variable|vwait)>" + +" The 'Tcl Standard Library' commands: http://www.tcl.tk/man/tcl8.6/TclCmd/library.htm +syn match tclCommand "\v<(auto_execok|auto_import|auto_load|auto_mkindex|auto_reset)>" +syn match tclCommand "\v<(auto_qualify|tcl_findLibrary|parray|tcl_endOfWord)>" +syn match tclCommand "\v<(tcl_startOfNextWord|tcl_startOfPreviousWord)>" +syn match tclCommand "\v<(tcl_wordBreakAfter|tcl_wordBreakBefore)>" + +" Modulefile commands: https://modules.readthedocs.io/en/stable/modulefile.html +syn match modCommand "\v<(append|prepend|remove)-path>" +syn match modCommand "\v" +syn match modCommand "\v<(module|conflict|chdir|prereq)>" +syn match modCommand "\v" +syn match modCommand "\v<(un)?set-(alias|function)>" +syn match modCommand "\v<(un)?setenv>" +syn match modCommand "\v" +syn match modCommand "\v<(system|uname|x-resource)>" + +syn match modCommand "\v" + +hi def link modCommand tclSpecial + +syn match modProc "\v" +syn match modProc "\v" +syn match modProc "\v" + +hi def link modProc tclSpecial + + +syn match modVar "\v" +hi def link modVar tclSpecial +