[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 6cb18913e4 152/212: Improved indentation for
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 6cb18913e4 152/212: Improved indentation for lines ending with closing bracket and comma |
Date: |
Wed, 26 Jan 2022 01:51:17 -0500 (EST) |
branch: externals/phps-mode
commit 6cb18913e4061783deea254a5c5a2e33a460bd9f
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation for lines ending with closing bracket and comma
---
phps-mode-indent.el | 111 ++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 95 insertions(+), 16 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index aafd7bc5e1..7415e78641 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -244,15 +244,15 @@
previous-indentation)
;; debug stuff
- (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)
- (message "previous-line-ends-with-terminus: %S"
previous-line-ends-with-terminus)
- (message "previous-bracket-level: %S" previous-bracket-level)
- (message "previous-indentation: %S" previous-indentation)
+ ;; (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)
+ ;; (message "previous-line-ends-with-terminus: %S"
previous-line-ends-with-terminus)
+ ;; (message "previous-bracket-level: %S" previous-bracket-level)
+ ;; (message "previous-indentation: %S" previous-indentation)
;; Case by case logic below - most specific to most general
@@ -757,7 +757,7 @@
new-indentation
(- new-indentation tab-width)))
-;; if (true) {
+ ;; if (true) {
;; $cacheKey = sprintf(
;; 'key_%s',
;; md5(json_encode($key))
@@ -1033,6 +1033,92 @@
new-indentation
(- new-indentation tab-width tab-width)))
+ ;; return array(
+ ;; '' => __(
+ ;; 'None',
+ ;; 'domain'
+ ;; ),
+ ;; '-' =>
+ ;; or
+ ;; return [
+ ;; [
+ ;; '25'
+ ;; ],
+ ;; 25
+ ((string-match-p
+ "[])][\t ]*,[\t ]*\\(\\?>[\t\n ]*\\)?$"
+ previous-line-string)
+
+ ;; Backtrack first to line were bracket started
+ ;; and use indentation from that line from that line
+ (forward-line (* -1 move-length1))
+ (end-of-line)
+ (search-backward-regexp "," nil t) ;; Skip trailing comma
+ (let ((not-found-bracket-start t)
+ (reference-line)
+ (parenthesis-level 1))
+ (while
+ (and
+ not-found-bracket-start
+ (search-backward-regexp
+ "\\()[][(),]\\|=>\\)"
+ nil
+ t))
+ (let ((match (match-string-no-properties 0)))
+ (cond
+
+ ((or
+ (string= "(" match)
+ (string= "[" match))
+ (setq
+ parenthesis-level
+ (1+ parenthesis-level))
+ (when (= parenthesis-level 0)
+ (setq
+ not-found-bracket-start
+ nil)))
+
+ ((or
+ (string= ")" match)
+ (string= "]" match))
+ (setq
+ parenthesis-level
+ (1- parenthesis-level))
+ (when (= parenthesis-level 0)
+ (setq
+ not-found-bracket-start
+ nil)))
+
+ (t
+ (when (= parenthesis-level 1)
+ (setq
+ not-found-bracket-start
+ nil)))
+
+ )))
+
+ ;; Found line were bracket started?
+ (unless not-found-bracket-start
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))
+
+ (when reference-line
+ ;; (message "reference-line-2: %S" reference-line)
+ (setq
+ new-indentation
+ (phps-mode-indent--string-indentation
+ reference-line)))
+
+ (when current-line-starts-with-closing-bracket
+ (setq
+ new-indentation
+ (- new-indentation tab-width))))
+
+ (goto-char point))
+
;; 'name' =>
;; $myObject->getName(),
;; 'age' =>
@@ -1045,13 +1131,6 @@
;; [
;; 2,
;; 3,
- ;; or TODO
- ;; return array(
- ;; '' => __(
- ;; 'None',
- ;; 'domain'
- ;; ),
- ;; '-' =>
((and
previous-line-ends-with-terminus
(string= previous-line-ends-with-terminus ","))
- [elpa] externals/phps-mode 395a4ed045 036/212: Started on bookkeeping via parser SDT for properties, (continued)
- [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, 2022/01/26
- [elpa] externals/phps-mode 6cb18913e4 152/212: Improved indentation for lines ending with closing bracket and comma,
Christian Johansson <=
- [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
- [elpa] externals/phps-mode c65d433a73 138/212: Improved indentation around multi-line function-calls, Christian Johansson, 2022/01/26