From 4c26733f60877130c49bd79fff5fb1e02cff3b1c Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 22 May 2019 08:31:21 +0200 Subject: Update php-mode and yasnippet --- .emacs.d/lisp/php-mode.el | 462 +++++++--------------------------------------- 1 file changed, 67 insertions(+), 395 deletions(-) (limited to '.emacs.d/lisp/php-mode.el') diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 8e72fe3..2fa1ab5 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el @@ -9,30 +9,28 @@ ;; Maintainer: USAMI Kenta ;; URL: https://github.com/emacs-php/php-mode ;; Keywords: languages php -;; Version: 1.21.0 +;; Version: 1.21.2 ;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) ;; License: GPL-3.0-or-later -(defconst php-mode-version-number "1.21.0" +(defconst php-mode-version-number "1.21.2" "PHP Mode version number.") -(defconst php-mode-modified "2019-02-28" +(defconst php-mode-modified "2019-05-11" "PHP Mode build date.") -;; This file is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 3 -;; of the License, or (at your option) any later version. +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. -;; This file is distributed in the hope that it will be useful, +;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this file; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -;; 02110-1301, USA. +;; along with this program. If not, see . ;;; Commentary: @@ -65,6 +63,8 @@ ;;; Code: +(require 'php) +(require 'php-face) (require 'cc-mode) (require 'cc-langs) @@ -80,12 +80,10 @@ (require 'font-lock) (require 'add-log) (require 'custom) -(require 'flymake) (require 'etags) (require 'speedbar) (require 'imenu) (require 'nadvice nil t) -(require 'package) (require 'cl-lib) (require 'mode-local) @@ -93,14 +91,13 @@ (eval-when-compile (require 'regexp-opt) - (autoload 'pkg-info-version-info "pkg-info") (defvar c-vsemi-status-unknown-p) (defvar syntax-propertize-via-font-lock)) ;; Work around emacs bug#18845, cc-mode expects cl to be loaded ;; while php-mode only uses cl-lib (without compatibility aliases) (eval-and-compile - (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) + (when (and (= emacs-major-version 24) (>= emacs-minor-version 4)) (require 'cl))) ;; Work around https://github.com/emacs-php/php-mode/issues/310. @@ -120,16 +117,10 @@ ;; need it in php-mode, just return nil. nil))) +(autoload 'php-mode-debug "php-mode-debug" + "Display informations useful for debugging PHP Mode." t) ;; Local variables -;;;###autoload -(defgroup php nil - "Language support for PHP." - :tag "PHP" - :group 'languages - :group 'php - :link '(url-link :tag "Official Site" "https://github.com/emacs-php/php-mode") - :link '(url-link :tag "PHP Mode Wiki" "https://github.com/emacs-php/php-mode/wiki")) ;;;###autoload (defgroup php-mode nil @@ -141,11 +132,6 @@ :link '(url-link :tag "Official Site" "https://github.com/emacs-php/php-mode") :link '(url-link :tag "PHP Mode Wiki" "https://github.com/emacs-php/php-mode/wiki")) -(defcustom php-executable (or (executable-find "php") - "/usr/bin/php") - "The location of the PHP executable." - :type 'string) - (define-obsolete-variable-alias 'php-default-face 'php-mode-default-face "1.20.0") (defcustom php-mode-default-face 'default "Default face in `php-mode' buffers." @@ -180,20 +166,11 @@ Turning this on will open it whenever `php-mode' is loaded." :group 'php-mode :type 'boolean) -(defsubst php-in-string-p () - (nth 3 (syntax-ppss))) - -(defsubst php-in-comment-p () - (nth 4 (syntax-ppss))) - -(defsubst php-in-string-or-comment-p () - (nth 8 (syntax-ppss))) - (defun php-mode-extra-constants-create-regexp (kwds) "Create regexp for the list of extra constant keywords KWDS." (concat "[^_$]?\\<\\(" (regexp-opt - (append kwds + (append kwds (when (boundp 'web-mode-extra-php-constants) web-mode-extra-php-constants))) "\\)\\>[^_]?")) @@ -227,67 +204,6 @@ of constants when set." :type '(repeat string) :set 'php-mode-extra-constants-set) -(defun php-create-regexp-for-method (visibility) - "Make a regular expression for methods with the given VISIBILITY. - -VISIBILITY must be a string that names the visibility for a PHP -method, e.g. 'public'. The parameter VISIBILITY can itself also -be a regular expression. - -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." - (concat - ;; Initial space with possible 'abstract' or 'final' keywords - "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?" - ;; 'static' keyword may come either before or after visibility - "\\(?:" visibility "\\(?:\\s-+static\\)?\\|\\(?:static\\s-+\\)?" visibility "\\)\\s-+" - ;; Make sure 'function' comes next with some space after - "function\\s-+" - ;; Capture the name as the first group and the regexp and make sure - ;; by the end we see the opening parenthesis for the parameters. - "\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(")) - -(defun php-create-regexp-for-classlike (type) - "Accepts a `TYPE' of a 'classlike' object as a string, such as -'class' or 'interface', and returns a regexp as a string which -can be used to match against definitions for that classlike." - (concat - ;; First see if 'abstract' or 'final' appear, although really these - ;; are not valid for all values of `type' that the function - ;; accepts. - "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?" - ;; The classlike type - type - ;; Its name, which is the first captured group in the regexp. We - ;; allow backslashes in the name to handle namespaces, but again - ;; this is not necessarily correct for all values of `type'. - "\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)")) - -(defvar php-imenu-generic-expression - `(("Namespaces" - ,(php-create-regexp-for-classlike "namespace") 1) - ("Classes" - ,(php-create-regexp-for-classlike "class") 1) - ("Interfaces" - ,(php-create-regexp-for-classlike "interface") 1) - ("Traits" - ,(php-create-regexp-for-classlike "trait") 1) - ("All Methods" - ,(php-create-regexp-for-method "\\(?:\\sw\\|\\s_\\)+") 1) - ("Private Methods" - ,(php-create-regexp-for-method "private") 1) - ("Protected Methods" - ,(php-create-regexp-for-method "protected") 1) - ("Public Methods" - ,(php-create-regexp-for-method "public") 1) - ("Anonymous Functions" - "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*function\\s-*(" 1) - ("Named Functions" - "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1)) - "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.") - (define-obsolete-variable-alias 'php-do-not-use-semantic-imenu 'php-mode-do-not-use-semantic-imenu "1.20.0") (defcustom php-mode-do-not-use-semantic-imenu t "Customize `imenu-create-index-function' for `php-mode'. @@ -299,34 +215,6 @@ parent. Set this variable to t if you want to use enabled." :type 'boolean) -(defcustom php-site-url "https://secure.php.net/" - "Default PHP.net site URL. - -The URL to use open PHP manual and search word. -You can find a mirror site closer to you." - :type 'string - :link '(url-link :tag "List of Mirror Sites" "https://secure.php.net/mirrors.php")) - -(defcustom php-manual-url 'en - "URL at which to find PHP manual. -You can replace \"en\" with your ISO language code." - :type '(choice (const :tag "English" 'en) - (const :tag "Brazilian Portuguese" 'pt_BR) - (const :tag "Chinese (Simplified)" 'zh) - (const :tag "French" 'fr) - (const :tag "German" 'de) - (const :tag "Japanese" 'ja) - (const :tag "Romanian" 'ro) - (const :tag "Russian" 'ru) - (const :tag "Spanish" 'es) - (const :tag "Turkish" 'tr) - (string :tag "PHP manual URL"))) - -(defcustom php-search-url nil - "URL at which to search for documentation on a word." - :type '(choice (string :tag "URL to search PHP documentation") - (const :tag "Use `php-site-url' variable" nil))) - (defcustom php-completion-file "" "Path to the file which contains the function names known to PHP." :type 'string) @@ -524,6 +412,10 @@ In that case set to `NIL'." (left-assoc "\\" "::" "->") (prefix "\\" "::"))) +(c-lang-defconst c-operators + php (delete '(postfix-if-paren "<" ">") + (c-lang-const c-operators))) + ;; Allow '\' when scanning from open brace back to defining ;; construct like class (c-lang-defconst c-block-prefix-disallowed-chars @@ -580,40 +472,35 @@ PHP does not have an \"enum\"-like keyword." php '("implements" "extends")) (c-lang-defconst c-type-list-kwds - php '("new" "use" "implements" "extends" "namespace" "instanceof" "insteadof")) + php '("@new" ;; @new is *NOT* language construct, it's workaround for coloring. + "new" "use" "implements" "extends" "namespace" "instanceof" "insteadof")) (c-lang-defconst c-ref-list-kwds php nil) (c-lang-defconst c-block-stmt-2-kwds - php (append '("elseif" "foreach" "declare") - (remove "synchronized" (c-lang-const c-block-stmt-2-kwds)))) + php '("catch" "declare" "elseif" "for" "foreach" "if" "switch" "while")) (c-lang-defconst c-simple-stmt-kwds - php (append '("include" "include_once" "require" "require_once" - "echo" "print" "die" "exit") - (c-lang-const c-simple-stmt-kwds))) + php '("break" "continue" "die" "echo" "exit" "goto" "return" "throw" + "include" "include_once" "print" "require" "require_once")) (c-lang-defconst c-constant-kwds - php '("true" - "false" - "null")) + php '("true" "false" "null")) (c-lang-defconst c-lambda-kwds - php '("function" - "use")) + php '("function" "use")) (c-lang-defconst c-other-block-decl-kwds php '("namespace")) (c-lang-defconst c-other-kwds "Keywords not accounted for by any other `*-kwds' language constant." - php '( + php + '( "__halt_compiler" "and" "array" - "callable" - "iterable" "as" "break" "catch" @@ -627,6 +514,7 @@ PHP does not have an \"enum\"-like keyword." "endswitch" "endwhile" "eval" + "fn" ;; NOT c-lambda-kwds "global" "isset" "list" @@ -656,6 +544,12 @@ PHP does not have an \"enum\"-like keyword." (c-lang-defconst c-recognize-<>-arglists php nil) +(c-lang-defconst c-<>-type-kwds + php nil) + +(c-lang-defconst c-inside-<>-type-kwds + php nil) + (c-lang-defconst c-enums-contain-decls php nil) @@ -679,6 +573,13 @@ might be to handle switch and goto labels differently." php (cl-remove-if (lambda (elm) (and (listp elm) (equal (car elm) "\\s|"))) (c-lang-const c-basic-matchers-before php))) +(c-lang-defconst c-basic-matchers-after + php (cl-remove-if (lambda (elm) (and (listp elm) (memq 'c-annotation-face elm))) + (c-lang-const c-basic-matchers-after php))) + +(c-lang-defconst c-opt-<>-sexp-key + php nil) + (defun php-lineup-cascaded-calls (langelem) "Line up chained methods using `c-lineup-cascaded-calls', but only if the setting is enabled" @@ -788,10 +689,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) @@ -800,9 +701,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. @@ -988,7 +890,7 @@ this ^ lineup" "Build a regular expression for the end of a heredoc started by the string HEREDOC-START." ;; Extract just the identifier without <<< and quotes. (string-match "\\_<.+?\\_>" heredoc-start) - (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W")) + (concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W")) (defun php-syntax-propertize-function (start end) "Apply propertize rules from START to END." @@ -1000,12 +902,7 @@ this ^ lineup" (while (re-search-forward "['\"]" end t) (when (php-in-comment-p) (c-put-char-property (match-beginning 0) - 'syntax-table (string-to-syntax "_")))) - (funcall - (syntax-propertize-rules - ("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) - ("\\('\\)\\(\\\\.\\|[^'\n\\]\\)*\\('\\)" (1 "\"") (3 "\""))) - start end)) + 'syntax-table (string-to-syntax "_"))))) (defun php-heredoc-syntax () "Mark the boundaries of searched heredoc." @@ -1041,106 +938,6 @@ this ^ lineup" (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" (cons "PHP" (c-lang-const c-mode-menu php))) - -;; Faces - -;;;###autoload -(defgroup php-faces nil - "Faces used in PHP Mode" - :tag "PHP Faces" - :group 'php-mode - :group 'faces) - -(defface php-string '((t (:inherit font-lock-string-face))) - "PHP Mode face used to highlight string literals." - :group 'php-faces) - -(defface php-keyword '((t (:inherit font-lock-keyword-face))) - "PHP Mode face used to highlight keywords." - :group 'php-faces) - -(defface php-builtin '((t (:inherit font-lock-builtin-face))) - "PHP Mode face used to highlight builtins." - :group 'php-faces) - -(defface php-function-name '((t (:inherit font-lock-function-name-face))) - "PHP Mode face used to highlight function names." - :group 'php-faces) - -(defface php-function-call '((t (:inherit default))) - "PHP Mode face used to highlight function names in calles." - :group 'php-faces) - -(defface php-method-call '((t (:inherit php-function-call))) - "PHP Mode face used to highlight method names in calles." - :group 'php-faces) - -(defface php-static-method-call '((t (:inherit php-method-call))) - "PHP Mode face used to highlight static method names in calles." - :group 'php-faces) - -(defface php-variable-name '((t (:inherit font-lock-variable-name-face))) - "PHP Mode face used to highlight variable names." - :group 'php-faces) - -(defface php-property-name '((t (:inherit php-variable-name))) - "PHP Mode face used to highlight property names." - :group 'php-faces) - -(defface php-variable-sigil '((t (:inherit default))) - "PHP Mode face used to highlight variable sigils ($)." - :group 'php-faces) - -(defface php-object-op '((t (:inherit default))) - "PHP Mode face used to object operators (->)." - :group 'php-faces) - -(defface php-paamayim-nekudotayim '((t (:inherit default))) - "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)." - :group 'php-faces) - -(defface php-type '((t (:inherit font-lock-type-face))) - "PHP Mode face used to highlight types." - :group 'php-faces) - -(defface php-constant '((t (:inherit font-lock-constant-face))) - "PHP Mode face used to highlight constants." - :group 'php-faces) - -(defface php-$this '((t (:inherit php-constant))) - "PHP Mode face used to highlight $this variables." - :group 'php-faces) - -(defface php-$this-sigil '((t (:inherit php-constant))) - "PHP Mode face used to highlight sigils($) of $this variable." - :group 'php-faces) - -(defface php-php-tag '((t (:inherit font-lock-preprocessor-face))) - "PHP Mode face used to highlight PHP tags." - :group 'php-faces) - -(defface php-doc-annotation-tag '((t . (:inherit font-lock-constant-face))) - "Face used to highlight annotation tags in doc-comment." - :group 'php-faces) - -(defface php-doc-variable-sigil '((t (:inherit font-lock-variable-name-face))) - "PHP Mode face used to highlight variable sigils($)." - :group 'php-faces) - -(defface php-doc-$this '((t (:inherit php-type))) - "PHP Mode face used to highlight $this variable in doc-comment." - :group 'php-faces) - -(defface php-doc-$this-sigil '((t (:inherit php-type))) - "PHP Mode face used to highlight sigil of $this variable in doc-comment." - :group 'php-faces) - -(defface php-doc-class-name '((t (:inherit php-string))) - "Face used to class names in doc-comment." - :group 'php-faces) - -(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") - (defvar-local php-mode--delayed-set-style nil) (defun php-set-style (stylename &optional dont-override) @@ -1199,70 +996,6 @@ After setting the stylevars run hooks according to STYLENAME (prog1 (php-set-style (symbol-name coding-style)) (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) -(defun php-mode-debug--buffer (&optional command &rest args) - "Return buffer for php-mode-debug, and execute `COMMAND' with `ARGS'." - (with-current-buffer (get-buffer-create "*PHP Mode DEBUG*") - (cl-case command - (init (erase-buffer) - (goto-address-mode)) - (top (goto-char (point-min))) - (insert (goto-char (point-max)) - (apply #'insert args))) - (current-buffer))) - -(defun php-mode-debug--message (format-string &rest args) - "Write message `FORMAT-STRING' and `ARGS' to debug buffer, like `message'." - (declare (indent 1)) - (php-mode-debug--buffer 'insert (apply #'format format-string args) "\n")) - -(declare-function custom-group-members "cus-edit" (symbol groups-only)) - -(defun php-mode-debug () - "Display informations useful for debugging PHP Mode." - (interactive) - (require 'cus-edit) - (require 'pkg-info nil t) - (php-mode-debug--buffer 'init) - (php-mode-debug--message "Feel free to report on GitHub what you noticed!") - (php-mode-debug--message "https://github.com/emacs-php/php-mode/issues/new") - (php-mode-debug--message "") - (php-mode-debug--message "Pasting the following information on the issue will help us to investigate the cause.") - (php-mode-debug--message "```") - (php-mode-debug--message "--- PHP-MODE DEBUG BEGIN ---") - (php-mode-debug--message "versions: %s; %s" (emacs-version) (php-mode-version)) - (php-mode-debug--message "package-version: %s" - (if (fboundp 'pkg-info) - (pkg-info-version-info 'php-mode) - (let ((pkg (and (boundp 'package-alist) - (cadr (assq 'php-mode package-alist))))) - (when (and pkg (member (package-desc-status pkg) '("unsigned" "dependency"))) - (package-version-join (package-desc-version pkg)))))) - - (php-mode-debug--message "major-mode: %s" major-mode) - (php-mode-debug--message "minor-modes: %s" - (cl-loop for s in minor-mode-list - unless (string-match-p "global" (symbol-name s)) - if (and (boundp s) (symbol-value s)) - collect s)) - (php-mode-debug--message "variables: %s" - (cl-loop for v in '(indent-tabs-mode tab-width) - collect (list v (symbol-value v)))) - (php-mode-debug--message "custom variables: %s" - (cl-loop for (v type) in (custom-group-members 'php nil) - if (eq type 'custom-variable) - collect (list v (symbol-value v)))) - (php-mode-debug--message "c-indentation-style: %s" c-indentation-style) - (php-mode-debug--message "c-style-variables: %s" - (cl-loop for v in c-style-variables - unless (memq v '(c-doc-comment-style c-offsets-alist)) - collect (list v (symbol-value v)))) - (php-mode-debug--message "c-doc-comment-style: %s" c-doc-comment-style) - (php-mode-debug--message "c-offsets-alist: %s" c-offsets-alist) - (php-mode-debug--message "--- PHP-MODE DEBUG END ---") - (php-mode-debug--message "```\n") - (php-mode-debug--message "Thank you!") - (pop-to-buffer (php-mode-debug--buffer 'top))) - ;;;###autoload (define-derived-mode php-mode c-mode "PHP" "Major mode for editing PHP code. @@ -1657,21 +1390,16 @@ a completion list." ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but ;; not in $obj->var() ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) + ("\\<\\(const\\)\\s-+\\(\\_<.+?\\_>\\)" (1 'php-keyword) (2 'php-constant-assign)) ;; Highlight special variables - ("\\(\\$\\)\\(this\\|that\\)\\_>" (1 'php-$this-sigil) (2 'php-$this)) - ("\\(\\$\\)\\([a-zA-Z0-9_]+\\)" (1 'php-variable-sigil) (2 'php-variable-name)) + ("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this)) + ("\\(\\$+\\)\\(\\sw+\\)" (1 'php-variable-sigil) (2 'php-variable-name)) ("\\(->\\)\\([a-zA-Z0-9_]+\\)" (1 'php-object-op) (2 'php-property-name)) ;; Highlight function/method names ("\\" 1 'php-constant) @@ -1756,34 +1490,12 @@ a completion list." (defvar php-font-lock-keywords php-font-lock-keywords-3 "Default expressions to highlight in PHP Mode.") -;;; Provide support for Flymake so that users can see warnings and -;;; errors in real-time as they write code. - -(defun php-flymake-php-init () - "PHP specific init-cleanup routines. - -This is an alternative function of `flymake-php-init'. -Look at the `php-executable' variable instead of the constant \"php\" command." - (let* ((temp-file - (funcall - (eval-when-compile - (if (fboundp 'flymake-proc-init-create-temp-buffer-copy) - 'flymake-proc-init-create-temp-buffer-copy - 'flymake-init-create-temp-buffer-copy)) - 'flymake-create-temp-inplace)) - (local-file (file-relative-name - temp-file - (file-name-directory buffer-file-name)))) - (list php-executable (list "-f" local-file "-l")))) - -(add-to-list 'flymake-allowed-file-name-masks - '("\\.php[345s]?\\'" - php-flymake-php-init - flymake-simple-cleanup - flymake-get-real-file-name)) - -(add-to-list 'flymake-err-line-patterns - '("\\(Parse\\|Fatal\\) error: \\(.*?\\) in \\(.*?\\) on line \\([0-9]+\\)" 3 4 nil 2)) +(add-to-list + (eval-when-compile + (if (boundp 'flymake-proc-allowed-file-name-masks) + 'flymake-proc-allowed-file-name-masks + 'flymake-allowed-file-name-masks)) + '("\\.php[345s]?\\'" php-flymake-php-init)) (defun php-send-region (start end) @@ -1836,46 +1548,6 @@ The output will appear in the buffer *PHP*." (ad-activate 'fixup-whitespace) - -(defcustom php-class-suffix-when-insert "::" - "Suffix for inserted class." - :group 'php - :type 'string) - -(defcustom php-namespace-suffix-when-insert "\\" - "Suffix for inserted namespace." - :group 'php - :type 'string) - -(defvar php--re-namespace-pattern - (php-create-regexp-for-classlike "namespace")) - -(defvar php--re-classlike-pattern - (php-create-regexp-for-classlike (regexp-opt '("class" "interface" "trait")))) - -(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)))) - -;;;###autoload -(defun php-current-class () - "Insert current class name if cursor in class context." - (interactive) - (let ((matched (php-get-current-element php--re-classlike-pattern))) - (when matched - (insert (concat matched php-class-suffix-when-insert))))) - -;;;###autoload -(defun php-current-namespace () - "Insert current namespace if cursor in namespace context." - (interactive) - (let ((matched (php-get-current-element php--re-namespace-pattern))) - (when matched - (insert (concat matched php-namespace-suffix-when-insert))))) - - ;;;###autoload (add-to-list 'auto-mode-alist (cons -- cgit v1.3