branch: externals/phps-mode
commit 99fbd9912997ac1e95494556e7b51c2c37535bac
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Passing more advanced case of narrow-to-defun
---
phps-mode-lex-analyzer.el | 57 ++++++++++++++++++++++++++++++++-----
test/phps-mode-test-lex-analyzer.el | 2 +-
2 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 634af06d69..deeb62ac47 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1520,7 +1520,7 @@ of performed operations. Optionally do it
FORCE-SYNCHRONOUS."
(while (and found-index (< index iterations))
(if
(search-backward-regexp
- "\n[\t ]*function[\t\n ]+[A-Za-Z_[:nonascii:]]"
+ "[\n\t ]+function\\([\t\n ]+\\|(\\)"
nil
t)
(progn
@@ -1542,8 +1542,10 @@ 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))
+ (found-initial-bracket)
+ (failed-to-find-ending-quote))
(while (and
+ (not failed-to-find-ending-quote)
(or
(not found-initial-bracket)
(not (= bracket-level 0)))
@@ -1557,12 +1559,53 @@ 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
- )
+ (let ((is-escaped)
+ (quote-ending-at))
+ (save-excursion
+ (backward-char 2)
+ (while (looking-at-p "\\\\")
+ (setq is-escaped (not is-escaped))
+ (backward-char)))
+ (unless is-escaped
+ (save-excursion
+ (while (and
+ (not quote-ending-at)
+ (search-forward-regexp "\"" nil t))
+ (let ((is-escaped-ending))
+ (save-excursion
+ (backward-char 2)
+ (while (looking-at-p "\\\\")
+ (setq is-escaped-ending (not is-escaped-ending))
+ (backward-char)))
+ (unless is-escaped-ending
+ (setq quote-ending-at (point)))))))
+ (if quote-ending-at
+ (goto-char quote-ending-at)
+ (setq failed-to-find-ending-quote t))))
((string= match-string "'")
- ;; TODO Handle single-quoted string here
- ))))
+ (let ((is-escaped)
+ (quote-ending-at))
+ (save-excursion
+ (backward-char 2)
+ (while (looking-at-p "\\\\")
+ (setq is-escaped (not is-escaped))
+ (backward-char)))
+ (unless is-escaped
+ (save-excursion
+ (while (and
+ (not quote-ending-at)
+ (search-forward-regexp "'" nil t))
+ (let ((is-escaped-ending))
+ (save-excursion
+ (backward-char 2)
+ (while (looking-at-p "\\\\")
+ (setq is-escaped-ending (not is-escaped-ending))
+ (backward-char)))
+ (unless is-escaped-ending
+ (setq quote-ending-at (point)))))))
+ (if quote-ending-at
+ (goto-char quote-ending-at)
+ (setq failed-to-find-ending-quote 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 bff8959257..1d0f95a834 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -169,7 +169,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}"
+ "<?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))