Skip to content

Commit

Permalink
Merge branch 'tagbar-batteries-included'
Browse files Browse the repository at this point in the history
* tagbar-batteries-included:
  Nix overbearing ctags executable check
  Include Scala ctags definition for Tagbar
  Add standard plugin guards, modelines
  Remove help plugin stuff
  • Loading branch information
ches committed Feb 6, 2015
2 parents aa662c5 + 77637d4 commit 0f49942
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 100 deletions.
50 changes: 0 additions & 50 deletions after/plugin/help.vim

This file was deleted.

10 changes: 8 additions & 2 deletions after/syntax/help.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
let b:current_syntax = ''
unlet b:current_syntax
" Extends standard help syntax with highlighting of Scala code.
"
" Place code between !sc! and !/sc! delimiters. These will be hidden if Vim is
" built with conceal support.

unlet! b:current_syntax

syntax include @ScalaCode syntax/scala.vim

if has('conceal')
syntax region rgnScala matchgroup=Ignore concealends start='!sc!' end='!/sc!' contains=@ScalaCode
else
Expand Down
8 changes: 7 additions & 1 deletion compiler/sbt.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
" Vim compiler file for sbt, the Scala build tool.
" Vim compiler file
" Language: Scala SBT (http://www.scala-sbt.org/)
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Apache 2
" ----------------------------------------------------------------------------

if exists('current_compiler')
finish
Expand All @@ -22,3 +27,4 @@ CompilerSet errorformat=
let &cpo = s:cpo_save
unlet s:cpo_save

" vim:set sw=2 sts=2 ts=8 et:
13 changes: 13 additions & 0 deletions ctags/scala.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--langdef=scala
--langmap=scala:.scala

--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*class[ \t ]+([a-zA-Z0-9_]+)/\4/c,classes/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*object[ \t ]+([a-zA-Z0-9_]+)/\4/c,objects/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*case class[ \t ]+([a-zA-Z0-9_]+)/\6/c,case classes/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*case object[ \t ]+([a-zA-Z0-9_]+)/\4/c,case objects/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy)[ \t ]*)*(private[^ ]*|protected)?[ \t ]*trait[ \t ]+([a-zA-Z0-9_]+)/\4/t,traits/
--regex-scala=/^[ \t ]*type[ \t ]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*(\[[a-z]*\])*|protected)[ \t ]*)*def[ \t ]+([a-zA-Z0-9_]+)/\4/m,methods/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*val[ \t ]+([a-zA-Z0-9_]+)/\3/l,constants/
--regex-scala=/^[ \t ]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t ]*)*var[ \t ]+([a-zA-Z0-9_]+)/\3/l,variables/
--regex-scala=/^[ \t ]*package[ \t ]+([a-zA-Z0-9_.]+)/\1/p,packages/
75 changes: 74 additions & 1 deletion doc/scala.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
*scala.txt* Syntax highlighting and helper functions for the Scala language.

This plugin is only available if 'compatible' is not set.
{Vi does not have any of this}

==============================================================================
INTRODUCTION *scala*

Syntax highlighting and helper functions for the scala language.
Syntax highlighting and helper functions for the scala language. Extras
include:

- Sorting of import statements, configurable to your conventions.
- Tagbar support to navigate definitions within a file in the plugin's
sidebar window.
- ...and probably more that we've forgotten to update in this doc.

==============================================================================
OPTIONS *scala-options*

Use these options to control behavior of the plugin. Default values are
indicated in the examples.

*'g:scala_use_builtin_tagbar_defs'*
If you are using the Tagbar Vim plugin, vim-scala includes a Tagbar type
definition and ctags definition for Scala, so you can use Tagbar immediately.
If you have your own ctags definition in `~/.ctags` and prefer to use it, set
this option to 0 (we would appreciate contributions if you've improved the
ctags definition!).

Note that Tagbar's ctags definition for Scala is not used to generate a
|tags| file that Vim can use to navigate to definitions in other files, only
for the plugin sidebar. Feel free to copy `vim-scala/ctags/scala.ctags` into
your own `~/.ctags` if you wish to generate |tags| files.
>
let g:scala_use_builtin_tagbar_defs = 1
<
*'g:scala_use_default_keymappings'*
Set this option to disable definition of all mappings provided by vim-scala.
See |scala-mappings|.
>
let g:scala_use_default_keymappings = 1
<
==============================================================================
COMMANDS *scala-commands*

*:SortScalaImports*
Expand Down Expand Up @@ -41,4 +78,40 @@ COMMANDS *scala-commands*
g:scala_first_party_namespaces=
\ '\(controllers\|views\|models\)'

==============================================================================
MAPPINGS *scala-mappings*

Currently the only mappings defined are for FuzzyFinder users--these will
only be enabled if FuzzyFinder is detected.

*scala-leader-fs*
<Leader>fs "Find src". Primes |:FufFile| with `src/main/scala`,
and goes deeper still if only a single directory
exists below that. Helpful for package namespacing
like `src/main/scala/com/myorg`.

*scala-leader-ft*
<Leader>ft "Find test". Like |scala-leader-fs|, but with
`src/test/scala`.

*scala-leader-fr*
<Leader>fr "Find from root". For the rarer cases when you want to
start FuzzyFinder at project root (parent of `src/`).

Disabling Mappings~

