[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting-stack |
Date: |
Sat, 13 Jul 2019 10:00:10 -0400 (EDT) |
branch: externals/phps-mode
commit 8a760392f607f839c4cd7e917141d81f094d2741
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
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"
- [elpa] externals/phps-mode f283e4b 173/405: Added new failing unit tests for multiple-lines IF and single line class declaration, (continued)
- [elpa] externals/phps-mode f283e4b 173/405: Added new failing unit tests for multiple-lines IF and single line class declaration, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 59474ea 180/405: Improved debugging messages, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9659ab4 174/405: Added failing test for doc-comments are namespace and class, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c5d8ec6 168/405: Indentation calculation for class implement working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f93765d 184/405: Improved code structure of indentation were nesting start and end equals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2af8abd 206/405: Made TODO notes in algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative control structures passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d18fddc 175/405: Fixed bug with indentation for indented doc-comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm handles class declaration indents, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting-stack,
Stefan Monnier <=
- [elpa] externals/phps-mode cf7dc07 210/405: Preparations for multi-line quoted indentation tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 208a788 208/405: Re-organized indent tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c678fc1 209/405: New algorithm handles HEREDOC indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b6cf3a4 191/405: Started on new algorithm for indentation calculation based on stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a4b98e 215/405: More work on algorithm description, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6105e5d 226/405: Added a new failing test for indetation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5f445cd 229/405: Fixed indentation for while expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode eb0ee5e 236/405: Updated README with imenu-support, Stefan Monnier, 2019/07/13