ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Scala​Format

by timonwong ALL

Yet another Scala code formatter for Sublime Text.

Labels scala, formatting

Details

Installs

  • Total 9K
  • Win 3K
  • Mac 4K
  • Linux 2K
Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5 Mar 4 Mar 3 Mar 2 Mar 1 Feb 29 Feb 28 Feb 27 Feb 26 Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9 Feb 8 Feb 7 Feb 6 Feb 5 Feb 4
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

ScalaFormat

Summary

ScalaFormat is a scala code formatter plugin for Sublime Text. It is rewritten from Takafumi Ikeda's Sublime Scalariform plugin, with following enhancements:

  • Formatting buffer instead of formatting source file directly.
  • Auto format on file save support (disabled by default).
  • Sublime Text 3 support.

Prerequisites

  • Java™ 5 or later.
  • Patience :) - It may take a few seconds before scalariform finished.

Installation

With the Package Control plugin

The easiest way to install ScalaFormat is through Package Control.

Once you have Package Control installed, restart Sublime Text.

  1. Bring up the Command Palette (Ctrl+Shift+P under Windows and Linux; ++P under OS X).
  2. Type “Install” and select “Package Control: Install Package”.
  3. Select “ScalaFormat” from list.

The advantage of using Package Control is that it will keep ScalaFormat up to date automatically.

Manual Install

Without Git: Download the latest source code, and extract to the Packages directory.

With Git: Type the following command in your Sublime Text 2 Packages directory:

git clone git://github.com/timonwong/ScalaFormat.git

The “Packages” directory is located at:

  • Windows: %APPDATA%\Sublime Text 2\Packages\
  • Linux: ~/.config/sublime-text-2/Packages/
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/

Usage

Key Bindings

The default key bindings for this plugin:

  • Ctrl+Alt+F: Format current file.

Command Palette

Open the command palette, it apperas as ScalaFormat: Format Current File.

Settings

{
    // If the executable is not in the system path, you may have to set the java executable manually
    "java_executable": "java",
    // Absolute path to your scalariform binary, leave null to use the one shipped with this plugin
    "scalariform_jar": null,
    // Auto format on file save
    "autoformat_on_save": false,
    // scalariform command line options - preferences
    // https://github.com/mdr/scalariform/wiki/Command-line-tool
    "scalariform": {
        // Enable/disable Align parameters on different lines in the same column
        "alignParameters": false,
        // Enable/disable Align the arrows of consecutive single-line case statements
        "alignSingleLineCaseStatements": false,
        // Set Maximum number of spaces inserted before an arrow to align case statements: [1-100]
        "alignSingleLineCaseStatements.maxArrowIndent": 40,
        // Enable/disable Compact Control Readability style
        "compactControlReadability": false,
        // Enable/disable Omit spaces when formatting a '+' operator on String literals
        "compactStringConcatenation": false,
        // Enable/disable Double indent either a class's parameters or its inheritance list
        "doubleIndentClassDeclaration": false,
        // Enable/disable Format XML literals
        "formatXml": true,
        // Enable/disable Indent local defs an extra level
        "indentLocalDefs": false,
        // Enable/disable Indent package blocks
        "indentPackageBlocks": true,
        // Set Number of spaces to use for indentation: [1-10]
        "indentSpaces": 2,
        // Enable/disable Use a tab character for indentation
        "indentWithTabs": false,
        // Enable/disable Start multiline Scaladoc comment body on same line as the opening '/**'
        "multilineScaladocCommentsStartOnFirstLine": false,
        // Enable/disable Allow a newline before a ')' in an argument expression
        "preserveDanglingCloseParenthesis": false,
        // Enable/disable Place Scaladoc asterisks beneath the second asterisk in the opening '/**', as opposed to the first
        "placeScaladocAsterisksBeneathSecondAsterisk": false,
        // Enable/disable Preserve a space before a parenthesis argument
        "preserveSpaceBeforeArguments": false,
        // Enable/disable Replace arrow tokens with unicode, equivalents: => with ⇒, and <- with ←
        "rewriteArrowSymbols": false,
        // Enable/disable Add a space before colons
        "spaceBeforeColon": false,
        // Enable/disable Require a space after '[' and before ']'
        "spaceInsideBrackets": false,
        // Enable/disable Require a space after '(' and before ')'
        "spaceInsideParentheses": false,
        // Enable/disable Add a space around the @ token in pattern binders
        "spacesWithinPatternBinders": true
    }
}

Per-project setting

Before starting, you may want to have a look at ScalaFormat.sublime-settings.

To edit your project setting, select Project/Edit Project from main menu. A project setting contains per-project settings for ScalaFormat should look like this:

{
    // project folders, etc
    // ...
    // project settings
    "settings":
    {
        "ScalaFormat":
        {
            "autoformat_on_save": true,
            "scalariform": {
                "alignParameters": true,
                "rewriteArrowSymbols": true
            }
        }
    }
}

What's New

v1.2.0 (July 19, 2013)

  • Fix custom settings that did't work at all.
  • Less error-prone default options overriding (You don't need to duplicate whole 'scalariform' section before customizing now, default options in 'scalariform' section will be retrieved automatically).
  • Add per-project setting support.

v1.1.1 (July 15, 2013)

  • Fix compatibility with Sublime Text 3 and Packge Control.

v1.1 (June 3, 2013)

  • Add support for Sublime Text 3.
  • Updated scalariform excutable.

v1.0

  • First release.

License

This plugin released under MIT License:

Copyright (c) 2012-2013 Timon Wong
Portions Copyright (c) 2012 Takafumi Ikeda

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.