Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added vim syntax file for SLI #253

Merged
merged 13 commits into from Apr 26, 2016
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -51,6 +51,10 @@ build/
.ipynb_checkpoints/
TAGS

### tags and cscope
tags
cscope.out

### CMAKE stuff
cmake_install.cmake
CMakeFiles/
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -263,8 +263,8 @@ configure_file(
)

configure_file(
"${PROJECT_SOURCE_DIR}/extras/emacs/sli.el.in"
"${PROJECT_BINARY_DIR}/extras/emacs/sli.el" @ONLY
"${PROJECT_SOURCE_DIR}/extras/EditorSupport/emacs/sli.el.in"
"${PROJECT_BINARY_DIR}/extras/EditorSupport/emacs/sli.el" @ONLY
)

configure_file(
Expand Down
16 changes: 14 additions & 2 deletions README.md
Expand Up @@ -17,6 +17,18 @@ information header in the source files.
Emacs users may use the SLI mode, which provides syntax highlighting
for SLI. To install it, add the following lines to your `.emacs` file:
```
(load-library "${prefix}/share/nest/extras/emacs/postscript-sli")
(load-library "${prefix}/share/nest/extras/emacs/sli")
(load-library "${prefix}/share/nest/extras/EditorSupport/emacs/postscript-sli")
(load-library "${prefix}/share/nest/extras/EditorSupport/emacs/sli")
```

A simple syntax file for VIM users has been provided. Copy it to your vim
configuration folder to make it available to VIM:
```
$ cp ${prefix}/share/nest/extras/EditorSupport/vim/syntax/sli.vim ~/.vim/syntax/sli.vim
```
Then add the following lines to your `~/.vimrc` file to use it:
```
" sli
au BufRead,BufNewFile *.sli set filetype=sli
au FileType sli setl foldenable foldmethod=syntax
```
8 changes: 6 additions & 2 deletions extras/CMakeLists.txt
Expand Up @@ -28,8 +28,12 @@ install( DIRECTORY bibliography logos
DESTINATION ${INSTALL_DOC_DIR}
)

install( FILES emacs/postscript-sli.el emacs/psvn.el ${CMAKE_CURRENT_BINARY_DIR}/emacs/sli.el
DESTINATION ${INSTALL_DATA_DIR}/extras/emacs
install( FILES EditorSupport/emacs/postscript-sli.el EditorSupport/emacs/psvn.el ${CMAKE_CURRENT_BINARY_DIR}/EditorSupport/emacs/sli.el
DESTINATION ${INSTALL_DATA_DIR}/extras/EditorSupport/emacs
)

install( FILES EditorSupport/vim/syntax/sli.vim
DESTINATION ${INSTALL_DATA_DIR}/extras/EditorSupport/vim/syntax
)

install( PROGRAMS
Expand Down
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions extras/EditorSupport/vim/syntax/sli.vim
@@ -0,0 +1,73 @@
" Vim syntax file
" Language: nest SLI
" Maintainer: Ankur Sinha/Nest initiative
" Latest revision: 01 March 2016

if exists("b:current_syntax")
finish
endif

setlocal softtabstop=2
setlocal cindent shiftwidth=2
setlocal tabstop=2
setlocal expandtab
setlocal cindent

syntax keyword sliTodo TODO XXX FIXME NOTE
hi def link sliTodo Todo

syn keyword sliKeyword abort abs abs_d abs_i ac_generator acos add addpath addtotrie allocations and append AppendTo Apply apropos arange area2 area array arrayload ArrayQ ArrayShape arraystore asin assert available backtrace_off backtrace_on begin bind break breakup callback call capacity case cd ceil cerr ChangeSubnet cin clear cleardict cleardictstack clic clock cloc clonedict close closeinput CompareFiles CompileMath Connect connruledict continue ConvergentConnect copy CopyFile CopyModel correlation_detector correlomatrix_detector correlospinmatrix_detector cos count countdictstack counttomark cout Create CreateRDV CreateRNG cst ctermid currentdict currentname CurrentSubnet cv1d convert 2-dimensional coordinates to 1-dim index cv2d cva cva_d cva_t cvd cvdict cvd_s cv_dv cvgidcollection cvi cvi_s cv_iv cvlit cvn cvo cvs cvs_f cvt_a cvx cycles CyclicValue DataConnect_a DataConnect DataConnect_i_D_s dc_generator debug debugoff debugon debug.sli def DeleteFile Device dexp dict DictQ dictstack Dimensions Directory dirname div DivergentConnect Dot1D Dot DoubleQ drand Drop dup2 dup edit elementstates empty end endl endusing environment eof eq_dv eq_iv eq erase Erfc Erf errordict eval EvaluateLiteralInfixes E exch exec ExecFunction ExecMath execstack executive exit exithook exp Export FileNames file FindConnections FindRoot FiniteQ First FixedPoint Flatten floor flush FoldList Fold forall forallindexed for fork FractionalPart frexp Function gabor_ Gammainc gamma_sup_generator gauss2d_ GaussDiskConv geq GetConnections getc GetDefaults get_d getenv GetGlobalChildren GetGlobalLeaves GetGlobalNodesInfo GetGlobalNodes GetGlobalRNG getinterval getline GetLocalChildren GetLocalLeaves GetLocalNodes GetMax GetMin GetNetwork GetOption GetOptions getPGRP getPID getPPID get gets GetStatus_dict GetStatus GetStatus_v GetSynapseStatus GetVpRNG GNUaddhistory GNUreadline good grep gt handleerror HasDifferentMemberQ helpdesk helpindex help iclear ieof ifail ifstream ignore igood in_avail index info info_ds initialize_module Inline insertelement insert inspect Install IntegerPart IntegerQ inv irand iround isatty is_mpi is_threaded is_threaded_with_openmp join joinpath JoinTo kernel keys kill known LambertW0 LambertWm1 LambertW Last LayoutArray LayoutNetwork ldexp length_a length length_d length_lp length_p length_s leq license LiteralQ ln load LocateFileNames log lookup loop ls lt MakeDirectory makehelp Map MapAt MapIndexed MapThread mark MathematicaToSliIndex mathexecutive MatrixQ Max max Mean MemberQ MemoryInfo memory_thisjob_bg memory_thisjob_darwin memory_thisjob MergeDictionary MergeLists message Min min mip_generator mkfifo mod modeldict modf Most MoveDirectory MoveFile ms2hms mul multimeter music_cont_in_proxy music_event_in_proxy music_event_out_proxy music_message_in_proxy namespace neg_d neg_i neg neq Nest nest_indirect NestList nest_serial Node noise_generator noop not npop NumberQ NumProcesses oclear oeof ofsopen ofstream ogood oldgetline ones operandstack Options OptionsDictionary or osstream ostrstream OuterProduct over page pageoutput parsestdin Partition Part path pclockspersec pclocks pcvs pgetrusage pick pipe Pi Plus poisson_generator_ps poisson_generator pop pow ppage ppd_sup_generator pp_pop_psc_delta pp_psc_delta pprint prepend print_error PrintNetwork print ProcessorName proxynode PseudoRecordingDevice pstack ptimes pulsepacket_generator put_d putinterval put pwd quit raiseagain raiseerror RandomArray RandomConvergentConnect RandomDivergentConnect Random RandomSubset Range Rank rdevdict ReadDouble ReadInt readline ReadList ReadModes readPGM Read ReadWord realtime RecordingDevice references regcomp regexdict regexec regex_find regex_find_r regex_find_rf regex_find_s regex_find_sf regex_replace RemoveDirectory removeguard repeatany repeat ReplaceOccurrences ReplacePart replace reserve ResetKernel ResetNetwork ResetOptions reset RestoreDictionary restoreestack RestoreOptions restoreostack restore Rest resume ResumeSimulation reverse rngdict rolld roll rollu rot round run SaveDictionary SaveOptions save ScanThread searchfile searchif searchifstream search seed Select SetAcceptableLatency SetDefaults Set SetDirectory SetFakeNumProcesses setguard setNONBLOCK SetNumRecProcesses SetOptions setpath setprecision SetStatus_dict SetStatus SetStatus_v SetSynapseStatus setverbosity SFWdumpparameters ShowDefaults ShowOptions ShowStatus shpawn shrink signaldict Sign Simulate sin sinusoidal_gamma_generator sinusoidal_poisson_generator size sleep_i sleep SLIFunctionWrapper SliToMathematicaIndex Sort spawn spike_detector spike_dilutor spike_generator spikes spin_detector Split spoon sqr sqrt stack StandardDeviation start statusdict step_current_generator StimulatingDevice stopped stop StringQ str subnet SubsetQ sub switchdefault switch symbol symbol_s synapsedict SyncProcesses sysexec system systemtime Table Take taskset taskset_thisjob TensorRank tic TimeCommunicationAlltoall TimeCommunicationAlltoall TimeCommunicationAlltoallv TimeCommunicationAlltoallv TimeCommunicationOffgrid TimeCommunication TimeCommunication TimeCommunicationv time Times tmpnam toc token_is token token_s ToLowercase ToMathematicaExpression topinfo_d Total ToUppercase Transpose trie trieinfo trim trunc typebind typeinfo type typestack undef unit_conversion UnitStep usertime using validate values Variance variant verbosity voltmeter volume_transmitter waitPID wait welcome which who whos writePGM xifstream xor zeros
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't change much, but do you want to keep the devices (like spike_detector in the list of keywords?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them after @heplesser 's remark that things from the API such as models may change in the future, and if we haven't a mechanism in place that will automatically update the list in sli.vim, we'd rather leave them out. I'm still looking at whether there's a way to autogenerate a list of keywords, but I think that requires a more complex plugin like YCM or something. I'm sure it can be done, I just haven't enough vim-fu to know how XD

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you. But there are still a lot of devices in the list of keywords. For example, there is the ac_generator, dc_generator, poisson_generator, spike_detector, spike_generator. voltmeter, volume_transmitter, multimeter, music_cont_in_proxy, ...

Please take a look again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've removed all the devices and models now - hopefully.

hi def link sliKeyword Keyword

syn keyword sliConstant M_INFO M_ERROR M_DEBUG M_WARNING M_STATUS M_FATAL
hi def link sliConstant Constant

syn match sliUnit '\smV'
syn match sliUnit '\spF'
syn match sliUnit '\spA'
syn match sliUnit '\sms'
syn match sliUnit '\ss'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases this line causes a wrong highlighting. For example, the in command M_ERROR setverbosity the s is highlighted as unit. You could add a space after the declaration of the units to prevent that to happen.

After you change that, 👍 from me. Thanks for this work, I already used it several times!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this - maybe I can add word boundaries or something to restrict the match.

syn match sliUnit '\sHz'
syn match sliUnit '\snS'
hi def link sliUnit Constant

syn match sliNumber '\d\+'
syn match sliNumber '[-+]\d\+'
syn match sliNumber '[-+]\d\+\.\d*'
syn match sliNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+'
syn match sliNumber '\d[[:digit:]]*[eE][\-+]\=\d\+'
syn match sliNumber '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
syn match sliNumber '\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
hi def link sliNumber Constant

" Identifiers
syn match sliIdentifier '/\w\+'
hi def link sliIdentifier Identifier

" Booleans
syn keyword sliBoolean true false
hi def link sliBoolean Boolean

" Regions
syn region sliFunc start="{" end="}" fold transparent
hi def link sliFunc Function

syn region sliDict start="<<" end=">>" fold transparent
hi def link sliDict Structure

syn region sliGroup start="(" end=")" fold transparent
hi def link sliGroup String

syn match sliComment "%.*$"
hi def link sliComment Comment
syn region sliCommentBlock start="/\*" end=".*\*/" fold
hi def link sliCommentBlock Comment

syn keyword sliConditional if ifelse
hi def link sliConditional Conditional

syn keyword sliRepeat forall repeat
hi def link sliRepeat Repeat

" Finishing touches
let b:current_syntax = "sli"