[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode f7e7c74 219/405: Work on indentation for swit
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode f7e7c74 219/405: Work on indentation for switch-case |
Date: |
Sat, 13 Jul 2019 10:00:16 -0400 (EDT) |
branch: externals/phps-mode
commit f7e7c7439c82001aaa85a1e4c7dce94f92511bc1
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Work on indentation for switch-case
---
phps-mode-functions.el | 92 ++++++++++++++++++---------------------------
phps-mode-test-functions.el | 14 +------
2 files changed, 37 insertions(+), 69 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 57ae83d..d954e93 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -60,7 +60,7 @@
(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-case-alternative-stack nil)
(curly-bracket-level 0)
(round-bracket-level 0)
(square-bracket-level 0)
@@ -86,7 +86,6 @@
(in-class-declaration nil)
(in-class-declaration-level 0)
(token nil)
- (in-function-declaration nil)
(token-start-line-number 0)
(token-end-line-number)
(tokens (nreverse phps-mode-lexer-tokens))
@@ -167,13 +166,6 @@
(setq in-class-declaration-level 1)
(setq class-declaration-started-this-line t)))
- ;; Keep track of function declarations
- (if (and in-function-declaration
- (string= token "{"))
- (setq in-function-declaration nil)
- (when (equal token 'T_FUNCTION)
- (setq in-function-declaration t)))
-
;; Keep track of curly bracket level
(when (or (equal token 'T_CURLY_OPEN)
(equal token 'T_DOLLAR_OPEN_CURLY_BRACES)
@@ -193,13 +185,6 @@
(when (equal token 'T_CLOSE_TAG)
(setq in-scripting nil))
- ;; Decrease switch curly stack if any
- (when (and switch-curly-stack
- (= curly-bracket-level (car switch-curly-stack)))
- (setq curly-bracket-level (1- curly-bracket-level))
- ;; (message "Found ending switch curly bracket")
- (setq allow-custom-column-decrement t)
- (pop switch-curly-stack))
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
@@ -213,11 +198,9 @@
(setq alternative-control-structure-level (1-
alternative-control-structure-level))
;; (message "Found ending alternative token %s %s" token
alternative-control-structure-level)
- (when (equal token 'T_ENDSWITCH)
-
- ;; Decrement end switch with two points
- (setq allow-custom-column-decrement t)
- (setq alternative-control-structure-level (1-
alternative-control-structure-level)))
+ (when (and (equal token 'T_ENDSWITCH)
+ switch-case-alternative-stack)
+ (pop switch-case-alternative-stack))
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
@@ -233,16 +216,13 @@
(setq after-special-control-structure-token token)
;; Is token not a curly bracket - because that is a
ordinary control structure syntax
- (if (string= token "{")
-
- (when (equal after-special-control-structure-token
'T_SWITCH)
- ;; (message "Opening switch, increase curly brackets
to %s" curly-bracket-level)
- (push curly-bracket-level switch-curly-stack))
+ (unless (string= token "{")
;; Is it the start of an alternative control structure?
(if (string= token ":")
(progn
+
(setq alternative-control-structure-level (1+
alternative-control-structure-level))
(when phps-mode-functions-verbose
@@ -255,23 +235,18 @@
(when phps-mode-functions-verbose
(message "\nStarted inline control-structure after
%s at %s\n" after-special-control-structure-token token))
- (setq in-inline-control-structure t)
- (setq temp-pre-indent (1+ column-level))))
+ (setq in-inline-control-structure t)
+ (setq temp-pre-indent (1+ column-level))))
- (setq after-special-control-structure nil)
- (setq after-special-control-structure-token nil)
- (setq after-special-control-structure-first-on-line nil)))
+ (setq after-special-control-structure nil)
+ (setq after-special-control-structure-token nil)
+ (setq after-special-control-structure-first-on-line nil)))
- ;; Support extra special control structures (CASE:)
+ ;; Support extra special control structures (CASE)
(when (and after-extra-special-control-structure
(string= token ":"))
-
- (when phps-mode-functions-verbose
- (message "Started CASE"))
-
- (setq alternative-control-structure-level (1+
alternative-control-structure-level))
-
(setq line-contained-nesting-increase t)
+ (setq alternative-control-structure-level (1+
alternative-control-structure-level))
(when after-extra-special-control-structure-first-on-line
(setq first-token-is-nesting-decrease t))
(setq after-extra-special-control-structure nil))
@@ -320,13 +295,12 @@
(< round-bracket-level in-assignment))
(progn
(setq in-assignment nil)
- (setq in-assignment-level 0))
+ (setq in-assignment-level 0))
(when first-token-on-line
(setq in-assignment-level 1)
;; (message "In assignment on new-line at %s" token)
))
(when (and (not after-special-control-structure)
- (not in-function-declaration)
(string= token "="))
;; (message "Started assignment")
(setq in-assignment round-bracket-level)
@@ -336,9 +310,19 @@
;; 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 after-extra-special-control-structure-first-on-line
first-token-on-line))
+ (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)))
+ (setq alternative-control-structure-level (1-
alternative-control-structure-level))
+ (when first-token-on-line
+ (setq first-token-is-nesting-decrease t))
+ (pop switch-case-alternative-stack))
- )
+ (push alternative-control-structure-level
switch-case-alternative-stack)))
(when token
@@ -402,6 +386,16 @@
(setq column-level-start column-level)
+ ;; Indent token-less lines here in between last tokens
if distance is more than 1 line
+ (when (and (> next-token-start-line-number (1+
token-start-line-number))
+ (not (equal token 'T_CLOSE_TAG)))
+ (let ((token-line-number-diff (1- (-
token-start-line-number next-token-start-line-number))))
+ (while (>= token-line-number-diff 0)
+ (puthash (- token-start-line-number
token-line-number-diff) `(,column-level-start ,tuning-level) line-indents)
+ ;; (message "Saved line %s indent %s %s" (-
token-end-line-number token-line-number-diff) column-level tuning-level)
+ (setq token-line-number-diff (1-
token-line-number-diff)))))
+
+
;; Support temporarily pre-indent
(when temp-pre-indent
(setq column-level-start temp-pre-indent)
@@ -480,20 +474,6 @@
(setq tuning-level 0)))
-;; Indent token-less lines here in between last tokens if distance is more
than 1 line
- (when (and (> next-token-start-line-number (1+
token-end-line-number))
- (not (equal token 'T_CLOSE_TAG)))
-
- (when phps-mode-functions-verbose
- (message "\nDetected token-less lines between %s and
%s, should have indent: %s\n" token-end-line-number
next-token-start-line-number column-level))
-
- (let ((token-line-number-diff (1- (-
next-token-start-line-number token-end-line-number))))
- (while (>= token-line-number-diff 0)
- (puthash (- next-token-start-line-number
token-line-number-diff) `(,column-level ,tuning-level) line-indents)
- ;; (message "Saved line %s indent %s %s" (-
token-end-line-number token-line-number-diff) column-level tuning-level)
- (setq token-line-number-diff (1-
token-line-number-diff)))))
-
-
;; ;; When nesting decreases but ends with a nesting
increase, increase indent by one
;; (when (and (< nesting-end nesting-start)
;; line-contained-nesting-increase)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e0f6ee7..e765760 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -123,12 +123,6 @@
;; (message "Tokens: %s" phps-mode-lexer-tokens)
(should (equal '((1 (0 0)) (2 (1 0)) (3 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
- (phps-mode-test-with-buffer
- "<?php\nif (true) {\n\n\n echo 'here';\n\n}"
- "Regular if-expression white token-less lines"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (1
0)) (7 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
-
)
(defun phps-mode-test-functions-get-lines-indent-multi-line-assignments ()
@@ -231,12 +225,6 @@
;; (message "Tokens: %s" phps-mode-lexer-tokens)
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
- (phps-mode-test-with-buffer
- "<?php\nclass MyClass\n{\n public function __construct(\n $arg1 =
false,\n $arg2 = []\n ) {\n echo 'here';\n }\n}"
- "Class multi-line optional function arguments"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (2 0)) (6 (2
0)) (7 (1 0)) (8 (2 0)) (9 (1 0)) (10 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
-
(phps-mode-test-with-buffer
"<?php\n/**\n *\n */\nnamespace Aomebo\n{\n /**\n *\n */\n
class Base\n {\n }\n}\n"
@@ -288,7 +276,7 @@
"<html><head><title><?php if ($myCondition) {\n if ($mySeconCondition)
{\n echo $title2;\n\n } ?></title><body>Bla bla</body></html>"
"Mixed HTML/PHP with if expression"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (2 0)) (5 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+ (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (5 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<html><head><title><?php\nif ($myCondition) {\n if ($mySecondCondition)
{\n echo $title;\n } else if ($mySecondCondition) {\n echo
$title4;\n } else {\n echo $title2;\n echo $title3;\n }\n}
?></title><body>Bla bla</body></html>"
- [elpa] externals/phps-mode 8707777 237/405: Updated README, (continued)
- [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
- [elpa] externals/phps-mode f7186a1 239/405: Preparations for hierarchical imenu, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 43bf350 216/405: Added tests for token-less lines, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0de10fa 235/405: Passes first test for imenu, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f791cee 234/405: Started on unit tests for imenu-index generation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b56a15c 233/405: Removed debugging output, updated todo items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 73784d0 225/405: Cleaned up tests for indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f7e7c74 219/405: Work on indentation for switch-case,
Stefan Monnier <=
- [elpa] externals/phps-mode c2af31e 240/405: Imenu support now shows hierarchical information, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 55953de 232/405: Lexer now doesn't find keywords in function names, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b8e9449 247/405: Refactored Imenu to use a persistent variable per buffer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 67b8701 244/405: Decreased length of imenu items to prevent truncation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e78d8ed 248/405: Clean-up of indentation code, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c2db7d3 250/405: Preparations for integration test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 11309b8 256/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode fcc920f 258/405: More preparations for merging indent and Imenu into one function, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 41c12c1 251/405: Updated paths for byte-compilation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0e927e8 252/405: Fixed compilation command in makefile, Stefan Monnier, 2019/07/13