[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 40ecf58372 189/212: Adjustments for indent he
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 40ecf58372 189/212: Adjustments for indent helper function determining last index line |
Date: |
Wed, 26 Jan 2022 01:51:25 -0500 (EST) |
branch: externals/phps-mode
commit 40ecf58372206aee506583e7b592a7f06895607f
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Adjustments for indent helper function determining last index line
---
phps-mode-indent.el | 248 ++++++++++++++++++------------------------
test/phps-mode-test-indent.el | 31 +++++-
2 files changed, 131 insertions(+), 148 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index ff8e0a2d7f..ade1f7d914 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -163,93 +163,91 @@
bracket-level))
(defun phps-mode-indent--get-previous-reference-index-line ()
- "Get previous index line as reference, if any exist."
- (let ((reference-line)
- (old-point (point)))
- (end-of-line)
- (search-backward-regexp "\\(,\\|[^[({\t ]\\)" nil t)
- (unless (string= (match-string-no-properties 0) ",")
- (forward-char 1))
- (let ((not-found-bracket-start t)
- (found-colon)
- (reference-line-started-bracket)
- (parenthesis-level 0))
- (while
- (and
- not-found-bracket-start
- (search-backward-regexp
- "\\([][{}(),]\\|=>\\)"
- nil
- t))
- (let ((match (match-string-no-properties 0)))
- ;; (message "match: %S" match)
- (cond
+ "Get previous index line as reference, if any exist. A index line is a
previous element line inside current bracket scope."
+ (let ((reference-line))
+ (save-excursion
+ (end-of-line)
+ (search-backward-regexp "," nil t) ;; Skip trailing comma
+ (let ((not-found-bracket-start t)
+ (found-colon)
+ (parenthesis-level 0))
+ (while
+ (and
+ not-found-bracket-start
+ (search-backward-regexp
+ "\\([][{}(),]\\|=>\\)"
+ nil
+ t))
+ (let ((match (match-string-no-properties 0)))
+ ;; (message "match: %S" match)
+ (cond
- ((or
- (string= "(" match)
- (string= "[" match)
- (string= "{" match))
- (setq
- parenthesis-level
- (1+ parenthesis-level))
- (when (= parenthesis-level 1)
- (unless found-colon
+ ((or
+ (string= "(" match)
+ (string= "[" match)
+ (string= "{" match))
+ (setq
+ parenthesis-level
+ (1+ parenthesis-level))
+
+ (cond
+
+ ((= parenthesis-level 1)
(setq
- reference-line-started-bracket
- t)
+ not-found-bracket-start
+ nil))
+
+ ((= parenthesis-level 0)
(setq
reference-line
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))
+
+ ))
+
+ ((or
+ (string= ")" match)
+ (string= "]" match)
+ (string= "}" match))
(setq
- not-found-bracket-start
- nil)))
+ parenthesis-level
+ (1- parenthesis-level)))
- ((or
- (string= ")" match)
- (string= "]" match)
- (string= "}" match))
- (setq
- parenthesis-level
- (1- parenthesis-level)))
-
- ;; The second occurrence of a colon
- ;; is a significant marker of
- ;; a starting bracket row
- ((string= "," match)
- (when (= parenthesis-level 0)
- (if found-colon
+ ;; The second occurrence of a colon
+ ;; is a significant marker of
+ ;; a starting bracket row
+ ((string= "," match)
+ (when (= parenthesis-level 0)
+ (if found-colon
+ (setq
+ not-found-bracket-start
+ nil)
(setq
- not-found-bracket-start
- nil)
- (setq
- found-colon
- t)
+ found-colon
+ t)
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))))
+
+ ;; The first occurrence of a =>
+ ;; is a significant marker of
+ ;; a starting bracket row
+ ((string= "=>" match)
+ (when (= parenthesis-level 0)
(setq
reference-line
(buffer-substring-no-properties
(line-beginning-position)
- (line-end-position))))))
-
- ;; The first occurrence of a =>
- ;; is a significant marker of
- ;; a starting bracket row
- ((string= "=>" match)
- (when (= parenthesis-level 0)
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
- (setq
- not-found-bracket-start
- nil)))
-
- )))
+ (line-end-position)))
+ (setq
+ not-found-bracket-start
+ nil)))
- (goto-char old-point)
- reference-line)))
+ )))))
+ reference-line))
(defun phps-mode-indent--get-previous-start-of-bracket-line
(&optional from-end-of-line)
@@ -537,7 +535,8 @@
;; debug stuff
(phps-mode-debug-message
(message "\ncurrent-line-string: %S" current-line-string)
- (message "previous-line-string: %S" previous-line-string))
+ (message "previous-line-string: %S" previous-line-string)
+ (message "previous-indentation: %S" previous-indentation))
;; (message "current-line-starts-with-closing-bracket: %S"
current-line-starts-with-closing-bracket)
;; (message "current-line-starts-with-opening-bracket: %S"
current-line-starts-with-opening-bracket)
@@ -868,8 +867,7 @@
(not is-bracket-less-command))
(setq
new-indentation
- (+ new-indentation tab-width))))
- (goto-char point))
+ (+ new-indentation tab-width)))))
;; LINE AFTER OPENING HEREDOC/NOWDOC
;; echo <<<VAR
@@ -1011,31 +1009,37 @@
'line-after-line-ending-with-comma)
(forward-line (* -1 move-length1))
- (end-of-line)
- (search-backward-regexp "," nil t) ;; Skip trailing comma
- (when-let
- ((reference-line
- (phps-mode-indent--get-previous-reference-index-line)))
- ;; (message "reference-line-2: %S" reference-line)
- (setq
- new-indentation
- (phps-mode-indent--string-indentation
- reference-line))
- (let ((reference-bracket-level
- (phps-mode-indent--get-string-brackets-count
+ (let ((reference-line
+ (phps-mode-indent--get-previous-reference-index-line)))
+ (if reference-line
+ (progn
+ (message "reference-line-2: %S" reference-line)
+ (setq
+ new-indentation
+ (phps-mode-indent--string-indentation
reference-line)))
- ;; (message "reference-bracket-level: %S"
reference-bracket-level)
;; define('_PRIVATE_ROOT',
;; 'here');
;; or
;; ['abc',
;; 'def'];
- (when (> reference-bracket-level 0)
+ ;; but ignore
+ ;; array(
+ ;; array(
+ ;; 1,
+ ;; ),
+ ;; array(
+ (when (> previous-bracket-level 0)
(setq
new-indentation
(+ new-indentation tab-width)))))
+ ;; array(
+ ;; array(
+ ;; 1,
+ ;; ),
+ ;; ),
(when current-line-starts-with-closing-bracket
(setq
new-indentation
@@ -1264,52 +1268,11 @@
(when-let
((reference-line
(phps-mode-indent--get-previous-start-of-bracket-line
t)))
- (let ((reference-line2
- (buffer-substring-no-properties
- (point)
- (line-end-position)))
- (reference-indentation
- (phps-mode-indent--string-indentation
- reference-line)))
- (let ((new-indentation
- reference-indentation)
- (reference-bracket-level
- (phps-mode-indent--get-string-brackets-count
- reference-line))
- (reference-bracket-level2
- (phps-mode-indent--get-string-brackets-count
- reference-line2))
- (reference-contains-assignment
- (string-match-p
- "^[\t ]*$[a-zA-Z0-9_]+[\t ]*[^=!]*=\\($\\|[\t
]+.*[^,;]$\\)"
- reference-line)))
- ;; if (
- ;; (is_array($data)
- ;; && !empty($data['index'])
- ;; && (is_a($data['index'], 'Index')
- ;; || is_a($data['Index'], 'Index2')))
- ;; || is_a($data, 'WC_Index')
- ;; or
- ;; $copies = method_exists($object, 'get_copies')
- ;; ? true
- ;; (message "reference-bracket-level: %S"
reference-bracket-level)
- ;; (message "reference-bracket-level2: %S"
reference-bracket-level2)
-
- (when (or
- reference-contains-assignment
- (and
- (> reference-bracket-level 0)
- (> reference-bracket-level
reference-bracket-level2)))
- (setq
- new-indentation
- (+ new-indentation tab-width))))
-
- (when current-line-starts-with-closing-bracket
- (setq
- new-indentation
- (- new-indentation tab-width)))
-
- )))
+ ;; (message "reference-line: %S" reference-line)
+ (setq
+ new-indentation
+ (phps-mode-indent--string-indentation
+ reference-line))))
;; LINE AFTER OPENING MULTI-LINE ASSIGNMENT
;; $var = 'A line' .
@@ -1397,10 +1360,7 @@
;; Use its indentation for this line as well
(setq
new-indentation
- bracket-start-indentation)))
-
- ;; Reset point
- (goto-char old-point)))
+ bracket-start-indentation)))))
;; LINE THAT CONTINUES MULTI-LINE CONCATENATION
;; echo 'Something'
@@ -1486,10 +1446,7 @@
;; We use previous concatenated lines indent
(setq
new-indentation
- first-concatenated-line-indent)))
-
- ;; Reset point
- (goto-char old-point)))
+ first-concatenated-line-indent)))))
;; LINE AFTER CASE DEFINITION
;; case true:
@@ -1525,14 +1482,15 @@
)
(phps-mode-debug-message
- (message "new-indentation: %S" new-indentation)
- (message "match-type: %S" match-type))
+ (message "match-type: %S" match-type)
+ (message "new-indentation: %S" new-indentation))
(when (< new-indentation 0)
(setq
new-indentation
0))
+ (goto-char point)
(indent-line-to new-indentation)))))
;; Only move to end of line if point is the current point and is at end
of line
(when (equal point (point))
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index e7bf7c013a..33e7d39f61 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -99,10 +99,19 @@
(string=
(phps-mode-indent--get-previous-reference-index-line)
" 'element 1',")))
+ (message "Passed reference index line 1")
+
+ (with-temp-buffer
+ (insert "<?php\nthrow new Exception(\n sprintf(\n
self::systemTranslate(\n 'Invalid parameters for Application.
Parameters: \"%s\".'\n ),\n print_r(self::$_parameters, true)\n
)\n);\n")
+ (goto-char 144)
+ (should
+ (string=
+ (phps-mode-indent--get-previous-reference-index-line)
+ " self::systemTranslate(")))
(with-temp-buffer
(insert "<?php\necho 'command 1';\necho 'command 2';")
- (goto-char (point-max))
+ (goto-char (1- (point-max)))
(should
(string=
(phps-mode-indent--get-previous-reference-command-line)
@@ -110,7 +119,7 @@
(with-temp-buffer
(insert "<?php\n$var = 'command'\n . '1';\necho 'command 2';")
- (goto-char (point-max))
+ (goto-char (1- (point-max)))
(should
(string=
(phps-mode-indent--get-previous-reference-command-line)
@@ -118,12 +127,28 @@
(with-temp-buffer
(insert "<?php\nif(true):\n echo 'here';\nelse:\n echo 'Something
else';\n echo 'Something else again';")
- (goto-char (point-max))
+ (goto-char (1- (point-max)))
+ (should
+ (string=
+ (phps-mode-indent--get-previous-reference-command-line)
+ " echo 'Something else';")))
+
+ (with-temp-buffer
+ (insert "<?php\nif(true):\n echo 'here';\nelse:\n echo 'Something
else';\n echo 'Something else again';")
+ (goto-char (1- (point-max)))
(should
(string=
(phps-mode-indent--get-previous-reference-command-line)
" echo 'Something else';")))
+ (with-temp-buffer
+ (insert "<?php\n\nif (true) {\n switch ($var):\n case true:\n
echo 'here';\n endswitch;\n echo 'was here';\n}")
+ (goto-char 105)
+ (should
+ (string=
+ (phps-mode-indent--get-previous-reference-command-line)
+ " endswitch;")))
+
(with-temp-buffer
(insert "<?php\nif (true) {\n array(\n 8,\n );")
(goto-char (point-max))
- [elpa] externals/phps-mode 6a49784b8b 161/212: When indentation search previous code lines it skips commented out lines, (continued)
- [elpa] externals/phps-mode 6a49784b8b 161/212: When indentation search previous code lines it skips commented out lines, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5432a61340 162/212: Improved indentation around closing of multi-dimensional brackets, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 28a5302e08 148/212: Passing indentation on line after closing bracket and command and were current line starts with closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode be61c94dc3 165/212: Added TODO item, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c65d433a73 138/212: Improved indentation around multi-line function-calls, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f537965850 168/212: Improved indentation on lines after lines that ends with semicolon, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6d8544d7fa 171/212: Added two more failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 616e3dc7ea 172/212: Added a TODO file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d74686e07c 180/212: Started on optimizing lexer, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 06b35e4bf1 183/212: Fixed TODO item in this branch, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 40ecf58372 189/212: Adjustments for indent helper function determining last index line,
Christian Johansson <=
- [elpa] externals/phps-mode edba476df8 191/212: Byte compilation fixes for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 580298c395 201/212: Improved indentation of multi-line concatenated strings containing brackets, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3e79319cf5 195/212: Added failing indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 72c692b511 210/212: Re-scan buffer interactively now clears cache and kills running threads, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 55d59ee365 207/212: More work on cache support, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 733f36a123 203/212: Added more failing indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d4f0db2c0c 211/212: Added failing bookkeeping test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cb4d95cd7a 204/212: Passed new indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a907f103f0 026/212: More work on AST for bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 95078e0db2 029/212: Added SDT for increment variable production, Christian Johansson, 2022/01/26