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

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

[elpa] externals/phps-mode 76d72d3: Improved indentation for mixed PHP a


From: Christian Johansson
Subject: [elpa] externals/phps-mode 76d72d3: Improved indentation for mixed PHP and HTML content
Date: Mon, 7 Oct 2019 12:06:18 -0400 (EDT)

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

    Improved indentation for mixed PHP and HTML content
---
 phps-mode-analyzer.el            |  7 +++++--
 phps-mode.el                     |  4 ++--
 test/phps-mode-test-functions.el | 18 ++++++++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el
index 78e9a49..53d221c 100644
--- a/phps-mode-analyzer.el
+++ b/phps-mode-analyzer.el
@@ -2066,7 +2066,7 @@
         (line-indents nil)
         (first-object-on-line t)
         (first-object-is-nesting-decrease nil))
-    (while (string-match 
"\\([\n\C-m]\\)\\|\\(<[a-zA-Z]+\\)\\|\\(</[a-zA-Z]+\\)\\|\\(/>\\)\\|\\(\\[\\)\\|\\()\\)\\|\\((\\)"
 inline-html start)
+    (while (string-match 
"\\([\n\C-m]\\)\\|\\(<[a-zA-Z]+\\)\\|\\(</[a-zA-Z]+\\)\\|\\(/>\\)\\|\\(\\[\\)\\|\\()\\)\\|\\((\\)\\|\\({\\|}\\)"
 inline-html start)
       (let* ((end (match-end 0))
              (string (substring inline-html (match-beginning 0) end)))
 
@@ -2151,6 +2151,7 @@
               (inline-html-square-bracket-level 0)
               (inline-html-round-bracket-level 0)
               (inline-html-is-whitespace nil)
+              (inline-html-rest-is-whitespace nil)
               (first-token-is-inline-html nil)
               (after-special-control-structure nil)
               (after-special-control-structure-token nil)
@@ -2387,6 +2388,7 @@
 
                   ;; Flag whether inline-html is whitespace or not
                   (setq inline-html-is-whitespace (string= (string-trim 
(substring string (1- token-start) (1- token-end))) ""))
+                  (setq inline-html-rest-is-whitespace (string-match "^[\ 
\t]\n" (substring string (1- token-start) (1- token-end))))
 
                   (when first-token-on-line
                     (setq first-token-is-inline-html t))
@@ -2870,7 +2872,8 @@
                       (when (and (> token-start-line-number 0)
                                  (or
                                   (not first-token-is-inline-html)
-                                  inline-html-is-whitespace))
+                                  inline-html-is-whitespace
+                                  inline-html-rest-is-whitespace))
                         (phps-mode-debug-message
                          (message "Putting indent on line %s to %s at #C" 
token-start-line-number column-level-start))
                         (puthash token-start-line-number `(,column-level-start 
,tuning-level) line-indents))
diff --git a/phps-mode.el b/phps-mode.el
index 9ce64e8..02417d5 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: 30 Sep 2019
-;; Version: 0.3.4
+;; Modified: 10 Oct 2019
+;; Version: 0.3.5
 ;; 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 a44332b..8bd42ec 100644
--- a/test/phps-mode-test-functions.el
+++ b/test/phps-mode-test-functions.el
@@ -856,6 +856,13 @@
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal buffer-contents "<html>\n    <head>\n        <title><?php 
echo $title; ?></title>\n    </head>\n    <body class=\"<?php echo $class; 
?>\">\n        <div class=\"contents\"><?php echo $body; ?></div>\n    
</body>\n</html>"))))
 
+  (phps-mode-test-with-buffer
+   "<html>\n    <head>\n        <title><?php $myTitle; ?></title>\n    
</head>\n    <body>\n        <?php echo 'test'; ?>\n        <h1>My title</h1>\n 
       <?php if ($myTest): ?>\n        <div>\n            A lot of other 
stuff.\n        </div>\n        <?php endif; ?>\n    </body>\n</html>"
+   "Indent mixed HTML and one-line PHP lines."
+   (indent-region (point-min) (point-max))
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal buffer-contents "<html>\n    <head>\n        <title><?php 
$myTitle; ?></title>\n    </head>\n    <body>\n        <?php echo 'test'; ?>\n  
      <h1>My title</h1>\n        <?php if ($myTest): ?>\n        <div>\n        
    A lot of other stuff.\n        </div>\n        <?php endif; ?>\n    
</body>\n</html>"))))
+
   )
 
 (defun phps-mode-test-functions-imenu ()
@@ -1046,6 +1053,17 @@
                    0
                    ))))
 
+  (should (equal
+           '(0 1 2 1 0)
+           (nth 0 (phps-mode-functions--get-inline-html-indentation
+                   "<script type=\"text/javascript\">\n    if (something()) 
{\n        alert('Something here');\n    }\n</script>\n"
+                   0
+                   0
+                   0
+                   0
+                   0
+                   ))))
+
   )
 
 (defun phps-mode-test-functions ()



reply via email to

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