Skip to content
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

Add php-topsy-beginning-of-defun-with-class for Topsy #766

Merged
merged 1 commit into from
Nov 18, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this

## Unreleased

### Added

* Add `php-topsy-beginning-of-defun-with-class` to display classname with function signature. ([#766])

### Removed

* Removed Phan-specific features from `php-project` ([#754])

[#754]: https://github.com/emacs-php/php-mode/pull/754
[#766]: https://github.com/emacs-php/php-mode/pull/766

## [1.25.0] - 2023-07-24

Expand Down
31 changes: 31 additions & 0 deletions lisp/php.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ a completion list."
:type 'integer
:link '(url-link :tag "Built-in web server"
"https://www.php.net/manual/features.commandline.webserver.php"))

(defcustom php-topsy-separator " > "
"Separator string for `php-topsy-beginning-of-defun-with-class'."
:group 'php
:tag "PHP Topsy Separator"
:type 'string)

;;; PHP Keywords
(defconst php-magical-constants
Expand Down Expand Up @@ -655,6 +661,31 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
(if (string= class "") "" (concat "\\" class "::"))
(if (string= namedfunc "") "" (concat namedfunc "()"))))))

(defun php-topsy-beginning-of-defun-with-class ()
"Return function signature and class name string for header line in topsy.

You can add the function to topsy with the code below:
\(add-to-list 'topsy-mode-functions '(php-mode . php-topsy-beginning-of-defun-with-class))"
(save-excursion
(goto-char (window-start))
(mapconcat
#'identity
(append
(save-match-data
(save-excursion
(when (re-search-backward php--re-classlike-pattern nil t)
(font-lock-ensure (point) (line-end-position))
(list (string-trim (buffer-substring (point) (line-end-position)))))))
(progn
(beginning-of-defun)
(font-lock-ensure (point) (line-end-position))
(list (string-trim
(replace-regexp-in-string
(eval-when-compile (rx bos "<?php"))
""
(buffer-substring (point) (line-end-position)))))))
php-topsy-separator)))

;;;###autoload
(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root)
"Run PHP Built-in web server.
Expand Down
Loading