Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for formatSource

The following lines should be added to .ensime file:

;; :formatting-prefs (symbol_map)
;; https://github.com/mdr/scalariform
:formatting-prefs (:alignParameters t
                  :alignSingleLineCaseStatements nil
                  :alignSingleLineCaseStatements_maxArrowIndent 20
                  :compactControlReadability t
                  :compactStringConcatenation t
                  :doubleIndentClassDeclaration t
                  :indentLocalDefs nil
                  :indentPackageBlocks nil
                  :indentSpaces 2
                  :indentWithTabs nil
                  :multilineScaladocCommentsStartOnFirstLine nil
                  :preserveDanglingCloseParenthesis t
                  :placeScaladocAsterisksBeneathSecondAsterisk nil
                  :preserveSpaceBeforeArguments nil
                  :rewriteArrowSymbols nil
                  :spaceBeforeColon nil
                  :spaceInsideBrackets nil
                  :spaceInsideParentheses nil
                  :spacesWithinPatternBinders t)

Thanks to Richard Emberson for the initial patch!!
  • Loading branch information...
commit e490139d362a747ecc836ad7064922eec8af1721 1 parent f9ea9d2
Jeanluc Chasseriau authored
View
35 README.md
@@ -285,6 +285,39 @@ Default shortcut:
<C-x><C-o>
+### Source formatting
+
+Command:
+
+ :EnvimFormatSource
+
+Default shortcut:
+
+ <leader>es
+
+Configuration example (to add in .ensime file):
+
+ ;; :formatting-prefs (symbol_map)
+ ;; https://github.com/mdr/scalariform
+ :formatting-prefs (:alignParameters t
+ :alignSingleLineCaseStatements nil
+ :alignSingleLineCaseStatements_maxArrowIndent 20
+ :compactControlReadability t
+ :compactStringConcatenation t
+ :doubleIndentClassDeclaration t
+ :indentLocalDefs nil
+ :indentPackageBlocks nil
+ :indentSpaces 2
+ :indentWithTabs nil
+ :multilineScaladocCommentsStartOnFirstLine nil
+ :preserveDanglingCloseParenthesis t
+ :placeScaladocAsterisksBeneathSecondAsterisk nil
+ :preserveSpaceBeforeArguments nil
+ :rewriteArrowSymbols nil
+ :spaceBeforeColon nil
+ :spaceInsideBrackets nil
+ :spaceInsideParentheses nil
+ :spacesWithinPatternBinders t)
## Acknoledgements and thanks
@@ -296,4 +329,4 @@ Default shortcut:
- Hubert Behaghel, a dear friend and strong supporter of this initiative.
-
+- Richard Emberson for his many contributions.
View
4 autoload/envim.vim
@@ -179,6 +179,10 @@ fun! envim#UsesOfSymbolAtPoint()
py Envim().usesOfSymbolAtPoint()
endfun
+fun! envim#FormatSource()
+ py Envim().formatSource()
+endfun
+
fun! envim#logEvent(event)
py elog().debug("envim#logEvent: %s", vim.eval("a:event"))
endfun
View
1  ftplugin/scala.vim
@@ -16,3 +16,4 @@
setlocal omnifunc=envim#Completions
setlocal completeopt=menuone,preview
+setlocal autoread
View
2  plugin/envim.vim
@@ -23,11 +23,13 @@ command! -nargs=0 EnvimTypecheckFile call envim#TypecheckFile()
command! -nargs=0 EnvimTypecheckAll call envim#TypecheckAll()
command! -nargs=0 EnvimSymbolAtPoint call envim#SymbolAtPoint()
command! -nargs=0 EnvimUsesOfSymbolAtPoint call envim#UsesOfSymbolAtPoint()
+command! -nargs=0 EnvimFormatSource call envim#FormatSource()
noremap <leader>ef :EnvimTypecheckFile<cr>
noremap <leader>ea :EnvimTypecheckAll<cr>
noremap <leader>ei :EnvimSymbolAtPoint<cr>
noremap <leader>eo :EnvimUsesOfSymbolAtPoint<cr>
+noremap <leader>es :EnvimFormatSource<cr>
augroup ENVIM
au!
View
13 python/Envim.py
@@ -105,6 +105,19 @@ def usesOfSymbolAtPoint(self):
SwankRpc().usesOfSymbolAtPoint(filename, offset)(UsesOfSymbolAtPointHandler())
@CatchAndLogException
+ def formatSource(self):
+ if not checkCompilerReady(): return
+
+ # @todo: ensure that file is in source-roots
+ filename = getCurrentFilename()
+ if filename == None:
+ echoe("Unknown current filename")
+ else:
+ vim.command("update")
+ SwankRpc().formatSource([filename])(FormatSourceHandler())
+ echo("Please wait while formating...")
+
+ @CatchAndLogException
def onCursorMoved(self):
PreviewOutput().close()
View
20 python/Responses.py
@@ -185,3 +185,23 @@ def response(self, completions):
OmniOutput().showCompletions()
+@SimpleSingleton
+class FormatSourceHandler(SwankCallHandler):
+
+ def abort(self, code, details):
+ echoe("FormatSource abort: "+codeDetailsString(code, details))
+
+ def response(self, r):
+ if not r:
+ echoe("FormatSource file error")
+ return
+
+ cmds = [
+ "call feedkeys('<cr>')",
+ # @todo: we use feedkeys() in order to avoid loosing the syntax colors, simply 'e' should be enough (cf. #9)
+ "call feedkeys(':e')"
+ ]
+ vimCommands(cmds)
+
+ echo("FormatSource done")
+
Please sign in to comment.
Something went wrong with that request. Please try again.