[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 86404c8 207/405: New algorithm now passes tes
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 86404c8 207/405: New algorithm now passes tests for alternative control structure |
Date: |
Sat, 13 Jul 2019 10:00:14 -0400 (EDT) |
branch: externals/phps-mode
commit 86404c818818244ca161e62c5e220d75078948e8
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
New algorithm now passes tests for alternative control structure
---
docs/indentation-algorithm.md | 34 ++++++++++++++++++++++----------
phps-mode-functions.el | 46 ++++++++++++++++++++++++++++++++++---------
phps-mode-test-functions.el | 4 ++--
3 files changed, 63 insertions(+), 21 deletions(-)
diff --git a/docs/indentation-algorithm.md b/docs/indentation-algorithm.md
index 43e08cf..42667c7 100644
--- a/docs/indentation-algorithm.md
+++ b/docs/indentation-algorithm.md
@@ -17,24 +17,38 @@ Here follows pseudo-code for a algorithm that calculates
indentation for each li
```php
foreach token in buffer:
-
+
calculate nesting-end;
-
+
if nesting-stack AND nesting-end <= nesting-stack-start: // #decrease
pop stack;
- indent--;
+
+ if first-token-on-line-is-nesting-decrease:
+ indent--;
+ else:
+ if !temp-post-indent:
+ temp-post-indent = indent;
+ endif;
+
+ temp-post-indent--;
+ endif;
+
endif;
-
- if we reached end of a line:
+ if we reached end of a line:
+
indent-start = indent;
-
+
if temp-pre-indent: // #temp-pre-indent
indent-start = temp-pre-indent;
endif;
-
+
save line indent-start; // #save
-
+
+ if temp-post-indent: #temp-post-indent
+ indent = temp-post-indent;
+ endif;
+
if nesting-end > 0 AND (!nesting-stack OR nesting-end >
nesting-stack-end): // #increase
if !nesting-stack:
nesting-stack-end = 0;
@@ -44,7 +58,7 @@ foreach token in buffer:
indent++;
endif;
endif;
-
+
endforeach;
```
@@ -66,7 +80,7 @@ if (function( // #save indent: 0, #increase push (0
2) indent: 1
```php // #save indent: 0
if (function( // #save indent: 0, #increase push (0 2) indent: 1
- false)) { // #decrease pop (0 2) post-indent: 0, #save indent: 1,
#increase push (0 1) indent: 1 TODO fix ERROR
+ false)) { // #decrease pop (0 2) temp-post-indent: 0, #save
indent: 1, #temp-post-indent indent: 0, #increase push (0 1) indent: 1
echo true; // #save indent: 1
} // #decrease pop (0 1) indent: 0, #save
indent: 0
```
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index c8d60e4..2f9974c 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -92,7 +92,8 @@
(after-class-declaration nil)
(class-declaration-started-this-line nil)
(special-control-structure-started-this-line nil)
- (temp-pre-indent nil))
+ (temp-pre-indent nil)
+ (temp-post-indent nil))
(push `(END_PARSE ,(point-max) . ,(point-max)) tokens)
@@ -294,6 +295,10 @@
(string= (car (cdr (cdr (car nesting-stack))))
":"))
(setq alternative-control-structure-level (1-
alternative-control-structure-level))
+
+ (when first-token-on-line
+ (setq first-token-is-nesting-decrease t))
+
(when phps-mode-functions-verbose
(message "\nDecreasing alternative control structure
nesting at %s to %s\n" token alternative-control-structure-level))
)
@@ -346,16 +351,35 @@
)
(pop nesting-stack)
- ;; Decrement column
- (if allow-custom-column-decrement
+ (if first-token-is-nesting-decrease
+
(progn
- (setq column-level (- column-level (- nesting-start
nesting-end)))
- (setq allow-custom-column-increment nil))
- (setq column-level (1- column-level)))
+ ;; Decrement column
+ (if allow-custom-column-decrement
+ (progn
+ (setq column-level (- column-level (-
nesting-start nesting-end)))
+ (setq allow-custom-column-increment nil))
+ (setq column-level (1- column-level)))
+
+ ;; Prevent negative column-values
+ (when (< column-level 0)
+ (setq column-level 0)))
+
+ (when (not temp-post-indent)
+ (setq temp-post-indent column-level))
+
+ ;; Decrement column
+ (if allow-custom-column-decrement
+ (progn
+ (setq temp-post-indent (- temp-post-indent (-
nesting-start nesting-end)))
+ (setq allow-custom-column-increment nil))
+ (setq temp-post-indent (1- temp-post-indent)))
+
+ ;; Prevent negative column-values
+ (when (< temp-post-indent 0)
+ (setq temp-post-indent 0))
- ;; Prevent negative column-values
- (when (< column-level 0)
- (setq column-level 0)))
+ ))
;; Are we on a new line or is it the last token of the buffer?
(if (> next-token-start-line-number token-start-line-number)
@@ -405,6 +429,10 @@
;; Rest tuning-level used for comments
(setq tuning-level 0))
+ ;; Support trailing indent decrements
+ (when temp-post-indent
+ (setq column-level temp-post-indent)
+ (setq temp-post-indent nil))
;; Decrease indentation
(when (and (> nesting-end 0)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index f21aae3..c5c3363 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -156,13 +156,13 @@
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
- "<?php\nif (true)\n echo 'Something';\nelse if\n echo 'Something
else';\necho true;\n"
+ "<?php\nif (true)\n echo 'Something';\nelse if (true)\n echo
'Something else';\necho true;\n"
"Inline control structures if else if"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\nwhile (true)\n echo 'Something';"
- "Inline control structures"
+ "Inline control structures while"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
)
- [elpa] externals/phps-mode 9db28d9 185/405: Added verbose flag for unit tests, (continued)
- [elpa] externals/phps-mode 9db28d9 185/405: Added verbose flag for unit tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2a1ed52 196/405: Optimized algorithm for indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a30c3f6 177/405: More work on indentation tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e8a8d41 204/405: Merged remote changes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode faa4e00 201/405: Started on conceptually describing algorithm for multi-line assignment indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 874701d 195/405: Work on alternative and inline control structure syntax with new algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ec69d07 193/405: Added a failing class declaration indentation case, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 164b77e 205/405: Unit test for alternative control syntax passes with new algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e8658c8 192/405: New indentation algorithm now passes class unit tests, started on indentation document, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ba9d8a0 199/405: More organization of tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 86404c8 207/405: New algorithm now passes tests for alternative control structure,
Stefan Monnier <=
- [elpa] externals/phps-mode 8b4c188 188/405: Now able to detect indent change of scope with same nesting level, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 91715f6 217/405: Added another test for multi-line function arguments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 75c4af4 214/405: Fixed indentation for lines wrapped in scripting open/close, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d754163 221/405: More work on multi-line token-less lines, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8947e6e 202/405: Conceptual work on indentation-calculation for multi-line assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode fc2e8b7 212/405: Added logic to indent token-less lines as well, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8707777 237/405: Updated README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2d4646f 203/405: Work on inline control structure indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 202827b 198/405: New indentation algorithm now supports inline control structures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2a5700 218/405: Fixed indentation for multi-line optional function arguments, Stefan Monnier, 2019/07/13