Skip to content

Commit 1da0573

Browse files
authored
Merge pull request #504 from sergeyklay/fix/beginning-of-defun-function
Function php-beginning-of-defun should return non-nil on success
2 parents bcde734 + f79ec8d commit 1da0573

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes of the PHP Mode 1.19.1 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [1.21.2]
6+
7+
### Fixed
8+
9+
* Function `php-beginning-of-defun` should return non-nil on success
10+
([#503](https://github.com/emacs-php/php-mode/issues/503))
11+
512
## [1.21.1] - 2019-04-01
613

714
### Changed

php-mode-test.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,4 +949,28 @@ as a keyword."
949949
(should (string= (abbreviate-file-name default-directory)
950950
(php-project-get-root-dir))))
951951

952+
(defun php-mode-test-in-function-p (&optional pos)
953+
"Determine whether POS is inside a function.
954+
Meant for `php-mode-test-issue-503'."
955+
(let (bof (pos (or pos (point))))
956+
(save-excursion
957+
(when (beginning-of-defun)
958+
(setq bof (point))
959+
(end-of-defun)
960+
(and (> pos bof)
961+
(< pos (point)))))))
962+
963+
(ert-deftest php-mode-test-issue-503 ()
964+
"Function `php-beginning-of-defun' should return non-nil on success."
965+
(with-php-mode-test
966+
("issue-503.php")
967+
(php-mode)
968+
(goto-char (point-max))
969+
(should (eq (php-mode-test-in-function-p) nil))
970+
(should (eq (php-mode-test-in-function-p (1- (point))) t))
971+
(should (eq (php-mode-test-in-function-p 1) nil))
972+
(should (eq (php-mode-test-in-function-p 24) t))
973+
(goto-char (point-min))
974+
(should (eq (php-mode-test-in-function-p nil) nil))))
975+
952976
;;; php-mode-test.el ends here

php-mode.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ but only if the setting is enabled"
786786
"Move to the beginning of the ARGth PHP function from point.
787787
Implements PHP version of `beginning-of-defun-function'."
788788
(interactive "p")
789-
(let ((arg (or arg 1)))
789+
(let (found-p (arg (or arg 1)))
790790
(while (> arg 0)
791-
(re-search-backward php-beginning-of-defun-regexp
792-
nil 'noerror)
791+
(setq found-p (re-search-backward php-beginning-of-defun-regexp
792+
nil 'noerror))
793793
(setq arg (1- arg)))
794794
(while (< arg 0)
795795
(end-of-line 1)
@@ -798,9 +798,10 @@ Implements PHP version of `beginning-of-defun-function'."
798798
(forward-list 2)
799799
(forward-line 1)
800800
(if (eq opoint (point))
801-
(re-search-forward php-beginning-of-defun-regexp
802-
nil 'noerror))
803-
(setq arg (1+ arg))))))
801+
(setq found-p (re-search-forward php-beginning-of-defun-regexp
802+
nil 'noerror)))
803+
(setq arg (1+ arg))))
804+
(not (null found-p))))
804805

805806
(defun php-end-of-defun (&optional arg)
806807
"Move the end of the ARGth PHP function from point.

tests/issue-503.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
function foo () {
3+
4+
}

0 commit comments

Comments
 (0)