[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8374026917 166/212: Improved indentation on l
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 8374026917 166/212: Improved indentation on lines starting with a closing square bracket |
Date: |
Wed, 26 Jan 2022 01:51:21 -0500 (EST) |
branch: externals/phps-mode
commit 8374026917298a90ee76a859d99fd972b072ebc7
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation on lines starting with a closing square bracket
---
phps-mode-indent.el | 122 +++++-----------------------------------------------
1 file changed, 11 insertions(+), 111 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index a93cbb7394..457c4693be 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -1115,8 +1115,8 @@
match-type
'line-that-ends-curly-bracket)
(let ((old-point (point))
- (end-of-switch-statement)
(still-looking t)
+ (bracket-start-line)
(curly-bracket-balance -1))
;; Should keep track of brackets
@@ -1138,121 +1138,21 @@
(setq
still-looking
nil)
- (let ((bracket-start-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
- (when (string-match-p
- "^[\t ]*switch[\t ]*("
- bracket-start-line)
- (setq
- end-of-switch-statement
- t)))))
+ (setq
+ bracket-start-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))))
(goto-char old-point)
- ;; TODO Should use reference line indentation instead of
decrementing
-
- ;; Ignore cases like
- ;; if (true) {
- ;; }
- ;; or
- ;; switch($var) {
- ;; }
- (unless previous-line-ends-with-opening-bracket
-
- ;; if (true) {
- ;; echo 'here';
- (setq
- new-indentation
- (- new-indentation tab-width))
-
- ;; switch($match) {
- ;; case 'here':
- ;; echo 'there';
- ;; }
- (when end-of-switch-statement
+ (unless still-looking
+ (let ((reference-indentation
+ (phps-mode-indent--string-indentation
+ bracket-start-line)))
(setq
new-indentation
- (- new-indentation tab-width)))
-
- ;; should indent double if previous
- ;; line ended a multi-line assignment:
- ;; if (true) {
- ;; $var =
- ;; 'abc';
- ;; }
- (when (and
- previous-line-ends-with-terminus
- (string= previous-line-ends-with-terminus ";")
- (not
- (string-match-p
- "^[\t ]*\\(echo[\t ]+\\|print[\t ]+\\)"
- previous-line-string)))
- ;; Back-trace buffer from previous line
- ;; Determine if semi-colon ended an multi-line
assignment or bracket-less command or not
- ;; If it's on the same line we ignore it
- (forward-line (* -1 move-length1))
- (end-of-line)
- (search-backward-regexp ";" nil t) ;; Skip the semi-colon
-
- (let ((not-found t)
- (is-assignment nil)
- (parenthesis-level 0)
- (is-same-line-p t)
- (is-object-chaining)
- (is-object-chaining-on-same-line))
- (while
- (and
- not-found
- (search-backward-regexp
- "\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9_]+'?\"?\\|->\\)"
- nil
- t))
- (let ((match (match-string-no-properties 0)))
- (cond
- ((string= match "\n")
- (setq is-same-line-p nil))
- ((string-match-p
- "<<<'?\"?[a-zA-Z0-9_]+'?\"?"
- match)
- (setq
- not-found
- nil))
- ((string= match "(")
- (setq
- parenthesis-level
- (1+ parenthesis-level)))
- ((string= match ")")
- (setq
- parenthesis-level
- (1- parenthesis-level)))
- ((string= match "->")
- (when (= parenthesis-level 0)
- (setq
- is-object-chaining
- t)
- (setq
- is-object-chaining-on-same-line
- is-same-line-p)))
- ((= parenthesis-level 0)
- (setq is-assignment (string= match "="))
- (setq not-found nil)))))
-
- (when (or
- (and
- (not is-same-line-p)
- is-assignment)
- (and
- (not is-object-chaining-on-same-line)
- is-object-chaining))
- (setq
- new-indentation
- (- new-indentation tab-width)))
-
- (goto-char point)))
-
- )))
+ reference-indentation)))))
;; LINE THAT ENDS ALTERNATIVE SWITCH BLOCK
;; switch (blala):
- [elpa] externals/phps-mode df91b8e433 117/212: More handling of string-doc indentation, (continued)
- [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, 2022/01/26
- [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 <=
- [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
- [elpa] externals/phps-mode 2a4d5dea37 019/212: Passed bookkeeping of function arguments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c29e35fea2 021/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0daaa97f8d 025/212: SDT for for() loop started, Christian Johansson, 2022/01/26