unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
@ 2024-09-02 13:29 Vincenzo Pupillo
  2024-09-02 14:23 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Vincenzo Pupillo @ 2024-09-02 13:29 UTC (permalink / raw)
  To: 72966

[-- Attachment #1: Type: text/plain, Size: 229 bytes --]

Ciao, 
this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserver' that 
allows you to specify an alternative php.ini file to the default (or whatever 
is specified in 'php-ts-mode-php-config').
Thanks.

Vincenzo.


[-- Attachment #2: 0001-Support-for-custom-php.ini-for-the-built-in-PHP-web-.patch --]
[-- Type: text/x-patch, Size: 5203 bytes --]

From 8b688884219e081a086559728251172d710b51e2 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Mon, 2 Sep 2024 14:11:01 +0200
Subject: [PATCH] Support for custom php.ini for the built-in PHP web server.

A new CONFIG attribute, which defaults to 'php-ts-mode-php-config',
allows an alternative php.ini file to be specified for the built-in web
server. The 'php-ts-mode-run-php-webserver' function, when called
interactively with a prefix argument, also requires this new attribute.

* lisp/progmodes/php-ts-mode.el (php-ts-mode-run-php-webserver):
New CONFIG attribute. Update docstring.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--webserver-read-args):
Support the new TYPE. Update docstring.
---
 lisp/progmodes/php-ts-mode.el | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index 3f89de14075..34304049c5c 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -1469,8 +1469,12 @@ php-ts-mode
 
 \f
 ;;;###autoload
-(defun php-ts-mode-run-php-webserver (&optional port hostname document-root
-                                                router-script num-of-workers)
+(defun php-ts-mode-run-php-webserver (&optional port
+                                                hostname
+                                                document-root
+                                                router-script
+                                                config
+                                                num-of-workers)
   "Run PHP built-in web server.
 
 PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
@@ -1482,12 +1486,14 @@ php-ts-mode-run-php-webserver
 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'
+CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.
 NUM-OF-WORKERS: Before run the web server set the
 PHP_CLI_SERVER_WORKERS env variable useful for testing code against
 multiple simultaneous requests.
 
+
 Interactively, when invoked with prefix argument, always prompt
-for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
+for PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT and CONFIG."
   (interactive (when current-prefix-arg
                  (php-ts-mode--webserver-read-args)))
   (let* ((port (or
@@ -1502,6 +1508,9 @@ php-ts-mode-run-php-webserver
                          document-root
                          php-ts-mode-ws-document-root
                          (php-ts-mode--webserver-read-args 'document-root)))
+         (config (or config
+                     (when php-ts-mode-php-config
+                       (expand-file-name php-ts-mode-php-config))))
          (host (format "%s:%d" hostname port))
          (name (format "PHP web server on: %s" host))
          (buf-name (format "*%s*" name))
@@ -1509,6 +1518,8 @@ php-ts-mode-run-php-webserver
                 nil
                 (list "-S" host
                       "-t" document-root
+                      (when config
+			(format "-c %s" config))
                       router-script)))
          (process-environment
           (cons (cond
@@ -1529,8 +1540,8 @@ php-ts-mode-run-php-webserver
 
 (defun php-ts-mode--webserver-read-args (&optional type)
   "Helper for `php-ts-mode-run-php-webserver'.
-The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\" or
-\"router-script\", otherwise it requires all of them."
+The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\",
+\"router-script\" or \"config\", otherwise it requires all of them."
   (let ((ask-port (lambda ()
                     (read-number "Port: " 3000)))
         (ask-hostname (lambda ()
@@ -1546,17 +1557,25 @@ php-ts-mode--webserver-read-args
                               (read-file-name "Router script: "
                                               (file-name-directory
                                                (or (buffer-file-name)
-                                                   default-directory)))))))
+                                                   default-directory))))))
+        (ask-config (lambda()
+                      (expand-file-name
+                       (read-file-name "Alternative php.ini: "
+                                       (file-name-directory
+                                        (or (buffer-file-name)
+                                            default-directory)))))))
     (cl-case type
       (port (funcall ask-port))
       (hostname (funcall ask-hostname))
       (document-root (funcall ask-document-root))
       (router-script (funcall ask-router-script))
+      (config (funcall ask-config))
       (t (list
           (funcall ask-port)
           (funcall ask-hostname)
           (funcall ask-document-root)
-          (funcall ask-router-script))))))
+          (funcall ask-router-script)
+          (funcall ask-config))))))
 
 (define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP"
   "Major mode for PHP inferior process."
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
  2024-09-02 13:29 bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver Vincenzo Pupillo
@ 2024-09-02 14:23 ` Eli Zaretskii
  2024-09-02 14:52   ` Vincenzo Pupillo
  2024-09-05 19:16   ` Vincenzo Pupillo
  0 siblings, 2 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-09-02 14:23 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: 72966

> From: Vincenzo Pupillo <v.pupillo@gmail.com>
> Date: Mon, 02 Sep 2024 15:29:23 +0200
> 
> Ciao, 
> this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserver' that 
> allows you to specify an alternative php.ini file to the default (or whatever 
> is specified in 'php-ts-mode-php-config').

Thanks.

> -(defun php-ts-mode-run-php-webserver (&optional port hostname document-root
> -                                                router-script num-of-workers)
> +(defun php-ts-mode-run-php-webserver (&optional port
> +                                                hostname
> +                                                document-root
> +                                                router-script
> +                                                config
> +                                                num-of-workers)
>    "Run PHP built-in web server.

This changes a public API in backward-incompatible way, something we
don't do, because it could break someone's code out there.  (It is
true that php-ts-mode was introduced in Emacs 30, but that version is
already in pretest and will be released soon, so I don't think we can
change this there, either.)

So please find a backward-compatible way of adding this feature,
perhaps add the new CONFIG argument as the last one?

Also, I think this needs a NEWS entry describing the change in
behavior.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
  2024-09-02 14:23 ` Eli Zaretskii
@ 2024-09-02 14:52   ` Vincenzo Pupillo
  2024-09-05 19:16   ` Vincenzo Pupillo
  1 sibling, 0 replies; 6+ messages in thread
From: Vincenzo Pupillo @ 2024-09-02 14:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72966

Ok, thanks. 
I will fix ASAP.

Vincenzo.

In data lunedì 2 settembre 2024 16:23:53 CEST, Eli Zaretskii ha scritto:
> > From: Vincenzo Pupillo <v.pupillo@gmail.com>
> > Date: Mon, 02 Sep 2024 15:29:23 +0200
> > 
> > Ciao,
> > this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserver'
> > that allows you to specify an alternative php.ini file to the default (or
> > whatever is specified in 'php-ts-mode-php-config').
> 
> Thanks.
> 
> > -(defun php-ts-mode-run-php-webserver (&optional port hostname
> > document-root -                                               
> > router-script num-of-workers) +(defun php-ts-mode-run-php-webserver
> > (&optional port
> > +                                                hostname
> > +                                                document-root
> > +                                                router-script
> > +                                                config
> > +                                                num-of-workers)
> > 
> >    "Run PHP built-in web server.
> 
> This changes a public API in backward-incompatible way, something we
> don't do, because it could break someone's code out there.  (It is
> true that php-ts-mode was introduced in Emacs 30, but that version is
> already in pretest and will be released soon, so I don't think we can
> change this there, either.)
> 
> So please find a backward-compatible way of adding this feature,
> perhaps add the new CONFIG argument as the last one?
> 
> Also, I think this needs a NEWS entry describing the change in
> behavior.









^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
  2024-09-02 14:23 ` Eli Zaretskii
  2024-09-02 14:52   ` Vincenzo Pupillo
@ 2024-09-05 19:16   ` Vincenzo Pupillo
  2024-09-08  6:48     ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Vincenzo Pupillo @ 2024-09-05 19:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72966

[-- Attachment #1: Type: text/plain, Size: 1694 bytes --]

Hi Eli, I followed your suggestion and moved the CONFIG argument. I also added 
a new entry to the NEWS file.

Thanks.
Vincenzo

In data lunedì 2 settembre 2024 16:23:53 CEST, Eli Zaretskii ha scritto:
> > From: Vincenzo Pupillo <v.pupillo@gmail.com>
> > Date: Mon, 02 Sep 2024 15:29:23 +0200
> > 
> > Ciao,
> > this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserver'
> > that allows you to specify an alternative php.ini file to the default (or
> > whatever is specified in 'php-ts-mode-php-config').
> 
> Thanks.
> 
> > -(defun php-ts-mode-run-php-webserver (&optional port hostname
> > document-root -                                               
> > router-script num-of-workers) +(defun php-ts-mode-run-php-webserver
> > (&optional port
> > +                                                hostname
> > +                                                document-root
> > +                                                router-script
> > +                                                config
> > +                                                num-of-workers)
> > 
> >    "Run PHP built-in web server.
> 
> This changes a public API in backward-incompatible way, something we
> don't do, because it could break someone's code out there.  (It is
> true that php-ts-mode was introduced in Emacs 30, but that version is
> already in pretest and will be released soon, so I don't think we can
> change this there, either.)
> 
> So please find a backward-compatible way of adding this feature,
> perhaps add the new CONFIG argument as the last one?
> 
> Also, I think this needs a NEWS entry describing the change in
> behavior.


[-- Attachment #2: 0001-Support-for-custom-php.ini-for-the-built-in-PHP-web-.patch --]
[-- Type: text/x-patch, Size: 8863 bytes --]

From ae9182be63bfa8625c8c8486c1856dced4fb9152 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Mon, 2 Sep 2024 14:11:01 +0200
Subject: [PATCH] Support for custom php.ini for the built-in PHP web server.

A new CONFIG attribute, which defaults to 'php-ts-mode-php-config',
allows an alternative php.ini file to be specified for the built-in web
server. The 'php-ts-mode-run-php-webserver' function, when called
interactively with a prefix argument, also requires this new attribute.

* etc/NEWS: Described the new CONFIG attribute and the different
behavior of 'php-ts-mode-run-php-webserver'.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--parent-html-bol):
Fix docstring.
* lisp/progmodes/php-ts-mode.el (php-ts-mode-run-php-webserver):
New CONFIG attribute. Update docstring.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--webserver-read-args):
Support the new TYPE. Update docstring.
---
 etc/NEWS                      | 10 +++++
 lisp/progmodes/php-ts-mode.el | 75 +++++++++++++++++++++++++++--------
 2 files changed, 69 insertions(+), 16 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index f2c999a3955..0539bf47479 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1965,6 +1965,16 @@ the 'widget-inactive' face).
 If non-nil, moving point forward or backward between widgets by typing
 'TAB' or 'S-TAB' skips over inactive widgets.  The default value is nil.
 
+**  PHP-ts mode
+
+---
+*** 'php-ts-mode-run-php-webserver' now accepts a custom php.ini.
+A new attribute, CONFIG, allows you to specify an custom php.ini.
+By default it retains the previous behavior: prompt for HOSTNAME
+and PORT only if their respective values are nil.
+Interactively, when invoked with prefix argument, always prompt for
+PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and CONFIG.
+
 ** Ruby mode
 
 ---
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index 3f89de14075..f8d240b746b 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -490,7 +490,7 @@ php-ts-mode--parent-html-bol
         (treesit-node-start parent)))))
 
 (defun php-ts-mode--parent-html-heuristic (node parent _bol &rest _)
-  "Returns position based on html indentation.
+  "Return position based on html indentation.
 
 Returns 0 if the NODE is after the </html>, otherwise returns the
 indentation point of the last word before the NODE, plus the
@@ -1469,8 +1469,12 @@ php-ts-mode
 
 \f
 ;;;###autoload
-(defun php-ts-mode-run-php-webserver (&optional port hostname document-root
-                                                router-script num-of-workers)
+(defun php-ts-mode-run-php-webserver (&optional port
+                                                hostname
+                                                document-root
+                                                router-script
+                                                num-of-workers
+                                                config)
   "Run PHP built-in web server.
 
 PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
@@ -1484,10 +1488,12 @@ php-ts-mode-run-php-webserver
 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
-multiple simultaneous requests.
+multiple simultaneous requests
+CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.
 
-Interactively, when invoked with prefix argument, always prompt
-for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
+Interactively, when invoked with prefix argument, always prompt for
+PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and
+CONFIG."
   (interactive (when current-prefix-arg
                  (php-ts-mode--webserver-read-args)))
   (let* ((port (or
@@ -1502,6 +1508,9 @@ php-ts-mode-run-php-webserver
                          document-root
                          php-ts-mode-ws-document-root
                          (php-ts-mode--webserver-read-args 'document-root)))
+         (config (or config
+                     (when php-ts-mode-php-config
+                       (expand-file-name php-ts-mode-php-config))))
          (host (format "%s:%d" hostname port))
          (name (format "PHP web server on: %s" host))
          (buf-name (format "*%s*" name))
@@ -1509,12 +1518,18 @@ php-ts-mode-run-php-webserver
                 nil
                 (list "-S" host
                       "-t" document-root
+                      (when config
+			(format "-c %s" config))
                       router-script)))
          (process-environment
-          (cons (cond
-                 (num-of-workers (format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers))
-                 (php-ts-mode-ws-workers (format "PHP_CLI_SERVER_WORKERS=%d" php-ts-mode-ws-workers)))
-                process-environment)))
+          (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)))
     (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"
@@ -1529,12 +1544,17 @@ php-ts-mode-run-php-webserver
 
 (defun php-ts-mode--webserver-read-args (&optional type)
   "Helper for `php-ts-mode-run-php-webserver'.
-The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\" or
-\"router-script\", otherwise it requires all of them."
+The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\",
+\"router-script\", \"num-workers\" or \"config\", otherwise it requires all of them."
   (let ((ask-port (lambda ()
-                    (read-number "Port: " 3000)))
+                    (read-number "Port: " (or
+                                           php-ts-mode-ws-port
+                                           3000))))
         (ask-hostname (lambda ()
-                        (read-string "Hostname: " "localhost")))
+                        (read-string "Hostname: "
+                                     (or
+                                      php-ts-mode-ws-hostname
+                                      "localhost"))))
         (ask-document-root (lambda ()
                              (expand-file-name
                               (read-directory-name "Document root: "
@@ -1546,17 +1566,40 @@ php-ts-mode--webserver-read-args
                               (read-file-name "Router script: "
                                               (file-name-directory
                                                (or (buffer-file-name)
-                                                   default-directory)))))))
+                                                   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)))))
     (cl-case type
       (port (funcall ask-port))
       (hostname (funcall ask-hostname))
       (document-root (funcall ask-document-root))
       (router-script (funcall ask-router-script))
+      (num-of-workers (funcall ask-num-workers))
+      (config (funcall ask-config))
       (t (list
           (funcall ask-port)
           (funcall ask-hostname)
           (funcall ask-document-root)
-          (funcall ask-router-script))))))
+          (funcall ask-router-script)
+          (funcall ask-num-workers)
+          (funcall ask-config))))))
 
 (define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP"
   "Major mode for PHP inferior process."
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
  2024-09-05 19:16   ` Vincenzo Pupillo
@ 2024-09-08  6:48     ` Eli Zaretskii
  2024-09-08 10:52       ` Vincenzo Pupillo
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-09-08  6:48 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: 72966-done

> From: Vincenzo Pupillo <v.pupillo@gmail.com>
> Cc: 72966@debbugs.gnu.org
> Date: Thu, 05 Sep 2024 21:16:29 +0200
> 
> Hi Eli, I followed your suggestion and moved the CONFIG argument. I also added 
> a new entry to the NEWS file.

Thanks, installed on the master branch, and closing the bug.

Please in the future try to adhere to our conventions of leaving two
spaces between sentences (I fixed that in this patch).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver
  2024-09-08  6:48     ` Eli Zaretskii
@ 2024-09-08 10:52       ` Vincenzo Pupillo
  0 siblings, 0 replies; 6+ messages in thread
From: Vincenzo Pupillo @ 2024-09-08 10:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72966-done

In data domenica 8 settembre 2024 08:48:09 CEST, Eli Zaretskii ha scritto:
> > From: Vincenzo Pupillo <v.pupillo@gmail.com>
> > Cc: 72966@debbugs.gnu.org
> > Date: Thu, 05 Sep 2024 21:16:29 +0200
> > 
> > Hi Eli, I followed your suggestion and moved the CONFIG argument. I also
> > added a new entry to the NEWS file.
> 
> Thanks, installed on the master branch, and closing the bug.
> 
> Please in the future try to adhere to our conventions of leaving two
> spaces between sentences (I fixed that in this patch).

Thank you Eli.

Vincenzo.







^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-09-08 10:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-02 13:29 bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver Vincenzo Pupillo
2024-09-02 14:23 ` Eli Zaretskii
2024-09-02 14:52   ` Vincenzo Pupillo
2024-09-05 19:16   ` Vincenzo Pupillo
2024-09-08  6:48     ` Eli Zaretskii
2024-09-08 10:52       ` Vincenzo Pupillo

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).