branch: externals/phps-mode
commit 8a760392f607f839c4cd7e917141d81f094d2741
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Started implementing nesting-stack
---
phps-mode-functions.el | 25 +++++++++++++++++++++----
phps-mode-test-functions.el | 4 ++--
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 87959ee..46419e2 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -318,7 +318,13 @@
(setq nesting-end (+ round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
inline-control-structure-level in-assignment-level in-class-declaration-level))
;; Is line ending indentation lesser than line beginning
indentation?
- (when (< nesting-end nesting-start)
+ (when (and nesting-stack
+ (<= nesting-end (car nesting-stack)))
+
+ (when phps-mode-functions-verbose
+ (message "Popping %s from nesting-stack since %s is
lesser" (car nesting-stack) nesting-end))
+
+ (pop nesting-stack)
;; Decrement column
(if allow-custom-column-decrement
@@ -331,16 +337,20 @@
(when (< column-level 0)
(setq column-level 0)))
+ ;; Start indentation might differ from ending
indentation in cases like } else {
(setq column-level-start column-level)
(when (= nesting-end nesting-start)
+
+ ;; Handle cases like: } else {
(when (and first-token-is-nesting-decrease
(not first-token-is-nesting-increase)
(> column-level-start 0))
(setq column-level-start (1- column-level-start)))
+
+ ;; Handle cases like if (blaha)\n echo 'blaha';
(when (and first-token-is-nesting-increase
(not first-token-is-nesting-decrease))
(setq column-level-start (1+ column-level-start))))
-
(when phps-mode-functions-verbose
(message "Process line ending. nesting: %s-%s,
line-number: %s-%s, indent: %s.%s, token: %s" nesting-start nesting-end
token-start-line-number token-end-line-number column-level-start tuning-level
token))
@@ -376,12 +386,19 @@
(progn
(setq column-level (+ column-level (-
nesting-end nesting-start)))
(setq allow-custom-column-increment nil))
- (setq column-level (1+ column-level))))
+ (setq column-level (1+ column-level)))
+
+ (when phps-mode-functions-verbose
+ (message "Pushing %s to nesting-stack since is
greater than %s" nesting-end nesting-start))
+ (push nesting-start nesting-stack))
;; When nesting decreases but ends with a nesting
increase, increase indent by one
(when (and (< nesting-end nesting-start)
line-contained-nesting-increase)
- (setq column-level (1+ column-level)))
+ (setq column-level (1+ column-level))
+ (when phps-mode-functions-verbose
+ (message "Pushing %s to nesting-stack since is
greater than %s" nesting-end nesting-start))
+ (push nesting-start nesting-stack))
;; 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 35846a4..2180dfc 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -81,7 +81,7 @@
(phps-mode-test-with-buffer
"<?php\nmyFunction(array(\n 23,\n [\n 25\n ]\n )\n);"
"Round and square bracket expressions"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (2 0)) (6 (1
0)) (7 (0 0)) (8 (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 (1 0)) (5 (2 0)) (6 (1
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\nswitch ($condition) {\n case true:\n echo 'here';\n
echo 'here 2';\n case false:\n echo 'here 4';\n default:\n
echo 'here 3';\n}\n"
@@ -98,7 +98,7 @@
"<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
"Array assignment on only two lines"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (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 (0 0)) )
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\n$str = <<<'EOD'\nExample of string\nspanning multiple lines\nusing
nowdoc syntax.\nEOD;\n"