Skip to content
Browse files

Upgrade VimClojure to 2.3.1.

  • Loading branch information...
1 parent 97f42c5 commit fbeb53c68073eaad4e71fae09e995d7ba0591968 @jszakmeister committed Jan 15, 2012
Showing with 209 additions and 158 deletions.
  1. +60 −47 autoload/vimclojure.vim
  2. +53 −34 autoload/vimclojure/util.vim
  3. +1 −1 doc/notes.txt
  4. +15 −12 ftplugin/clojure.vim
  5. +70 −60 indent/clojure.vim
  6. +10 −4 syntax/clojure.vim
View
107 autoload/vimclojure.vim
@@ -107,33 +107,34 @@ function! vimclojure#AddCompletions(ns)
endif
endfunction
-" Nailgun part:
-function! vimclojure#ExtractSexpr(toplevel)
- let closure = {
- \ "flag" : (a:toplevel ? "r" : ""),
- \ "level" : (a:toplevel ? "0" : '\d')
- \ }
+function! ClojureExtractSexprWorker() dict
+ let pos = [0, 0]
+ let start = getpos(".")
- function closure.f() dict
- let pos = [0, 0]
- let start = getpos(".")
+ if getline(start[1])[start[2] - 1] == "("
+ \ && vimclojure#util#SynIdName() =~ 'clojureParen' . self.level
+ let pos = [start[1], start[2]]
+ endif
- if getline(start[1])[start[2] - 1] == "("
- \ && vimclojure#util#SynIdName() =~ 'clojureParen' . self.level
- let pos = [start[1], start[2]]
- endif
+ if pos == [0, 0]
+ let pos = searchpairpos('(', '', ')', 'bW' . self.flag,
+ \ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"')
+ endif
- if pos == [0, 0]
- let pos = searchpairpos('(', '', ')', 'bW' . self.flag,
- \ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"')
- endif
+ if pos == [0, 0]
+ throw "Error: Not in a s-expression!"
+ endif
- if pos == [0, 0]
- throw "Error: Not in a s-expression!"
- endif
+ return [pos, vimclojure#util#Yank('l', 'normal! "ly%')]
+endfunction
- return [pos, vimclojure#util#Yank('l', 'normal! "ly%')]
- endfunction
+" Nailgun part:
+function! vimclojure#ExtractSexpr(toplevel)
+ let closure = {
+ \ "flag" : (a:toplevel ? "r" : ""),
+ \ "level" : (a:toplevel ? "0" : '\d'),
+ \ "f" : function("ClojureExtractSexprWorker")
+ \ }
return vimclojure#util#WithSavedPosition(closure)
endfunction
@@ -225,6 +226,7 @@ let vimclojure#Object = {}
function! vimclojure#Object.New(...) dict
let instance = copy(self)
+ let instance.prototype = self
call call(instance.Init, a:000, instance)
@@ -321,21 +323,29 @@ let vimclojure#ResultBuffer["__superBufferNew"] = vimclojure#ResultBuffer["New"]
let vimclojure#ResultBuffer["__superBufferInit"] = vimclojure#ResultBuffer["Init"]
let vimclojure#ResultBuffer.__instance = []
+function! ClojureResultBufferNewWorker() dict
+ set switchbuf=useopen
+ call self.instance.goHereWindow()
+ call call(self.instance.Init, self.args, self.instance)
+
+ return self.instance
+endfunction
+
function! vimclojure#ResultBuffer.New(...) dict
if g:vimclojure#ResultBuffer.__instance != []
- let closure = {
- \ 'instance' : g:vimclojure#ResultBuffer.__instance[0],
- \ 'args' : a:000
- \ }
- function closure.f() dict
- set switchbuf=useopen
- call self.instance.goHereWindow()
- call call(self.instance.Init, self.args, self.instance)
-
- return self.instance
- endfunction
-
- return vimclojure#util#WithSavedOption('switchbuf', closure)
+ let oldInstance = g:vimclojure#ResultBuffer.__instance[0]
+
+ if oldInstance.prototype is self
+ let closure = {
+ \ 'instance' : oldInstance,
+ \ 'args' : a:000,
+ \ 'f' : function("ClojureResultBufferNewWorker")
+ \ }
+
+ return vimclojure#util#WithSavedOption('switchbuf', closure)
+ else
+ call oldInstance.close()
+ endif
endif
let b:vimclojure_result_buffer = 1
@@ -401,13 +411,16 @@ if !exists("vimclojure#NailgunClient")
let vimclojure#NailgunClient = "ng"
endif
-function! vimclojure#ShellEscapeArguments(vals)
- let closure = { 'vals': a:vals }
+function! ClojureShellEscapeArgumentsWorker() dict
+ set noshellslash
+ return map(copy(self.vals), 'shellescape(v:val)')
+endfunction
- function closure.f() dict
- set noshellslash
- return map(copy(self.vals), 'shellescape(v:val)')
- endfunction
+function! vimclojure#ShellEscapeArguments(vals)
+ let closure = {
+ \ 'vals': a:vals,
+ \ 'f' : function("ClojureShellEscapeArgumentsWorker")
+ \ }
return vimclojure#util#WithSavedOption('shellslash', closure)
endfunction
@@ -664,17 +677,17 @@ function! vimclojure#EvalToplevel()
wincmd p
endfunction
+function! ClojureEvalParagraphWorker() dict
+ normal! }
+ return line(".")
+endfunction
+
function! vimclojure#EvalParagraph()
let file = vimclojure#BufferName()
let ns = b:vimclojure_namespace
let startPosition = line(".")
- let closure = {}
-
- function! closure.f() dict
- normal! }
- return line(".")
- endfunction
+ let closure = { 'f' : function("ClojureEvalParagraphWorker") }
let endPosition = vimclojure#util#WithSavedPosition(closure)
View
87 autoload/vimclojure/util.vim
@@ -19,60 +19,79 @@ function! vimclojure#util#WithSaved(closure)
return r
endfunction
-function! vimclojure#util#WithSavedPosition(closure)
- function a:closure.save() dict
- let [ _b, l, c, _o ] = getpos(".")
- let b = bufnr("%")
- return [b, l, c]
- endfunction
+function! s:SavePosition() dict
+ let [ _b, l, c, _o ] = getpos(".")
+ let b = bufnr("%")
+ return [b, l, c]
+endfunction
- function a:closure.restore(value) dict
- let [b, l, c] = a:value
+function! s:RestorePosition(value) dict
+ let [b, l, c] = a:value
- if bufnr("%") != b
- execute b "buffer!"
- endif
- call setpos(".", [0, l, c, 0])
- endfunction
+ if bufnr("%") != b
+ execute b "buffer!"
+ endif
+ call setpos(".", [0, l, c, 0])
+endfunction
+
+function! vimclojure#util#WithSavedPosition(closure)
+ let a:closure.save = function("s:SavePosition")
+ let a:closure.restore = function("s:RestorePosition")
return vimclojure#util#WithSaved(a:closure)
endfunction
+function! s:SaveRegister(reg)
+ return [a:reg, getreg(a:reg, 1), getregtype(a:reg)]
+endfunction
+
+function! s:SaveRegisters() dict
+ return map([self._register, "", "/", "-",
+ \ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
+ \ "s:SaveRegister(v:val)")
+endfunction
+
+function! s:RestoreRegisters(registers) dict
+ for register in a:registers
+ call call(function("setreg"), register)
+ endfor
+endfunction
+
function! vimclojure#util#WithSavedRegister(reg, closure)
let a:closure._register = a:reg
+ let a:closure.save = function("s:SaveRegisters")
+ let a:closure.restore = function("s:RestoreRegisters")
- function a:closure.save() dict
- return [getreg(self._register, 1), getregtype(self._register)]
- endfunction
+ return vimclojure#util#WithSaved(a:closure)
+endfunction
- function a:closure.restore(value) dict
- call call(function("setreg"), [self._register] + a:value)
- endfunction
+function! s:SaveOption() dict
+ return eval("&" . self._option)
+endfunction
- return vimclojure#util#WithSaved(a:closure)
+function! s:RestoreOption(value) dict
+ execute "let &" . self._option . " = a:value"
endfunction
function! vimclojure#util#WithSavedOption(option, closure)
let a:closure._option = a:option
-
- function a:closure.save() dict
- return eval("&" . self._option)
- endfunction
-
- function a:closure.restore(value) dict
- execute "let &" . self._option . " = a:value"
- endfunction
+ let a:closure.save = function("s:SaveOption")
+ let a:closure.restore = function("s:RestoreOption")
return vimclojure#util#WithSaved(a:closure)
endfunction
-function! vimclojure#util#Yank(r, how)
- let closure = {'reg': a:r, 'yank': a:how}
+function! s:DoYank() dict
+ silent execute self.yank
+ return getreg(self.reg)
+endfunction
- function closure.f() dict
- silent execute self.yank
- return getreg(self.reg)
- endfunction
+function! vimclojure#util#Yank(r, how)
+ let closure = {
+ \ 'reg': a:r,
+ \ 'yank': a:how,
+ \ 'f': function("s:DoYank")
+ \ }
return vimclojure#util#WithSavedRegister(a:r, closure)
endfunction
View
2 doc/notes.txt
@@ -1244,7 +1244,7 @@ Installation:
VIMCLOJURE *notes_vimclojure*
Support for the Clojure programming language |VimClojure|
-Version 2.3.0 from http://www.vim.org/scripts/script.php?script_id=2501
+Version 2.3.1 from http://www.vim.org/scripts/script.php?script_id=2501
Installation:
- Ran "unzip /path/to/vimclojure-<version>.zip -x LICENSE.txt README.markdown"
View
27 ftplugin/clojure.vim
@@ -59,22 +59,25 @@ for ns in [ "clojure.core", "clojure.inspector", "clojure.java.browse",
endfor
" Define toplevel folding if desired.
-function! ClojureGetFoldingLevel(lineno)
- let closure = { 'lineno' : a:lineno }
+function! ClojureGetFoldingLevelWorker() dict
+ execute self.lineno
- function closure.f() dict
- execute self.lineno
+ if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
+ return 1
+ endif
- if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
- return 1
- endif
+ if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
+ return 1
+ endif
- if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
- return 1
- endif
+ return 0
+endfunction
- return 0
- endfunction
+function! ClojureGetFoldingLevel(lineno)
+ let closure = {
+ \ 'lineno' : a:lineno,
+ \ 'f' : function("ClojureGetFoldingLevelWorker")
+ \ }
return vimclojure#WithSavedPosition(closure)
endfunction
View
130 indent/clojure.vim
@@ -31,82 +31,85 @@ function! s:MatchPairs(open, close, stopat)
\ a:stopat)
endfunction
-function! s:CheckForString()
- let closure = {}
-
- function closure.f() dict
- " Check whether there is the last character of the previous line is
- " highlighted as a string. If so, we check whether it's a ". In this
- " case we have to check also the previous character. The " might be the
- " closing one. In case the we are still in the string, we search for the
- " opening ". If this is not found we take the indent of the line.
- let nb = prevnonblank(v:lnum - 1)
+function! ClojureCheckForStringWorker() dict
+ " Check whether there is the last character of the previous line is
+ " highlighted as a string. If so, we check whether it's a ". In this
+ " case we have to check also the previous character. The " might be the
+ " closing one. In case the we are still in the string, we search for the
+ " opening ". If this is not found we take the indent of the line.
+ let nb = prevnonblank(v:lnum - 1)
+
+ if nb == 0
+ return -1
+ endif
- if nb == 0
- return -1
- endif
+ call cursor(nb, 0)
+ call cursor(0, col("$") - 1)
+ if vimclojure#util#SynIdName() != "clojureString"
+ return -1
+ endif
- call cursor(nb, 0)
- call cursor(0, col("$") - 1)
+ " This will not work for a " in the first column...
+ if vimclojure#util#Yank('l', 'normal! "lyl') == '"'
+ call cursor(0, col("$") - 2)
if vimclojure#util#SynIdName() != "clojureString"
return -1
endif
-
- " This will not work for a " in the first column...
- if vimclojure#util#Yank('l', 'normal! "lyl') == '"'
- call cursor(0, col("$") - 2)
- if vimclojure#util#SynIdName() != "clojureString"
- return -1
- endif
- if vimclojure#util#Yank('l', 'normal! "lyl') != '\\'
- return -1
- endif
- call cursor(0, col("$") - 1)
+ if vimclojure#util#Yank('l', 'normal! "lyl') != '\\'
+ return -1
endif
+ call cursor(0, col("$") - 1)
+ endif
- let p = searchpos('\(^\|[^\\]\)\zs"', 'bW')
+ let p = searchpos('\(^\|[^\\]\)\zs"', 'bW')
- if p != [0, 0]
- return p[1] - 1
- endif
+ if p != [0, 0]
+ return p[1] - 1
+ endif
- return indent(".")
- endfunction
+ return indent(".")
+endfunction
- return vimclojure#util#WithSavedPosition(closure)
+function! s:CheckForString()
+ return vimclojure#util#WithSavedPosition({
+ \ 'f' : function("ClojureCheckForStringWorker")
+ \ })
endfunction
-function! s:IsMethodSpecialCase(position)
- let closure = { 'pos': a:position }
+function! ClojureIsMethodSpecialCaseWorker() dict
+ " Find the next enclosing form.
+ call vimclojure#util#MoveBackward()
- function closure.f() dict
- " Find the next enclosing form.
- call vimclojure#util#MoveBackward()
+ " Special case: we are at a '(('.
+ if vimclojure#util#Yank('l', 'normal! "lyl') == '('
+ return 0
+ endif
+ call cursor(self.pos)
- " Special case: we are at a '(('.
- if vimclojure#util#Yank('l', 'normal! "lyl') == '('
- return 0
- endif
- call cursor(self.pos)
+ let nextParen = s:MatchPairs('(', ')', 0)
- let nextParen = s:MatchPairs('(', ')', 0)
+ " Special case: we are now at toplevel.
+ if nextParen == [0, 0]
+ return 0
+ endif
+ call cursor(nextParen)
+
+ call vimclojure#util#MoveForward()
+ let keyword = vimclojure#util#Yank('l', 'normal! "lye')
+ if index([ 'deftype', 'defrecord', 'reify', 'proxy',
+ \ 'extend', 'extend-type', 'extend-protocol',
+ \ 'letfn' ], keyword) >= 0
+ return 1
+ endif
- " Special case: we are now at toplevel.
- if nextParen == [0, 0]
- return 0
- endif
- call cursor(nextParen)
-
- call vimclojure#util#MoveForward()
- let keyword = vimclojure#util#Yank('l', 'normal! "lye')
- if index([ 'deftype', 'defrecord', 'reify', 'proxy',
- \ 'extend', 'extend-type', 'extend-protocol',
- \ 'letfn' ], keyword) >= 0
- return 1
- endif
+ return 0
+endfunction
- return 0
- endfunction
+function! s:IsMethodSpecialCase(position)
+ let closure = {
+ \ 'pos': a:position,
+ \ 'f' : function("ClojureIsMethodSpecialCaseWorker")
+ \ }
return vimclojure#util#WithSavedPosition(closure)
endfunction
@@ -200,7 +203,14 @@ function! GetClojureIndent()
return paren[1] + &shiftwidth - 1
endif
- if g:vimclojure#FuzzyIndent && w =~ '\(^\|/\)\(def\|with\)'
+ " XXX: Slight glitch here with special cases. However it's only
+ " a heureustic. Offline we can't do more.
+ if g:vimclojure#FuzzyIndent
+ \ && w != 'with-meta'
+ \ && w != 'clojure.core/with-meta'
+ \ && w =~ '\(^\|/\)\(def\|with\)'
+ \ && w !~ '\(^\|/\)\(def\|with\).*\*$'
+ \ && w !~ '\(^\|/\)\(def\|with\).*-fn$'
return paren[1] + &shiftwidth - 1
endif
View
14 syntax/clojure.vim
@@ -63,7 +63,7 @@ if g:vimclojure#HighlightBuiltins != 0
\ . "eval find-doc file-seq flush hash load load-file "
\ . "read read-line scan slurp subs sync test "
\ . "format printf loaded-libs use require load-reader "
- \ . "load-string + +' -' *' /' < <= == >= > dec dec' "
+ \ . "load-string + - * / +' -' *' /' < <= == >= > dec dec' "
\ . "inc inc' min max "
\ . "neg? pos? quot rem zero? rand rand-int decimal? even? "
\ . "odd? float? integer? number? ratio? rational? "
@@ -233,9 +233,15 @@ syn region clojureSet matchgroup=clojureParen0 start="#{" matchgroup=clojur
syn region clojurePattern start=/L\=\#"/ skip=/\\\\\|\\"/ end=/"/
-syn region clojureCommentSexp start="(" end=")" transparent contained contains=clojureCommentSexp
-syn region clojureComment matchgroup=clojureParen0 start="(comment"rs=s+1 matchgroup=clojureParen0 end=")" contains=clojureCommentSexp
-syn region clojureComment start="#!" end="\n"
+" FIXME: Matching of 'comment' is broken. It seems we can't nest
+" the different highlighting items, when they share the same end
+" pattern.
+" See also: https://bitbucket.org/kotarak/vimclojure/issue/87/comment-is-highlighted-incorrectly
+"
+"syn region clojureCommentSexp start="(" end=")" transparent contained contains=clojureCommentSexp
+"syn region clojureComment matchgroup=clojureParen0 start="(comment"rs=s+1 matchgroup=clojureParen0 end=")" contains=clojureTopCluster
+syn match clojureComment "comment"
+syn region clojureComment start="#!" end="\n"
syn match clojureComment "#_"
syn sync fromstart

0 comments on commit fbeb53c

Please sign in to comment.
Something went wrong with that request. Please try again.