From aede1540a05b083908ef17ef4571569e0960dda0 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 27 May 2019 09:57:43 +0200 Subject: Update php-mode --- .emacs.d/lisp/php-face.el | 77 +++++++++++++++++++---------- .emacs.d/lisp/php-mode.el | 115 ++++++++++++++++++++++++++++--------------- .emacs.d/lisp/php-project.el | 92 ++++++++++++++++++++-------------- .emacs.d/lisp/php.el | 98 +++++++++++++++++++++++++++++++++++- 4 files changed, 278 insertions(+), 104 deletions(-) (limited to '.emacs.d/lisp') diff --git a/.emacs.d/lisp/php-face.el b/.emacs.d/lisp/php-face.el index e01d517..a674dd4 100644 --- a/.emacs.d/lisp/php-face.el +++ b/.emacs.d/lisp/php-face.el @@ -4,7 +4,7 @@ ;; Author: USAMI Kenta ;; Created: 5 May 2019 -;; Version: 1.21.2 +;; Version: 1.21.3 ;; Keywords: faces, php ;; Homepage: https://github.com/emacs-php/php-mode ;; Package-Requires: ((emacs "24.3")) @@ -38,103 +38,128 @@ (defface php-string '((t (:inherit font-lock-string-face))) "PHP Mode face used to highlight string literals." - :group 'php-faces) + :group 'php-faces + :tag "PHP String") (defface php-keyword '((t (:inherit font-lock-keyword-face))) "PHP Mode face used to highlight keywords." - :group 'php-faces) + :group 'php-faces + :tag "PHP Keyword") (defface php-builtin '((t (:inherit font-lock-builtin-face))) "PHP Mode face used to highlight builtins." - :group 'php-faces) + :group 'php-faces + :tag "PHP Built-in") (defface php-function-name '((t (:inherit font-lock-function-name-face))) "PHP Mode face used to highlight function names." - :group 'php-faces) + :group 'php-faces + :tag "PHP Function Name") (defface php-function-call '((t (:inherit default))) "PHP Mode face used to highlight function names in calles." - :group 'php-faces) + :group 'php-faces + :tag "PHP Function Call") (defface php-method-call '((t (:inherit php-function-call))) "PHP Mode face used to highlight method names in calles." - :group 'php-faces) + :group 'php-faces + :tag "PHP Method Call") (defface php-static-method-call '((t (:inherit php-method-call))) "PHP Mode face used to highlight static method names in calles." - :group 'php-faces) + :group 'php-faces + :tag "PHP Static Method Call") (defface php-variable-name '((t (:inherit font-lock-variable-name-face))) "PHP Mode face used to highlight variable names." - :group 'php-faces) + :group 'php-faces + :tag "PHP Variable Name") (defface php-property-name '((t (:inherit php-variable-name))) "PHP Mode face used to highlight property names." - :group 'php-faces) + :group 'php-faces + :tag "PHP Property Name") (defface php-variable-sigil '((t (:inherit default))) "PHP Mode face used to highlight variable sigils ($)." - :group 'php-faces) + :group 'php-faces + :tag "PHP Variable Sigil") (defface php-object-op '((t (:inherit default))) "PHP Mode face used to object operators (->)." - :group 'php-faces) + :group 'php-faces + :tag "PHP Object Op") (defface php-paamayim-nekudotayim '((t (:inherit default))) "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)." - :group 'php-faces) + :group 'php-faces + :tag "PHP Paamayim Nekudotayim") (defface php-type '((t (:inherit font-lock-type-face))) "PHP Mode face used to highlight types." - :group 'php-faces) + :group 'php-faces + :tag "PHP Type") (defface php-constant '((t (:inherit font-lock-constant-face))) "PHP Mode face used to highlight constants." - :group 'php-faces) + :group 'php-faces + :tag "PHP Constant") (defface php-constant-assign '((t (:inherit font-lock-type-face))) "PHP Mode face used to highlight constant assigning (\"const\" statement)." - :group 'php-faces) + :group 'php-faces + :tag "PHP Constant Assign") (defface php-magical-constant '((t (:inherit font-lock-builtin-face))) "PHP Mode face used to highlight magical constants." - :group 'php-faces) + :group 'php-faces + :tag "PHP Magical Constant") (defface php-$this '((t (:inherit php-constant))) "PHP Mode face used to highlight $this variables." - :group 'php-faces) + :group 'php-faces + :tag "PHP $this") (defface php-$this-sigil '((t (:inherit php-constant))) "PHP Mode face used to highlight sigils($) of $this variable." - :group 'php-faces) + :group 'php-faces + :tag "PHP $this Sigil") (defface php-errorcontrol-op '((t (:inherit font-lock-type-face))) "PHP Mode face used to highlight errorcontrol operators (@).." - :group 'php-face) + :group 'php-faces + :tag "PHP ErrorControl Op") (defface php-php-tag '((t (:inherit font-lock-preprocessor-face))) "PHP Mode face used to highlight PHP tags." - :group 'php-faces) + :group 'php-faces + :tag "PHP php Tag") (defface php-doc-annotation-tag '((t . (:inherit font-lock-constant-face))) "Face used to highlight annotation tags in doc-comment." - :group 'php-faces) + :group 'php-faces + :tag "PHPDoc Annotation Tag") (defface php-doc-variable-sigil '((t (:inherit font-lock-variable-name-face))) "PHP Mode face used to highlight variable sigils($)." - :group 'php-faces) + :group 'php-faces + :tag "PHPDoc Variable Sigil") (defface php-doc-$this '((t (:inherit php-type))) "PHP Mode face used to highlight $this variable in doc-comment." - :group 'php-faces) + :group 'php-faces + :tag "PHPDoc $this") (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) + :group 'php-faces + :tag "PHPDoc $this Sigil") (defface php-doc-class-name '((t (:inherit php-string))) "Face used to class names in doc-comment." - :group 'php-faces) + :group 'php-faces + :tag "PHPDoc Class Name") (define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 2fa1ab5..09d762b 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el @@ -9,14 +9,14 @@ ;; Maintainer: USAMI Kenta ;; URL: https://github.com/emacs-php/php-mode ;; Keywords: languages php -;; Version: 1.21.2 +;; Version: 1.21.3 ;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) ;; License: GPL-3.0-or-later -(defconst php-mode-version-number "1.21.2" +(defconst php-mode-version-number "1.21.3" "PHP Mode version number.") -(defconst php-mode-modified "2019-05-11" +(defconst php-mode-modified "2019-05-25" "PHP Mode build date.") ;; This program is free software; you can redistribute it and/or modify @@ -136,6 +136,7 @@ (defcustom php-mode-default-face 'default "Default face in `php-mode' buffers." :group 'php-mode + :tag "PHP Mode Default Face" :type 'face) (define-obsolete-variable-alias 'php-speedbar-config 'php-mode-speedbar-config "1.20.0") @@ -143,6 +144,7 @@ "When set to true automatically configures Speedbar to observe PHP files. Ignores php-file patterns option; fixed to expression \"\\.\\(inc\\|php[s345]?\\)\"" :group 'php-mode + :tag "PHP Mode Speedbar Config" :type 'boolean :set (lambda (sym val) (set-default sym val) @@ -154,6 +156,7 @@ Ignores php-file patterns option; fixed to expression \"\\.\\(inc\\|php[s345]?\\ "Normally `php-mode' starts with the speedbar closed. Turning this on will open it whenever `php-mode' is loaded." :group 'php-mode + :tag "PHP Mode Speedbar Open" :type 'boolean :set (lambda (sym val) (set-default sym val) @@ -164,6 +167,7 @@ Turning this on will open it whenever `php-mode' is loaded." (defcustom php-mode-template-compatibility t "Should detect presence of html tags." :group 'php-mode + :tag "PHP Mode Template Compatibility" :type 'boolean) (defun php-mode-extra-constants-create-regexp (kwds) @@ -194,6 +198,7 @@ of constants when set." (defcustom php-mode-lineup-cascaded-calls nil "Indent chained method calls to the previous line." :group 'php-mode + :tag "PHP Mode Lineup Cascaded Calls" :type 'boolean) @@ -201,6 +206,7 @@ of constants when set." (defcustom php-mode-extra-constants '() "A list of additional strings to treat as PHP constants." :group 'php-mode + :tag "PHP Mode Extra Constants" :type '(repeat string) :set 'php-mode-extra-constants-set) @@ -213,6 +219,8 @@ set to `semantic-create-imenu-index' due to `c-mode' being its parent. Set this variable to t if you want to use `imenu-default-create-index-function' even with `semantic-mode' enabled." + :group 'php-mode + :tag "PHP Mode Do Not Use Semantic Imenu" :type 'boolean) (defcustom php-completion-file "" @@ -233,31 +241,45 @@ enabled." (defcustom php-mode-hook nil "List of functions to be executed on entry to `php-mode'." + :group 'php-mode + :tag "PHP Mode Hook" :type 'hook) (defcustom php-mode-pear-hook nil "Hook called when a PHP PEAR file is opened with `php-mode'." + :group 'php-mode + :tag "PHP Mode Pear Hook" :type 'hook) (defcustom php-mode-drupal-hook nil "Hook called when a Drupal file is opened with `php-mode'." + :group 'php-mode + :tag "PHP Mode Drupal Hook" :type 'hook) (defcustom php-mode-wordpress-hook nil "Hook called when a WordPress file is opened with `php-mode'." + :group 'php-mode + :tag "PHP Mode WordPress Hook" :type 'hook) (defcustom php-mode-symfony2-hook nil "Hook called when a Symfony2 file is opened with `php-mode'." + :group 'php-mode + :tag "PHP Mode Symfony2 Hook" :type 'hook) (defcustom php-mode-psr2-hook nil "Hook called when a PSR-2 file is opened with `php-mode'." + :group 'php-mode + :tag "PHP Mode PSR-2 Hook" :type 'hook) (defcustom php-mode-force-pear nil "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" Turning this on will force PEAR rules on all PHP files." + :group 'php-mode + :tag "PHP Mode Force Pear" :type 'boolean) (defcustom php-mode-warn-if-mumamo-off t @@ -265,6 +287,8 @@ Turning this on will force PEAR rules on all PHP files." mumamo-mode turned on. Detects if there are any HTML tags in the buffer before warning, but this is is not very smart; e.g. if you have any tags inside a PHP string, it will be fooled." + :group 'php-mode + :tag "PHP Mode Warn If MuMaMo Off" :type '(choice (const :tag "Warn" t) (const "Don't warn" nil))) (defcustom php-mode-coding-style 'pear @@ -282,6 +306,8 @@ This variable can take one of the following symbol values: `Symfony2' - use coding styles preferred for working with Symfony2 projects. `PSR-2' - use coding styles preferred for working with projects using PSR-2 standards." + :group 'php-mode + :tag "PHP Mode Coding Style" :type '(choice (const :tag "Default" default) (const :tag "PEAR" pear) (const :tag "Drupal" drupal) @@ -297,6 +323,8 @@ This variable can take one of the following symbol values: If you want to suppress styles from being overwritten by directory / file local variables, set NIL." + :group 'php-mode + :tag "PHP Mode Enable Project Coding Style" :type 'boolean) (defcustom php-mode-enable-backup-style-variables t @@ -304,11 +332,15 @@ local variables, set NIL." This function may interfere with other hooks and other behaviors. In that case set to `NIL'." + :group 'php-mode + :tag "PHP Mode Enable Backup Style Variables" :type 'boolean) (define-obsolete-variable-alias 'php-mode-disable-parent-mode-hooks 'php-mode-disable-c-mode-hook "1.21.0") (defcustom php-mode-disable-c-mode-hook t "When set to `T', do not run hooks of parent modes (`java-mode', `c-mode')." + :group 'php-mode + :tag "PHP Mode Disable C Mode Hook" :type 'boolean :group 'php-mode) @@ -432,9 +464,7 @@ In that case set to `NIL'." php t) (c-lang-defconst c-assignment-operators - ;; falls back to java, so no need to specify the language - php (append (remove ">>>=" (c-lang-const c-assignment-operators)) - '(".="))) + php '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=" ".=" "??=")) (c-lang-defconst beginning-of-defun-function php 'php-beginning-of-defun) @@ -790,13 +820,20 @@ example `html-mode'. Known such libraries are:\n\t" nil)))) (defun php-cautious-indent-region (start end &optional quiet) + "Carefully indent region `START' `END' in contexts other than HTML templates. + +If the optional argument `QUIET' is non-nil then no syntactic errors are +reported, even if `c-report-syntactic-errors' is non-nil." (if (or (not php-mode-warn-if-mumamo-off) + (not (php-in-poly-php-html-mode)) php-warned-bad-indent (php-check-html-for-indentation)) (funcall 'c-indent-region start end quiet))) (defun php-cautious-indent-line () + "Carefully indent lines in contexts other than HTML templates." (if (or (not php-mode-warn-if-mumamo-off) + (not (php-in-poly-php-html-mode)) php-warned-bad-indent (php-check-html-for-indentation)) (let ((here (point)) @@ -843,8 +880,8 @@ This is was done due to the problem reported here: ret))) (defun php-c-vsemi-status-unknown-p () - "See `php-c-at-vsemi-p'." - ) + "Always return NIL. See `php-c-at-vsemi-p'." + nil) (defun php-lineup-string-cont (langelem) "Line up string toward equal sign or dot. @@ -996,11 +1033,23 @@ 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))))) +(defvar php-mode-syntax-table + (let ((table (make-syntax-table))) + (c-populate-syntax-table table) + (modify-syntax-entry ?_ "_" table) + (modify-syntax-entry ?` "\"" table) + (modify-syntax-entry ?\" "\"" table) + (modify-syntax-entry ?# "< b" table) + (modify-syntax-entry ?\n "> b" table) + (modify-syntax-entry ?$ "'" table) + table)) + ;;;###autoload (define-derived-mode php-mode c-mode "PHP" "Major mode for editing PHP code. \\{php-mode-map}" + :syntax-table php-mode-syntax-table ;; :after-hook (c-update-modeline) ;; (setq abbrev-mode t) (when php-mode-disable-c-mode-hook @@ -1010,6 +1059,15 @@ After setting the stylevars run hooks according to STYLENAME (c-init-language-vars php-mode) (c-common-init 'php-mode) + (setq-local comment-start "// ") + (setq-local comment-start-skip + (eval-when-compile + (rx (group (or (: "#") + (: "/" (+ "/")) + (: "/*"))) + (* (syntax whitespace))))) + (setq-local comment-end "") + (setq-local font-lock-string-face 'php-string) (setq-local font-lock-keyword-face 'php-keyword) (setq-local font-lock-builtin-face 'php-builtin) @@ -1018,13 +1076,6 @@ After setting the stylevars run hooks according to STYLENAME (setq-local font-lock-variable-name-face 'php-variable-name) (setq-local font-lock-constant-face 'php-constant) - (modify-syntax-entry ?_ "_" php-mode-syntax-table) - (modify-syntax-entry ?` "\"" php-mode-syntax-table) - (modify-syntax-entry ?\" "\"" php-mode-syntax-table) - (modify-syntax-entry ?# "< b" php-mode-syntax-table) - (modify-syntax-entry ?\n "> b" php-mode-syntax-table) - (modify-syntax-entry ?$ "'" php-mode-syntax-table) - (setq-local syntax-propertize-function #'php-syntax-propertize-function) (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) #'php-syntax-propertize-extend-region) @@ -1054,12 +1105,8 @@ After setting the stylevars run hooks according to STYLENAME (setq indent-line-function 'php-cautious-indent-line) (setq indent-region-function 'php-cautious-indent-region) - (setq c-at-vsemi-p-fn 'php-c-at-vsemi-p) - (setq c-vsemi-status-unknown-p 'php-c-vsemi-status-unknown-p) - - ;; syntax-begin-function is obsolete in Emacs 25.1 - (with-no-warnings - (setq-local syntax-begin-function 'c-beginning-of-syntax)) + (setq c-at-vsemi-p-fn #'php-c-at-vsemi-p) + (setq c-vsemi-status-unknown-p-fn #'php-c-vsemi-status-unknown-p) ;; We map the php-{beginning,end}-of-defun functions so that they ;; replace the similar commands that we inherit from CC Mode. @@ -1079,7 +1126,10 @@ After setting the stylevars run hooks according to STYLENAME (when (>= emacs-major-version 25) (with-silent-modifications (save-excursion - (php-syntax-propertize-function (point-min) (point-max)))))) + (let* ((start (point-min)) + (end (min (point-max) + (+ start syntax-propertize-chunk-size)))) + (php-syntax-propertize-function start end)))))) (declare-function semantic-create-imenu-index "semantic/imenu" (&optional stream)) @@ -1221,6 +1271,7 @@ current `tags-file-name'." If non-nil, this shadows the value of `browse-url-browser-function' when calling `php-search-documentation' or `php-search-local-documentation'." :group 'php + :tag "PHP Search Documentation Browser Function" :type '(choice (const :tag "default" nil) function) :link '(variable-link browse-url-browser-function)) @@ -1549,23 +1600,9 @@ The output will appear in the buffer *PHP*." (ad-activate 'fixup-whitespace) ;;;###autoload -(add-to-list 'auto-mode-alist - (cons - (eval-when-compile - (rx (or - ;; File name extensions (ex. "*.php", "*.phtml") - (: "." - (or (: "php" (? (in "s345t"))) - "amk" - "phtml")) - ;; Full file names (ex. "/Makefile", "/Amkfile") - (: "/" - (or "Amkfile" - ".php_cs" - ".php_cs.dist"))) - string-end)) - 'php-mode) - t) +(progn + (add-to-list 'auto-mode-alist '("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-mode)) + (add-to-list 'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-mode-maybe))) (provide 'php-mode) ;;; php-mode.el ends here diff --git a/.emacs.d/lisp/php-project.el b/.emacs.d/lisp/php-project.el index e12d83a..7ab003e 100644 --- a/.emacs.d/lisp/php-project.el +++ b/.emacs.d/lisp/php-project.el @@ -5,7 +5,7 @@ ;; Author: USAMI Kenta ;; Keywords: tools, files ;; URL: https://github.com/emacs-php/php-mode -;; Version: 1.21.2 +;; Version: 1.21.3 ;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) ;; License: GPL-3.0-or-later @@ -102,85 +102,90 @@ STRING If the string is an actual directory path, it is set as the absolute path of the root directory, not the marker.") (put 'php-project-root 'safe-local-variable - #'(lambda (v) (or (stringp v) (assq v php-project-available-root-files))))) + #'(lambda (v) (or (stringp v) (assq v php-project-available-root-files)))) -;;;###autoload -(progn (defvar-local php-project-bootstrap-scripts nil "List of path to bootstrap php script file. The ideal bootstrap file is silent, it only includes dependent files, defines constants, and sets the class loaders.") - (put 'php-project-bootstrap-scripts 'safe-local-variable #'php-project--eval-bootstrap-scripts)) + (put 'php-project-bootstrap-scripts 'safe-local-variable #'php-project--eval-bootstrap-scripts) -;;;###autoload -(progn (defvar-local php-project-php-executable nil "Path to php executable file.") (put 'php-project-php-executable 'safe-local-variable - #'(lambda (v) (and (stringp v) (file-executable-p v))))) + #'(lambda (v) (and (stringp v) (file-executable-p v)))) -;;;###autoload -(progn (defvar-local php-project-phan-executable nil "Path to phan executable file.") - (put 'php-project-phan-executable 'safe-local-variable #'php-project--eval-bootstrap-scripts)) + (put 'php-project-phan-executable 'safe-local-variable #'php-project--eval-bootstrap-scripts) -;;;###autoload -(progn (defvar-local php-project-coding-style nil "Symbol value of the coding style of the project that PHP major mode refers to. Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.") - (put 'php-project-coding-style 'safe-local-variable #'symbolp)) + (put 'php-project-coding-style 'safe-local-variable #'symbolp) -;;;###autoload -(progn - (defvar php-project-repl nil + (defvar-local php-project-php-file-as-template 'auto + " +`auto' (default) + Automatically switch to mode for template when HTML tag detected in file. + +`t' + Switch all PHP files in that directory to mode for HTML template. + +`nil' + Any .php in that directory is just a PHP script. + +\(\(PATTERN . SYMBOL)) + Alist of file name pattern regular expressions and the above symbol pairs. + PATTERN is regexp pattern. +") + (put 'php-project-php-file-as-template 'safe-local-variable #'php-project--validate-php-file-as-template) + + (defvar-local php-project-repl nil "Function name or path to REPL (interactive shell) script.") - (make-variable-buffer-local 'php-project-repl) (put 'php-project-repl 'safe-local-variable #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v))))) + (php-project--eval-bootstrap-scripts v)))) -;;;###autoload -(progn - (defvar php-project-unit-test nil + (defvar-local php-project-unit-test nil "Function name or path to unit test script.") - (make-variable-buffer-local 'php-project-unit-test) (put 'php-project-unit-test 'safe-local-variable #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v))))) + (php-project--eval-bootstrap-scripts v)))) -;;;###autoload -(progn - (defvar php-project-deploy nil + (defvar-local php-project-deploy nil "Function name or path to deploy script.") - (make-variable-buffer-local 'php-project-deploy) (put 'php-project-deploy 'safe-local-variable #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v))))) + (php-project--eval-bootstrap-scripts v)))) -;;;###autoload -(progn - (defvar php-project-build nil + (defvar-local php-project-build nil "Function name or path to build script.") - (make-variable-buffer-local 'php-project-build) (put 'php-project-build 'safe-local-variable #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v))))) + (php-project--eval-bootstrap-scripts v)))) -;;;###autoload -(progn - (defvar php-project-server-start nil + (defvar-local php-project-server-start nil "Function name or path to server-start script.") - (make-variable-buffer-local 'php-project-server-start) (put 'php-project-server-start 'safe-local-variable #'(lambda (v) (or (functionp v) (php-project--eval-bootstrap-scripts v))))) ;; Functions +(defun php-project--validate-php-file-as-template (val) + "Return T when `VAL' is valid list of safe ." + (cond + ((null val) t) + ((memq val '(t auto)) t) + ((listp val) + (cl-loop for v in val + always (and (consp v) + (stringp (car v)) + (php-project--validate-php-file-as-template (cdr v))))) + (t nil))) (defun php-project--eval-bootstrap-scripts (val) "Return T when `VAL' is valid list of safe bootstrap php script." @@ -213,6 +218,17 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.") (cons 'root "vendor/bin/phan")))) (executable-find "phan"))) +(defun php-project-get-file-html-template-type (filename) + "Return symbol T, NIL or `auto' by `FILENAME'." + (cond + ((not php-project-php-file-as-template) nil) + ((eq t php-project-php-file-as-template) t) + ((eq 'auto php-project-php-file-as-template) 'auto) + ((listp php-project-php-file-as-template) + (assoc-default filename php-project-php-file-as-template #'string-match-p)) + (t (prog1 nil + (warn "php-project-php-file-as-template is unexpected format"))))) + ;;;###autoload (defun php-project-get-bootstrap-scripts () "Return list of bootstrap script." diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el index db9e46d..13f2cef 100644 --- a/.emacs.d/lisp/php.el +++ b/.emacs.d/lisp/php.el @@ -4,7 +4,7 @@ ;; Author: USAMI Kenta ;; Created: 5 Dec 2018 -;; Version: 1.21.2 +;; Version: 1.21.3 ;; Keywords: languages, php ;; Homepage: https://github.com/emacs-php/php-mode ;; Package-Requires: ((emacs "24.3") (cl-lib "0.5")) @@ -29,6 +29,7 @@ ;;; Code: (require 'flymake) +(require 'php-project) ;;;###autoload (defgroup php nil @@ -40,17 +41,23 @@ (defcustom php-executable (or (executable-find "php") "/usr/bin/php") "The location of the PHP executable." + :group 'php + :tag "PHP Executable" :type 'string) (defcustom php-site-url "https://php.net/" "Default PHP.net site URL. The URL to use open PHP manual and search word." + :group 'php + :tag "PHP Site URL" :type 'string) (defcustom php-manual-url 'en "URL at which to find PHP manual. You can replace \"en\" with your ISO language code." + :group 'php + :tag "PHP Manual URL" :type '(choice (const :tag "English" 'en) (const :tag "Brazilian Portuguese" 'pt_BR) (const :tag "Chinese (Simplified)" 'zh) @@ -66,6 +73,7 @@ You can replace \"en\" with your ISO language code." (defcustom php-search-url nil "URL at which to search for documentation on a word." :group 'php + :tag "PHP Search URL" :type '(choice (string :tag "URL to search PHP documentation") (const :tag "Use `php-site-url' variable" nil))) @@ -78,6 +86,41 @@ You can replace \"en\" with your ISO language code." "Suffix for inserted namespace." :group 'php :type 'string) + +(defcustom php-default-major-mode 'php-mode + "Major mode for editing PHP script." + :group 'php + :tag "PHP Default Major Mode" + :type 'function) + +(defcustom php-html-template-major-mode 'web-mode + "Major mode for editing PHP-HTML template." + :group 'php + :tag "PHP-HTML Template Major Mode" + :type 'function) + +(defcustom php-blade-template-major-mode 'web-mode + "Major mode for editing Blade template." + :group 'php + :tag "PHP Blade Template Major Mode" + :type 'function) + +(defcustom php-template-mode-alist + `(("\\.blade" . ,php-blade-template-major-mode) + ("\\.phpt\\'" . ,(if (fboundp 'phpt-mode) 'phpt-mode php-html-template-major-mode)) + ("\\.phtml\\'" . ,php-html-template-major-mode)) + "Automatically use another MAJOR-MODE when open template file." + :group 'php + :tag "PHP Template Mode Alist" + :type '(alist :key-type regexp :value-type function) + :link '(url-link :tag "web-mode" "http://web-mode.org/") + :link '(url-link :tag "phpt-mode" "https://github.com/emacs-php/phpt-mode")) + +(defcustom php-mode-maybe-hook nil + "List of functions to be executed on entry to `php-mode-maybe'." + :group 'php + :tag "PHP Mode Maybe Hook" + :type 'hook) ;;; PHP Keywords (defconst php-magical-constants @@ -101,6 +144,11 @@ it is the character that will terminate the string, or t if the string should be "Return character address of start of comment or string; nil if not in one." (nth 8 (syntax-ppss))) +(defsubst php-in-poly-php-html-mode () + "Return T if current buffer is in `poly-html-mode'." + (and (boundp 'poly-php-html-mode) + (symbol-value 'poly-php-html-mode))) + (defun php-create-regexp-for-method (visibility) "Make a regular expression for methods with the given VISIBILITY. @@ -187,6 +235,54 @@ Look at the `php-executable' variable instead of the constant \"php\" command." 'flymake-php-init))))) (list php-executable (cdr init)))) +(defconst php-re-detect-html-tag + (eval-when-compile + (rx (or (: string-start (* (in space)) + "")) + (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">")))))) + +(defun php-buffer-has-html-tag () + "Return position of HTML tag or NIL in current buffer." + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (re-search-forward php-re-detect-html-tag nil t)))) + +(defun php-derivation-major-mode () + "Return major mode for PHP file by file-name and its content." + (let ((mode (assoc-default buffer-file-name + php-template-mode-alist + #'string-match-p)) + type) + (when (and (null mode) buffer-file-name + php-project-php-file-as-template) + (setq type (php-project-get-file-html-template-type buffer-file-name)) + (cond + ((eq t type) (setq mode php-html-template-major-mode)) + ((eq 'auto type) + (when (php-buffer-has-html-tag) + (setq mode php-html-template-major-mode))))) + (when (and mode (not (fboundp mode))) + (if (string-match-p "\\.blade\\." buffer-file-name) + (warn "php-mode is NOT support blade template. %s" + "Please install `web-mode' package") + (setq mode nil))) + (or mode php-default-major-mode))) + +;;;###autoload +(defun php-mode-maybe () + "Select PHP mode or other major mode." + (interactive) + (run-hooks php-mode-maybe-hook) + (funcall (php-derivation-major-mode))) + ;;;###autoload (defun php-current-class () "Insert current class name if cursor in class context." -- cgit v1.3