emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode ac1ec14: Improved alternative indentation aft


From: Christian Johansson
Subject: [elpa] externals/phps-mode ac1ec14: Improved alternative indentation after opening doc-comment block
Date: Mon, 4 May 2020 06:33:48 -0400 (EDT)

branch: externals/phps-mode
commit ac1ec14406753f8a2176669954d263b79619b1d1
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Improved alternative indentation after opening doc-comment block
---
 phps-mode-lex-analyzer.el           |  8 +++++
 phps-mode.el                        |  4 +--
 test/phps-mode-test-lex-analyzer.el | 68 +++++++++++++++++++++++++++++++++----
 3 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index c367dc0..add8cf0 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -2019,6 +2019,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
             (let* ((old-indentation (current-indentation))
                    (current-line-starts-with-closing-bracket 
(phps-mode-lex-analyzer--string-starts-with-closing-bracket-p 
current-line-string))
                    (line-starts-with-closing-bracket 
(phps-mode-lex-analyzer--string-starts-with-closing-bracket-p line-string))
+                   (line-starts-with-opening-doc-comment 
(phps-mode-lex-analyzer--string-starts-with-opening-doc-comment-p line-string))
                    (line-ends-with-assignment 
(phps-mode-lex-analyzer--string-ends-with-assignment-p line-string))
                    (line-ends-with-opening-bracket 
(phps-mode-lex-analyzer--string-ends-with-opening-bracket-p line-string))
                    (line-ends-with-terminus 
(phps-mode-lex-analyzer--string-ends-with-terminus-p line-string))
@@ -2041,6 +2042,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               (when current-line-starts-with-closing-bracket
                 (setq new-indentation (- new-indentation tab-width)))
 
+              (when line-starts-with-opening-doc-comment
+                (setq new-indentation (+ new-indentation 1)))
+
               (when line-ends-with-assignment
                 (setq new-indentation (+ new-indentation tab-width)))
 
@@ -2120,6 +2124,10 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
   "Get bracket count for STRING."
   (string-match-p "^[\t ]*\\([\]})[]\\|</[a-zA-Z]+\\|/>\\)" string))
 
+(defun phps-mode-lex-analyzer--string-starts-with-opening-doc-comment-p 
(string)
+  "Get bracket count for STRING."
+  (string-match-p "^[\t ]*/\\*\\*" string))
+
 (defun phps-mode-lex-analyzer--string-ends-with-opening-bracket-p (string)
   "Get bracket count for STRING."
   (string-match-p "\\([\[{(]\\|<[a-zA-Z]+\\)[\t ]*$" string))
diff --git a/phps-mode.el b/phps-mode.el
index 49fa07d..736ee8b 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: 27 Apr 2020
-;; Version: 0.3.44
+;; Modified: 4 May 2020
+;; Version: 0.3.45
 ;; 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 6514b26..7c9539f 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -59,6 +59,13 @@
 
   )
 
+(defun phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer ()
+  "Use alternative indentation of every line of buffer."
+  (goto-char (point-min))
+  (phps-mode-lex-analyzer--alternative-indentation)
+  (while (search-forward "\n" nil t nil)
+    (phps-mode-lex-analyzer--alternative-indentation)))
+
 (defun phps-mode-test-lex-analyzer--alternative-indentation ()
   "Test `phps-mode-lex-analyzer--alternative-indentation'."
 
@@ -77,6 +84,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -97,6 +105,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -113,10 +122,11 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
-              "<?php\nif ($test) {\n    if ($test2) {\n\n    }\n}"))))
+              "<?php\nif ($test) {\n    if ($test2) {\n        \n    }\n}"))))
 
   (phps-mode-test--with-buffer
    "<?php\nif ($test) {\n    if ($test2) {\n        \n    }\n\n}"
@@ -125,6 +135,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -137,6 +148,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -149,6 +161,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -161,6 +174,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             1))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -173,6 +187,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -184,7 +199,12 @@
    (goto-char 13)
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
-            0)))
+            0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal
+              buffer-contents
+              "/**\n *\n **/\n"))))
 
   (phps-mode-test--with-buffer
    "$var = 'abc';\n// Comment"
@@ -193,6 +213,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -205,6 +226,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -217,6 +239,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -229,6 +252,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -245,6 +269,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -257,6 +282,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -269,10 +295,11 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
-              "<?php\nif ($here) {\n    if ($wasHere)\n    {\n    \n    
}\n}\n\n"))))
+              "<?php\nif ($here) {\n    if ($wasHere)\n    {\n        \n    
}\n}\n\n"))))
 
   (phps-mode-test--with-buffer
    "<?php\nif ($myCondition)\n{\n    $var = array(\n        'was here'\n    
);\n// Was here\n}\n"
@@ -281,6 +308,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -298,6 +326,7 @@
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
             4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal
               buffer-contents
@@ -310,7 +339,13 @@
    (goto-char 41)
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
-            4)))
+            4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal
+              buffer-contents
+              "<?php\nif (is_array(\n    $array\n)) {\n    echo 'was here';\n}"
+              ))))
 
   (phps-mode-test--with-buffer
    "<?php\n\n$var = array(\n    '123' =>\n        'def',\n);"
@@ -322,7 +357,13 @@
    (goto-char 50)
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
-            0)))
+            0))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal
+              buffer-contents
+              "<?php\n\n$var = array(\n    '123' =>\n        'def',\n);"
+              ))))
 
   (phps-mode-test--with-buffer
    "<?php\n$var = array(\n    '123' => true,\n    \n);"
@@ -330,7 +371,13 @@
    (goto-char 44)
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
-            4)))
+            4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal
+              buffer-contents
+              "<?php\n$var = array(\n    '123' => true,\n    \n);"
+              ))))
 
   (phps-mode-test--with-buffer
    "<?php\nfunction myFunction(\n    $arg = true,\n    $arg2 = false\n) {\n    
\n}"
@@ -338,7 +385,14 @@
    (goto-char 49)
    (should (equal
             (phps-mode-lex-analyzer--alternative-indentation)
-            4)))
+            4))
+   (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal
+              buffer-contents
+              "<?php\nfunction myFunction(\n    $arg = true,\n    $arg2 = 
false\n) {\n    \n}"
+              ))))
+
   )
 
 (defun phps-mode-test-lex-analyzer--move-lines-indent ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]