Skip to content

Commit

Permalink
Configure asterisk alignment in multiline comments to match scaladoc …
Browse files Browse the repository at this point in the history
…recommendation (#129)
  • Loading branch information
mjp4 authored and derekwyatt committed Aug 2, 2016
1 parent 16beb53 commit a6a350f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ There are different modes for import sorting available. For details, please
consult the vimdoc help with

:help :SortScalaImports

##Scaladoc comment indentation

By default, the plugin indents documentation comments according to the standard
Javadoc format

/**
* This is a doc comment using Javadoc-style indentation.
*/

To enable the indentation standard as recommended for Scaladoc comments (from
http://docs.scala-lang.org/style/scaladoc.html, since Scaladoc2), add the
command ``let g:scala_scaladoc_indent = 1`` to .vimrc file, e.g:

/** This is a Scaladoc comment using the recommended indentation.
* let g:scala_scaladoc_indent = 1
*/
16 changes: 16 additions & 0 deletions doc/scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ See |scala-mappings|.
>
let g:scala_use_default_keymappings = 1
<

*'g:scala_scaladoc_indent'*
By default, the plugin indents documentation comments according to the
standard Javadoc format.
/**
* This is a doc comment using Javadoc-style indentation.
*/
Set this option to enable the indentation standard as recommended for Scaladoc
comments.
/** This is a Scaladoc comment using
* the recommended indentation.
*/
>
let g:scala_scaladoc_indent = 1
<

==============================================================================
COMMANDS *scala-commands*

Expand Down
6 changes: 5 additions & 1 deletion ftplugin/scala.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ silent! setlocal formatoptions+=j

" Just like c.vim, but additionally doesn't wrap text onto /** line when
" formatting. Doesn't bungle bulleted lists when formatting.
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/**,mb:*,ex:*/,s1:/*,mb:*,ex:*/,://
if get(g:, 'scala_scaladoc_indent', 0)
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s2:/**,mb:*,ex:*/,s1:/*,mb:*,ex:*/,://
else
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/**,mb:*,ex:*/,s1:/*,mb:*,ex:*/,://
endif
setlocal commentstring=//\ %s

setlocal shiftwidth=2 softtabstop=2 expandtab
Expand Down
9 changes: 7 additions & 2 deletions indent/scala.vim
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,17 @@ function! GetScalaIndent()
let prevline = scala#GetLine(prevlnum)
let curlnum = v:lnum
let curline = scala#GetLine(curlnum)
if get(g:, 'scala_scaladoc_indent', 0)
let star_indent = 2
else
let star_indent = 1
end

if prevline =~ '^\s*/\*\*'
if prevline =~ '\*/\s*$'
return ind
else
return ind + 1
return ind + star_indent
endif
endif

Expand Down Expand Up @@ -536,7 +541,7 @@ function! GetScalaIndent()
if prevline =~ '^\s*\*/'
\ || prevline =~ '*/\s*$'
call scala#ConditionalConfirm("18")
let ind = ind - 1
let ind = ind - star_indent
endif

if scala#LineEndsInIncomplete(prevline)
Expand Down

0 comments on commit a6a350f

Please sign in to comment.