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

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

[elpa] externals/phps-mode 5bc592a 368/405: More work on moving indent i


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 5bc592a 368/405: More work on moving indent indexes
Date: Sat, 13 Jul 2019 10:00:52 -0400 (EDT)

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

    More work on moving indent indexes
---
 phps-mode-functions.el      | 30 +++++++++++++++++-------------
 phps-mode-test-functions.el | 13 +++++++++++++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 16c7340..4de504b 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -69,20 +69,24 @@
     (phps-mode-functions--process-current-buffer)
     (setq phps-mode-functions-processed-buffer t)))
 
-;; TODO Fix this function
+(defun phps-mode-functions-get-moved-lines-indent (old-lines-indents 
start-line-number diff)
+  "Move OLD-LINES-INDENTS from START-LINE-NUMBER with DIFF points."
+  (let ((lines-indents (make-hash-table :test 'equal))
+        (line-number 1))
+    (let ((line-indent (gethash line-number old-lines-indents)))
+      (while line-indent
+        (if (< line-number start-line-number)
+            (puthash line-number line-indent lines-indents)
+          (setq new-line-number (1+ line-number))
+          (puthash new-line-number line-indent lines-indents)
+          (message "Added new indent %s from %s to %s" line-indent line-number 
new-line-number))
+        (setq line-number (1+ line-number))
+        (setq line-indent (gethash line-number old-lines-indents))))
+    lines-indents))
+
 (defun phps-mode-functions-move-lines-indent (start-line-number diff)
-  "Move line-indent index from START-LINE-NUMBER with DIFF amount."
-  (let ((lines-indent (phps-mode-functions-get-lines-indent))
-        (line-number (+ start-line-number diff)))
-    (when lines-indent
-      (let ((line-indent (gethash line-number 
phps-mode-functions-lines-indent)))
-        (while line-indent
-          (when (not (= line-number start-line-number))
-            (puthash (1- line-number) line-indent lines-indent)
-            )
-          (setq line-number (1+ line-number))
-          (setq line-indent (gethash line-number lines-indent)))
-        (setq phps-mode-functions-lines-indent lines-indent)))))
+  "Move lines indent from START-LINE-NUMBER with DIFF points."
+  (setq phps-mode-functions-lines-indent 
(phps-mode-functions-get-moved-lines-indent phps-mode-functions-lines-indent 
start-line-number diff)))
 
 (defun phps-mode-functions-get-lines-indent ()
   "Return lines indent, process buffer if not done already."
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e843588..7579027 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -34,10 +34,22 @@
 (autoload 'phps-mode-functions-indent-line "phps-mode-functions")
 (autoload 'phps-mode-functions-get-lines-indent "phps-mode-functions")
 (autoload 'phps-mode-functions-get-imenu "phps-mode-functions")
+(autoload 'phps-mode-functions-get-moved-lines-indent "phps-mode-functions")
 (autoload 'phps-mode-test-hash-to-list "phps-mode-test")
 (autoload 'phps-mode-lexer-get-tokens "phps-mode-lexer")
 (autoload 'should "ert")
 
+(defun phps-mode-test-functions-move-lines-indent ()
+  "Test `phps-mode-functions-move-lines-indent'."
+
+  (phps-mode-test-with-buffer
+   "<?php\n/**\n * Bla\n */"
+   "DOC-COMMENT"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 1)) (4 (0 1))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 1)) (5 (0 1))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-moved-lines-indent 
(phps-mode-functions-get-lines-indent) 2 1)))))
+
+  )
+
 (defun phps-mode-test-functions-get-lines-indent ()
   "Test `phps-mode-functions-get-lines-indent' function."
   
@@ -902,6 +914,7 @@
   (phps-mode-test-functions-indent-line)
   (phps-mode-test-functions-imenu)
   (phps-mode-test-functions-comment-uncomment-region)
+  (phps-mode-test-functions-move-lines-indent)
   (phps-mode-test-functions-whitespace-modifications))
 
 (phps-mode-test-functions)



reply via email to

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