[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 13e9148 159/405: Indentation unit test for as
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 13e9148 159/405: Indentation unit test for assignment is passing |
Date: |
Sat, 13 Jul 2019 10:00:04 -0400 (EDT) |
branch: externals/phps-mode
commit 13e9148feabac75e79688d7f40e282f8426f0c59
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Indentation unit test for assignment is passing
---
phps-mode-functions.el | 50 ++++++++++++++++++++++++++++++++++++++-------
phps-mode-test-functions.el | 11 +++++-----
2 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 1d142ab..022ef6b 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -74,7 +74,9 @@
(last-token nil)
(last-token-was-first-on-new-line nil)
(allow-custom-column-increment nil)
- (allow-custom-column-decrement nil))
+ (allow-custom-column-decrement nil)
+ (in-assignment nil)
+ (in-assignment-on-new-line nil))
;; Iterate through all buffer tokens from beginning to end
(dolist (item phps-mode-lexer-tokens)
@@ -96,9 +98,14 @@
;; 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))
+ ;; Inside assignment increment by one
+ (when in-assignment
+ (setq nesting-end (1+ nesting-end)))
+
;; Is line ending indentation lesser than line beginning
indentation?
(when (and (< nesting-end nesting-start)
- (> column-level 0))
+ (> column-level 0)
+ (not in-assignment-on-new-line))
;; Decrement column
(if allow-custom-column-decrement
@@ -115,7 +122,7 @@
(when first-token-is-nesting-increase
(setq column-level (1+ column-level))))
- ;; (message "new line at %s, %s %s.%s (%s - %s) = %s %s %s
%s %s [%s %s]" token last-token column-level tuning-level nesting-start
nesting-end round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase)
+ (message "new line at %s, %s %s.%s (%s - %s) = %s %s %s %s
%s [%s %s] %s" token last-token column-level tuning-level nesting-start
nesting-end round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase in-assignment)
;; Put indent-level to hash-table
(when (> last-line-number 0)
@@ -151,11 +158,14 @@
;; Calculate indentation level at start of line
(setq nesting-start (+ round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
inline-control-structure-level))
+ ;; Inside assignment increment by one
+ (when in-assignment
+ (setq nesting-start (1+ nesting-start)))
+
;; Set initial values for tracking first token
(setq first-token-on-line t)
(setq first-token-is-nesting-increase nil)
- (setq first-token-is-nesting-decrease nil)
- (setq last-token token))
+ (setq first-token-is-nesting-decrease nil))
(setq first-token-on-line nil))
;; Keep track of round bracket level
@@ -287,6 +297,27 @@
(setq after-special-control-structure round-bracket-level)
(setq after-special-control-structure-token token))
+ ;; Keep track of assignments
+ (when in-assignment
+ (if (string= token ";")
+ (progn
+ (setq in-assignment nil)
+ (message "Assignment ended at semi-colon"))
+ (when first-token-on-line
+ (if (or (equal token 'T_VARIABLE)
+ (equal token 'T_CONSTANT_ENCAPSED_STRING)
+ (equal token 'T_OBJECT_OPERATOR))
+ (progn
+ (message "In assignment on new-line at %s" token)
+ (setq in-assignment-on-new-line t))
+ (message "Not in assignment on new-line at %s" token)
+ (setq in-assignment-on-new-line nil)))))
+ (when (and (not after-special-control-structure)
+ (string= token "="))
+ (message "Started assignment")
+ (setq in-assignment t)
+ (setq in-assignment-on-new-line nil))
+
;; Did we encounter a token that supports extra special
alternative control structures?
(when (equal token 'T_CASE)
(setq after-extra-special-control-structure t)
@@ -311,7 +342,8 @@
;; Update last line number
(setq last-line-number token-start-line-number))
- (setq token-number (1+ token-number))))
+ (setq token-number (1+ token-number))
+ (setq last-token token)))
;; Process line if last token was first on new line
(when last-token-was-first-on-new-line
@@ -319,6 +351,10 @@
;; 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))
+ ;; Inside assignment increment by one
+ (when in-assignment
+ (setq nesting-end (1+ nesting-end)))
+
;; Is line ending indentation lesser than line beginning
indentation?
(when (and (< nesting-end nesting-start)
(> column-level 0))
@@ -338,7 +374,7 @@
(when first-token-is-nesting-increase
(setq column-level (1+ column-level))))
- ;; (message "last token at %s %s.%s (%s - %s) = %s %s %s %s %s [%s
%s]" last-token column-level tuning-level nesting-start nesting-end
round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase)
+ (message "last token at %s %s.%s (%s - %s) = %s %s %s %s %s [%s
%s]" last-token column-level tuning-level nesting-start nesting-end
round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase)
;; Put indent-level to hash-table
(puthash last-line-number `(,column-level ,tuning-level)
line-indents))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 1f6968b..c862954 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -172,14 +172,16 @@
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
(should (equal buffer-contents "<?php\n/**\n* My first line\n* My second
line\n **/\n"))))
+ ;; TODO Fix this and also indentation for class implements
+
(phps-mode-test-with-buffer
"<?php\n$variable = array(\n'random4');\n$variable = true;\n"
"Round bracket test 1"
- (goto-char 29)
+ (goto-char 30)
(phps-mode-functions-indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
+ (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable =
array(\n'random4');\n$variable = true;\n"))))
+ (should (equal buffer-contents "<?php\n$variable = array(\n
'random4');\n$variable = true;\n"))))
(phps-mode-test-with-buffer
"<?php\nadd_filter(\n\"views_{$screen->id}\",'__return_empty_array'\n);"
@@ -244,8 +246,6 @@
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
(should (equal buffer-contents "<?php\nif (myRandomCondition()):\necho
'Something here';\nelse:\n echo 'Something else here 8';\nendif;\n"))))
- ;; switch case
-
(phps-mode-test-with-buffer
"<?php\nswitch (myRandomCondition()) {\ncase 'Something here':\necho
'Something else here';\n}\n"
"Switch case indentation test"
@@ -297,6 +297,7 @@
(phps-mode-test-with-buffer
"<?php\n$var = $var2->getHead()\n->getTail();\n"
"Multi-line assignment indentation test 1"
+ (message "Tokens: %s" phps-mode-lexer-tokens)
(goto-char 35)
(phps-mode-functions-indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- [elpa] externals/phps-mode 20e77aa 181/405: Removed debug output, (continued)
- [elpa] externals/phps-mode 20e77aa 181/405: Removed debug output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 321803a 182/405: Line indents are now cleaning on buffer changes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 38bcabb 176/405: Improved detection of assignment ends in function optional arguments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f1236e2 169/405: Unit tests for indentation calculation for multi-line strings passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 105fece 149/405: New indent calculation for inline syntax passes test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0a32b17 161/405: Improved calculation for indentation for multi-line assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2eac4d 154/405: More work on switch case default, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6b5a5c3 155/405: More work on calculating indentations, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ce2d4bd 148/405: New indentation calculation function passes alternative, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3718931 156/405: Basic tests for indentation calculation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 13e9148 159/405: Indentation unit test for assignment is passing,
Stefan Monnier <=
- [elpa] externals/phps-mode b5c64c1 162/405: Added failing tests for HEREDOC and NOWDOC assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f283e4b 173/405: Added new failing unit tests for multiple-lines IF and single line class declaration, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 59474ea 180/405: Improved debugging messages, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9659ab4 174/405: Added failing test for doc-comments are namespace and class, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c5d8ec6 168/405: Indentation calculation for class implement working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f93765d 184/405: Improved code structure of indentation were nesting start and end equals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2af8abd 206/405: Made TODO notes in algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative control structures passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d18fddc 175/405: Fixed bug with indentation for indented doc-comments, Stefan Monnier, 2019/07/13