[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8c1f529f87 145/212: Passing indent for line a
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 8c1f529f87 145/212: Passing indent for line after ending of statement / expression with trailing closing bracket |
Date: |
Wed, 26 Jan 2022 01:51:16 -0500 (EST) |
branch: externals/phps-mode
commit 8c1f529f87505300315f201550aa8ada77d719c0
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing indent for line after ending of statement / expression with
trailing closing bracket
---
phps-mode-indent.el | 113 +++++++++++++++++++++++++++++++++++++++---
test/phps-mode-test-indent.el | 2 +-
2 files changed, 106 insertions(+), 9 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index e5db7504cf..84c4574e39 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -243,6 +243,7 @@
new-indentation
previous-indentation)
+ ;; debug stuff
;; (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)
@@ -1059,6 +1060,110 @@
))
+ ;; 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';
@@ -1088,14 +1193,6 @@
;; or
;; define('_PRIVATE_ROOT_',
;; 'here');
-
- ;; TODO Handle cases like
- ;; if (true) {
- ;; $cacheKey = sprintf(
- ;; 'key_%s',
- ;; md5(json_encode($key))
- ;; );
- ;; $cache =
((and
previous-line-ends-with-terminus
(string= previous-line-ends-with-terminus ";")
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index e3ab3b1e81..c12b9166b7 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -329,7 +329,7 @@
"Comment after assignment from method call on same line")
(phps-mode-test-indent--should-equal
- "<?php\nif (true) {\n // My comment\n $cacheKey = sprintf(\n
'key_%s',\n md5(json_encode($key))\n );\n $cache =\n
Cache::getInstance();\n"
+ "<?php\nif (true) {\n // My comment\n $cacheKey = sprintf(\n
'key_%s',\n md5(json_encode($key))\n );\n $cache =\n
Cache::getInstance();\n "
"Line after assignment from multi-line function-call")
)
- [elpa] externals/phps-mode daff4ad5e0 085/212: More work on indentation, (continued)
- [elpa] externals/phps-mode daff4ad5e0 085/212: More work on indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b82475c697 090/212: Passed token-blind indentation for multi-line class extends and implements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2ea2360c3e 091/212: Created indent helper functions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode df91b8e433 117/212: More handling of string-doc indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6fac0d5585 102/212: Passed indent test for heredoc string, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1af63142f3 127/212: Fixed incremental issue with new SDT based bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3565c7efb3 125/212: Fixed byte-compilation warnings for indent file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a8097b5b5e 147/212: Improved indentation on line after equal operator in if condition list, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode dece7f242e 160/212: Added more failing indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a530988fe0 134/212: Added more failing indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8c1f529f87 145/212: Passing indent for line after ending of statement / expression with trailing closing bracket,
Christian Johansson <=
- [elpa] externals/phps-mode d7aa22d251 146/212: Added two new failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c453932f32 139/212: Added TODO item, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8374026917 166/212: Improved indentation on lines starting with a closing square bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2afb7dc87a 002/212: Generating basic imenu-index via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 41b1566c40 010/212: Imenu generation via parser SDT passing more tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8f9870fb9b 013/212: Parser SDT does not use global variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4753734b0a 006/212: Moved syntax coloring to separate file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d037aa09bc 023/212: Added bookkeeping via parser SDT foreach ($x as $y) {}, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3d54b6ff01 022/212: Passed another test for bookkeeping generated via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 442ad93cb2 018/212: Fix for function parameter formatting in AST, Christian Johansson, 2022/01/26