Closed phpmycoder closed 9 years ago
Here's a really rough (and sloppily coded) idea of something that might work. It's untested though, and right now it ignores backslash escapes, but I believe it will ignore alignment chars within quotes:
https://github.com/phpmycoder/sublime_alignment/commit/9e6f852aff012081da7cd6c2ac19dfa5e34f382e
the only solution i see is AlignTab by randy3k it allows to break the lines with regular expressions
While this may not be the answer you want to hear, I see this as "functioning properly." This package is really meant as a quick aide for helping align some code, and is not meant to be a general purpose code formatting tool. I think that language-specific packages with formatting rules are probably the kind of thing that should be use for more complex situations.
Perhaps https://packagecontrol.io/packages/phpfmt would be useful?
However, that said, here is how I would align the equals:
$urlMap = array(
'/old-url' => '/new-url-for-old-url',
'/another-old-url' => '/new-url-for-other-old-url',
'/older-url?page=cart' => '/cart',
'/older-url?page=home' => '/',
'/bad-url' => '/better-url'
);
=
signNow, seeing this list, it might sound complicated, but it takes all of three seconds once you are familiar with the scope selection. Additionally, such features work with any language and can be used to format code in situations where automated formatting makes things a mess.
I ran into an bug when trying to align the following
PHP
:Running
sublime_alignment
, modifies the block of code to look like this:What I expected:
The problem here, I presume, is that alignment has no knowledge that the first equals is within a string. I know that it would very difficult (if not impossible) to have it parse code in all of the languages with which it is compatible to determine whether an equals is actually an assignment operator that should be aligned to. However, I think it is pretty universal that characters surrounded by single or double quotes are strings. With this assumption, I would like to propose adding a rudimentary understanding of strings to
sublime_alignment
, so that it doesn't incorrectly align to characters within a string.Any thoughts?
Thanks!