[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8587c24bbd 09/12: Passing tests for beginning
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 8587c24bbd 09/12: Passing tests for beginning-of-defun, end-of-defun and narrow-to-defun |
Date: |
Mon, 13 Feb 2023 12:39:22 -0500 (EST) |
branch: externals/phps-mode
commit 8587c24bbddb547d4178b263d9589615cf62ece3
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing tests for beginning-of-defun, end-of-defun and narrow-to-defun
---
phps-mode-lex-analyzer.el | 165 +++++++++++++++++++-----------------
test/phps-mode-test-lex-analyzer.el | 13 +++
2 files changed, 98 insertions(+), 80 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index deeb62ac47..e3b66ba516 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1518,100 +1518,105 @@ of performed operations. Optionally do it
FORCE-SYNCHRONOUS."
(save-excursion
(move-end-of-line nil)
(while (and found-index (< index iterations))
- (if
+ (setq found-index nil)
+ (setq index (1+ index))
+ (when
(search-backward-regexp
"[\n\t ]+function\\([\t\n ]+\\|(\\)"
nil
t)
- (progn
- (search-forward-regexp
- "[\n]+")
- (setq found-index (point)))
- (setq found-index nil))
- (setq index (1+ index))))
+ (search-forward-regexp "[\n]*")
+ (move-beginning-of-line nil)
+ (setq found-index (point)))))
(if found-index
(progn
(goto-char found-index)
t)
nil)))
-(defun phps-mode-lex-analyzer--end-of-defun (&optional arg interactive)
+(defun phps-mode-lex-analyzer--end-of-defun (&optional arg _interactive)
"Custom implementation of `end-of-defun'."
- (let ((found-index))
+ (let ((found-index t)
+ (index 0)
+ (iterations (if arg arg 1)))
(save-excursion
- (when (phps-mode-lex-analyzer--beginning-of-defun)
- (let ((beginning (point))
- (bracket-level 0)
- (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)))
- (search-forward-regexp "[{}\"']" nil t))
- (let ((match-string (match-string 0)))
- (cond
- ((string= match-string "{")
- (unless found-initial-bracket
- (setq found-initial-bracket t))
- (setq bracket-level (1+ bracket-level)))
- ((string= match-string "}")
- (setq bracket-level (1- bracket-level)))
- ((string= match-string "\"")
- (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
+ (while (and
+ found-index
+ (< index iterations))
+ (setq found-index nil)
+ (setq index (1+ index))
+ (when (phps-mode-lex-analyzer--beginning-of-defun)
+ (let ((bracket-level 0)
+ (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)))
+ (search-forward-regexp "[{}\"']" nil t))
+ (let ((match-string (match-string 0)))
+ (cond
+ ((string= match-string "{")
+ (unless found-initial-bracket
+ (setq found-initial-bracket t))
+ (setq bracket-level (1+ bracket-level)))
+ ((string= match-string "}")
+ (setq bracket-level (1- bracket-level)))
+ ((string= match-string "\"")
+ (let ((is-escaped)
+ (quote-ending-at))
(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 "'")
- (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
+ (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 "'")
+ (let ((is-escaped)
+ (quote-ending-at))
(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)
- (setq
- found-index
- (point))))))
+ (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)
+ (setq
+ found-index
+ (point)))))))
(if found-index
(progn
(goto-char found-index)
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index 1d0f95a834..f906f9dc54 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -181,6 +181,19 @@
(should (equal (point-min) 7))
(should (equal (point-max) 108)))
+ (phps-mode-test--with-buffer
+ "<?php\necho 'here';\n$var = function() {\n echo 'here';\n};\necho
'there';"
+ "Test `beginning-of-defun', `end-of-defun' and `narrow-to-defun' for a
anonymous function."
+ (goto-char 53)
+ (should (equal (phps-mode-lex-analyzer--beginning-of-defun) t))
+ (should (equal (point) 20))
+ (should (equal (phps-mode-lex-analyzer--end-of-defun) t))
+ (should (equal (point) 58))
+ (goto-char 47)
+ (narrow-to-defun)
+ (should (equal (point-min) 20))
+ (should (equal (point-max) 58)))
+
)
(defun phps-mode-test-lex-analyzer ()
- [elpa] externals/phps-mode updated (a32f68a0d4 -> 7619526596), Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 1bb2af276e 02/12: Started on support for narrow-to-defun, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 3c0de0167e 03/12: Merge branch 'master' of git.cvj.se:git/emacs-phps-mode, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 295cd646d3 01/12: Added TODO item, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode f197368bb7 04/12: Started custom implementation of beginning-of-defun, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 99fbd99129 08/12: Passing more advanced case of narrow-to-defun, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 72eec26571 11/12: Made test output more pedagogical, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode da43f8d5ad 05/12: More work on beginning-of-defun, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 34f36e6b43 07/12: Passing basic test narrow-to-defun, end-of-defun, beginning-of-defun, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 8587c24bbd 09/12: Passing tests for beginning-of-defun, end-of-defun and narrow-to-defun,
Christian Johansson <=
- [elpa] externals/phps-mode cef3c1b3f7 06/12: More work on end-of-defun implementation, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode e7c6888248 10/12: Improved end-of-defun, beginning-of-defun and narrow-to-defun by taking commented out code into account, Christian Johansson, 2023/02/13
- [elpa] externals/phps-mode 7619526596 12/12: Updated version and changelog for 0.4.38, Christian Johansson, 2023/02/13