branch: externals/phps-mode commit 43c13b4e827833febc3277ebe7d51c54e9ed74ee Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Started on new algorithm for concatenation indentation --- phps-mode-functions.el | 35 +++++++++++++++++++++++------------ phps-mode-lexer.el | 3 ++- phps-mode-test-functions.el | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/phps-mode-functions.el b/phps-mode-functions.el index 89a5501..5d5d2b7 100644 --- a/phps-mode-functions.el +++ b/phps-mode-functions.el @@ -95,7 +95,10 @@ (round-bracket-level 0) (square-bracket-level 0) (alternative-control-structure-level 0) - (concatenation-level 0) + (in-concatenation nil) + (in-concatenation-round-bracket-level nil) + (in-concatenation-square-bracket-level nil) + (in-concatenation-level 0) (column-level 0) (column-level-start 0) (tuning-level 0) @@ -397,15 +400,23 @@ (setq first-token-is-nesting-decrease t)) (setq after-extra-special-control-structure nil)) - ;; Keep track of concatenations - (when (> next-token-start-line-number token-end-line-number) - (if (or (string= token ".") - (string= next-token ".")) - (progn - (when phps-mode-functions-verbose - (message "\nFound ending dot, indenting next line with one.\n")) - (setq concatenation-level 1)) - (setq concatenation-level 0))) + ;; Keep track of concatenation + (if in-concatenation + (when (or (string= token ";") + (and (string= token ")") + (<= round-bracket-level in-concatenation-round-bracket-level)) + (and (string= token"]") + (<= square-bracket-level in-concatenation-square-bracket-level))) + (setq in-concatenation nil) + (setq in-concatenation-level 0)) + (when (and (> next-token-start-line-number token-end-line-number) + (or (string= token ".") + (string= next-token "."))) + ;; (message "Started assignment") + (setq in-concatenation t) + (setq in-concatenation-round-bracket-level round-bracket-level) + (setq in-concatenation-square-bracket-level square-bracket-level) + (setq in-concatenation-level 1))) ;; Did we reach a semicolon inside a inline block? Close the inline block (when (and in-inline-control-structure @@ -487,7 +498,7 @@ (message "Processing token: %s" token)) ;; Calculate nesting - (setq nesting-end (+ round-bracket-level square-bracket-level curly-bracket-level alternative-control-structure-level in-assignment-level in-class-declaration-level concatenation-level)) + (setq nesting-end (+ round-bracket-level square-bracket-level curly-bracket-level alternative-control-structure-level in-assignment-level in-class-declaration-level in-concatenation-level)) ;; Keep track of whether we are inside a HEREDOC or NOWDOC (when (equal token 'T_START_HEREDOC) @@ -653,7 +664,7 @@ ;; Calculate indentation level at start of line - (setq nesting-start (+ round-bracket-level square-bracket-level curly-bracket-level alternative-control-structure-level in-assignment-level in-class-declaration-level concatenation-level)) + (setq nesting-start (+ round-bracket-level square-bracket-level curly-bracket-level alternative-control-structure-level in-assignment-level in-class-declaration-level in-concatenation-level)) ;; Set initial values for tracking first token (when (> token-start-line-number last-line-number) diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el index 87a824e..95e171a 100644 --- a/phps-mode-lexer.el +++ b/phps-mode-lexer.el @@ -1694,7 +1694,8 @@ (end (cdr (cdr token)))) (if (< start previous-token-end) (progn - (semantic-lex-push-token (semantic-lex-token token start end)) + ;; NOTE Does following line make any difference? + ;; (semantic-lex-push-token (semantic-lex-token token start end)) (push token old-tokens)) (throw 'stop-iteration nil))))) (setq old-tokens (nreverse old-tokens)) diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el index 7f18ae7..5a8397b 100644 --- a/phps-mode-test-functions.el +++ b/phps-mode-test-functions.el @@ -335,7 +335,7 @@ "<?php\n$var =\n 500 .\n \"200\" .\n 100.0 .\n '200' .\n $this->getTail()\n ->getBottom();" "Multi-line assignments" ;; (message "Tokens: %s" phps-mode-lexer-tokens) - (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))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))) + (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (1 0)) (7 (1 0)) (8 (1 0))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))) )