[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode ce2d4bd 148/405: New indentation calculation
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode ce2d4bd 148/405: New indentation calculation function passes alternative |
Date: |
Sat, 13 Jul 2019 10:00:02 -0400 (EDT) |
branch: externals/phps-mode
commit ce2d4bd01bb7b7b19dad3804e7f410e1d3ceb39c
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
New indentation calculation function passes alternative
---
phps-mode-functions.el | 100 +++++++++++++++++++++++++-------------------
phps-mode-test-functions.el | 1 +
2 files changed, 59 insertions(+), 42 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 240e90c..badc339 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -43,14 +43,14 @@
"Get the column and tuning indentation-numbers for each line in buffer that
contain tokens."
(if (boundp 'phps-mode-lexer-tokens)
(save-excursion
- (beginning-of-line)
- (let ((line-beginning (line-beginning-position))
- (line-end (line-end-position))
- (in-scripting nil)
+ (beginning-of-buffer)
+ (let ((in-scripting nil)
(in-heredoc nil)
(in-doc-comment nil)
(in-inline-control-structure nil)
(after-special-control-structure nil)
+ (after-special-control-structure-token nil)
+ (after-special-control-structure-first-on-line nil)
(after-extra-special-control-structure nil)
(curly-bracket-level 0)
(round-bracket-level 0)
@@ -67,7 +67,8 @@
(first-token-is-nesting-decrease nil)
(first-token-is-nesting-increase nil)
(token-number 1)
- (last-token-number (length phps-mode-lexer-tokens)))
+ (last-token-number (length phps-mode-lexer-tokens))
+ (last-token nil))
;; Iterate through all buffer tokens from beginning to end
(dolist (item phps-mode-lexer-tokens)
@@ -102,12 +103,19 @@
(setq tuning-level 1)
(setq tuning-level 0))
- (message "%s, %s, %s, %s = %s %s %s %s %s %s" token
column-level nesting-start nesting-end tuning-level round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
inline-control-structure-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)
;; Put indent-level to hash-table
(when (> last-line-number 0)
(puthash last-line-number `(,column-level ,tuning-level)
line-indents))
+ ;; Is line ending indentation equal to line beginning
indentation and did we have a change of scope?
+ (when (= nesting-end nesting-start)
+ (when first-token-is-nesting-decrease
+ (setq column-level (1+ column-level)))
+ (when first-token-is-nesting-increase
+ (setq column-level (1- column-level))))
+
;; Is line ending indentation higher than line beginning
indentation?
(when (> nesting-end nesting-start)
@@ -120,7 +128,8 @@
;; 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 first-token-is-nesting-decrease nil)
+ (setq last-token token))
(setq first-token-on-line nil))
;; Keep track of round bracket level
@@ -162,6 +171,7 @@
(equal token 'T_ENDFOREACH)
(equal token 'T_ENDSWITCH))
(setq alternative-control-structure-level (1-
alternative-control-structure-level))
+ (message "Found ending alternative token %s %s" token
alternative-control-structure-level)
(when first-token-on-line
(setq first-token-is-nesting-decrease t)))
@@ -178,13 +188,24 @@
;; Is it the start of an alternative control structure?
(if (string= token ":")
(progn
- (setq alternative-control-structure-level (1+
alternative-control-structure-level))
- (when first-token-on-line
- (setq first-token-is-nesting-increase t)))
- (setq inline-control-structure-level (1+
inline-control-structure-level))
- (when first-token-on-line
- (setq first-token-is-nesting-increase t))
- (setq in-inline-control-structure t)))
+ (if (or (equal after-special-control-structure-token
'T_ELSE)
+ (equal after-special-control-structure-token
'T_ELSEIF))
+ (progn
+ (when
after-special-control-structure-first-on-line
+ (setq first-token-is-nesting-decrease t)))
+ (setq alternative-control-structure-level (1+
alternative-control-structure-level))
+ (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
+ (when after-special-control-structure-first-on-line
+ (setq first-token-is-nesting-decrease t)))
+ (message "Was inline-control structure %s %s"
after-special-control-structure-token token)
+ (setq inline-control-structure-level (1+
inline-control-structure-level))
+ (when after-special-control-structure-first-on-line
+ (setq first-token-is-nesting-increase t))
+ (setq in-inline-control-structure t))))
(setq after-special-control-structure nil))
@@ -210,37 +231,34 @@
(equal token 'T_SWITCH)
(equal token 'T_ELSE)
(equal token 'T_ELSEIF))
- (setq after-special-control-structure round-bracket-level))
+ (setq after-special-control-structure-first-on-line
first-token-on-line)
+ (setq after-special-control-structure round-bracket-level)
+ (setq after-special-control-structure-token token))
;; Did we encounter a token that supports extra special
alternative control structures?
(when (or (equal token 'T_CASE)
(equal token 'T_DEFAULT))
(setq after-extra-special-control-structure t))
- ;; Does token end before current line begins?
- (when (< token-start line-beginning)
-
- ;; Keep track of in scripting
- (when (or (equal token 'T_OPEN_TAG)
- (equal token 'T_OPEN_TAG_WITH_ECHO))
- (setq in-scripting t))
- (when (equal token 'T_CLOSE_TAG)
- (setq in-scripting nil))
-
- ;; Keep track of whether we are inside a doc-comment
- (when (equal token 'T_DOC_COMMENT)
- (setq in-doc-comment token-end))
- (when (and in-doc-comment
- (> token-start in-doc-comment))
- (setq in-doc-comment nil))
-
- ;; Keep track of whether we are inside a HEREDOC or NOWDOC
- (when (equal token 'T_START_HEREDOC)
- (setq in-heredoc t))
- (when (equal token 'T_END_HEREDOC)
- (setq in-heredoc nil))
-
- )
+ ;; Keep track of in scripting
+ (when (or (equal token 'T_OPEN_TAG)
+ (equal token 'T_OPEN_TAG_WITH_ECHO))
+ (setq in-scripting t))
+ (when (equal token 'T_CLOSE_TAG)
+ (setq in-scripting nil))
+
+ ;; Keep track of whether we are inside a doc-comment
+ (when (equal token 'T_DOC_COMMENT)
+ (setq in-doc-comment token-end))
+ (when (and in-doc-comment
+ (> token-start in-doc-comment))
+ (setq in-doc-comment nil))
+
+ ;; Keep track of whether we are inside a HEREDOC or NOWDOC
+ (when (equal token 'T_START_HEREDOC)
+ (setq in-heredoc t))
+ (when (equal token 'T_END_HEREDOC)
+ (setq in-heredoc nil))
;; Are we on a new line?
(when (> token-line-number last-line-number)
@@ -248,9 +266,7 @@
;; Update last line number
(setq last-line-number token-line-number))
- )
-
- (setq token-number (1+ token-number)))
+ (setq token-number (1+ token-number))))
line-indents))
nil))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index d560ab8..f5f0536 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -56,6 +56,7 @@
(phps-mode-test-with-buffer
"<?php\nif (true):\n echo 'Something';\nelse:\n echo 'Something
else';\nendif;\necho true;\n"
"Alternative control structures"
+ ;; (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)) (7 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
- [elpa] externals/phps-mode e37c1cf 150/405: New indention calculation works with doc-comments, (continued)
- [elpa] externals/phps-mode e37c1cf 150/405: New indention calculation works with doc-comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f789468 172/405: Took notes of new indentation tests, Stefan Monnier, 2019/07/13
- [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 <=
- [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, 2019/07/13
- [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