[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8b4c188 188/405: Now able to detect indent ch
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 8b4c188 188/405: Now able to detect indent change of scope with same nesting level |
Date: |
Sat, 13 Jul 2019 10:00:10 -0400 (EDT) |
branch: externals/phps-mode
commit 8b4c18803f8f61f08749e0557d8e2aa57b6806fc
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Now able to detect indent change of scope with same nesting level
---
phps-mode-functions.el | 30 ++++++++++++++++--------------
phps-mode-test-functions.el | 12 +++++++++---
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 2693b4e..87959ee 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -74,8 +74,8 @@
(line-indents (make-hash-table :test 'equal))
(first-token-is-nesting-decrease nil)
(first-token-is-nesting-increase nil)
- (last-token-is-nesting-increase nil)
- (last-token-is-nesting-decrease nil)
+ (line-contained-nesting-decrease nil)
+ (line-contained-nesting-increase nil)
(token-number 1)
(allow-custom-column-increment nil)
(allow-custom-column-decrement nil)
@@ -114,6 +114,7 @@
;; Keep track of round bracket level
(when (string= token "(")
(setq round-bracket-level (1+ round-bracket-level))
+ (setq line-contained-nesting-increase t)
(when first-token-on-line
(setq first-token-is-nesting-increase t)))
(when (string= token ")")
@@ -124,10 +125,12 @@
;; Keep track of square bracket level
(when (string= token "[")
(setq square-bracket-level (1+ square-bracket-level))
+ (setq line-contained-nesting-increase t)
(when first-token-on-line
(setq first-token-is-nesting-increase t)))
(when (string= token "]")
(setq square-bracket-level (1- square-bracket-level))
+ (setq line-contained-nesting-decrease t)
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
@@ -136,9 +139,11 @@
(equal token 'T_DOLLAR_OPEN_CURLY_BRACES)
(string= token "{"))
(setq curly-bracket-level (1+ curly-bracket-level))
+ (setq line-contained-nesting-increase t)
(when first-token-on-line
(setq first-token-is-nesting-increase t)))
(when (string= token "}")
+ (setq line-contained-nesting-decrease t)
(setq curly-bracket-level (1- curly-bracket-level))
;; Keep track of in scripting
@@ -196,6 +201,7 @@
(equal after-special-control-structure-token
'T_ELSEIF)
(equal after-special-control-structure-token
'T_DEFAULT))
(progn
+ (setq line-contained-nesting-increase t)
(when
after-special-control-structure-first-on-line
(setq first-token-is-nesting-decrease t)))
@@ -204,15 +210,18 @@
(setq allow-custom-column-increment t))
(setq alternative-control-structure-level (1+
alternative-control-structure-level))
+ (setq line-contained-nesting-increase t)
(when after-special-control-structure-first-on-line
(setq first-token-is-nesting-increase t))))
(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))))
@@ -224,6 +233,7 @@
;; Support extra special control structures (CASE)
(when (and after-extra-special-control-structure
(string= token ":"))
+ (setq line-contained-nesting-increase t)
(when after-extra-special-control-structure-first-on-line
(setq first-token-is-nesting-decrease t))
(setq after-extra-special-control-structure nil))
@@ -231,6 +241,7 @@
;; Did we reach a semicolon inside a inline block? Close the
inline block
(when (and in-inline-control-structure
(string= token ";"))
+ (setq line-contained-nesting-decrease t)
(setq inline-control-structure-level (1-
inline-control-structure-level))
(setq in-inline-control-structure nil))
@@ -306,17 +317,6 @@
;; Calculate indentation level at end of line
(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))
- ;; Set flags for last token
- (setq last-token-is-nesting-increase (or (string= token
"{")
- (string= token
"(")
- (string= token
"[")))
- (setq last-token-is-nesting-decrease (or (string= token
"}")
- (string= token
")")
- (string= token
"]")))
-
- ;; TODO Should keep stack of nesting-levels and only
change columns when nesting exceeds previous
- ;; TODO Should only change column-level once below
-
;; Is line ending indentation lesser than line beginning
indentation?
(when (< nesting-end nesting-start)
@@ -380,7 +380,7 @@
;; When nesting decreases but ends with a nesting
increase, increase indent by one
(when (and (< nesting-end nesting-start)
- last-token-is-nesting-increase)
+ line-contained-nesting-increase)
(setq column-level (1+ column-level)))
;; Calculate indentation level at start of line
@@ -393,6 +393,8 @@
(setq first-token-is-nesting-decrease nil)
(setq in-assignment-level 0)
(setq in-class-declaration-level 0)
+ (setq line-contained-nesting-increase nil)
+ (setq line-contained-nesting-decrease nil)
(setq in-assignment-started-this-line nil)))
(setq first-token-on-line nil)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index fa7439a..35846a4 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -203,14 +203,20 @@
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (2
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (1 0)) (11 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
- "<?php\nif (myFunction(\n true)\n) {\n echo 'was here';\n}\n"
+ "<?php\nif (myFunction(true)\n) {\n echo 'was here';\n}\n"
"If expression spanning multiple lines 4"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (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)))))
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ (phps-mode-test-with-buffer
+ "<?php\nif (myFunction(\ntrue)\n) {\n echo 'was here';\n}\n"
+ "If expression spanning multiple lines 5"
+ ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (1 0)) (6 (0
0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\nif (true) {\n if (myFunction(\n true)\n ) {\n
echo 'was here';\n }\n}\n"
- "Nested if expression spanning multiple lines 5"
+ "Nested if expression spanning multiple lines 6"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
- [elpa] externals/phps-mode 2a1ed52 196/405: Optimized algorithm for indentation, (continued)
- [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, 2019/07/13
- [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 <=
- [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
- [elpa] externals/phps-mode fc2e8b7 212/405: Added logic to indent token-less lines as well, Stefan Monnier, 2019/07/13
- [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