2072 / PHP-Indenting-for-VIm

The official VIm indent script for PHP
http://www.2072productions.com/to/phpindent.txt
128 stars 29 forks source link

Feature request: Option to specify indentation for parameters on multi-line function calls #71

Closed bendoh closed 5 years ago

bendoh commented 5 years ago

I'm working with a particular standard that isn't supported by this current version but I think could be fairly easily be made as an option.

The standard is: parameters for multi-line function calls receive an additional level of indentation.

For example, instead of

function f() {
  $this->function(
      $param1,
      $param2,
      [
        'key1' => 1,
        'key2' => 2
      ]
  );
}

Essentially, this just means that if the previous line ends with something that looks like a function call, [\w_]\+($, we add one more level of indentation.

A cursory glance at the plugin suggests to me that adding such an option to this indentation engine wouldn't be much of a stretch, and could be configured in a variable, e.g.,

let g:PHP_IndentFunctionParameters = 2

2072 commented 5 years ago

So you want the above code to look like this:

function f() {
  $this->validFunctionName( // note that if you use 'function' as your function name, the indent script will not work 
          $param1,
          $param2,
          [
            'key1' => 1,
            'key2' => 2
          ]
      );
}

I had to implement proper searchpair matching for closing ) and ] for this option to be possible but it's a good thing in the end so thank you for this request, it made me fix a very old issue that was disregarded a long time ago because it used to be too slow... (15 years ago!)

So I've added the option PHP_IndentFunctionParameters. You can set it globally, before loading a file, or per buffer, at anytime, using let b:PHP_IndentFunctionParameters.

I've tested this new option a little bit but more testing would be very valuable so if you could confirm that it works well for you it would be very appreciated.