[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for m
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for multi-line class implements |
Date: |
Wed, 26 Jan 2022 01:50:58 -0500 (EST) |
branch: externals/phps-mode
commit b469f0ffbbdb62bfc996f50a89775aa7f2d77c46
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing indentation for multi-line class implements
---
phps-mode-indent.el | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 18792d2411..d5baa6d4f9 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -16,6 +16,19 @@
(length (substring string (match-beginning 0) (match-end 0)))
0))
+(defun phps-mode-indent--backwards-looking-at-p (regexp)
+ "Non-nil if point is backwards looking at REGEXP."
+ (let ((point (point))
+ (limit 100))
+ (when (< point limit)
+ (setq limit (1- point)))
+ (let* ((start (- point limit))
+ (backward-string
+ (buffer-substring-no-properties
+ start
+ (1+ point))))
+ (string-match-p regexp backward-string))))
+
(defun phps-mode-indent-line (&optional initial-point)
"Apply alternative indentation at INITIAL-POINT here."
(let ((point))
@@ -43,7 +56,7 @@
(line-beginning-position)
(line-end-position)))
- (message "Current line: %S" current-line-string)
+ (message "\nCurrent line: %S" current-line-string)
;; Try to find previous non-empty line
(while (and
@@ -66,6 +79,7 @@
(indent-line-to 0)
(let* ((old-indentation (phps-mode-indent--string-indentation
line-string))
(current-line-starts-with-closing-bracket
(phps-mode-indent--string-starts-with-closing-bracket-p current-line-string))
+ (current-line-starts-with-opening-bracket
(phps-mode-indent--string-starts-with-opening-bracket current-line-string))
(line-starts-with-closing-bracket
(phps-mode-indent--string-starts-with-closing-bracket-p line-string))
(line-starts-with-opening-doc-comment
(phps-mode-indent--string-starts-with-opening-doc-comment-p line-string))
(line-ends-with-assignment
(phps-mode-indent--string-ends-with-assignment-p line-string))
@@ -93,6 +107,13 @@
line-starts-with-closing-bracket)
(setq new-indentation (+ new-indentation tab-width)))
+ (when (and
+ current-line-starts-with-opening-bracket
+ (string= current-line-starts-with-opening-bracket "{")
+ (phps-mode-indent--backwards-looking-at-p
+ "[\t ]*implements[\n\t ]+\\([\n\t
]*[a-zA-Z_0-9]+,?\\)+[\n\t ]*{$"))
+ (setq new-indentation (- new-indentation tab-width)))
+
(when current-line-starts-with-closing-bracket
(setq new-indentation (- new-indentation tab-width)))
@@ -109,9 +130,12 @@
(< bracket-level 0))
(setq new-indentation (+ new-indentation tab-width)))
- (when line-ends-with-terminus
+ (when (and
+ line-ends-with-terminus
+ (not (string-match-p "^[\t ]*\\(echo[\t ]+\\|print[\t
]+\\)" line-string)))
;; Back-trace buffer from previous line
- ;; Determine if semi-colon ended an assignment or bracket-less
command or not
+ ;; 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-length))
(end-of-line)
(forward-char -1)
@@ -211,6 +235,13 @@
"Does STRING start with opening doc comment?"
(string-match-p "^[\t ]*/\\*\\*" string))
+(defun phps-mode-indent--string-starts-with-opening-bracket (string)
+ "If STRING start with opening bracket return it otherwise nil."
+ (if
+ (string-match "^[\t ]*\\([\[{(]\\)" string)
+ (match-string 0 string)
+ nil))
+
(defun phps-mode-indent--string-ends-with-opening-bracket-p (string)
"Get bracket count for STRING."
(string-match-p "\\([\[{(]\\|<[a-zA-Z]+\\|[\t ]+implements\\)[\t ]*$"
string))
- [elpa] externals/phps-mode d802a669c0 061/212: Bookkeeping via AST working with isset() and !empty() scoped variables, (continued)
- [elpa] externals/phps-mode d802a669c0 061/212: Bookkeeping via AST working with isset() and !empty() scoped variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9115ec583 069/212: Cleaned up AST bookkeeping tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f4d2164f8b 067/212: Bookkeeping via parser SDT passing static variables in function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8b5ce22d87 072/212: Fixed issue with SDT for return statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 491c82a2a1 071/212: Added TODO item for bookkeeping via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5ec32f5f5a 076/212: Bookkeeping via AST passing all tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 228f212127 080/212: Starting on removing the old process tokens in string function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5b1f5b4774 079/212: Improved format of SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3f3a8bb0fa 081/212: Major refactor of indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for multi-line class implements,
Christian Johansson <=
- [elpa] externals/phps-mode f69df4fdf6 083/212: Moved indentation to separate file and test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 481deb6331 082/212: More work on indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fe9cb90c44 097/212: Passing indent test for some multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c9f715a1fd 093/212: Improved comments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f0ab7a2cdb 095/212: Passed tests for inline control structures, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 08f57c1d36 107/212: Added TODO item for indent, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenation test for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1ed09d42f5 111/212: Passing another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d205d8392f 113/212: Passed another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1a62f48783 130/212: Improved indentation in cases with multi-expressions last line does not start with closing bracket, Christian Johansson, 2022/01/26