2024-06-07 12:39:03 +02:00
|
|
|
|
;;; php-ts-mode.el --- Major mode for editing PHP files using tree-sitter -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2024 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
;; Author: Vincenzo Pupillo <v.pupillo@gmail.com>
|
|
|
|
|
;; Maintainer: Vincenzo Pupillo <v.pupillo@gmail.com>
|
|
|
|
|
;; Created: Jun 2024
|
|
|
|
|
;; Keywords: PHP language tree-sitter
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;
|
|
|
|
|
;; This package provides `php-ts-mode' which is a major mode
|
|
|
|
|
;; for editing PHP files with embedded HTML, JavaScript, CSS and phpdoc.
|
|
|
|
|
;; Tree Sitter is used to parse each of these languages.
|
|
|
|
|
;;
|
|
|
|
|
;; Please note that this package requires `html-ts-mode', which
|
|
|
|
|
;; registers itself as the major mode for editing HTML.
|
|
|
|
|
;;
|
|
|
|
|
;; This package is compatible and has been tested with the following
|
|
|
|
|
;; tree-sitter grammars:
|
|
|
|
|
;; * https://github.com/tree-sitter/tree-sitter-php
|
|
|
|
|
;; * https://github.com/tree-sitter/tree-sitter-html
|
|
|
|
|
;; * https://github.com/tree-sitter/tree-sitter-javascript
|
2024-06-25 11:29:54 +02:00
|
|
|
|
;; * https://github.com/tree-sitter/tree-sitter-jsdoc
|
2024-06-07 12:39:03 +02:00
|
|
|
|
;; * https://github.com/tree-sitter/tree-sitter-css
|
|
|
|
|
;; * https://github.com/claytonrcarter/tree-sitter-phpdoc
|
|
|
|
|
;;
|
|
|
|
|
;; Features
|
|
|
|
|
;;
|
|
|
|
|
;; * Indent
|
|
|
|
|
;; * IMenu
|
|
|
|
|
;; * Navigation
|
|
|
|
|
;; * Which-function
|
|
|
|
|
;; * Flymake
|
|
|
|
|
;; * Tree-sitter parser installation helper
|
|
|
|
|
;; * PHP built-in server support
|
|
|
|
|
;; * Shell interaction: execute PHP code in a inferior PHP process
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'treesit)
|
|
|
|
|
(require 'c-ts-common) ;; For comment indent and filling.
|
|
|
|
|
(require 'css-mode) ;; for embed css into html
|
|
|
|
|
(require 'js) ;; for embed javascript into html
|
|
|
|
|
(require 'comint)
|
|
|
|
|
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(require 'cl-lib)
|
|
|
|
|
(require 'rx)
|
|
|
|
|
(require 'subr-x))
|
|
|
|
|
|
|
|
|
|
(declare-function treesit-node-child "treesit.c")
|
|
|
|
|
(declare-function treesit-node-child-by-field-name "treesit.c")
|
|
|
|
|
(declare-function treesit-node-end "treesit.c")
|
|
|
|
|
(declare-function treesit-node-parent "treesit.c")
|
|
|
|
|
(declare-function treesit-node-start "treesit.c")
|
|
|
|
|
(declare-function treesit-node-string "treesit.c")
|
|
|
|
|
(declare-function treesit-node-type "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-add-notifier "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-buffer "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-create "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-included-ranges "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-list "treesit.c")
|
|
|
|
|
(declare-function treesit-parser-language "treesit.c")
|
2024-09-28 15:06:44 +03:00
|
|
|
|
(declare-function treesit-query-compile "treesit.c")
|
2024-06-15 20:03:39 +03:00
|
|
|
|
(declare-function treesit-search-forward "treesit.c")
|
|
|
|
|
(declare-function treesit-node-prev-sibling "treesit.c")
|
|
|
|
|
(declare-function treesit-node-first-child-for-pos "treesit.c")
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
;;; Install treesitter language parsers
|
|
|
|
|
(defvar php-ts-mode--language-source-alist
|
2024-11-07 12:55:50 +01:00
|
|
|
|
'((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.5" "php/src"))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc"))
|
2024-09-27 13:07:06 +02:00
|
|
|
|
(html . ("https://github.com/tree-sitter/tree-sitter-html" "v0.23.0"))
|
|
|
|
|
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.0"))
|
|
|
|
|
(jsdoc . ("https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.23.0"))
|
|
|
|
|
(css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.23.0")))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"Treesitter language parsers required by `php-ts-mode'.
|
|
|
|
|
You can customize this variable if you want to stick to a specific
|
|
|
|
|
commit and/or use different parsers.")
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-install-parsers ()
|
|
|
|
|
"Install all the required treesitter parsers.
|
|
|
|
|
`php-ts-mode--language-source-alist' defines which parsers to install."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((treesit-language-source-alist php-ts-mode--language-source-alist))
|
|
|
|
|
(dolist (item php-ts-mode--language-source-alist)
|
|
|
|
|
(treesit-install-language-grammar (car item)))))
|
|
|
|
|
|
|
|
|
|
;;; Custom variables
|
|
|
|
|
|
|
|
|
|
(defgroup php-ts-mode nil
|
|
|
|
|
"Major mode for editing PHP files."
|
|
|
|
|
:prefix "php-ts-mode-"
|
|
|
|
|
:group 'languages)
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-indent-offset 4
|
|
|
|
|
"Number of spaces for each indentation step in `php-ts-mode'."
|
|
|
|
|
:tag "PHP indent offset"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'integer
|
|
|
|
|
:safe 'integerp)
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-js-css-indent-offset 2
|
|
|
|
|
"JavaScript and CSS indent spaces related to the <script> and <style> HTML tags.
|
|
|
|
|
By default should have same value as `html-ts-mode-indent-offset'."
|
|
|
|
|
:tag "PHP javascript or css indent offset"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'integer
|
|
|
|
|
:safe 'integerp)
|
|
|
|
|
|
2024-06-22 23:11:17 +02:00
|
|
|
|
(defcustom php-ts-mode-css-fontify-colors t
|
|
|
|
|
"Whether CSS colors should be fontified using the color as the background.
|
2024-06-23 08:01:28 +03:00
|
|
|
|
If non-nil, text representing a CSS color will be fontified
|
2024-06-22 23:11:17 +02:00
|
|
|
|
such that its background is the color itself.
|
|
|
|
|
Works like `css--fontify-region'."
|
|
|
|
|
:tag "PHP colors the CSS properties values."
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:safe 'booleanp)
|
|
|
|
|
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(defcustom php-ts-mode-php-executable (or (executable-find "php") "/usr/bin/php")
|
|
|
|
|
"The location of PHP executable."
|
|
|
|
|
:tag "PHP Executable"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'file)
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-php-config nil
|
|
|
|
|
"The location of php.ini file.
|
|
|
|
|
If nil the default one is used to run the embedded webserver or
|
|
|
|
|
inferior PHP process."
|
|
|
|
|
:tag "PHP Init file"
|
|
|
|
|
:version "30.1"
|
2024-06-15 16:20:01 +03:00
|
|
|
|
:type '(choice (const :tag "Default init file" nil) file))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-ws-hostname "localhost"
|
|
|
|
|
"The hostname that will be served by the PHP built-in webserver.
|
|
|
|
|
If nil then `php-ts-mode-run-php-webserver' will ask you for the hostname.
|
|
|
|
|
See `https://www.php.net/manual/en/features.commandline.webserver.php'."
|
|
|
|
|
:tag "PHP built-in web server hostname"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'string
|
|
|
|
|
:safe 'stringp)
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-ws-port nil
|
|
|
|
|
"The port on which the PHP built-in webserver will listen.
|
|
|
|
|
If nil `php-ts-mode-run-php-webserver' will ask you for the port number."
|
|
|
|
|
:tag "PHP built-in web server port"
|
|
|
|
|
:version "30.1"
|
2024-06-15 16:20:01 +03:00
|
|
|
|
:type '(choice (const :tag "Ask which port to use" nil) integer)
|
|
|
|
|
:safe 'integer-or-null-p)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-ws-document-root nil
|
|
|
|
|
"The root of the documents that the PHP built-in webserver will serve.
|
|
|
|
|
If nil `php-ts-mode-run-php-webserver' will ask you for the document root."
|
|
|
|
|
:tag "PHP built-in web server document root"
|
|
|
|
|
:version "30.1"
|
2024-06-15 16:20:01 +03:00
|
|
|
|
:type '(choice (const :tag "Ask for document root" nil) directory))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-ws-workers nil
|
|
|
|
|
"The number of workers the PHP built-in webserver will fork.
|
|
|
|
|
Useful for testing code against multiple simultaneous requests."
|
|
|
|
|
:tag "PHP built-in number of workers"
|
|
|
|
|
:version "30.1"
|
2024-06-15 16:20:01 +03:00
|
|
|
|
:type '(choice (const :tag "No workers" nil) integer)
|
|
|
|
|
:safe 'integer-or-null-p)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-inferior-php-buffer "*PHP*"
|
|
|
|
|
"Name of the inferior PHP buffer."
|
|
|
|
|
:tag "PHP inferior process buffer name"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type 'string
|
|
|
|
|
:safe 'stringp)
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-inferior-history nil
|
|
|
|
|
"File used to save command history of the inferior PHP process."
|
|
|
|
|
:tag "PHP inferior process history file."
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type '(choice (const :tag "None" nil) file)
|
|
|
|
|
:safe 'string-or-null-p)
|
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--inferior-prompt "php >"
|
|
|
|
|
"Prompt used by PHP inferior process.")
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--indent-style-setter (sym val)
|
|
|
|
|
"Custom setter for `php-ts-mode-set-style'.
|
|
|
|
|
|
|
|
|
|
Apart from setting the default value of SYM to VAL, also change
|
|
|
|
|
the value of SYM in `php-ts-mode' buffers to VAL.
|
|
|
|
|
SYM should be `php-ts-mode-indent-style', and VAL should be a style
|
|
|
|
|
symbol."
|
|
|
|
|
(set-default sym val)
|
|
|
|
|
(dolist (buffer (buffer-list))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(when (derived-mode-p 'php-ts-mode)
|
|
|
|
|
(php-ts-mode-set-style val)))))
|
|
|
|
|
|
2024-07-15 15:08:41 -05:00
|
|
|
|
;; taken from c-ts-mode
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(defun php-ts-indent-style-safep (style)
|
|
|
|
|
"Non-nil if STYLE's value is safe for file-local variables."
|
|
|
|
|
(and (symbolp style) (not (functionp style))))
|
|
|
|
|
|
|
|
|
|
(defcustom php-ts-mode-indent-style 'psr2
|
|
|
|
|
"Style used for indentation.
|
|
|
|
|
The selected style could be one of:
|
2024-06-16 21:59:42 +02:00
|
|
|
|
`PSR-2/PSR-12' - use PSR standards (PSR-2, PSR-12), this is the default.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
`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.
|
|
|
|
|
`Symfony' - use coding styles preferred for working with Symfony projects.
|
|
|
|
|
`Zend' - use coding styles preferred for working with Zend projects.
|
|
|
|
|
|
|
|
|
|
If one of the supplied styles doesn't suffice, a function could be
|
|
|
|
|
set instead. This function is expected return a list that
|
|
|
|
|
follows the form of `treesit-simple-indent-rules'."
|
|
|
|
|
:tag "PHP indent style"
|
|
|
|
|
:version "30.1"
|
|
|
|
|
:type '(choice (const :tag "PSR-2/PSR-12" psr2)
|
|
|
|
|
(const :tag "PEAR" pear)
|
|
|
|
|
(const :tag "Drupal" drupal)
|
|
|
|
|
(const :tag "WordPress" wordpress)
|
|
|
|
|
(const :tag "Symfony" symfony)
|
|
|
|
|
(const :tag "Zend" zend)
|
|
|
|
|
(function :tag "A function for user customized style" ignore))
|
|
|
|
|
:set #'php-ts-mode--indent-style-setter
|
|
|
|
|
:safe #'php-ts-indent-style-safep)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Flymake integration
|
|
|
|
|
|
|
|
|
|
;; based on lua-ts-mode
|
|
|
|
|
(defvar-local php-ts-mode--flymake-process nil
|
|
|
|
|
"Store the Flymake process.")
|
|
|
|
|
|
|
|
|
|
;; TODO: add phpmd and phpcs
|
|
|
|
|
(defun php-ts-mode-flymake-php (report-fn &rest _args)
|
|
|
|
|
"PHP backend for Flymake.
|
|
|
|
|
Calls REPORT-FN directly."
|
|
|
|
|
(when (process-live-p php-ts-mode--flymake-process)
|
|
|
|
|
(kill-process php-ts-mode--flymake-process))
|
|
|
|
|
(let ((source (current-buffer))
|
|
|
|
|
(diagnostics-pattern (eval-when-compile
|
2024-06-16 21:59:42 +02:00
|
|
|
|
(rx bol (? "PHP ") ;; every diagnostic line start with PHP
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(group (or "Fatal" "Parse")) ;; 1: type
|
|
|
|
|
" error:" (+ (syntax whitespace))
|
2024-06-13 10:49:28 +02:00
|
|
|
|
(group (+? nonl)) ;; 2: msg
|
|
|
|
|
" in " (group (+? nonl)) ;; 3: file
|
2024-06-07 12:39:03 +02:00
|
|
|
|
" on line " (group (+ num)) ;; 4: line
|
|
|
|
|
eol))))
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(setq php-ts-mode--flymake-process
|
|
|
|
|
(make-process
|
|
|
|
|
:name "php-ts-mode-flymake"
|
|
|
|
|
:noquery t
|
|
|
|
|
:connection-type 'pipe
|
|
|
|
|
:buffer (generate-new-buffer " *php-ts-mode-flymake*")
|
|
|
|
|
:command `(,php-ts-mode-php-executable
|
|
|
|
|
"-l" "-d" "display_errors=0")
|
|
|
|
|
:sentinel
|
|
|
|
|
(lambda (proc _event)
|
|
|
|
|
(when (eq 'exit (process-status proc))
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(if (with-current-buffer source
|
|
|
|
|
(eq proc php-ts-mode--flymake-process))
|
|
|
|
|
(with-current-buffer (process-buffer proc)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(let (diags)
|
|
|
|
|
(while (search-forward-regexp
|
|
|
|
|
diagnostics-pattern
|
|
|
|
|
nil t)
|
|
|
|
|
(let* ((beg
|
|
|
|
|
(car (flymake-diag-region
|
|
|
|
|
source
|
|
|
|
|
(string-to-number (match-string 4)))))
|
|
|
|
|
(end
|
|
|
|
|
(cdr (flymake-diag-region
|
|
|
|
|
source
|
|
|
|
|
(string-to-number (match-string 4)))))
|
|
|
|
|
(msg (match-string 2))
|
|
|
|
|
(type :error))
|
|
|
|
|
(push (flymake-make-diagnostic
|
|
|
|
|
source beg end type msg)
|
|
|
|
|
diags)))
|
|
|
|
|
(funcall report-fn diags)))
|
|
|
|
|
(flymake-log :warning "Canceling obsolete check %s" proc))
|
|
|
|
|
(kill-buffer (process-buffer proc)))))))
|
|
|
|
|
(process-send-region php-ts-mode--flymake-process (point-min) (point-max))
|
|
|
|
|
(process-send-eof php-ts-mode--flymake-process))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Utils
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--get-indent-style ()
|
|
|
|
|
"Helper function to set indentation style.
|
|
|
|
|
MODE can be `psr2', `pear', `drupal', `wordpress', `symfony', `zend'."
|
|
|
|
|
(let ((style
|
|
|
|
|
(if (functionp php-ts-mode-indent-style)
|
|
|
|
|
(funcall php-ts-mode-indent-style)
|
|
|
|
|
(cl-case php-ts-mode-indent-style
|
|
|
|
|
(psr2 (alist-get 'psr2 (php-ts-mode--indent-styles)))
|
|
|
|
|
(pear (alist-get 'pear (php-ts-mode--indent-styles)))
|
|
|
|
|
(drupal (alist-get 'drupal (php-ts-mode--indent-styles)))
|
|
|
|
|
(wordpress (alist-get 'wordpress (php-ts-mode--indent-styles)))
|
|
|
|
|
(symfony (alist-get 'symfony (php-ts-mode--indent-styles)))
|
|
|
|
|
(zend (alist-get 'zend (php-ts-mode--indent-styles)))
|
|
|
|
|
(t (alist-get 'psr2 (php-ts-mode--indent-styles)))))))
|
|
|
|
|
`((php ,@style))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--prompt-for-style ()
|
|
|
|
|
"Prompt for an indent style and return the symbol for it."
|
|
|
|
|
(intern
|
|
|
|
|
(completing-read
|
|
|
|
|
"Style: "
|
|
|
|
|
(mapcar #'car (php-ts-mode--indent-styles))
|
|
|
|
|
nil t nil nil "default")))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-set-global-style (style)
|
|
|
|
|
"Set the indent style of PHP modes globally to STYLE.
|
|
|
|
|
|
|
|
|
|
This changes the current indent style of every PHP buffer and
|
|
|
|
|
the default PHP indent style for `php-ts-mode'
|
|
|
|
|
in this Emacs session."
|
|
|
|
|
(interactive (list (php-ts-mode--prompt-for-style)))
|
|
|
|
|
(php-ts-mode--indent-style-setter 'php-ts-mode-indent-style style))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--set-indent-property (style)
|
|
|
|
|
"Set the offset, tab, etc. according to STYLE."
|
|
|
|
|
(cl-case style
|
|
|
|
|
(psr2 (setq php-ts-mode-indent-offset 4
|
|
|
|
|
tab-width 4
|
|
|
|
|
indent-tabs-mode nil))
|
|
|
|
|
(pear (setq php-ts-mode-indent-offset 4
|
|
|
|
|
tab-width 4
|
|
|
|
|
indent-tabs-mode nil))
|
|
|
|
|
(drupal (setq php-ts-mode-indent-offset 2
|
|
|
|
|
tab-width 2
|
|
|
|
|
indent-tabs-mode nil))
|
|
|
|
|
(wordpress (setq php-ts-mode-indent-offset 4
|
|
|
|
|
tab-width 4
|
|
|
|
|
indent-tabs-mode t))
|
|
|
|
|
(symfony (setq php-ts-mode-indent-offset 4
|
|
|
|
|
tab-width 4
|
|
|
|
|
indent-tabs-mode nil))
|
|
|
|
|
(zend (setq php-ts-mode-indent-offset 4
|
|
|
|
|
tab-width 4
|
|
|
|
|
indent-tabs-mode nil))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-set-style (style)
|
|
|
|
|
"Set the PHP indent style of the current buffer to STYLE.
|
|
|
|
|
To set the default indent style globally, use
|
|
|
|
|
`php-ts-mode-set-global-style'."
|
|
|
|
|
(interactive (list (php-ts-mode--prompt-for-style)))
|
|
|
|
|
(cond
|
|
|
|
|
((not (derived-mode-p 'php-ts-mode))
|
|
|
|
|
(user-error "The current buffer is not in `php-ts-mode'"))
|
|
|
|
|
((equal php-ts-mode-indent-style style)
|
|
|
|
|
(message "The style is already %s" style));; nothing to do
|
|
|
|
|
(t (progn
|
|
|
|
|
(setq-local php-ts-mode-indent-style style)
|
|
|
|
|
(php-ts-mode--set-indent-property style)
|
|
|
|
|
(let ((rules (assq-delete-all 'php treesit-simple-indent-rules))
|
|
|
|
|
(new-style (car (treesit--indent-rules-optimize
|
|
|
|
|
(php-ts-mode--get-indent-style)))))
|
|
|
|
|
(setq treesit-simple-indent-rules (cons new-style rules))
|
|
|
|
|
(message "Switch to %s style" style))))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--get-parser-ranges ()
|
|
|
|
|
"Return the ranges covered by the parsers.
|
|
|
|
|
|
|
|
|
|
`php-ts-mode' use five parsers, this function returns, for the
|
|
|
|
|
current buffer, the ranges covered by each parser.
|
2024-06-16 21:59:42 +02:00
|
|
|
|
Useful for debugging."
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(let ((ranges)
|
|
|
|
|
(parsers (treesit-parser-list nil nil t)))
|
|
|
|
|
(if (not parsers)
|
|
|
|
|
(message "At least one parser must be initialized"))
|
|
|
|
|
(cl-loop
|
|
|
|
|
for parser in parsers
|
|
|
|
|
do (push (list parser (treesit-parser-included-ranges parser)) ranges)
|
|
|
|
|
finally return ranges)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Syntax table
|
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--syntax-table
|
|
|
|
|
(let ((table (make-syntax-table)))
|
|
|
|
|
(modify-syntax-entry ?\\ "\\" table)
|
|
|
|
|
(modify-syntax-entry ?+ "." table)
|
|
|
|
|
(modify-syntax-entry ?- "." table)
|
|
|
|
|
(modify-syntax-entry ?= "." table)
|
|
|
|
|
(modify-syntax-entry ?% "." table)
|
|
|
|
|
(modify-syntax-entry ?< "." table)
|
|
|
|
|
(modify-syntax-entry ?> "." table)
|
|
|
|
|
(modify-syntax-entry ?& "." table)
|
|
|
|
|
(modify-syntax-entry ?| "." table)
|
|
|
|
|
(modify-syntax-entry ?\' "\"" table)
|
|
|
|
|
(modify-syntax-entry ?\240 "." table)
|
|
|
|
|
(modify-syntax-entry ?/ ". 124b" table)
|
|
|
|
|
(modify-syntax-entry ?* ". 23" table)
|
|
|
|
|
(modify-syntax-entry ?\n "> b" table)
|
|
|
|
|
(modify-syntax-entry ?\^m "> b" table)
|
|
|
|
|
;; php specific syntax
|
|
|
|
|
(modify-syntax-entry ?_ "w" table)
|
|
|
|
|
(modify-syntax-entry ?` "\"" table)
|
|
|
|
|
(modify-syntax-entry ?\" "\"" table)
|
|
|
|
|
(modify-syntax-entry ?\r "> b" table)
|
|
|
|
|
(modify-syntax-entry ?# "< b" table)
|
|
|
|
|
(modify-syntax-entry ?$ "_" table)
|
|
|
|
|
table)
|
|
|
|
|
"Syntax table for `php-ts-mode'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Indent
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(defconst php-ts-mode--possibly-braceless-keyword-re
|
|
|
|
|
(regexp-opt '("if" "for" "foreach" "while" "do") 'symbols)
|
|
|
|
|
"Regexp matching keywords optionally followed by an opening brace.")
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--open-statement-group-heuristic (node _parent bol &rest _)
|
|
|
|
|
"Heuristic matcher for statement-group without closing bracket.
|
|
|
|
|
|
|
|
|
|
Return `php-ts-mode-indent-offset' plus 1 when BOL is after
|
|
|
|
|
`php-ts-mode--possibly-braceless-keyword-re', otherwise return 0. It's
|
2024-10-27 07:49:32 +01:00
|
|
|
|
useful for matching incomplete compound_statement or colon_block.
|
2024-10-10 16:06:37 +02:00
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
|
|
|
|
(and (null node)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(if (re-search-forward
|
|
|
|
|
php-ts-mode--possibly-braceless-keyword-re
|
|
|
|
|
bol t)
|
|
|
|
|
(+ 1 php-ts-mode-indent-offset)
|
|
|
|
|
0))))
|
|
|
|
|
|
2024-06-07 12:39:03 +02:00
|
|
|
|
;; taken from c-ts-mode
|
|
|
|
|
(defun php-ts-mode--else-heuristic (node parent bol &rest _)
|
|
|
|
|
"Heuristic matcher for when \"else\" is followed by a closing bracket.
|
|
|
|
|
|
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
|
|
|
|
(and (null node)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(looking-at (rx (* whitespace) "else" (* whitespace) eol)))
|
|
|
|
|
(let ((next-node (treesit-node-first-child-for-pos parent bol)))
|
|
|
|
|
(equal (treesit-node-type next-node) "}"))))
|
|
|
|
|
|
|
|
|
|
;; taken from c-ts-mode
|
|
|
|
|
(defun php-ts-mode--first-sibling (node parent &rest _)
|
|
|
|
|
"Matches when NODE is the \"first sibling\".
|
|
|
|
|
|
|
|
|
|
\"First sibling\" is defined as: the first child node of PARENT
|
|
|
|
|
such that it's on its own line. NODE is the node to match and
|
|
|
|
|
PARENT is its parent."
|
|
|
|
|
(let ((prev-sibling (treesit-node-prev-sibling node t)))
|
|
|
|
|
(or (null prev-sibling)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (treesit-node-start prev-sibling))
|
|
|
|
|
(<= (line-beginning-position)
|
|
|
|
|
(treesit-node-start parent)
|
|
|
|
|
(line-end-position))))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--js-css-tag-bol (node _parent &rest _)
|
2024-06-16 21:59:42 +02:00
|
|
|
|
"Find the first non-space characters of html tags <script> or <style>.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
If NODE is nil return `line-beginning-position'. PARENT is ignored.
|
|
|
|
|
NODE is the node to match and PARENT is its parent."
|
|
|
|
|
(if (null node)
|
|
|
|
|
(line-beginning-position)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (treesit-node-start node))
|
|
|
|
|
(re-search-backward "<script>\\|<style>" nil t))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--parent-eol (_node parent &rest _)
|
2024-06-16 21:59:42 +02:00
|
|
|
|
"Find the last non-space characters of the PARENT of the current NODE.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
NODE is the node to match and PARENT is its parent."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (treesit-node-start parent))
|
|
|
|
|
(line-end-position)))
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(defun php-ts-mode--parent-html-bol (node parent bol &rest _)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"Find the first non-space characters of the HTML tags before NODE.
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
When NODE is nil call `php-ts-mode--open-statement-group-heuristic'.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(if (null node)
|
|
|
|
|
;; If NODE is nil it could be an open statement-group.
|
|
|
|
|
(php-ts-mode--open-statement-group-heuristic node parent bol)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((html-node (treesit-search-forward node "text" t)))
|
|
|
|
|
(if html-node
|
|
|
|
|
(let ((end-html (treesit-node-end html-node)))
|
|
|
|
|
(goto-char end-html)
|
|
|
|
|
(backward-word)
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(point))
|
|
|
|
|
(treesit-node-start parent))))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--parent-html-heuristic (node parent bol &rest _)
|
2024-09-02 14:11:01 +02:00
|
|
|
|
"Return position based on html indentation.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
Returns 0 if the NODE is after the </html>, otherwise returns the
|
2024-10-10 16:06:37 +02:00
|
|
|
|
indentation point of the last word before the NODE, plus the indentation
|
|
|
|
|
offset. If there is no HTML tag, it returns the beginning of the
|
|
|
|
|
parent. When NODE is nil call `php-ts-mode--open-statement-group-heuristic'.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
It can be used when you want to indent PHP code relative to the HTML.
|
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(if (null node)
|
|
|
|
|
;; If NODE is nil it could be an open statement-group.
|
|
|
|
|
(php-ts-mode--open-statement-group-heuristic node parent bol)
|
|
|
|
|
(let ((html-node (treesit-search-forward node "text" t)))
|
|
|
|
|
(if html-node
|
|
|
|
|
(let ((end-html (treesit-node-end html-node)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char end-html)
|
|
|
|
|
(backward-word)
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(if (search-forward "</html>" end-html t 1)
|
|
|
|
|
0
|
|
|
|
|
(+ (point) php-ts-mode-indent-offset))))
|
|
|
|
|
;; Maybe it's better to use bol?
|
|
|
|
|
(treesit-node-start parent)))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--array-element-heuristic (_node parent _bol &rest _)
|
|
|
|
|
"Return of the position of the first element of the array.
|
|
|
|
|
|
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
|
|
|
|
(let ((parent-start
|
|
|
|
|
(treesit-node-start parent))
|
|
|
|
|
(parent-first-child-start
|
|
|
|
|
(treesit-node-start (treesit-node-child parent 2))))
|
|
|
|
|
(if (equal
|
|
|
|
|
(line-number-at-pos parent-start)
|
|
|
|
|
(line-number-at-pos parent-first-child-start))
|
|
|
|
|
;; if array_creation_expression and the first
|
|
|
|
|
;; array_element_initializer are on the same same line
|
|
|
|
|
parent-first-child-start
|
|
|
|
|
;; else return parent-bol plus the offset
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (treesit-node-start parent))
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(+ (point) php-ts-mode-indent-offset)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--anchor-first-sibling (_node parent _bol &rest _)
|
|
|
|
|
"Return the start of the first child of a sibling of PARENT.
|
|
|
|
|
|
|
|
|
|
If the fist sibling of PARENT and the first child of the sibling are
|
2024-06-16 21:59:42 +02:00
|
|
|
|
on the same line return the start position of the first child of the
|
2024-06-07 12:39:03 +02:00
|
|
|
|
sibling. Otherwise return the start of the first sibling.
|
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
|
|
|
|
(let ((first-sibling-start
|
|
|
|
|
(treesit-node-start (treesit-node-child parent 0)))
|
|
|
|
|
(first-sibling-child-start
|
|
|
|
|
(treesit-node-start (treesit-node-child parent 1))))
|
|
|
|
|
(if (equal
|
|
|
|
|
(line-number-at-pos first-sibling-start)
|
|
|
|
|
(line-number-at-pos first-sibling-child-start))
|
|
|
|
|
;; if are on the same line return the child start
|
|
|
|
|
first-sibling-child-start
|
|
|
|
|
first-sibling-start)))
|
|
|
|
|
|
|
|
|
|
;; adapted from c-ts-mode--anchor-prev-sibling
|
|
|
|
|
(defun php-ts-mode--anchor-prev-sibling (node parent bol &rest _)
|
|
|
|
|
"Return the start of the previous named sibling of NODE.
|
|
|
|
|
|
|
|
|
|
Return nil if a) there is no prev-sibling, or b) prev-sibling
|
|
|
|
|
doesn't have a child.
|
|
|
|
|
|
|
|
|
|
PARENT is NODE's parent, BOL is the beginning of non-whitespace
|
|
|
|
|
characters of the current line."
|
Mark if-let and when-let obsolete
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark
if-let and when-let obsolete (bug#73853 and elsewhere). Move
docstring text around so that if-let* and when-let* descriptions
no longer refer to if-let and when-let.
* etc/NEWS: Announce the change.
* admin/admin.el (reminder-for-release-blocking-bugs):
* doc/misc/erc.texi (display-buffer):
* lisp/ansi-color.el (ansi-color-apply)
(ansi-color--face-vec-face):
* lisp/ansi-osc.el (ansi-osc-apply-on-region)
(ansi-osc-hyperlink):
* lisp/arc-mode.el (archive-goto-file)
(archive-next-file-displayer):
* lisp/auth-source-pass.el (auth-source-pass-search)
(auth-source-pass--parse-data)
(auth-source-pass--find-match-many):
* lisp/autorevert.el (auto-revert-notify-rm-watch):
* lisp/buff-menu.el (Buffer-menu-unmark-all-buffers)
(Buffer-menu-group-by-root):
* lisp/calendar/parse-time.el (parse-iso8601-time-string):
* lisp/cedet/pulse.el (pulse-tick):
* lisp/comint.el (comint--fontify-input-ppss-flush-indirect)
(comint--intersect-regions):
* lisp/completion-preview.el (completion-preview--try-table)
(completion-preview--capf-wrapper, completion-preview--update):
* lisp/cus-edit.el (setopt--set)
(custom-dirlocals-maybe-update-cons, custom-dirlocals-validate):
* lisp/custom.el (load-theme):
* lisp/descr-text.el (describe-char):
* lisp/desktop.el (desktop--emacs-pid-running-p):
* lisp/dired-x.el (menu):
* lisp/dired.el (dired-font-lock-keywords)
(dired-insert-directory, dired--insert-disk-space, dired-mode):
* lisp/dnd.el (dnd-handle-multiple-urls):
* lisp/dom.el (dom-remove-attribute):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare):
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec):
* lisp/emacs-lisp/comp-cstr.el (comp--all-classes)
(comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem)
(comp-cstr-intersection-no-mem, comp-cstr-fixnum-p)
(comp-cstr-type-p):
* lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install)
(native--compile-async):
* lisp/emacs-lisp/comp.el (comp--get-function-cstr)
(comp--function-pure-p, comp--intern-func-in-ctxt)
(comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar)
(comp--add-call-cstr, comp--compute-dominator-tree)
(comp--dom-tree-walker, comp--ssa-rename)
(comp--function-call-maybe-fold, comp--fwprop-call)
(comp--call-optim-func):
* lisp/emacs-lisp/edebug.el (edebug-global-prefix)
(edebug-remove-instrumentation):
* lisp/emacs-lisp/eieio.el (initialize-instance):
* lisp/emacs-lisp/ert-x.el (ert-resource-directory):
* lisp/emacs-lisp/ert.el (ert--expand-should-1)
(ert-test-location, ert-write-junit-test-report)
(ert-test--erts-test):
* lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string)
(icons--create):
* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p):
* lisp/emacs-lisp/loaddefs-gen.el
(loaddefs-generate--make-autoload)
(loaddefs-generate--parse-file):
* lisp/emacs-lisp/multisession.el
(multisession-edit-mode--revert, multisession-edit-value):
* lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data)
(package-vc--version, package-vc--clone):
* lisp/emacs-lisp/package.el (package--reload-previously-loaded):
* lisp/emacs-lisp/pp.el (pp--insert-lisp):
* lisp/emacs-lisp/subr-x.el (add-display-text-property):
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-print):
* lisp/emacs-lisp/timer.el (run-at-time):
* lisp/emacs-lisp/vtable.el (vtable-goto-table)
(vtable-goto-column, vtable-update-object, vtable--insert-line)
(vtable--compute-widths, vtable--make-keymap):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/epa-file.el (epa-file-insert-file-contents):
* lisp/epa.el (epa-show-key):
* lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt)
(PRIVMSG, erc--get-isupport-entry):
* lisp/erc/erc-button.el (erc-button-add-nickname-buttons)
(erc--button-next):
* lisp/erc/erc-common.el (erc--find-group):
* lisp/erc/erc-fill.el (erc-fill, erc-fill-static)
(erc-fill--wrap-escape-hidden-speaker)
(erc-fill--wrap-unmerge-on-date-stamp)
(erc-fill--wrap-massage-initial-message-post-clear)
(erc-fill-wrap, erc-fill--wrap-rejigger-region):
* lisp/erc/erc-goodies.el (erc--scrolltobottom-all)
(erc--keep-place-indicator-on-window-buffer-change)
(keep-place-indicator, erc--keep-place-indicator-adjust-on-clear)
(erc-keep-place-move, erc--command-indicator-display):
* lisp/erc/erc-ibuffer.el (erc-members):
* lisp/erc/erc-join.el (erc-join--remove-requested-channel)
(erc-autojoin--join):
* lisp/erc/erc-networks.el
(erc-networks--id-qualifying-init-parts, erc-networks--id-reload)
(erc-networks--id-ensure-comparable)
(erc-networks--reclaim-orphaned-target-buffers)
(erc-networks--server-select):
* lisp/erc/erc-nicks.el (erc-nicks-invert)
(erc-nicks--redirect-face-widget-link, erc-nicks--highlight)
(erc-nicks--highlight-button)
(erc-nicks--list-faces-help-button-action, erc-nicks-list-faces)
(erc-nicks-refresh, erc-nicks--colors-from-faces)
(erc-nicks--track-prioritize)
(erc-nicks--remember-face-for-track):
* lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next)
(erc--querypoll-on-352, erc--querypoll-send):
* lisp/erc/erc-sasl.el (erc-sasl--read-password):
* lisp/erc/erc-services.el
(erc-services-issue-ghost-and-retry-nick):
* lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar)
(erc-speedbar-toggle-nicknames-window-lock)
(erc-speedbar--compose-nicks-face):
* lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect)
(erc-stamp-prefix-log-filter, erc--conceal-prompt)
(erc--insert-timestamp-left, erc-insert-timestamp-right)
(erc-stamp--defer-date-insertion-on-post-modify)
(erc-insert-timestamp-left-and-right)
(erc-stamp--redo-right-stamp-post-clear)
(erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps):
* lisp/erc/erc-status-sidebar.el (bufbar)
(erc-status-sidebar-prefer-target-as-name)
(erc-status-sidebar-default-allsort, erc-status-sidebar-click):
* lisp/erc/erc-track.el (erc-track--shortened-names-get)
(erc-track--setup, erc-track--select-mode-line-face)
(erc-track-modified-channels, erc-track--collect-faces-in)
(erc-track--switch-buffer, erc-track--replace-killed-buffer):
* lisp/erc/erc-truncate.el (erc-truncate--setup)
(erc-truncate-buffer):
* lisp/erc/erc.el (erc--ensure-query-member)
(erc--ensure-query-members, erc--remove-channel-users-but)
(erc--cusr-change-status, erc--find-mode, erc--update-modules)
(erc-log-irc-protocol, erc--refresh-prompt)
(erc--restore-important-text-props)
(erc--order-text-properties-from-hash, erc-send-input-line)
(erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY)
(erc-cmd-BANLIST, erc--speakerize-nick)
(erc--format-speaker-input-message, erc-channel-receive-names)
(erc-send-current-line, erc-format-target-and/or-network)
(erc-kill-buffer-function, erc-restore-text-properties)
(erc--get-eq-comparable-cmd):
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which)
(eshell-maybe-replace-by-alias):
* lisp/eshell/em-glob.el (eshell-glob-convert):
* lisp/eshell/em-pred.el (eshell-pred-user-or-group)
(eshell-pred-file-time, eshell-pred-file-type)
(eshell-pred-file-mode, eshell-pred-file-links)
(eshell-pred-file-size):
* lisp/eshell/em-prompt.el (eshell-forward-paragraph)
(eshell-next-prompt):
* lisp/eshell/esh-arg.el (eshell-resolve-current-argument):
* lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which)
(eshell-plain-command--which, eshell-plain-command):
* lisp/eshell/esh-io.el (eshell-duplicate-handles)
(eshell-protect-handles, eshell-get-target, eshell-close-target):
* lisp/eshell/esh-proc.el (eshell-sentinel):
* lisp/eshell/esh-var.el (eshell-parse-variable-ref)
(eshell-get-variable, eshell-set-variable):
* lisp/faces.el (face-at-point):
* lisp/ffap.el (ffap-in-project):
* lisp/filenotify.el (file-notify--rm-descriptor):
* lisp/files-x.el (read-dir-locals-file)
(connection-local-update-profile-variables)
(connection-local-value):
* lisp/files.el (file-remote-p, abbreviate-file-name)
(set-auto-mode, hack-local-variables)
(revert-buffer-restore-read-only):
* lisp/find-dired.el (find-dired-sort-by-filename):
* lisp/font-lock.el (font-lock--filter-keywords):
* lisp/gnus/gnus-art.el (article-emojize-symbols):
* lisp/gnus/gnus-int.el (gnus-close-server):
* lisp/gnus/gnus-search.el (gnus-search-transform)
(gnus-search-indexed-parse-output, gnus-search-server-to-engine):
* lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url):
* lisp/gnus/gnus.el (gnus-check-backend-function):
* lisp/gnus/message.el (message-send-mail):
* lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers):
* lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article)
(nnatom--read-article-or-group-authors, nnatom--read-publish)
(nnatom--read-update, nnatom--read-links):
* lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server)
(nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article)
(nnfeed-retrieve-headers, nnfeed--print-part)
(nnfeed-request-article, nnfeed-request-group)
(nnfeed-request-list, nnfeed--group-description)
(nnfeed-request-group-description)
(nnfeed-request-list-newsgroups, nnfeed-request-rename-group):
* lisp/gnus/nnmh.el (nnmh-update-gnus-unreads):
* lisp/help-fns.el (help-find-source)
(help-fns--insert-menu-bindings, help-fns--mention-first-release)
(help-fns--mention-shortdoc-groups)
(help-fns--customize-variable-version)
(help-fns--face-custom-version-info, describe-mode):
* lisp/help-mode.el (help-make-xrefs):
* lisp/help.el (help-key-description, help--describe-command):
* lisp/hfy-cmap.el (htmlfontify-load-rgb-file):
* lisp/ibuf-ext.el (ibuffer-jump-to-filter-group)
(ibuffer-kill-filter-group, ibuffer-kill-line)
(ibuffer-save-filter-groups, ibuffer-save-filters, filename)
(basename, file-extension, ibuffer-diff-buffer-with-file-1)
(ibuffer-mark-by-file-name-regexp)
(ibuffer-mark-by-content-regexp):
* lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen):
* lisp/ibuffer.el (ibuffer-mouse-toggle-mark)
(ibuffer-toggle-marks, ibuffer-mark-interactive)
(ibuffer-compile-format, process, ibuffer-map-lines):
* lisp/image.el (image--compute-map)
(image--compute-original-map):
* lisp/image/exif.el (exif-parse-buffer):
* lisp/image/image-converter.el (image-convert-p, image-convert)
(image-converter--find-converter):
* lisp/image/image-dired-util.el
(image-dired-file-name-at-point):
* lisp/image/image-dired.el (image-dired-track-original-file)
(image-dired--on-file-in-dired-buffer)
(image-dired--with-thumbnail-buffer)
(image-dired-jump-original-dired-buffer)
(image-dired--slideshow-step, image-dired-display-image):
* lisp/image/wallpaper.el (wallpaper--init-action-kill)
(wallpaper--find-setter, wallpaper--find-command)
(wallpaper--find-command-args, wallpaper--x-monitor-name):
* lisp/info-look.el (info-lookup-interactive-arguments)
(info-complete)::(:mode):
* lisp/info.el (info-pop-to-buffer, Info-read-node-name-1):
* lisp/international/emoji.el (emoji--adjust-displayable-1)
(emoji--add-recent):
* lisp/jsonrpc.el (jsonrpc--call-deferred)
(jsonrpc--process-sentinel, jsonrpc--remove):
* lisp/keymap.el (keymap-local-lookup):
* lisp/mail/emacsbug.el (report-emacs-bug-hook)
(submit-emacs-patch):
* lisp/mail/ietf-drums.el (ietf-drums-parse-addresses):
* lisp/mail/mailclient.el (mailclient-send-it):
* lisp/mail/rfc6068.el (rfc6068-parse-mailto-url):
* lisp/mail/undigest.el (rmail-digest-parse-mixed-mime):
* lisp/minibuffer.el (completion-metadata-get)
(completions--after-change)
(minibuffer-visible-completions--filter):
* lisp/net/browse-url.el (browse-url-url-at-point)
(browse-url-file-url, browse-url-emacs):
* lisp/net/dbus.el (dbus-byte-array-to-string)
(dbus-monitor-goto-serial):
* lisp/net/dictionary.el (dictionary-search):
* lisp/net/eww.el (eww--download-directory)
(eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit)
(eww-follow-link, eww-read-alternate-url)
(eww-copy-alternate-url):
* lisp/net/goto-addr.el (goto-address-at-point):
* lisp/net/mailcap.el (mailcap-mime-info):
* lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string)
(rcirc-kill-buffer-hook, rcirc-print, rcirc-when)
(rcirc-color-attributes, rcirc-handler-NICK)
(rcirc-handler-TAGMSG, rcirc-handler-BATCH):
* lisp/net/shr.el (shr-descend, shr-adaptive-fill-function)
(shr-correct-dom-case, shr-tag-a):
* lisp/net/sieve.el (sieve-manage-quit):
* lisp/outline.el (outline-cycle-buffer):
* lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate):
* lisp/proced.el (proced-auto-update-timer):
* lisp/progmodes/bug-reference.el
(bug-reference-try-setup-from-vc):
* lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph):
* lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset)
(c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun):
* lisp/progmodes/compile.el (compilation-error-properties)
(compilation-find-file-1):
* lisp/progmodes/eglot.el (eglot--check-object)
(eglot--read-server, eglot-upgrade-eglot)
(eglot-handle-notification, eglot--CompletionParams)
(eglot-completion-at-point, eglot--sig-info)
(eglot-register-capability):
* lisp/progmodes/elisp-mode.el
(emacs-lisp-native-compile-and-load)
(elisp-eldoc-var-docstring-with-value):
* lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test):
* lisp/progmodes/flymake.el (flymake--update-eol-overlays)
(flymake-eldoc-function):
* lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom)
(gdb-frame-handler):
* lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring)
(go-ts-mode--comment-on-previous-line-p)
(go-ts-mode--get-test-regexp-at-point)
(go-ts-mode-test-this-file):
* lisp/progmodes/grep.el (lgrep, rgrep-default-command)
(grep-file-at-point):
* lisp/progmodes/perl-mode.el (perl--end-of-format-p):
* lisp/progmodes/php-ts-mode.el
(php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun):
* lisp/progmodes/project.el (project--other-place-command)
(project--find-default-from, project--transplant-file-name)
(project-prefixed-buffer-name, project--remove-from-project-list)
(project-prompt-project-name, project-remember-projects-under)
(project--switch-project-command)
(project-uniquify-dirname-transform, project-mode-line-format):
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration)
(python--treesit-fontify-union-types)
(python-shell-get-process-name, python-shell-restart)
(python-shell-completion-at-point, python-ffap-module-path)
(python-util-comint-end-of-output-p, python--import-sources)
(python-add-import, python-remove-import, python-fix-imports):
* lisp/progmodes/xref.el (xref--add-log-current-defun):
* lisp/repeat.el (repeat-echo-message-string):
* lisp/saveplace.el (save-place-dired-hook):
* lisp/server.el (server-save-buffers-kill-terminal):
* lisp/shadowfile.el (shadow-make-fullname)
(shadow-contract-file-name, shadow-define-literal-group):
* lisp/shell.el (shell-highlight-undef-mode):
* lisp/simple.el (command-completion-using-modes-p)
(command-execute, file-user-uid, file-group-gid)
(first-completion, last-completion, switch-to-completions):
* lisp/startup.el (startup--load-user-init-file):
* lisp/tab-line.el (tab-line-tabs-buffer-group-by-project):
* lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer):
* lisp/term/android-win.el (android-encode-select-string)
(gui-backend-set-selection):
* lisp/term/haiku-win.el (haiku-dnd-convert-string)
(haiku-select-encode-xstring, haiku-select-encode-utf-8-string):
* lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize):
* lisp/textmodes/ispell.el (ispell-completion-at-point):
* lisp/textmodes/sgml-mode.el (sgml-validate)
(html-mode--complete-at-point):
* lisp/textmodes/tex-mode.el (tex-recenter-output-buffer)
(xref-backend-references):
* lisp/thingatpt.el (thing-at-point-file-at-point)
(thing-at-point-face-at-point):
* lisp/thread.el (thread-list--get-status):
* lisp/time.el (world-clock-copy-time-as-kill, world-clock):
* lisp/touch-screen.el (touch-screen-handle-touch):
* lisp/treesit.el (treesit-language-at, treesit-node-at)
(treesit-node-on, treesit-buffer-root-node)
(treesit-node-field-name, treesit-local-parsers-at)
(treesit-local-parsers-on, treesit--cleanup-local-range-overlays)
(treesit-font-lock-recompute-features)
(treesit-font-lock-fontify-region, treesit-transpose-sexps)
(treesit-add-log-current-defun, treesit-major-mode-setup)
(treesit--explorer-refresh, treesit-install-language-grammar):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/vc/smerge-mode.el (smerge-diff):
* lisp/vc/vc-dir.el (vc-dir):
* lisp/vc/vc-dispatcher.el (vc-do-async-command):
* lisp/vc/vc-git.el (vc-git-dir--branch-headers)
(vc-git-dir--stash-headers, vc-git--log-edit-summary-check)
(vc-git-stash-list):
* lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset)
(vc-clone):
* lisp/visual-wrap.el (visual-wrap--apply-to-line):
* lisp/wid-edit.el (widget-text)
(widget-editable-list-insert-before):
* lisp/window-tool-bar.el
(window-tool-bar--keymap-entry-to-string):
* lisp/window.el (display-buffer, display-buffer-full-frame)
(window-point-context-set, window-point-context-use)
(window-point-context-use-default-function):
* lisp/xdg.el (xdg-current-desktop):
* lisp/xwidget.el (xwidget-webkit-callback):
* lisp/yank-media.el (yank-media--get-selection)
(yank-media-types):
* test/lisp/comint-tests.el
(comint-tests/test-password-function):
* test/lisp/completion-preview-tests.el
(completion-preview-tests--capf):
* test/lisp/cus-edit-tests.el (with-cus-edit-test):
* test/lisp/erc/erc-scenarios-base-local-modules.el
(-phony-sblm-):
* test/lisp/erc/erc-scenarios-stamp.el
(erc-scenarios-stamp--on-post-modify):
* test/lisp/erc/erc-services-tests.el
(erc-services-tests--asp-parse-entry):
* test/lisp/erc/erc-tests.el (erc-modules--internal-property)
(erc--find-mode, erc-tests--update-modules):
* test/lisp/erc/resources/erc-d/erc-d-i.el
(erc-d-i--parse-message):
* test/lisp/erc/resources/erc-d/erc-d-t.el
(erc-d-t-kill-related-buffers, erc-d-t-with-cleanup):
* test/lisp/erc/resources/erc-d/erc-d-tests.el
(erc-d-i--parse-message--irc-parser-tests):
* test/lisp/erc/resources/erc-d/erc-d-u.el
(erc-d-u--read-exchange-slowly):
* test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire)
(erc-d--finalize-done, erc-d--command-handle-all):
* test/lisp/erc/resources/erc-scenarios-common.el
(erc-scenarios-common-with-cleanup):
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests--common-display-message)
(erc-tests-common-create-subprocess):
* test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058):
* test/lisp/international/mule-tests.el
(mule-cmds-tests--ucs-names-missing-names):
* test/lisp/progmodes/python-tests.el
(python-tests-get-shell-interpreter)
(python-tests--get-interpreter-info):
* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-resource-file):
* test/lisp/replace-tests.el (replace-tests-with-undo):
* test/src/emacs-tests.el (emacs-tests--seccomp-debug):
* test/src/process-tests.el (process-tests--emacs-command)
(process-tests--emacs-binary, process-tests--dump-file):
* test/src/treesit-tests.el (treesit--ert-test-defun-navigation):
Replace use of the now-obsolete if-let and when-let.
2024-10-24 16:50:07 +08:00
|
|
|
|
(when-let* ((prev-sibling
|
|
|
|
|
(or (treesit-node-prev-sibling node t)
|
|
|
|
|
(treesit-node-prev-sibling
|
|
|
|
|
(treesit-node-first-child-for-pos parent bol) t)
|
|
|
|
|
(treesit-node-child parent -1 t)))
|
|
|
|
|
(continue t))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(save-excursion
|
|
|
|
|
(while (and prev-sibling continue)
|
|
|
|
|
(goto-char (treesit-node-start prev-sibling))
|
|
|
|
|
(if (looking-back (rx bol (* whitespace))
|
|
|
|
|
(line-beginning-position))
|
|
|
|
|
(setq continue nil)
|
|
|
|
|
(setq prev-sibling
|
|
|
|
|
(treesit-node-prev-sibling prev-sibling)))))
|
|
|
|
|
(treesit-node-start prev-sibling)))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--indent-styles ()
|
|
|
|
|
"Indent rules supported by `php-ts-mode'."
|
|
|
|
|
(let ((common
|
|
|
|
|
`((php-ts-mode--else-heuristic prev-line php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
((query "(ERROR (ERROR)) @indent") column-0 0)
|
|
|
|
|
|
|
|
|
|
((node-is ")") parent-bol 0)
|
|
|
|
|
((node-is "]") parent-bol 0)
|
|
|
|
|
((node-is "else_clause") parent-bol 0)
|
|
|
|
|
((node-is "case_statement") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((node-is "default_statement") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "default_statement") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((and
|
|
|
|
|
(parent-is "expression_statement")
|
|
|
|
|
(node-is ";"))
|
|
|
|
|
parent-bol 0)
|
|
|
|
|
((parent-is "expression_statement") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
;; `c-ts-common-looking-at-star' has to come before
|
|
|
|
|
;; `c-ts-common-comment-2nd-line-matcher'.
|
|
|
|
|
((and (parent-is "comment") c-ts-common-looking-at-star)
|
|
|
|
|
c-ts-common-comment-start-after-first-star -1)
|
|
|
|
|
(c-ts-common-comment-2nd-line-matcher
|
|
|
|
|
c-ts-common-comment-2nd-line-anchor
|
|
|
|
|
1)
|
|
|
|
|
((parent-is "comment") prev-adaptive-prefix 0)
|
|
|
|
|
|
|
|
|
|
((parent-is "method_declaration") parent-bol 0)
|
|
|
|
|
((node-is "class_interface_clause") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((query "(class_interface_clause (name) @indent)") php-ts-mode--parent-eol 1)
|
|
|
|
|
((query "(class_interface_clause (qualified_name) @indent)")
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "class_declaration") parent-bol 0)
|
2024-11-07 12:55:50 +01:00
|
|
|
|
((parent-is "namespace_use_declaration") parent-bol php-ts-mode-indent-offset)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
((parent-is "namespace_use_group") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "function_definition") parent-bol 0)
|
|
|
|
|
((parent-is "member_call_expression") first-sibling php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "conditional_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "assignment_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "array_creation_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "parenthesized_expression") first-sibling 1)
|
|
|
|
|
((parent-is "binary_expression") parent 0)
|
|
|
|
|
((or (parent-is "arguments")
|
|
|
|
|
(parent-is "formal_parameters"))
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
((query "(for_statement (assignment_expression left: (_)) @indent)")
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((query "(for_statement (binary_expression left: (_)) @indent)")
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((query "(for_statement (update_expression (_)) @indent)")
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((query "(function_call_expression arguments: (_) @indent)")
|
|
|
|
|
parent php-ts-mode-indent-offset)
|
|
|
|
|
((query "(member_call_expression arguments: (_) @indent)")
|
|
|
|
|
parent php-ts-mode-indent-offset)
|
|
|
|
|
((query "(scoped_call_expression name: (_) @indent)")
|
|
|
|
|
parent php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "scoped_property_access_expression")
|
|
|
|
|
parent php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
;; Closing bracket. Must stay here, the rule order matter.
|
|
|
|
|
((node-is "}") standalone-parent 0)
|
|
|
|
|
;; handle multiple single line comment that start at the and of a line
|
|
|
|
|
((match "comment" "declaration_list") php-ts-mode--anchor-prev-sibling 0)
|
|
|
|
|
((parent-is "declaration_list") column-0 php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
((parent-is "initializer_list") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
;; Statement in {} blocks.
|
2024-10-10 16:06:37 +02:00
|
|
|
|
((or (and (or (parent-is "compound_statement")
|
|
|
|
|
(parent-is "colon_block"))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
;; If the previous sibling(s) are not on their
|
|
|
|
|
;; own line, indent as if this node is the first
|
|
|
|
|
;; sibling
|
|
|
|
|
php-ts-mode--first-sibling)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(or (match null "compound_statement")
|
|
|
|
|
(match null "colon_block")))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
standalone-parent php-ts-mode-indent-offset)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
((or (parent-is "compound_statement")
|
|
|
|
|
(parent-is "colon_block"))
|
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
;; Opening bracket.
|
2024-10-10 16:06:37 +02:00
|
|
|
|
((or (node-is "compound_statement")
|
|
|
|
|
(node-is "colon_block"))
|
|
|
|
|
standalone-parent php-ts-mode-indent-offset)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
((parent-is "match_block") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "switch_block") parent-bol 0)
|
|
|
|
|
|
|
|
|
|
;; These rules are for cases where the body is bracketless.
|
|
|
|
|
((match "while" "do_statement") parent-bol 0)
|
2024-06-21 23:24:33 +02:00
|
|
|
|
;; rule for PHP alternative syntax
|
|
|
|
|
((or (node-is "else_if_clause")
|
|
|
|
|
(node-is "endif")
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(node-is "endfor")
|
2024-06-21 23:24:33 +02:00
|
|
|
|
(node-is "endforeach")
|
|
|
|
|
(node-is "endwhile"))
|
|
|
|
|
parent-bol 0)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
((or (parent-is "if_statement")
|
|
|
|
|
(parent-is "else_clause")
|
|
|
|
|
(parent-is "for_statement")
|
|
|
|
|
(parent-is "foreach_statement")
|
|
|
|
|
(parent-is "while_statement")
|
|
|
|
|
(parent-is "do_statement")
|
|
|
|
|
(parent-is "switch_statement")
|
|
|
|
|
(parent-is "case_statement")
|
|
|
|
|
(parent-is "empty_statement"))
|
2024-10-10 16:06:37 +02:00
|
|
|
|
parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
|
|
|
|
|
;; Workaround: handle "for" open statement group. Currently
|
|
|
|
|
;; the grammar handles it differently than other control structures.
|
|
|
|
|
(no-node php-ts-mode--open-statement-group-heuristic 0))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
`((psr2
|
2024-10-10 16:06:37 +02:00
|
|
|
|
((parent-is "program") php-ts-mode--open-statement-group-heuristic 0)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
((parent-is "text_interpolation") column-0 0)
|
|
|
|
|
((parent-is "function_call_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
,@common)
|
|
|
|
|
(pear
|
|
|
|
|
((parent-is "program") php-ts-mode--parent-html-heuristic 0)
|
|
|
|
|
((parent-is "text_interpolation") php-ts-mode--parent-html-heuristic 0)
|
|
|
|
|
((or (node-is "case_statement")
|
|
|
|
|
(node-is "default_statement"))
|
|
|
|
|
parent-bol 0)
|
|
|
|
|
((parent-is "binary_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
,@common)
|
|
|
|
|
(drupal
|
|
|
|
|
((parent-is "program") php-ts-mode--parent-html-heuristic 0)
|
|
|
|
|
((parent-is "text_interpolation") php-ts-mode--parent-html-bol 0)
|
|
|
|
|
((parent-is "if_statement") parent-bol 0)
|
|
|
|
|
((parent-is "binary_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
((parent-is "function_call_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
,@common)
|
|
|
|
|
(symfony
|
|
|
|
|
((parent-is "function_call_expression") parent-bol php-ts-mode-indent-offset)
|
|
|
|
|
,@common)
|
|
|
|
|
(wordpress
|
|
|
|
|
((parent-is "program") php-ts-mode--parent-html-bol 0)
|
|
|
|
|
((parent-is "text_interpolation") php-ts-mode--parent-html-bol 0)
|
|
|
|
|
,@common)
|
|
|
|
|
(zend
|
|
|
|
|
((parent-is "class_interface_clause") php-ts-mode--anchor-first-sibling 0)
|
|
|
|
|
((parent-is "function_call_expression") first-sibling 0)
|
|
|
|
|
((parent-is "array_creation_expression") php-ts-mode--array-element-heuristic 0)
|
|
|
|
|
,@common))))
|
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--phpdoc-indent-rules
|
|
|
|
|
'((phpdoc
|
|
|
|
|
((and (parent-is "document") c-ts-common-looking-at-star)
|
|
|
|
|
c-ts-common-comment-start-after-first-star -1)
|
|
|
|
|
(c-ts-common-comment-2nd-line-matcher
|
|
|
|
|
c-ts-common-comment-2nd-line-anchor
|
|
|
|
|
1)))
|
2024-06-23 16:28:31 +02:00
|
|
|
|
"Tree-sitter indentation rules for `phpdoc'.")
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Font-lock
|
|
|
|
|
|
|
|
|
|
(defconst php-ts-mode--keywords
|
|
|
|
|
'("abstract" "and" "array" "as" "break" "callable" "case" "catch"
|
|
|
|
|
"class" "clone" "const" "continue" "declare" "default" "do" "echo"
|
|
|
|
|
"else" "elseif" "enddeclare" "endfor" "endforeach" "endif"
|
2024-08-24 23:16:09 +02:00
|
|
|
|
"endswitch" "endwhile" "enum" "exit" "extends" "final" "finally" "fn"
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"for" "foreach" "from" "function" "global" "goto" "if" "implements"
|
|
|
|
|
"include" "include_once" "instanceof" "insteadof" "interface"
|
|
|
|
|
"list" "match" "namespace" "new" "null" "or" "print" "private"
|
|
|
|
|
"protected" "public" "readonly" "require" "require_once" "return"
|
|
|
|
|
"static" "switch" "throw" "trait" "try" "unset" "use" "while" "xor"
|
|
|
|
|
"yield")
|
|
|
|
|
"PHP keywords for tree-sitter font-locking.")
|
|
|
|
|
|
|
|
|
|
(defconst php-ts-mode--operators
|
|
|
|
|
'("--" "**=" "*=" "/=" "%=" "+=" "-=" ".=" "<<=" ">>=" "&=" "^="
|
|
|
|
|
"|=" "??" "??=" "||" "&&" "|" "^" "&" "==" "!=" "<>" "===" "!=="
|
|
|
|
|
"<" ">" "<=" ">=" "<=>" "<<" ">>" "+" "-" "." "*" "**" "/" "%"
|
2024-11-07 12:55:50 +01:00
|
|
|
|
"->" "?->" "...")
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"PHP operators for tree-sitter font-locking.")
|
|
|
|
|
|
|
|
|
|
(defconst php-ts-mode--predefined-constant
|
|
|
|
|
'(;; predefined constant
|
|
|
|
|
"PHP_VERSION" "PHP_MAJOR_VERSION" "PHP_MINOR_VERSION"
|
|
|
|
|
"PHP_RELEASE_VERSION" "PHP_VERSION_ID" "PHP_EXTRA_VERSION"
|
|
|
|
|
"ZEND_THREAD_SAFE" "ZEND_DEBUG_BUILD" "PHP_ZTS" "PHP_DEBUG"
|
|
|
|
|
"PHP_MAXPATHLEN" "PHP_OS" "PHP_OS_FAMILY" "PHP_SAPI" "PHP_EOL"
|
|
|
|
|
"PHP_INT_MAX" "PHP_INT_MIN" "PHP_INT_SIZE" "PHP_FLOAT_DIG"
|
|
|
|
|
"PHP_FLOAT_EPSILON" "PHP_FLOAT_MIN" "PHP_FLOAT_MAX"
|
|
|
|
|
"PHP_WINDOWS_EVENT_CTRL_C" "PHP_WINDOWS_EVENT_CTRL_BREAK"
|
|
|
|
|
"DEFAULT_INCLUDE_PATH" "PEAR_INSTALL_DIR" "PEAR_EXTENSION_DIR"
|
|
|
|
|
"PHP_EXTENSION_DIR" "PHP_PREFIX" "PHP_BINDIR" "PHP_BINARY"
|
|
|
|
|
"PHP_MANDIR" "PHP_LIBDIR" "PHP_DATADIR" "PHP_SYSCONFDIR"
|
|
|
|
|
"PHP_LOCALSTATEDIR" "PHP_CONFIG_FILE_PATH" "PHP_CONFIG_FILE_SCAN_DIR"
|
|
|
|
|
"PHP_SHLIB_SUFFIX" "PHP_FD_SETSIZE" "E_ERROR" "E_WARNING" "E_PARSE"
|
|
|
|
|
"E_NOTICE" "E_CORE_ERROR" "E_CORE_WARNING" "E_COMPILE_ERROR"
|
|
|
|
|
"E_COMPILE_WARNING" "E_USER_ERROR" "E_USER_WARNING"
|
2024-06-13 10:49:28 +02:00
|
|
|
|
"E_USER_NOTICE" "E_DEPRECATED" "E_USER_DEPRECATED"
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"E_ALL" "E_STRICT"
|
2024-08-24 23:16:09 +02:00
|
|
|
|
;; math constant
|
|
|
|
|
"M_PI" "M_E" "M_LOG2E" "M_LOG10E" "M_LN2" "M_LN10" "M_PI_2"
|
|
|
|
|
"M_PI_4" "M_1_PI" "M_2_PI" "M_SQRTPI" "M_2_SQRTPI" "M_SQRT2"
|
|
|
|
|
"M_SQRT3" "M_SQRT1_2" "M_LNPI" "M_EULER" "PHP_ROUND_HALF_UP"
|
|
|
|
|
"PHP_ROUND_HALF_DOWN" "PHP_ROUND_HALF_EVEN" "PHP_ROUND_HALF_ODD"
|
|
|
|
|
"NAN" "INF"
|
2024-06-07 12:39:03 +02:00
|
|
|
|
;; magic constant
|
|
|
|
|
"__COMPILER_HALT_OFFSET__" "__CLASS__" "__DIR__" "__FILE__"
|
|
|
|
|
"__FUNCTION__" "__LINE__" "__METHOD__" "__NAMESPACE__" "__TRAIT__")
|
|
|
|
|
"PHP predefined constant.")
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(defconst php-ts-mode--class-magic-methods
|
|
|
|
|
'("__construct" "__destruct" "__call" "__callStatic" "__get" "__set"
|
|
|
|
|
"__isset" "__unset" "__sleep" "__wakeup" "__serialize" "__unserialize"
|
|
|
|
|
"__toString" "__invoke" "__set_state" "__clone" "__debugInfo")
|
|
|
|
|
"PHP predefined magic methods.")
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--test-namespace-name-as-prefix-p ()
|
|
|
|
|
"Return t if namespace_name_as_prefix is a named node, nil otherwise."
|
2024-09-27 13:07:06 +02:00
|
|
|
|
(ignore-errors
|
|
|
|
|
(progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(defun php-ts-mode--test-namespace-aliasing-clause-p ()
|
|
|
|
|
"Return t if namespace_aliasing_clause is a named node, nil otherwise."
|
2024-09-27 13:07:06 +02:00
|
|
|
|
(ignore-errors
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(progn (treesit-query-compile 'php "(namespace_aliasing_clause)" t) t)))
|
2024-09-27 13:07:06 +02:00
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--test-namespace-use-group-clause-p ()
|
2024-10-10 16:06:37 +02:00
|
|
|
|
"Return t if namespace_use_group_clause is a named node, nil otherwise."
|
2024-09-27 13:07:06 +02:00
|
|
|
|
(ignore-errors
|
|
|
|
|
(progn (treesit-query-compile 'php "(namespace_use_group_clause)" t) t)))
|
|
|
|
|
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(defun php-ts-mode--test-visibility-modifier-operation-clause-p ()
|
|
|
|
|
"Return t if (visibility_modifier (operation)) is defined, nil otherwise."
|
|
|
|
|
(ignore-errors
|
|
|
|
|
(progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
|
|
|
|
|
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(defun php-ts-mode--font-lock-settings ()
|
|
|
|
|
"Tree-sitter font-lock settings."
|
|
|
|
|
(treesit-font-lock-rules
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'keyword
|
|
|
|
|
:override t
|
2024-10-10 16:06:37 +02:00
|
|
|
|
`([,@php-ts-mode--keywords] @font-lock-keyword-face
|
|
|
|
|
,@(when (php-ts-mode--test-visibility-modifier-operation-clause-p)
|
|
|
|
|
'((visibility_modifier (operation) @font-lock-builtin-face)))
|
|
|
|
|
(var_modifier) @font-lock-builtin-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'comment
|
|
|
|
|
:override t
|
|
|
|
|
'((comment) @font-lock-comment-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'constant
|
|
|
|
|
`((boolean) @font-lock-constant-face
|
|
|
|
|
(null) @font-lock-constant-face
|
2024-08-24 23:16:09 +02:00
|
|
|
|
;; predefined constant or built in constant (part of PHP core)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
((name) @font-lock-builtin-face
|
|
|
|
|
(:match ,(rx-to-string
|
|
|
|
|
`(: bos (or ,@php-ts-mode--predefined-constant) eos))
|
|
|
|
|
@font-lock-builtin-face))
|
|
|
|
|
;; user defined constant
|
|
|
|
|
((name) @font-lock-constant-face
|
2024-08-24 23:16:09 +02:00
|
|
|
|
(:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(const_declaration
|
|
|
|
|
(const_element (name) @font-lock-constant-face))
|
|
|
|
|
;; declare directive
|
|
|
|
|
(declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'name
|
2024-08-24 23:16:09 +02:00
|
|
|
|
'((goto_statement (name) @font-lock-constant-face)
|
|
|
|
|
(named_label_statement (name) @font-lock-constant-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'delimiter
|
|
|
|
|
`((["," ":" ";" "\\"]) @font-lock-delimiter-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'operator
|
2024-08-24 23:16:09 +02:00
|
|
|
|
`((error_suppression_expression "@" @font-lock-keyword-face)
|
|
|
|
|
[,@php-ts-mode--operators] @font-lock-operator-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'variable-name
|
|
|
|
|
:override t
|
2024-08-24 23:16:09 +02:00
|
|
|
|
'(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(variable_name (name) @font-lock-variable-name-face)
|
2024-08-24 23:16:09 +02:00
|
|
|
|
(relative_scope ["parent" "self" "static"] @font-lock-builtin-face)
|
|
|
|
|
(relative_scope) @font-lock-constant-face
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(dynamic_variable_name (name) @font-lock-variable-name-face)
|
|
|
|
|
(member_access_expression
|
|
|
|
|
name: (_) @font-lock-variable-name-face)
|
|
|
|
|
(scoped_property_access_expression
|
2024-08-24 23:16:09 +02:00
|
|
|
|
scope: (name) @font-lock-constant-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'string
|
|
|
|
|
`(("\"") @font-lock-string-face
|
|
|
|
|
(encapsed_string) @font-lock-string-face
|
|
|
|
|
(string_content) @font-lock-string-face
|
|
|
|
|
(string) @font-lock-string-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'literal
|
|
|
|
|
'((integer) @font-lock-number-face
|
|
|
|
|
(float) @font-lock-number-face
|
|
|
|
|
(heredoc identifier: (heredoc_start) @font-lock-constant-face)
|
|
|
|
|
(heredoc_body (string_content) @font-lock-string-face)
|
|
|
|
|
(heredoc end_tag: (heredoc_end) @font-lock-constant-face)
|
|
|
|
|
(nowdoc identifier: (heredoc_start) @font-lock-constant-face)
|
|
|
|
|
(nowdoc_body (nowdoc_string) @font-lock-string-face)
|
|
|
|
|
(nowdoc end_tag: (heredoc_end) @font-lock-constant-face)
|
|
|
|
|
(shell_command_expression) @font-lock-string-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'type
|
|
|
|
|
:override t
|
2024-08-24 23:16:09 +02:00
|
|
|
|
'((union_type "|" @font-lock-operator-face)
|
|
|
|
|
(union_type) @font-lock-type-face
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(bottom_type) @font-lock-type-face
|
|
|
|
|
(primitive_type) @font-lock-type-face
|
|
|
|
|
(cast_type) @font-lock-type-face
|
|
|
|
|
(named_type) @font-lock-type-face
|
|
|
|
|
(optional_type) @font-lock-type-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'definition
|
|
|
|
|
:override t
|
2024-09-27 13:07:06 +02:00
|
|
|
|
`((php_tag) @font-lock-preprocessor-face
|
2024-06-07 12:39:03 +02:00
|
|
|
|
("?>") @font-lock-preprocessor-face
|
|
|
|
|
;; Highlights identifiers in declarations.
|
|
|
|
|
(class_declaration
|
|
|
|
|
name: (_) @font-lock-type-face)
|
|
|
|
|
(class_interface_clause (name) @font-lock-type-face)
|
|
|
|
|
(interface_declaration
|
|
|
|
|
name: (_) @font-lock-type-face)
|
|
|
|
|
(trait_declaration
|
|
|
|
|
name: (_) @font-lock-type-face)
|
|
|
|
|
(enum_declaration
|
|
|
|
|
name: (_) @font-lock-type-face)
|
|
|
|
|
(function_definition
|
|
|
|
|
name: (_) @font-lock-function-name-face)
|
|
|
|
|
(method_declaration
|
|
|
|
|
name: (_) @font-lock-function-name-face)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(method_declaration
|
|
|
|
|
name: (name) @font-lock-builtin-face
|
|
|
|
|
(:match ,(rx-to-string
|
|
|
|
|
`(: bos (or ,@php-ts-mode--class-magic-methods) eos))
|
|
|
|
|
@font-lock-builtin-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
("=>") @font-lock-keyword-face
|
|
|
|
|
(object_creation_expression
|
|
|
|
|
(name) @font-lock-type-face)
|
2024-09-27 13:07:06 +02:00
|
|
|
|
,@(when (php-ts-mode--test-namespace-name-as-prefix-p)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
'((namespace_name_as_prefix "\\" @font-lock-delimiter-face)
|
|
|
|
|
(namespace_name_as_prefix
|
|
|
|
|
(namespace_name (name)) @font-lock-type-face)))
|
2024-09-27 13:07:06 +02:00
|
|
|
|
,@(if (php-ts-mode--test-namespace-aliasing-clause-p)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
'((namespace_aliasing_clause (name) @font-lock-type-face))
|
|
|
|
|
'((namespace_use_clause alias: (name) @font-lock-type-face)))
|
2024-09-27 13:07:06 +02:00
|
|
|
|
,@(when (not (php-ts-mode--test-namespace-use-group-clause-p))
|
2024-10-10 16:06:37 +02:00
|
|
|
|
'((namespace_use_group
|
|
|
|
|
(namespace_use_clause (name) @font-lock-type-face))))
|
2024-10-23 20:45:48 +02:00
|
|
|
|
(namespace_use_clause (name) @font-lock-type-face)
|
2024-08-24 23:16:09 +02:00
|
|
|
|
(namespace_name "\\" @font-lock-delimiter-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(namespace_name (name) @font-lock-type-face)
|
2024-10-10 16:06:37 +02:00
|
|
|
|
(use_declaration (name) @font-lock-property-use-face)
|
|
|
|
|
(use_instead_of_clause (name) @font-lock-type-face)
|
|
|
|
|
(binary_expression
|
|
|
|
|
operator: "instanceof"
|
|
|
|
|
right: (name) @font-lock-type-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'function-scope
|
|
|
|
|
:override t
|
2024-08-24 23:16:09 +02:00
|
|
|
|
'((scoped_call_expression
|
2024-06-07 12:39:03 +02:00
|
|
|
|
scope: (name) @font-lock-constant-face)
|
|
|
|
|
(class_constant_access_expression (name) @font-lock-constant-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'function-call
|
|
|
|
|
:override t
|
|
|
|
|
'((function_call_expression
|
|
|
|
|
function: (name) @font-lock-function-call-face)
|
|
|
|
|
(scoped_call_expression
|
2024-10-10 16:06:37 +02:00
|
|
|
|
name: (_) @font-lock-function-call-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(member_call_expression
|
2024-10-10 16:06:37 +02:00
|
|
|
|
name: (_) @font-lock-function-call-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(nullsafe_member_call_expression
|
2024-11-07 12:55:50 +01:00
|
|
|
|
name: (_) @font-lock-function-call-face))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'argument
|
|
|
|
|
'((argument
|
|
|
|
|
name: (_) @font-lock-constant-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'escape-sequence
|
|
|
|
|
:override t
|
|
|
|
|
'((string (escape_sequence) @font-lock-escape-face)
|
|
|
|
|
(encapsed_string (escape_sequence) @font-lock-escape-face)
|
|
|
|
|
(heredoc_body (escape_sequence) @font-lock-escape-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'base-clause
|
|
|
|
|
:override t
|
2024-09-27 13:07:06 +02:00
|
|
|
|
`((base_clause (name) @font-lock-type-face)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(use_as_clause (name) @font-lock-property-use-face)
|
2024-09-27 13:07:06 +02:00
|
|
|
|
,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p))
|
|
|
|
|
'((qualified_name prefix: "\\" @font-lock-delimiter-face)))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(qualified_name (name) @font-lock-constant-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'property
|
|
|
|
|
'((enum_case
|
|
|
|
|
name: (_) @font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'attribute
|
|
|
|
|
'((((attribute (_) @attribute_name) @font-lock-preprocessor-face)
|
|
|
|
|
(:equal "Deprecated" @attribute_name))
|
|
|
|
|
(attribute_group (attribute (name) @font-lock-constant-face)))
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'bracket
|
|
|
|
|
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
|
|
|
|
|
|
|
|
|
|
:language 'php
|
|
|
|
|
:feature 'error
|
|
|
|
|
:override t
|
|
|
|
|
'((ERROR) @php-ts-mode--fontify-error)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Font-lock helpers
|
|
|
|
|
|
|
|
|
|
(defconst php-ts-mode--custom-html-font-lock-settings
|
|
|
|
|
(treesit-font-lock-rules
|
|
|
|
|
:language 'html
|
|
|
|
|
:override t
|
|
|
|
|
:feature 'comment
|
|
|
|
|
`((comment) @font-lock-comment-face
|
|
|
|
|
;; handle shebang path and others type of comment
|
|
|
|
|
(document (text) @font-lock-comment-face))
|
|
|
|
|
|
|
|
|
|
:language 'html
|
|
|
|
|
:override t
|
|
|
|
|
:feature 'keyword
|
|
|
|
|
`("doctype" @font-lock-keyword-face)
|
|
|
|
|
|
|
|
|
|
:language 'html
|
|
|
|
|
:override t
|
|
|
|
|
:feature 'definition
|
|
|
|
|
`((tag_name) @font-lock-function-name-face)
|
|
|
|
|
|
|
|
|
|
:language 'html
|
|
|
|
|
:override 'append
|
|
|
|
|
:feature 'string
|
|
|
|
|
`((quoted_attribute_value) @font-lock-string-face)
|
|
|
|
|
|
|
|
|
|
:language 'html
|
|
|
|
|
:override t
|
|
|
|
|
:feature 'property
|
|
|
|
|
`((attribute_name) @font-lock-variable-name-face))
|
2024-06-25 10:37:40 +02:00
|
|
|
|
"Tree-sitter Font-lock settings for HTML when embedded in PHP.
|
|
|
|
|
Like `html-ts-mode--font-lock-settings' but adapted for `php-ts-mode'.")
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--phpdoc-font-lock-settings
|
|
|
|
|
(treesit-font-lock-rules
|
|
|
|
|
:language 'phpdoc
|
|
|
|
|
:feature 'document
|
|
|
|
|
:override t
|
|
|
|
|
'((document) @font-lock-doc-face)
|
|
|
|
|
|
|
|
|
|
:language 'phpdoc
|
|
|
|
|
:feature 'type
|
|
|
|
|
:override t
|
|
|
|
|
'((union_type
|
|
|
|
|
[(array_type) (primitive_type) (named_type) (optional_type)] @font-lock-type-face)
|
|
|
|
|
([(array_type) (primitive_type) (named_type) (optional_type)] @font-lock-type-face)
|
|
|
|
|
(fqsen (name) @font-lock-function-name-face))
|
|
|
|
|
|
|
|
|
|
:language 'phpdoc
|
|
|
|
|
:feature 'attribute
|
|
|
|
|
:override t
|
|
|
|
|
`((tag_name) @font-lock-constant-face
|
|
|
|
|
(uri) @font-lock-doc-markup-face
|
|
|
|
|
(tag
|
|
|
|
|
[(version) (email_address)] @font-lock-doc-markup-face)
|
|
|
|
|
(tag (author_name) @font-lock-property-name-face))
|
|
|
|
|
|
|
|
|
|
:language 'phpdoc
|
|
|
|
|
:feature 'variable
|
|
|
|
|
:override t
|
|
|
|
|
'((variable_name (name) @font-lock-variable-name-face)))
|
|
|
|
|
"Tree-sitter font-lock settings for phpdoc.")
|
|
|
|
|
|
2024-06-22 23:11:17 +02:00
|
|
|
|
(defun php-ts-mode--colorize-css-value (node override start end &rest _)
|
|
|
|
|
"Colorize CSS property value like `css--fontify-region'.
|
|
|
|
|
For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'."
|
|
|
|
|
(if (and php-ts-mode-css-fontify-colors
|
|
|
|
|
(string-equal "plain_value" (treesit-node-type node)))
|
|
|
|
|
(let ((color (css--compute-color start (treesit-node-text node t))))
|
|
|
|
|
(when color
|
|
|
|
|
(treesit-fontify-with-override
|
|
|
|
|
(treesit-node-start node) (treesit-node-end node)
|
|
|
|
|
(list 'face
|
|
|
|
|
(list :background color
|
|
|
|
|
:foreground (readable-foreground-color
|
|
|
|
|
color)
|
|
|
|
|
:box '(:line-width -1)))
|
|
|
|
|
override start end)))
|
|
|
|
|
(treesit-fontify-with-override
|
|
|
|
|
(treesit-node-start node) (treesit-node-end node)
|
|
|
|
|
'font-lock-variable-name-face
|
|
|
|
|
override start end)))
|
|
|
|
|
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(defun php-ts-mode--fontify-error (node override start end &rest _)
|
|
|
|
|
"Fontify the error nodes.
|
|
|
|
|
For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'."
|
|
|
|
|
(treesit-fontify-with-override
|
|
|
|
|
(treesit-node-start node) (treesit-node-end node)
|
|
|
|
|
'font-lock-warning-face
|
|
|
|
|
override start end))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--html-language-at-point (point)
|
|
|
|
|
"Return the language at POINT assuming the point is within a HTML region."
|
|
|
|
|
(let* ((node (treesit-node-at point 'html))
|
|
|
|
|
(parent (treesit-node-parent node))
|
|
|
|
|
(node-query (format "(%s (%s))"
|
|
|
|
|
(treesit-node-type parent)
|
|
|
|
|
(treesit-node-type node))))
|
|
|
|
|
(cond
|
|
|
|
|
((string-equal "(script_element (raw_text))" node-query) 'javascript)
|
|
|
|
|
((string-equal "(style_element (raw_text))" node-query) 'css)
|
|
|
|
|
(t 'html))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--language-at-point (point)
|
|
|
|
|
"Return the language at POINT."
|
|
|
|
|
(let* ((node (treesit-node-at point 'php))
|
|
|
|
|
(node-type (treesit-node-type node))
|
|
|
|
|
(parent (treesit-node-parent node))
|
|
|
|
|
(node-query (format "(%s (%s))" (treesit-node-type parent) node-type)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (treesit-node-start node))
|
|
|
|
|
(cond
|
|
|
|
|
((not (member node-query '("(program (text))"
|
|
|
|
|
"(text_interpolation (text))")))
|
|
|
|
|
'php)
|
|
|
|
|
(t (php-ts-mode--html-language-at-point point))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Imenu
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--parent-object (node)
|
|
|
|
|
"Return the name of the object that own NODE."
|
|
|
|
|
(treesit-parent-until
|
|
|
|
|
node
|
|
|
|
|
(lambda (n)
|
|
|
|
|
(member (treesit-node-type n)
|
|
|
|
|
'("class_declaration"
|
|
|
|
|
"enum_declaration"
|
|
|
|
|
"function_definition"
|
|
|
|
|
"interface_declaration"
|
|
|
|
|
"method_declaration"
|
|
|
|
|
"namespace_definition"
|
|
|
|
|
"trait_declaration")))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--defun-name-separator (node)
|
|
|
|
|
"Return a separator to connect object name, based on NODE type."
|
|
|
|
|
(let ((node-type (treesit-node-type node)))
|
|
|
|
|
(cond ((member node-type '("function_definition" "method_declaration"))
|
|
|
|
|
"()::")
|
|
|
|
|
((member node-type '("class_declaration" "enum_declaration" "trait_declaration"))
|
|
|
|
|
"::")
|
|
|
|
|
(t "\\"))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--defun-object-name (node node-text)
|
|
|
|
|
"Compose the full name of a NODE that is a PHP variable, method, class etc.
|
|
|
|
|
If the NODE has a parent, it recursively concat the parent names with NODE-TEXT,
|
|
|
|
|
otherwise it returns NODE-TEXT."
|
|
|
|
|
(let* ((parent-node (php-ts-mode--parent-object node))
|
|
|
|
|
(parent-node-text
|
|
|
|
|
(treesit-node-text
|
|
|
|
|
(treesit-node-child-by-field-name parent-node "name") t))
|
|
|
|
|
(parent-node-separator (php-ts-mode--defun-name-separator parent-node)))
|
|
|
|
|
(if parent-node
|
|
|
|
|
(progn
|
|
|
|
|
(setq parent-node-text
|
|
|
|
|
(php-ts-mode--defun-object-name
|
|
|
|
|
parent-node
|
|
|
|
|
parent-node-text))
|
|
|
|
|
(concat parent-node-text parent-node-separator node-text))
|
|
|
|
|
node-text)))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--defun-name (node)
|
|
|
|
|
"Return the defun name of NODE.
|
|
|
|
|
Return nil if the NODE has no field “name” or if NODE is not a defun node."
|
|
|
|
|
(let ((child (treesit-node-child-by-field-name node "name")))
|
|
|
|
|
(cl-case (intern (treesit-node-type node))
|
|
|
|
|
(class_declaration (treesit-node-text child t))
|
|
|
|
|
(trait_declaration (treesit-node-text child t))
|
|
|
|
|
(interface_declaration (treesit-node-text child t))
|
|
|
|
|
(namespace_definition (treesit-node-text child t))
|
|
|
|
|
(enum_declaration (treesit-node-text child t))
|
|
|
|
|
(function_definition (treesit-node-text child t))
|
|
|
|
|
(method_declaration
|
|
|
|
|
(php-ts-mode--defun-object-name node (treesit-node-text child t)))
|
|
|
|
|
(variable_name
|
|
|
|
|
(php-ts-mode--defun-object-name node (treesit-node-text node t)))
|
|
|
|
|
(const_element
|
|
|
|
|
(php-ts-mode--defun-object-name
|
|
|
|
|
node
|
|
|
|
|
(treesit-node-text (treesit-node-child node 0) t))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Defun navigation
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--indent-defun ()
|
|
|
|
|
"Indent the current top-level declaration syntactically.
|
|
|
|
|
`treesit-defun-type-regexp' defines what constructs to indent."
|
|
|
|
|
(interactive "*")
|
Mark if-let and when-let obsolete
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark
if-let and when-let obsolete (bug#73853 and elsewhere). Move
docstring text around so that if-let* and when-let* descriptions
no longer refer to if-let and when-let.
* etc/NEWS: Announce the change.
* admin/admin.el (reminder-for-release-blocking-bugs):
* doc/misc/erc.texi (display-buffer):
* lisp/ansi-color.el (ansi-color-apply)
(ansi-color--face-vec-face):
* lisp/ansi-osc.el (ansi-osc-apply-on-region)
(ansi-osc-hyperlink):
* lisp/arc-mode.el (archive-goto-file)
(archive-next-file-displayer):
* lisp/auth-source-pass.el (auth-source-pass-search)
(auth-source-pass--parse-data)
(auth-source-pass--find-match-many):
* lisp/autorevert.el (auto-revert-notify-rm-watch):
* lisp/buff-menu.el (Buffer-menu-unmark-all-buffers)
(Buffer-menu-group-by-root):
* lisp/calendar/parse-time.el (parse-iso8601-time-string):
* lisp/cedet/pulse.el (pulse-tick):
* lisp/comint.el (comint--fontify-input-ppss-flush-indirect)
(comint--intersect-regions):
* lisp/completion-preview.el (completion-preview--try-table)
(completion-preview--capf-wrapper, completion-preview--update):
* lisp/cus-edit.el (setopt--set)
(custom-dirlocals-maybe-update-cons, custom-dirlocals-validate):
* lisp/custom.el (load-theme):
* lisp/descr-text.el (describe-char):
* lisp/desktop.el (desktop--emacs-pid-running-p):
* lisp/dired-x.el (menu):
* lisp/dired.el (dired-font-lock-keywords)
(dired-insert-directory, dired--insert-disk-space, dired-mode):
* lisp/dnd.el (dnd-handle-multiple-urls):
* lisp/dom.el (dom-remove-attribute):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare):
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec):
* lisp/emacs-lisp/comp-cstr.el (comp--all-classes)
(comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem)
(comp-cstr-intersection-no-mem, comp-cstr-fixnum-p)
(comp-cstr-type-p):
* lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install)
(native--compile-async):
* lisp/emacs-lisp/comp.el (comp--get-function-cstr)
(comp--function-pure-p, comp--intern-func-in-ctxt)
(comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar)
(comp--add-call-cstr, comp--compute-dominator-tree)
(comp--dom-tree-walker, comp--ssa-rename)
(comp--function-call-maybe-fold, comp--fwprop-call)
(comp--call-optim-func):
* lisp/emacs-lisp/edebug.el (edebug-global-prefix)
(edebug-remove-instrumentation):
* lisp/emacs-lisp/eieio.el (initialize-instance):
* lisp/emacs-lisp/ert-x.el (ert-resource-directory):
* lisp/emacs-lisp/ert.el (ert--expand-should-1)
(ert-test-location, ert-write-junit-test-report)
(ert-test--erts-test):
* lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string)
(icons--create):
* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p):
* lisp/emacs-lisp/loaddefs-gen.el
(loaddefs-generate--make-autoload)
(loaddefs-generate--parse-file):
* lisp/emacs-lisp/multisession.el
(multisession-edit-mode--revert, multisession-edit-value):
* lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data)
(package-vc--version, package-vc--clone):
* lisp/emacs-lisp/package.el (package--reload-previously-loaded):
* lisp/emacs-lisp/pp.el (pp--insert-lisp):
* lisp/emacs-lisp/subr-x.el (add-display-text-property):
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-print):
* lisp/emacs-lisp/timer.el (run-at-time):
* lisp/emacs-lisp/vtable.el (vtable-goto-table)
(vtable-goto-column, vtable-update-object, vtable--insert-line)
(vtable--compute-widths, vtable--make-keymap):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/epa-file.el (epa-file-insert-file-contents):
* lisp/epa.el (epa-show-key):
* lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt)
(PRIVMSG, erc--get-isupport-entry):
* lisp/erc/erc-button.el (erc-button-add-nickname-buttons)
(erc--button-next):
* lisp/erc/erc-common.el (erc--find-group):
* lisp/erc/erc-fill.el (erc-fill, erc-fill-static)
(erc-fill--wrap-escape-hidden-speaker)
(erc-fill--wrap-unmerge-on-date-stamp)
(erc-fill--wrap-massage-initial-message-post-clear)
(erc-fill-wrap, erc-fill--wrap-rejigger-region):
* lisp/erc/erc-goodies.el (erc--scrolltobottom-all)
(erc--keep-place-indicator-on-window-buffer-change)
(keep-place-indicator, erc--keep-place-indicator-adjust-on-clear)
(erc-keep-place-move, erc--command-indicator-display):
* lisp/erc/erc-ibuffer.el (erc-members):
* lisp/erc/erc-join.el (erc-join--remove-requested-channel)
(erc-autojoin--join):
* lisp/erc/erc-networks.el
(erc-networks--id-qualifying-init-parts, erc-networks--id-reload)
(erc-networks--id-ensure-comparable)
(erc-networks--reclaim-orphaned-target-buffers)
(erc-networks--server-select):
* lisp/erc/erc-nicks.el (erc-nicks-invert)
(erc-nicks--redirect-face-widget-link, erc-nicks--highlight)
(erc-nicks--highlight-button)
(erc-nicks--list-faces-help-button-action, erc-nicks-list-faces)
(erc-nicks-refresh, erc-nicks--colors-from-faces)
(erc-nicks--track-prioritize)
(erc-nicks--remember-face-for-track):
* lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next)
(erc--querypoll-on-352, erc--querypoll-send):
* lisp/erc/erc-sasl.el (erc-sasl--read-password):
* lisp/erc/erc-services.el
(erc-services-issue-ghost-and-retry-nick):
* lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar)
(erc-speedbar-toggle-nicknames-window-lock)
(erc-speedbar--compose-nicks-face):
* lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect)
(erc-stamp-prefix-log-filter, erc--conceal-prompt)
(erc--insert-timestamp-left, erc-insert-timestamp-right)
(erc-stamp--defer-date-insertion-on-post-modify)
(erc-insert-timestamp-left-and-right)
(erc-stamp--redo-right-stamp-post-clear)
(erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps):
* lisp/erc/erc-status-sidebar.el (bufbar)
(erc-status-sidebar-prefer-target-as-name)
(erc-status-sidebar-default-allsort, erc-status-sidebar-click):
* lisp/erc/erc-track.el (erc-track--shortened-names-get)
(erc-track--setup, erc-track--select-mode-line-face)
(erc-track-modified-channels, erc-track--collect-faces-in)
(erc-track--switch-buffer, erc-track--replace-killed-buffer):
* lisp/erc/erc-truncate.el (erc-truncate--setup)
(erc-truncate-buffer):
* lisp/erc/erc.el (erc--ensure-query-member)
(erc--ensure-query-members, erc--remove-channel-users-but)
(erc--cusr-change-status, erc--find-mode, erc--update-modules)
(erc-log-irc-protocol, erc--refresh-prompt)
(erc--restore-important-text-props)
(erc--order-text-properties-from-hash, erc-send-input-line)
(erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY)
(erc-cmd-BANLIST, erc--speakerize-nick)
(erc--format-speaker-input-message, erc-channel-receive-names)
(erc-send-current-line, erc-format-target-and/or-network)
(erc-kill-buffer-function, erc-restore-text-properties)
(erc--get-eq-comparable-cmd):
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which)
(eshell-maybe-replace-by-alias):
* lisp/eshell/em-glob.el (eshell-glob-convert):
* lisp/eshell/em-pred.el (eshell-pred-user-or-group)
(eshell-pred-file-time, eshell-pred-file-type)
(eshell-pred-file-mode, eshell-pred-file-links)
(eshell-pred-file-size):
* lisp/eshell/em-prompt.el (eshell-forward-paragraph)
(eshell-next-prompt):
* lisp/eshell/esh-arg.el (eshell-resolve-current-argument):
* lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which)
(eshell-plain-command--which, eshell-plain-command):
* lisp/eshell/esh-io.el (eshell-duplicate-handles)
(eshell-protect-handles, eshell-get-target, eshell-close-target):
* lisp/eshell/esh-proc.el (eshell-sentinel):
* lisp/eshell/esh-var.el (eshell-parse-variable-ref)
(eshell-get-variable, eshell-set-variable):
* lisp/faces.el (face-at-point):
* lisp/ffap.el (ffap-in-project):
* lisp/filenotify.el (file-notify--rm-descriptor):
* lisp/files-x.el (read-dir-locals-file)
(connection-local-update-profile-variables)
(connection-local-value):
* lisp/files.el (file-remote-p, abbreviate-file-name)
(set-auto-mode, hack-local-variables)
(revert-buffer-restore-read-only):
* lisp/find-dired.el (find-dired-sort-by-filename):
* lisp/font-lock.el (font-lock--filter-keywords):
* lisp/gnus/gnus-art.el (article-emojize-symbols):
* lisp/gnus/gnus-int.el (gnus-close-server):
* lisp/gnus/gnus-search.el (gnus-search-transform)
(gnus-search-indexed-parse-output, gnus-search-server-to-engine):
* lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url):
* lisp/gnus/gnus.el (gnus-check-backend-function):
* lisp/gnus/message.el (message-send-mail):
* lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers):
* lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article)
(nnatom--read-article-or-group-authors, nnatom--read-publish)
(nnatom--read-update, nnatom--read-links):
* lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server)
(nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article)
(nnfeed-retrieve-headers, nnfeed--print-part)
(nnfeed-request-article, nnfeed-request-group)
(nnfeed-request-list, nnfeed--group-description)
(nnfeed-request-group-description)
(nnfeed-request-list-newsgroups, nnfeed-request-rename-group):
* lisp/gnus/nnmh.el (nnmh-update-gnus-unreads):
* lisp/help-fns.el (help-find-source)
(help-fns--insert-menu-bindings, help-fns--mention-first-release)
(help-fns--mention-shortdoc-groups)
(help-fns--customize-variable-version)
(help-fns--face-custom-version-info, describe-mode):
* lisp/help-mode.el (help-make-xrefs):
* lisp/help.el (help-key-description, help--describe-command):
* lisp/hfy-cmap.el (htmlfontify-load-rgb-file):
* lisp/ibuf-ext.el (ibuffer-jump-to-filter-group)
(ibuffer-kill-filter-group, ibuffer-kill-line)
(ibuffer-save-filter-groups, ibuffer-save-filters, filename)
(basename, file-extension, ibuffer-diff-buffer-with-file-1)
(ibuffer-mark-by-file-name-regexp)
(ibuffer-mark-by-content-regexp):
* lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen):
* lisp/ibuffer.el (ibuffer-mouse-toggle-mark)
(ibuffer-toggle-marks, ibuffer-mark-interactive)
(ibuffer-compile-format, process, ibuffer-map-lines):
* lisp/image.el (image--compute-map)
(image--compute-original-map):
* lisp/image/exif.el (exif-parse-buffer):
* lisp/image/image-converter.el (image-convert-p, image-convert)
(image-converter--find-converter):
* lisp/image/image-dired-util.el
(image-dired-file-name-at-point):
* lisp/image/image-dired.el (image-dired-track-original-file)
(image-dired--on-file-in-dired-buffer)
(image-dired--with-thumbnail-buffer)
(image-dired-jump-original-dired-buffer)
(image-dired--slideshow-step, image-dired-display-image):
* lisp/image/wallpaper.el (wallpaper--init-action-kill)
(wallpaper--find-setter, wallpaper--find-command)
(wallpaper--find-command-args, wallpaper--x-monitor-name):
* lisp/info-look.el (info-lookup-interactive-arguments)
(info-complete)::(:mode):
* lisp/info.el (info-pop-to-buffer, Info-read-node-name-1):
* lisp/international/emoji.el (emoji--adjust-displayable-1)
(emoji--add-recent):
* lisp/jsonrpc.el (jsonrpc--call-deferred)
(jsonrpc--process-sentinel, jsonrpc--remove):
* lisp/keymap.el (keymap-local-lookup):
* lisp/mail/emacsbug.el (report-emacs-bug-hook)
(submit-emacs-patch):
* lisp/mail/ietf-drums.el (ietf-drums-parse-addresses):
* lisp/mail/mailclient.el (mailclient-send-it):
* lisp/mail/rfc6068.el (rfc6068-parse-mailto-url):
* lisp/mail/undigest.el (rmail-digest-parse-mixed-mime):
* lisp/minibuffer.el (completion-metadata-get)
(completions--after-change)
(minibuffer-visible-completions--filter):
* lisp/net/browse-url.el (browse-url-url-at-point)
(browse-url-file-url, browse-url-emacs):
* lisp/net/dbus.el (dbus-byte-array-to-string)
(dbus-monitor-goto-serial):
* lisp/net/dictionary.el (dictionary-search):
* lisp/net/eww.el (eww--download-directory)
(eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit)
(eww-follow-link, eww-read-alternate-url)
(eww-copy-alternate-url):
* lisp/net/goto-addr.el (goto-address-at-point):
* lisp/net/mailcap.el (mailcap-mime-info):
* lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string)
(rcirc-kill-buffer-hook, rcirc-print, rcirc-when)
(rcirc-color-attributes, rcirc-handler-NICK)
(rcirc-handler-TAGMSG, rcirc-handler-BATCH):
* lisp/net/shr.el (shr-descend, shr-adaptive-fill-function)
(shr-correct-dom-case, shr-tag-a):
* lisp/net/sieve.el (sieve-manage-quit):
* lisp/outline.el (outline-cycle-buffer):
* lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate):
* lisp/proced.el (proced-auto-update-timer):
* lisp/progmodes/bug-reference.el
(bug-reference-try-setup-from-vc):
* lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph):
* lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset)
(c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun):
* lisp/progmodes/compile.el (compilation-error-properties)
(compilation-find-file-1):
* lisp/progmodes/eglot.el (eglot--check-object)
(eglot--read-server, eglot-upgrade-eglot)
(eglot-handle-notification, eglot--CompletionParams)
(eglot-completion-at-point, eglot--sig-info)
(eglot-register-capability):
* lisp/progmodes/elisp-mode.el
(emacs-lisp-native-compile-and-load)
(elisp-eldoc-var-docstring-with-value):
* lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test):
* lisp/progmodes/flymake.el (flymake--update-eol-overlays)
(flymake-eldoc-function):
* lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom)
(gdb-frame-handler):
* lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring)
(go-ts-mode--comment-on-previous-line-p)
(go-ts-mode--get-test-regexp-at-point)
(go-ts-mode-test-this-file):
* lisp/progmodes/grep.el (lgrep, rgrep-default-command)
(grep-file-at-point):
* lisp/progmodes/perl-mode.el (perl--end-of-format-p):
* lisp/progmodes/php-ts-mode.el
(php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun):
* lisp/progmodes/project.el (project--other-place-command)
(project--find-default-from, project--transplant-file-name)
(project-prefixed-buffer-name, project--remove-from-project-list)
(project-prompt-project-name, project-remember-projects-under)
(project--switch-project-command)
(project-uniquify-dirname-transform, project-mode-line-format):
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration)
(python--treesit-fontify-union-types)
(python-shell-get-process-name, python-shell-restart)
(python-shell-completion-at-point, python-ffap-module-path)
(python-util-comint-end-of-output-p, python--import-sources)
(python-add-import, python-remove-import, python-fix-imports):
* lisp/progmodes/xref.el (xref--add-log-current-defun):
* lisp/repeat.el (repeat-echo-message-string):
* lisp/saveplace.el (save-place-dired-hook):
* lisp/server.el (server-save-buffers-kill-terminal):
* lisp/shadowfile.el (shadow-make-fullname)
(shadow-contract-file-name, shadow-define-literal-group):
* lisp/shell.el (shell-highlight-undef-mode):
* lisp/simple.el (command-completion-using-modes-p)
(command-execute, file-user-uid, file-group-gid)
(first-completion, last-completion, switch-to-completions):
* lisp/startup.el (startup--load-user-init-file):
* lisp/tab-line.el (tab-line-tabs-buffer-group-by-project):
* lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer):
* lisp/term/android-win.el (android-encode-select-string)
(gui-backend-set-selection):
* lisp/term/haiku-win.el (haiku-dnd-convert-string)
(haiku-select-encode-xstring, haiku-select-encode-utf-8-string):
* lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize):
* lisp/textmodes/ispell.el (ispell-completion-at-point):
* lisp/textmodes/sgml-mode.el (sgml-validate)
(html-mode--complete-at-point):
* lisp/textmodes/tex-mode.el (tex-recenter-output-buffer)
(xref-backend-references):
* lisp/thingatpt.el (thing-at-point-file-at-point)
(thing-at-point-face-at-point):
* lisp/thread.el (thread-list--get-status):
* lisp/time.el (world-clock-copy-time-as-kill, world-clock):
* lisp/touch-screen.el (touch-screen-handle-touch):
* lisp/treesit.el (treesit-language-at, treesit-node-at)
(treesit-node-on, treesit-buffer-root-node)
(treesit-node-field-name, treesit-local-parsers-at)
(treesit-local-parsers-on, treesit--cleanup-local-range-overlays)
(treesit-font-lock-recompute-features)
(treesit-font-lock-fontify-region, treesit-transpose-sexps)
(treesit-add-log-current-defun, treesit-major-mode-setup)
(treesit--explorer-refresh, treesit-install-language-grammar):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/vc/smerge-mode.el (smerge-diff):
* lisp/vc/vc-dir.el (vc-dir):
* lisp/vc/vc-dispatcher.el (vc-do-async-command):
* lisp/vc/vc-git.el (vc-git-dir--branch-headers)
(vc-git-dir--stash-headers, vc-git--log-edit-summary-check)
(vc-git-stash-list):
* lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset)
(vc-clone):
* lisp/visual-wrap.el (visual-wrap--apply-to-line):
* lisp/wid-edit.el (widget-text)
(widget-editable-list-insert-before):
* lisp/window-tool-bar.el
(window-tool-bar--keymap-entry-to-string):
* lisp/window.el (display-buffer, display-buffer-full-frame)
(window-point-context-set, window-point-context-use)
(window-point-context-use-default-function):
* lisp/xdg.el (xdg-current-desktop):
* lisp/xwidget.el (xwidget-webkit-callback):
* lisp/yank-media.el (yank-media--get-selection)
(yank-media-types):
* test/lisp/comint-tests.el
(comint-tests/test-password-function):
* test/lisp/completion-preview-tests.el
(completion-preview-tests--capf):
* test/lisp/cus-edit-tests.el (with-cus-edit-test):
* test/lisp/erc/erc-scenarios-base-local-modules.el
(-phony-sblm-):
* test/lisp/erc/erc-scenarios-stamp.el
(erc-scenarios-stamp--on-post-modify):
* test/lisp/erc/erc-services-tests.el
(erc-services-tests--asp-parse-entry):
* test/lisp/erc/erc-tests.el (erc-modules--internal-property)
(erc--find-mode, erc-tests--update-modules):
* test/lisp/erc/resources/erc-d/erc-d-i.el
(erc-d-i--parse-message):
* test/lisp/erc/resources/erc-d/erc-d-t.el
(erc-d-t-kill-related-buffers, erc-d-t-with-cleanup):
* test/lisp/erc/resources/erc-d/erc-d-tests.el
(erc-d-i--parse-message--irc-parser-tests):
* test/lisp/erc/resources/erc-d/erc-d-u.el
(erc-d-u--read-exchange-slowly):
* test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire)
(erc-d--finalize-done, erc-d--command-handle-all):
* test/lisp/erc/resources/erc-scenarios-common.el
(erc-scenarios-common-with-cleanup):
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests--common-display-message)
(erc-tests-common-create-subprocess):
* test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058):
* test/lisp/international/mule-tests.el
(mule-cmds-tests--ucs-names-missing-names):
* test/lisp/progmodes/python-tests.el
(python-tests-get-shell-interpreter)
(python-tests--get-interpreter-info):
* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-resource-file):
* test/lisp/replace-tests.el (replace-tests-with-undo):
* test/src/emacs-tests.el (emacs-tests--seccomp-debug):
* test/src/process-tests.el (process-tests--emacs-command)
(process-tests--emacs-binary, process-tests--dump-file):
* test/src/treesit-tests.el (treesit--ert-test-defun-navigation):
Replace use of the now-obsolete if-let and when-let.
2024-10-24 16:50:07 +08:00
|
|
|
|
(when-let* ((orig-point (point-marker))
|
|
|
|
|
(node (treesit-defun-at-point)))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(indent-region (treesit-node-start node)
|
|
|
|
|
(treesit-node-end node))
|
|
|
|
|
(goto-char orig-point)))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--defun-valid-p (node)
|
|
|
|
|
"Return non-nil if NODE is a valid defun node.
|
|
|
|
|
Ie, NODE is not nested."
|
|
|
|
|
(not (and (member (treesit-node-type node)
|
|
|
|
|
'("variable_name"
|
|
|
|
|
"const_element"
|
|
|
|
|
"enum_declaration"
|
|
|
|
|
"union_declaration"
|
|
|
|
|
"declaration"))
|
|
|
|
|
;; If NODE's type is one of the above, make sure it is
|
|
|
|
|
;; top-level.
|
|
|
|
|
(treesit-node-top-level
|
|
|
|
|
node (rx (or "variable_name"
|
|
|
|
|
"const_element"
|
|
|
|
|
"function_definition"
|
|
|
|
|
"enum_declaration"
|
|
|
|
|
"union_declaration"
|
|
|
|
|
"declaration"))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Filling
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--comment-indent-new-line (&optional soft)
|
|
|
|
|
"Break line at point and indent, continuing comment if within one.
|
|
|
|
|
Like `c-ts-common-comment-indent-new-line', but handle the
|
|
|
|
|
less common PHP-style # comment. SOFT works the same as in
|
|
|
|
|
`comment-indent-new-line'."
|
|
|
|
|
(if (save-excursion
|
|
|
|
|
;; Line start with # or ## or ###...
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(rx "#" (group (* (any "#")) (* " ")))
|
|
|
|
|
(line-end-position)
|
|
|
|
|
t nil))
|
|
|
|
|
(let ((offset (- (match-beginning 0) (line-beginning-position)))
|
2024-11-07 12:55:50 +01:00
|
|
|
|
(comment-prefix (match-string 0))
|
|
|
|
|
(insert-line-break
|
|
|
|
|
(lambda ()
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(if soft
|
|
|
|
|
(insert-and-inherit ?\n)
|
|
|
|
|
(newline 1)))))
|
|
|
|
|
(funcall insert-line-break)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(delete-region (line-beginning-position) (point))
|
|
|
|
|
(insert
|
|
|
|
|
(make-string offset ?\s)
|
|
|
|
|
comment-prefix))
|
|
|
|
|
;; other style of comments
|
|
|
|
|
(c-ts-common-comment-indent-new-line soft)))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-comment-setup ()
|
|
|
|
|
"Set up local variables for PHP comment.
|
|
|
|
|
Depends on `c-ts-common-comment-setup'."
|
|
|
|
|
(c-ts-common-comment-setup)
|
|
|
|
|
(setq-local c-ts-common--comment-regexp "comment"
|
|
|
|
|
comment-line-break-function #'php-ts-mode--comment-indent-new-line
|
|
|
|
|
comment-style 'extra-line
|
|
|
|
|
comment-start-skip (rx (or (seq "#" (not (any "[")))
|
|
|
|
|
(seq "/" (+ "/"))
|
|
|
|
|
(seq "/" (+ "*")))
|
|
|
|
|
(* (syntax whitespace)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Modes
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-set-comment-style ()
|
|
|
|
|
"Set a different comment style."
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq-local comment-start
|
|
|
|
|
(completing-read
|
|
|
|
|
"Choose comment style: "
|
|
|
|
|
'("/**" "//" "/*" "#") nil t nil nil "// "))
|
|
|
|
|
(cond
|
|
|
|
|
((equal comment-start "/*") (setq-local comment-end "*/"))
|
|
|
|
|
((equal comment-start "//") (setq-local comment-end ""))
|
|
|
|
|
((equal comment-start "#") (setq-local comment-end ""))
|
|
|
|
|
((equal comment-start "/**") (setq-local comment-end "*/"))))
|
|
|
|
|
|
|
|
|
|
(defvar-keymap php-ts-mode-map
|
|
|
|
|
:doc "Keymap for `php-ts-mode' buffers."
|
|
|
|
|
:parent prog-mode-map
|
|
|
|
|
"C-c C-q" #'php-ts-mode--indent-defun
|
|
|
|
|
"C-c ." #'php-ts-mode-set-style
|
|
|
|
|
"C-c C-k" #'php-ts-mode-set-comment-style
|
|
|
|
|
"C-c C-n" #'run-php
|
|
|
|
|
"C-c C-c" #'php-ts-mode-send-buffer
|
|
|
|
|
"C-c C-l" #'php-ts-mode-send-file
|
|
|
|
|
"C-c C-r" #'php-ts-mode-send-region)
|
|
|
|
|
|
|
|
|
|
(easy-menu-define php-ts-mode-menu php-ts-mode-map
|
|
|
|
|
"Menu bar entry for `php-ts-mode'."
|
|
|
|
|
`("PHP"
|
|
|
|
|
["Comment Out Region" comment-region
|
|
|
|
|
:enable mark-active
|
|
|
|
|
:help "Comment out the region between the mark and point"]
|
|
|
|
|
["Uncomment Region" (comment-region (region-beginning)
|
|
|
|
|
(region-end) '(4))
|
|
|
|
|
:enable mark-active
|
|
|
|
|
:help "Uncomment the region between the mark and point"]
|
|
|
|
|
["Indent Top-level Expression" php-ts-mode--indent-defun
|
|
|
|
|
:help "Indent/reindent top-level function, class, etc."]
|
|
|
|
|
["Indent Line or Region" indent-for-tab-command
|
|
|
|
|
:help "Indent current line or region, or insert a tab"]
|
|
|
|
|
["Forward Expression" forward-sexp
|
|
|
|
|
:help "Move forward across one balanced expression"]
|
|
|
|
|
["Backward Expression" backward-sexp
|
|
|
|
|
:help "Move back across one balanced expression"]
|
|
|
|
|
("Style..."
|
|
|
|
|
["Set Indentation Style..." php-ts-mode-set-style
|
|
|
|
|
:help "Set PHP indentation style for current buffer"]
|
|
|
|
|
["Show Current Style Name"(message "Indentation Style: %s"
|
|
|
|
|
php-ts-mode-indent-style)
|
|
|
|
|
:help "Show the name of the PHP indentation style for current buffer"]
|
|
|
|
|
["Set Comment Style" php-ts-mode-set-comment-style
|
|
|
|
|
:help "Choose PHP comment style between block and line comments"])
|
|
|
|
|
"--"
|
|
|
|
|
["Start interpreter" run-php
|
|
|
|
|
:help "Run inferior PHP process in a separate buffer"]
|
|
|
|
|
["Show interpreter buffer" php-ts-mode-show-process-buffer]
|
|
|
|
|
["Hide interpreter buffer" php-ts-mode-hide-process-buffer]
|
|
|
|
|
["Kill interpreter process" php-ts-mode-kill-process]
|
|
|
|
|
["Evaluate buffer" php-ts-mode-send-buffer]
|
|
|
|
|
["Evaluate file" php-ts-mode-send-file]
|
|
|
|
|
["Evaluate region" php-ts-mode-send-region]
|
|
|
|
|
"--"
|
|
|
|
|
["Start built-in webserver" php-ts-mode-run-php-webserver
|
|
|
|
|
:help "Run the built-in PHP webserver"]
|
|
|
|
|
"--"
|
2024-06-22 22:36:54 +02:00
|
|
|
|
["Customize" (lambda () (interactive) (customize-group "php-ts-mode"))]))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--feature-list
|
|
|
|
|
'((;; common
|
|
|
|
|
comment definition spell
|
|
|
|
|
;; CSS specific
|
|
|
|
|
query selector
|
|
|
|
|
;; HTML specific
|
|
|
|
|
text
|
|
|
|
|
;; PHPDOC specific
|
|
|
|
|
document
|
|
|
|
|
phpdoc-error)
|
|
|
|
|
(keyword string type name)
|
|
|
|
|
(;; common
|
|
|
|
|
attribute assignment constant escape-sequence function-scope
|
|
|
|
|
base-clause literal variable-name variable
|
|
|
|
|
;; Javascript specific
|
|
|
|
|
jsx number pattern string-interpolation)
|
|
|
|
|
(;; common
|
|
|
|
|
argument bracket delimiter error function-call operator property
|
|
|
|
|
;; Javascript specific
|
|
|
|
|
function)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-derived-mode php-ts-mode prog-mode "PHP"
|
|
|
|
|
"Major mode for editing PHP, powered by tree-sitter."
|
|
|
|
|
:syntax-table php-ts-mode--syntax-table
|
|
|
|
|
|
|
|
|
|
(if (not (and
|
|
|
|
|
(treesit-ready-p 'php)
|
|
|
|
|
(treesit-ready-p 'phpdoc)
|
|
|
|
|
(treesit-ready-p 'html)
|
|
|
|
|
(treesit-ready-p 'javascript)
|
2024-06-25 11:29:54 +02:00
|
|
|
|
(treesit-ready-p 'jsdoc)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(treesit-ready-p 'css)))
|
|
|
|
|
(error "Tree-sitter for PHP isn't
|
|
|
|
|
available. You can install the parsers with M-x
|
|
|
|
|
`php-ts-mode-install-parsers'")
|
|
|
|
|
|
|
|
|
|
;; Require html-ts-mode only when we load php-ts-mode
|
|
|
|
|
;; so that we don't get a tree-sitter compilation warning for
|
|
|
|
|
;; php-ts-mode.
|
|
|
|
|
(defvar html-ts-mode--indent-rules)
|
|
|
|
|
(require 'html-ts-mode)
|
|
|
|
|
;; For embed html
|
|
|
|
|
|
2024-06-16 21:59:42 +02:00
|
|
|
|
;; phpdoc is a local parser, don't create a parser for it
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(treesit-parser-create 'html)
|
|
|
|
|
(treesit-parser-create 'css)
|
|
|
|
|
(treesit-parser-create 'javascript)
|
|
|
|
|
|
|
|
|
|
;; define the injected parser ranges
|
|
|
|
|
(setq-local treesit-range-settings
|
|
|
|
|
(treesit-range-rules
|
|
|
|
|
:embed 'phpdoc
|
|
|
|
|
:host 'php
|
|
|
|
|
:local t
|
|
|
|
|
'(((comment) @cap
|
|
|
|
|
(:match "/\\*\\*" @cap)))
|
|
|
|
|
|
|
|
|
|
:embed 'html
|
|
|
|
|
:host 'php
|
|
|
|
|
'((program (text) @cap)
|
|
|
|
|
(text_interpolation (text) @cap))
|
|
|
|
|
|
|
|
|
|
:embed 'javascript
|
|
|
|
|
:host 'html
|
|
|
|
|
:offset '(1 . -1)
|
|
|
|
|
'((script_element
|
|
|
|
|
(start_tag (tag_name))
|
|
|
|
|
(raw_text) @cap))
|
|
|
|
|
|
2024-06-25 11:29:54 +02:00
|
|
|
|
:embed 'jsdoc
|
|
|
|
|
:host 'javascript
|
|
|
|
|
:local t
|
|
|
|
|
`(((comment) @cap
|
|
|
|
|
(:match ,js--treesit-jsdoc-beginning-regexp @cap)))
|
|
|
|
|
|
2024-06-07 12:39:03 +02:00
|
|
|
|
:embed 'css
|
|
|
|
|
:host 'html
|
|
|
|
|
:offset '(1 . -1)
|
|
|
|
|
'((style_element
|
|
|
|
|
(start_tag (tag_name))
|
|
|
|
|
(raw_text) @cap))))
|
|
|
|
|
|
|
|
|
|
(setq-local treesit-language-at-point-function #'php-ts-mode--language-at-point)
|
|
|
|
|
|
|
|
|
|
;; Navigation.
|
|
|
|
|
(setq-local treesit-defun-type-regexp
|
|
|
|
|
(regexp-opt '("class_declaration"
|
|
|
|
|
"enum_declaration"
|
|
|
|
|
"function_definition"
|
|
|
|
|
"interface_declaration"
|
|
|
|
|
"method_declaration"
|
|
|
|
|
"namespace_definition"
|
|
|
|
|
"trait_declaration")))
|
|
|
|
|
|
|
|
|
|
(setq-local treesit-defun-name-function #'php-ts-mode--defun-name)
|
|
|
|
|
|
|
|
|
|
(setq-local treesit-thing-settings
|
|
|
|
|
`((php
|
|
|
|
|
(defun ,treesit-defun-type-regexp)
|
|
|
|
|
(sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
|
|
|
|
|
(sentence ,(regexp-opt
|
|
|
|
|
'("break_statement"
|
|
|
|
|
"case_statement"
|
|
|
|
|
"continue_statement"
|
|
|
|
|
"declaration"
|
|
|
|
|
"default_statement"
|
|
|
|
|
"do_statement"
|
|
|
|
|
"expression_statement"
|
|
|
|
|
"for_statement"
|
|
|
|
|
"if_statement"
|
|
|
|
|
"return_statement"
|
|
|
|
|
"switch_statement"
|
|
|
|
|
"while_statement"
|
|
|
|
|
"statement")))
|
|
|
|
|
(text ,(regexp-opt '("comment" "text"))))))
|
|
|
|
|
|
|
|
|
|
;; Nodes like struct/enum/union_specifier can appear in
|
|
|
|
|
;; function_definitions, so we need to find the top-level node.
|
|
|
|
|
(setq-local treesit-defun-prefer-top-level t)
|
|
|
|
|
|
|
|
|
|
;; Indent.
|
|
|
|
|
(when (eq php-ts-mode-indent-style 'wordpress)
|
|
|
|
|
(setq-local indent-tabs-mode t))
|
|
|
|
|
|
|
|
|
|
(setq-local c-ts-common-indent-offset 'php-ts-mode-indent-offset)
|
|
|
|
|
(setq-local treesit-simple-indent-rules (php-ts-mode--get-indent-style))
|
|
|
|
|
(setq-local treesit-simple-indent-rules
|
|
|
|
|
(append treesit-simple-indent-rules
|
|
|
|
|
php-ts-mode--phpdoc-indent-rules
|
|
|
|
|
html-ts-mode--indent-rules
|
|
|
|
|
;; Extended rules for js and css, to
|
|
|
|
|
;; indent appropriately when injected
|
|
|
|
|
;; into html
|
|
|
|
|
`((javascript ((parent-is "program")
|
|
|
|
|
php-ts-mode--js-css-tag-bol
|
|
|
|
|
php-ts-mode-js-css-indent-offset)
|
|
|
|
|
,@(cdr (car js--treesit-indent-rules))))
|
|
|
|
|
`((css ((parent-is "stylesheet")
|
|
|
|
|
php-ts-mode--js-css-tag-bol
|
|
|
|
|
php-ts-mode-js-css-indent-offset)
|
|
|
|
|
,@(cdr (car css--treesit-indent-rules))))))
|
|
|
|
|
|
|
|
|
|
;; Comment
|
|
|
|
|
(php-ts-mode-comment-setup)
|
|
|
|
|
|
|
|
|
|
;; PHP vars are case-sensitive
|
|
|
|
|
(setq-local case-fold-search t)
|
|
|
|
|
|
|
|
|
|
;; Electric
|
|
|
|
|
(setq-local electric-indent-chars
|
|
|
|
|
(append "{}():;," electric-indent-chars))
|
|
|
|
|
|
|
|
|
|
;; Imenu/Which-function/Outline
|
|
|
|
|
(setq-local treesit-simple-imenu-settings
|
|
|
|
|
'(("Class" "\\`class_declaration\\'" nil nil)
|
|
|
|
|
("Enum" "\\`enum_declaration\\'" nil nil)
|
|
|
|
|
("Function" "\\`function_definition\\'" nil nil)
|
|
|
|
|
("Interface" "\\`interface_declaration\\'" nil nil)
|
|
|
|
|
("Method" "\\`method_declaration\\'" nil nil)
|
|
|
|
|
("Namespace" "\\`namespace_definition\\'" nil nil)
|
|
|
|
|
("Trait" "\\`trait_declaration\\'" nil nil)
|
|
|
|
|
("Variable" "\\`variable_name\\'" nil nil)
|
|
|
|
|
("Constant" "\\`const_element\\'" nil nil)))
|
|
|
|
|
|
|
|
|
|
;; Font-lock.
|
|
|
|
|
(setq-local treesit-font-lock-settings
|
2024-06-22 23:11:17 +02:00
|
|
|
|
(append (php-ts-mode--font-lock-settings)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
php-ts-mode--custom-html-font-lock-settings
|
|
|
|
|
js--treesit-font-lock-settings
|
2024-06-22 23:11:17 +02:00
|
|
|
|
(append
|
|
|
|
|
;; Rule for coloring CSS property values.
|
|
|
|
|
;; Placed before `css--treesit-settings'
|
|
|
|
|
;; to win against the same rule contained therein.
|
|
|
|
|
(treesit-font-lock-rules
|
|
|
|
|
:language 'css
|
|
|
|
|
:override t
|
|
|
|
|
:feature 'variable
|
|
|
|
|
'((plain_value) @php-ts-mode--colorize-css-value))
|
|
|
|
|
css--treesit-settings)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
php-ts-mode--phpdoc-font-lock-settings))
|
|
|
|
|
|
|
|
|
|
(setq-local treesit-font-lock-feature-list php-ts-mode--feature-list)
|
|
|
|
|
|
|
|
|
|
;; Align.
|
|
|
|
|
(setq-local align-indent-before-aligning t)
|
|
|
|
|
|
|
|
|
|
;; should be the last one
|
|
|
|
|
(setq-local treesit-primary-parser (treesit-parser-create 'php))
|
|
|
|
|
(treesit-font-lock-recompute-features)
|
|
|
|
|
(treesit-major-mode-setup)
|
|
|
|
|
(add-hook 'flymake-diagnostic-functions #'php-ts-mode-flymake-php nil 'local)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(defun php-ts-mode-run-php-webserver (&optional port
|
|
|
|
|
hostname
|
|
|
|
|
document-root
|
|
|
|
|
router-script
|
|
|
|
|
num-of-workers
|
|
|
|
|
config)
|
2024-06-07 12:39:03 +02:00
|
|
|
|
"Run PHP built-in web server.
|
|
|
|
|
|
|
|
|
|
PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
|
|
|
|
|
Prompt for the port if the default value is nil.
|
|
|
|
|
HOSTNAME: Hostname or IP address of Built-in web server,
|
|
|
|
|
default `php-ts-mode-ws-hostname'. Prompt for the hostname if the
|
|
|
|
|
default value is nil.
|
|
|
|
|
DOCUMENT-ROOT: Path to Document root, default `php-ts-mode-ws-document-root'.
|
|
|
|
|
Prompt for the document-root if the default value is nil.
|
|
|
|
|
ROUTER-SCRIPT: Path of the router PHP script,
|
|
|
|
|
see `https://www.php.net/manual/en/features.commandline.webserver.php'
|
|
|
|
|
NUM-OF-WORKERS: Before run the web server set the
|
|
|
|
|
PHP_CLI_SERVER_WORKERS env variable useful for testing code against
|
2024-09-02 14:11:01 +02:00
|
|
|
|
multiple simultaneous requests
|
|
|
|
|
CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
2024-09-02 14:11:01 +02:00
|
|
|
|
Interactively, when invoked with prefix argument, always prompt for
|
|
|
|
|
PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and
|
|
|
|
|
CONFIG."
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(interactive (when current-prefix-arg
|
|
|
|
|
(php-ts-mode--webserver-read-args)))
|
|
|
|
|
(let* ((port (or
|
|
|
|
|
port
|
|
|
|
|
php-ts-mode-ws-port
|
|
|
|
|
(php-ts-mode--webserver-read-args 'port)))
|
|
|
|
|
(hostname (or
|
|
|
|
|
hostname
|
|
|
|
|
php-ts-mode-ws-hostname
|
|
|
|
|
(php-ts-mode--webserver-read-args 'hostname)))
|
|
|
|
|
(document-root (or
|
|
|
|
|
document-root
|
|
|
|
|
php-ts-mode-ws-document-root
|
|
|
|
|
(php-ts-mode--webserver-read-args 'document-root)))
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(config (or config
|
|
|
|
|
(when php-ts-mode-php-config
|
|
|
|
|
(expand-file-name php-ts-mode-php-config))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(host (format "%s:%d" hostname port))
|
|
|
|
|
(name (format "PHP web server on: %s" host))
|
|
|
|
|
(buf-name (format "*%s*" name))
|
|
|
|
|
(args (delq
|
|
|
|
|
nil
|
|
|
|
|
(list "-S" host
|
|
|
|
|
"-t" document-root
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(when config
|
|
|
|
|
(format "-c %s" config))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
router-script)))
|
|
|
|
|
(process-environment
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(nconc (cond
|
|
|
|
|
(num-of-workers
|
|
|
|
|
(list
|
|
|
|
|
(format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers)))
|
|
|
|
|
(php-ts-mode-ws-workers
|
|
|
|
|
(list
|
|
|
|
|
(format "PHP_CLI_SERVER_WORKERS=%d" php-ts-mode-ws-workers))))
|
|
|
|
|
process-environment)))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(if (get-buffer buf-name)
|
|
|
|
|
(message "Switch to already running web server into buffer %s" buf-name)
|
|
|
|
|
(message "Run PHP built-in web server with args %s into buffer %s"
|
|
|
|
|
(string-join args " ")
|
|
|
|
|
buf-name)
|
|
|
|
|
(apply #'make-comint name php-ts-mode-php-executable nil args))
|
|
|
|
|
(funcall
|
|
|
|
|
(if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
|
|
|
|
|
buf-name)))
|
|
|
|
|
|
|
|
|
|
(derived-mode-add-parents 'php-ts-mode '(php-mode))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode--webserver-read-args (&optional type)
|
2024-06-15 18:57:29 +02:00
|
|
|
|
"Helper for `php-ts-mode-run-php-webserver'.
|
2024-09-02 14:11:01 +02:00
|
|
|
|
The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\",
|
|
|
|
|
\"router-script\", \"num-workers\" or \"config\", otherwise it requires all of them."
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(let ((ask-port (lambda ()
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(read-number "Port: " (or
|
|
|
|
|
php-ts-mode-ws-port
|
|
|
|
|
3000))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(ask-hostname (lambda ()
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(read-string "Hostname: "
|
|
|
|
|
(or
|
|
|
|
|
php-ts-mode-ws-hostname
|
|
|
|
|
"localhost"))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(ask-document-root (lambda ()
|
|
|
|
|
(expand-file-name
|
|
|
|
|
(read-directory-name "Document root: "
|
2024-06-15 18:57:29 +02:00
|
|
|
|
(file-name-directory
|
|
|
|
|
(or (buffer-file-name)
|
|
|
|
|
default-directory))))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(ask-router-script (lambda ()
|
|
|
|
|
(expand-file-name
|
|
|
|
|
(read-file-name "Router script: "
|
2024-06-15 18:57:29 +02:00
|
|
|
|
(file-name-directory
|
|
|
|
|
(or (buffer-file-name)
|
2024-09-02 14:11:01 +02:00
|
|
|
|
default-directory))))))
|
|
|
|
|
(ask-num-workers (lambda ()
|
|
|
|
|
(let ((num-workers
|
|
|
|
|
(read-number
|
|
|
|
|
"Number of workers (less then 2 means no workers): "
|
|
|
|
|
(or php-ts-mode-ws-workers 0))))
|
|
|
|
|
;; num-workers must be >= 2 or nil
|
|
|
|
|
;; otherwise PHP's built-in web server will not start.
|
|
|
|
|
(if (> num-workers 1)
|
|
|
|
|
num-workers
|
|
|
|
|
nil))))
|
|
|
|
|
(ask-config (lambda()
|
|
|
|
|
(let ((file-name (expand-file-name
|
|
|
|
|
(read-file-name "Alternative php.ini: "
|
|
|
|
|
(file-name-directory
|
|
|
|
|
(or (buffer-file-name)
|
|
|
|
|
default-directory))))))
|
|
|
|
|
(if (string= "" (file-name-directory file-name))
|
|
|
|
|
nil
|
|
|
|
|
file-name)))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(cl-case type
|
|
|
|
|
(port (funcall ask-port))
|
|
|
|
|
(hostname (funcall ask-hostname))
|
|
|
|
|
(document-root (funcall ask-document-root))
|
|
|
|
|
(router-script (funcall ask-router-script))
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(num-of-workers (funcall ask-num-workers))
|
|
|
|
|
(config (funcall ask-config))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
(t (list
|
|
|
|
|
(funcall ask-port)
|
|
|
|
|
(funcall ask-hostname)
|
|
|
|
|
(funcall ask-document-root)
|
2024-09-02 14:11:01 +02:00
|
|
|
|
(funcall ask-router-script)
|
|
|
|
|
(funcall ask-num-workers)
|
|
|
|
|
(funcall ask-config))))))
|
2024-06-07 12:39:03 +02:00
|
|
|
|
|
|
|
|
|
(define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP"
|
|
|
|
|
"Major mode for PHP inferior process."
|
|
|
|
|
(setq-local scroll-conservatively 1
|
|
|
|
|
comint-input-ring-file-name php-ts-mode-inferior-history
|
|
|
|
|
comint-input-ignoredups t
|
|
|
|
|
comint-prompt-read-only t
|
|
|
|
|
comint-use-prompt-regexp t
|
|
|
|
|
comint-prompt-regexp (concat "^" php-ts-mode--inferior-prompt " "))
|
|
|
|
|
(comint-read-input-ring t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Inferior PHP process.
|
|
|
|
|
|
|
|
|
|
(defvar php-ts-mode--inferior-php-process nil
|
|
|
|
|
"The PHP inferior process associated to `php-ts-mode-inferior-php-buffer'.")
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun run-php (&optional cmd config)
|
|
|
|
|
"Run an PHP interpreter as a inferior process.
|
|
|
|
|
|
2024-06-23 16:28:31 +02:00
|
|
|
|
Arguments CMD and CONFIG, default to `php-ts-mode-php-executable'
|
2024-06-07 12:39:03 +02:00
|
|
|
|
and `php-ts-mode-php-config' respectively, control which PHP interpreter is run.
|
|
|
|
|
Prompt for CMD if `php-ts-mode-php-executable' is nil.
|
|
|
|
|
Optional CONFIG, if supplied, is the php.ini file to use."
|
|
|
|
|
(interactive (when current-prefix-arg
|
|
|
|
|
(list
|
|
|
|
|
(read-string "Run PHP: " php-ts-mode-php-executable)
|
|
|
|
|
(expand-file-name
|
|
|
|
|
(read-file-name "With config: " php-ts-mode-php-config)))))
|
|
|
|
|
(let ((buffer (get-buffer-create php-ts-mode-inferior-php-buffer))
|
|
|
|
|
(cmd (or
|
|
|
|
|
cmd
|
|
|
|
|
php-ts-mode-php-executable
|
|
|
|
|
(read-string "Run PHP: " php-ts-mode-php-executable)))
|
|
|
|
|
(config (or
|
|
|
|
|
config
|
|
|
|
|
(and php-ts-mode-php-config
|
|
|
|
|
(expand-file-name php-ts-mode-php-config)))))
|
|
|
|
|
(unless (comint-check-proc buffer)
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(inferior-php-ts-mode-startup cmd config)
|
|
|
|
|
(inferior-php-ts-mode)))
|
|
|
|
|
(when buffer
|
|
|
|
|
(pop-to-buffer buffer))))
|
|
|
|
|
|
|
|
|
|
(defun inferior-php-ts-mode-startup (cmd &optional config)
|
|
|
|
|
"Start an inferior PHP process with command CMD and init file CONFIG.
|
|
|
|
|
CMD is the command to run. Optional CONFIG, if supplied, is the php.ini
|
|
|
|
|
file to use."
|
|
|
|
|
(setq-local php-ts-mode--inferior-php-process
|
|
|
|
|
(apply #'make-comint-in-buffer
|
|
|
|
|
(string-replace "*" "" php-ts-mode-inferior-php-buffer)
|
|
|
|
|
php-ts-mode-inferior-php-buffer
|
|
|
|
|
cmd
|
|
|
|
|
nil
|
|
|
|
|
(delq
|
|
|
|
|
nil
|
|
|
|
|
(list
|
|
|
|
|
(when config
|
|
|
|
|
(format "-c %s" config))
|
|
|
|
|
"-a"))))
|
|
|
|
|
(add-hook 'comint-preoutput-filter-functions
|
|
|
|
|
(lambda (string)
|
|
|
|
|
(let ((prompt (concat php-ts-mode--inferior-prompt " ")))
|
|
|
|
|
(if (member
|
|
|
|
|
string
|
|
|
|
|
(list prompt "php { " "php ( " "/* > " "Interactive shell\n\n"))
|
|
|
|
|
string
|
|
|
|
|
(let (;; Filter out prompts characters that accumulate when sending
|
|
|
|
|
;; regions to the inferior process.
|
|
|
|
|
(clean-string
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
(rx-to-string `(or
|
|
|
|
|
(+ "php >" (opt space))
|
|
|
|
|
(+ "php {" (opt space))
|
|
|
|
|
(+ "php (" (opt space))
|
|
|
|
|
(+ "/*" (1+ space) (1+ ">") (opt space))))
|
|
|
|
|
"" string)))
|
|
|
|
|
;; Re-add the prompt for the next line, if isn't empty.
|
|
|
|
|
(if (string= clean-string "")
|
|
|
|
|
""
|
|
|
|
|
(concat (string-chop-newline clean-string) "\n" prompt))))))
|
|
|
|
|
nil t)
|
|
|
|
|
(when php-ts-mode-inferior-history
|
|
|
|
|
(set-process-sentinel
|
|
|
|
|
(get-buffer-process php-ts-mode-inferior-php-buffer)
|
|
|
|
|
'php-ts-mode-inferior--write-history)))
|
|
|
|
|
|
|
|
|
|
;; taken and adapted from lua-ts-mode
|
|
|
|
|
(defun php-ts-mode-inferior--write-history (process _)
|
|
|
|
|
"Write history file for inferior PHP PROCESS."
|
|
|
|
|
;; Depending on how the process is killed the buffer may not be
|
|
|
|
|
;; around anymore; e.g. `kill-buffer'.
|
|
|
|
|
(when-let* ((buffer (process-buffer process))
|
|
|
|
|
((buffer-live-p (process-buffer process))))
|
|
|
|
|
(with-current-buffer buffer (comint-write-input-ring))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-send-region (beg end)
|
|
|
|
|
"Send region between BEG and END to the inferior PHP process."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(if (buffer-live-p php-ts-mode--inferior-php-process)
|
|
|
|
|
(progn
|
|
|
|
|
(php-ts-mode-show-process-buffer)
|
|
|
|
|
(comint-send-string php-ts-mode--inferior-php-process "\n")
|
|
|
|
|
(comint-send-string
|
|
|
|
|
php-ts-mode--inferior-php-process
|
|
|
|
|
(buffer-substring-no-properties beg end))
|
|
|
|
|
(comint-send-string php-ts-mode--inferior-php-process "\n"))
|
|
|
|
|
(message "Invoke run-php first!")))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-send-buffer ()
|
|
|
|
|
"Send current buffer to the inferior PHP process."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(search-forward "<?php" nil t)
|
|
|
|
|
(php-ts-mode-send-region (point) (point-max))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-send-file (file)
|
|
|
|
|
"Send contents of FILE to the inferior PHP process."
|
|
|
|
|
(interactive "f")
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents-literally file)
|
|
|
|
|
(search-forward "<?php" nil t)
|
|
|
|
|
(php-ts-mode-send-region (point) (point-max))))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-show-process-buffer ()
|
|
|
|
|
"Show the inferior PHP process buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(display-buffer php-ts-mode-inferior-php-buffer))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-hide-process-buffer ()
|
|
|
|
|
"Hide the inferior PHP process buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(delete-windows-on php-ts-mode-inferior-php-buffer))
|
|
|
|
|
|
|
|
|
|
(defun php-ts-mode-kill-process ()
|
|
|
|
|
"Kill the inferior PHP process."
|
|
|
|
|
(interactive)
|
|
|
|
|
(with-current-buffer php-ts-mode-inferior-php-buffer
|
|
|
|
|
(kill-buffer-and-window)))
|
|
|
|
|
|
|
|
|
|
(when (treesit-ready-p 'php)
|
|
|
|
|
(add-to-list
|
|
|
|
|
'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode))
|
|
|
|
|
(add-to-list
|
|
|
|
|
'auto-mode-alist '("\\.\\(?:php\\|inc\\|stub\\)\\'" . php-ts-mode))
|
|
|
|
|
(add-to-list
|
|
|
|
|
'auto-mode-alist '("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-ts-mode))
|
|
|
|
|
(add-to-list
|
|
|
|
|
'interpreter-mode-alist
|
|
|
|
|
(cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-ts-mode)))
|
|
|
|
|
|
|
|
|
|
(provide 'php-ts-mode)
|
|
|
|
|
;;; php-ts-mode.el ends here
|