[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 4d72218: Improved alternative indentation aft
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 4d72218: Improved alternative indentation after conditional equalities |
Date: |
Tue, 14 Apr 2020 16:32:47 -0400 (EDT) |
branch: externals/phps-mode
commit 4d72218a820f84807af0a8ed22b180e2f56602bc
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Improved alternative indentation after conditional equalities
---
phps-mode-lex-analyzer.el | 17 +++++++----------
phps-mode.el | 4 ++--
test/phps-mode-test-lex-analyzer.el | 26 ++++++++++++++++++++++----
3 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index c9e90dc..e683e94 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -20,7 +20,7 @@
;;; Commentary:
-;; This file contains all meta-lexer logic. That is things like:
+;; This file contains all meta-lexer logic. That is things like:
;;
;; * Executing different kinds of lexers based on conditions
;; * Also supply logic for indentation and imenu-handling
@@ -2011,11 +2011,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(setq line-end-position (line-end-position))
(setq
line-string
- (buffer-substring-no-properties line-beginning-position
line-end-position)
- )
+ (buffer-substring-no-properties line-beginning-position
line-end-position))
(setq line-is-empty (string-match-p "^[ \t\f\r\n]*$" line-string))
- (setq move-length (1+ move-length))
- )
+ (setq move-length (1+ move-length)))
(unless line-is-empty
(let* ((old-indentation (current-indentation))
@@ -2025,7 +2023,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(line-ends-with-semicolon
(phps-mode-lex-analyzer--string-ends-with-semicolon-p line-string))
(bracket-level
(phps-mode-lex-analyzer--get-string-brackets-count line-string)))
(setq new-indentation old-indentation)
- (forward-line move-length)
+ (goto-char point)
(when (> bracket-level 0)
(if (< bracket-level tab-width)
@@ -2053,11 +2051,10 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(is-assignment nil))
(while (and
not-found
- (search-backward-regexp "\\(;\\|=\\)" nil t))
+ (search-backward-regexp "\\(;\\|:\\|)\\|=\\)" nil t))
(let ((match (buffer-substring-no-properties
(match-beginning 0) (match-end 0))))
(setq is-assignment (string= match "="))
- (setq not-found nil)
- ))
+ (setq not-found nil)))
;; If it ended an assignment, decrease indentation
(when (and is-assignment
(> bracket-level -1))
@@ -2112,7 +2109,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(defun phps-mode-lex-analyzer--string-starts-with-closing-bracket-p (string)
"Get bracket count for STRING."
- (string-match-p "^[\r\t ]*\\([\]})[]\\|</[a-zA-Z]+\\|/>\\)" string))
+ (string-match-p "^[\t ]*\\([\]})[]\\|</[a-zA-Z]+\\|/>\\)" string))
(defun phps-mode-lex-analyzer--string-ends-with-assignment-p (string)
"Get bracket count for STRING."
diff --git a/phps-mode.el b/phps-mode.el
index 291aa5e..0c0b1a2 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
;; Author: Christian Johansson <address@hidden>
;; Maintainer: Christian Johansson <address@hidden>
;; Created: 3 Mar 2018
-;; Modified: 10 Apr 2020
-;; Version: 0.3.39
+;; Modified: 14 Apr 2020
+;; Version: 0.3.40
;; Keywords: tools, convenience
;; URL: https://github.com/cjohansson/emacs-phps-mode
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index 588388d..3824060 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -57,14 +57,14 @@
(phps-mode-lex-analyzer--process-changes)
'((INCREMENTAL-LEX 15)))))
- )
+ )
(defun phps-mode-test-lex-analyzer--alternative-indentation ()
"Test `phps-mode-lex-analyzer--alternative-indentation'."
(phps-mode-test--with-buffer
"<?php\nif ($myCondition) {\necho 'I was here';\n}"
- "Alternative indentation inside if block"
+ "Alternative indentation inside if block"
(goto-char 32)
(should (equal
(phps-mode-lex-analyzer--alternative-indentation)
@@ -84,7 +84,7 @@
(phps-mode-test--with-buffer
"<?php\nif ($myCondition) {\necho 'I was here';\necho 'I was here
again';\n}"
- "Alternative indentation on closing if block"
+ "Alternative indentation on closing if block"
(goto-char 30)
(should (equal
(phps-mode-lex-analyzer--alternative-indentation)
@@ -104,7 +104,7 @@
(phps-mode-test--with-buffer
"<?php\nif ($test) {\n if ($test2) {\n\n}\n}"
- "Alternative indentation on nested if block with empty contents"
+ "Alternative indentation on nested if block with empty contents"
(goto-char 40)
(should (equal
(phps-mode-lex-analyzer--alternative-indentation)
@@ -279,6 +279,24 @@
"<?php\nif ($myCondition)\n{\n $var = array(\n 'was
here'\n );\n // Was here\n}\n"
))))
+ (phps-mode-test--with-buffer
+ "<?php\nif ($myCondition == 2) {\n echo 'store_vars: <pre>' .
print_r($store_vars, true) . '</pre>';\n echo 'search_ids: <pre>' .
print_r($search_ids, true) . '</pre>';\n}"
+ "Alternative indentation on line echo"
+ (goto-char 36)
+ (should (equal
+ (phps-mode-lex-analyzer--alternative-indentation)
+ 4))
+ (goto-char 106)
+ (should (equal
+ (phps-mode-lex-analyzer--alternative-indentation)
+ 4))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($myCondition == 2) {\n echo 'store_vars: <pre>' .
print_r($store_vars, true) . '</pre>';\n echo 'search_ids: <pre>' .
print_r($search_ids, true) . '</pre>';\n}"
+ ))))
+
+
)
(defun phps-mode-test-lex-analyzer--move-lines-indent ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/phps-mode 4d72218: Improved alternative indentation after conditional equalities,
Christian Johansson <=