From 9daec97a593cd6c419badbf08259bdf3653520ab Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 27 Aug 2026 20:53:38 +0200 Subject: Upgrade markdown-mode rust-mode and yaml-mode. Remove PHP mode. --- .emacs | 1 + .emacs.d/lisp/markdown-mode.el | 20 +- .emacs.d/lisp/php-face.el | 207 ----- .emacs.d/lisp/php-mode.el | 1744 -------------------------------------- .emacs.d/lisp/php-project.el | 283 ------- .emacs.d/lisp/php-util-buffer.el | 135 --- .emacs.d/lisp/php.el | 452 ---------- .emacs.d/lisp/rust-playpen.el | 2 +- .emacs.d/lisp/yaml-mode.el | 36 +- .emacs.pure | 1 + 10 files changed, 40 insertions(+), 2841 deletions(-) delete mode 100644 .emacs.d/lisp/php-face.el delete mode 100644 .emacs.d/lisp/php-mode.el delete mode 100644 .emacs.d/lisp/php-project.el delete mode 100644 .emacs.d/lisp/php-util-buffer.el delete mode 100644 .emacs.d/lisp/php.el diff --git a/.emacs b/.emacs index 49e2d9c..b89bcb7 100644 --- a/.emacs +++ b/.emacs @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- ;; Set up the keyboard so the delete key on both the regular keyboard ;; and the keypad delete the character under the cursor and to the right ;; under X, instead of the default, backspace behavior. diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 08ed4bb..18e1e96 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -1255,6 +1255,21 @@ Function is called repeatedly until it returns nil. For details, see (unless (and (eq new-start start) (eq new-end end)) (cons new-start (min new-end (point-max)))))))) +(defvar font-lock-beg) +(defvar font-lock-end) + +(defun markdown-font-lock-extend-region () + "Extend the font-lock region to cover whole blocks. +Used in `font-lock-extend-region-functions'. Inline constructs +such as bold and italic may span several lines within a block, so +fontifying a region that begins or ends in the middle of one +would miss the match entirely." + (let ((res (markdown-syntax-propertize-extend-region font-lock-beg font-lock-end))) + (when res + (setq font-lock-beg (car res) + font-lock-end (cdr res)) + t))) + (defun markdown-font-lock-extend-region-function (start end _) "Used in `jit-lock-after-change-extend-region-functions'. Delegates to `markdown-syntax-propertize-extend-region'. START @@ -4803,7 +4818,8 @@ at the beginning of the block." while pos-prop for lang = (markdown-code-block-lang pos-prop) do (progn (when lang (markdown-gfm-add-used-language lang)) - (goto-char (next-single-property-change (point) prop))))))) + (goto-char (or (next-single-property-change (point) prop) + (point-max)))))))) (defun markdown-insert-foldable-block () "Insert details disclosure element to make content foldable. @@ -10439,6 +10455,8 @@ rows and columns and the column alignment." #'markdown-syntax-propertize-extend-region nil t) (add-hook 'jit-lock-after-change-extend-region-functions #'markdown-font-lock-extend-region-function t t) + (add-hook 'font-lock-extend-region-functions + #'markdown-font-lock-extend-region t t) (setq-local syntax-propertize-function #'markdown-syntax-propertize) (syntax-propertize (point-max)) ;; Propertize before hooks run, etc. ;; Font lock. diff --git a/.emacs.d/lisp/php-face.el b/.emacs.d/lisp/php-face.el deleted file mode 100644 index 5f40257..0000000 --- a/.emacs.d/lisp/php-face.el +++ /dev/null @@ -1,207 +0,0 @@ -;;; php-face.el --- Face definitions for PHP script -*- lexical-binding: t; -*- - -;; Copyright (C) 2019 Friends of Emacs-PHP development - -;; Author: USAMI Kenta -;; Created: 5 May 2019 -;; Version: 1.22.1 -;; Keywords: faces, php -;; Homepage: https://github.com/emacs-php/php-mode -;; Package-Requires: ((emacs "24.3")) -;; 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 . - -;;; Commentary: - -;; Face definitions for PHP script. - -;;; Code: - -;;;###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 - :tag "PHP String") - -(defface php-keyword '((t (:inherit font-lock-keyword-face))) - "PHP Mode face used to highlight keywords." - :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 - :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 - :tag "PHP Function Name") - -(defface php-function-call '((t ())) - "PHP Mode face used to highlight function names in calles." - :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 - :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 - :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 - :tag "PHP Variable Name") - -(defface php-property-name '((t (:inherit php-variable-name))) - "PHP Mode face used to highlight property names." - :group 'php-faces - :tag "PHP Property Name") - -(defface php-variable-sigil '((t ())) - "PHP Mode face used to highlight variable sigils ($)." - :group 'php-faces - :tag "PHP Variable Sigil") - -(defface php-operator '((t ())) - "PHP Mode face used to operators." - :group 'php-faces - :tag "PHP Operator") - -(defface php-assignment-op '((t (:inherit php-operator))) - "PHP Mode face used to assignment operators (=, +=, ...)." - :group 'php-faces - :tag "PHP Object Op") - -(defface php-comparison-op '((t (:inherit php-operator))) - "PHP Mode face used to comparison operators (==, !=, ===, ...)." - :group 'php-faces - :tag "PHP Comparison Op") - -(defface php-logical-op '((t (:inherit php-operator))) - "PHP Mode face used to logical operators (&&, ||, ?:)." - :group 'php-faces - :tag "PHP Logical Op") - -(defface php-arithmetic-op '((t (:inherit php-operator))) - "PHP Mode face used to arithmetic operators (+, -, %, ...)." - :group 'php-faces - :tag "PHP Arithmetic Op") - -(defface php-inc-dec-op '((t (:inherit php-operator))) - "PHP Mode face used to increment and decremt operators (--, ++)." - :group 'php-faces - :tag "PHP Increment/Decrement Op") - -(defface php-string-op '((t (:inherit php-operator))) - "PHP Mode face used to logical operators (.)." - :group 'php-faces - :tag "PHP String Op") - -(defface php-object-op '((t (:inherit php-operator))) - "PHP Mode face used to object operators (->)." - :group 'php-faces - :tag "PHP Object Op") - -(defface php-paamayim-nekudotayim '((t ())) - "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)." - :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 - :tag "PHP Type") - -(defface php-class '((t (:inherit font-lock-type-face))) - "PHP Mode face used to highlight class." - :group 'php-faces - :tag "PHP Class") - -(defface php-constant '((t (:inherit font-lock-constant-face))) - "PHP Mode face used to highlight constants." - :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 - :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 - :tag "PHP Magical Constant") - -(defface php-$this '((t (:inherit php-constant))) - "PHP Mode face used to highlight $this variables." - :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 - :tag "PHP $this Sigil") - -(defface php-errorcontrol-op '((t (:inherit font-lock-type-face))) - "PHP Mode face used to highlight errorcontrol operators (@).." - :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 - :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 - :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 - :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 - :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 - :tag "PHPDoc $this Sigil") - -(defface php-doc-class-name '((t (:inherit php-string))) - "Face used to class names in doc-comment." - :group 'php-faces - :tag "PHPDoc Class Name") - -(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") - -(provide 'php-face) -;;; php-face.el ends here diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el deleted file mode 100644 index faf2ec5..0000000 --- a/.emacs.d/lisp/php-mode.el +++ /dev/null @@ -1,1744 +0,0 @@ -;;; php-mode.el --- Major mode for editing PHP code - -;; Copyright (C) 2018-2019 Friends of Emacs-PHP development -;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad -;; 2008 Aaron S. Hawley -;; 2011, 2012, 2013, 2014, 2015, 2016, 2017 Eric James Michael Ritz - -;; Author: Eric James Michael Ritz -;; Maintainer: USAMI Kenta -;; URL: https://github.com/emacs-php/php-mode -;; Keywords: languages php -;; Version: 1.22.1 -;; Package-Requires: ((emacs "24.3")) -;; License: GPL-3.0-or-later - -(defconst php-mode-version-number "1.22.1" - "PHP Mode version number.") - -;; 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 . - -;;; Commentary: - -;; PHP Mode is a major mode for editing PHP script. It's an extension -;; of CC mode; thus it inherits all C mode's navigation functionality. -;; But it colors according to the PHP syntax and indents according to the -;; PSR-2 coding guidelines. It also includes a couple handy IDE-type -;; features such as documentation search and a source and class browser. - -;; Please read the manual for setting items compatible with CC Mode. -;; https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html - -;; This mode is designed for PHP scripts consisting of a single = 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" - "Display informations useful for debugging PHP Mode." t) - -;; Local variables - -;;;###autoload -(defgroup php-mode nil - "Major mode for editing PHP code." - :tag "PHP Mode" - :prefix "php-mode-" - :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")) - -(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." - :group 'php-mode - :tag "PHP Mode Default Face" - :type 'face) - -(define-obsolete-variable-alias 'php-speedbar-config 'php-mode-speedbar-config "1.20.0") -(defcustom php-mode-speedbar-config t - "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) - (when val - (speedbar-add-supported-extension - "\\.\\(inc\\|php[s345]?\\|phtml\\)")))) - -(defcustom php-mode-speedbar-open nil - "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) - (when val - (speedbar 1)))) - -(define-obsolete-variable-alias 'php-template-compatibility 'php-mode-template-compatibility "1.20.0") -(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) - "Create regexp for the list of extra constant keywords KWDS." - (concat "[^_$]?\\<\\(" - (regexp-opt - (append kwds - (when (boundp 'web-mode-extra-php-constants) web-mode-extra-php-constants))) - "\\)\\>[^_]?")) - -(defun php-mode-extra-constants-set (sym value) - "Apply the list of extra constant keywords `VALUE'. - -This function is called when the custom variable php-extra-constants -is updated. The web-mode-extra-constants list is appended to the list -of constants when set." - ;; remove old keywords - (when (boundp 'php-extra-constants) - (font-lock-remove-keywords - 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 'php-constant)))) - ;; add new keywords - (when value - (font-lock-add-keywords - 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 'php-constant)))) - (set sym value)) - -(define-obsolete-variable-alias 'php-lineup-cascaded-calls 'php-mode-lineup-cascaded-calls "1.20.0") -(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) - -(defcustom php-mode-page-delimiter - (eval-when-compile - (rx symbol-start - (or "namespace" "function" "class" "trait" "interface") - symbol-end)) - "Regexp describing line-beginnings that PHP declaration statements." - :group 'php-mode - :tag "PHP Mode Page Delimiter" - :type 'regexp) - -(define-obsolete-variable-alias 'php-extra-constants 'php-mode-extra-constants "1.20.0") -(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) - -(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'. - -If using function `semantic-mode' `imenu-create-index-function' will be -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 "" - "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 -(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 - ;; 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 - "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 - "Warn once per buffer if you try to indent a buffer without -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 - "Select default coding style to use with php-mode. -This variable can take one of the following symbol values: - -`Default' - use a reasonable default style for PHP. - -`PEAR' - use coding styles preferred for PEAR code and modules. - -`Drupal' - use coding styles preferred for working with Drupal projects. - -`WordPress' - use coding styles preferred for working with WordPress projects. - -`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" php) - (const :tag "PEAR" pear) - (const :tag "Drupal" drupal) - (const :tag "WordPress" wordpress) - (const :tag "Symfony2" symfony2) - (const :tag "PSR-2" psr2)) - :initialize 'custom-initialize-default) - -;; Since this function has a bad influence on the environment of many users, -;; temporarily disable it -(defcustom php-mode-enable-project-coding-style nil - "When set to true override php-mode-coding-style by php-project-coding-style. - -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 - "When set to `T', back up values set by hook and buffer local variables. - -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) - -(defcustom php-mode-enable-project-local-variable t - "When set to `T', apply project local variable to buffer local variable." - :group 'php-mode - :tag "PHP Mode Enable Project Local Variable" - :type 'boolean) - -(defun php-mode-version () - "Display string describing the version of PHP Mode." - (interactive) - (let ((fmt - (eval-when-compile - (let ((id "$Id$")) - (concat "PHP Mode %s" - (if (string= id (concat [?$ ?I ?d ?$])) - "" - (concat " " id))))))) - (funcall - (if (called-interactively-p 'interactive) #'message #'format) - fmt php-mode-version-number))) - -;;;###autoload -(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") - -(defvar php-mode-map - (let ((map (make-sparse-keymap "PHP Mode"))) - ;; Remove menu item for c-mode - (define-key map [menu-bar C] nil) - - ;; (define-key map [menu-bar php complete-function] - ;; '("Complete function name" . php-complete-function)) - ;; (define-key map [menu-bar php browse-manual] - ;; '("Browse manual" . php-browse-manual)) - ;; (define-key map [menu-bar php search-documentation] - ;; '("Search documentation" . php-search-documentation)) - - ;; By default PHP Mode binds C-M-h to c-mark-function, which it - ;; inherits from cc-mode. But there are situations where - ;; c-mark-function fails to properly mark a function. For - ;; example, if we use c-mark-function within a method definition - ;; then the region will expand beyond the method and into the - ;; class definition itself. - ;; - ;; Changing the default to mark-defun provides behavior that users - ;; are more likely to expect. - (define-key map (kbd "C-M-h") 'mark-defun) - - ;; Many packages based on cc-mode provide the 'C-c C-w' binding - ;; to toggle Subword Mode. See the page - ;; - ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html - ;; - ;; for more information about Subword mode. - (define-key map (kbd "C-c C-w") 'subword-mode) - - ;; We inherit c-beginning-of-defun and c-end-of-defun from CC Mode - ;; but we have two replacement functions specifically for PHP. We - ;; remap the commands themselves and not their default - ;; key-bindings so that our PHP-specific versions will work even - ;; if the user has reconfigured their keys, e.g. if they rebind - ;; c-end-of-defun to something other than C-M-e. - (define-key map [remap c-beginning-of-defun] 'php-beginning-of-defun) - (define-key map [remap c-end-of-defun] 'php-end-of-defun) - (define-key map [remap c-set-style] 'php-set-style) - - (define-key map [(control c) (control f)] 'php-search-documentation) - (define-key map [(meta tab)] 'php-complete-function) - (define-key map [(control c) (control m)] 'php-browse-manual) - (define-key map [(control .)] 'php-show-arglist) - (define-key map [(control c) (control r)] 'php-send-region) - ;; Use the Emacs standard indentation binding. This may upset c-mode - ;; which does not follow this at the moment, but I see no better - ;; choice. - (define-key map [tab] 'indent-for-tab-command) - map) - "Keymap for `php-mode'.") - -(c-lang-defconst c-mode-menu - php (append '(["Complete function name" php-complete-function t] - ["Browse manual" php-browse-manual t] - ["Search documentation" php-search-documentation t] - ["----" t]) - (c-lang-const c-mode-menu))) - -(c-lang-defconst c-at-vsemi-p-fn - php 'php-c-at-vsemi-p) - -(c-lang-defconst c-vsemi-status-unknown-p-fn - php 'php-c-vsemi-status-unknown-p) - -(c-lang-defconst c-get-state-before-change-functions - php nil) - -(c-lang-defconst c-before-font-lock-functions - php (c-get-lang-constant 'c-before-font-lock-functions nil t)) - -;; Make php-mode recognize opening tags as preprocessor macro's. -;; -;; This is a workaround, the tags must be recognized as something -;; in order for the syntactic guesses of code below the tag -;; to be correct and as a result not break indentation. -;; -;; Note that submatches or \\| here are not expected by cc-mode. -(c-lang-defconst c-opt-cpp-prefix - php "\\s-*<\\?") - -(c-lang-defconst c-anchored-cpp-prefix - php "\\s-*\\(<\\?(=\\|\\sw+)\\)") - -(c-lang-defconst c-identifier-ops - php '( - (left-assoc "\\" "::" "->") - (prefix "\\" "::"))) - -(c-lang-defconst c-operators - php `((prefix "new" "clone") - ,@(c-lang-const c-identifier-ops) - (postfix "->") - (postfix "++" "--" "[" "]" "(" ")") - (right-assoc "**") - (prefix "++" "--" "+" "-" "~" "(" ")" "@") - (prefix "instanceof") - (prefix "!") - (left-assoc "*" "/" "%") - (left-assoc "+" "-" ".") - (left-assoc "<<" ">>") - (left-assoc "<" ">" "<=" ">=") - (left-assoc "==" "!=" "===" "!==" "<>" "<=>") - (left-assoc "&") - (left-assoc "^") - (left-assoc "|") - (left-assoc "&&") - (left-assoc "||") - (right-assoc "??") - (left-assoc "?:") - (right-assoc-sequence "?" ":") - (right-assoc ,@(c-lang-const c-assignment-operators)) - (left-assoc "and") - (left-assoc "xor") - (left-assoc "or") - (left-assoc ","))) - -;; Allow '\' when scanning from open brace back to defining -;; construct like class -(c-lang-defconst c-block-prefix-disallowed-chars - php (cl-set-difference (c-lang-const c-block-prefix-disallowed-chars) - '(?\\))) - -;; Allow $ so variables are recognized in cc-mode and remove @. This -;; makes cc-mode highlight variables and their type hints in arglists. -(c-lang-defconst c-symbol-start - php (concat "[" c-alpha "_$]")) - -;; All string literals can possibly span multiple lines -(c-lang-defconst c-multiline-string-start-char - php t) - -(c-lang-defconst c-assignment-operators - php '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=" ".=" "??=")) - -(c-lang-defconst beginning-of-defun-function - php 'php-beginning-of-defun) - -(c-lang-defconst end-of-defun-function - php 'php-end-of-defun) - -(c-lang-defconst c-primitive-type-kwds - php '("int" "integer" "bool" "boolean" "float" "double" "real" - "string" "object" "void")) - -(c-lang-defconst c-class-decl-kwds - "Keywords introducing declarations where the following block (if any) -contains another declaration level that should be considered a class." - php '("class" "trait" "interface")) - -(c-lang-defconst c-brace-list-decl-kwds - "Keywords introducing declarations where the following block (if -any) is a brace list. - -PHP does not have an \"enum\"-like keyword." - php nil) - -(c-lang-defconst c-typeless-decl-kwds - php (append (c-lang-const c-class-decl-kwds) '("function"))) - -(c-lang-defconst c-modifier-kwds - php '("abstract" "const" "final" "static")) - -(c-lang-defconst c-protection-kwds - "Access protection label keywords in classes." - php '("private" "protected" "public")) - -(c-lang-defconst c-postfix-decl-spec-kwds - php '("implements" "extends")) - -(c-lang-defconst c-type-list-kwds - 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 '("catch" "declare" "elseif" "for" "foreach" "if" "switch" "while")) - -(c-lang-defconst 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")) - -(c-lang-defconst c-lambda-kwds - 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 - '( - "__halt_compiler" - "and" - "array" - "as" - "break" - "catch" - "clone" - "default" - "empty" - "enddeclare" - "endfor" - "endforeach" - "endif" - "endswitch" - "endwhile" - "eval" - "fn" ;; NOT c-lambda-kwds - "global" - "isset" - "list" - "or" - "parent" - "static" - "unset" - "var" - "xor" - "yield" - "yield from" - - ;; Below keywords are technically not reserved keywords, but - ;; threated no differently by php-mode from actual reserved - ;; keywords - ;; - ;;; declare directives: - "encoding" - "ticks" - "strict_types" - - ;;; self for static references: - "self" - )) - -;; PHP does not have <> templates/generics -(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) - -(c-lang-defconst c-nonlabel-token-key - "Regexp matching things that can't occur in generic colon labels. - -This overrides cc-mode `c-nonlabel-token-key' to support switching on -double quoted strings and true/false/null. - -Note: this regexp is also applied to goto-labels, a future improvement -might be to handle switch and goto labels differently." - php (concat - ;; All keywords except `c-label-kwds' and `c-constant-kwds'. - (c-make-keywords-re t - (cl-set-difference (c-lang-const c-keywords) - (append (c-lang-const c-label-kwds) - (c-lang-const c-constant-kwds)) - :test 'string-equal)))) - -(c-lang-defconst c-basic-matchers-before - 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) - -(defconst php-mode--re-return-typed-closure - (eval-when-compile - (rx symbol-start "function" symbol-end - (* (syntax whitespace)) - "(" (* (not (any "("))) ")" - (* (syntax whitespace)) - (? symbol-start "use" symbol-end - (* (syntax whitespace)) - "(" (* (not (any "("))) ")" - (* (syntax whitespace))) - ":" (+ (not (any "{}"))) - (group "{")))) - -(defun php-c-lineup-arglist (langelem) - "Line up the current argument line under the first argument using `c-lineup-arglist' LANGELEM." - (let (in-return-typed-closure) - (when (and (consp langelem) - (eq 'arglist-cont-nonempty (car langelem))) - (save-excursion - (save-match-data - (when (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) - (goto-char (match-beginning 1)) - (when (not (php-in-string-or-comment-p)) - (setq in-return-typed-closure t)))))) - (unless in-return-typed-closure - (c-lineup-arglist langelem)))) - -(defun php-lineup-cascaded-calls (langelem) - "Line up chained methods using `c-lineup-cascaded-calls', -but only if the setting is enabled" - (when php-mode-lineup-cascaded-calls - (c-lineup-cascaded-calls langelem))) - -(c-add-style - "php" - `((c-basic-offset . 4) - (c-offsets-alist . ((arglist-close . php-lineup-arglist-close) - (arglist-cont . (first php-lineup-cascaded-calls 0)) - (arglist-cont-nonempty . (first php-lineup-cascaded-calls php-c-lineup-arglist)) - (arglist-intro . php-lineup-arglist-intro) - (case-label . +) - (class-open . 0) - (comment-intro . 0) - (inexpr-class . 0) - (inlambda . 0) - (inline-open . 0) - (namespace-open . 0) - (lambda-intro-cont . +) - (label . +) - (statement-cont . (first php-lineup-cascaded-calls php-lineup-string-cont +)) - (substatement-open . 0) - (topmost-intro-cont . (first php-lineup-cascaded-calls +)))) - (indent-tabs-mode . nil) - (tab-width . ,(default-value 'tab-width)) - (fill-column . ,(default-value 'fill-column)) - (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace)) - (php-mode-lineup-cascaded-calls . t) - (php-style-delete-trailing-whitespace . nil))) - -(defun php-enable-default-coding-style () - "Set PHP Mode to use reasonable default formatting." - (interactive) - (php-set-style "php")) - -(c-add-style - "pear" - '("php" - (c-basic-offset . 4) - (c-offsets-alist . ((case-label . 0))) - (tab-width . 4))) - -(defun php-enable-pear-coding-style () - "Set up php-mode to use the coding styles preferred for PEAR code and modules." - (interactive) - (php-set-style "pear")) - -(c-add-style - "drupal" - '("php" - (c-basic-offset . 2) - (tab-width . 2) - (fill-column . 78) - (show-trailing-whitespace . t) - (php-mode-lineup-cascaded-calls . nil) - (php-style-delete-trailing-whitespace . t))) - -(defun php-enable-drupal-coding-style () - "Make php-mode use coding styles that are preferable for working with Drupal." - (interactive) - (php-set-style "drupal")) - -(c-add-style - "wordpress" - '("php" - (c-basic-offset . 4) - (c-indent-comments-syntactically-p t) - (indent-tabs-mode . t) - (tab-width . 4) - (fill-column . 78))) - -(defun php-enable-wordpress-coding-style () - "Make php-mode use coding styles that are preferable for working with Wordpress." - (interactive) - (php-set-style "wordpress")) - -(c-add-style - "symfony2" - '("php" - (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon))) - (c-indent-comments-syntactically-p . t) - (php-mode-lineup-cascaded-calls . nil) - (fill-column . 78))) - -(defun php-enable-symfony2-coding-style () - "Make php-mode use coding styles that are preferable for working with Symfony2." - (interactive) - (php-set-style "symfony2")) - -(c-add-style - "psr2" ; PSR-2 / PSR-12 - '("php" - (c-offsets-alist . ((statement-cont . +))) - (c-indent-comments-syntactically-p . t) - (fill-column . 78) - (show-trailing-whitespace . t) - (php-mode-lineup-cascaded-calls . nil) - (php-style-delete-trailing-whitespace . t))) - -(defun php-enable-psr2-coding-style () - "Make php-mode comply to the PSR-2 coding style." - (interactive) - (php-set-style "psr2")) - -(defun php-beginning-of-defun (&optional arg) - "Move to the beginning of the ARGth PHP function from point. -Implements PHP version of `beginning-of-defun-function'." - (interactive "p") - (let (found-p (arg (or arg 1))) - (while (> arg 0) - (setq found-p (re-search-backward php-beginning-of-defun-regexp - nil 'noerror)) - (setq arg (1- arg))) - (while (< arg 0) - (end-of-line 1) - (let ((opoint (point))) - (beginning-of-defun 1) - (forward-list 2) - (forward-line 1) - (if (eq opoint (point)) - (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. -Implements PHP version of `end-of-defun-function' - -See `php-beginning-of-defun'." - (interactive "p") - (php-beginning-of-defun (- (or arg 1)))) - - -(defvar php-warned-bad-indent nil) - -;; Do it but tell it is not good if html tags in buffer. -(defun php-check-html-for-indentation () - (let ((html-tag-re "^\\s-*") - (here (point))) - (goto-char (line-beginning-position)) - (if (or (when (boundp 'mumamo-multi-major-mode) mumamo-multi-major-mode) - ;; Fix-me: no idea how to check for mmm or multi-mode - (save-match-data - (not (or (re-search-forward html-tag-re (line-end-position) t) - (re-search-backward html-tag-re (line-beginning-position) t))))) - (progn - (goto-char here) - t) - (goto-char here) - (setq php-warned-bad-indent t) - (let* ((known-multi-libs '(("mumamo" mumamo (lambda () (nxhtml-mumamo))) - ("mmm-mode" mmm-mode (lambda () (mmm-mode 1))) - ("multi-mode" multi-mode (lambda () (multi-mode 1))) - ("web-mode" web-mode (lambda () (web-mode))))) - (known-names (mapcar (lambda (lib) (car lib)) known-multi-libs)) - (available-multi-libs (delq nil - (mapcar - (lambda (lib) - (when (locate-library (car lib)) lib)) - known-multi-libs))) - (available-names (mapcar (lambda (lib) (car lib)) available-multi-libs)) - (base-msg - (concat - "Indentation fails badly with mixed HTML/PHP in the HTML part in -plain `php-mode'. To get indentation to work you must use an -Emacs library that supports 'multiple major modes' in a buffer. -Parts of the buffer will then be in `php-mode' and parts in for -example `html-mode'. Known such libraries are:\n\t" - (mapconcat 'identity known-names ", ") - "\n" - (if available-multi-libs - (concat - "You have these available in your `load-path':\n\t" - (mapconcat 'identity available-names ", ") - "\n\n" - "Do you want to turn any of those on? ") - "You do not have any of those in your `load-path'."))) - (is-using-multi - (catch 'is-using - (dolist (lib available-multi-libs) - (when (and (boundp (cadr lib)) - (symbol-value (cadr lib))) - (throw 'is-using t)))))) - (unless is-using-multi - (if available-multi-libs - (if (not (y-or-n-p base-msg)) - (message "Did not do indentation, but you can try again now if you want") - (let* ((name - (if (= 1 (length available-multi-libs)) - (car available-names) - ;; Minibuffer window is more than one line, fix that first: - (message "") - (completing-read "Choose multiple major mode support library: " - available-names nil t - (car available-names) - '(available-names . 1) - ))) - (mode (when name - (cl-caddr (assoc name available-multi-libs))))) - (when mode - ;; Minibuffer window is more than one line, fix that first: - (message "") - (load name) - (funcall mode)))) - (lwarn 'php-indent :warning base-msg))) - 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)) - doit) - (move-beginning-of-line nil) - ;; Don't indent heredoc end mark - (save-match-data - (unless (and (looking-at "[a-zA-Z0-9_]+;\n") - (php-in-string-p)) - (setq doit t))) - (goto-char here) - (when doit - (funcall 'c-indent-line))))) - -(defun php-c-at-vsemi-p (&optional pos) - "Return t on html lines (including php region border), otherwise nil. -POS is a position on the line in question. - -This is was done due to the problem reported here: - - URL `https://answers.launchpad.net/nxhtml/+question/43320'" - (if (not php-template-compatibility) - nil - (setq pos (or pos (point))) - (let ((here (point)) - ret) - (save-match-data - (goto-char pos) - (beginning-of-line) - (setq ret (looking-at - (rx - (or (seq - bol - (0+ space) - "<" - (in "a-z\\?")) - (seq - (0+ not-newline) - (in "a-z\\?") - ">" - (0+ space) - eol)))))) - (goto-char here) - ret))) - -(defun php-c-vsemi-status-unknown-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. -e.g. -$str = 'some' - . 'string'; -this ^ lineup" - (save-excursion - (goto-char (cdr langelem)) - (let (ret finish) - (while (and (not finish) (re-search-forward "[=.]" (line-end-position) t)) - (unless (php-in-string-or-comment-p) - (setq finish t - ret (vector (1- (current-column)))))) - ret))) - -(defun php-lineup-arglist-intro (langelem) - (save-excursion - (goto-char (cdr langelem)) - (vector (+ (current-column) c-basic-offset)))) - -(defun php-lineup-arglist-close (langelem) - (save-excursion - (goto-char (cdr langelem)) - (vector (current-column)))) - -(defun php-lineup-arglist (_langelem) - (save-excursion - (beginning-of-line) - (if (looking-at-p "\\s-*->") '+ 0))) - -(defun php-lineup-hanging-semicolon (_langelem) - (save-excursion - (beginning-of-line) - (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) - -(eval-and-compile - (defconst php-heredoc-start-re - "<<<\\(?:\\_<.+?\\_>\\|'\\_<.+?\\_>'\\|\"\\_<.+?\\_>\"\\)$" - "Regular expression for the start of a PHP heredoc.")) - -(defun php-heredoc-end-re (heredoc-start) - "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 "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W")) - -(defun php-syntax-propertize-function (start end) - "Apply propertize rules from START to END." - (goto-char start) - (while (and (< (point) end) - (re-search-forward php-heredoc-start-re end t)) - (php-heredoc-syntax)) - (goto-char start) - (while (re-search-forward "['\"]" end t) - (when (php-in-comment-p) - (c-put-char-property (match-beginning 0) - 'syntax-table (string-to-syntax "_"))))) - -(defun php-heredoc-syntax () - "Mark the boundaries of searched heredoc." - (goto-char (match-beginning 0)) - (c-put-char-property (point) 'syntax-table (string-to-syntax "|")) - (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) - (goto-char (match-end 1)) - ;; Did not find the delimiter so go to the end of the buffer. - (goto-char (point-max))) - (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) - -(defvar-local php-mode--propertize-extend-region-current nil - "Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION") - -(defun php-syntax-propertize-extend-region (start end) - "Extend the propertize region if START or END falls inside a PHP heredoc." - (let ((pair (cons start end))) - (when (not (member pair php-mode--propertize-extend-region-current)) - ;; re-search functions may trigger - ;; syntax-propertize-extend-region-functions to be called again, which in - ;; turn call this to be called again. - (push pair php-mode--propertize-extend-region-current) - (unwind-protect - (let ((new-start) - (new-end)) - (goto-char start) - (when (re-search-backward php-heredoc-start-re nil t) - (let ((maybe (point))) - (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) - (> (point) start)) - (setq new-start maybe)))) - (goto-char end) - (when (re-search-backward php-heredoc-start-re nil t) - (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) - (when (> (point) end) - (setq new-end (point))) - (setq new-end (point-max)))) - (when (or new-start new-end) - (cons (or new-start start) (or new-end end)))) - ;; Cleanup - (setq php-mode--propertize-extend-region-current - (delete pair php-mode--propertize-extend-region-current)))))) - -(easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" - (cons "PHP" (c-lang-const c-mode-menu php))) - -(defun php-mode-get-style-alist () - "Return an alist consisting of `php' style and styles that inherit it." - (cl-loop for l in c-style-alist - if (or (string= (car l) "php") - (equal (cadr l) "php")) - collect l)) - -(defvar php-mode-set-style-history nil) -(defvar-local php-mode--delayed-set-style nil) -(defvar-local php-style-delete-trailing-whitespace nil) - -(defun php-set-style (stylename &optional dont-override) - "Set the current `php-mode' buffer to use the style STYLENAME. -STYLENAME is one of the names selectable in `php-mode-coding-style'. - -Borrow the `interactive-form' from `c-set-style' and use the original -`c-set-style' function to set all declared stylevars. -For compatibility with `c-set-style' pass DONT-OVERRIDE to it. - -After setting the stylevars run hooks according to STYLENAME - - \"pear\" `php-mode-pear-hook' - \"drupal\" `php-mode-drupal-hook' - \"wordpress\" `php-mode-wordpress-hook' - \"symfony2\" `php-mode-symfony2-hook' - \"psr2\" `php-mode-psr2-hook'" - (interactive - (list (let ((completion-ignore-case t) - (prompt (format "Which %s indentation style? " - mode-name))) - (completing-read prompt - (php-mode-get-style-alist) - nil t nil - 'php-mode-set-style-history - c-indentation-style)))) - (php-mode--disable-delay-set-style) - - ;; Back up manually set variables - (let* (value - (backup-vars - (and php-mode-enable-backup-style-variables - (cl-loop for name in c-style-variables - do (setq value (symbol-value name)) - if (and value (not (eq 'set-from-style value))) - collect (cons name value))))) - (c-set-style stylename dont-override) - ;; Restore variables - (cl-loop for (name . value) in backup-vars - do (set (make-local-variable name) value))) - - (if (eq (symbol-value 'php-style-delete-trailing-whitespace) t) - (add-hook 'before-save-hook 'delete-trailing-whitespace nil t) - (remove-hook 'before-save-hook 'delete-trailing-whitespace t)) - (cond ((equal stylename "pear") (run-hooks 'php-mode-pear-hook)) - ((equal stylename "drupal") (run-hooks 'php-mode-drupal-hook)) - ((equal stylename "wordpress") (run-hooks 'php-mode-wordpress-hook)) - ((equal stylename "symfony2") (run-hooks 'php-mode-symfony2-hook)) - ((equal stylename "psr2") (run-hooks 'php-mode-psr2-hook)))) - -(defun php-mode--disable-delay-set-style (&rest args) - "Disable php-mode-set-style-delay on after hook. `ARGS' be ignore." - (setq php-mode--delayed-set-style nil) - (when (fboundp 'advice-remove) - (advice-remove #'php-mode--disable-delay-set-style #'c-set-style))) - -(defun php-mode-set-style-delay () - "Set the current `php-mode' buffer to use the style by custom or local variables." - (when php-mode--delayed-set-style - (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) - php-mode-coding-style))) - (prog1 (when coding-style - (php-set-style (symbol-name coding-style))) - (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) - -(defun php-mode-set-local-variable-delay () - "Set local variable from php-project." - (php-project-apply-local-variables) - (remove-hook 'hack-local-variables-hook #'php-mode-set-local-variable-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 - (setq-local c-mode-hook nil) - (setq-local java-mode-hook nil)) - (c-initialize-cc-mode t) - (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 page-delimiter php-mode-page-delimiter) - - (setq-local font-lock-string-face 'php-string) - (setq-local font-lock-keyword-face 'php-keyword) - (setq-local font-lock-builtin-face 'php-builtin) - (setq-local c-preprocessor-face-name 'php-php-tag) - (setq-local font-lock-function-name-face 'php-function-name) - (setq-local font-lock-variable-name-face 'php-variable-name) - (setq-local font-lock-constant-face 'php-constant) - - (setq-local syntax-propertize-function #'php-syntax-propertize-function) - (add-hook 'syntax-propertize-extend-region-functions - #'php-syntax-propertize-extend-region t t) - - (setq imenu-generic-expression php-imenu-generic-expression) - - ;; PHP vars are case-sensitive - (setq case-fold-search t) - - (when php-mode-enable-project-local-variable - (add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t)) - - ;; When php-mode-enable-project-coding-style is set, it is delayed by hook. - ;; Since it depends on the timing at which the file local variable is set. - ;; File local variables are set after initialization of major mode except `run-hook' is complete. - (if php-mode-enable-project-coding-style - (progn - (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t 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)))) - (let ((php-mode-enable-backup-style-variables nil)) - (php-set-style (symbol-name php-mode-coding-style)))) - - (when (or php-mode-force-pear - (and (stringp buffer-file-name) - (string-match "PEAR\\|pear" buffer-file-name) - (string-match "\\.php\\'" buffer-file-name))) - (php-set-style "pear")) - - (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-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. - ;; Because of our remapping we may not actually need to keep the - ;; following two local variables, but we keep them for now until we - ;; are completely sure their removal will not break any current - ;; behavior or backwards compatibility. - (setq-local beginning-of-defun-function 'php-beginning-of-defun) - (setq-local end-of-defun-function 'php-end-of-defun) - - (setq-local open-paren-in-column-0-is-defun-start nil) - (setq-local defun-prompt-regexp - "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") - (setq-local add-log-current-defun-header-regexp - php-beginning-of-defun-regexp) - - (when (>= emacs-major-version 25) - (with-silent-modifications - (save-excursion - (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)) - -(defvar-mode-local php-mode imenu-create-index-function - (if php-do-not-use-semantic-imenu - #'imenu-default-create-index-function - (require 'semantic/imenu) - #'semantic-create-imenu-index) - "Imenu index function for PHP.") - - -;; 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 () - "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-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 () - "Show function arguments at cursor position." - (interactive) - (let* ((tagname (php-get-pattern)) - (buf (find-tag-noselect tagname nil nil)) - arglist) - (with-current-buffer buf - (save-excursion - (goto-char (point-min)) - (when (re-search-forward - (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) - nil t) - (setq arglist (buffer-substring-no-properties - (match-beginning 1) (match-end 1)))))) - (if arglist - (message "Arglist for %s: %s" tagname arglist) - (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 -(defconst php-phpdoc-type-keywords - (list "string" "integer" "int" "boolean" "bool" "float" - "double" "object" "mixed" "array" "resource" - "void" "null" "false" "true" "self" "static" - "callable" "iterable" "number")) - -(defconst php-phpdoc-type-tags - (list "package" "param" "property" "property-read" "property-write" - "return" "throws" "var")) - -(defconst php-phpdoc-font-lock-doc-comments - `(("{@[-[:alpha:]]+\\s-*\\([^}]*\\)}" ; "{@foo ...}" markup. - (0 'php-doc-annotation-tag prepend nil) - (1 'php-string prepend nil)) - (,(rx (group "$") (group (in "A-Za-z_") (* (in "0-9A-Za-z_")))) - (1 'php-doc-variable-sigil prepend nil) - (2 'php-variable-name prepend nil)) - ("\\(\\$\\)\\(this\\)\\>" (1 'php-doc-$this-sigil prepend nil) (2 'php-doc-$this prepend nil)) - (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" - "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") - 1 'php-string prepend nil) - (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\(" - (regexp-opt php-phpdoc-type-keywords 'words) - "\\)") - 1 font-lock-type-face prepend nil) - ("https?://[^\n\t ]+" - 0 'link prepend nil) - ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup. - 1 'php-doc-annotation-tag prepend nil))) - -(defvar php-phpdoc-font-lock-keywords - `((,(lambda (limit) - (c-font-lock-doc-comments "/\\*\\*" limit - php-phpdoc-font-lock-doc-comments))))) - -(defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php) - "Basic highlighting for PHP Mode.") - -(defconst php-font-lock-keywords-2 (c-lang-const c-matchers-2 php) - "Medium level highlighting for PHP Mode.") - -(defconst php-font-lock-keywords-3 - (append - php-phpdoc-font-lock-keywords - ;; php-mode patterns *before* cc-mode: - ;; only add patterns here if you want to prevent cc-mode from applying - ;; a different face. - `( - ;; 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)) - - ;; Logical operator (!) - ("\\(![^=]\\)" 1 'php-logical-op) - - ;; Highlight special variables - ("\\(\\$\\)\\(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 - ("\\" - "" ;; obsolete ASP tag - ;; Obsoleted tags were deleted in PHP 7. - ;; @see http://php.net/manual/language.basic-syntax.phptags.php - )) - 0 'php-php-tag)) - - ;; cc-mode patterns - (c-lang-const c-matchers-3 php) - - ;; php-mode patterns *after* cc-mode: - ;; most patterns should go here, faces will only be applied if not - ;; already fontified by another pattern. Note that using OVERRIDE - ;; is usually overkill. - `( - ("\\<\\(@\\)" 1 'php-errorcontrol-op) - ;; Highlight function calls - ("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call) - ;; Highlight all upper-cased symbols as constant - ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) - - ;; Highlight all statically accessed class names as constant, - ;; another valid option would be using type-face, but using - ;; constant-face because this is how it works in c++-mode. - ("\\(\\sw+\\)\\(::\\)" (1 'php-constant) (2 'php-paamayim-nekudotayim)) - - ;; Highlight class name after "use .. as" - ("\\]+?\\([\-+./%]?=\\)[^=]+?\\)" 2 'php-assignment-op) - - ;; Comparison operators (==, ===, >=, ...) - ("\\([!=]=\\{1,2\\}[>]?\\|[<>]=?\\)" 1 'php-comparison-op) - - ;; Arithmetic operators (+, -, *, **, /, %) - ("\\(?:[A-Za-z0-9[:blank:]]\\)\\([\-+*/%]\\*?\\)\\(?:[A-Za-z0-9[:blank:]]\\)" 1 'php-arithmetic-op) - - ;; Increment and Decrement operators (++, --) - ("\\(\-\-\\|\+\+\\)\$\\w+" 1 'php-inc-dec-op) ;; pre inc/dec - ("\$\\w+\\(\-\-\\|\+\+\\)" 1 'php-inc-dec-op) ;; post inc/dec - - ;; Logical operators (and, or, &&, ...) - ;; Not operator (!) is defined in "before cc-mode" section above. - ("\\(&&\\|||\\)" 1 'php-logical-op))) - "Detailed highlighting for PHP Mode.") - -(defvar php-font-lock-keywords php-font-lock-keywords-3 - "Default expressions to highlight in PHP Mode.") - -(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) - "Send the region between `START' and `END' to PHP for execution. -The output will appear in the buffer *PHP*." - (interactive "r") - (let ((php-buffer (get-buffer-create "*PHP*")) - (code (buffer-substring start end))) - ;; Calling 'php -r' will fail if we send it code that starts with - ;; '\\|::") - (no-front-space "->\\|::")) - (when (and (eq major-mode 'php-mode) - (or (looking-at-p (concat " \\(" no-behind-space "\\)")) - (save-excursion - (forward-char -2) - (looking-at-p no-front-space)))) - (delete-char 1)))) - -(ad-activate 'fixup-whitespace) - -;;;###autoload -(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 deleted file mode 100644 index 18115cc..0000000 --- a/.emacs.d/lisp/php-project.el +++ /dev/null @@ -1,283 +0,0 @@ -;;; php-project.el --- Project support for PHP application -*- lexical-binding: t; -*- - -;; Copyright (C) 2018-2019 Friends of Emacs-PHP development - -;; Author: USAMI Kenta -;; Keywords: tools, files -;; URL: https://github.com/emacs-php/php-mode -;; Version: 1.22.1 -;; Package-Requires: ((emacs "24.3")) -;; 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 . - -;;; Commentary: - -;; Define project specific functions and variables for PHP application. -;; -;; ## API -;; -;; ### `php-project-get-root-dir()' -;; -;; Return root directory of current buffer file. The root directory is -;; determined by several marker file or directory. -;; -;; ### `php-project-get-bootstrap-scripts()' -;; -;; Return list of path to bootstrap script file. -;; -;; ### `php-project-get-php-executable()' -;; -;; Return path to PHP executable file with the project settings overriding. -;; -;; ### `php-project-get-phan-executable()' -;; -;; Return path to Phan executable file with the project settings overriding. -;; Phan is a static analyzer and LSP server implementation for PHP. -;; See https://github.com/phan/phan -;; -;; ## `.dir-locals.el' support -;; -;; - `php-project-coding-style' -;; - Symbol value of the coding style. (ex. `pear', `psr2') -;; - `php-project-root' -;; - Symbol of marker file of project root. (ex. `git', `composer') -;; - Full path to project root directory. (ex. "/path/to/your-project") -;; - `php-project-bootstrap-scripts' -;; - List of path to bootstrap file of project. -;; (ex. (((root . "vendor/autoload.php") (root . "inc/bootstrap.php"))) -;; - `php-project-php-executable' -;; - Path to project specific PHP executable file. -;; - If you want to use a file different from the system wide `php' command. -;; - `php-project-phan-executable' -;; - Path to project specific Phan executable file. -;; - When not specified explicitly, it is automatically searched from -;; Composer's dependency of the project and `exec-path'. -;; - -;;; Code: -(require 'cl-lib) - -;; Constants -(defconst php-project-composer-autoloader "vendor/autoload.php") - -;; Custom variables -(defgroup php-project nil - "Major mode for editing PHP code." - :tag "PHP Project" - :prefix "php-project-" - :group 'php) - -(defcustom php-project-auto-detect-etags-file nil - "If `T', automatically detect etags file when file is opened." - :tag "PHP Project Auto Detect Etags File" - :group 'php-project - :type 'boolean) - -;; Variables -(defvar php-project-available-root-files - '((projectile ".projectile") - (composer "composer.json" "composer.lock") - (git ".git") - (mercurial ".hg") - (subversion ".svn") - ;; NOTICE: This method does not detect the top level of .editorconfig - ;; However, we can integrate it by adding the editorconfig.el's API. - ;;(editorconfig . ".editorconfig") - )) - -;; Buffer local variables - -;;;###autoload -(progn - (defvar-local php-project-root 'auto - "Method of searching for the top level directory. - -`auto' (default) - Try to search file in order of `php-project-available-root-files'. - -SYMBOL - Key of `php-project-available-root-files'. - -STRING - A file/directory name of top level marker. - 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)))) - - (defvar-local php-project-etags-file nil) - (put 'php-project-etags-file 'safe-local-variable - #'(lambda (v) (or (functionp v) - (eq v t) - (php-project--eval-bootstrap-scripts v)))) - - (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) - - (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)))) - - (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) - - (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) - - (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.") - (put 'php-project-repl 'safe-local-variable - #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v)))) - - (defvar-local php-project-unit-test nil - "Function name or path to unit test script.") - (put 'php-project-unit-test 'safe-local-variable - #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v)))) - - (defvar-local php-project-deploy nil - "Function name or path to deploy script.") - (put 'php-project-deploy 'safe-local-variable - #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v)))) - - (defvar-local php-project-build nil - "Function name or path to build script.") - (put 'php-project-build 'safe-local-variable - #'(lambda (v) (or (functionp v) - (php-project--eval-bootstrap-scripts v)))) - - (defvar-local php-project-server-start nil - "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))))) - -;; 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." - (cond - ((stringp val) (and (file-exists-p val) val)) - ((eq 'composer val) - (let ((path (expand-file-name php-project-composer-autoloader (php-project-get-root-dir)))) - (and (file-exists-p path) path))) - ((and (consp val) (eq 'root (car val)) (stringp (cdr val))) - (let ((path (expand-file-name (cdr val) (php-project-get-root-dir)))) - (and (file-exists-p path) path))) - ((null val) nil) - ((listp val) - (cl-loop for v in val collect (php-project--eval-bootstrap-scripts v))) - (t nil))) - -(defun php-project-get-php-executable () - "Return path to PHP executable file." - (cond - ((and (stringp php-project-php-executable) - (file-executable-p php-project-php-executable)) - php-project-php-executable) - ((boundp 'php-executable) php-executable) - (t (executable-find "php")))) - -(defun php-project-get-phan-executable () - "Return path to phan executable file." - (or (car-safe (php-project--eval-bootstrap-scripts - (list php-project-phan-executable - (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"))))) - -(defun php-project-apply-local-variables () - "Apply php-project variables to local variables." - (when (null tags-file-name) - (when (or (and php-project-auto-detect-etags-file - (null php-project-etags-file)) - (eq php-project-etags-file t)) - (let ((tags-file (expand-file-name "TAGS" (php-project-get-root-dir)))) - (when (file-exists-p tags-file) - (setq-local php-project-etags-file tags-file)))) - (when php-project-etags-file - (setq-local tags-file-name (php-project--eval-bootstrap-scripts php-project-etags-file))))) -;;;###autoload -(defun php-project-get-bootstrap-scripts () - "Return list of bootstrap script." - (let ((scripts (php-project--eval-bootstrap-scripts php-project-bootstrap-scripts))) - (if (stringp scripts) (list scripts) scripts))) - -;;;###autoload -(defun php-project-get-root-dir () - "Return path to current PHP project." - (if (and (stringp php-project-root) (file-directory-p php-project-root)) - php-project-root - (let ((detect-method - (cond - ((stringp php-project-root) (list php-project-root)) - ((eq php-project-root 'auto) - (cl-loop for m in php-project-available-root-files - append (cdr m))) - (t (cdr-safe (assq php-project-root php-project-available-root-files)))))) - (cl-loop for m in detect-method - thereis (locate-dominating-file default-directory m))))) - -(provide 'php-project) -;;; php-project.el ends here diff --git a/.emacs.d/lisp/php-util-buffer.el b/.emacs.d/lisp/php-util-buffer.el deleted file mode 100644 index 70836a0..0000000 --- a/.emacs.d/lisp/php-util-buffer.el +++ /dev/null @@ -1,135 +0,0 @@ -;;; php-util-buffer.el --- Utility function for buffer manipulation -*- lexical-binding: t; -*- - -;; Copyright (C) 2018-2019 Friends of Emacs-PHP development -;; Copyright 2013 The go-mode Authors. All rights reserved. - -;; Author: Dominik Honnef -;; Maintainer: USAMI Kenta -;; URL: https://github.com/emacs-php/php-mode -;; Keywords: lisp - -;; 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 . - -;;; Commentary: - -;; Functions for patching buffer. - -;;; Original License: - -;; Copyright (c) 2014 The go-mode Authors. All rights reserved. - -;; Redistribution and use in source and binary forms, with or without -;; modification, are permitted provided that the following conditions are -;; met: - -;; * Redistributions of source code must retain the above copyright -;; notice, this list of conditions and the following disclaimer. -;; * Redistributions in binary form must reproduce the above -;; copyright notice, this list of conditions and the following disclaimer -;; in the documentation and/or other materials provided with the -;; distribution. -;; * Neither the name of the copyright holder nor the names of its -;; contributors may be used to endorse or promote products derived from -;; this software without specific prior written permission. - -;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -;;; Code: - -;; gofmt apply-rcs-patch Function -;; These functions are copied by go-mode(gofmt). -(defun php-util-buffer--delete-whole-line (&optional arg) - "Delete the current line without putting it in the `kill-ring'. -Derived from function `kill-whole-line'. ARG is defined as for that -function." - (setq arg (or arg 1)) - (if (and (> arg 0) - (eobp) - (save-excursion (forward-visible-line 0) (eobp))) - (signal 'end-of-buffer nil)) - (if (and (< arg 0) - (bobp) - (save-excursion (end-of-visible-line) (bobp))) - (signal 'beginning-of-buffer nil)) - (cond ((zerop arg) - (delete-region (progn (forward-visible-line 0) (point)) - (progn (end-of-visible-line) (point)))) - ((< arg 0) - (delete-region (progn (end-of-visible-line) (point)) - (progn (forward-visible-line (1+ arg)) - (unless (bobp) - (backward-char)) - (point)))) - (t - (delete-region (progn (forward-visible-line 0) (point)) - (progn (forward-visible-line arg) (point)))))) - -(defun php-util-buffer-apply-rcs-patch (target-buffer patch-buffer) - "Apply an RCS-formatted diff from `PATCH-BUFFER' to the `TARGET-BUFFER'." - (let ( - ;; Relative offset between buffer line numbers and line numbers - ;; in patch. - ;; - ;; Line numbers in the patch are based on the source file, so - ;; we have to keep an offset when making changes to the - ;; buffer. - ;; - ;; Appending lines decrements the offset (possibly making it - ;; negative), deleting lines increments it. This order - ;; simplifies the forward-line invocations. - (line-offset 0) - (column (current-column))) - (save-excursion - (with-current-buffer patch-buffer - (goto-char (point-min)) - (while (not (eobp)) - (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)") - (error "Invalid rcs patch or internal error in php-util-buffer-apply-rcs-patch")) - (forward-line) - (let ((action (match-string 1)) - (from (string-to-number (match-string 2))) - (len (string-to-number (match-string 3)))) - (cond - ((equal action "a") - (let ((start (point))) - (forward-line len) - (let ((text (buffer-substring start (point)))) - (with-current-buffer target-buffer - (cl-decf line-offset len) - (goto-char (point-min)) - (forward-line (- from len line-offset)) - (insert text))))) - ((equal action "d") - (with-current-buffer target-buffer - (goto-char (point-min)) - (forward-line (1- (- from line-offset))) - (cl-incf line-offset len) - (php-util-buffer--delete-whole-line len))) - (t - (error "Invalid rcs patch or internal error in php-util-buffer--apply-rcs-patch"))))))) - (move-to-column column))) -;; Copy of go-mode.el ends here - -(provide 'php-util-buffer) -;;; php-util-buffer.el ends here diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el deleted file mode 100644 index 663559a..0000000 --- a/.emacs.d/lisp/php.el +++ /dev/null @@ -1,452 +0,0 @@ -;;; php.el --- PHP support for friends -*- lexical-binding: t; -*- - -;; Copyright (C) 2019 Friends of Emacs-PHP development - -;; Author: USAMI Kenta -;; Created: 5 Dec 2018 -;; Version: 1.22.1 -;; Keywords: languages, php -;; Homepage: https://github.com/emacs-php/php-mode -;; Package-Requires: ((emacs "24.3")) -;; 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 . - -;;; Commentary: - -;; This file provides common variable and functions for PHP packages. - -;;; Code: -(require 'cl-lib) -(require 'flymake) -(require 'php-project) -(require 'rx) - -;;;###autoload -(defgroup php nil - "Language support for PHP." - :tag "PHP" - :group 'languages - :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." - :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) - (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." - :group 'php - :tag "PHP Search URL" - :type '(choice (string :tag "URL to search PHP documentation") - (const :tag "Use `php-site-url' variable" nil))) - -(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) - -(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-default-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) - -(defcustom php-default-builtin-web-server-port 3939 - "Port number of PHP Built-in HTTP server (php -S)." - :group 'php - :tag "PHP Default Built-in Web Server Port" - :type 'integer - :link '(url-link :tag "Built-in web server" - "https://www.php.net/manual/features.commandline.webserver.php")) - -;;; PHP Keywords -(defconst php-magical-constants - (list "__LINE__" "__FILE__" "__FUNCTION__" "__CLASS__" "__TRAIT__" "__METHOD__" "__NAMESPACE__") - "Magical keyword that is expanded at compile time. - -These are different from \"constants\" in strict terms. -see https://www.php.net/manual/language.constants.predefined.php") - -;;; Utillity for locate language construction -(defsubst php-in-string-p () - "Return non-nil if inside a string. -it is the character that will terminate the string, or t if the string should be terminated by a generic string delimiter." - (nth 3 (syntax-ppss))) - -(defsubst php-in-comment-p () - "Return nil if outside a comment, t if inside a non-nestable comment, else an integer (the current comment nesting)." - (nth 4 (syntax-ppss))) - -(defsubst php-in-string-or-comment-p () - "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))) - -(defconst php-beginning-of-defun-regexp - "^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(\\sw\\|\\s_\\)+\\)\\s-*(" - "Regular expression for a PHP function.") - -(eval-when-compile - (defun php-create-regexp-for-method (&optional 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." - (when (stringp visibility) - (setq visibility (list visibility))) - (rx-to-string `(: line-start - (* (syntax whitespace)) - ,@(if visibility - `((* (or "abstract" "final" "static") - (+ (syntax whitespace))) - (or ,@visibility) - (+ (syntax whitespace)) - (* (or "abstract" "final" "static") - (+ (syntax whitespace)))) - '((* (* (or "abstract" "final" "static" - "private" "protected" "public") - (+ (syntax whitespace)))))) - "function" - (+ (syntax whitespace)) - (? "&" (* (syntax whitespace))) - (group (+ (or (syntax word) (syntax symbol)))) - (* (syntax whitespace)) - "("))) - - (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_\\)+\\)"))) - -(defconst php-imenu-generic-expression - (eval-when-compile - `(("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) 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-*f\\(unctio\\)?n\\s-*(" 1) - ("Named Functions" - "^\\s-*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1))) - "Imenu generic expression for PHP Mode. See `imenu-generic-expression'.") - -(defconst php--re-namespace-pattern - (eval-when-compile - (php-create-regexp-for-classlike "namespace"))) - -(defconst php--re-classlike-pattern - (eval-when-compile - (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 - (save-match-data - (when (re-search-backward re-pattern nil t) - (match-string-no-properties 1))))) - -;;; Provide support for Flymake so that users can see warnings and -;;; errors in real-time as they write code. -(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* ((init (funcall (eval-when-compile - (if (fboundp 'flymake-proc-php-init) - 'flymake-proc-php-init - 'flymake-php-init))))) - (list php-executable (cdr init)))) - -(defconst php-re-detect-html-tag-aggressive - (eval-when-compile - (rx (or (: string-start (* (in space)) - "")) - (: "<" (* (in space)) (+ (in alpha "-")) (* (in space)) ">")))))) - -(defconst php-re-detect-html-tag-default - (eval-when-compile - (rx (or (: string-start (* (in space)) - "")))))) - -(defcustom php-re-detect-html-tag 'php-re-detect-html-tag-default - "Regexp pattern variable-name of HTML detection." - :group 'php - :tag "PHP Re Detect HTML Tag" - :type '(choice (const :tag "Default pattern" 'php-re-detect-html-tag-default) - (const :tag "Aggressive pattern" 'php-re-detect-html-tag-aggressive) - (variable :tag "Variable name of RegExp pattern"))) - -(defsubst php-re-detect-html-tag () - "Return RegExp pattern for HTML detection." - (if (symbolp php-re-detect-html-tag) - (symbol-value php-re-detect-html-tag) - php-re-detect-html-tag)) - -(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)) - (save-match-data - (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." - (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 -(defun php-copyit-fqsen () - "Copy/kill class/method FQSEN." - (interactive) - (let ((namespace (or (php-get-current-element php--re-namespace-pattern) "")) - (class (or (php-get-current-element php--re-classlike-pattern) "")) - (namedfunc (php-get-current-element php-beginning-of-defun-regexp))) - (kill-new (concat (if (string= namespace "") "" namespace) - (if (string= class "") "" (concat "\\" class "::")) - (if (string= namedfunc "") "" (concat namedfunc "()")))))) - -;;;###autoload -(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root) - "Run PHP Built-in web server. - -`ROUTER-OR-DIR': Path to router PHP script or Document root. -`HOSTNAME': Hostname or IP address of Built-in web server. -`PORT': Port number of Built-in web server. -`DOCUMENT-ROOT': Path to Document root. - -When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'." - (interactive - (let ((insert-default-directory t) - (d-o-r (read-file-name "Document root or Script: " default-directory))) - (list - (expand-file-name d-o-r) - (read-string "Hostname: " "0.0.0.0") - (read-number "Port: " php-default-builtin-web-server-port) - (if (file-directory-p d-o-r) - nil - (let ((root-input (read-file-name "Document root: " (directory-file-name d-o-r)))) - (file-name-directory - (if (file-directory-p root-input) - root-input - (directory-file-name root-input)))))))) - (let* ((default-directory - (or document-root - (if (file-directory-p router-or-dir) - router-or-dir - (directory-file-name router-or-dir)))) - (short-dirname (abbreviate-file-name default-directory)) - (short-filename (abbreviate-file-name router-or-dir)) - (buf-name (format "php -S %s:%s -t %s %s" - hostname - port - short-dirname - (if document-root short-filename ""))) - (args (cl-remove-if - #'null - (list "-S" - (format "%s:%d" hostname port) - "-t" - default-directory - (when document-root router-or-dir))))) - (message "Run PHP built-in server: %s" buf-name) - (apply #'make-comint buf-name php-executable nil args) - (funcall - (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer) - (format "*%s*" buf-name)))) - -(defun php-ini () - "Get `php --ini' output buffer." - (interactive) - (let ((buffer (get-buffer-create " *php --ini*"))) - (with-current-buffer buffer - (view-mode -1) - (read-only-mode -1) - (erase-buffer) - (shell-command (concat php-executable " --ini") buffer) - (view-mode +1)) - (if (called-interactively-p 'interactive) - (pop-to-buffer buffer) - buffer))) - -(defun php-find-system-php-ini-file (&optional file) - "Find php.ini FILE by `php --ini'." - (interactive - (list - (let* ((default-directory (expand-file-name "~")) - (buffer (php-ini)) - (path (with-current-buffer buffer - (goto-char (point-min)) - (save-match-data - (when (re-search-forward ": \\(.+?\\)$" nil nil) - (match-string 1)))))) - (when (or (null path) (not (file-directory-p path))) - (when (called-interactively-p 'interactive) - (pop-to-buffer buffer)) - (user-error "Failed get path to PHP ini files directory")) - (read-file-name "Find php.ini file: " - (concat (expand-file-name path) "/") - nil nil nil - #'file-exists-p)))) - (find-file file)) - -(provide 'php) -;;; php.el ends here diff --git a/.emacs.d/lisp/rust-playpen.el b/.emacs.d/lisp/rust-playpen.el index a80a184..07b7296 100644 --- a/.emacs.d/lisp/rust-playpen.el +++ b/.emacs.d/lisp/rust-playpen.el @@ -17,7 +17,7 @@ :group 'rust-mode) (defcustom rust-playpen-enable-shortener t - "Enable shortended URL for playpen links." + "Enable shortened URL for playpen links." :type 'boolean :safe #'booleanp :group 'rust-mode) diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index 1bfa43b..dad0380 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el @@ -78,7 +78,7 @@ (defcustom yaml-indent-offset 2 "*Amount of offset per level of indentation." :type 'integer - :safe 'natnump + :safe #'natnump :group 'yaml) (defcustom yaml-backspace-function 'backward-delete-char-untabify @@ -186,11 +186,11 @@ that key is pressed to begin a block literal." (defvar yaml-mode-map (let ((map (make-sparse-keymap))) - (define-key map "|" 'yaml-electric-bar-and-angle) - (define-key map ">" 'yaml-electric-bar-and-angle) - (define-key map "-" 'yaml-electric-dash-and-dot) - (define-key map "." 'yaml-electric-dash-and-dot) - (define-key map (kbd "DEL") 'yaml-electric-backspace) + (define-key map "|" #'yaml-electric-bar-and-angle) + (define-key map ">" #'yaml-electric-bar-and-angle) + (define-key map "-" #'yaml-electric-dash-and-dot) + (define-key map "." #'yaml-electric-dash-and-dot) + (define-key map (kbd "DEL") #'yaml-electric-backspace) map) "Keymap used in `yaml-mode' buffers.") @@ -216,20 +216,18 @@ that key is pressed to begin a block literal." ;;;###autoload (define-derived-mode yaml-mode text-mode "YAML" - "Simple mode to edit YAML. - -\\{yaml-mode-map}" - :syntax-table yaml-mode-syntax-table + "Simple mode to edit YAML." + (setq-local electric-indent-inhibit t) ;We can't *re*indent reliably. (set (make-local-variable 'comment-start) "# ") (set (make-local-variable 'comment-start-skip) "#+ *") (set (make-local-variable 'comment-end) "") - (set (make-local-variable 'indent-line-function) 'yaml-indent-line) + (set (make-local-variable 'indent-line-function) #'yaml-indent-line) (set (make-local-variable 'indent-tabs-mode) nil) - (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph) + (set (make-local-variable 'fill-paragraph-function) #'yaml-fill-paragraph) (set (make-local-variable 'page-delimiter) "^---\\([ \t].*\\)*\n") (set (make-local-variable 'syntax-propertize-function) - 'yaml-mode-syntax-propertize-function) + #'yaml-mode-syntax-propertize-function) (setq font-lock-defaults '(yaml-font-lock-keywords))) @@ -459,6 +457,7 @@ Outside of comments, this behaves as `fill-paragraph' except that filling does not cross boundaries of block literals. Inside comments, this will do usual adaptive fill behaviors." (interactive "*P") + ;; FIXME: Can we get away with setting only `fill-forward-paragraph-function'? (save-restriction (yaml-narrow-to-block-literal) (let ((fill-paragraph-function nil)) @@ -466,12 +465,13 @@ this will do usual adaptive fill behaviors." (fill-paragraph justify region))))) (defun yaml-set-imenu-generic-expression () - (make-local-variable 'imenu-generic-expression) - (make-local-variable 'imenu-create-index-function) - (setq imenu-create-index-function 'imenu-default-create-index-function) - (setq imenu-generic-expression yaml-imenu-generic-expression)) + ;; FIXME: Why set this var to its default value? + (setq-local imenu-create-index-function #'imenu-default-create-index-function) + (setq-local imenu-generic-expression yaml-imenu-generic-expression)) -(add-hook 'yaml-mode-hook 'yaml-set-imenu-generic-expression) +;; FIXME: Why not inline `yaml-set-imenu-generic-expression' into the +;; major mode function? +(add-hook 'yaml-mode-hook #'yaml-set-imenu-generic-expression) (defun yaml-mode-version () diff --git a/.emacs.pure b/.emacs.pure index 46acbfe..9dc4f05 100644 --- a/.emacs.pure +++ b/.emacs.pure @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- ;; Set up the keyboard so the delete key on both the regular keyboard ;; and the keypad delete the character under the cursor and to the right ;; under X, instead of the default, backspace behavior. -- cgit v1.3