Coder Social home page Coder Social logo

stopfmt's Introduction

stopfmt

Whenever I've programmed in Go I've gotten annoyed by the fact that gofmt makes my if err != nil { return } stanzas take up three whole lines. stopfmt undoes gofmt's evil and automatically folds away the newlines in short if statements so you can read your code how you like without your coworkers or gofmt noticing.

I also threw in a command I've had in my personal SublimeTect repo for a while which lets you toggle folding away the bodies of functions so you can get all the benefits of header/interface files in languages without them, without having to write them!

screenshot

How to use

First git clone this repository into your Sublime Packages folder. You can get to this using the Preferences > Browse Packages menu item.

Folding short if statements in Go files on load is enabled by default but if you write your own if statements and want them folded, or want to toggle folding, you need to bind keyboard shortcuts of your choice to the folding commands. You can do this by using the "Preferences > Key Bindings" menu item to open your key bindings file and adding lines like these but with your choice of shortcut:

{ "keys": ["ctrl+,"], "command": "fold_short_ifs" }, // toggle folding short if statements, meant for Go
{ "keys": ["ctrl+b"], "command": "fold_function_bodies" }, // toggle folding function bodies

Pressing either of these keybinds while something remains to be folded will fold that thing, pressing them when everything is folded will unfold all its folds.

How to configure

You can create a stopfmt.sublime-settings file in your User package which overrides the following settings:

{
  // Maximum line length for a folded if statement to be and still fold
  "max_line_length": 100,
  // Automatically run fold_short_ifs when a Go file loads
  "auto_fold_go": true,
}

The fold icon is too bright

The color of the folded code icon is controlled by your theme, and you might find it too blatant for this use case. You can fix it by making your own tweaks to your favorite color scheme and modifying the fold_marker global.

  1. Use the UI: Select Color Scheme command to see what your current color scheme is
  2. Use View Package File and then search for your scheme to open it
  3. Make a file in your User package with a modified name like FancyScheme-tristan.sublime-color-scheme and copy the contents
  4. If your theme is a .tmTheme file, run the Convert Color Scheme command (either variable style is fine) to make a .sublime-color-scheme version
  5. Set the fold_marker global in the globals to the color you want, probably some grey or background-y color taken from elsewhere in the color scheme.
  6. Use the UI: Select Color Scheme command to select your modified color scheme to use

Protip: This is a handy thing to have anyways, if something doesn't highlight how you like you can use ctrl+shift+p to find out what it's scope is and modify your theme to highlight it how you want!

stopfmt's People

Contributors

kipply avatar trishume avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.