[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 42239f9: Improved token-blind indentation for
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 42239f9: Improved token-blind indentation for closing brackets and doc-block comments |
Date: |
Thu, 12 Dec 2019 01:00:17 -0500 (EST) |
branch: externals/phps-mode
commit 42239f95715a65d7b92bdd986d7bfeeae391660e
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Improved token-blind indentation for closing brackets and doc-block comments
---
phps-mode-analyzer.el | 23 +++++++++++++++++------
phps-mode.el | 4 ++--
test/phps-mode-test-functions.el | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el
index 7b2ee74..5dd928d 100644
--- a/phps-mode-analyzer.el
+++ b/phps-mode-analyzer.el
@@ -3313,7 +3313,12 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(forward-line move-length)
(when (> bracket-level 0)
- (setq new-indentation (+ new-indentation tab-width)))
+ (if (< bracket-level tab-width)
+ (setq new-indentation (+ new-indentation 1))
+ (setq new-indentation (+ new-indentation tab-width))))
+
+ (when (= bracket-level -1)
+ (setq new-indentation (1- new-indentation)))
(when (and (= bracket-level 0)
line-starts-with-closing-bracket)
@@ -3341,7 +3346,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(string-match-p "^[ \t\f\r\n]*$" string)))
(unless line-is-empty
(while (string-match
- "\\([\]{}()[]\\|<[a-zA-Z]+\\|</[a-zA-Z]+\\|/>\\)"
+ "\\([\]{}()[]\\|<[a-zA-Z]+\\|</[a-zA-Z]+\\|/>\\|^/\\*\\*\\|^
\\*/\\)"
string
start)
(setq start (match-end 0))
@@ -3353,14 +3358,20 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(string= bracket "(")
(string= bracket "<")
(string-match "<[a-zA-Z]+" bracket))
- (setq bracket-level (1+ bracket-level)))
+ (setq bracket-level (+ bracket-level tab-width)))
+ ((string-match "^ \\*/" bracket )
+ (setq bracket-level (- bracket-level 1)))
+ ((or
+ (string-match "^/\\*\\*" bracket)
+ (string-match "^ \\*" bracket))
+ (setq bracket-level (+ bracket-level 1)))
(t
- (setq bracket-level (1- bracket-level)))))))
- (* bracket-level tab-width)))
+ (setq bracket-level (- bracket-level tab-width)))))))
+ bracket-level))
(defun phps-mode-analyzer--string-starts-with-closing-bracket-p (string)
"Get bracket count for STRING."
- (string-match-p "^\\([\]{}()[]\\|<[a-zA-Z]+\\|</[a-zA-Z]+\\|/>\\)" string))
+ (string-match-p "^[\n\r\t ]*\\([\]{}()[]\\|<[a-zA-Z]+\\|</[a-zA-Z]+\\|/>\\)"
string))
(defun phps-mode-functions--cancel-idle-timer ()
"Cancel idle timer."
diff --git a/phps-mode.el b/phps-mode.el
index 957f7da..2b7f7df 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 Dec 2019
-;; Version: 0.3.23
+;; Modified: 12 Dec 2019
+;; Version: 0.3.24
;; Keywords: tools, convenience
;; URL: https://github.com/cjohansson/emacs-phps-mode
diff --git a/test/phps-mode-test-functions.el b/test/phps-mode-test-functions.el
index 77aaf14..739c865 100644
--- a/test/phps-mode-test-functions.el
+++ b/test/phps-mode-test-functions.el
@@ -142,6 +142,42 @@
buffer-contents
"<?php\nif ($test) {\n \n} else if ($test) {\n \n}\n"))))
+ (phps-mode-test-with-buffer
+ "if ($true) {\n if ($true) {\n }\n}"
+ "Alternative indentation on closing bracket inside parent bracket"
+ (goto-char 36)
+ (should (equal
+ (phps-mode-analyzer--alternative-indentation)
+ 4))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "if ($true) {\n if ($true) {\n }\n}"))))
+
+ (phps-mode-test-with-buffer
+ "/**\n *\n */"
+ "Alternative indentation on last line of doc comment block"
+ (goto-char 11)
+ (should (equal
+ (phps-mode-analyzer--alternative-indentation)
+ 1))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "/**\n *\n */"))))
+
+ (phps-mode-test-with-buffer
+ "/**\n *\n */\n"
+ "Alternative indentation on line after closing of doc comment block"
+ (goto-char 12)
+ (should (equal
+ (phps-mode-analyzer--alternative-indentation)
+ 0))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "/**\n *\n */\n"))))
+
)
(defun phps-mode-test-functions-move-lines-indent ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/phps-mode 42239f9: Improved token-blind indentation for closing brackets and doc-block comments,
Christian Johansson <=