From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.bugs,gmane.emacs.devel Subject: bug#28691: [PATCH] Add file name handler support for 'make-process' (Bug#28691) Date: Mon, 17 Dec 2018 20:20:11 +0100 Message-ID: <20181217192011.17783-1-phst@google.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1545074356 27218 195.159.176.226 (17 Dec 2018 19:19:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Dec 2018 19:19:16 +0000 (UTC) Cc: Philipp Stephani To: emacs-devel@gnu.org, Michael Albinus , 28691@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 17 20:19:11 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYyPy-0006s6-4r for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Dec 2018 20:19:06 +0100 Original-Received: from localhost ([::1]:48630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYyS4-0006nU-MS for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Dec 2018 14:21:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYyRu-0006lw-DO for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2018 14:21:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYyRq-0007d0-82 for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2018 14:21:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47897) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gYyRq-0007cq-3C for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2018 14:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gYyRp-00089Q-UO for bug-gnu-emacs@gnu.org; Mon, 17 Dec 2018 14:21:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philipp Stephani Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Dec 2018 19:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28691 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 28691-submit@debbugs.gnu.org id=B28691.154507444131296 (code B ref 28691); Mon, 17 Dec 2018 19:21:01 +0000 Original-Received: (at 28691) by debbugs.gnu.org; 17 Dec 2018 19:20:41 +0000 Original-Received: from localhost ([127.0.0.1]:52155 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYyRU-00088h-9f for submit@debbugs.gnu.org; Mon, 17 Dec 2018 14:20:41 -0500 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:37019) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYyRS-00088S-Gs for 28691@debbugs.gnu.org; Mon, 17 Dec 2018 14:20:39 -0500 Original-Received: by mail-wm1-f49.google.com with SMTP id g67so367104wmd.2 for <28691@debbugs.gnu.org>; Mon, 17 Dec 2018 11:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1676kd7OqYi6h4t6lC3KNxEjd54EArpog8SZEwD40mg=; b=vhi2zB0WMruuhQA3p2/pGc7NyxqZHtN0WggMOnKOH2AH5zjUqZxuyBd1OsGVEzPRCA K2WQDYKvjx2d8AkxvhAITsE+W3p3eF6dawiEfpyaRa+rQNMLLfsvACnY93oWiO08UU0s VL221ekA1oKvcurD1iRCHrdc4FQJMLBKS0u+Uv1nN1LvLgyeUxRTW5Km0iwtPL+XkXvO 4bfw+e9aGe9xqUYLHV4POJWLg1qqH4FZhBnfGYIuYQSruC9cWLwbHWEbWljbbstzLDlz 8CLqONP973jDUOG8Ru5g+4a2H4hfLV/7dWhq0ml59T2tR8rqs/klNz1L/sFuVn/rlbx4 EjkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1676kd7OqYi6h4t6lC3KNxEjd54EArpog8SZEwD40mg=; b=PVo6pd5eehxX68+kYy1hWwqdvq0ToNdAEJBIV+I1imJW/l8NA0yYG4/LuIm0lcZA9l JN0mb9z7kl/HLxh3pVTmE7IYV3cF10s/rHWV9e+7jo3517evOxIV4stwBcWuWyVCT7VO j30vFc3Y8SFALRVm79p9K7Ca8rzSBr0nfbNNcGU/ZCqIgvUNkAcHladx+lfn+692ylb4 PzbuaS9jLbACem39F/1CtreZYXUvvYEqdytJ1NcT8n72D8bLn9z6aU3PSFTYEEi7SzCY PlGoYmC0+mjCh62iZTlqMbjSUlsGWUW1DOuJ41GWK9aHf0dytbIjaGE0YqoU8650RkVB qOkw== X-Gm-Message-State: AA+aEWZE1gha5sOgd90EnTLIxIFBN7yanucTsZl0Q7LWwNXgj1BpwJUk G1aI/EJmr9EZg361yCLyKxU= X-Google-Smtp-Source: AFSGD/XQyEhYhVEaLfRV4BDNIt3YFjnHj1uU0jLtBT7q0C/ZI4DuqEki44QGdTx2R842VWwe4Q0HDg== X-Received: by 2002:a1c:c90b:: with SMTP id f11mr333816wmb.33.1545074432576; Mon, 17 Dec 2018 11:20:32 -0800 (PST) Original-Received: from phst-glaptop.cm.cablesurf.de ([2001:4c50:25a:f300:2a16:adff:fe49:52c8]) by smtp.gmail.com with ESMTPSA id f137sm62245wmg.29.2018.12.17.11.20.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 11:20:31 -0800 (PST) X-Google-Original-From: Philipp Stephani X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153528 gmane.emacs.devel:231891 Archived-At: * src/process.c (Fmake_process): Add new keyword argument ':file-handler'. (syms_of_process) : Define new symbols. * lisp/files.el (file-name-non-special): Add support for 'make-process'. * test/src/process-tests.el (make-process/file-handler/found) (make-process/file-handler/not-found) (make-process/file-handler/disable): New unit tests. (process-tests--file-handler): New helper function. * test/lisp/files-tests.el (files-tests-file-name-non-special-make-process): New unit test. * doc/lispref/files.texi (Magic File Names): Document that 'make-process' can invoke file name handlers. * doc/lispref/processes.texi (Asynchronous Processes): Document ':file-handlers' argument to 'make-process'. --- doc/lispref/files.texi | 2 ++ doc/lispref/processes.texi | 9 ++++++-- etc/NEWS | 5 ++++ lisp/files.el | 11 +++++++-- src/process.c | 16 +++++++++++++ test/lisp/files-tests.el | 9 ++++++++ test/src/process-tests.el | 47 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 95 insertions(+), 4 deletions(-) diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index b795864815..00e7fc1841 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -3171,6 +3171,7 @@ Magic File Names @code{make-directory}, @code{make-directory-internal}, @code{make-nearby-temp-file}, +@code{make-process}, @code{make-symbolic-link},@* @code{process-file}, @code{rename-file}, @code{set-file-acl}, @code{set-file-modes}, @@ -3227,6 +3228,7 @@ Magic File Names @code{make-auto-save-file-name}, @code{make-direc@discretionary{}{}{}tory}, @code{make-direc@discretionary{}{}{}tory-internal}, +@code{make-process}, @code{make-symbolic-link}, @code{process-file}, @code{rename-file}, @code{set-file-acl}, @code{set-file-modes}, diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index d88c7fbe62..7ca0ac475f 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -696,6 +696,11 @@ Asynchronous Processes created with @code{make-pipe-process}, described below. If @var{stderr} is @code{nil}, standard error is mixed with standard output, and both are sent to @var{buffer} or @var{filter}. + +@item :file-handler @var{file-handler} +If @var{file-handler} is non-@code{nil}, then look for a file name +handler for the current buffer's @code{default-directory}. If there +is no such handler, proceed as if @var{file-handler} were nil. @end table The original argument list, modified with the actual connection @@ -704,8 +709,8 @@ Asynchronous Processes The current working directory of the subprocess is set to the current buffer's value of @code{default-directory} if that is local (as determined by `unhandled-file-name-directory'), or "~" otherwise. If -you want to run a process in a remote directory use -@code{start-file-process}. +you want to run a process in a remote directory, pass +@code{:file-handler t} to @code{make-process}. @end defun @defun make-pipe-process &rest args diff --git a/etc/NEWS b/etc/NEWS index c88f6ef5ca..942b6501a8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1407,6 +1407,11 @@ un-obsoleting it. +++ ** New function 'group-name' returns a group name corresponding to GID. +** 'make-process' now takes a keyword argument ':file-handler'; if +that is non-nil, it will look for a file name handler for the current +buffer's 'default-directory'. That way 'make-process' can start +remote processes. + * Changes in Emacs 27.1 on Non-Free Operating Systems diff --git a/lisp/files.el b/lisp/files.el index fb6cf0193a..448df62710 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7103,7 +7103,8 @@ file-name-non-special (default-directory (if (memq operation '(insert-directory process-file start-file-process - shell-command temporary-file-directory)) + make-process shell-command + temporary-file-directory)) (directory-file-name (expand-file-name (unhandled-file-name-directory default-directory))) @@ -7151,7 +7152,13 @@ file-name-non-special ;; These file-notify-* operations take a ;; descriptor. (file-notify-rm-watch) - (file-notify-valid-p))) + (file-notify-valid-p) + ;; `make-process' uses keyword arguments and + ;; doesn't mangle its filenames in any way. + ;; It already strips /: from the binary + ;; filename, so we don't have to do this + ;; here. + (make-process))) ;; For all other operations, treat the first ;; argument only as the file name. '(nil 0)))) diff --git a/src/process.c b/src/process.c index 8e0b2349f9..80c700a09b 100644 --- a/src/process.c +++ b/src/process.c @@ -1661,6 +1661,10 @@ to the standard error of subprocess. Specifying this implies `:connection-type' is set to `pipe'. If STDERR is nil, standard error is mixed with standard output and sent to BUFFER or FILTER. +:file-handler FILE-HANDLER -- If FILE-HANDLER is non-nil, then look +for a file name handler for the current buffer's `default-directory'. +If there is no such handler, proceed as if FILE-HANDLER were nil. + usage: (make-process &rest ARGS) */) (ptrdiff_t nargs, Lisp_Object *args) { @@ -1674,6 +1678,15 @@ usage: (make-process &rest ARGS) */) /* Save arguments for process-contact and clone-process. */ contact = Flist (nargs, args); + if (!NILP (Fplist_get (contact, QCfile_handler))) + { + Lisp_Object file_handler + = Ffind_file_name_handler (BVAR (current_buffer, directory), + Qmake_process); + if (!NILP (file_handler)) + return CALLN (Fapply, file_handler, Qmake_process, contact); + } + buffer = Fplist_get (contact, QCbuffer); if (!NILP (buffer)) buffer = Fget_buffer_create (buffer); @@ -8098,6 +8111,8 @@ init_process_emacs (int sockfd) void syms_of_process (void) { + DEFSYM (Qmake_process, "make-process"); + #ifdef subprocesses DEFSYM (Qprocessp, "processp"); @@ -8138,6 +8153,7 @@ syms_of_process (void) DEFSYM (Qreal, "real"); DEFSYM (Qnetwork, "network"); DEFSYM (Qserial, "serial"); + DEFSYM (QCfile_handler, ":file-handler"); DEFSYM (QCbuffer, ":buffer"); DEFSYM (QChost, ":host"); DEFSYM (QCservice, ":service"); diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 3b192ee872..708d6d4659 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1109,6 +1109,15 @@ files-tests-file-attributes-equal (with-temp-buffer (write-region nil nil nospecial nil :visit)))) +(ert-deftest files-tests-file-name-non-special-make-process () + "Check that the ‘:file-handler’ argument of ‘make-process’ +works as expected if the default directory is quoted." + (skip-unless (file-accessible-directory-p "/:/bin/")) + (let ((default-directory "/:/bin/")) + (should (processp (make-process :name "name" + :command '("/:/bin/true") + :file-handler t))))) + (ert-deftest files-tests--insert-directory-wildcard-in-dir-p () (let ((alist (list (cons "/home/user/*/.txt" (cons "/home/user/" "*/.txt")) (cons "/home/user/.txt" nil) diff --git a/test/src/process-tests.el b/test/src/process-tests.el index 551b34ff37..3587e3bfd8 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el @@ -215,5 +215,52 @@ process-tests--mixable (string-to-list "stdout\n") (string-to-list "stderr\n")))))) +(ert-deftest make-process/file-handler/found () + "Check that the ‘:file-handler’ argument of ‘make-process’ +works as expected if a file handler is found." + (let ((file-handler-calls 0)) + (cl-flet ((file-handler + (&rest args) + (should (equal default-directory "test-handler:/dir/")) + (should (equal args '(make-process :name "name" + :command ("/bin/true") + :file-handler t))) + (cl-incf file-handler-calls) + 'fake-process)) + (let ((file-name-handler-alist (list (cons (rx bos "test-handler:") + #'file-handler))) + (default-directory "test-handler:/dir/")) + (should (eq (make-process :name "name" + :command '("/bin/true") + :file-handler t) + 'fake-process)) + (should (= file-handler-calls 1)))))) + +(ert-deftest make-process/file-handler/not-found () + "Check that the ‘:file-handler’ argument of ‘make-process’ +works as expected if no file handler is found." + (skip-unless (file-accessible-directory-p "/bin/")) + (let ((default-directory "/bin/")) + (should (processp (make-process :name "name" + :command '("/bin/true") + :file-handler t))))) + +(ert-deftest make-process/file-handler/disable () + "Check ‘make-process’ works as expected if it shouldn’t use the +file handler." + (let ((file-name-handler-alist (list (cons (rx bos "test-handler:") + #'process-tests--file-handler))) + (default-directory "test-handler:/dir/")) + (should (processp (make-process :name "name" + :command '("/bin/true")))))) + +(defun process-tests--file-handler (operation &rest _args) + (cl-ecase operation + (unhandled-file-name-directory "/") + (make-process (ert-fail "file handler called unexpectedly")))) + +(put #'process-tests--file-handler 'operations + '(unhandled-file-name-directory make-process)) + (provide 'process-tests) ;; process-tests.el ends here. -- 2.20.0.405.gbc1bbc6f85-goog