aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincenzo Pupillo2025-03-14 21:11:22 +0100
committerEli Zaretskii2025-03-29 14:32:31 +0300
commit99ff59bd66cc07df40b14cb0a8acf22d440581e5 (patch)
treec5b0e4caf049b7787bad92d18db4d1cd576e4f94
parent26873d5028ed8aa0e2fc56c7d6ed3b43ff976d3c (diff)
downloademacs-99ff59bd66cc07df40b14cb0a8acf22d440581e5.tar.gz
emacs-99ff59bd66cc07df40b14cb0a8acf22d440581e5.zip
PHP should be in the PATH, either locally or remotely. (bug#76242).
* lisp/progmodes/php-ts-mode.el (php-ts-mode-php-default-executable): Renamed from 'php-ts-mode-php-executable'. (php-ts-mode--executable): New function that returns the absolute filename of the PHP executable, local or remote, based on 'default-directory'. (php-ts-mode--anchor-prev-sibling): Replaced 'when-let' with “when-let*.” (php-ts-mode--indent-defun): Replaced 'when-let' with 'when-let*'. (php-ts-mode-run-php-webserver): Use the new function (php-ts-mode-php-default-executable). (run-php): Use the new function (php-ts-mode-php-default-executable).
-rw-r--r--lisp/progmodes/php-ts-mode.el47
1 files changed, 31 insertions, 16 deletions
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index 56c15dad36f..b626a19a0de 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -134,12 +134,16 @@ Works like `css--fontify-region'."
134 :type 'boolean 134 :type 'boolean
135 :safe 'booleanp) 135 :safe 'booleanp)
136 136
137(defcustom php-ts-mode-php-executable (or (executable-find "php") "/usr/bin/php") 137(defcustom php-ts-mode-php-default-executable (or (executable-find "php") "/usr/bin/php")
138 "The location of PHP executable." 138 "The default PHP executable."
139 :tag "PHP Executable" 139 :tag "PHP Executable"
140 :version "30.1" 140 :version "30.1"
141 :type 'file) 141 :type 'file)
142 142
143(defvar-local php-ts-mode-alternative-php-program-name nil
144 "An alternative to the usual `php' program name.
145In non-nil, `php-ts-mode--executable' try to find this executable.")
146
143(defcustom php-ts-mode-php-config nil 147(defcustom php-ts-mode-php-config nil
144 "The location of php.ini file. 148 "The location of php.ini file.
145If nil the default one is used to run the embedded webserver or 149If nil the default one is used to run the embedded webserver or
@@ -270,7 +274,7 @@ Calls REPORT-FN directly."
270 :noquery t 274 :noquery t
271 :connection-type 'pipe 275 :connection-type 'pipe
272 :buffer (generate-new-buffer " *php-ts-mode-flymake*") 276 :buffer (generate-new-buffer " *php-ts-mode-flymake*")
273 :command `(,php-ts-mode-php-executable 277 :command `(,(php-ts-mode--executable)
274 "-l" "-d" "display_errors=0") 278 "-l" "-d" "display_errors=0")
275 :sentinel 279 :sentinel
276 (lambda (proc _event) 280 (lambda (proc _event)
@@ -306,6 +310,16 @@ Calls REPORT-FN directly."
306 310
307;;; Utils 311;;; Utils
308 312
313(defun php-ts-mode--executable ()
314 "Return the absolute filename of the php executable.
315If the `default-directory' is remote, search on a remote host, otherwise
316it searches locally. If `php-ts-mode-alternative-php-program-name' is
317non-zero, it searches for this program instead of the usual `php'.
318If the search fails, it returns `php-ts-mode-php-default-executable'."
319 (or (executable-find
320 (or php-ts-mode-alternative-php-program-name "php") t)
321 php-ts-mode-php-default-executable))
322
309(defun php-ts-mode--get-indent-style () 323(defun php-ts-mode--get-indent-style ()
310 "Helper function to set indentation style. 324 "Helper function to set indentation style.
311MODE can be `psr2', `pear', `drupal', `wordpress', `symfony', `zend'." 325MODE can be `psr2', `pear', `drupal', `wordpress', `symfony', `zend'."
@@ -595,7 +609,7 @@ doesn't have a child.
595 609
596PARENT is NODE's parent, BOL is the beginning of non-whitespace 610PARENT is NODE's parent, BOL is the beginning of non-whitespace
597characters of the current line." 611characters of the current line."
598 (when-let ((prev-sibling 612 (when-let* ((prev-sibling
599 (or (treesit-node-prev-sibling node t) 613 (or (treesit-node-prev-sibling node t)
600 (treesit-node-prev-sibling 614 (treesit-node-prev-sibling
601 (treesit-node-first-child-for-pos parent bol) t) 615 (treesit-node-first-child-for-pos parent bol) t)
@@ -1236,7 +1250,7 @@ Return nil if the NODE has no field “name” or if NODE is not a defun node."
1236 "Indent the current top-level declaration syntactically. 1250 "Indent the current top-level declaration syntactically.
1237`treesit-defun-type-regexp' defines what constructs to indent." 1251`treesit-defun-type-regexp' defines what constructs to indent."
1238 (interactive "*") 1252 (interactive "*")
1239 (when-let ((orig-point (point-marker)) 1253 (when-let* ((orig-point (point-marker))
1240 (node (treesit-defun-at-point))) 1254 (node (treesit-defun-at-point)))
1241 (indent-region (treesit-node-start node) 1255 (indent-region (treesit-node-start node)
1242 (treesit-node-end node)) 1256 (treesit-node-end node))
@@ -1613,7 +1627,7 @@ for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
1613 (message "Run PHP built-in web server with args %s into buffer %s" 1627 (message "Run PHP built-in web server with args %s into buffer %s"
1614 (string-join args " ") 1628 (string-join args " ")
1615 buf-name) 1629 buf-name)
1616 (apply #'make-comint name php-ts-mode-php-executable nil args)) 1630 (apply #'make-comint name (php-ts-mode--executable) nil args))
1617 (funcall 1631 (funcall
1618 (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer) 1632 (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
1619 buf-name))) 1633 buf-name)))
@@ -1677,18 +1691,19 @@ Prompt for CMD if `php-ts-mode-php-executable' is nil.
1677Optional CONFIG, if supplied, is the php.ini file to use." 1691Optional CONFIG, if supplied, is the php.ini file to use."
1678 (interactive (when current-prefix-arg 1692 (interactive (when current-prefix-arg
1679 (list 1693 (list
1680 (read-string "Run PHP: " php-ts-mode-php-executable) 1694 (read-string "Run PHP: " (php-ts-mode--executable))
1681 (expand-file-name 1695 (expand-file-name
1682 (read-file-name "With config: " php-ts-mode-php-config))))) 1696 (read-file-name "With config: " php-ts-mode-php-config)))))
1683 (let ((buffer (get-buffer-create php-ts-mode-inferior-php-buffer)) 1697 (let* ((php-prog (php-ts-mode--executable))
1684 (cmd (or 1698 (buffer (get-buffer-create php-ts-mode-inferior-php-buffer))
1685 cmd 1699 (cmd (or
1686 php-ts-mode-php-executable 1700 cmd
1687 (read-string "Run PHP: " php-ts-mode-php-executable))) 1701 php-prog
1688 (config (or 1702 (read-string "Run PHP: " php-prog)))
1689 config 1703 (config (or
1690 (and php-ts-mode-php-config 1704 config
1691 (expand-file-name php-ts-mode-php-config))))) 1705 (and php-ts-mode-php-config
1706 (expand-file-name php-ts-mode-php-config)))))
1692 (unless (comint-check-proc buffer) 1707 (unless (comint-check-proc buffer)
1693 (with-current-buffer buffer 1708 (with-current-buffer buffer
1694 (inferior-php-ts-mode-startup cmd config) 1709 (inferior-php-ts-mode-startup cmd config)