[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 874701d 195/405: Work on alternative and inli
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 874701d 195/405: Work on alternative and inline control structure syntax with new algorithm |
Date: |
Sat, 13 Jul 2019 10:00:11 -0400 (EDT) |
branch: externals/phps-mode
commit 874701d380036ae3426505b31f2a7e80311f7eac
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Work on alternative and inline control structure syntax with new algorithm
---
phps-mode-functions.el | 41 +++++++++++++++++++++++++++++++----------
phps-mode-test-functions.el | 26 +++++++++++++++++++++-----
2 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 165d6ea..ddf0270 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -91,7 +91,8 @@
(nesting-stack nil)
(changed-nesting-stack-in-line nil)
(after-class-declaration nil)
- (class-declaration-started-this-line nil))
+ (class-declaration-started-this-line nil)
+ (special-control-structure-started-this-line nil))
(push `(END_PARSE ,(point-max) . ,(point-max)) tokens)
@@ -149,13 +150,10 @@
(pop nesting-stack))
(when first-token-on-line
-
(setq after-class-declaration t)
(setq first-token-is-nesting-increase nil)
(setq first-token-is-nesting-decrease t))
- (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))
-
)
(when first-token-on-line
(setq in-class-declaration-level 1)))
@@ -226,7 +224,9 @@
;; Is it the start of an alternative control structure?
(if (string= token ":")
+
(progn
+ ;; Alternative syntax for control structures here
(if (or (equal after-special-control-structure-token
'T_ELSE)
(equal after-special-control-structure-token
'T_ELSEIF)
(equal after-special-control-structure-token
'T_DEFAULT))
@@ -243,18 +243,26 @@
(setq line-contained-nesting-increase t)
(when after-special-control-structure-first-on-line
(setq first-token-is-nesting-increase t))))
+
+ ;; Inline syntax for control structures here
(if (or (equal after-special-control-structure-token
'T_ELSE)
(equal after-special-control-structure-token
'T_ELSEIF))
(progn
(setq line-contained-nesting-increase t)
(when after-special-control-structure-first-on-line
+
+
(setq first-token-is-nesting-increase t)))
;; (message "Was inline-control structure %s %s"
after-special-control-structure-token token)
(setq inline-control-structure-level (1+
inline-control-structure-level))
(setq line-contained-nesting-increase t)
(when after-special-control-structure-first-on-line
(setq first-token-is-nesting-increase t))
- (setq in-inline-control-structure t))))
+ (setq in-inline-control-structure t))
+
+ (when (not special-control-structure-started-this-line)
+ (setq column-level (1+ column-level)))
+ ))
(setq after-special-control-structure nil)
(setq after-special-control-structure-token nil)
@@ -270,7 +278,9 @@
;; Did we reach a semicolon inside a inline block? Close the
inline block
(when (and in-inline-control-structure
- (string= token ";"))
+ (string= token ";")
+ (not special-control-structure-started-this-line))
+ (setq column-level (1- column-level))
(setq line-contained-nesting-decrease t)
(setq inline-control-structure-level (1-
inline-control-structure-level))
(setq in-inline-control-structure nil))
@@ -286,7 +296,18 @@
(equal token 'T_DEFAULT))
(setq after-special-control-structure-first-on-line
first-token-on-line)
(setq after-special-control-structure round-bracket-level)
- (setq after-special-control-structure-token token))
+ (setq after-special-control-structure-token token)
+ (setq special-control-structure-started-this-line t)
+
+ (when (and (or (equal token 'T_ELSE)
+ (equal token 'T_ELSEIF)
+ (equal token 'T_DEFAULT))
+ nesting-stack
+ (string= (car (cdr (cdr (car nesting-stack))))
":"))
+ (setq column-level (1- column-level))
+ (pop nesting-stack))
+
+ )
;; Keep track of assignments
(if in-assignment
@@ -410,7 +431,6 @@
;; Has nesting decreased?
- ;; If nesting-end > 0 AND (!nesting-stack OR nesting-end
> nesting-stack-end), push stack, increase indent
(when (and (> nesting-end 0)
(or (not nesting-stack)
(> nesting-end (car (cdr (car
nesting-stack))))))
@@ -428,7 +448,7 @@
(when phps-mode-functions-verbose
;; (message "\nPushing (%s %s) to nesting-stack
since %s is greater than %s or stack is empty" nesting-start nesting-end
nesting-end (car (cdr (car nesting-stack))))
)
- (push `(,nesting-stack-end ,nesting-end)
nesting-stack)
+ (push `(,nesting-stack-end ,nesting-end ,token)
nesting-stack)
(when phps-mode-functions-verbose
;; (message "New stack %s, start: %s end: %s\n"
nesting-stack (car (car nesting-stack)) (car (cdr (car nesting-stack))))
)))
@@ -457,7 +477,8 @@
(setq line-contained-nesting-decrease nil)
(setq in-assignment-started-this-line nil)
(setq changed-nesting-stack-in-line nil)
- (setq class-declaration-started-this-line nil)))
+ (setq class-declaration-started-this-line nil)
+ (setq special-control-structure-started-this-line
nil)))
;; Current token is not first
(setq first-token-on-line nil)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 16bb3f4..ebc2f8f 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -48,11 +48,6 @@
"Test `phps-mode-functions-get-lines-indent' function."
(phps-mode-test-with-buffer
- "<?php\nif (true):\n echo 'Something';\nelseif (true):\n echo
'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
- "Alternative control structures"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0)) (7 (1 0)) (8 (1 0)) (9 (0 0)) (10 (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\n echo 'Something
else';\necho true;\n"
"Inline control structures"
(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)))))
@@ -153,6 +148,26 @@
)
+(defun phps-mode-test-functions-get-lines-indent-alternative-if ()
+ "Test for alternative if indentations."
+
+ (phps-mode-test-with-buffer
+ "<?php\nif (true):\n echo 'Something';\nelseif (true):\n echo
'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
+ "Alternative control structures"
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0)) (7 (1 0)) (8 (1 0)) (9 (0 0)) (10 (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';\nelseif (true\n && true):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
+ "Alternative control structures with multi-line elseif 1"
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (1
0)) (7 (0 0)) (8 (1 0)) (9 (1 0)) (10 (0 0)) (11 (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';\nelseif (true\n && true\n):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something
else again';\nendif;\necho true;\n"
+ "Alternative control structures with multi-line elseif 1"
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0)) (7 (1 0)) (8 (0 0)) (9 (1 0)) (10 (1 0)) (11 (0 0)) (12 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ )
+
(defun phps-mode-test-function-get-lines-indent-classes ()
"Test for class indent."
@@ -489,6 +504,7 @@
(phps-mode-test-functions-get-lines-lindent-if)
(phps-mode-test-function-get-lines-indent-classes)
(phps-mode-test-functions-get-lines-indent)
+ (phps-mode-test-functions-get-lines-indent-alternative-if)
(phps-mode-test-functions-indent-line))
(phps-mode-test-functions)
- [elpa] externals/phps-mode d9a0119 183/405: Optimized indentation code by removing unused variables, (continued)
- [elpa] externals/phps-mode d9a0119 183/405: Optimized indentation code by removing unused variables, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a0cbcd1 186/405: More work on indentation of multi-line IF-expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d7c5f67 190/405: More work on nesting-stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 253839f 170/405: Added indentation unit tests for concatenated strings outside assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e38794b0 197/405: More conceptual work on algorithm for inline control structures, Stefan Monnier, 2019/07/13
- [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 <=
- [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, 2019/07/13
- [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