[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 834275b 354/405: Fixed indentation calculatio
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 834275b 354/405: Fixed indentation calculation of nested alternative control structures |
Date: |
Sat, 13 Jul 2019 10:00:47 -0400 (EDT) |
branch: externals/phps-mode
commit 834275b2db5aa7505786c95257ad7e357f35ea73
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Fixed indentation calculation of nested alternative control structures
---
phps-mode-functions.el | 31 +++++++++++++++++++++----------
phps-mode-test-functions.el | 3 ++-
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 3be811b..d3649e1 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -130,6 +130,7 @@
(token-end-line-number 0)
(tokens (nreverse phps-mode-lexer-tokens))
(nesting-stack nil)
+ (nesting-key nil)
(class-declaration-started-this-line nil)
(special-control-structure-started-this-line nil)
(temp-pre-indent nil)
@@ -450,22 +451,31 @@
(equal token 'T_DEFAULT))
(setq after-special-control-structure round-bracket-level)
(setq after-special-control-structure-token token)
+ (setq nesting-key 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))))
":"))
-
+ ;; ELSE and ELSEIF after a IF, ELSE, ELESIF
+ ;; and DEFAULT after a CASE
+ ;; should decrease alternative control structure level
+ (when (and nesting-stack
+ (string= (car (cdr (cdr (cdr (car
nesting-stack))))) ":")
+ (or
+ (and (or (equal token 'T_ELSE)
+ (equal token 'T_ELSEIF))
+ (or (equal (car (cdr (cdr (car
nesting-stack)))) 'T_IF)
+ (equal (car (cdr (cdr (car
nesting-stack)))) 'T_ELSEIF)
+ (equal (car (cdr (cdr (car
nesting-stack)))) 'T_ELSE)))
+ (and (equal token 'T_DEFAULT)
+ (equal (car (cdr (cdr (car
nesting-stack)))) 'T_CASE))))
(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))
- ))
+ (message "\nDecreasing alternative control structure
nesting at %s to %s\n" token alternative-control-structure-level)))
+
+ )
;; Keep track of assignments
(when in-assignment
@@ -537,6 +547,7 @@
;; Did we encounter a token that supports extra special
alternative control structures?
(when (equal token 'T_CASE)
(setq after-extra-special-control-structure t)
+ (setq nesting-key token)
(setq after-extra-special-control-structure-first-on-line
first-token-on-line)
(when (and switch-case-alternative-stack
@@ -675,9 +686,9 @@
(setq column-level (1+ column-level)))
(when phps-mode-functions-verbose
- (message "\nPushing (%s %s %s) to nesting-stack
since %s is greater than %s or stack is empty\n" nesting-start nesting-end
token nesting-end (car (cdr (car nesting-stack))))
+ (message "\nPushing (%s %s %s %s) to nesting-stack
since %s is greater than %s or stack is empty\n" nesting-start nesting-end
nesting-key token nesting-end (car (cdr (car nesting-stack))))
)
- (push `(,nesting-stack-end ,nesting-end ,token)
nesting-stack)
+ (push `(,nesting-stack-end ,nesting-end ,nesting-key
,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))))
)))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 471e512..6e25f76 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -205,7 +205,8 @@
(phps-mode-test-with-buffer
"<?php\nswitch ($condition) {\n case 34:\n if ($item['Random'] %
10 == 0) {\n $attributes['item'] = ($item['IntegerValue'] / 10);\n
} else {\n $attributes['item'] =\n
number_format(($item['IntegerValue'] / 10), 1, '.', '');\n }\n
break;\n}\n"
"Switch case with conditional modulo expression"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (2
0)) (7 (3 0)) (8 (4 0)) (9 (3 0)) (10 (3 0)) (11 (0 0)))
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+ (message "indent: %s" (phps-mode-test-hash-to-list
(phps-mode-functions-get-lines-indent)))
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (2
0)) (7 (3 0)) (8 (4 0)) (9 (2 0)) (10 (2 0)) (11 (0 0)))
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\n$options = array(\n 'options' => array(array(\n
'errorTo'\n ))\n);"
- [elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline logic, (continued)
- [elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline logic, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d8ad25b 341/405: Passes new test indentation of multi-line double-arrow inside assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e7cb803 346/405: Added another indentation test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dabe0ea 345/405: Added failing indentation test for multi-dimension array in assignment with double arrows, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d6e6cbc 358/405: Another optimization of line-number-at-pos inside loop, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e681c9c 347/405: Updated color syntax for T_STRING tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c11bcc5 360/405: More work on newline advice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 282115f 357/405: Using incremental line-number calculation as optimization, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c118f58 342/405: Added TODO items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 812dc49 353/405: Removed TODO item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 834275b 354/405: Fixed indentation calculation of nested alternative control structures,
Stefan Monnier <=
- [elpa] externals/phps-mode 62f1fc5 348/405: Added another failing indentation test for return expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 071acc0 349/405: Added support for multi-line return indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 46d0575 373/405: Passes all tests for adding newline and indenting without affect lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 71858d1 374/405: Removed side-effect of END_PARSE token being added to tokens after processing buffer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 228b657 380/405: Updated README with license logo and Travis CI build status, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6308e3e 366/405: Removed debug notice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bd90dc9 370/405: Removed debug output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 38bd348 361/405: More work on advice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2efd7d7 367/405: Started on function to move line-indent index, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5bc592a 368/405: More work on moving indent indexes, Stefan Monnier, 2019/07/13