Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
- Stopped using `airline`. Wow... it made _everything_ slow, and I don't
  know why, and I don't really care - it was just pretty. Leaving insert
  mode had lag, switching windows had lag, ugh... no longer smooth like
  glass.
  - So I put back my old status line
- Added switching to integration tests for `scala`
- Added the ability to wipeout all buffers -- well, I had this before
  but it wasn't working, so I had to make it smarter
- The code that asks things about git is now smarter, as it uses a cache
  file instead of asking the `git` executable
- stopped using my version of `ag` and am now back to using `rking`s
  • Loading branch information
Derek Wyatt committed May 5, 2015
1 parent 56fede2 commit 9e82d52
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 44 deletions.
2 changes: 1 addition & 1 deletion bundle/Vundle.vim
Submodule Vundle.vim updated from 0b28e3 to 7d9b10
6 changes: 5 additions & 1 deletion ftplugin/scala.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ if !exists("*s:CodeOrTestFile")
let specExt = "Test.scala"
endif
if current =~ "/src/main/"
let other = substitute(current, "/main/", "/test/", "")
let other = substitute(current, "/main/", "/it/", "")
let other = substitute(other, ".scala$", specExt, "")
if !filereadable(other)
let other = substitute(current, "/main/", "/test/", "")
let other = substitute(other, ".scala$", specExt, "")
endif
elseif current =~ "/src/test/"
let other = substitute(current, "/test/", "/main/", "")
let other = substitute(other, specExt . "$", ".scala", "")
Expand Down
92 changes: 64 additions & 28 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ set nocompatible
filetype off
set runtimepath+=~/.vim/bundle/Vundle.vim,~/.vim/bundle/vim-jira,~/.vim/bundle/vim-mpc
call vundle#begin()
Plugin 'bling/vim-airline'
Plugin 'derekwyatt/ag.vim'
" OMG This makes editing soooooo sllloooooowwwwww
" Plugin 'bling/vim-airline'
Plugin 'rking/ag.vim'
Plugin 'bufkill.vim'
Plugin 'MarcWeber/vim-addon-completion'
Plugin 'kien/ctrlp.vim'
Expand Down Expand Up @@ -115,6 +116,21 @@ set hidden
" the text and replacing it
set cpoptions=ces$

function! DerekFugitiveStatusLine()
let status = fugitive#statusline()
let trimmed = substitute(status, '\[Git(\(.*\))\]', '\1', '')
let trimmed = substitute(trimmed, '\(\w\)\w\+\ze/', '\1', '')
let trimmed = substitute(trimmed, '/[^_]*\zs_.*', '', '')
if len(trimmed) == 0
return ""
else
return '(' . trimmed[0:10] . ')'
endif
endfunction

" Set the status line the way i like it
set stl=%f\ %m\ %r%{DerekFugitiveStatusLine()}\ Line:%l/%L[%p%%]\ Col:%v\ Buf:#%n\ [%b][0x%B]

" tell VIM to always put a status line in, even if there is only one window
set laststatus=2

Expand Down Expand Up @@ -232,7 +248,7 @@ let g:scala_use_default_keymappings = 0
let mapleader = ","

" Wipe out all buffers
nmap <silent> ,wa :1,9000bwipeout<cr>
nmap <silent> ,wa :call BWipeoutAll()<cr>
" Toggle paste mode
nmap <silent> ,p :set invpaste<CR>:set paste?<CR>
Expand Down Expand Up @@ -453,9 +469,14 @@ endif
"-----------------------------------------------------------------------------
" AG (SilverSearcher) Settings
"-----------------------------------------------------------------------------
nmap ,sf :AgForCurrentFileDir
nmap ,sr :AgForProjectRoot
nmap ,se :AgForExtension
function! AgProjectRoot(pattern)
let dir = FindGitDirOrRoot()
execute ':Ag ' . a:pattern . ' ' . dir
endfunction

command! -nargs=+ AgProjectRoot call AgProjectRoot(<q-args>)

