branch: externals/phps-mode
commit e7c6888248a228604d8d619200a554017c46abf5
Author: Christian Johansson <christ...@cvj.se>
Commit: Christian Johansson <christ...@cvj.se>

    Improved end-of-defun, beginning-of-defun and narrow-to-defun by taking 
commented out code into account
---
 phps-mode-lex-analyzer.el           | 13 ++++++++++---
 test/phps-mode-test-lex-analyzer.el | 13 +++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index e3b66ba516..33b8826faa 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1554,8 +1554,8 @@ of performed operations.  Optionally do it 
FORCE-SYNCHRONOUS."
                     (or
                      (not found-initial-bracket)
                      (not (= bracket-level 0)))
-                    (search-forward-regexp "[{}\"']" nil t))
-              (let ((match-string (match-string 0)))
+                    (search-forward-regexp "\\(/\\*\\|[{}\"'#]\\|//\\)" nil t))
+              (let ((match-string (match-string-no-properties 0)))
                 (cond
                  ((string= match-string "{")
                   (unless found-initial-bracket
@@ -1610,7 +1610,14 @@ of performed operations.  Optionally do it 
FORCE-SYNCHRONOUS."
                               (setq quote-ending-at (point)))))))
                     (if quote-ending-at
                         (goto-char quote-ending-at)
-                      (setq failed-to-find-ending-quote t)))))))
+                      (setq failed-to-find-ending-quote t))))
+                 ((or
+                   (string= match-string "#")
+                   (string= match-string "//"))
+                  (forward-line)
+                  )
+                 ((string= match-string "/*")
+                  (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 f906f9dc54..02c460054a 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -194,6 +194,19 @@
    (should (equal (point-min) 20))
    (should (equal (point-max) 58)))
 
+  (phps-mode-test--with-buffer
+   "<?php\nnamespace myNamespace\n{\n    class myClass\n    {\n        
function myFunction($arg)\n        {\n            /**\n             * if ($arg) 
{ return true; }\n             */\n            if ($arg) {\n                // 
}}\n                # }}\n            }\n            return false;\n        }\n 
   }\n}"
+   "Test `beginning-of-defun', `end-of-defun' and `narrow-to-defun' with 
commented-out code."
+   (goto-char 148)
+   (should (equal (phps-mode-lex-analyzer--beginning-of-defun) t))
+   (should (equal (point) 55))
+   (should (equal (phps-mode-lex-analyzer--end-of-defun) t))
+   (should (equal (point) 289))
+   (goto-char 253)
+   (narrow-to-defun)
+   (should (equal (point-min) 55))
+   (should (equal (point-max) 290)))
+
   )
 
 (defun phps-mode-test-lex-analyzer ()

Reply via email to