If you wish to disable the default key mappings, write the following line in
your ~/.vimrc: >
let g:scala_use_default_keymappings = 0
==============================================================================
CREDITS *scala-credits*

Developed by Derek Wyatt, building on initial work by Stefan Matthias Aust.
Distributed under the Apache 2 license.

Project's home and Git repository: https://github.com/derekwyatt/vim-scala

------------------------------------------------------------------------------
vim:tw=78:ts=8:ft=help:norl:
58 changes: 14 additions & 44 deletions ftplugin/scala.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
" Vim filetype plugin
" Language: Scala
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Apache 2
" ----------------------------------------------------------------------------

if exists('b:did_ftplugin') || &cp
finish
endif
let b:did_ftplugin = 1

setlocal formatoptions+=ro

" Just like c.vim, but additionally doesn't wrap text onto /** line when
Expand Down Expand Up @@ -130,49 +142,6 @@ if globpath(&rtp, 'plugin/fuf.vim') != ''
endif
endif

" If you want to disable the default key mappings, write the following line in
" your ~/.vimrc
" let g:scala_use_default_keymappings = 0
if get(g:, 'scala_use_default_keymappings', 1)
nnoremap <buffer> <Leader>jt :call JustifyCurrentLine()<cr>
endif

"
" TagBar
"
let g:tagbar_type_scala = {
\ 'ctagstype' : 'scala',
\ 'kinds' : [
\ 'p:packages:1',
\ 'V:values',
\ 'v:variables',
\ 'T:types',
\ 't:traits',
\ 'o:objects',
\ 'a:aclasses',
\ 'c:classes',
\ 'r:cclasses',
\ 'm:methods'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'T' : 'type',
\ 't' : 'trait',
\ 'o' : 'object',
\ 'a' : 'abstract class',
\ 'c' : 'class',
\ 'r' : 'case class'
\ },
\ 'scope2kind' : {
\ 'type' : 'T',
\ 'trait' : 't',
\ 'object' : 'o',
\ 'abstract class' : 'a',
\ 'class' : 'c',
\ 'case class' : 'r'
\ }
\ }

function! s:CreateOrExpression(keywords)
return '('.join(a:keywords, '|').')'
endfunction
Expand All @@ -194,5 +163,6 @@ function! s:NextSection(backwards)
endfunction

noremap <script> <buffer> <silent> ]] :call <SID>NextSection(0)<cr>
noremap <script> <buffer> <silent> [[ :call <SID>NextSection(1)<cr>
" vim:set sw=2 sts=2 ts=8 et:
47 changes: 47 additions & 0 deletions ftplugin/scala/tagbar.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"
" Support for Tagbar -- https://github.com/majutsushi/tagbar
"
" Hat tip to Leonard Ehrenfried for the built-in ctags deffile:
" https://leonard.io/blog/2013/04/editing-scala-with-vim/
"
if !exists(':Tagbar')
finish
endif

let g:tagbar_type_scala = {
\ 'ctagstype' : 'scala',
\ 'kinds' : [
\ 'p:packages:1',
\ 'V:values',
\ 'v:variables',
\ 'T:types',
\ 't:traits',
\ 'o:objects',
\ 'a:aclasses',
\ 'c:classes',
\ 'r:cclasses',
\ 'm:methods'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'T' : 'type',
\ 't' : 'trait',
\ 'o' : 'object',
\ 'a' : 'abstract class',
\ 'c' : 'class',
\ 'r' : 'case class'
\ },
\ 'scope2kind' : {
\ 'type' : 'T',
\ 'trait' : 't',
\ 'object' : 'o',
\ 'abstract class' : 'a',
\ 'class' : 'c',
\ 'case class' : 'r'
\ }
\ }

" In case you've updated/customized your ~/.ctags and prefer to use it.
if get(g:, 'scala_use_builtin_tagbar_defs', 1)
let g:tagbar_type_scala.deffile = expand('<sfile>:p:h:h:h') . '/ctags/scala.ctags'
endif
3 changes: 2 additions & 1 deletion indent/scala.vim
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,6 @@ function! GetScalaIndent()

return ind
endfunction
" vim:set ts=2 sts=2 sw=2:

" vim:set sw=2 sts=2 ts=8 et:
" vim600:fdm=marker fdl=1 fdc=0:
15 changes: 14 additions & 1 deletion plugin/scala.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
" Vim plugin file
" Language: Scala
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Apache 2
" ----------------------------------------------------------------------------

if exists('g:loaded_scala') || &cp
finish
endif
let g:loaded_scala = 1

"
" Sort imports
"
" author: Leonard Ehrenfried <leonard.ehrenfried@gmail.com>
"

function! SortScalaImports()
let save_cursor = getpos(".")

Expand Down Expand Up @@ -130,3 +141,5 @@ function! s:sortIgnoreCase(i1, i2)
endfunction

command! SortScalaImports call SortScalaImports()

" vim:set sw=2 sts=2 ts=8 et:
9 changes: 9 additions & 0 deletions syntax/scala.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
" Vim syntax file
" Language: Scala
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Apache 2
" ----------------------------------------------------------------------------

if !exists('main_syntax')
if version < 600
syntax clear
Expand Down Expand Up @@ -201,3 +208,5 @@ let b:current_syntax = 'scala'
if main_syntax ==# 'scala'
unlet main_syntax
endif

" vim:set sw=2 sts=2 ts=8 et:

0 comments on commit 0f49942

Please sign in to comment.