Skip to content

Function php-beginning-of-defun should return non-nil on success #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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.

## [1.21.2]

### Fixed

* Function `php-beginning-of-defun` should return non-nil on success
([#503](https://github.com/emacs-php/php-mode/issues/503))

## [1.21.1] - 2019-04-01

### Changed
Expand Down
24 changes: 24 additions & 0 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,28 @@ as a keyword."
(should (string= (abbreviate-file-name default-directory)
(php-project-get-root-dir))))

(defun php-mode-test-in-function-p (&optional pos)
"Determine whether POS is inside a function.
Meant for `php-mode-test-issue-503'."
(let (bof (pos (or pos (point))))
(save-excursion
(when (beginning-of-defun)
(setq bof (point))
(end-of-defun)
(and (> pos bof)
(< pos (point)))))))

(ert-deftest php-mode-test-issue-503 ()
"Function `php-beginning-of-defun' should return non-nil on success."
(with-php-mode-test
("issue-503.php")
(php-mode)
(goto-char (point-max))
(should (eq (php-mode-test-in-function-p) nil))
(should (eq (php-mode-test-in-function-p (1- (point))) t))
(should (eq (php-mode-test-in-function-p 1) nil))
(should (eq (php-mode-test-in-function-p 24) t))
(goto-char (point-min))
(should (eq (php-mode-test-in-function-p nil) nil))))

;;; php-mode-test.el ends here
13 changes: 7 additions & 6 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,10 @@ but only if the setting is enabled"
"Move to the beginning of the ARGth PHP function from point.
Implements PHP version of `beginning-of-defun-function'."
(interactive "p")
(let ((arg (or arg 1)))
(let (found-p (arg (or arg 1)))
(while (> arg 0)
(re-search-backward php-beginning-of-defun-regexp
nil 'noerror)
(setq found-p (re-search-backward php-beginning-of-defun-regexp
nil 'noerror))
(setq arg (1- arg)))
(while (< arg 0)
(end-of-line 1)
Expand All @@ -798,9 +798,10 @@ Implements PHP version of `beginning-of-defun-function'."
(forward-list 2)
(forward-line 1)
(if (eq opoint (point))
(re-search-forward php-beginning-of-defun-regexp
nil 'noerror))
(setq arg (1+ arg))))))
(setq found-p (re-search-forward php-beginning-of-defun-regexp
nil 'noerror)))
(setq arg (1+ arg))))
(not (null found-p))))

(defun php-end-of-defun (&optional arg)
"Move the end of the ARGth PHP function from point.
Expand Down
4 changes: 4 additions & 0 deletions tests/issue-503.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
function foo () {

}