Subject: bug#76955: 30.1; php-ts-mode-php-executable default path may not match remote path

From: Vincenzo Pupillo <[email-masked]>
Date: Wed, 19 Mar 2025 19:25:18 +0100

In data mercoledì 19 marzo 2025 18:30:23 Ora standard dell’Europa centrale, 
Michael Albinus ha scritto:
> Vincenzo Pupillo <[email-masked]> writes:
> > Ciao Micheal, thank you.
> 
> Hi Vincenzo,
> 
> > The new version of the patch is attached.
> 
> I guess the docstring of php-ts-mode--executable must be adapted to the
> recent affair.

Done

> > Thanks.
> > Vincenzo
> Best regards, Michael.

Thanks!

Vincenzo

From 5c9edc087efcb6e9d7c80cf52cacd6df46e45df3 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Fri, 14 Mar 2025 21:11:22 +0100
Subject: [PATCH] PHP should be in the PATH, either locally or remotely.
 (bug#76242).
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* 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).
---
 lisp/progmodes/php-ts-mode.el | 47 +++++++++++++++++++++++------------
 1 file 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 @@ php-ts-mode-css-fontify-colors
   :type 'boolean
   :safe 'booleanp)
 
-(defcustom php-ts-mode-php-executable (or (executable-find "php") "/usr/bin/php")
-  "The location of PHP executable."
+(defcustom php-ts-mode-php-default-executable (or (executable-find "php") "/usr/bin/php")
+  "The default PHP executable."
   :tag "PHP Executable"
   :version "30.1"
   :type 'file)
 
+(defvar-local php-ts-mode-alternative-php-program-name nil
+  "An alternative to the usual `php' program name.
+In non-nil, `php-ts-mode--executable' try to find this executable.")
+
 (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
@@ -270,7 +274,7 @@ php-ts-mode-flymake-php
              :noquery t
              :connection-type 'pipe
              :buffer (generate-new-buffer " *php-ts-mode-flymake*")
-             :command `(,php-ts-mode-php-executable
+             :command `(,(php-ts-mode--executable)
                         "-l" "-d" "display_errors=0")
              :sentinel
              (lambda (proc _event)
@@ -306,6 +310,16 @@ php-ts-mode-flymake-php
 
 ;;; Utils
 
+(defun php-ts-mode--executable ()
+  "Return the absolute filename of the php executable.
+If the `default-directory' is remote, search on a remote host, otherwise
+it searches locally.  If `php-ts-mode-alternative-php-program-name' is
+non-zero, it searches for this program instead of the usual `php'.
+If the search fails, it returns `php-ts-mode-php-default-executable'."
+  (or (executable-find
+      (or php-ts-mode-alternative-php-program-name "php") t)
+    php-ts-mode-php-default-executable))
+
 (defun php-ts-mode--get-indent-style ()
   "Helper function to set indentation style.
 MODE can be `psr2', `pear', `drupal', `wordpress', `symfony', `zend'."
@@ -595,7 +609,7 @@ php-ts-mode--anchor-prev-sibling
 
 PARENT is NODE's parent, BOL is the beginning of non-whitespace
 characters of the current line."
-  (when-let ((prev-sibling
+  (when-let* ((prev-sibling
               (or (treesit-node-prev-sibling node t)
                   (treesit-node-prev-sibling
                    (treesit-node-first-child-for-pos parent bol) t)
@@ -1236,7 +1250,7 @@ php-ts-mode--indent-defun
   "Indent the current top-level declaration syntactically.
 `treesit-defun-type-regexp' defines what constructs to indent."
   (interactive "*")
-  (when-let ((orig-point (point-marker))
+  (when-let* ((orig-point (point-marker))
              (node (treesit-defun-at-point)))
     (indent-region (treesit-node-start node)
                    (treesit-node-end node))
@@ -1613,7 +1627,7 @@ php-ts-mode-run-php-webserver
       (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))
+      (apply #'make-comint name (php-ts-mode--executable) nil args))
     (funcall
      (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
      buf-name)))
@@ -1677,18 +1691,19 @@ run-php
 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)
+                  (read-string "Run PHP: " (php-ts-mode--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)))))
+  (let* ((php-prog (php-ts-mode--executable))
+         (buffer (get-buffer-create php-ts-mode-inferior-php-buffer))
+         (cmd (or
+               cmd
+               php-prog
+               (read-string "Run PHP: " php-prog)))
+         (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)
-- 
2.48.1