randy3k / AlignTab

An alignment plugin for Sublime Text using regular expression
MIT License
631 stars 25 forks source link

Support => alignment #47

Closed dantman closed 8 years ago

dantman commented 9 years ago

Ruby, Puppet, and a few other languages use => for some parts of their syntax. Being able to align these would be nice.

You can try to align by = but then AlignTab turns them all into = >'s.

randy3k commented 9 years ago

I believe that you can use => as the input in AlignTab.

dantman commented 9 years ago

I'm referring to the context menu -> Align By items.

=> alignment is more common than some of the other items on the list, but it's not included.

randy3k commented 9 years ago

You could add your own items to the context menu, check README.

dantman commented 9 years ago

As I said, => is more common than some of the other items in the list.

I think it deserves an entry in that list that exists by default.

randy3k commented 9 years ago

I see. How could I call this operator?

dantman commented 9 years ago

What, are you asking where => would be used?

It's used in PHP for array syntax:

$arr = array(
  'foo'   => 1,
  'bar'   => 2,
  'baz'   => 3,
  'hello' => 'world',
);

It's used in Ruby for hash syntax:

h = {
  :foo    => 1,
  :bar    => 2,
  :baz    => 3,
  'Hello' => 'World'
}

It's used in Puppet:

file { '/home/foo/bar':
  content => "Hello World\n",
  owner   => foo,
  group   => foo,
  mode    => '0644',
}

I believe Perl also uses it for hashes:

%h = (
  foo   => 1,
  bar   => 2,
  baz   => 3,
  hello => "world",
);
zx8 commented 9 years ago

@randy3k - http://en.wikipedia.org/wiki/Fat_comma

isimmons commented 9 years ago

Asking what to call it in the menu? "Fat Arrow" seems the best choice IMHO

leem32 commented 9 years ago

To add align by => to the context menu, go to Preferences -> Package Settings -> AlignTab -> Context Menu and paste this:

[
   {"caption" : "-"},
    {
      "id": "aligntab",
      "caption": "Align By",
      "children": [
          {
          "caption" : "Array Value ( => )",
          "command" : "align_tab",
          "args"    : {"user_input" : "\\=>"}
          }
      ]
  }
]

Name it whatever you like. I named it "Array Value" because i use it with PHP, so it makes the most sense to me. When you use => to align with PHP, make sure the cursor is selected inside the array, or it won't work. :)

randy3k commented 8 years ago

Sorry for the long delay, ede864803f82d4cb8581746404d7bc8c7962a341 adds Fat Arrow and removes some of the un-commons (I think).