branch: externals/phps-mode
commit 34f36e6b43a9a78fd5338632b2f88e76bcb394e9
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Passing basic test narrow-to-defun, end-of-defun, beginning-of-defun
---
phps-mode-lex-analyzer.el | 19 ++++++-------------
test/phps-mode-test-lex-analyzer.el | 21 +++++++++++++++++++--
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index d594334b0c..634af06d69 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1516,6 +1516,7 @@ of performed operations. Optionally do it
FORCE-SYNCHRONOUS."
(index 0)
(found-index t))
(save-excursion
+ (move-end-of-line nil)
(while (and found-index (< index iterations))
(if
(search-backward-regexp
@@ -1541,16 +1542,13 @@ of performed operations. Optionally do it
FORCE-SYNCHRONOUS."
(when (phps-mode-lex-analyzer--beginning-of-defun)
(let ((beginning (point))
(bracket-level 0)
- (found-initial-bracket)
- (next-bracket (search-forward-regexp "[{}\"']" nil t)))
- (message "beginning: %S" beginning)
+ (found-initial-bracket))
(while (and
- next-bracket
(or
(not found-initial-bracket)
- (not (= bracket-level 0))))
+ (not (= bracket-level 0)))
+ (search-forward-regexp "[{}\"']" nil t))
(let ((match-string (match-string 0)))
- (message "match-string: %S" match-string)
(cond
((string= match-string "{")
(unless found-initial-bracket
@@ -1559,17 +1557,12 @@ of performed operations. Optionally do it
FORCE-SYNCHRONOUS."
((string= match-string "}")
(setq bracket-level (1- bracket-level)))
((string= match-string "\"")
+
;; TODO Handle double quoted string here
)
((string= match-string "'")
;; TODO Handle single-quoted string here
- )))
- (unless (and
- found-initial-bracket
- (= bracket-level 0))
- (setq
- next-bracket
- (search-forward-regexp "[{}\"']" nil t))))
+ ))))
(when (and
(= bracket-level 0)
found-initial-bracket)
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index 946903be63..bff8959257 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -157,12 +157,29 @@
(phps-mode-test--with-buffer
"<?php\nfunction test($a) {\n return $a + 1;\n}\necho 'here';\n"
- "Test beginning-of-defun and end-of-defun"
+ "Test `beginning-of-defun', `end-of-defun' and `narrow-to-defun' basic
example"
(goto-char 27)
(should (equal (phps-mode-lex-analyzer--beginning-of-defun) t))
(should (equal (point) 7))
(should (equal (phps-mode-lex-analyzer--end-of-defun) t))
- (should (equal (point) 47)))
+ (should (equal (point) 47))
+ (goto-char 27)
+ (narrow-to-defun)
+ (should (equal (point-min) 7))
+ (should (equal (point-max) 48)))
+
+ (phps-mode-test--with-buffer
+ "<?php\nfunction test2($a) {\n echo 'was there }';\n echo \"was here
\\\\\"}\\\\\" or there\";\n return $a + 1;\n}"
+ "Test `beginning-of-defun', `end-of-defun' and `narrow-to-defun' advanced
example"
+ (goto-char 41)
+ (should (equal (phps-mode-lex-analyzer--beginning-of-defun) t))
+ (should (equal (point) 7))
+ (should (equal (phps-mode-lex-analyzer--end-of-defun) t))
+ (should (equal (point) 108))
+ (goto-char 65)
+ (narrow-to-defun)
+ (should (equal (point-min) 7))
+ (should (equal (point-max) 108)))
)