emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode b9956e278f 120/212: Indent support for closin


From: Christian Johansson
Subject: [elpa] externals/phps-mode b9956e278f 120/212: Indent support for closing bracket after closing multi-line assignment
Date: Wed, 26 Jan 2022 01:51:12 -0500 (EST)

branch: externals/phps-mode
commit b9956e278f4550da83b9aadff7fa90d8e43b4ae4
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Indent support for closing bracket after closing multi-line assignment
---
 phps-mode-indent.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 99e0358407..c669fc399c 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -721,6 +721,73 @@
                       ;;     $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)
+                        (forward-char -1)
+
+                        (let ((not-found t)
+                              (is-assignment nil)
+                              (is-string-doc)
+                              (parenthesis-level 0)
+                              (is-bracket-less-command nil)
+                              (is-same-line-p t)
+                              (bracket-opened-on-first-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
+                                 is-string-doc
+                                 t)
+                                (setq
+                                 not-found
+                                 nil))
+                               ((string= match "(")
+                                (setq
+                                 parenthesis-level
+                                 (1+ parenthesis-level)))
+                               ((string= match ")")
+                                (setq
+                                 parenthesis-level
+                                 (1- parenthesis-level)))
+                               ((= parenthesis-level 0)
+                                (setq is-assignment (string= match "="))
+                                (setq is-bracket-less-command
+                                      (string-match-p
+                                       "\\(echo[\t ]+\\|print[\t ]+\\)"
+                                       match))
+                                (setq not-found nil)))))
+
+                          (when (and
+                                 (not is-same-line-p)
+                                 (and
+                                  is-assignment
+                                  (not bracket-opened-on-first-line)))
+                            (setq
+                             new-indentation
+                             (- new-indentation tab-width)))
+
+                          (goto-char point)))
 
                       ))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]