branch: externals/phps-mode
commit abd78a099b989a9605ca59e6a7490980a7b68beb
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Work on incremental newline logic
---
phps-mode-functions.el | 21 +++++++++++++++++++++
phps-mode-test-functions.el | 16 +++++++++++++++-
phps-mode-test-integration.el | 1 -
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index d0a84ca..5584a67 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -802,6 +802,24 @@
(setq phps-mode-functions-imenu nil)
(setq phps-mode-functions-lines-indent nil)))
+(defun phps-mode-functions-around-newline (old-function &rest arguments)
+ "Call OLD-FUNCTION with ARGUMENTS and then shift indexes if the rest of the
line is just whitespace."
+ (let ((old-pos (point))
+ (new-pos)
+ (looking-at-whitespace (looking-at-p "[\ \n\t\r]*\n")))
+ (apply old-function arguments)
+ (message "Running advice")
+ (if looking-at-whitespace
+ (progn
+ (setq new-pos (point))
+ (let ((diff (- new-pos old-pos)))
+ (when (> diff 0)
+ (phps-mode-lexer-move-tokens old-pos diff)
+ (phps-mode-lexer-move-states old-pos diff)
+ (message "Old pos %s, new pos: %s, diff: %s" old-pos new-pos
diff)
+ )))
+ (message "Not looking at white-space"))))
+
(defun phps-mode-functions-indent-line ()
"Indent line."
(phps-mode-functions-process-current-buffer)
@@ -964,6 +982,9 @@
;; MUST NOT use tabs for indenting
(set (make-local-variable 'indent-tabs-mode) nil))
+ ;; Add support for moving indexes quickly when making newlines
+ (advice-add #'newline :around #'phps-mode-functions-around-newline)
+
;; Reset flags
(set (make-local-variable 'phps-mode-functions-buffer-changes-start) nil)
(set (make-local-variable 'phps-mode-functions-lines-indent) nil)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 165fdfd..4052d76 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -854,6 +854,19 @@
)
+(defun phps-mode-test-functions-whitespace-modifications ()
+ "Test white-space modifications functions."
+ (phps-mode-test-with-buffer
+ "<?php\n$var = 'abc';\n\n$var2 = '123';\n"
+ "Add newline between two assignments and inspect moved tokens and states"
+ (message "Tokens %s" (phps-mode-lexer-get-tokens))
+ (should (equal (phps-mode-lexer-get-tokens)
+ '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13)
(T_CONSTANT_ENCAPSED_STRING 14 . 19) (";" 19 . 20) (T_VARIABLE 22 . 27) ("=" 28
. 29) (T_CONSTANT_ENCAPSED_STRING 30 . 35) (";" 35. 36))))
+ (goto-char 21)
+ (newline-and-indent)
+ (should (equal (phps-mode-lexer-get-tokens)
+ '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13)
(T_CONSTANT_ENCAPSED_STRING 14 . 19) (";" 19 . 20) (T_VARIABLE 23 . 28) ("=" 29
. 30) (T_CONSTANT_ENCAPSED_STRING 31 . 36) (";" 36. 37))))))
+
(defun phps-mode-test-functions ()
"Run test for functions."
;; (setq debug-on-error t)
@@ -868,7 +881,8 @@
(phps-mode-test-functions-get-lines-indent)
(phps-mode-test-functions-indent-line)
(phps-mode-test-functions-imenu)
- (phps-mode-test-functions-comment-uncomment-region))
+ (phps-mode-test-functions-comment-uncomment-region)
+ (phps-mode-test-functions-whitespace-modifications))
(phps-mode-test-functions)
diff --git a/phps-mode-test-integration.el b/phps-mode-test-integration.el
index 7d8d7ef..9edec18 100644
--- a/phps-mode-test-integration.el
+++ b/phps-mode-test-integration.el
@@ -31,7 +31,6 @@
(autoload 'phps-mode-test-with-buffer "phps-mode-test")
(autoload 'phps-mode-test-incremental-vs-intial-buffer "phps-mode-test")
-(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-buffer-changes-start "phps-mode-functions")