branch: externals/phps-mode commit a0cbcd1c9f5a64ecda3b4f457c48a3cffcbb309c Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
More work on indentation of multi-line IF-expressions --- phps-mode-functions.el | 6 ++++++ phps-mode-test-functions.el | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/phps-mode-functions.el b/phps-mode-functions.el index 09deb3b..0583e55 100644 --- a/phps-mode-functions.el +++ b/phps-mode-functions.el @@ -351,6 +351,7 @@ ;; Put indent-level to hash-table (when (> token-start-line-number 0) (puthash token-start-line-number `(,column-level-start ,tuning-level) line-indents)) + ;; Does token span over several lines? (when (> token-end-line-number token-start-line-number) ;; (message "Token %s starts at %s and ends at %s indent %s %s" next-token token-start-line-number token-end-line-number column-level tuning-level) @@ -378,6 +379,11 @@ (setq allow-custom-column-increment nil)) (setq column-level (1+ column-level)))) + ;; When nesting decreases but ends with a nesting increase, increase indent by one + (when (and (< nesting-end nesting-start) + last-token-is-nesting-increase) + (setq column-level (1+ column-level))) + ;; Calculate indentation level at start of line (setq nesting-start (+ round-bracket-level square-bracket-level curly-bracket-level alternative-control-structure-level inline-control-structure-level in-assignment-level in-class-declaration-level)) diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el index f3bdf87..2ccd757 100644 --- a/phps-mode-test-functions.el +++ b/phps-mode-test-functions.el @@ -185,16 +185,23 @@ (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) (phps-mode-test-with-buffer + "<?php\nif (\n true\n && true\n) {\n echo 'was here';\n}\n" + "If expression spanning multiple lines 1" + ;; (message "Tokens: %s" phps-mode-lexer-tokens) + (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (1 0)) (7 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) + + (phps-mode-test-with-buffer "<?php\n// Can we load configuration?\nif ($configuration::load(\n self::getParameter(self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_CONFIGURATION_EXTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_EXTERNAL_FILENAME)\n)) {\n echo 'was here';\n}\n" - "If expression spanning multiple lines" + "If expression spanning multiple lines 2" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (1 0)) (7 (1 0)) (8 (0 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) - (phps-mode-test-with-buffer - "<?php\n// Can we load configuration?\nif ($configuration::load(\n self::getParameter(self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_CONFIGURATION_EXTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_EXTERNAL_FILENAME))\n) {\n echo 'was here';\n}\n" - "If expression spanning multiple lines" + (phps-mode-test-with-buffer + "<?php\nif (true) {\n if ($configuration::load(\n self::getParameter(self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_CONFIGURATION_EXTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_INTERNAL_FILENAME),\n self::getParameter(self::PARAMETER_STRUCTURE_EXTERNAL_FILENAME)\n )) {\n echo 'was here';\n }\n}\n" + "If expression spanning multiple lines 2" ;; (message "Tokens: %s" phps-mode-lexer-tokens) - (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (1 0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) + (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (2 0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) (phps-mode-test-functions--hash-to-list (phps-mode-functions-get-lines-indent))))) + )