[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode a259292 047/405: Changed indentation function
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode a259292 047/405: Changed indentation function to work solely on tokens |
Date: |
Sat, 13 Jul 2019 09:59:40 -0400 (EDT) |
branch: externals/phps-mode
commit a259292c393926de51a9faa8f44290034bdea5c4
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Changed indentation function to work solely on tokens
---
phps-functions.el | 48 +++++++++++++++++++++++++++++++++++++++---------
phps-test-functions.el | 28 +++++++++++++++-------------
2 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/phps-functions.el b/phps-functions.el
index 7bdfe26..54e021c 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -49,15 +49,45 @@
;; Are we in scripting?
(when in-scripting
- (let ((indent-start (* (+ (nth 1 start) (nth 2 start)) tab-width))
- (indent-end (* (+ (nth 1 end) (nth 2 end)) tab-width))
- (indent-diff 0))
- (when (and (> indent-start indent-end)
- (looking-at-p "^[][ \t)(}{};]+\\($\\|?>\\)"))
- (setq indent-diff (- indent-start indent-end)))
- (let ((indent-level (- indent-start indent-diff)))
- (message "inside scripting, start: %s, end: %s, indenting to
column %s " start end indent-level)
- (indent-line-to indent-level))))))))
+ (let ((start-bracket-level (nth 1 start))
+ (start-parenthesis-level (nth 2 start))
+ (start-token-number (nth 4 start))
+ (end-bracket-level (nth 1 end))
+ (end-parenthesis-level (nth 2 end))
+ (end-token-number (nth 4 end)))
+ (let* ((indent-start (+ start-bracket-level
start-parenthesis-level))
+ (indent-end (+ end-bracket-level end-parenthesis-level))
+ (indent-level indent-start))
+ ;; (message "indent-start %s, indent-end %s" indent-start
indent-end)
+ (when (and
+ (boundp 'phps-mode/lexer-tokens)
+ (> indent-start indent-end))
+ (let ((token-number start-token-number)
+ (valid-tokens t))
+ ;; (message "token start %s, token end %s"
start-token-number end-token-number)
+ (while (and valid-tokens
+ (<= token-number end-token-number))
+ (let ((token (car (nth token-number
phps-mode/lexer-tokens)))
+ (token-start (car (cdr (nth token-number
phps-mode/lexer-tokens)))))
+ (when (and valid-tokens
+ (>= token-start (point))
+ (not (or
+ (string= token "{")
+ (string= token "}")
+ (string= token "(")
+ (string= token ")")
+ (string= token "[")
+ (string= token "]")
+ (string= token ";")
+ (eq token 'T_CLOSE_TAG))))
+ ;; (message "Token %s - %s in %s was invalid" token
token-number phps-mode/lexer-tokens)
+ (setq valid-tokens nil)))
+ (setq token-number (+ token-number 1)))
+ (when valid-tokens
+ ;; (message "Tokens was valid, decreasing indent %s - %s"
(line-beginning-position) (line-end-position))
+ (setq indent-level (- indent-level (- indent-start
indent-end))))))
+ ;; (message "inside scripting, start: %s, end: %s, indenting to
column %s " start end indent-level)
+ (indent-line-to (* indent-level tab-width)))))))))
(defun phps-mode/indent-region ()
"Indent region."
diff --git a/phps-test-functions.el b/phps-test-functions.el
index d207c62..644f916 100644
--- a/phps-test-functions.el
+++ b/phps-test-functions.el
@@ -51,49 +51,51 @@
(should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\n if ($mySeconCondition) {\necho $title;\n\n}
?></title><body>Bla bla</body></html>"))))
(phps-mode/with-test-buffer
- "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title;\n} ?></title><body>Bla bla</body></html>"
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title1;\n} ?></title><body>Bla bla</body></html>"
(goto-char 75)
(phps-mode/indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\n echo $title;\n}
?></title><body>Bla bla</body></html>"))))
+ (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\n echo $title1;\n}
?></title><body>Bla bla</body></html>"))))
(phps-mode/with-test-buffer
- "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title2;\n\n} ?></title><body>Bla bla</body></html>"
(goto-char 98)
(phps-mode/indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\necho $title;\n\n }
?></title><body>Bla bla</body></html>"))))
+ (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\necho $title2;\n\n }
?></title><body>Bla bla</body></html>"))))
(phps-mode/with-test-buffer
- "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title;\n\n}\n?>\n</title><body>Bla bla</body></html>"
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title3;\n\n}\n?>\n</title><body>Bla bla</body></html>"
(goto-char 110)
(phps-mode/indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\necho
$title;\n\n}\n?>\n</title><body>Bla bla</body></html>"))))
+ (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\necho
$title3;\n\n}\n?>\n</title><body>Bla bla</body></html>"))))
(phps-mode/with-test-buffer
- "<?php\n$variable = array(\n'random'\n);\n$variable = true;\n"
+ "<?php\n$variable = array(\n'random3'\n);\n$variable = true;\n"
(goto-char 28)
(phps-mode/indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random'\n);\n$variable = true;\n"))))
+ (should (equal buffer-contents "<?php\n$variable = array(\n
'random3'\n);\n$variable = true;\n"))))
(phps-mode/with-test-buffer
- "<?php\n$variable = array(\n 'random'\n );\n$variable = true;\n"
- (goto-char 39)
+ "<?php\n$variable = array(\n 'random2'\n );\n$variable = true;\n"
+ (goto-char 43)
+ ;; (message "Tokens %s point %s" phps-mode/lexer-tokens (point))
(phps-mode/indent-line)
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random'\n);\n$variable = true;\n"))))
+ (should (equal buffer-contents "<?php\n$variable = array(\n
'random2'\n);\n$variable = true;\n"))))
(phps-mode/with-test-buffer
- "<?php\n$variable = array(\n'random');\n$variable = true;\n"
+ "<?php\n$variable = array(\n'random4');\n$variable = true;\n"
(goto-char 29)
(phps-mode/indent-line)
+ ;; (message "Tokens %s point %s" phps-mode/lexer-tokens (point))
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random');\n$variable = true;\n"))))
+ (should (equal buffer-contents "<?php\n$variable = array(\n
'random4');\n$variable = true;\n"))))
)
- [elpa] externals/phps-mode feb5724 039/405: Various debug work, (continued)
- [elpa] externals/phps-mode feb5724 039/405: Various debug work, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e36d477 045/405: token-number from point now is the same format as (nth), Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b437374 040/405: Fixed bug in parsing of object parameters inside double quoted string, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7161184 041/405: Handles stacked states better, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c625217 042/405: Added flag for PSR-2 white-space settings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b629c4b 050/405: Updated comments and TODOs, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 4b4a375 043/405: Using lexical bindings for all files, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c040358 046/405: Point lexer token information makes more sense, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 94492c4 048/405: Added changes tracking to functions from lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode be46d9c 044/405: Added lexer autoload to functions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a259292 047/405: Changed indentation function to work solely on tokens,
Stefan Monnier <=
- [elpa] externals/phps-mode 4098f46 049/405: Started with incremental lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode da1d1de 051/405: Temporary lexer after change until other work is ready, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 990d3dd 054/405: Added test for indentation of multiple-line doc comment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dd80d27 055/405: Started work on detecting doc comment blocks, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e1b7160 053/405: (newline-and-indent) now working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8aa1ab6 059/405: Another test for getting point data inside doc block, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 09daec3 052/405: Foundation for incremental lexer and syntax colorer completed, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3f4c344 056/405: Fixed detection of doc comment blocks, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3824abf 060/405: Resolved indent with trailing parenthesis, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a61cb8b 062/405: Fixed issue with doc comment indentation, Stefan Monnier, 2019/07/13