emacs-elpa-diffs
[Top][All Lists]
Advanced

[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);"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]