[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of htt
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode |
Date: |
Sat, 13 Jul 2019 10:00:15 -0400 (EDT) |
branch: externals/phps-mode
commit 9031c3a86d989a5abe8edafd560341f320ca3fa0
Merge: 208a788 cf7dc07
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode
---
docs/indentation-algorithm.md | 15 +++++++++++++++
phps-mode-functions.el | 29 +++++++++++++++++++----------
phps-mode-test-functions.el | 11 +++++++++--
3 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/docs/indentation-algorithm.md b/docs/indentation-algorithm.md
index 42667c7..9d41b0c 100644
--- a/docs/indentation-algorithm.md
+++ b/docs/indentation-algorithm.md
@@ -18,6 +18,14 @@ Here follows pseudo-code for a algorithm that calculates
indentation for each li
```php
foreach token in buffer:
+ if token = T_START_HEREDOC:
+ in-heredoc = true;
+ in-heredoc-started-this-line = true;
+ elseif token == T_END_HEREDOC:
+ in-heredoc = false;
+ in-heredoc-ended-this-line = true;
+ endif;
+
calculate nesting-end;
if nesting-stack AND nesting-end <= nesting-stack-start: // #decrease
@@ -43,6 +51,10 @@ foreach token in buffer:
indent-start = temp-pre-indent;
endif;
+ if (in-heredoc AND !in-heredoc-started-this-line) OR
in-heredoc-ended-this-line:
+ indent-start = 0;
+ endif;
+
save line indent-start; // #save
if temp-post-indent: #temp-post-indent
@@ -57,6 +69,9 @@ foreach token in buffer:
push (nesting-stack-end nesting-end) to stack;
indent++;
endif;
+
+ in-heredoc-started-this-line = false;
+ in-heredoc-ended-this-line = false;
endif;
endforeach;
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 2f9974c..64545f0 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -52,6 +52,8 @@
(message "\nCalculation indentation for all lines in buffer:\n\n%s"
(buffer-substring-no-properties (point-min) (point-max))))
(let ((in-scripting nil)
(in-heredoc nil)
+ (in-heredoc-started-this-line nil)
+ (in-heredoc-ended-this-line nil)
(in-inline-control-structure nil)
(after-special-control-structure nil)
(after-special-control-structure-token nil)
@@ -312,8 +314,7 @@
(progn
(setq in-assignment nil)
(setq in-assignment-level 0))
- (when (and first-token-on-line
- (not in-heredoc))
+ (when first-token-on-line
(setq in-assignment-level 1)
;; (message "In assignment on new-line at %s" token)
))
@@ -329,12 +330,6 @@
(setq after-extra-special-control-structure t)
(setq after-extra-special-control-structure-first-on-line
first-token-on-line))
- ;; 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))
-
)
(when token
@@ -342,6 +337,14 @@
;; Calculate nesting
(setq nesting-end (+ round-bracket-level square-bracket-level
curly-bracket-level alternative-control-structure-level in-assignment-level
in-class-declaration-level))
+ ;; Keep track of whether we are inside a HEREDOC or NOWDOC
+ (when (equal token 'T_START_HEREDOC)
+ (setq in-heredoc t)
+ (setq in-heredoc-started-this-line t))
+ (when (equal token 'T_END_HEREDOC)
+ (setq in-heredoc nil)
+ (setq in-heredoc-ended-this-line t))
+
;; Has nesting increased?
(when (and nesting-stack
(<= nesting-end (car (car nesting-stack))))
@@ -397,6 +400,11 @@
(setq temp-pre-indent nil))
+ ;; HEREDOC lines should have zero indent
+ (when (or (and in-heredoc
+ (not in-heredoc-started-this-line))
+ in-heredoc-ended-this-line)
+ (setq column-level-start 0))
;; Save line indent
@@ -422,7 +430,7 @@
(let ((token-line-number-diff (1- (-
token-end-line-number token-start-line-number))))
(while (>= token-line-number-diff 0)
- (puthash (- token-end-line-number
token-line-number-diff) `(,column-level ,tuning-level) line-indents)
+ (puthash (- token-end-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))))
@@ -434,7 +442,7 @@
(setq column-level temp-post-indent)
(setq temp-post-indent nil))
- ;; Decrease indentation
+ ;; Increase indentation
(when (and (> nesting-end 0)
(or (not nesting-stack)
(> nesting-end (car (cdr (car
nesting-stack))))))
@@ -482,6 +490,7 @@
(setq in-assignment-started-this-line nil)
(setq changed-nesting-stack-in-line nil)
(setq class-declaration-started-this-line nil)
+ (setq in-heredoc-started-this-line nil)
(setq special-control-structure-started-this-line
nil)))
;; Current token is not first
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 25fb65a..9cf29e5 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -57,6 +57,13 @@
"Round and square bracket expressions"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (2 0)) (6 (1
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+ (phps-mode-test-with-buffer
+ "<?php\nvar_dump(array(<<<EOD\nfoobar!\nEOD\n));\n?>"
+ "HEREDOC in arguments example"
+ ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 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\n$str = <<<'EOD'\nExample of string\nspanning multiple lines\nusing
nowdoc syntax.\nEOD;\n"
"Multi-line NOWDOC string"
@@ -67,13 +74,13 @@
"<?php\n$var = \"A line\nmore text here\nlast line here\";"
"Multi-line double-quoted string"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+ (should (equal '((1 (0 0)) (2 (1 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\n$var = 'A line\nmore text here\nlast line here';"
"Multi-line single-quoted string"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+ (should (equal '((1 (0 0)) (2 (1 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\necho \"A line\" .\n \"more text here\" .\n \"last line
here\";"
- [elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line, (continued)
- [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
- [elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm handles class declaration indents, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting-stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode cf7dc07 210/405: Preparations for multi-line quoted indentation tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 208a788 208/405: Re-organized indent tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c678fc1 209/405: New algorithm handles HEREDOC indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b6cf3a4 191/405: Started on new algorithm for indentation calculation based on stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a4b98e 215/405: More work on algorithm description, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode,
Stefan Monnier <=
- [elpa] externals/phps-mode 6105e5d 226/405: Added a new failing test for indetation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5f445cd 229/405: Fixed indentation for while expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode eb0ee5e 236/405: Updated README with imenu-support, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d2e5a03 228/405: Updated indentation algorithm document and README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1aa0f90 238/405: Typo in README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode da1cfd5 231/405: Adding failing lexer test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug with expressions inside double quoted strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0c49d6d 243/405: Removed debugging output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 95ac15a 245/405: Imenu index now handles class extends and implements, Stefan Monnier, 2019/07/13