Skip to content

Commit 7e630bf

Browse files
authored
Merge pull request #561 from emacs-php/feature/current-elm
Add new command php-copyit-fqsen and fix regexp patterns
2 parents 2a5f7f7 + 4d87f5e commit 7e630bf

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

php.el

+20-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ it is the character that will terminate the string, or t if the string should be
160160
(symbol-value 'poly-php-html-mode)))
161161

162162
(defconst php-beginning-of-defun-regexp
163-
"^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*("
163+
"^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(\\sw\\|\\s_\\)+\\)\\s-*("
164164
"Regular expression for a PHP function.")
165165

166166
(eval-when-compile
@@ -175,6 +175,8 @@ The regular expression this function returns will check for other
175175
keywords that can appear in method signatures, e.g. 'final' and
176176
'static'. The regular expression will have one capture group
177177
which will be the name of the method."
178+
(when (stringp visibility)
179+
(setq visibility (list visibility)))
178180
(rx-form `(: line-start
179181
(* (syntax whitespace))
180182
,@(if visibility
@@ -185,10 +187,11 @@ which will be the name of the method."
185187
(* (or "abstract" "final" "static")
186188
(+ (syntax whitespace))))
187189
'((* (* (or "abstract" "final" "static"
188-
"private" "protected" "public"))
189-
(+ (syntax whitespace)))))
190+
"private" "protected" "public")
191+
(+ (syntax whitespace))))))
190192
"function"
191193
(+ (syntax whitespace))
194+
(? "&" (* (syntax whitespace)))
192195
(group (+ (or (syntax word) (syntax symbol))))
193196
(* (syntax whitespace))
194197
"(")))
@@ -244,8 +247,9 @@ can be used to match against definitions for that classlike."
244247
(defun php-get-current-element (re-pattern)
245248
"Return backward matched element by RE-PATTERN."
246249
(save-excursion
247-
(when (re-search-backward re-pattern nil t)
248-
(match-string-no-properties 1))))
250+
(save-match-data
251+
(when (re-search-backward re-pattern nil t)
252+
(match-string-no-properties 1)))))
249253

250254
;;; Provide support for Flymake so that users can see warnings and
251255
;;; errors in real-time as they write code.
@@ -349,6 +353,17 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
349353
(when matched
350354
(insert (concat matched php-namespace-suffix-when-insert)))))
351355

356+
;;;###autoload
357+
(defun php-copyit-fqsen ()
358+
"Copy/kill class/method FQSEN."
359+
(interactive)
360+
(let ((namespace (or (php-get-current-element php--re-namespace-pattern) ""))
361+
(class (or (php-get-current-element php--re-classlike-pattern) ""))
362+
(namedfunc (php-get-current-element php-beginning-of-defun-regexp)))
363+
(kill-new (concat (if (string= namespace "") "" namespace)
364+
(if (string= class "") "" (concat "\\" class "::"))
365+
(if (string= namedfunc "") "" (concat namedfunc "()"))))))
366+
352367
;;;###autoload
353368
(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root)
354369
"Run PHP Built-in web server.

0 commit comments

Comments
 (0)