[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 811c499 220/405: New algorithm now works for
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax |
Date: |
Sat, 13 Jul 2019 10:00:17 -0400 (EDT) |
branch: externals/phps-mode
commit 811c4998425aedf9b9cd08c13808fd0f13624d40
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
New algorithm now works for switch, case syntax
---
phps-mode-functions.el | 57 ++++++++++++++++++++++++++++++++++++---------
phps-mode-test-functions.el | 9 +++++--
2 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index d954e93..7555c93 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -60,6 +60,8 @@
(after-special-control-structure-first-on-line nil)
(after-extra-special-control-structure nil)
(after-extra-special-control-structure-first-on-line nil)
+ (switch-curly-stack nil)
+ (switch-alternative-stack nil)
(switch-case-alternative-stack nil)
(curly-bracket-level 0)
(round-bracket-level 0)
@@ -178,17 +180,26 @@
(setq line-contained-nesting-decrease t)
(setq curly-bracket-level (1- curly-bracket-level))
- ;; Keep track of in scripting
- (when (or (equal token 'T_OPEN_TAG)
- (equal token 'T_OPEN_TAG_WITH_ECHO))
- (setq in-scripting t))
- (when (equal token 'T_CLOSE_TAG)
- (setq in-scripting nil))
+ (when (and switch-curly-stack
+ (= (1+ curly-bracket-level) (car
switch-curly-stack)))
+ (when phps-mode-functions-verbose
+ (message "Ended switch curly stack at %s"
curly-bracket-level))
+ (setq allow-custom-column-decrement t)
+ (setq alternative-control-structure-level (1-
alternative-control-structure-level))
+ (pop switch-curly-stack))
+
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
+ ;; Keep track of in scripting
+ (when (or (equal token 'T_OPEN_TAG)
+ (equal token 'T_OPEN_TAG_WITH_ECHO))
+ (setq in-scripting t))
+ (when (equal token 'T_CLOSE_TAG)
+ (setq in-scripting nil))
+
;; Keep track of ending alternative control structure level
(when (or (equal token 'T_ENDIF)
(equal token 'T_ENDWHILE)
@@ -200,7 +211,14 @@
(when (and (equal token 'T_ENDSWITCH)
switch-case-alternative-stack)
- (pop switch-case-alternative-stack))
+
+ (when phps-mode-functions-verbose
+ (message "Ended alternative switch stack at %s"
alternative-control-structure-level))
+
+ (pop switch-alternative-stack)
+ (pop switch-case-alternative-stack)
+ (setq allow-custom-column-decrement t)
+ (setq alternative-control-structure-level (1-
alternative-control-structure-level)))
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
@@ -216,13 +234,29 @@
(setq after-special-control-structure-token token)
;; Is token not a curly bracket - because that is a
ordinary control structure syntax
- (unless (string= token "{")
+ (if (string= token "{")
+
+ ;; Save curly bracket level when switch starts
+ (when (equal after-special-control-structure-token
'T_SWITCH)
+
+ (when phps-mode-functions-verbose
+ (message "Started switch curly stack at %s"
curly-bracket-level))
+
+ (push curly-bracket-level switch-curly-stack))
;; Is it the start of an alternative control structure?
(if (string= token ":")
(progn
+ ;; Save alternative nesting level for switch
+ (when (equal after-special-control-structure-token
'T_SWITCH)
+
+ (when phps-mode-functions-verbose
+ (message "Started switch alternative stack at
%s" alternative-control-structure-level))
+
+ (push alternative-control-structure-level
switch-alternative-stack))
+
(setq alternative-control-structure-level (1+
alternative-control-structure-level))
(when phps-mode-functions-verbose
@@ -312,11 +346,12 @@
(setq after-extra-special-control-structure t)
(setq after-extra-special-control-structure-first-on-line
first-token-on-line)
- (when phps-mode-functions-verbose
- (message "Found CASE %s vs %s" (1-
alternative-control-structure-level) (car switch-case-alternative-stack)))
-
(when (and switch-case-alternative-stack
(= (1- alternative-control-structure-level) (car
switch-case-alternative-stack)))
+
+ (when phps-mode-functions-verbose
+ (message "Found CASE %s vs %s" (1-
alternative-control-structure-level) (car switch-case-alternative-stack)))
+
(setq alternative-control-structure-level (1-
alternative-control-structure-level))
(when first-token-on-line
(setq first-token-is-nesting-decrease t))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e765760..c59ffcb 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -294,12 +294,17 @@
(defun phps-mode-test-functions-get-lines-indent-switch-case ()
"Test for switch-case indentation."
- (phps-mode-test-with-buffer
+ (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"
"Switch, case, default"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (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';\nendswitch;\n"
+ "Switch, case, default with alternative control structure"
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ )
(defun phps-mode-test-functions-indent-line ()
"Test for indentation."
- [elpa] externals/phps-mode cf7dc07 210/405: Preparations for multi-line quoted indentation tests, (continued)
- [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
- [elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax,
Stefan Monnier <=
- [elpa] externals/phps-mode d2e5a03 228/405: Updated indentation algorithm document and README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1aa0f90 238/405: Typo in README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode da1cfd5 231/405: Adding failing lexer test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug with expressions inside double quoted strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0c49d6d 243/405: Removed debugging output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 95ac15a 245/405: Imenu index now handles class extends and implements, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 67233ef 213/405: Fixed indent algorithm for multi-line strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 36a4b64 222/405: Added lost test for token-less lines again, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 70f2d46 242/405: Fixed lexer issue with multiple expressions inside double-quoted string, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0286660 224/405: Indentation passes new tests for concatenated strings, Stefan Monnier, 2019/07/13