[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline logic |
Date: |
Sat, 13 Jul 2019 10:00:48 -0400 (EDT) |
branch: externals/phps-mode
commit abd78a099b989a9605ca59e6a7490980a7b68beb
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
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")
- [elpa] externals/phps-mode d27af61 327/405: Fixed bug with incremental lexer were states are missing, (continued)
- [elpa] externals/phps-mode d27af61 327/405: Fixed bug with incremental lexer were states are missing, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 32f9808 329/405: indent and imenu now triggers incremental lexer if buffer changed, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 365d739 324/405: Changed structure of integration tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2807902 343/405: Added syntax coloring for %, =, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1bac28a 352/405: Updated readme with decreased percent for indent, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2801604 350/405: Added TODO item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c80aa68 351/405: Added a new failing test for indentation of else expression inside switch, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a8fbe7d 344/405: Improved syntax coloring of =, % and more, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 64e1789 356/405: Fixed indentation were assignments end at next line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 83d5de8 355/405: Removed uneccesary debug output in unit test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline logic,
Stefan Monnier <=
- [elpa] externals/phps-mode d8ad25b 341/405: Passes new test indentation of multi-line double-arrow inside assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e7cb803 346/405: Added another indentation test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dabe0ea 345/405: Added failing indentation test for multi-dimension array in assignment with double arrows, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d6e6cbc 358/405: Another optimization of line-number-at-pos inside loop, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e681c9c 347/405: Updated color syntax for T_STRING tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c11bcc5 360/405: More work on newline advice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 282115f 357/405: Using incremental line-number calculation as optimization, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c118f58 342/405: Added TODO items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 812dc49 353/405: Removed TODO item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 834275b 354/405: Fixed indentation calculation of nested alternative control structures, Stefan Monnier, 2019/07/13