Code Monkey home page Code Monkey logo

align.tmbundle's Introduction

align.tmbundle

This is a greatly improved alignment command. Rather than just aligning assignments it will align all sorts of things.

This is a work in progress and I've published this bundle so people can give it a try. In the long term I hope this will get merged into TextMate.

Installation

cd ~/Library/Application\ Support/Avian/Bundles
git clone https://github.com/mads379/align.tmbundle.git

How to add alignment rules

Open the bundle editor (ctrl+alt+cmd+b). Find the Align bundle. Hit cmd+n and choose settings.

In the new setting item, first set its name (something like Alignment Patterns (yourLanguage) and scope (e.g source.yourLanguage). Then add something like the following as content for the setting:

{ shellVariables = (
    { name = 'TM_SOURCE_ALIGNMENT_PATTERN';
      value = '[
      { 
        "regexp" : "=", 
        "padding" : "before"
      },
      { 
        "regexp" : ":", 
        "padding" : "after"
      }]';
    },
  );
}

value is a JSON array containing a list of regexp and padding properties.

This example contains two alignment targets: = and :

regexp is a regular expression which will capture your alignment string. It could be as simple as "=".

padding can be set to before or after depending on whether you wish to insert the padding spaces before or after the alignment string.

minimum_spacing_before and minimum_spacing_after can be set to define the minimum spacing surrounding the matched symbol.

Advanced

You might want a more complex regular expression to capture the alignment string. For instance to capture any of =,+=, -=, *=, /=, the following would work:

`\s[+-*\/]?=\s`

Missing features

  • Left/right justify captures
  • Enable scope specific block separators (currently uses blank lines and indentation to find blocks of code)

History

align.tmbundle's People

Contributors

mads-hartmann avatar tbates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

align.tmbundle's Issues

spaces around symbols

align doesn't equalise the spacing around symbols, so

a=b adam = b
goes to
a =b adam = b

Would be nice to have a spec in the value array for minimum spacing around items so:

    "regexp" : "=",
    "minimum_spacing" : " ",
    "padding" : "before"

Then the space around the item found by the regexp would be trimmed and//or padded to minimum_spacing before padding lines
If "minimum_spacing" : " NA", then behave as at present time

I would also suggest calling spacing "padding" as we are padding before or after, but there is space often before and after

cope with multiple align-characters (: and = ) in Objective-C

Take the case of a switch/case statement in Objective-C with the case statements on a single line: you want to align on "=", but instead it aligns on : because Objective-C users align their method arguments on : so that character is included in align-characters…

Allow TM_SOURCE_ALIGNMENT_PATTERN to specify before/after for each match

Perhaps I'm approaching this from the wrong angle, but it appears that TM_SOURCE_ALIGNMENT_PATTERN only permits a single 'place whitespace before/after' value. However, in Ruby, I want to place whitespace before some separators, and after others. Viz:

# standard Hash-literal syntax:
{
  :short => 'bar',
  :much_longer => 'baz'
}

# should become:
{
  :short       => 'bar',
  :much_longer => 'baz'
}

# but 1.9 Hash-literal syntax:
{
  short: 'bar',
  much_longer: 'baz'
}

# should become:
{
  short:       'bar',
  much_longer: 'baz'
}

Is this currently possible with the align bundle?

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.