Skip to content

Commit d46195c

Browse files
authored
Merge pull request #766 from emacs-php/feature/topsy-functions
Add php-topsy-beginning-of-defun-with-class for Topsy
2 parents 4a29636 + 2bad994 commit d46195c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
44

55
## Unreleased
66

7+
### Added
8+
9+
* Add `php-topsy-beginning-of-defun-with-class` to display classname with function signature. ([#766])
10+
711
### Removed
812

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

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

1318
## [1.25.0] - 2023-07-24
1419

lisp/php.el

+31
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ a completion list."
203203
:type 'integer
204204
:link '(url-link :tag "Built-in web server"
205205
"https://www.php.net/manual/features.commandline.webserver.php"))
206+
207+
(defcustom php-topsy-separator " > "
208+
"Separator string for `php-topsy-beginning-of-defun-with-class'."
209+
:group 'php
210+
:tag "PHP Topsy Separator"
211+
:type 'string)
206212

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

664+
(defun php-topsy-beginning-of-defun-with-class ()
665+
"Return function signature and class name string for header line in topsy.
666+
667+
You can add the function to topsy with the code below:
668+
\(add-to-list 'topsy-mode-functions '(php-mode . php-topsy-beginning-of-defun-with-class))"
669+
(save-excursion
670+
(goto-char (window-start))
671+
(mapconcat
672+
#'identity
673+
(append
674+
(save-match-data
675+
(save-excursion
676+
(when (re-search-backward php--re-classlike-pattern nil t)
677+
(font-lock-ensure (point) (line-end-position))
678+
(list (string-trim (buffer-substring (point) (line-end-position)))))))
679+
(progn
680+
(beginning-of-defun)
681+
(font-lock-ensure (point) (line-end-position))
682+
(list (string-trim
683+
(replace-regexp-in-string
684+
(eval-when-compile (rx bos "<?php"))
685+
""
686+
(buffer-substring (point) (line-end-position)))))))
687+
php-topsy-separator)))
688+
658689
;;;###autoload
659690
(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root)
660691
"Run PHP Built-in web server.

0 commit comments

Comments
 (0)