Actualizar php-mode

This commit is contained in:
kj 2021-06-08 02:00:16 -04:00
parent 0dca4fac3e
commit 719e3d9e1e
24 changed files with 5067 additions and 4550 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2020-12-05T06:05:02-0400 using RSA Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2021-06-07T05:05:02-0400 using RSA

File diff suppressed because it is too large Load Diff

View File

@ -1,39 +0,0 @@
;;; php-local-manual.el --- Tools for local PHP manual -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Friends of Emacs-PHP development
;; Author: Eric James Michael Ritz
;; Maintainer: USAMI Kenta <tadsan@zonu.me>
;; URL: https://github.com/emacs-php/php-mode
;; Keywords: docs, php
;; Version: 2.0.0
;; License: GPL-3.0-or-later
;; 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 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 program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package helps you search the locally installed PHP Manual.
;; If you're only developing online, this feature is probably unnecessary.
;;; Code:
(require 'php-mode)
(defalias 'php-local-manual-search #'php-search-local-documentation)
;; TODO: move implementation
;; (define-obsolete-function-alias 'php-search-local-documentation #'php-local-manual-search)
(provide 'php-local-manual)
;;; php-local-manual.el ends here

Binary file not shown.

View File

@ -7,7 +7,7 @@
;; Maintainer: USAMI Kenta <tadsan@zonu.me> ;; Maintainer: USAMI Kenta <tadsan@zonu.me>
;; Keywords: php languages convenience align ;; Keywords: php languages convenience align
;; Homepage: https://github.com/emacs-php/php-mode ;; Homepage: https://github.com/emacs-php/php-mode
;; Version: 1.23.0 ;; Version: 1.24.0
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify

View File

@ -4,7 +4,7 @@
;; Author: USAMI Kenta <tadsan@zonu.me> ;; Author: USAMI Kenta <tadsan@zonu.me>
;; Created: 5 May 2019 ;; Created: 5 May 2019
;; Version: 1.23.0 ;; Version: 1.24.0
;; Keywords: faces, php ;; Keywords: faces, php
;; Homepage: https://github.com/emacs-php/php-mode ;; Homepage: https://github.com/emacs-php/php-mode
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later

View File

@ -0,0 +1,217 @@
;;; php-local-manual.el --- Tools for local PHP manual -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Friends of Emacs-PHP development
;; Author: phil-s
;; Maintainer: USAMI Kenta <tadsan@zonu.me>
;; URL: https://github.com/emacs-php/php-mode/wiki/Local-PHP-Manual
;; Keywords: docs, php
;; Version: 2.0.0
;; License: GPL-3.0-or-later
;; 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 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 program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package helps you search the locally installed PHP Manual.
;; If you're only developing online, this feature is probably unnecessary.
;;
;; ## Notice
;;
;; This file is marked as an unmaintained feature.
;; https://github.com/emacs-php/php-mode/wiki/Unmaintained-Features
;;
;; ## How to use
;;
;; see https://github.com/emacs-php/php-mode/wiki/Local-PHP-Manual
;;
;; ### php-local-manual-search
;;
;; Put follows code into your .emacs (~/.emacs.d/init.el) file:
;;
;; (custom-set-variables
;; '(php-manual-path (expand-file-name "~/local/share/php-manual"))
;; '(php-search-documentation-function #'php-local-manual-search))
;;
;;; Code:
(require 'php)
(require 'etags)
(defconst php-local-manual-documentation-types
'("function" "control-structures" "class" "book")
;; "intro" and "ref" also look interesting, but for all practical purposes
;; their terms are sub-sets of the "book" terms (with the few exceptions
;; being very unlikely search terms).
"The set (and priority sequence) of documentation file prefixes
under which to search for files in the local documentation directory.")
(defvar php-local-manual--words-cache nil)
(defun php-local-manual--read-arg ()
"Obtain interactive argument for searching documentation."
;; Cache the list of documentation words available for completion,
;; based on the defined types-of-interest.
(let ((types-list php-local-manual-documentation-types)
(words-cache php-local-manual--words-cache)
(local-manual (and (stringp php-manual-path)
(not (string= php-manual-path "")))))
(when (and local-manual
(not (assq types-list words-cache)))
;; Generate the cache on the first run, or if the types changed.
;; We read the filenames matching our types list in the local
;; documentation directory, and extract the 'middle' component
;; of each. e.g. "function.array-map.html" => "array_map".
(let* ((types-opt (regexp-opt types-list))
(pattern (concat "\\`" types-opt "\\.\\(.+\\)\\.html\\'"))
(collection
(mapcar (lambda (filename)
(subst-char-in-string ?- ?_ (replace-regexp-in-string
pattern "\\1" filename)))
(directory-files php-manual-path nil pattern))))
;; Replace the entire cache. If the types changed, we don't need
;; to retain the collection for the previous value.
(setq words-cache (list (cons types-list collection)))
(setq php-local-manual--words-cache words-cache)))
;; By default we search for (current-word) immediately, without prompting.
;; With a prefix argument, or if there is no (current-word), we perform a
;; completing read for a word from the cached collection.
(let* ((default (current-word))
(prompt (if default
(format "Search PHP docs (%s): " default)
"Search PHP docs: "))
(collection (and local-manual
(cdr (assq types-list words-cache))))
(word (if (or current-prefix-arg (not default))
(completing-read prompt collection nil nil nil nil default)
default)))
;; Return interactive argument list.
(list word))))
;;;###autoload
(defun php-local-manual-search (word)
"Search the local PHP documentation (i.e. in `php-manual-path') for
the word at point. The function returns t if the requested documentation
exists, and nil otherwise.
With a prefix argument, prompt (with completion) for a word to search for."
(interactive (php-local-manual--read-arg))
(let ((file (catch 'found
(cl-loop for type in php-local-manual-documentation-types do
(let* ((doc-html (format "%s.%s.html"
type
(replace-regexp-in-string
"_" "-" (downcase word))))
(file (expand-file-name doc-html php-manual-path)))
(when (file-exists-p file)
(throw 'found file)))))))
(when file
(let ((file-url (if (string-prefix-p "file://" file)
file
(concat "file://" file))))
(php-browse-documentation-url file-url))
t)))
;;;###autoload
(define-obsolete-function-alias 'php-search-local-documentation #'php-local-manual-search "2.0.0")
;; Define function name completion function
(defvar php-local-manual--completion-table nil
"Obarray of tag names defined in current tags table and functions known to PHP.")
(defun php-local-manual-complete-function ()
"Perform function completion on the text around point.
Completes to the set of names listed in the current tags table
and the standard php functions.
The string to complete is chosen in the same way as the default
for \\[find-tag] (which see)."
(interactive)
(let ((pattern (php-get-pattern))
beg
completion
(php-functions (php-local-manual-completion-table)))
(if (not pattern) (message "Nothing to complete")
(if (not (search-backward pattern nil t))
(message "Can't complete here")
(setq beg (point))
(forward-char (length pattern))
(setq completion (try-completion pattern php-functions nil))
(cond ((eq completion t))
((null completion)
(message "Can't find completion for \"%s\"" pattern)
(ding))
((not (string= pattern completion))
(delete-region beg (point))
(insert completion))
(t
(let ((selected (completing-read
"Select completion: "
(all-completions pattern php-functions)
nil t pattern)))
(delete-region beg (point))
(insert selected))))))))
(defun php-local-manual-completion-table ()
"Build variable `php-local-manual--completion-table' on demand.
The table includes the PHP functions and the tags from the
current `tags-file-name'."
(or (and tags-file-name
(save-excursion (tags-verify-table tags-file-name))
php-local-manual--completion-table)
(let ((tags-table
(when tags-file-name
(with-current-buffer (get-file-buffer tags-file-name)
(etags-tags-completion-table))))
(php-table
(cond ((and (not (string= "" php-completion-file))
(file-readable-p php-completion-file))
(php-local-manual-build-table-from-file php-completion-file))
((and (not (string= "" php-manual-path))
(file-directory-p php-manual-path))
(php-local-manual-build-table-from-path php-manual-path))
(t nil))))
(unless (or php-table tags-table)
(user-error
(concat "No TAGS file active nor are "
"`php-completion-file' or `php-manual-path' set")))
(when tags-table
;; Combine the tables.
(if (obarrayp tags-table)
(mapatoms (lambda (sym) (intern (symbol-name sym) php-table))
tags-table)
(setq php-table (append tags-table php-table))))
(setq php-local-manual--completion-table php-table))))
(defun php-local-manual-build-table-from-file (filename)
(let ((table (make-vector 1022 0))
(buf (find-file-noselect filename)))
(with-current-buffer buf
(goto-char (point-min))
(while (re-search-forward
"^\\([-a-zA-Z0-9_.]+\\)\n"
nil t)
(intern (buffer-substring (match-beginning 1) (match-end 1))
table)))
(kill-buffer buf)
table))
(defun php-local-manual-build-table-from-path (path)
"Return list of PHP function name from `PATH' directory."
(cl-loop for file in (directory-files path nil "^function\\..+\\.html$")
if (string-match "\\.\\([-a-zA-Z_0-9]+\\)\\.html$" file)
collect (replace-regexp-in-string
"-" "_" (substring file (match-beginning 1) (match-end 1)) t)))
(provide 'php-local-manual)
;;; php-local-manual.el ends here

Binary file not shown.

View File

@ -12,24 +12,16 @@
(let ((loads (get 'php 'custom-loads))) (if (member '"php" loads) nil (put 'php 'custom-loads (cons '"php" loads)))) (let ((loads (get 'php 'custom-loads))) (if (member '"php" loads) nil (put 'php 'custom-loads (cons '"php" loads))))
(autoload 'php-mode-maybe "php" "\ (autoload 'php-mode-maybe "php" "\
Select PHP mode or other major mode. Select PHP mode or other major mode." t nil)
\(fn)" t nil)
(autoload 'php-current-class "php" "\ (autoload 'php-current-class "php" "\
Insert current class name if cursor in class context. Insert current class name if cursor in class context." t nil)
\(fn)" t nil)
(autoload 'php-current-namespace "php" "\ (autoload 'php-current-namespace "php" "\
Insert current namespace if cursor in namespace context. Insert current namespace if cursor in namespace context." t nil)
\(fn)" t nil)
(autoload 'php-copyit-fqsen "php" "\ (autoload 'php-copyit-fqsen "php" "\
Copy/kill class/method FQSEN. Copy/kill class/method FQSEN." t nil)
\(fn)" t nil)
(autoload 'php-run-builtin-web-server "php" "\ (autoload 'php-run-builtin-web-server "php" "\
Run PHP Built-in web server. Run PHP Built-in web server.
@ -56,13 +48,16 @@ Find php.ini FILE by `php --ini'.
;;; Generated autoloads from php-align.el ;;; Generated autoloads from php-align.el
(autoload 'php-align-setup "php-align" "\ (autoload 'php-align-setup "php-align" "\
Setup alignment configuration for PHP code. Setup alignment configuration for PHP code." nil nil)
\(fn)" nil nil)
(autoload 'php-align-mode "php-align" "\ (autoload 'php-align-mode "php-align" "\
Alignment lines for PHP script. Alignment lines for PHP script.
If called interactively, enable Php-Align mode if ARG is
positive, and disable it if ARG is zero or negative. If called
from Lisp, also enable the mode if ARG is omitted or nil, and
toggle it if ARG is `toggle'; disable the mode otherwise.
\(fn &optional ARG)" t nil) \(fn &optional ARG)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-align" '("php-align-"))) (if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-align" '("php-align-")))
@ -82,7 +77,18 @@ Alignment lines for PHP script.
;;;;;; 0 0 0)) ;;;;;; 0 0 0))
;;; Generated autoloads from php-local-manual.el ;;; Generated autoloads from php-local-manual.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-local-manual" '("php-local-manual-search"))) (autoload 'php-local-manual-search "php-local-manual" "\
Search the local PHP documentation (i.e. in `php-manual-path') for
the word at point. The function returns t if the requested documentation
exists, and nil otherwise.
With a prefix argument, prompt (with completion) for a word to search for.
\(fn WORD)" t nil)
(define-obsolete-function-alias 'php-search-local-documentation #'php-local-manual-search "2.0.0")
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-local-manual" '("php-local-manual-")))
;;;*** ;;;***
@ -91,7 +97,7 @@ Alignment lines for PHP script.
(let ((loads (get 'php-mode 'custom-loads))) (if (member '"php-mode" loads) nil (put 'php-mode 'custom-loads (cons '"php-mode" loads)))) (let ((loads (get 'php-mode 'custom-loads))) (if (member '"php-mode" loads) nil (put 'php-mode 'custom-loads (cons '"php-mode" loads))))
(if (version< emacs-version "24.4") (dolist (i '("php" "php5" "php7")) (add-to-list 'interpreter-mode-alist (cons i 'php-mode))) (add-to-list 'interpreter-mode-alist (cons "php\\(?:-?[3457]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode))) (add-to-list 'interpreter-mode-alist (cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode))
(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") (define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0")
@ -217,14 +223,10 @@ Function name or path to server-start script.")
(put 'php-project-server-start 'safe-local-variable #'(lambda (v) (or (functionp v) (php-project--eval-bootstrap-scripts v)))) (put 'php-project-server-start 'safe-local-variable #'(lambda (v) (or (functionp v) (php-project--eval-bootstrap-scripts v))))
(autoload 'php-project-get-bootstrap-scripts "php-project" "\ (autoload 'php-project-get-bootstrap-scripts "php-project" "\
Return list of bootstrap script. Return list of bootstrap script." nil nil)
\(fn)" nil nil)
(autoload 'php-project-get-root-dir "php-project" "\ (autoload 'php-project-get-root-dir "php-project" "\
Return path to current PHP project. Return path to current PHP project." nil nil)
\(fn)" nil nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-project" '("php-project-"))) (if (fboundp 'register-definition-prefixes) (register-definition-prefixes "php-project" '("php-project-")))

View File

@ -5,7 +5,7 @@
;; Author: USAMI Kenta <tadsan@zonu.me> ;; Author: USAMI Kenta <tadsan@zonu.me>
;; URL: https://github.com/emacs-php/php-mode ;; URL: https://github.com/emacs-php/php-mode
;; Keywords: maint ;; Keywords: maint
;; Version: 1.23.0 ;; Version: 1.24.0
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify

View File

@ -1,11 +1,11 @@
(define-package "php-mode" "20200812.1129" "Major mode for editing PHP code" (define-package "php-mode" "20210519.1728" "Major mode for editing PHP code"
'((emacs "24.3")) '((emacs "25.2"))
:commit "f4c7c6995dadcdc6da5fefadfd362f8418b2eec1" :keywords :commit "9561a6c0a92a3d7c00e7e57972f42cb5be775898" :authors
'("languages" "php")
:authors
'(("Eric James Michael Ritz")) '(("Eric James Michael Ritz"))
:maintainer :maintainer
'("USAMI Kenta" . "tadsan@zonu.me") '("USAMI Kenta" . "tadsan@zonu.me")
:keywords
'("languages" "php")
:url "https://github.com/emacs-php/php-mode") :url "https://github.com/emacs-php/php-mode")
;; Local Variables: ;; Local Variables:
;; no-byte-compile: t ;; no-byte-compile: t

View File

@ -1,4 +1,4 @@
;;; php-mode.el --- Major mode for editing PHP code ;;; php-mode.el --- Major mode for editing PHP code -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Friends of Emacs-PHP development ;; Copyright (C) 2020 Friends of Emacs-PHP development
;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad
@ -9,11 +9,11 @@
;; Maintainer: USAMI Kenta <tadsan@zonu.me> ;; Maintainer: USAMI Kenta <tadsan@zonu.me>
;; URL: https://github.com/emacs-php/php-mode ;; URL: https://github.com/emacs-php/php-mode
;; Keywords: languages php ;; Keywords: languages php
;; Version: 1.23.0 ;; Version: 1.24.0
;; Package-Requires: ((emacs "24.3")) ;; Package-Requires: ((emacs "25.2"))
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later
(defconst php-mode-version-number "1.23.0" (defconst php-mode-version-number "1.24.0"
"PHP Mode version number.") "PHP Mode version number.")
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -56,9 +56,9 @@
(require 'php) (require 'php)
(require 'php-face) (require 'php-face)
(require 'cc-mode) (require 'cc-mode)
(require 'cc-langs)
(eval-when-compile (eval-when-compile
(require 'cc-langs)
(require 'cc-fonts)) (require 'cc-fonts))
;; Boilerplate from other `cc-mode' derived modes. See ;; Boilerplate from other `cc-mode' derived modes. See
@ -69,45 +69,22 @@
(require 'font-lock) (require 'font-lock)
(require 'custom) (require 'custom)
(require 'etags)
(require 'speedbar) (require 'speedbar)
(require 'imenu) (require 'imenu)
(require 'nadvice nil t) (require 'package)
(require 'nadvice)
(require 'cl-lib)
(require 'mode-local) (require 'mode-local)
(require 'php-project) (require 'php-project)
(eval-when-compile (eval-when-compile
(require 'rx)
(require 'cl-lib)
(require 'regexp-opt) (require 'regexp-opt)
(defvar add-log-current-defun-header-regexp) (defvar add-log-current-defun-header-regexp)
(defvar add-log-current-defun-function) (defvar add-log-current-defun-function)
(defvar c-vsemi-status-unknown-p) (defvar c-vsemi-status-unknown-p)
(defvar syntax-propertize-via-font-lock)) (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
(when (and (= emacs-major-version 24) (>= emacs-minor-version 4))
(require 'cl)))
;; Work around https://github.com/emacs-php/php-mode/issues/310.
;;
;; In emacs 24.4 and 24.5, lines after functions with a return type
;; are incorrectly analyzed as member-init-cont.
;;
;; Before emacs 24.4, c member initializers are not supported this
;; way. Starting from emacs 25.1, cc-mode only detects member
;; initializers when the major mode is c++-mode.
(eval-and-compile
(if (and (= emacs-major-version 24) (or (= emacs-minor-version 4)
(= emacs-minor-version 5)))
(defun c-back-over-member-initializers ()
;; Override of cc-engine.el, cc-mode in emacs 24.4 and 24.5 are too
;; optimistic in recognizing c member initializers. Since we don't
;; need it in php-mode, just return nil.
nil)))
(autoload 'php-mode-debug "php-mode-debug" (autoload 'php-mode-debug "php-mode-debug"
"Display informations useful for debugging PHP Mode." t) "Display informations useful for debugging PHP Mode." t)
@ -191,21 +168,10 @@ enabled."
:tag "PHP Mode Do Not Use Semantic Imenu" :tag "PHP Mode Do Not Use Semantic Imenu"
:type 'boolean) :type 'boolean)
(defcustom php-completion-file ""
"Path to the file which contains the function names known to PHP."
:type 'string)
(defcustom php-manual-path ""
"Path to the directory which contains the PHP manual."
:type 'string)
;;;###autoload ;;;###autoload
(if (version< emacs-version "24.4") (add-to-list 'interpreter-mode-alist
(dolist (i '("php" "php5" "php7")) ;; Match php, php-3, php5, php7, php5.5, php-7.0.1, etc.
(add-to-list 'interpreter-mode-alist (cons i 'php-mode))) (cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode))
(add-to-list 'interpreter-mode-alist
;; Match php, php-3, php5, php7, php5.5, php-7.0.1, etc.
(cons "php\\(?:-?[3457]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode)))
(defcustom php-mode-hook nil (defcustom php-mode-hook nil
"List of functions to be executed on entry to `php-mode'." "List of functions to be executed on entry to `php-mode'."
@ -318,6 +284,9 @@ In that case set to `NIL'."
:tag "PHP Mode Enable Project Local Variable" :tag "PHP Mode Enable Project Local Variable"
:type 'boolean) :type 'boolean)
(defconst php-mode-cc-vertion
(eval-when-compile c-version))
(defun php-mode-version () (defun php-mode-version ()
"Display string describing the version of PHP Mode." "Display string describing the version of PHP Mode."
(interactive) (interactive)
@ -414,8 +383,7 @@ In that case set to `NIL'."
php "\\s-*\\(<\\?(=\\|\\sw+)\\)") php "\\s-*\\(<\\?(=\\|\\sw+)\\)")
(c-lang-defconst c-identifier-ops (c-lang-defconst c-identifier-ops
php '( php '((left-assoc "\\" "::" "->")
(left-assoc "\\" "::" "->")
(prefix "\\" "::"))) (prefix "\\" "::")))
(c-lang-defconst c-operators (c-lang-defconst c-operators
@ -472,25 +440,25 @@ In that case set to `NIL'."
(c-lang-defconst c-primitive-type-kwds (c-lang-defconst c-primitive-type-kwds
php '("int" "integer" "bool" "boolean" "float" "double" "real" php '("int" "integer" "bool" "boolean" "float" "double" "real"
"string" "object" "void" "mixed")) "string" "object" "void" "mixed" "never"))
(c-lang-defconst c-class-decl-kwds (c-lang-defconst c-class-decl-kwds
"Keywords introducing declarations where the following block (if any) "Keywords introducing declarations where the following block (if any)
contains another declaration level that should be considered a class." contains another declaration level that should be considered a class."
php '("class" "trait" "interface")) php '("class" "trait" "interface" "enum"))
(c-lang-defconst c-brace-list-decl-kwds (c-lang-defconst c-brace-list-decl-kwds
"Keywords introducing declarations where the following block (if "Keywords introducing declarations where the following block (if
any) is a brace list. any) is a brace list.
PHP does not have an \"enum\"-like keyword." PHP does not have an C-like \"enum\" keyword."
php nil) php nil)
(c-lang-defconst c-typeless-decl-kwds (c-lang-defconst c-typeless-decl-kwds
php (append (c-lang-const c-class-decl-kwds) '("function"))) php (append (c-lang-const c-class-decl-kwds) '("function")))
(c-lang-defconst c-modifier-kwds (c-lang-defconst c-modifier-kwds
php '("abstract" "const" "final" "static")) php '("abstract" "const" "final" "static" "case"))
(c-lang-defconst c-protection-kwds (c-lang-defconst c-protection-kwds
"Access protection label keywords in classes." "Access protection label keywords in classes."
@ -528,8 +496,7 @@ PHP does not have an \"enum\"-like keyword."
(c-lang-defconst c-other-kwds (c-lang-defconst c-other-kwds
"Keywords not accounted for by any other `*-kwds' language constant." "Keywords not accounted for by any other `*-kwds' language constant."
php php
'( '("__halt_compiler"
"__halt_compiler"
"and" "and"
"array" "array"
"as" "as"
@ -911,19 +878,18 @@ This is was done due to the problem reported here:
(if pos (if pos
(goto-char pos) (goto-char pos)
(setq pos (point))) (setq pos (point)))
(unless (php-in-string-or-comment-p) (cond
(or ;; Detect PHP8 attribute: #[Attribute()]
;; Detect PHP8 attribute: <<Attribute()>> ((and (< 1 pos) (< 1 (- pos (c-point 'bol))))
(when (and (< 2 pos) (< 2 (- pos (c-point 'bol)))) (backward-char 1)
(backward-char 2) (looking-at-p (eval-when-compile (rx "]" (* (syntax whitespace)) (or "#[" line-end)))))
(looking-at-p ">>\\s-*\\(?:<<\\|$\\)")) ;; Detect HTML/XML tag and PHP tag (<?php, <?=, ?>)
;; Detect HTML/XML tag and PHP tag (<?php, <?=, ?>) (php-mode-template-compatibility
(when php-mode-template-compatibility (beginning-of-line)
(beginning-of-line) (looking-at-p
(looking-at-p (eval-when-compile
(eval-when-compile (rx (or (: bol (0+ space) "<" (in "?a-z"))
(rx (or (: bol (0+ space) "<" (in "a-z\\?")) (: (0+ not-newline) (in "?a-z") ">" (0+ space) eol)))))))))
(: (0+ not-newline) (in "a-z\\?") ">" (0+ space) eol))))))))))
(defun php-c-vsemi-status-unknown-p () (defun php-c-vsemi-status-unknown-p ()
"Always return NIL. See `c-vsemi-status-unknown-p'." "Always return NIL. See `c-vsemi-status-unknown-p'."
@ -967,7 +933,12 @@ this ^ lineup"
(eval-and-compile (eval-and-compile
(defconst php-heredoc-start-re (defconst php-heredoc-start-re
"<<<\\(?:\\_<.+?\\_>\\|'\\_<.+?\\_>'\\|\"\\_<.+?\\_>\"\\)$" (rx "<<<"
(* (syntax whitespace))
(or (group (+ (or (syntax word) (syntax symbol))))
(: "\"" (group (+ (or (syntax word) (syntax symbol)))) "\"")
(: "'" (group (+ (or (syntax word) (syntax symbol)))) "'"))
line-end)
"Regular expression for the start of a PHP heredoc.")) "Regular expression for the start of a PHP heredoc."))
(defun php-heredoc-end-re (heredoc-start) (defun php-heredoc-end-re (heredoc-start)
@ -976,27 +947,40 @@ this ^ lineup"
(string-match "\\_<.+?\\_>" heredoc-start) (string-match "\\_<.+?\\_>" heredoc-start)
(concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W")) (concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W"))
(defun php-syntax-propertize-function (start end) (eval-and-compile
"Apply propertize rules from START to END." (defconst php-syntax-propertize-rules
(goto-char start) `((php-heredoc-start-re
(while (and (< (point) end) (0 (ignore (php--syntax-propertize-heredoc
(re-search-forward php-heredoc-start-re end t)) (match-beginning 0)
(php-heredoc-syntax)) (or (match-string 1) (match-string 2) (match-string 3))
(goto-char start) (null (match-string 3))))))
(while (re-search-forward "['\"]" end t) (,(rx "#[")
(when (php-in-comment-p) (0 (ignore (php--syntax-propertize-attributes (match-beginning 0)))))
(c-put-char-property (match-beginning 0) (,(rx (or "'" "\"" ))
'syntax-table (string-to-syntax "_"))))) (0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0)))))))
(defun php-heredoc-syntax () (defmacro php-build-propertize-function ()
"Mark the boundaries of searched heredoc." `(syntax-propertize-rules ,@php-syntax-propertize-rules))
(goto-char (match-beginning 0))
(c-put-char-property (point) 'syntax-table (string-to-syntax "|")) (defalias 'php-syntax-propertize-function (php-build-propertize-function)))
(if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t)
(goto-char (match-end 1)) (defun php--syntax-propertize-heredoc (start id is-heredoc)
;; Did not find the delimiter so go to the end of the buffer. "Apply propertize Heredoc and Nowdoc from START, with ID and IS-HEREDOC."
(goto-char (point-max))) (let ((terminator (rx-to-string `(: line-start (* (syntax whitespace)) ,id word-boundary))))
(c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) (put-text-property start (1+ start) 'syntax-table (string-to-syntax "|"))
(re-search-forward terminator nil t)
(when (match-string 0)
(put-text-property (1- (point)) (point) 'syntax-table (string-to-syntax "|")))))
(defun php--syntax-propertize-quotes-in-comment (pos)
"Apply propertize quotes (' and \") from POS."
(when (php-in-comment-p)
(put-text-property pos (1+ pos) 'syntax-table (string-to-syntax "_"))))
(defun php--syntax-propertize-attributes (start)
"Apply propertize PHP8 #[Attributes] (without # comment) from START."
(unless (php-in-string-p)
(put-text-property start (1+ start) 'syntax-table (string-to-syntax "."))))
(defvar-local php-mode--propertize-extend-region-current nil (defvar-local php-mode--propertize-extend-region-current nil
"Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION") "Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION")
@ -1010,8 +994,7 @@ this ^ lineup"
;; turn call this to be called again. ;; turn call this to be called again.
(push pair php-mode--propertize-extend-region-current) (push pair php-mode--propertize-extend-region-current)
(unwind-protect (unwind-protect
(let ((new-start) (let (new-start new-end)
(new-end))
(goto-char start) (goto-char start)
(when (re-search-backward php-heredoc-start-re nil t) (when (re-search-backward php-heredoc-start-re nil t)
(let ((maybe (point))) (let ((maybe (point)))
@ -1095,8 +1078,7 @@ After setting the stylevars run hooks according to STYLENAME
(defun php-mode--disable-delay-set-style (&rest args) (defun php-mode--disable-delay-set-style (&rest args)
"Disable php-mode-set-style-delay on after hook. `ARGS' be ignore." "Disable php-mode-set-style-delay on after hook. `ARGS' be ignore."
(setq php-mode--delayed-set-style nil) (setq php-mode--delayed-set-style nil)
(when (fboundp 'advice-remove) (advice-remove #'php-mode--disable-delay-set-style #'c-set-style))
(advice-remove #'php-mode--disable-delay-set-style #'c-set-style)))
(defun php-mode-set-style-delay () (defun php-mode-set-style-delay ()
"Set the current `php-mode' buffer to use the style by custom or local variables." "Set the current `php-mode' buffer to use the style by custom or local variables."
@ -1131,6 +1113,13 @@ After setting the stylevars run hooks according to STYLENAME
:syntax-table php-mode-syntax-table :syntax-table php-mode-syntax-table
;; :after-hook (c-update-modeline) ;; :after-hook (c-update-modeline)
;; (setq abbrev-mode t) ;; (setq abbrev-mode t)
(unless (string= php-mode-cc-vertion c-version)
(user-error "CC Mode has been updated. %s"
(if (package-installed-p 'php-mode)
"Please run `M-x package-reinstall php-mode' command."
"Please byte recompile PHP Mode files.")))
(when php-mode-disable-c-mode-hook (when php-mode-disable-c-mode-hook
(setq-local c-mode-hook nil) (setq-local c-mode-hook nil)
(setq-local java-mode-hook nil)) (setq-local java-mode-hook nil))
@ -1141,7 +1130,7 @@ After setting the stylevars run hooks according to STYLENAME
(setq-local comment-start "// ") (setq-local comment-start "// ")
(setq-local comment-start-skip (setq-local comment-start-skip
(eval-when-compile (eval-when-compile
(rx (group (or (: "#") (rx (group (or (: "#" (not (any "[")))
(: "/" (+ "/")) (: "/" (+ "/"))
(: "/*"))) (: "/*")))
(* (syntax whitespace))))) (* (syntax whitespace)))))
@ -1160,7 +1149,9 @@ After setting the stylevars run hooks according to STYLENAME
(add-hook 'syntax-propertize-extend-region-functions (add-hook 'syntax-propertize-extend-region-functions
#'php-syntax-propertize-extend-region t t) #'php-syntax-propertize-extend-region t t)
(setq imenu-generic-expression php-imenu-generic-expression) (setq imenu-generic-expression (if (symbolp php-imenu-generic-expression)
(symbol-value php-imenu-generic-expression)
php-imenu-generic-expression))
;; PHP vars are case-sensitive ;; PHP vars are case-sensitive
(setq case-fold-search t) (setq case-fold-search t)
@ -1175,8 +1166,7 @@ After setting the stylevars run hooks according to STYLENAME
(progn (progn
(add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t)
(setq php-mode--delayed-set-style t) (setq php-mode--delayed-set-style t)
(when (fboundp 'advice-add) (advice-add #'c-set-style :after #'php-mode--disable-delay-set-style '(local)))
(advice-add #'c-set-style :after #'php-mode--disable-delay-set-style '(local))))
(let ((php-mode-enable-backup-style-variables nil)) (let ((php-mode-enable-backup-style-variables nil))
(php-set-style (symbol-name php-mode-coding-style)))) (php-set-style (symbol-name php-mode-coding-style))))
@ -1208,7 +1198,8 @@ After setting the stylevars run hooks according to STYLENAME
(when (fboundp 'c-looking-at-or-maybe-in-bracelist) (when (fboundp 'c-looking-at-or-maybe-in-bracelist)
(advice-add #'c-looking-at-or-maybe-in-bracelist (advice-add #'c-looking-at-or-maybe-in-bracelist
:override 'php-c-looking-at-or-maybe-in-bracelist)) :override 'php-c-looking-at-or-maybe-in-bracelist '(local)))
(advice-add #'fixup-whitespace :after #'php-mode--fixup-whitespace-after '(local))
(when (>= emacs-major-version 25) (when (>= emacs-major-version 25)
(with-silent-modifications (with-silent-modifications
@ -1227,10 +1218,7 @@ After setting the stylevars run hooks according to STYLENAME
#'semantic-create-imenu-index) #'semantic-create-imenu-index)
"Imenu index function for PHP.") "Imenu index function for PHP.")
(autoload 'php-local-manual-complete-function "php-local-manual")
;; Define function name completion function
(defvar php-completion-table nil
"Obarray of tag names defined in current tags table and functions known to PHP.")
(defun php-complete-function () (defun php-complete-function ()
"Perform function completion on the text around point. "Perform function completion on the text around point.
@ -1239,102 +1227,7 @@ and the standard php functions.
The string to complete is chosen in the same way as the default The string to complete is chosen in the same way as the default
for \\[find-tag] (which see)." for \\[find-tag] (which see)."
(interactive) (interactive)
(let ((pattern (php-get-pattern)) (php-local-manual-complete-function))
beg
completion
(php-functions (php-completion-table)))
(if (not pattern) (message "Nothing to complete")
(if (not (search-backward pattern nil t))
(message "Can't complete here")
(setq beg (point))
(forward-char (length pattern))
(setq completion (try-completion pattern php-functions nil))
(cond ((eq completion t))
((null completion)
(message "Can't find completion for \"%s\"" pattern)
(ding))
((not (string= pattern completion))
(delete-region beg (point))
(insert completion))
(t
(let ((selected (completing-read
"Select completion: "
(all-completions pattern php-functions)
nil t pattern)))
(delete-region beg (point))
(insert selected))))))))
(defun php-completion-table ()
"Build variable `php-completion-table' on demand.
The table includes the PHP functions and the tags from the
current `tags-file-name'."
(or (and tags-file-name
(save-excursion (tags-verify-table tags-file-name))
php-completion-table)
(let ((tags-table
(when tags-file-name
(with-current-buffer (get-file-buffer tags-file-name)
(etags-tags-completion-table))))
(php-table
(cond ((and (not (string= "" php-completion-file))
(file-readable-p php-completion-file))
(php-build-table-from-file php-completion-file))
((and (not (string= "" php-manual-path))
(file-directory-p php-manual-path))
(php-build-table-from-path php-manual-path))
(t nil))))
(unless (or php-table tags-table)
(error
(concat "No TAGS file active nor are "
"`php-completion-file' or `php-manual-path' set")))
(when tags-table
;; Combine the tables.
(if (obarrayp tags-table)
(mapatoms (lambda (sym) (intern (symbol-name sym) php-table))
tags-table)
(setq php-table (append tags-table php-table))))
(setq php-completion-table php-table))))
(defun php-build-table-from-file (filename)
(let ((table (make-vector 1022 0))
(buf (find-file-noselect filename)))
(with-current-buffer buf
(goto-char (point-min))
(while (re-search-forward
"^\\([-a-zA-Z0-9_.]+\\)\n"
nil t)
(intern (buffer-substring (match-beginning 1) (match-end 1))
table)))
(kill-buffer buf)
table))
(defun php-build-table-from-path (path)
"Return list of PHP function name from `PATH' directory."
(cl-loop for file in (directory-files path nil "^function\\..+\\.html$")
if (string-match "\\.\\([-a-zA-Z_0-9]+\\)\\.html$" file)
collect (replace-regexp-in-string
"-" "_" (substring file (match-beginning 1) (match-end 1)) t)))
;; Find the pattern we want to complete
;; find-tag-default from GNU Emacs etags.el
(defun php-get-pattern ()
(save-excursion
(while (looking-at "\\sw\\|\\s_")
(forward-char 1))
(if (or (re-search-backward "\\sw\\|\\s_"
(save-excursion (beginning-of-line) (point))
t)
(re-search-forward "\\(\\sw\\|\\s_\\)+"
(save-excursion (end-of-line) (point))
t))
(progn (goto-char (match-end 0))
(buffer-substring-no-properties
(point)
(progn (forward-sexp -1)
(while (looking-at "\\s'")
(forward-char 1))
(point))))
nil)))
(defun php-show-arglist () (defun php-show-arglist ()
"Show function arguments at cursor position." "Show function arguments at cursor position."
@ -1354,130 +1247,6 @@ current `tags-file-name'."
(message "Arglist for %s: %s" tagname arglist) (message "Arglist for %s: %s" tagname arglist)
(message "Unknown function: %s" tagname)))) (message "Unknown function: %s" tagname))))
(defcustom php-search-documentation-browser-function nil
"Function to display PHP documentation in a WWW browser.
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))
(defun php-browse-documentation-url (url)
"Browse a documentation URL using the configured browser function.
See `php-search-documentation-browser-function'."
(let ((browse-url-browser-function
(or php-search-documentation-browser-function
browse-url-browser-function)))
(browse-url url)))
(defvar php-search-local-documentation-types
(list "function" "control-structures" "class" "book")
;; "intro" and "ref" also look interesting, but for all practical purposes
;; their terms are sub-sets of the "book" terms (with the few exceptions
;; being very unlikely search terms).
"The set (and priority sequence) of documentation file prefixes
under which to search for files in the local documentation directory.")
(defvar php-search-local-documentation-words-cache nil)
(defun php--search-documentation-read-arg ()
"Obtain interactive argument for searching documentation."
;; Cache the list of documentation words available for completion,
;; based on the defined types-of-interest.
(let ((types-list php-search-local-documentation-types)
(words-cache php-search-local-documentation-words-cache)
(local-manual (and (stringp php-manual-path)
(not (string= php-manual-path "")))))
(when (and local-manual
(not (assq types-list words-cache)))
;; Generate the cache on the first run, or if the types changed.
;; We read the filenames matching our types list in the local
;; documentation directory, and extract the 'middle' component
;; of each. e.g. "function.array-map.html" => "array_map".
(let* ((types-opt (regexp-opt types-list))
(pattern (concat "\\`" types-opt "\\.\\(.+\\)\\.html\\'"))
(collection
(mapcar (lambda (filename) (subst-char-in-string
?- ?_ (replace-regexp-in-string
pattern "\\1" filename)))
(directory-files php-manual-path nil pattern))))
;; Replace the entire cache. If the types changed, we don't need
;; to retain the collection for the previous value.
(setq words-cache (list (cons types-list collection)))
(setq php-search-local-documentation-words-cache words-cache)))
;; By default we search for (current-word) immediately, without prompting.
;; With a prefix argument, or if there is no (current-word), we perform a
;; completing read for a word from the cached collection.
(let* ((default (current-word))
(prompt (if default
(format "Search PHP docs (%s): " default)
"Search PHP docs: "))
(collection (and local-manual
(cdr (assq types-list words-cache))))
(word (if (or current-prefix-arg (not default))
(completing-read prompt collection nil nil nil nil default)
default)))
;; Return interactive argument list.
(list word))))
(defun php-search-local-documentation (word)
"Search the local PHP documentation (i.e. in `php-manual-path') for
the word at point. The function returns t if the requested documentation
exists, and nil otherwise.
With a prefix argument, prompt (with completion) for a word to search for."
(interactive (php--search-documentation-read-arg))
(let ((file (catch 'found
(cl-loop for type in php-search-local-documentation-types do
(let* ((doc-html (format "%s.%s.html"
type
(replace-regexp-in-string
"_" "-" (downcase word))))
(file (expand-file-name doc-html php-manual-path)))
(when (file-exists-p file)
(throw 'found file)))))))
(when file
(let ((file-url (if (string-prefix-p "file://" file)
file
(concat "file://" file))))
(php-browse-documentation-url file-url))
t)))
(defsubst php-search-web-documentation (word)
"Return URL to search PHP manual search by `WORD'."
(php-browse-documentation-url (concat (or php-search-url php-site-url) word)))
;; Define function documentation function
(defun php-search-documentation (word)
"Search PHP documentation for the `WORD' at point.
If `php-manual-path' has a non-empty string value then the command
will first try searching the local documentation. If the requested
documentation does not exist it will fallback to searching the PHP
website.
With a prefix argument, prompt for a documentation word to search
for. If the local documentation is available, it is used to build
a completion list."
(interactive (php--search-documentation-read-arg))
(if (and (stringp php-manual-path)
(not (string= php-manual-path "")))
(or (php-search-local-documentation word)
(php-search-web-documentation word))
(php-search-web-documentation word)))
;; Define function for browsing manual
(defun php-browse-manual ()
"Bring up manual for PHP."
(interactive)
(browse-url (if (stringp php-manual-url)
php-manual-url
(format "%smanual/%s/" php-site-url php-manual-url))))
;; Font Lock ;; Font Lock
(defconst php-phpdoc-type-keywords (defconst php-phpdoc-type-keywords
(list "string" "integer" "int" "boolean" "bool" "float" (list "string" "integer" "int" "boolean" "bool" "float"
@ -1670,7 +1439,9 @@ a completion list."
;; Logical operators (and, or, &&, ...) ;; Logical operators (and, or, &&, ...)
;; Not operator (!) is defined in "before cc-mode" section above. ;; Not operator (!) is defined in "before cc-mode" section above.
("\\(&&\\|||\\)" 1 'php-logical-op))) ("\\(&&\\|||\\)" 1 'php-logical-op)
;; string interpolation ("$var, ${var}, {$var}")
(php-mode--string-interpolated-variable-font-lock-find 0 nil)))
"Detailed highlighting for PHP Mode.") "Detailed highlighting for PHP Mode.")
(defvar php-font-lock-keywords php-font-lock-keywords-3 (defvar php-font-lock-keywords php-font-lock-keywords-3
@ -1702,37 +1473,24 @@ The output will appear in the buffer *PHP*."
(defconst php-string-interpolated-variable-regexp (defconst php-string-interpolated-variable-regexp
"{\\$[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}\\|\\${\\sw+}\\|\\$\\sw+") "{\\$[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}\\|\\${\\sw+}\\|\\$\\sw+")
(defun php-string-intepolated-variable-font-lock-find (limit) (defun php-mode--string-interpolated-variable-font-lock-find (limit)
(while (re-search-forward php-string-interpolated-variable-regexp limit t) "Apply text-property to LIMIT for string interpolation by font-lock."
(let ((quoted-stuff (nth 3 (syntax-ppss)))) (let (quoted-stuff)
(when (and quoted-stuff (member quoted-stuff '(?\" ?`))) (while (re-search-forward php-string-interpolated-variable-regexp limit t)
(put-text-property (match-beginning 0) (match-end 0) (setq quoted-stuff (php-in-string-p))
'face 'php-variable-name)))) (when (or (eq ?\" quoted-stuff) (eq ?` quoted-stuff))
(put-text-property (match-beginning 0) (match-end 0) 'face 'php-variable-name))))
nil) nil)
(eval-after-load 'php-mode
'(progn
(font-lock-add-keywords
'php-mode
`((php-string-intepolated-variable-font-lock-find))
'append)))
;;; Correct the behavior of `delete-indentation' by modifying the ;;; Correct the behavior of `delete-indentation' by modifying the
;;; logic of `fixup-whitespace'. ;;; logic of `fixup-whitespace'.
(defadvice fixup-whitespace (after php-mode-fixup-whitespace) (defun php-mode--fixup-whitespace-after ()
"Remove whitespace before certain characters in PHP Mode." "Remove whitespace before certain characters in PHP Mode."
(let* ((no-behind-space ";\\|,\\|->\\|::") (when (or (looking-at-p " \\(?:;\\|,\\|->\\|::\\)")
(no-front-space "->\\|::")) (save-excursion
(when (and (eq major-mode 'php-mode) (forward-char -2)
(or (looking-at-p (concat " \\(" no-behind-space "\\)")) (looking-at-p "->\\|::")))
(save-excursion (delete-char 1)))
(forward-char -2)
(looking-at-p no-front-space))))
(delete-char 1))))
(ad-activate 'fixup-whitespace)
;;;###autoload ;;;###autoload
(progn (progn

Binary file not shown.

View File

@ -5,7 +5,7 @@
;; Author: USAMI Kenta <tadsan@zonu.me> ;; Author: USAMI Kenta <tadsan@zonu.me>
;; Keywords: tools, files ;; Keywords: tools, files
;; URL: https://github.com/emacs-php/php-mode ;; URL: https://github.com/emacs-php/php-mode
;; Version: 1.23.0 ;; Version: 1.24.0
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -66,7 +66,8 @@
;; ;;
;;; Code: ;;; Code:
(require 'cl-lib) (eval-when-compile
(require 'cl-lib))
(require 'projectile nil t) (require 'projectile nil t)
;; Constants ;; Constants

View File

@ -4,7 +4,7 @@
;; Author: USAMI Kenta <tadsan@zonu.me> ;; Author: USAMI Kenta <tadsan@zonu.me>
;; Created: 5 Dec 2018 ;; Created: 5 Dec 2018
;; Version: 1.23.0 ;; Version: 1.24.0
;; Keywords: languages, php ;; Keywords: languages, php
;; Homepage: https://github.com/emacs-php/php-mode ;; Homepage: https://github.com/emacs-php/php-mode
;; License: GPL-3.0-or-later ;; License: GPL-3.0-or-later
@ -27,7 +27,8 @@
;; This file provides common variable and functions for PHP packages. ;; This file provides common variable and functions for PHP packages.
;;; Code: ;;; Code:
(require 'cl-lib) (eval-when-compile
(require 'cl-lib))
(require 'flymake) (require 'flymake)
(require 'php-project) (require 'php-project)
(require 'rx) (require 'rx)
@ -46,7 +47,7 @@
:tag "PHP Executable" :tag "PHP Executable"
:type 'string) :type 'string)
(defcustom php-site-url "https://php.net/" (defcustom php-site-url "https://www.php.net/"
"Default PHP.net site URL. "Default PHP.net site URL.
The URL to use open PHP manual and search word." The URL to use open PHP manual and search word."
@ -78,6 +79,70 @@ You can replace \"en\" with your ISO language code."
:type '(choice (string :tag "URL to search PHP documentation") :type '(choice (string :tag "URL to search PHP documentation")
(const :tag "Use `php-site-url' variable" nil))) (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)
(defcustom php-manual-path ""
"Path to the directory which contains the PHP manual."
:type 'string)
(defcustom php-search-documentation-function #'php-search-web-documentation
"Function to search PHP Manual at cursor position."
:group 'php
:tag "PHP Search Documentation Function"
:type '(choice (const :tag "Use online documentation" #'php-search-web-documentation)
(const :tag "Use local documentation" #'php-local-manual-search)
(function :tag "Use other function")))
(defcustom php-search-documentation-browser-function nil
"Function to display PHP documentation in a WWW browser.
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))
;; Define function for browsing manual
(defun php-browse-documentation-url (url)
"Browse a documentation URL using the configured browser function.
See `php-search-documentation-browser-function'."
(let ((browse-url-browser-function
(or php-search-documentation-browser-function
browse-url-browser-function)))
(browse-url url)))
(defun php-browse-manual ()
"Bring up manual for PHP."
(interactive)
(browse-url (if (stringp php-manual-url)
php-manual-url
(format "%smanual/%s/" php-site-url php-manual-url))))
(defun php-search-web-documentation (word)
"Return URL to search PHP manual search by `WORD'."
(interactive (list (current-word)))
(php-browse-documentation-url (concat (or php-search-url php-site-url) word)))
(defun php-search-documentation (&optional word)
"Search PHP documentation for the `WORD' at point.
If `php-manual-path' has a non-empty string value then the command
will first try searching the local documentation. If the requested
documentation does not exist it will fallback to searching the PHP
website.
With a prefix argument, prompt for a documentation word to search
for. If the local documentation is available, it is used to build
a completion list."
(interactive)
(if (called-interactively-p 'interactive)
(call-interactively php-search-documentation-function)
(funcall php-search-documentation-function word)))
(defcustom php-class-suffix-when-insert "::" (defcustom php-class-suffix-when-insert "::"
"Suffix for inserted class." "Suffix for inserted class."
:group 'php :group 'php
@ -163,7 +228,7 @@ it is the character that will terminate the string, or t if the string should be
"Regular expression for a PHP function.") "Regular expression for a PHP function.")
(eval-when-compile (eval-when-compile
(defun php-create-regexp-for-method (&optional visibility) (cl-defun php-create-regexp-for-method (&optional visibility &key include-args)
"Make a regular expression for methods with the given VISIBILITY. "Make a regular expression for methods with the given VISIBILITY.
VISIBILITY must be a string that names the visibility for a PHP VISIBILITY must be a string that names the visibility for a PHP
@ -178,22 +243,25 @@ which will be the name of the method."
(setq visibility (list visibility))) (setq visibility (list visibility)))
(rx-to-string `(: line-start (rx-to-string `(: line-start
(* (syntax whitespace)) (* (syntax whitespace))
,@(if visibility (group
`((* (or "abstract" "final" "static") ,@(if visibility
(+ (syntax whitespace))) `((* (or "abstract" "final" "static")
(or ,@visibility) (+ (syntax whitespace)))
(+ (syntax whitespace)) (or ,@visibility)
(* (or "abstract" "final" "static") (+ (syntax whitespace))
(+ (syntax whitespace)))) (* (or "abstract" "final" "static")
'((* (* (or "abstract" "final" "static" (+ (syntax whitespace))))
"private" "protected" "public") '((* (* (or "abstract" "final" "static"
(+ (syntax whitespace)))))) "private" "protected" "public")
"function" (+ (syntax whitespace))))))
(+ (syntax whitespace)) "function"
(? "&" (* (syntax whitespace))) (+ (syntax whitespace))
(group (+ (or (syntax word) (syntax symbol)))) (? "&" (* (syntax whitespace)))
(* (syntax whitespace)) (group (+ (or (syntax word) (syntax symbol))))
"("))) (* (syntax whitespace))
"("
,@(when include-args
'((* any) line-end))))))
(defun php-create-regexp-for-classlike (type) (defun php-create-regexp-for-classlike (type)
"Accepts a `TYPE' of a 'classlike' object as a string, such as "Accepts a `TYPE' of a 'classlike' object as a string, such as
@ -211,7 +279,101 @@ can be used to match against definitions for that classlike."
;; this is not necessarily correct for all values of `type'. ;; this is not necessarily correct for all values of `type'.
"\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)"))) "\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)")))
(defconst php-imenu-generic-expression (defconst php-imenu-generic-expression-default
(eval-when-compile
`(("Methods"
,(php-create-regexp-for-method nil :include-args t) 1)
("Properties"
,(rx line-start
(* (syntax whitespace))
(group
(+ (or "public" "protected" "private" "static" "var")
(+ (syntax whitespace)))
(* (? (? (or "|" "?"))
(or "\\" (syntax word) (syntax symbol))
(+ (syntax whitespace))))
"$" (+ (or (syntax word) (syntax symbol)))
word-boundary))
1)
("Constants"
,(rx line-start
(* (syntax whitespace))
(group
(* (or "public" "protected" "private")
(+ (syntax whitespace)))
"const"
(+ (syntax whitespace))
(+ (or (syntax word) (syntax symbol)))
(* (syntax whitespace))
(? "=" (* (syntax whitespace))
(repeat 0 40 any))))
1)
("Functions"
,(rx line-start
(* (syntax whitespace))
(group
"function"
(+ (syntax whitespace))
(+ (or (syntax word) (syntax symbol)))
(* (syntax whitespace))
"("
(repeat 0 100 any)))
1)
("Import"
,(rx line-start
;; (* (syntax whitespace))
(group
"use"
(+ (syntax whitespace))
(repeat 0 100 any)))
1)
("Classes"
,(php-create-regexp-for-classlike "\\(?:class\\|interface\\|trait\\|enum\\)") 0)
("Namespace"
,(php-create-regexp-for-classlike "namespace") 1)))
"Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
(defconst php-imenu-generic-expression-simple
(eval-when-compile
`(("Methods"
,(php-create-regexp-for-method nil) 2)
("Properties"
,(rx line-start
(* (syntax whitespace))
(+ (or "public" "protected" "private" "static" "var")
(+ (syntax whitespace)))
(* (? (? (or "|" "?"))
(or "\\" (syntax word) (syntax symbol))
(+ (syntax whitespace))))
(group
"$" (+ (or (syntax word) (syntax symbol))))
word-boundary)
1)
("Constants"
,(rx line-start
(* (syntax whitespace))
(group
(* (or "public" "protected" "private")
(+ (syntax whitespace)))
"const"
(+ (syntax whitespace))
(+ (or (syntax word) (syntax symbol)))))
1)
("Functions"
,(rx line-start
(* (syntax whitespace))
"function"
(+ (syntax whitespace))
(group
(+ (or (syntax word) (syntax symbol)))))
1)
("Classes"
,(php-create-regexp-for-classlike "\\(?:class\\|interface\\|trait\\|enum\\)") 1)
("Namespace"
,(php-create-regexp-for-classlike "namespace") 1)))
"Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
(defconst php-imenu-generic-expression-legacy
(eval-when-compile (eval-when-compile
`(("Namespaces" `(("Namespaces"
,(php-create-regexp-for-classlike "namespace") 1) ,(php-create-regexp-for-classlike "namespace") 1)
@ -224,17 +386,25 @@ can be used to match against definitions for that classlike."
("All Methods" ("All Methods"
,(php-create-regexp-for-method) 1) ,(php-create-regexp-for-method) 1)
("Private Methods" ("Private Methods"
,(php-create-regexp-for-method '("private")) 1) ,(php-create-regexp-for-method '("private")) 2)
("Protected Methods" ("Protected Methods"
,(php-create-regexp-for-method '("protected")) 1) ,(php-create-regexp-for-method '("protected")) 2)
("Public Methods" ("Public Methods"
,(php-create-regexp-for-method '("public")) 1) ,(php-create-regexp-for-method '("public")) 2)
("Anonymous Functions" ("Anonymous Functions"
"\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*f\\(unctio\\)?n\\s-*(" 1) "\\<\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*=\\s-*f\\(unctio\\)?n\\s-*(" 1)
("Named Functions" ("Named Functions"
"^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1))) "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1)))
"Imenu generic expression for PHP Mode. See `imenu-generic-expression'.") "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.")
(defcustom php-imenu-generic-expression 'php-imenu-generic-expression-default
"Default Imenu generic expression for PHP Mode. See `imenu-generic-expression'."
:type '(choice (alist :key-type string :value-type list)
(const 'php-imenu-generic-expression-legacy)
(const 'php-imenu-generic-expression-simple)
variable)
:group 'php)
(defconst php--re-namespace-pattern (defconst php--re-namespace-pattern
(eval-when-compile (eval-when-compile
(php-create-regexp-for-classlike "namespace"))) (php-create-regexp-for-classlike "namespace")))
@ -250,6 +420,28 @@ can be used to match against definitions for that classlike."
(when (re-search-backward re-pattern nil t) (when (re-search-backward re-pattern nil t)
(match-string-no-properties 1))))) (match-string-no-properties 1)))))
(defun php-get-pattern ()
"Find the pattern we want to complete.
`find-tag-default' from GNU Emacs etags.el"
(save-excursion
(save-match-data
(while (looking-at "\\sw\\|\\s_")
(forward-char 1))
(when (or (re-search-backward "\\sw\\|\\s_"
(save-excursion (beginning-of-line) (point))
t)
(re-search-forward "\\(\\sw\\|\\s_\\)+"
(save-excursion (end-of-line) (point))
t))
(goto-char (match-end 0))
(buffer-substring-no-properties
(point)
(progn
(forward-sexp -1)
(while (looking-at "\\s'")
(forward-char 1))
(point)))))))
;;; Provide support for Flymake so that users can see warnings and ;;; Provide support for Flymake so that users can see warnings and
;;; errors in real-time as they write code. ;;; errors in real-time as they write code.
(defun php-flymake-php-init () (defun php-flymake-php-init ()

Binary file not shown.

34
init.el
View File

@ -13,26 +13,23 @@
;; If there is more than one, they won't work right. ;; If there is more than one, they won't work right.
'(ansi-color-names-vector '(ansi-color-names-vector
["#212121" "#CC5542" "#6aaf50" "#7d7c61" "#5180b3" "#DC8CC3" "#9b55c3" "#bdbdb3"]) ["#212121" "#CC5542" "#6aaf50" "#7d7c61" "#5180b3" "#DC8CC3" "#9b55c3" "#bdbdb3"])
'(compilation-message-face (quote default)) '(compilation-message-face 'default)
'(custom-enabled-themes (quote (dracula))) '(custom-enabled-themes '(dracula))
'(custom-safe-themes '(custom-safe-themes
(quote '("24714e2cb4a9d6ec1335de295966906474fdb668429549416ed8636196cb1441" "fa2b58bb98b62c3b8cf3b6f02f058ef7827a8e497125de0254f56e373abee088" "bffa9739ce0752a37d9b1eee78fc00ba159748f50dc328af4be661484848e476" "c7eb06356fd16a1f552cfc40d900fe7326ae17ae7578f0ef5ba1edd4fdd09e58" "f3ab34b145c3b2a0f3a570ddff8fabb92dafc7679ac19444c31058ac305275e1" "dcdd1471fde79899ae47152d090e3551b889edf4b46f00df36d653adc2bf550d" "3994b1c5c1f412c025bb71b2df5973a421c257afee5278684639c205d79d93ee" default))
("24714e2cb4a9d6ec1335de295966906474fdb668429549416ed8636196cb1441" "fa2b58bb98b62c3b8cf3b6f02f058ef7827a8e497125de0254f56e373abee088" "bffa9739ce0752a37d9b1eee78fc00ba159748f50dc328af4be661484848e476" "c7eb06356fd16a1f552cfc40d900fe7326ae17ae7578f0ef5ba1edd4fdd09e58" "f3ab34b145c3b2a0f3a570ddff8fabb92dafc7679ac19444c31058ac305275e1" "dcdd1471fde79899ae47152d090e3551b889edf4b46f00df36d653adc2bf550d" "3994b1c5c1f412c025bb71b2df5973a421c257afee5278684639c205d79d93ee" default)))
'(fci-rule-color "#2e2e2e") '(fci-rule-color "#2e2e2e")
'(highlight-changes-colors (quote ("#FD5FF0" "#AE81FF"))) '(highlight-changes-colors '("#FD5FF0" "#AE81FF"))
'(highlight-tail-colors '(highlight-tail-colors
(quote '(("#3C3D37" . 0)
(("#3C3D37" . 0)
("#679A01" . 20) ("#679A01" . 20)
("#4BBEAE" . 30) ("#4BBEAE" . 30)
("#1DB4D0" . 50) ("#1DB4D0" . 50)
("#9A8F21" . 60) ("#9A8F21" . 60)
("#A75B00" . 70) ("#A75B00" . 70)
("#F309DF" . 85) ("#F309DF" . 85)
("#3C3D37" . 100)))) ("#3C3D37" . 100)))
'(hl-todo-keyword-faces '(hl-todo-keyword-faces
(quote '(("TODO" . "#dc752f")
(("TODO" . "#dc752f")
("NEXT" . "#dc752f") ("NEXT" . "#dc752f")
("THEM" . "#2d9574") ("THEM" . "#2d9574")
("PROG" . "#4f97d7") ("PROG" . "#4f97d7")
@ -46,19 +43,17 @@
("TEMP" . "#b1951d") ("TEMP" . "#b1951d")
("FIXME" . "#dc752f") ("FIXME" . "#dc752f")
("XXX+" . "#dc752f") ("XXX+" . "#dc752f")
("\\?\\?\\?+" . "#dc752f")))) ("\\?\\?\\?+" . "#dc752f")))
'(inhibit-startup-screen t) '(inhibit-startup-screen t)
'(magit-diff-use-overlays nil) '(magit-diff-use-overlays nil)
'(package-selected-packages '(package-selected-packages
(quote '(dumb-jump csharp-mode yaml-mode smooth-scrolling web-mode multi-web-mode spacemacs-theme flycheck ac-emmet markdown-preview-mode multiple-cursors git-gutter powerline ample-zen-theme monokai-theme dracula-theme auto-complete neotree all-the-icons spinner markdown-mode lv ht f dash-functional))
(dumb-jump csharp-mode yaml-mode smooth-scrolling web-mode multi-web-mode spacemacs-theme flycheck ac-emmet markdown-preview-mode multiple-cursors git-gutter powerline ample-zen-theme monokai-theme dracula-theme auto-complete neotree all-the-icons spinner markdown-mode lv ht f dash-functional))) '(pdf-view-midnight-colors '("#b2b2b2" . "#292b2e"))
'(pdf-view-midnight-colors (quote ("#b2b2b2" . "#292b2e")))
'(pos-tip-background-color "#FFFACE") '(pos-tip-background-color "#FFFACE")
'(pos-tip-foreground-color "#272822") '(pos-tip-foreground-color "#272822")
'(vc-annotate-background "#3b3b3b") '(vc-annotate-background "#3b3b3b")
'(vc-annotate-color-map '(vc-annotate-color-map
(quote '((20 . "#dd5542")
((20 . "#dd5542")
(40 . "#CC5542") (40 . "#CC5542")
(60 . "#fb8512") (60 . "#fb8512")
(80 . "#baba36") (80 . "#baba36")
@ -75,11 +70,10 @@
(300 . "#528fd1") (300 . "#528fd1")
(320 . "#5180b3") (320 . "#5180b3")
(340 . "#6380b3") (340 . "#6380b3")
(360 . "#DC8CC3")))) (360 . "#DC8CC3")))
'(vc-annotate-very-old-color "#DC8CC3") '(vc-annotate-very-old-color "#DC8CC3")
'(weechat-color-list '(weechat-color-list
(quote '(unspecified "#272822" "#3C3D37" "#F70057" "#F92672" "#86C30D" "#A6E22E" "#BEB244" "#E6DB74" "#40CAE4" "#66D9EF" "#FB35EA" "#FD5FF0" "#74DBCD" "#A1EFE4" "#F8F8F2" "#F8F8F0")))
(unspecified "#272822" "#3C3D37" "#F70057" "#F92672" "#86C30D" "#A6E22E" "#BEB244" "#E6DB74" "#40CAE4" "#66D9EF" "#FB35EA" "#FD5FF0" "#74DBCD" "#A1EFE4" "#F8F8F2" "#F8F8F0"))))
(custom-set-faces (custom-set-faces
;; custom-set-faces was added by Custom. ;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful. ;; If you edit it by hand, you could mess it up, so be careful.
@ -154,7 +148,7 @@
(setq mouse-wheel-progressive-speed nil) ;Deshabilita la velocidad progresiva del scroll (mientras más scroll haces, mas rápido va) (setq mouse-wheel-progressive-speed nil) ;Deshabilita la velocidad progresiva del scroll (mientras más scroll haces, mas rápido va)
;Neotree con iconitos y con tamaño dinámico y sin número de líneas. ;Neotree con iconitos y con tamaño dinámico y sin número de líneas.
(require 'all-the-icons) (require 'all-the-icons)
(require 'neotree) (require 'neotree)
(setq neo-theme (if (display-graphic-p) 'icons 'all-the-icons)) (setq neo-theme (if (display-graphic-p) 'icons 'all-the-icons))
(setq neo-window-fixed-size nil) (setq neo-window-fixed-size nil)