aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincenzo Pupillo2024-09-02 14:11:01 +0200
committerEli Zaretskii2024-09-08 09:46:02 +0300
commitbb239841670f9bf87576c8196c41fdf295d5eac2 (patch)
treebb99e0ec158ca95fa036d482a69a0521f8ea9226
parent2ce0d397b12cafcb3e1ac5630bc3fbca61bd6b87 (diff)
downloademacs-bb239841670f9bf87576c8196c41fdf295d5eac2.tar.gz
emacs-bb239841670f9bf87576c8196c41fdf295d5eac2.zip
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--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. (Bug#72966)
-rw-r--r--lisp/progmodes/php-ts-mode.el75
1 files changed, 59 insertions, 16 deletions
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 @@ characters of the current line."
490 (treesit-node-start parent))))) 490 (treesit-node-start parent)))))
491 491
492(defun php-ts-mode--parent-html-heuristic (node parent _bol &rest _) 492(defun php-ts-mode--parent-html-heuristic (node parent _bol &rest _)
493 "Returns position based on html indentation. 493 "Return position based on html indentation.
494 494
495Returns 0 if the NODE is after the </html>, otherwise returns the 495Returns 0 if the NODE is after the </html>, otherwise returns the
496indentation point of the last word before the NODE, plus the 496indentation point of the last word before the NODE, plus the
@@ -1469,8 +1469,12 @@ Depends on `c-ts-common-comment-setup'."
1469 1469
1470 1470
1471;;;###autoload 1471;;;###autoload
1472(defun php-ts-mode-run-php-webserver (&optional port hostname document-root 1472(defun php-ts-mode-run-php-webserver (&optional port
1473 router-script num-of-workers) 1473 hostname
1474 document-root
1475 router-script
1476 num-of-workers
1477 config)
1474 "Run PHP built-in web server. 1478 "Run PHP built-in web server.
1475 1479
1476PORT: Port number of built-in web server, default `php-ts-mode-ws-port'. 1480PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
@@ -1484,10 +1488,12 @@ ROUTER-SCRIPT: Path of the router PHP script,
1484see `https://www.php.net/manual/en/features.commandline.webserver.php' 1488see `https://www.php.net/manual/en/features.commandline.webserver.php'
1485NUM-OF-WORKERS: Before run the web server set the 1489NUM-OF-WORKERS: Before run the web server set the
1486PHP_CLI_SERVER_WORKERS env variable useful for testing code against 1490PHP_CLI_SERVER_WORKERS env variable useful for testing code against
1487multiple simultaneous requests. 1491multiple simultaneous requests
1492CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.
1488 1493
1489Interactively, when invoked with prefix argument, always prompt 1494Interactively, when invoked with prefix argument, always prompt for
1490for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT." 1495PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and
1496CONFIG."
1491 (interactive (when current-prefix-arg 1497 (interactive (when current-prefix-arg
1492 (php-ts-mode--webserver-read-args))) 1498 (php-ts-mode--webserver-read-args)))
1493 (let* ((port (or 1499 (let* ((port (or
@@ -1502,6 +1508,9 @@ for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
1502 document-root 1508 document-root
1503 php-ts-mode-ws-document-root 1509 php-ts-mode-ws-document-root
1504 (php-ts-mode--webserver-read-args 'document-root))) 1510 (php-ts-mode--webserver-read-args 'document-root)))
1511 (config (or config
1512 (when php-ts-mode-php-config
1513 (expand-file-name php-ts-mode-php-config))))
1505 (host (format "%s:%d" hostname port)) 1514 (host (format "%s:%d" hostname port))
1506 (name (format "PHP web server on: %s" host)) 1515 (name (format "PHP web server on: %s" host))
1507 (buf-name (format "*%s*" name)) 1516 (buf-name (format "*%s*" name))
@@ -1509,12 +1518,18 @@ for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
1509 nil 1518 nil
1510 (list "-S" host 1519 (list "-S" host
1511 "-t" document-root 1520 "-t" document-root
1521 (when config
1522 (format "-c %s" config))
1512 router-script))) 1523 router-script)))
1513 (process-environment 1524 (process-environment
1514 (cons (cond 1525 (nconc (cond
1515 (num-of-workers (format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers)) 1526 (num-of-workers
1516 (php-ts-mode-ws-workers (format "PHP_CLI_SERVER_WORKERS=%d" php-ts-mode-ws-workers))) 1527 (list
1517 process-environment))) 1528 (format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers)))
1529 (php-ts-mode-ws-workers
1530 (list
1531 (format "PHP_CLI_SERVER_WORKERS=%d" php-ts-mode-ws-workers))))
1532 process-environment)))
1518 (if (get-buffer buf-name) 1533 (if (get-buffer buf-name)
1519 (message "Switch to already running web server into buffer %s" buf-name) 1534 (message "Switch to already running web server into buffer %s" buf-name)
1520 (message "Run PHP built-in web server with args %s into buffer %s" 1535 (message "Run PHP built-in web server with args %s into buffer %s"
@@ -1529,12 +1544,17 @@ for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
1529 1544
1530(defun php-ts-mode--webserver-read-args (&optional type) 1545(defun php-ts-mode--webserver-read-args (&optional type)
1531 "Helper for `php-ts-mode-run-php-webserver'. 1546 "Helper for `php-ts-mode-run-php-webserver'.
1532The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\" or 1547The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\",
1533\"router-script\", otherwise it requires all of them." 1548\"router-script\", \"num-workers\" or \"config\", otherwise it requires all of them."
1534 (let ((ask-port (lambda () 1549 (let ((ask-port (lambda ()
1535 (read-number "Port: " 3000))) 1550 (read-number "Port: " (or
1551 php-ts-mode-ws-port
1552 3000))))
1536 (ask-hostname (lambda () 1553 (ask-hostname (lambda ()
1537 (read-string "Hostname: " "localhost"))) 1554 (read-string "Hostname: "
1555 (or
1556 php-ts-mode-ws-hostname
1557 "localhost"))))
1538 (ask-document-root (lambda () 1558 (ask-document-root (lambda ()
1539 (expand-file-name 1559 (expand-file-name
1540 (read-directory-name "Document root: " 1560 (read-directory-name "Document root: "
@@ -1546,17 +1566,40 @@ The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\" or
1546 (read-file-name "Router script: " 1566 (read-file-name "Router script: "
1547 (file-name-directory 1567 (file-name-directory
1548 (or (buffer-file-name) 1568 (or (buffer-file-name)
1549 default-directory))))))) 1569 default-directory))))))
1570 (ask-num-workers (lambda ()
1571 (let ((num-workers
1572 (read-number
1573 "Number of workers (less then 2 means no workers): "
1574 (or php-ts-mode-ws-workers 0))))
1575 ;; num-workers must be >= 2 or nil
1576 ;; otherwise PHP's built-in web server will not start.
1577 (if (> num-workers 1)
1578 num-workers
1579 nil))))
1580 (ask-config (lambda()
1581 (let ((file-name (expand-file-name
1582 (read-file-name "Alternative php.ini: "
1583 (file-name-directory
1584 (or (buffer-file-name)
1585 default-directory))))))
1586 (if (string= "" (file-name-directory file-name))
1587 nil
1588 file-name)))))
1550 (cl-case type 1589 (cl-case type
1551 (port (funcall ask-port)) 1590 (port (funcall ask-port))
1552 (hostname (funcall ask-hostname)) 1591 (hostname (funcall ask-hostname))
1553 (document-root (funcall ask-document-root)) 1592 (document-root (funcall ask-document-root))
1554 (router-script (funcall ask-router-script)) 1593 (router-script (funcall ask-router-script))
1594 (num-of-workers (funcall ask-num-workers))
1595 (config (funcall ask-config))
1555 (t (list 1596 (t (list
1556 (funcall ask-port) 1597 (funcall ask-port)
1557 (funcall ask-hostname) 1598 (funcall ask-hostname)
1558 (funcall ask-document-root) 1599 (funcall ask-document-root)
1559 (funcall ask-router-script)))))) 1600 (funcall ask-router-script)
1601 (funcall ask-num-workers)
1602 (funcall ask-config))))))
1560 1603
1561(define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP" 1604(define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP"
1562 "Major mode for PHP inferior process." 1605 "Major mode for PHP inferior process."