ViM syntax file?

Started by Excalibor, July 13, 2004, 03:18:47 AM

Previous topic - Next topic

Excalibor

Hello there!



has anyone, by any luck, written a syntax file specifically for newLISP syntax? Neither LISP nor Scheme suit it perfectly...



I could do so myself, and probably will do if nobody has just done before me :-P



thanks for all,

david



PS- testing 8.0.8; it's working 100% so far

Lutz

#1
Sounds like a great idea, you can use the following to create a list of operators and functions in a file keywords.txt:



(device (open "keywords.txt" "w"))

(dolist (s (symbols)) (if (primitive? (eval s)) (println s)))

(close (device))



add 'nil', and 'true' and you have everything. Curly braces {,} can also be used as string delimeters in newLISP , in case VIM can handle that for coloring strings, and there are the tags [text] and [/text], which also are used to delimit bigger string portions. ; and # are used for starting comment lines, I think thats all.



Lutz

Excalibor

#2
OK, it's done. :-)



Based on lisp.vim syntax file (tried scheme.vim but it didn't work out very well)



It supports all of newLISP as of version 8.0.8, including using ; and # for comments, and all of "", {} and [text][/text] strings...



I'd like to tweak it more so it highlights the first element of every list that's not quoted (cause it must be a function or a macro, as in Scheme) and highlighting in a different color user functions and macros should be nice... but that will have to wait until I read more vim help files and test some more, so probably in a future release...



I'll email it to you so you can make it generally available or even add it to the distribution, same license than newLISP or similar files apply and that should work out pretty well, I think...



laters!

david

Lutz

#3
When you email please put the word 'newlisp' in the subject line. You also can it just include it in your posting with between tags.



Lutz



ps: I mean [ code ] [ / code ] tags

nigelbrown

#4
Hi David,

Please post the syntax file - I use Vim for newlisp and it would be useful for me.

Regards

Nigel

Excalibor

#5
OK, by popular petition, here it goes. It has some caveats (specially with using quotes within strings (for regexes as stuff) but it's inmediately useful (I am using it right now writing an application :-)



Also, by default *.lsp files are associated to lisp.vim syntax file, and using "au" commands to change this from my .vimrc isn't working, thus I write "# vim: ts=2 syntax=newlisp" after the "#!" line on my scripts and vim does the right thing... i also like 2 spaces indents when writing lispy code but the syntax file shouldn't force that...



finally, it syntaxifies newLISP version 8.0.8 which is the one I am using, if any 8.0.6 function is not highlighted is because it has been deprecated in 8.0.8, please take it as an early warning, ie. a feature and not a bug... ;-)



enjoy it, I'll try to hang it on a website for everybody to download and to keep it updated/enhance it... BTW I give Lutz all permissions needed to add it to the newlisp distro if he thinks it will be a good thing to do, apply any convenient free software licence to it and it will be OK. Same for everyone else...



laters,

david



PS.- the code. Install as $HOME/.vim/syntax/newlisp.vim.



" Vim syntax file
" Language:    newLISP
" Maintainer:  David S. de Lis <ocarina@tierramedia.org>
" Last Change: 2004-07-15
" Version:     1.0.1
"              (based on lisp.vim version 13,
"              http://www.erols.com/astronaut/vim/index.html#vimlinks_syntax)
" URL: http://www.geocities.com/excaliborus/newlisp/newlisp.vim (eventually)
" History: ver 1.0    initial version from lisp.vim
"          ver 1.0.1  tweaked to finally recognize [text][/text] strings
"
"

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

if version >= 600
 setlocal iskeyword=42,43,45,47-58,60-62,64-90,97-122,_
else
 set iskeyword=42,43,45,47-58,60-62,64-90,97-122,_
endif

" Clusters
syn cluster       newlispAtomCluster      contains=newlispAtomBarSymbol,newlispAtomList,newlispAtomNmbr0,newlispComment,newlispDecl,newlispFunc,newlispLeadWhite
syn cluster       newlispListCluster      contains=newlispAtom,newlispAtomBarSymbol,newlispAtomMark,newlispBQList,newlispBarSymbol,newlispComment,newlispConcat,newlispDecl,newlispFunc,newlispKey,newlispList,newlispNumber,newlispSpecial,newlispSymbol,newlispVar,newlispLeadWhite

" Lists
syn match       newlispSymbol        contained         ![^()'{}"; t]+!
syn match       newlispBarSymbol     contained         !|..-|!
syn region       newlispList        matchgroup=Delimiter start="(" skip="|.{-}|"          matchgroup=Delimiter end=")" contains=@newlispListCluster,newlispString
syn region       newlispString        matchgroup=Delimiter start="{" skip="|.{-}|"          matchgroup=Delimiter end="}" contains=@newlispListCluster,newlispString
syn region       newlispStringBig        matchgroup=Delimiter start="[text]" skip="|.{-}|"          matchgroup=Delimiter end="[/text]" contains=@newlispListCluster,newlispString
syn region       newlispBQList        matchgroup=PreProc   start="`("  skip="|.{-}|"        matchgroup=PreProc   end=")" contains=@newlispListCluster,newlispString
" Atoms
syn match       newlispAtomMark        "'"
syn match       newlispAtom        "'("me=e-1         contains=newlispAtomMark      nextgroup=newlispAtomList
syn match       newlispAtom        "'[^ t()]+"         contains=newlispAtomMark
syn match       newlispAtomBarSymbol      !'|..-|!         contains=newlispAtomMark
syn region       newlispAtom        start=+'"+         skip=+\"+ end=+"+
syn region       newlispAtom        start=+'{+         skip=+\}+ end=+}+
syn region       newlispAtomList        contained         matchgroup=Special start="("      skip="|.{-}|" matchgroup=Special end=")"            contains=@newlispAtomCluster,newlispString
syn match       newlispAtomNmbr        contained         "<d+"
syn match       newlispLeadWhite        contained         "^s+"

" Standard newlisp Functions and Macros
" lists, flow and integers
syn keyword newlispFunc + - * / % < > = <= >= != and append apply
syn keyword newlispFunc args assoc begin case catch collect cond cons
syn keyword newlispFunc constant count define define-macro difference
syn keyword newlispFunc dolist dotimes dotree ends-with eval first filter
syn keyword newlispFunc find flat for if index intersect last length let
syn keyword newlispFunc list lookup map match member name not nth nth-set
syn keyword newlispFunc or pop push quote ref rest replace replace-assoc
syn keyword newlispFunc reverse rotate select set setq set! set-nth
syn keyword newlispFunc silent slice sort starts-with swap unique unless
syn keyword newlispFunc until while
" floats and special math
syn keyword newlispFunc max min abs acos add asin atan atan2
syn keyword newlispFunc beta beta1 binomial ceil crit-z cos dec div exp
syn keyword newlispFunc fft floor gammai atan ifft inc log mod mul normal
syn keyword newlispFunc pow prob-chi2 prob-z sequence series sin rand random
syn keyword newlispFunc seed sqrt sub tan
" bits
syn keyword newlispFunc << >> & | ^ ~
" matrices
syn keyword newlispFunc invert multiply transpose
" arrays
syn keyword newlispFunc array array-list array? nth-set set-nth
" financial
syn keyword newlispFunc fv irr nper npv pv pmt
" date and time
syn keyword newlispFunc date date-value now time time-of-day
" strings and conversions
syn keyword newlispFunc append char chop collect ends-with encrypt
syn keyword newlispFunc eval-string explode find first float format
syn keyword newlispFunc get-char get-float get-integer get-string integer
syn keyword newlispFunc join last lower-case match nth nth-set pack
syn keyword newlispFunc parse regex replace rest reverse select set-nth
syn keyword newlispFunc slice source starts-with string symbol trim unicode
syn keyword newlispFunc unpack upper-case utf8 xml-error xml-parse
syn keyword newlispFunc xml-type-tags
" IO and files
syn keyword newlispFunc close command-line current-line device exec
syn keyword newlispFunc get-url load open post-url print println put-url
syn keyword newlispFunc read-buffer read-char read-file read-line save
syn keyword newlispFunc search seek write-buffer write-char write-file
syn keyword newlispFunc write-line
" directories
syn keyword newlispFunc change-dir copy-file delete-file directory file-info
syn keyword newlispFunc make-dir remove-dir rename-file
" system and predicates
syn keyword newlispFunc ! atom? break catch context context? debug delete
syn keyword newlispFunc directory? empty? env environ error-event error-number
syn keyword newlispFunc error-test exec file? float? getenv global import
syn keyword newlispFunc integer? lambda? list? macro? main-args NaN? new
syn keyword newlispFunc pipe pretty-print primitive? process putenv quote?
syn keyword newlispFunc reset set-locale sleep string? symbol? symbols
syn keyword newlispFunc sys-info throw trace trace-highlight
" network TCP/IP API
syn keyword newlispFunc net-accept net-close net-connect net-error net-listen
syn keyword newlispFunc net-local net-lookup net-peer net-peek net-receive
syn keyword newlispFunc net-receive-udp net-select net-send net-send-udp
syn keyword newlispFunc net-service net-sessions
" boolean values
syn keyword newlispBoolean true false

" Strings
syn region       newlispString        start=+"+ skip=+\\|\"+ end=+"+
syn region       newlispString        start=+{+ skip=+\\|\}+ end=+}+
syn region       newlispString        start=+[text]+ skip=+\\|\]+ end=+[/text]+

