[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 9a2573939a 094/212: More wrestling
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 9a2573939a 094/212: More wrestling |
Date: |
Wed, 26 Jan 2022 01:51:01 -0500 (EST) |
branch: externals/phps-mode
commit 9a2573939a7e3aaf053af2dacbb6d64bcd370c03
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More wrestling
---
phps-mode-indent.el | 205 +++++++++++++++++++++++++-----------------
test/phps-mode-test-indent.el | 4 +
2 files changed, 129 insertions(+), 80 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index f0a5da08fb..03c2f8b78d 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -114,11 +114,10 @@
(point-at-end-of-line (equal point (line-end-position))))
(save-excursion
(let ((move-length 0)
- (line-is-empty-p t)
- (line-beginning-position)
- (line-end-position)
- (line-string)
- (current-line-string))
+ (current-line-string "")
+ (previous-line-string "")
+ (previous-line-is-empty-p)
+ (previous2-line-string ""))
(when initial-point
(goto-char point))
@@ -133,50 +132,83 @@
;; (message "\nCurrent line: %S" current-line-string)
;; TODO Try to find previous 2 non-empty lines
- (while (and
- (= (forward-line -1) 0)
- line-is-empty-p)
- (beginning-of-line)
- (setq
- line-beginning-position (line-beginning-position))
- (setq
- line-end-position (line-end-position))
- (setq
- line-string
- (buffer-substring-no-properties line-beginning-position
line-end-position))
- (setq
- line-is-empty-p (string-match-p "^[ \t\f\r\n]*$" line-string))
- (setq
- move-length (1+ move-length)))
-
- (if line-is-empty-p
+ (let ((line-is-empty-p t)
+ (searching-previous-lines 2))
+ (while (and
+ (= (forward-line -1) 0)
+ (> searching-previous-lines 0))
+ (beginning-of-line)
+ (let ((line-string
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))
+ (setq
+ line-is-empty-p
+ (string-match-p
+ "^[ \t\f\r\n]*$"
+ line-string))
+ (unless line-is-empty-p
+ (cond
+ ((= searching-previous-lines 2)
+ (setq
+ previous-line-string
+ line-string))
+ ((= searching-previous-lines 1)
+ (setq
+ previous2-line-string
+ line-string)))
+ (setq
+ searching-previous-lines
+ (1- searching-previous-lines))
+ (when (= searching-previous-lines 1)
+ (setq
+ previous-line-is-empty-p
+ line-is-empty-p)))
+ (setq
+ move-length
+ (1+ move-length)))))
+ ;; (message "previous-line-string: %S" previous-line-string)
+ ;; (message "previous2-line-string: %S" previous2-line-string)
+
+ (if previous-line-is-empty-p
(indent-line-to 0)
- (let* ((old-indentation
- (phps-mode-indent--string-indentation line-string))
+ (let* ((previous-indentation
+ (phps-mode-indent--string-indentation
+ previous-line-string))
(current-line-starts-with-closing-bracket
- (phps-mode-indent--string-starts-with-closing-bracket
current-line-string))
+ (phps-mode-indent--string-starts-with-closing-bracket
+ current-line-string))
(current-line-starts-with-opening-bracket
- (phps-mode-indent--string-starts-with-opening-bracket
current-line-string))
+ (phps-mode-indent--string-starts-with-opening-bracket
+ current-line-string))
(current-line-ends-with-terminus
- (phps-mode-indent--string-ends-with-terminus
current-line-string))
- (line-starts-with-closing-bracket
- (phps-mode-indent--string-starts-with-closing-bracket
line-string))
- (line-ends-with-closing-bracket
- (phps-mode-indent--string-ends-with-closing-bracket
line-string))
- (line-starts-with-opening-doc-comment
- (phps-mode-indent--string-starts-with-opening-doc-comment
line-string))
- (line-ends-with-assignment
- (phps-mode-indent--string-ends-with-assignment
line-string))
- (line-ends-with-opening-bracket
- (phps-mode-indent--string-ends-with-opening-bracket
line-string))
- (line-ends-with-terminus
- (phps-mode-indent--string-ends-with-terminus line-string))
- (bracket-level
- (phps-mode-indent--get-string-brackets-count line-string)))
- ;; (message "Previous non-empty line: %S with indentation: %S"
line-string old-indentation)
- ;; (message "line-ends-with-terminus: %S"
line-ends-with-terminus)
-
- (setq new-indentation old-indentation)
+ (phps-mode-indent--string-ends-with-terminus
+ current-line-string))
+ (previous-line-starts-with-closing-bracket
+ (phps-mode-indent--string-starts-with-closing-bracket
+ previous-line-string))
+ (previous-line-ends-with-closing-bracket
+ (phps-mode-indent--string-ends-with-closing-bracket
+ previous-line-string))
+ (previous-line-starts-with-opening-doc-comment
+ (phps-mode-indent--string-starts-with-opening-doc-comment
+ previous-line-string))
+ (previous-line-ends-with-assignment
+ (phps-mode-indent--string-ends-with-assignment
+ previous-line-string))
+ (previous-line-ends-with-opening-bracket
+ (phps-mode-indent--string-ends-with-opening-bracket
+ previous-line-string))
+ (previous-line-ends-with-terminus
+ (phps-mode-indent--string-ends-with-terminus
+ previous-line-string))
+ (previous-bracket-level
+ (phps-mode-indent--get-string-brackets-count
+ previous-line-string)))
+ ;; (message "Previous non-empty line: %S with indentation: %S"
previous-line-string old-indentation)
+ ;; (message "previous-line-ends-with-terminus: %S"
previous-line-ends-with-terminus)
+
+ (setq new-indentation previous-indentation)
(goto-char point)
;; class MyClass implements
@@ -184,8 +216,8 @@
;; or
;; class MyClass extends
;; myParent
- (when (string-match-p "[\t ]+\\(extends\\|implements\\)$"
line-string)
- (setq bracket-level (+ tab-width)))
+ (when (string-match-p "[\t ]+\\(extends\\|implements\\)$"
previous-line-string)
+ (setq previous-bracket-level (+ tab-width)))
;; class MyClass
;; implements myInterface
@@ -219,66 +251,79 @@
;; echo 'Something';
(when (and
(not current-line-starts-with-closing-bracket)
- line-ends-with-closing-bracket
- (string= line-ends-with-closing-bracket ")")
- (string-match-p "^[\t ]*\\(if\\|while\\)[\t ]*("
line-string))
+ previous-line-ends-with-closing-bracket
+ (string= previous-line-ends-with-closing-bracket ")")
+ (string-match-p "^[\t ]*\\(if\\|while\\)[\t ]*("
previous-line-string))
(setq new-indentation (+ new-indentation tab-width)))
;; else
;; echo 'Something';
(when (phps-mode-indent--string-starts-with-regexp
- line-string
+ previous-line-string
"else[\t ]*$")
(setq new-indentation (+ new-indentation tab-width)))
- ;; if (true)
- ;; echo 'Something';
- ;; else
(when (and
- line-ends-with-terminus
- (string= line-ends-with-terminus ";"))
+ previous-line-ends-with-terminus
+ (string= previous-line-ends-with-terminus ";"))
+
+ ;; if (true)
+ ;; echo 'Something';
+ ;; else
(when (phps-mode-indent--string-starts-with-regexp
current-line-string "[\t ]*else")
- (setq new-indentation (- new-indentation tab-width))))
-
- ;; if (true)
- ;; echo 'Something';
- ;; else
- ;; echo 'Something else';
- ;; echo true;
- ;; TODO
-
- (when (> bracket-level 0)
- (if (< bracket-level tab-width)
+ (setq new-indentation (- new-indentation tab-width)))
+
+ ;; if (true)
+ ;; echo 'Something';
+ ;; else
+ ;; echo 'Something else';
+ ;; echo true;
+ ;; or
+ ;; if (true)
+ ;; echo 'Something';
+ ;; echo 'Something else';
+ ;; TODO
+ (when (or
+ (phps-mode-indent--string-starts-with-regexp
+ previous2-line-string "[\t ]*else")
+ (phps-mode-indent--string-starts-with-regexp
+ previous2-line-string "[\t ]*if[\t ]*("))
+ (setq new-indentation (- new-indentation tab-width)))
+
+ )
+
+ (when (> previous-bracket-level 0)
+ (if (< previous-bracket-level tab-width)
(setq new-indentation (+ new-indentation 1))
(setq new-indentation (+ new-indentation tab-width))))
- (when (= bracket-level -1)
+ (when (= previous-bracket-level -1)
(setq new-indentation (1- new-indentation)))
- (when (and (= bracket-level 0)
- line-starts-with-closing-bracket)
+ (when (and (= previous-bracket-level 0)
+ previous-line-starts-with-closing-bracket)
(setq new-indentation (+ new-indentation tab-width)))
(when current-line-starts-with-closing-bracket
(setq new-indentation (- new-indentation tab-width)))
- (when line-starts-with-opening-doc-comment
+ (when previous-line-starts-with-opening-doc-comment
(setq new-indentation (+ new-indentation 1)))
(when (and
- line-ends-with-assignment
- (<= bracket-level 0))
+ previous-line-ends-with-assignment
+ (<= previous-bracket-level 0))
(setq new-indentation (+ new-indentation tab-width)))
(when (and
- line-ends-with-opening-bracket
- (< bracket-level 0))
+ previous-line-ends-with-opening-bracket
+ (< previous-bracket-level 0))
(setq new-indentation (+ new-indentation tab-width)))
(when (and
- line-ends-with-terminus
- (not (string-match-p "^[\t ]*\\(echo[\t ]+\\|print[\t
]+\\)" line-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
@@ -312,11 +357,11 @@
(or
(and
is-assignment
- (> bracket-level -1))
+ (> previous-bracket-level -1))
is-bracket-less-command))
;; NOTE stuff like $var = array(\n 4\n);\n
- ;; will end assignment but also decrease bracket-level
+ ;; will end assignment but also decrease
previous-bracket-level
(setq new-indentation (- new-indentation tab-width))))
(goto-char point))
@@ -324,7 +369,7 @@
;; Decrease indentation if current line decreases in bracket
level
(when (< new-indentation 0)
(setq new-indentation 0))
- ;; (message "new-indentation: %S bracket-level: %S
old-indentation: %S" new-indentation bracket-level old-indentation)
+ ;; (message "new-indentation: %S previous-bracket-level: %S
old-indentation: %S" new-indentation previous-bracket-level old-indentation)
(indent-line-to new-indentation)))))
;; Only move to end of line if point is the current point and is at end
of line
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 6185d49ec2..bd210be7b3 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -352,6 +352,10 @@
(defun phps-mode-test-indent--get-lines-indent-inline-control-structures ()
"Test for inline control structures."
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true)\n echo 'Something';\necho 'Something after';\n"
+ "Inline control structures if")
+
(phps-mode-test-indent--should-equal
"<?php\nif (true)\n echo 'Something';\nelse\n echo 'Something
else';\necho true;\n"
"Inline control structures if else")
- [elpa] externals/phps-mode fa3681141b 027/212: Passed test for bookkeeping of conditional assignment via parser SDT, (continued)
- [elpa] externals/phps-mode fa3681141b 027/212: Passed test for bookkeeping of conditional assignment via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fc4c763d68 030/212: Added SDT for class properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f7c261cee1 032/212: Generate parser command now compatible with latest emacs-parser-generator, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f82c9a377d 033/212: Re-generated parser to verify automation functionality, improved automation documentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f858060096 034/212: More work on bookkeeping generated from parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c83b1c264e 060/212: Fixed SDT for isset_variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8fa61fa1f2 063/212: Passing bookkeeping of interface method arguments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7a636ccd28 078/212: Removed obsolete file parser-grammar-macro.el, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ee211dac6a 084/212: Started on indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f65ca852cd 092/212: Passed another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 9a2573939a 094/212: More wrestling,
Christian Johansson <=
- [elpa] externals/phps-mode 7c0cb57312 098/212: Added more multi-line assignment indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3a594466d5 100/212: Passed indent test for multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7deebc5f79 101/212: Improved indent test descriptions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d5d80017bc 104/212: Passed indent tests for concatenated string, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e083e90ac0 108/212: Passing more indentation tests for PSR-2, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 84d447e4e6 119/212: Added TODO item, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1ab6ac7324 131/212: Added failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7135a30446 173/212: Updated TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 63c5fef240 175/212: Started on tests for more basic functions of indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 735f1e0c89 176/212: More notes, Christian Johansson, 2022/01/26