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 new command php-copyit-fqsen and fix regexp patterns #561

Merged
merged 5 commits into from
Aug 18, 2019
Merged
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
25 changes: 20 additions & 5 deletions php.el
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ it is the character that will terminate the string, or t if the string should be
(symbol-value 'poly-php-html-mode)))

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

(eval-when-compile
Expand All @@ -175,6 +175,8 @@ The regular expression this function returns will check for other
keywords that can appear in method signatures, e.g. 'final' and
'static'. The regular expression will have one capture group
which will be the name of the method."
(when (stringp visibility)
(setq visibility (list visibility)))
(rx-form `(: line-start
(* (syntax whitespace))
,@(if visibility
Expand All @@ -185,10 +187,11 @@ which will be the name of the method."
(* (or "abstract" "final" "static")
(+ (syntax whitespace))))
'((* (* (or "abstract" "final" "static"
"private" "protected" "public"))
(+ (syntax whitespace)))))
"private" "protected" "public")
(+ (syntax whitespace))))))
"function"
(+ (syntax whitespace))
(? "&" (* (syntax whitespace)))
(group (+ (or (syntax word) (syntax symbol))))
(* (syntax whitespace))
"(")))
Expand Down Expand Up @@ -244,8 +247,9 @@ can be used to match against definitions for that classlike."
(defun php-get-current-element (re-pattern)
"Return backward matched element by RE-PATTERN."
(save-excursion
(when (re-search-backward re-pattern nil t)
(match-string-no-properties 1))))
(save-match-data
(when (re-search-backward re-pattern nil t)
(match-string-no-properties 1)))))

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

;;;###autoload
(defun php-copyit-fqsen ()
"Copy/kill class/method FQSEN."
(interactive)
(let ((namespace (or (php-get-current-element php--re-namespace-pattern) ""))
(class (or (php-get-current-element php--re-classlike-pattern) ""))
(namedfunc (php-get-current-element php-beginning-of-defun-regexp)))
(kill-new (concat (if (string= namespace "") "" namespace)
(if (string= class "") "" (concat "\\" class "::"))
(if (string= namedfunc "") "" (concat namedfunc "()"))))))

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