Permalink
Browse files

Poor man's fswitch for scala files - switch between the src file and …

…the test spec. Updates for working with LaTeX files
  • Loading branch information...
1 parent ad6e648 commit 910d371b53547e794fb1d8dd18c24244a252bc30 @derekwyatt committed Feb 19, 2012
@@ -1,6 +0,0 @@
-setlocal formatoptions=crq
-setlocal textwidth=80
-setlocal foldmethod=marker
-setlocal foldmarker=//{,//}
-setlocal foldlevel=0
-setlocal sw=2
View
@@ -0,0 +1,61 @@
+setlocal formatoptions=crq
+setlocal textwidth=80
+setlocal foldmethod=marker
+setlocal foldmarker=//{,//}
+setlocal foldlevel=0
+setlocal sw=2
+
+if !exists("*s:CodeOrTestFile")
+ function! s:CodeOrTestFile(precmd)
+ let current = expand('%:p')
+ let other = current
+ if current =~ "/main/"
+ let other = substitute(current, "/main/", "/test/", "")
+ let other = substitute(other, ".scala$", "Spec.scala", "")
+ elseif current =~ "/test/"
+ let other = substitute(current, "/test/", "/main/", "")
+ let other = substitute(other, "Spec.scala$", ".scala", "")
+ endif
+ if &switchbuf =~ "^use"
+ let i = 1
+ let bufnum = winbufnr(i)
+ while bufnum != -1
+ let filename = fnamemodify(bufname(bufnum), ':p')
+ if filename == other
+ execute ":sbuffer " . filename
+ return
+ endif
+ let i += 1
+ let bufnum = winbufnr(i)
+ endwhile
+ endif
+ if other != ''
+ if strlen(a:precmd) != 0
+ execute a:precmd
+ endif
+ execute 'edit ' . fnameescape(other)
+ else
+ echoerr "Alternate has evaluated to nothing."
+ endif
+ endfunction
+endif
+
+com! -buffer ScalaSwitchHere :call s:CodeOrTestFile('')
+com! -buffer ScalaSwitchRight :call s:CodeOrTestFile('wincmd l')
+com! -buffer ScalaSwitchSplitRight :call s:CodeOrTestFile('let b:curspr=&spr | set nospr | vsplit | wincmd l | if b:curspr | set spr | endif | unlet b:curspr')
+com! -buffer ScalaSwitchLeft :call s:CodeOrTestFile('wincmd h')
+com! -buffer ScalaSwitchSplitLeft :call s:CodeOrTestFile('let b:curspr=&spr | set nospr | vsplit | wincmd h | if b:curspr | set spr | endif | unlet b:curspr')
+com! -buffer ScalaSwitchAbove :call s:CodeOrTestFile('wincmd k')
+com! -buffer ScalaSwitchSplitAbove :call s:CodeOrTestFile('let b:cursb=&sb | set nosb | split | wincmd k | if b:cursb | set sb | endif | unlet b:cursb')
+com! -buffer ScalaSwitchBelow :call s:CodeOrTestFile('wincmd j')
+com! -buffer ScalaSwitchSplitBelow :call s:CodeOrTestFile('let b:cursb=&sb | set nosb | split | wincmd j | if b:cursb | set sb | endif | unlet b:cursb')
+
+nmap <buffer> <silent> ,of :ScalaSwitchHere<cr>
+nmap <buffer> <silent> ,ol :ScalaSwitchRight<cr>
+nmap <buffer> <silent> ,oL :ScalaSwitchSplitRight<cr>
+nmap <buffer> <silent> ,oh :ScalaSwitchLeft<cr>
+nmap <buffer> <silent> ,oH :ScalaSwitchSplitLeft<cr>
+nmap <buffer> <silent> ,ok :ScalaSwitchAbove<cr>
+nmap <buffer> <silent> ,oK :ScalaSwitchSplitAbove<cr>
+nmap <buffer> <silent> ,oj :ScalaSwitchBelow<cr>
+nmap <buffer> <silent> ,oJ :ScalaSwitchSplitBelow<cr>
View
@@ -6,5 +6,5 @@ setlocal fdl=0
setlocal fdm=marker
setlocal fmr=<<<,>>>
-imap jj <esc>:w<cr>
-imap jw <c-o>:w<cr>
+imap <buffer> jj <esc>:w<cr>
+imap <buffer> jw <c-o>:w<cr>
View
@@ -39,3 +39,5 @@ Changelog
livelocks
apps
sbt
+stateful
+UAP
View
Binary file not shown.
@@ -6,24 +6,34 @@ XPTinclude
XPT tt wrap=text hint=\\texttt{...}
\texttt{`text^}`cursor^
-XPT s wrap=title hint=\\section{...}
+XPT chapter wrap=title hint=\\chapter{...}
% `title^ <<<1
+\chapter{`title^}
+\label{sec:`label^}
+`cursor^
+
+XPT s wrap=title hint=\\section{...}
+% - `title^ <<<1
\section{`title^}
\label{sec:`label^}
`cursor^
XPT ss wrap=title hint=\\subsection{...}
-% - `title^ <<<1
+% -- `title^ <<<1
\subsection{`title^}
\label{sec:`label^}
`cursor^
XPT sss wrap=title hint=\\subsubsection{...}
-% -- `title^ <<<1
+% --- `title^ <<<1
\subsubsection{`title^}
\label{sec:`label^}
`cursor^
+XPT heading wrap=title hint=\\subsubsection*{...}
+\subsubsection{`title^}
+`cursor^
+
XPT begin hint=\\begin{}...\\end{}
\begin{`layout^}
`cursor^

0 comments on commit 910d371

Please sign in to comment.