branch: externals/phps-mode commit b2a57002bd5212a0a99f98f5cd82629ac1d6aa1f Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Fixed indentation for multi-line optional function arguments --- phps-mode-functions.el | 9 +++++++++ phps-mode-test-functions.el | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/phps-mode-functions.el b/phps-mode-functions.el index d5bd9da..57ae83d 100644 --- a/phps-mode-functions.el +++ b/phps-mode-functions.el @@ -86,6 +86,7 @@ (in-class-declaration nil) (in-class-declaration-level 0) (token nil) + (in-function-declaration nil) (token-start-line-number 0) (token-end-line-number) (tokens (nreverse phps-mode-lexer-tokens)) @@ -166,6 +167,13 @@ (setq in-class-declaration-level 1) (setq class-declaration-started-this-line t))) + ;; Keep track of function declarations + (if (and in-function-declaration + (string= token "{")) + (setq in-function-declaration nil) + (when (equal token 'T_FUNCTION) + (setq in-function-declaration t))) + ;; Keep track of curly bracket level (when (or (equal token 'T_CURLY_OPEN) (equal token 'T_DOLLAR_OPEN_CURLY_BRACES) @@ -318,6 +326,7 @@ ;; (message "In assignment on new-line at %s" token) )) (when (and (not after-special-control-structure) + (not in-function-declaration) (string= token "=")) ;; (message "Started assignment") (setq in-assignment round-bracket-level) diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el index 7b4e183..e0f6ee7 100644 --- a/phps-mode-test-functions.el +++ b/phps-mode-test-functions.el @@ -232,8 +232,8 @@ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) (phps-mode-test-with-buffer - "<?php\nclass MyClass\n{\n public function __construct(\n $arg1,\n $arg2\n ) {\n echo 'here';\n }\n}" - "Class multi-line function arguments" + "<?php\nclass MyClass\n{\n public function __construct(\n $arg1 = false,\n $arg2 = []\n ) {\n echo 'here';\n }\n}" + "Class multi-line optional function arguments" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (2 0)) (6 (2 0)) (7 (1 0)) (8 (2 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent)))))