branch: externals/phps-mode commit f197368bb77b3d2b870a09ee76b41153b621e1c2 Author: christian <christ...@cvj.se> Commit: christian <christ...@cvj.se>
Started custom implementation of beginning-of-defun --- TODO.md | 2 -- phps-mode-lex-analyzer.el | 27 +++++++++++++++++++++++++++ test/phps-mode-test-lex-analyzer.el | 13 +++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index a0231eb4b7..728dd9ec14 100644 --- a/TODO.md +++ b/TODO.md @@ -33,6 +33,4 @@ ## Other * Support for mmm-mode or similar? -* Make narrow-to-defun work in case character 26 in - <?php\nfunction test($a) {\n return $a + 1;\n}\n" diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el index b1a1d919f0..024ab78cf2 100644 --- a/phps-mode-lex-analyzer.el +++ b/phps-mode-lex-analyzer.el @@ -1510,6 +1510,33 @@ of performed operations. Optionally do it FORCE-SYNCHRONOUS." data))))) +(defun phps-mode-lex-analyzer--beginning-of-defun (&optional arg) + "Custom implementation of `beginning-of-defun'." + (let ((iterations (if arg arg 1)) + (index 0) + (found-index t)) + (save-excursion + (while (and found-index (< index iterations)) + (if + (search-backward-regexp + "\n[\t ]*function[\t\n ]+[A-Za-Z_[:nonascii:]]" + nil + t) + (progn + (search-forward-regexp + "[\n]+") + (setq found-index (point))) + (setq found-index nil)) + (setq index (1+ index)))) + (when found-index + (goto-char found-index)) + found-index)) + +(defun phps-mode-lex-analyzer--end-of-defun (&optional arg interactive) + "Custom implementation of `end-of-defun'." + ;; TODO Implement this + ) + (provide 'phps-mode-lex-analyzer) ;;; phps-mode-lex-analyzer.el ends here diff --git a/test/phps-mode-test-lex-analyzer.el b/test/phps-mode-test-lex-analyzer.el index c473f10c1b..5480b97282 100644 --- a/test/phps-mode-test-lex-analyzer.el +++ b/test/phps-mode-test-lex-analyzer.el @@ -152,9 +152,22 @@ ) +(defun phps-mode-test-lex-analyzer--narrow-to-defun () + "Test (narrow-to-defun)." + + (phps-mode-test--with-buffer + "<?php\nfunction test($a) {\n return $a + 1;\n}\necho 'here';\n" + (goto-char 27) + (narrow-to-defun) + (should (equal (point-min) 7)) + (should (equal (point-max) 47))) + + ) + (defun phps-mode-test-lex-analyzer () "Run test for functions." ;; (setq debug-on-error t) + (phps-mode-test-lex-analyzer--narrow-to-defun) (phps-mode-test-lex-analyzer--process-changes) (phps-mode-test-lex-analyzer--get-moved-imenu) (phps-mode-test-lex-analyzer--comment-uncomment-region))