nmap ,sr :AgProjectRoot
let g:agprg = '/usr/local/bin/ag'
let g:ag_results_mapping_replacements = {
\ 'open_and_close': '<cr>',
Expand Down Expand Up @@ -585,38 +606,42 @@ function! HasGitRepo()
endif
endfunction

function! GetThatBranch()
let root = FindGitDirOrRoot() " In ~/.vimrc
if root != '/'
if !has_key(g:last_known_branch, root)
let g:last_known_branch[root] = ''
function! GetThatBranch(root)
if a:root != '/'
if !has_key(g:last_known_branch, a:root)
let g:last_known_branch[a:root] = ''
endif
return g:last_known_branch[root]
return g:last_known_branch[a:root]
else
return ''
endif
endfunction

function! UpdateThatBranch()
let root = FindGitDirOrRoot() " In ~/.vimrc
if root != '/'
let g:last_known_branch[root] = GetThisBranch()
function! UpdateThatBranch(root)
if a:root != '/'
let g:last_known_branch[a:root] = GetThisBranch(a:root)
endif
endfunction

function! GetThisBranch()
return substitute(fugitive#head(), '/', '-', 'g')
function! GetThisBranch(root)
let file = a:root . '/.current_branch'
if filereadable(file)
return substitute(readfile(file)[0], '/', '-', 'g')
else
return substitute(fugitive#head(), '/', '-', 'g')
endif
endfunction

function! MaybeRunBranchSwitch()
if HasGitRepo()
let thisbranch = GetThisBranch()
let thatbranch = GetThatBranch()
let gitdir = substitute(FindGitDirOrRoot(), '/', '-', 'g')[1:]
let root = FindGitDirOrRoot()
if root != "/"
let thisbranch = GetThisBranch(root)
let thatbranch = GetThatBranch(root)
let gitdir = substitute(root, '/', '-', 'g')[1:]
let b:easytags_file = $HOME . '/.vim-tags/' . gitdir . '-' . thisbranch . '-tags'
execute 'setlocal tags=' . b:easytags_file
if thisbranch != thatbranch
call UpdateThatBranch()
call UpdateThatBranch(root)
CtrlPClearCache
endif
endif
Expand All @@ -632,6 +657,13 @@ command! RunBranchSwitch call RunBranchSwitch(expand('%:p:h'))
"-----------------------------------------------------------------------------
" Functions
"-----------------------------------------------------------------------------
function! BWipeoutAll()
let lastbuf = bufnr('$')
let ids = sort(filter(range(1, bufnr('$')), 'bufexists(v:val)'))
execute ":" . ids[0] . "," . lastbuf . "bwipeout"
unlet lastbuf
endfunction

if !exists('g:bufferJumpList')
let g:bufferJumpList = {}
endif
Expand Down Expand Up @@ -663,12 +695,16 @@ endfunction

function! FindGitDirOrRoot()
let filedir = expand('%:p:h')
let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
let gitdir = system(cmd)
if strlen(gitdir) == 0
return '/'
if isdirectory(filedir)
let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
let gitdir = system(cmd)
if strlen(gitdir) == 0
return '/'
else
return gitdir[:-2] " chomp
endif
else
return gitdir[:-2] " chomp
return '/'
endif
endfunction

Expand Down
49 changes: 35 additions & 14 deletions xpt-personal/ftplugin/scala/scala.xpt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function! s:f.multijvmBase(...)
endfunction

function! s:f.classNameFromSpec(...)
return substitute(s:f.classname(), 'Spec$', '', '')
return substitute(s:f.classname(), '\%(Spec\|Test\)$', '', '')
endfunction

function! s:f.classNameFromTest(...)
Expand Down Expand Up @@ -211,7 +211,17 @@ class `classname()^ extends WordSpec with Matchers {
`cursor^
}
}
// vim:fdl=1:

XPT fileflatspec hint=Creates\ a\ new\ FlatSpec\ test\ file
`getPackageLine()^

import org.scalatest.{ FlatSpec, Matchers }

class `classname()^ extends FlatSpec with Matchers {
"`classNameFromSpec()^" should "`do someting^" in {
`cursor^
}
}

XPT eorp hint=envOrNone.orElse.propOrNone
envOrNone("`Variable^").orElse(propOrNone("`property^"))
Expand Down Expand Up @@ -279,18 +289,6 @@ class `classname()^ extends TestKit(ActorSystem("`classname()^"))
}
}

XPT auviktest hint=Test\ file\ for\ Auvik\ code
`getPackageLine()^

import com.auvik.npl.common.AkkaTest

class `classname()^ extends AkkaTest {

"`classNameFromTest()^" should "`do something^" in {
`cursor^
}
}

XPT multijvm hint=Multi\ JVM\ Test\ for\ Scala
`getPackageLine()^

Expand Down Expand Up @@ -350,3 +348,26 @@ libraryDependencies := Seq(
"`groupId^" % "`artifactId^" % "`revision^",
"org.scalatest" %% "scalatest" % "2.0" % "test"
)

XPT extension hint=Creates\ a\ new\ Akka\ Extension
import akka.actor.{ Extension => AkkaExtension, ExtensionId => AkkaExtensionId, ExtensionIdProvider => AkkaExtensionIdProvider }

class `extensionName^(system: ExtendedActorSystem) extends AkkaExtension {
`cursor^
}

object `extensionName^ extends AkkaExtensionId[`extensionName^] with AkkaExtensionIdProvider {
def lookup() = this
def createExtension(system: ExtendedActorSystem): `extensionName^ = new `extensionName^(system)
}

XPT auviktest hint=Creates\ a\ new\ Auivk\ style\ Akka\ test\ file
`getPackageLine()^

import com.auvik.npl.common.AkkaTest

class `classname()^ extends AkkaTest {
"`classNameFromSpec()^" should "`description^" in {
`cursor^
}
}

0 comments on commit 9e82d52

Please sign in to comment.