From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.bugs Subject: bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver Date: Thu, 05 Sep 2024 21:16:29 +0200 Message-ID: <26551738.1r3eYUQgxm@fedora> References: <5614567.rdbgypaU67@fedora> <86bk16877q.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2272098.vFx2qVVIhK" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36932"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72966@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 05 21:18:35 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1smI02-0009Rg-M9 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 05 Sep 2024 21:18:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smHzt-0007oG-3s; Thu, 05 Sep 2024 15:18:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1smHzR-0007GS-D1 for bug-gnu-emacs@gnu.org; Thu, 05 Sep 2024 15:17:58 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1smHzQ-0000gt-Oa for bug-gnu-emacs@gnu.org; Thu, 05 Sep 2024 15:17:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=atq38V6QPZL1Xr80KPq1mUSULmVfWEOlvs/Kb7/hk34=; b=c+Tt7RhoR8JW7hqi/RaTcpwJ7lf2+TyS2fgSleIGcgFPYqeDVfr2/wdwFAGQ2BLwP+7c1dicg67NKq8V06KOxVNb1OCyXsVW4JfDy07qzbN/gIjgRyNAmJsUk1gkzzAyEGp2nt0gOExc0tLDmuJ0/My2l1WzZmGDspaTd8Z5b7pbm5RdAJR2y9S3YS/kMg6w7egZAjp5pKToNaLlstgpN3ouiC69re+26PpjDrE+90BYJtemGjGww93xupMCeNkVNHbL5o5404h/4WL8mSzzo0zdB5w5dxgeRwSiv0CeFRcr8NxvTXEYmieHJusVBtVj4LvsbjPqmM2x/AdBA7Oaow==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1smI0T-0002MT-N5 for bug-gnu-emacs@gnu.org; Thu, 05 Sep 2024 15:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Sep 2024 19:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72966 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72966-submit@debbugs.gnu.org id=B72966.17255639259022 (code B ref 72966); Thu, 05 Sep 2024 19:19:01 +0000 Original-Received: (at 72966) by debbugs.gnu.org; 5 Sep 2024 19:18:45 +0000 Original-Received: from localhost ([127.0.0.1]:38255 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1smI0C-0002LR-DW for submit@debbugs.gnu.org; Thu, 05 Sep 2024 15:18:45 -0400 Original-Received: from mail-ed1-f49.google.com ([209.85.208.49]:59559) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1smI0A-0002Kv-D8 for 72966@debbugs.gnu.org; Thu, 05 Sep 2024 15:18:43 -0400 Original-Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c26852af8fso1267888a12.2 for <72966@debbugs.gnu.org>; Thu, 05 Sep 2024 12:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725563791; x=1726168591; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=atq38V6QPZL1Xr80KPq1mUSULmVfWEOlvs/Kb7/hk34=; b=V9nKZwIWyorbc5MQ+e2YeSssUbcNsky6o4q89OYHbAKHeZaP8gnhWARjokN0KYywez lhsqs9nmOuwdNBZTS1GinXOKpHlahv1rx69Y9UuM/DPxN4YCwNWRWGcQhy8V8vs1dRTh 2JhHWpIR/eJ6hO0SWuPvUOx3nowTHjNeRAKusSKAogj0QTUu0n6oWBTJ61oT3ICUHv3i lTPC3MJNSrd+y9UIdNYOU+AIri9Wh31wgJRgBzgcMBCa+eskwp/njrICvFyBgfVevmB/ cTThECMz/FmvYUh/1rposLRHXZtyOXW4PLoe1Ed7YHJ3kOvdm7zj3Ha9K5VsXhuXgP6B 3Q7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725563791; x=1726168591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=atq38V6QPZL1Xr80KPq1mUSULmVfWEOlvs/Kb7/hk34=; b=fgg8wsydHeRpWTu7euCYwDq7171odl0GigYoh3lV0sz8pNkhAml3+k70xp8sgVK8eH nQbN8ze61OgM6kj1CgLA1ia0kBiks9fwaSUBKUUE2YtufKdZ2Tf+UfMZ4FoX0cFjRIGf elQArau7kHHyNLCJXp1yT46o0yPzxZkvsDKBNnLZtnOrq8OewbVTMKd2P8CSAGDoHPZU b0dOaR2NXyqawlbuy2YjtoQvEQQDg/xiAbfYXJCzioWZ6pl/+MqJ+qpE0dcQa/POdO+5 GUwpYo91s9xZTpJdg3gefjJW9HYvJLnRZmUKV3+270rGna5qv+ylraH7vVJdwnImAIWf JM6A== X-Gm-Message-State: AOJu0YyXb/dJNvRTfs5b2hrbHEOEJ76uiX6IefCIHzvXRFygtaRiwZxd br1c8ACgdCQM/Cp7iV1NiiD+nbTPEudtG1Prr79NSASZIOLWdH6A2wapQw== X-Google-Smtp-Source: AGHT+IHUYo0UYxB6SuvQW9VPEPyiMzZqMWSYry2vJfZCwPtOD8Q2KsG587zDnOiGTkhrn05lsohaAw== X-Received: by 2002:a17:907:60d0:b0:a86:acbe:8d61 with SMTP id a640c23a62f3a-a897fa71c13mr1829108266b.53.1725563790565; Thu, 05 Sep 2024 12:16:30 -0700 (PDT) Original-Received: from fedora.localnet (2-230-139-124.ip202.fastwebnet.it. [2.230.139.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a62083f1asm172150566b.94.2024.09.05.12.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 12:16:30 -0700 (PDT) In-Reply-To: <86bk16877q.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291289 Archived-At: This is a multi-part message in MIME format. --nextPart2272098.vFx2qVVIhK Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hi Eli, I followed your suggestion and moved the CONFIG argument. I also ad= ded=20 a new entry to the NEWS file. Thanks. Vincenzo In data luned=C3=AC 2 settembre 2024 16:23:53 CEST, Eli Zaretskii ha scritt= o: > > From: Vincenzo Pupillo > > Date: Mon, 02 Sep 2024 15:29:23 +0200 > >=20 > > Ciao, > > this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserve= r' > > that allows you to specify an alternative php.ini file to the default (= or > > whatever is specified in 'php-ts-mode-php-config'). >=20 > Thanks. >=20 > > -(defun php-ts-mode-run-php-webserver (&optional port hostname > > document-root - =20 > > router-script num-of-workers) +(defun php-ts-mode-run-php-webserver > > (&optional port > > + hostname > > + document-root > > + router-script > > + config > > + num-of-workers) > >=20 > > "Run PHP built-in web server. >=20 > 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.) >=20 > So please find a backward-compatible way of adding this feature, > perhaps add the new CONFIG argument as the last one? >=20 > Also, I think this needs a NEWS entry describing the change in > behavior. --nextPart2272098.vFx2qVVIhK Content-Disposition: attachment; filename="0001-Support-for-custom-php.ini-for-the-built-in-PHP-web-.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-Support-for-custom-php.ini-for-the-built-in-PHP-web-.patch" >From ae9182be63bfa8625c8c8486c1856dced4fb9152 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo 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 , otherwise returns the indentation point of the last word before the NODE, plus the @@ -1469,8 +1469,12 @@ php-ts-mode ;;;###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 --nextPart2272098.vFx2qVVIhK--