" Declarations, Macros, Functions
syn keyword newlispDecl     define  define-macro

" Numbers: supporting integers and floating point numbers
syn match newlispNumber     "-=(.d+|d+(.d*)=)(e[-+]=d+)="
syn match newlispNumber    "[-#+0-9.][-#+0-9a-feEx]*"

" syn match newlispSpecial     "*[a-zA-Z_][a-zA-Z_0-9-]**"
" syn match newlispSpecial     !#|[^()'`,"; t]+|#!
" syn match newlispSpecial     !#x[0-9a-fA-F]+!
" syn match newlispSpecial     !#o[0-7]+!
" syn match newlispSpecial     !#b[01]+!
" syn match newlispSpecial     !#\[ -~]!
" syn match newlispSpecial     !#[':][^()'`,"; t]+!
" syn match newlispSpecial     !#([^()'`,"; t]+)!

" syn match newlispConcat     "s.s"
syn match newlispParenError   ")"

" Comments
syn cluster newlispCommentGroup   contains=newlispTodo
syn match   newlispComment     ";.*$"          contains=@newlispCommentGroup
syn match   newlispComment     "#.*$"          contains=@newlispCommentGroup
"syn region  newlispCommentRegion   start="#|" end="|#"      contains=newlispCommentRegion,@newlispCommentGroup

