Commits

Meikel Brandmeyer committed ba55587

Highlight Exceptions and fold stracktraces

  • Participants
  • Parent commits 0c884fe

Comments (0)

Files changed (4)

File server/src/main/clojure/vimclojure/util.clj

                    #(.getMethodName %)))
         (remove noise?)))))
 
+(defn print-exception
+  [e]
+  (print "! ")
+  (stacktrace/print-throwable e)
+  (newline)
+  (print-stacktrace (get-stacktrace e)))
+
 ; Pretty printing.
 (defn pretty-print
   "Print the given form in a pretty way. If Tom Faulhaber's pretty printer is
   clojure.stacktrace and clojure.contrib.stacktrace in that order. Otherwise
   defaults to simple printing."
   [e]
-  (stacktrace/print-throwable e)
-  (newline)
-  (print-stacktrace (get-stacktrace e)))
+  (println "!! A crisis has arisen:")
+  (print-exception e))
 
 (defn pretty-print-causetrace
   "Print the causetrace of the given Throwable. Tries clj-stacktrace,
   clojure.stacktrace and clojure.contrib.stacktrace in that order. Otherwise
   defaults to simple printing."
   [e]
-  (pretty-print-stacktrace e)
-  (when-let [c (.getCause e)]
-    (print "Caused by: ")
-    (recur c)))
+  (println "!! A crisis has arisen:")
+  (loop [e e]
+    (print-exception e)
+    (when-let [c (.getCause e)]
+      (println "!! Caused by:")
+      (recur c))))
 
 ; Load optional libraries
 (defmacro defoptional

File vim/autoload/vimclojure.vim

 	return synIDattr(synID(line("."), col("."), 0), "name")
 endfunction
 
+function! vimclojure#GetExceptionFoldLevel(lnum)
+	if a:lnum == 1
+		return 0
+	endif
+
+	let pline = getline(a:lnum - 1)
+	let line  = getline(a:lnum)
+
+	if line[0] == '+' && pline[0] == '!'
+		return ">1"
+	endif
+
+	if line[0] != '+' && line[0] != '|'
+		return 0
+	endif
+
+	return "="
+endfunction
+
 function! vimclojure#WithSaved(closure)
 	let v = a:closure.get(a:closure.tosafe)
 	try
 
 function! vimclojure#ClojureResultBuffer.Init(instance) dict
 	call self.__superResultBufferInit(a:instance)
-	setfiletype clojure
+	let b:vimclojure_clojure_result_buffer = 1
+
+	set filetype=clojure
 
 	return a:instance
 endfunction

File vim/ftplugin/clojure.vim

 
 call vimclojure#MapPlug("n", "p", "CloseResultBuffer")
 
+if exists("b:vimclojure_repl") || exists("b:vimclojure_clojure_result_buffer")
+	setlocal foldexpr=vimclojure#GetExceptionFoldLevel(v:lnum)
+	setlocal foldmethod=expr
+	setlocal foldenable
+endif
+
 let &cpo = s:cpo_save

File vim/syntax/clojure.vim

 	endtry
 endif
 
-syn cluster clojureAtomCluster   contains=clojureError,clojureFunc,clojureMacro,clojureCond,clojureDefine,clojureRepeat,clojureException,clojureConstant,clojureVariable,clojureSpecial,clojureKeyword,clojureString,clojureCharacter,clojureNumber,clojureBoolean,clojureQuote,clojureUnquote,clojureDispatch,clojurePattern
+syn cluster clojureAtomCluster   contains=clojureError,clojureFunc,clojureMacro,clojureCond,clojureDefine,clojureRepeat,clojureConstant,clojureVariable,clojureSpecial,clojureKeyword,clojureString,clojureCharacter,clojureNumber,clojureBoolean,clojureQuote,clojureUnquote,clojureDispatch,clojurePattern
 syn cluster clojureTopCluster    contains=@clojureAtomCluster,clojureComment,clojureSexp,clojureAnonFn,clojureVector,clojureMap,clojureSet
 
 syn keyword clojureTodo contained FIXME XXX TODO FIXME: XXX: TODO:
 syn region  clojureComment                              start="#!" end="\n"
 syn match   clojureComment "#_"
 
+if exists("b:vimclojure_repl") || exists("b:vimclojure_clojure_result_buffer")
+	syn region  clojureException start=/^!!/ end=/\n/
+endif
+
 syn sync fromstart
 
 if version >= 600
 HiLink clojureVariable  Identifier
 HiLink clojureCond      Conditional
 HiLink clojureDefine    Define
-HiLink clojureException Exception
 HiLink clojureFunc      Function
 HiLink clojureMacro     Macro
 HiLink clojureRepeat    Repeat
 HiLink clojureTodo      Todo
 
 HiLink clojureError     Error
+HiLink clojureException Error
 
 HiLink clojureParen0    Delimiter