[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode d072fe5315 136/212: Improved indentation arou
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode d072fe5315 136/212: Improved indentation around array elements |
Date: |
Wed, 26 Jan 2022 01:51:13 -0500 (EST) |
branch: externals/phps-mode
commit d072fe53159ae875364e00d6a11c3f7c968d1f9c
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation around array elements
---
phps-mode-indent.el | 102 ++++++++++++++++++++++++++++++------------
test/phps-mode-test-indent.el | 8 ++++
2 files changed, 81 insertions(+), 29 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 2ba093ba46..190bb38450 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -299,7 +299,7 @@
current-line-starts-with-opening-bracket
(string= current-line-starts-with-opening-bracket "{")
(phps-mode-indent--backwards-looking-at
- "[\r\t ]*implements[\r\t ]+\\([\r\t
]*[\\a-zA-Z_0-9]+,?\\)+[\r\t ]*{$")
+ "[\r\t ]*implements[\r\t ]+\\([\r\t
]*[\\a-zA-Z_0-9_]+,?\\)+[\r\t ]*{$")
(not
(string-match-p
"[\t ]*\\(class\\|interface\\)[\t ]+"
@@ -343,7 +343,7 @@
;; echo <<<"VAR"
;; abc
((string-match-p
- "<<<'?\"?[a-zA-Z0-9]+'?\"?$"
+ "<<<'?\"?[a-zA-Z0-9_]+'?\"?$"
previous-line-string)
(setq
new-indentation
@@ -353,7 +353,7 @@
;; 'something';
((and
(string-match-p
- "^[\t ]*$[a-zA-Z0-9]+[\t ]*="
+ "^[\t ]*$[a-zA-Z0-9_]+[\t ]*="
previous-line-string)
(not
(string-match-p
@@ -764,7 +764,7 @@
(and
not-found
(search-backward-regexp
- "\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\|->\\)"
+ "\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9_]+'?\"?\\|->\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -772,7 +772,7 @@
((string= match "\n")
(setq is-same-line-p nil))
((string-match-p
- "<<<'?\"?[a-zA-Z0-9]+'?\"?"
+ "<<<'?\"?[a-zA-Z0-9_]+'?\"?"
match)
(setq
not-found
@@ -852,6 +852,12 @@
(end-of-line)
(forward-char -1)
+ (message
+ "at-line-start: %S"
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+
(let ((not-found t)
(reference-line)
(reference-indentation)
@@ -859,13 +865,14 @@
(is-function)
(is-bracket-less-command)
(parenthesis-level 0)
+ (is-declared-on-same-line-p)
(is-same-line-p t)
(bracket-opened-on-first-line))
(while
(and
not-found
(search-backward-regexp
- "\\([a-zA-Z]+[a-zA-Z0-9]*[\t
]*(\\|=>\\|,\\|[\]([]\\|\n\\)"
+ "\\([a-zA-Z_]+[a-zA-Z0-9_]*[\t
]*(\\|=>\\|,\\|[\])[]\\|\n\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -877,23 +884,27 @@
nil))
((string-match-p
- "[a-zA-Z]+[a-zA-Z0-9]*[\t ]*("
+ "[a-zA-Z_]+[a-zA-Z0-9_]*[\t ]*("
match)
(setq
parenthesis-level
(1+ parenthesis-level))
- (if (string-match-p
- "^array[\t ]*("
- match)
+ (when (= parenthesis-level 1)
+ (if (string-match-p
+ "^array[\t ]*("
+ match)
+ (setq
+ is-array
+ t)
(setq
- is-array
- t)
+ is-function
+ t))
(setq
- is-function
- t))
- (setq
- not-found
- nil))
+ is-declared-on-same-line-p
+ is-same-line-p)
+ (setq
+ not-found
+ nil)))
((string= match "[")
(setq
@@ -903,15 +914,13 @@
(setq
is-array
t)
+ (setq
+ is-declared-on-same-line-p
+ is-same-line-p)
(setq
not-found
nil)))
- ((string= match "(")
- (setq
- parenthesis-level
- (1+ parenthesis-level)))
-
((or
(string= match ")")
(string= match "]"))
@@ -939,6 +948,22 @@
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
+
+ ;; sprintf(__(
+ ;; 'Error %s', <-- use this indentation as reference
instead
+ ;; $error
+ (when (and
+ (not is-same-line-p)
+ (string-match-p
+ "[[(][\t ]*$"
+ reference-line))
+ (forward-line 1)
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))
+
(setq
reference-indentation
(phps-mode-indent--string-indentation
@@ -949,10 +974,14 @@
(message "not-found: %S" not-found)
(message "reference-line: %S" reference-line)
(message "reference-indentation: %S" reference-indentation)
-
- (when (and
- reference-indentation
- (not current-line-starts-with-closing-bracket))
+ (message
+ "at-line-end: %S"
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+ (message "is-declared-on-same-line-p: %S"
is-declared-on-same-line-p)
+
+ (when reference-indentation
(setq
new-indentation
reference-indentation))
@@ -960,13 +989,28 @@
;; myFunction(
;; 'arg',
;; );
+ ;; or
+ ;; 'weight' =>
+ ;; 1.2,
+ ;; ]);
(when current-line-starts-with-closing-bracket
(setq
new-indentation
(- new-indentation tab-width)))
- (goto-char point)
+ ;; define('_PRIVATE_ROOT',
+ ;; 'here');
+ ;; or
+ ;; ['abc',
+ ;; 'def'];
+ (when (and
+ (not current-line-starts-with-closing-bracket)
+ is-declared-on-same-line-p)
+ (setq
+ new-indentation
+ (+ new-indentation tab-width)))
+ (goto-char point)
))
@@ -1022,7 +1066,7 @@
(and
not-found
(search-backward-regexp
- "\\(;\\|{\\|(\\|)\\|=$\\|=[^>]\\|return\\|echo[\t
]+\\|print[\t ]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\)"
+ "\\(;\\|{\\|(\\|)\\|=$\\|=[^>]\\|return\\|echo[\t
]+\\|print[\t ]+\\|\n\\|<<<'?\"?[a-zA-Z0-9_]+'?\"?\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -1030,7 +1074,7 @@
((string= match "\n")
(setq is-same-line-p nil))
((string-match-p
- "<<<'?\"?[a-zA-Z0-9]+'?\"?"
+ "<<<'?\"?[a-zA-Z0-9_]+'?\"?"
match)
(setq
is-string-doc
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index e7974399b4..ed7c8d3e9f 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -276,6 +276,14 @@
"<?php\n$var = [\n 1,\n 2,\n 3\n];\n"
"Square bracket array definition in assignment")
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = [\n 1,\n [\n 2,\n [\n 3,\n
4\n ]\n ],\n [\n 5,\n 6,\n ],\n
7,\n];\n"
+ "Multi-dimensional square bracket array definition in assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = array(\n 1,\n array(\n 2,\n array(\n
3,\n 4\n )\n ),\n array(\n 5,\n
6,\n ),\n 7,\n);\n"
+ "Multi-dimensional round bracket array definition in assignment")
+
(phps-mode-test-indent--should-equal
"<?php\n/** @define string _PRIVATE_ROOT_ Absolute root to
private */\ndefine('_PRIVATE_ROOT_',\n
dirname($parameters[self::PARAMETER_SITE_PATH]) . DIRECTORY_SEPARATOR);\n"
"Mutiline define statement")
- [elpa] externals/phps-mode a9d0e941df 066/212: Started on SDT for static variables statement, (continued)
- [elpa] externals/phps-mode a9d0e941df 066/212: Started on SDT for static variables statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a8fecdfd68 055/212: Bookkeeping of variables inside arrow functions now working, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e42646dc3a 058/212: Added SDT for isset() and empty(), Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 9ad46d061e 057/212: Bookkeeping via AST passing two more tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 806bb902b3 122/212: Improved indentation for chaining objects, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cc3bf03786 123/212: Improved indentation after ending assignment expression, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3162dca5c4 159/212: Added two more failing indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1e44021653 163/212: Added more failing indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e7aff3f69d 157/212: Passed more indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode db7121941c 156/212: Passing indention on line after not equals condition, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d072fe5315 136/212: Improved indentation around array elements,
Christian Johansson <=
- [elpa] externals/phps-mode f880ba2d62 164/212: Improved indentation on lines after assignment that ends with closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode db019887af 170/212: Passed new indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 781356557c 194/212: More adjustments to indent helper to find previous command, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0735959c08 209/212: Using silent cache write, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e3bf9e8fed 059/212: SDT rules for some more infix operations, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2bc31a0f83 065/212: Added TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d802a669c0 061/212: Bookkeeping via AST working with isset() and !empty() scoped variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9115ec583 069/212: Cleaned up AST bookkeeping tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f4d2164f8b 067/212: Bookkeeping via parser SDT passing static variables in function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, Christian Johansson, 2022/01/26