" synchronization
syn sync lines=100

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_newlisp_syntax_inits")
  if version < 508
    let did_newlisp_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink newlispCommentRegion   newlispComment
  HiLink newlispAtomNmbr     newlispNumber
  HiLink newlispAtomMark     newlispMark
  HiLink newlispStringBig   newlispString
  HiLink newlispStringOpt   newlispString

  HiLink newlispAtom     Identifier
  HiLink newlispAtomBarSymbol   Special
  HiLink newlispBarSymbol     Special
  HiLink newlispBoolean     Special
  HiLink newlispComment     Comment
  HiLink newlispConcat     Statement
  HiLink newlispDecl     Statement
  HiLink newlispFunc     Statement
  HiLink newlispKey     Type
  HiLink newlispMark     Delimiter
  HiLink newlispNumber     Number
  HiLink newlispParenError     Error
  HiLink newlispSpecial     Type
  HiLink newlispString     String
  HiLink newlispTodo     Todo
  HiLink newlispVar     Statement

  delcommand HiLink
endif

let b:current_syntax = "newlisp"

" vim: ts=2

nigelbrown

#6
Thanks David - very nice.

I put the file in /usr/share/vim/syntax/ as lisp.vim (Mandrake 9.1)



I notice the fn keyword isn't highlighted



Regards

Nigel

Excalibor

#7
Hi there,


Quote from: "nigelbrown"Thanks David - very nice.

I put the file in /usr/share/vim/syntax/ as lisp.vim (Mandrake 9.1)


ah, that will definitely work ;-)


Quote
I notice the fn keyword isn't highlighted



Regards

Nigel


true... and silly me for not noticing (my own code is full of lambdas...) I'll check it and provide a fixed version ASAP...



thanks and laters,

david

Excalibor

#8
OK, solved :-P



where it says: "syn keyword newlispFunc until while" in line 62, change it to "syn keyword newlispFunc until while lambda fn" and that's it...



I'll upload it ASAP to the website



laters,

david



UPDATE: newlisp.vim available from:



http://www.geocities.com/excaliborus/newlisp/">http://www.geocities.com/excaliborus/newlisp/

Lutz

#9
Thanks David for this great contribution, many of us use Vim, this is a great enhancement for newLISP. With your permission (I think you gave it already) it will be include in the next newLISP release 8.1, due during the next weeks or so.



Lutz

Lutz

#10
there is a also link to yopur site here: http://www.newlisp.org/index.cgi?Code_Contributions">http://www.newlisp.org/index.cgi?Code_Contributions



lutz

Lutz

#11
I created .vim/synax/newlisp.vim and .vimrc containing 'syntax enable' in my home directory in CYGWIN, but I only get highlighting for strings (brown). Went through the Vim docs but cannot figure out what I am doing wrong, can somebody help me out?



Lutz

Lutz

#12
got it working by replacing the old /usr/share/vim/syntax/lisp.vim



Lutz

danil

#13
Thanks David



Lutz, it seems that correct way to enable newlisp syntax is to put next code in ~/.vimrc (assuming syntax was saved in newlisp.vim)

au BufNewFile,BufRead *.lsp,*.lisp setf newlisp
au BufNewFile,BufRead *.lsp,*.lisp vmap <F5> <F5>
au BufNewFile,BufRead *.lsp,*.lisp imap <F5> <ESC><F5>
au BufNewFile,BufRead *.lsp,*.lisp map <F5> :w! ~/.vim/lisp.src<CR>:!newlisp ~/.vim/lisp.src<CR>

Three other lines map F5 to save current vim buffer (or even visual selection) to certain file and load it into newlisp - very handy for testing, may be someone find it usefull too.



BTW, is it possible to get line numbers where newlisp fails? It is somewhat painfull to see something like "missing parenthesis : ")n" without any other hint.

Excalibor

#14
Quote from: "Lutz"Thanks David for this great contribution, many of us use Vim, this is a great enhancement for newLISP. With your permission (I think you gave it already) it will be include in the next newLISP release 8.1, due during the next weeks or so.



Lutz


Thanks to you for a great programming tool, I am having lots of fun working with newLISP! :-)



regarding the vim syntax file, yes, feel free to add it to the distribution, I will actually be honored... Regarding releasing, I'll try to keep it updated before releases, if you want to drop me an email one day or so before doing a final release I think I'l manage to give you an updated version for the tarball... just drop me an email to excaliborus [at] yahoo.com or to ocarina [at] tierramedia.org and that will do... I'll try to be watchful, anyway...



laters,

david