[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode f537965850 168/212: Improved indentation on l
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode f537965850 168/212: Improved indentation on lines after lines that ends with semicolon |
Date: |
Wed, 26 Jan 2022 01:51:21 -0500 (EST) |
branch: externals/phps-mode
commit f5379658504308923f0cf68300010b3bb1bb9e1d
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation on lines after lines that ends with semicolon
---
phps-mode-indent.el | 143 ++++++++++------------------------------------------
phps-mode-macros.el | 2 +-
2 files changed, 29 insertions(+), 116 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index d2d57c52e8..bc91f701f6 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -727,7 +727,7 @@
new-indentation
(- new-indentation tab-width)))
- ;; LINE AFTER ENDING OF BRACKET AND COMMA
+ ;; LINE AFTER LINE ENDING WITH COMMA
;; return array(
;; '' => __(
;; 'None',
@@ -762,7 +762,7 @@
previous-line-string)
(setq
match-type
- 'line-after-ending-of-bracket-and-comma)
+ 'line-after-line-ending-with-comma)
;; Backtrack first to line were bracket started
;; and use indentation from that line from that line
@@ -874,7 +874,7 @@
(goto-char point))
- ;; LINE AFTER ENDING OF COMMAND
+ ;; LINE AFTER LINE THATS ENDS WITH SEMICOLON
;; $var .=
;; 'hello';
;; echo 'here';
@@ -906,14 +906,10 @@
;; echo 'here';
((and
previous-line-ends-with-terminus
- (string= previous-line-ends-with-terminus ";")
- (not
- (string-match-p
- "^[\t ]*\\(echo[\t ]+\\|print[\t ]+\\)"
- previous-line-string)))
+ (string= previous-line-ends-with-terminus ";"))
(setq
match-type
- 'line-after-ending-of-command)
+ 'line-after-line-that-ends-with-semicolon)
;; Back-trace buffer from previous line
;; Determine if semi-colon ended an multi-line assignment or
bracket-less command or not
@@ -923,13 +919,9 @@
(search-backward-regexp ";" nil t) ;; Skip the semi-colon
(let ((not-found t)
- (is-assignment nil)
- (is-string-doc)
- (is-function-call)
- (parenthesis-level 0)
- (is-bracket-less-command nil)
- (is-same-line-p t)
- (bracket-opened-on-first-line))
+ (reference-line)
+ (reference-indentation)
+ (parenthesis-level 0))
(while
(and
not-found
@@ -940,19 +932,17 @@
(let ((match (match-string-no-properties 0)))
(cond
- ((string= match "\n")
- (setq is-same-line-p nil))
+ ((string= match "\n"))
+ ;; Start of HEREDOC / NOWDOC
((string-match-p
"<<<'?\"?[a-zA-Z0-9_]+'?\"?"
match)
- (setq
- is-string-doc
- t)
(setq
not-found
nil))
+ ;; Function call
((string-match-p
"[a-zA-Z_]+[a-zA-Z0-9_]*[\t ]*("
match)
@@ -960,9 +950,6 @@
parenthesis-level
(1+ parenthesis-level))
(when (= parenthesis-level 0)
- (setq
- is-function-call
- t)
(setq
not-found
nil)))
@@ -973,100 +960,26 @@
(1- parenthesis-level)))
((= parenthesis-level 0)
- (setq is-assignment (string-match-p "=" match))
- (setq is-bracket-less-command
- (string-match-p
- "\\(echo[\t ]+\\|print[\t ]+\\|return[\t ]+\\)"
- match))
- (setq not-found nil)))))
-
- ;; $var = <<<EOD
- ;; OKASDOKASD
- ;; EOD;
- ;; echo 'here';
- (when is-string-doc
- (setq
- new-indentation
- (phps-mode-indent--string-indentation
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))))
-
- ;; When we have an assignment
- ;; keep track if bracket was opened on first
- ;; line
- (when is-assignment
- (let ((start-bracket-count
- (phps-mode-indent--get-string-brackets-count
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))))
- ;; (message "start-bracket-count: %S from %S"
start-bracket-count (buffer-substring-no-properties
- ;; (line-beginning-position)
- ;; (line-end-position)))
- (setq
- bracket-opened-on-first-line
- (> start-bracket-count 0))))
-
- ;; (message "is-assignment: %S" is-assignment)
- ;; (message "bracket-opened-on-first-line: %S"
bracket-opened-on-first-line)
-
- ;; echo 'there' .
- ;; 'here';
- ;; echo 'here';
- ;; or
- ;; print 'there' .
- ;; 'here';
- ;; echo 'here';
- ;; or
- ;; $var =
- ;; 'opkeokoek';
- ;; echo 'here'
-
- ;; ignore cases like
- ;; $var = array(
- ;; 'here'
- ;; );
- ;; echo 'here';
- ;; but not cases like
- ;; $var = 'abc'
- ;; . 'def' . __(
- ;; 'okeoke'
- ;; ) . 'ere';
- ;; echo 'here';
- ;; NOTE stuff like $var = array(\n 4\n);\n
- ;; will end assignment but also decrease
previous-bracket-level
- ;; NOTE but cases like $var = array(\n 4);\n should pass
- (when (and
- (not is-same-line-p)
- (or
- (and
- is-assignment
- (or
- (not bracket-opened-on-first-line)
- (not previous-line-starts-with-closing-bracket)))
- is-bracket-less-command))
+ (setq
+ not-found
+ nil)))))
+ (goto-char point)
+
+ (unless not-found
(setq
- new-indentation
- (- new-indentation tab-width)))
-
- ;; define('_PRIVATE_ROOT',
- ;; 'here');
- ;; echo 'here';
- ;; but ignore
- ;; if (true) {
- ;; define('_PRIVATE_ROOT', 'here');
- ;; echo 'here';
- (when (and
- is-function-call
- (not is-same-line-p))
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
(setq
+ reference-indentation
+ (phps-mode-indent--string-indentation
+ reference-line))
+ ;; TODO The line after should use the same indentation
+ ;; as the line starting the command
+ (setq
new-indentation
- (- new-indentation tab-width)))
-
- )
-
- (goto-char point))
+ reference-indentation))))
;; LINE AFTER ALTERNATIVE CASE DEFINITION
;; switch ($array):
diff --git a/phps-mode-macros.el b/phps-mode-macros.el
index 7d4e2550d7..c3cffb5e82 100644
--- a/phps-mode-macros.el
+++ b/phps-mode-macros.el
@@ -9,7 +9,7 @@
(defconst
phps-mode-macrotime-debug
- t
+ nil
"Debug messages during macro expansion time, default nil.")
(defmacro phps-mode-debug-message (&rest message)
- [elpa] externals/phps-mode 26d7b64086 144/212: Added TODO item for indentation, (continued)
- [elpa] externals/phps-mode 26d7b64086 144/212: Added TODO item for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0e7eb04800 149/212: Passing indentation test for multiple function arguments with default values, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on line after closing bracket and comma, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1825ee499b 151/212: More wrestling with indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 29fee20e43 141/212: Passed all tests for indentation, Christian Johansson, 2022/01/26
- [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 <=
- [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, 2022/01/26
- [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