[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode fbe600500f 135/212: More work on array and ar
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode fbe600500f 135/212: More work on array and argument element indentation |
Date: |
Wed, 26 Jan 2022 01:51:13 -0500 (EST) |
branch: externals/phps-mode
commit fbe600500fbd24d7dac005a77e2b52c7eb96ca2c
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on array and argument element indentation
---
phps-mode-indent.el | 170 ++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 153 insertions(+), 17 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 4dc2044eb4..2ba093ba46 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -240,8 +240,8 @@
new-indentation
previous-indentation)
- ;; (message "\ncurrent-line-string: %S" current-line-string)
- ;; (message "previous-line-string: %S" previous-line-string)
+ (message "\ncurrent-line-string: %S" current-line-string)
+ (message "previous-line-string: %S" previous-line-string)
;; (message "current-line-starts-with-closing-bracket: %S"
current-line-starts-with-closing-bracket)
;; (message "current-line-starts-with-opening-bracket: %S"
current-line-starts-with-opening-bracket)
;; (message "previous-line-ends-with-opening-bracket: %S"
previous-line-ends-with-opening-bracket)
@@ -828,6 +828,149 @@
new-indentation
(- new-indentation tab-width tab-width)))
+ ;; TODO Fix this
+ ;; 'name' =>
+ ;; $myObject->getName(),
+ ;; 'age' =>
+ ;; or
+ ;; myFunction(
+ ;; 'my Argument',
+ ;; 'my second argument'
+ ;; or
+ ;; myFunction(
+ ;; [
+ ;; 2,
+ ;; 3,
+ ((and
+ previous-line-ends-with-terminus
+ (string= previous-line-ends-with-terminus ","))
+
+ ;; Back-trace buffer from previous line
+ ;; Determine if comma was part of array or function argument
or bracket-less command
+ ;; If it started on the same line we ignore it
+ (forward-line (* -1 move-length1))
+ (end-of-line)
+ (forward-char -1)
+
+ (let ((not-found t)
+ (reference-line)
+ (reference-indentation)
+ (is-array)
+ (is-function)
+ (is-bracket-less-command)
+ (parenthesis-level 0)
+ (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\\)"
+ nil
+ t))
+ (let ((match (match-string-no-properties 0)))
+ (cond
+
+ ((string= match "\n")
+ (setq
+ is-same-line-p
+ nil))
+
+ ((string-match-p
+ "[a-zA-Z]+[a-zA-Z0-9]*[\t ]*("
+ match)
+ (setq
+ parenthesis-level
+ (1+ parenthesis-level))
+ (if (string-match-p
+ "^array[\t ]*("
+ match)
+ (setq
+ is-array
+ t)
+ (setq
+ is-function
+ t))
+ (setq
+ not-found
+ nil))
+
+ ((string= match "[")
+ (setq
+ parenthesis-level
+ (1+ parenthesis-level))
+ (when (= parenthesis-level 1)
+ (setq
+ is-array
+ t)
+ (setq
+ not-found
+ nil)))
+
+ ((string= match "(")
+ (setq
+ parenthesis-level
+ (1+ parenthesis-level)))
+
+ ((or
+ (string= match ")")
+ (string= match "]"))
+ (setq
+ parenthesis-level
+ (1- parenthesis-level)))
+
+ ((= parenthesis-level 0)
+ (when (string-match-p "=>" match)
+ (setq
+ is-array
+ t))
+ (setq
+ is-bracket-less-command
+ (string-match-p
+ "echo[\t ]+"
+ match))
+ (setq
+ not-found
+ nil)))))
+
+ (unless not-found
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+ (setq
+ reference-indentation
+ (phps-mode-indent--string-indentation
+ reference-line)))
+
+ (message "is-array: %S" is-array)
+ (message "is-function: %S" is-function)
+ (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))
+ (setq
+ new-indentation
+ reference-indentation))
+
+ ;; myFunction(
+ ;; 'arg',
+ ;; );
+ (when current-line-starts-with-closing-bracket
+ (setq
+ new-indentation
+ (- new-indentation tab-width)))
+
+ (goto-char point)
+
+
+ ))
+
+
;; $var .=
;; 'hello';
;; echo 'here';
@@ -853,12 +996,9 @@
;; return myFunction(
;; 'expression');
;; echo 'here';
- ;; or
- ;; 'name' =>
- ;; $myObject->getName(),
- ;; 'age' =>
((and
previous-line-ends-with-terminus
+ (string= previous-line-ends-with-terminus ";")
(not
(string-match-p
"^[\t ]*\\(echo[\t ]+\\|print[\t ]+\\)"
@@ -882,7 +1022,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)))
@@ -984,14 +1124,6 @@
new-indentation
(- new-indentation tab-width)))
- (when (and
- current-line-starts-with-closing-bracket
- (not previous-line-ends-with-opening-bracket)
- (>= previous-indentation tab-width))
- (setq
- new-indentation
- (- new-indentation tab-width)))
-
)
(goto-char point))
@@ -1164,8 +1296,7 @@
;; ));
((and
current-line-starts-with-closing-bracket
- (not previous-line-ends-with-opening-bracket)
- (>= previous-indentation tab-width))
+ (not previous-line-ends-with-opening-bracket))
(setq
new-indentation
(- new-indentation tab-width)))
@@ -1206,6 +1337,11 @@
;; (message "new-indentation: %S" new-indentation)
+ (when (< new-indentation 0)
+ (setq
+ new-indentation
+ 0))
+
(indent-line-to new-indentation)))))
;; Only move to end of line if point is the current point and is at end
of line
(when (equal point (point))
- [elpa] externals/phps-mode b3b27951bd 015/212: More work on bookkeeping, (continued)
- [elpa] externals/phps-mode b3b27951bd 015/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 395a4ed045 036/212: Started on bookkeeping via parser SDT for properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 69341c9709 039/212: More working on bookkeeping of class properties via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cefab36fa8 054/212: More work on bookkeeping arrow function variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9cbe630b3 068/212: Passing bookkeeping of variables inside echo statements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0919855a31 073/212: Added SDT for concat operation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5df554fc47 070/212: Bookkeeping via AST properly handles $this reference in only non-static methods, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2432928a86 096/212: Indentation passing more tests for alternative control structures, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cef879268b 103/212: Added two new tests for failing indentation for multi-line concatenated strings, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 40ce934c11 116/212: Indent support for string-doc in assignment, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fbe600500f 135/212: More work on array and argument element indentation,
Christian Johansson <=
- [elpa] externals/phps-mode 6cb18913e4 152/212: Improved indentation for lines ending with closing bracket and comma, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 26d7b64086 144/212: Added TODO item for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0e7eb04800 149/212: Passing indentation test for multiple function arguments with default values, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on line after closing bracket and comma, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1825ee499b 151/212: More wrestling with indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 29fee20e43 141/212: Passed all tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6a49784b8b 161/212: When indentation search previous code lines it skips commented out lines, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5432a61340 162/212: Improved indentation around closing of multi-dimensional brackets, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 28a5302e08 148/212: Passing indentation on line after closing bracket and command and were current line starts with closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode be61c94dc3 165/212: Added TODO item, Christian Johansson, 2022/01/26