[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 28a5302e08 148/212: Passing indentation on li
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 28a5302e08 148/212: Passing indentation on line after closing bracket and command and were current line starts with closing bracket |
Date: |
Wed, 26 Jan 2022 01:51:17 -0500 (EST) |
branch: externals/phps-mode
commit 28a5302e083145d9954cabc6f53e7428a74a56e0
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing indentation on line after closing bracket and command and were
current line starts with closing bracket
---
phps-mode-indent.el | 220 +++++++++++++++++++++++++++-------------------------
1 file changed, 115 insertions(+), 105 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index e01934da15..f65b7bfb48 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -751,6 +751,121 @@
new-indentation
(- new-indentation tab-width)))
+;; if (true) {
+ ;; $cacheKey = sprintf(
+ ;; 'key_%s',
+ ;; md5(json_encode($key))
+ ;; );
+ ;; $cache =
+ ;; or
+ ;; if (true) {
+ ;; $cache =
+ ;; Cache::getInstance();
+ ;; echo 'here';
+ ((string-match-p
+ "[])][\t ]*;[\t ]*\\(\\?>[\t\n ]*\\)?$"
+ previous-line-string)
+
+ ;; Backtrack first to line were bracket started
+ ;; and then backwards until the line were statement /
expression
+ ;; 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 0))
+ (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)))
+
+ )))
+
+ ;; Found line were bracket started?
+ (unless not-found-bracket-start
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+ ;; (message "reference-line-1: %S" reference-line)
+
+ ;; Search for first line of statement / expression here
+ (let ((not-found-command-start t))
+ (while
+ (and
+ not-found-command-start
+ (search-backward-regexp
+ "\\(;\\|}\\|{\\|[\t ]*[^\t ]+[\t ]*$\\)"
+ nil
+ t))
+ (let ((match (match-string-no-properties 0)))
+ (cond
+
+ ;; End of expression / statement
+ ((or
+ (string= ";" match)
+ (string= "}" match)
+ (string= "{" match))
+ (setq
+ not-found-command-start
+ nil))
+
+ ;; Non-empty line
+ (t
+ (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
+ (and
+ current-line-starts-with-closing-bracket
+ (string= current-line-starts-with-closing-bracket "}"))
+ (setq
+ new-indentation
+ (- new-indentation tab-width))))
+
+ (goto-char point))
+
;; switch ($condition) {
;; case true:
;; echo 'here';
@@ -1070,111 +1185,6 @@
))
- ;; if (true) {
- ;; $cacheKey = sprintf(
- ;; 'key_%s',
- ;; md5(json_encode($key))
- ;; );
- ;; $cache =
- ;; or
- ;; if (true) {
- ;; $cache =
- ;; Cache::getInstance();
- ;; echo 'here';
- ((string-match-p
- "[])][\t ]*;[\t ]*\\(\\?>[\t\n ]*\\)?$"
- previous-line-string)
-
- ;; Backtrack first to line were bracket started
- ;; and then backwards until the line were statement /
expression
- ;; 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 0))
- (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)))
-
- )))
-
- ;; Found line were bracket started?
- (unless not-found-bracket-start
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
-
- ;; Search for first line of statement / expression here
- (let ((not-found-command-start t))
- (while
- (and
- not-found-command-start
- (search-backward-regexp
- "\\(;\\|}\\|{\\|[\t ]*[^\t ]+[\t ]*$\\)"
- nil
- t))
- (let ((match (match-string-no-properties 0)))
- (cond
-
- ;; End of expression / statement
- ((or
- (string= ";" match)
- (string= "}" match)
- (string= "{" match))
- (setq
- not-found-command-start
- nil))
-
- ;; Non-empty line
- (t
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
-
- )))))
-
- (when reference-line
- (setq
- new-indentation
- (phps-mode-indent--string-indentation
- reference-line))))
-
- (goto-char point))
-
;; $var .=
;; 'hello';
;; echo 'here';
- [elpa] externals/phps-mode 40ce934c11 116/212: Indent support for string-doc in assignment, (continued)
- [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, 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 <=
- [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
- [elpa] externals/phps-mode f537965850 168/212: Improved indentation on lines after lines that ends with semicolon, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6d8544d7fa 171/212: Added two more failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 616e3dc7ea 172/212: Added a TODO file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d74686e07c 180/212: Started on optimizing lexer, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 06b35e4bf1 183/212: Fixed TODO item in this branch, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 40ecf58372 189/212: Adjustments for indent helper function determining last index line, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode edba476df8 191/212: Byte compilation fixes for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 580298c395 201/212: Improved indentation of multi-line concatenated strings containing brackets, Christian Johansson, 2022/01/26