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

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

[elpa] externals/phps-mode efcefde 035/405: Added support for closing pa


From: Stefan Monnier
Subject: [elpa] externals/phps-mode efcefde 035/405: Added support for closing parenthesis and braces
Date: Sat, 13 Jul 2019 09:59:35 -0400 (EDT)

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

    Added support for closing parenthesis and braces
---
 phps-functions.el      | 14 ++++++++++----
 phps-test-functions.el | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/phps-functions.el b/phps-functions.el
index 677d19a..1d26588 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -41,12 +41,18 @@
   (let ((data (phps-mode/lexer-get-point-data)))
     (save-excursion
       (beginning-of-line)
-      (let ((start (nth 0 data))
-            (end (nth 1 data)))
+      (let* ((start (nth 0 data))
+             (end (nth 1 data))
+             (in-scripting (nth 0 start)))
 
         ;; Are we in scripting?
-        (if (nth 0 start)
-            (let ((indent-level (* (+ (nth 1 start) (nth 2 start)) 4)))
+        (if in-scripting
+            (let* ((indent-start (* (+ (nth 1 start) (nth 2 start)) 4))
+                   (indent-end (* (+ (nth 1 end) (nth 2 end)) 4))
+                   (indent-diff 0))
+              (when (> indent-start indent-end)
+                (setq indent-diff (- indent-start indent-end)))
+              (setq 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))
           (progn
diff --git a/phps-test-functions.el b/phps-test-functions.el
index 350c0cd..f5f637f 100644
--- a/phps-test-functions.el
+++ b/phps-test-functions.el
@@ -64,7 +64,7 @@
    (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 $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\n}\n?>\n</title><body>Bla bla</body></html>"
@@ -74,6 +74,20 @@
    (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>"))))
 
+  (phps-mode/with-test-buffer
+   "<?php\n$variable = array(\n'random'\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"))))
+
+(phps-mode/with-test-buffer
+   "<?php\n$variable = array(\n    'random'\n    );\n$variable = true;\n"
+   (goto-char 39)
+   (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"))))
+
   )
 
 (defun phps-mod/test-functions ()



reply via email to

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