From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#57795: FIXME about save-match-data in shell-command Date: Wed, 14 Sep 2022 15:25:35 +0200 Message-ID: <87o7vi84vk.fsf@gnus.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15302"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 57795@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 14 15:51:03 2022 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 1oYSn9-0003kg-Eb for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 14 Sep 2022 15:51:03 +0200 Original-Received: from localhost ([::1]:43156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSn8-00074U-C7 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 14 Sep 2022 09:51:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSOy-0002Wt-74 for bug-gnu-emacs@gnu.org; Wed, 14 Sep 2022 09:26:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37234) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSOw-0000za-NC for bug-gnu-emacs@gnu.org; Wed, 14 Sep 2022 09:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oYSOw-0003gD-Hl for bug-gnu-emacs@gnu.org; Wed, 14 Sep 2022 09:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Sep 2022 13:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57795 X-GNU-PR-Package: emacs Original-Received: via spool by 57795-submit@debbugs.gnu.org id=B57795.166316194614121 (code B ref 57795); Wed, 14 Sep 2022 13:26:02 +0000 Original-Received: (at 57795) by debbugs.gnu.org; 14 Sep 2022 13:25:46 +0000 Original-Received: from localhost ([127.0.0.1]:54166 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYSOg-0003fh-DS for submit@debbugs.gnu.org; Wed, 14 Sep 2022 09:25:46 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:48984) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYSOe-0003fT-PI for 57795@debbugs.gnu.org; Wed, 14 Sep 2022 09:25:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0u/w2mqkdUTpYQMQB4NW6JJwtxjfbGuoCmerMz1CQT8=; b=J0Xa73/bRNkYMx+vJdkKSk7fYY h9eDZg0hliJrCprUt00nTsOiQxbqFnUKx0rGX/lyzr9prV3B40VixFbICW3Xm/UWk2s5kBBsiZ6Nf YEGMZwHecQsuCZ4eY4SpEfQXhETc18jynK/C3OmWdV/NR6IEn/qln0hN90NGXhZGoaiw=; Original-Received: from [84.212.220.105] (helo=joga) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYSOV-0006qE-O5; Wed, 14 Sep 2022 15:25:37 +0200 In-Reply-To: (Stefan Kangas's message of "Wed, 14 Sep 2022 00:36:30 -0700") X-Now-Playing: Joan as Police Woman's _Joanthology (3)_: "The Classic (Live at the BBC)" 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" Xref: news.gmane.io gmane.emacs.bugs:242460 Archived-At: Stefan Kangas writes: > In `shell-command', we have the following comment: > > ;; Preserve the match data in case called from a program. > ;; FIXME: It'd be ridiculous for an Elisp function to call > ;; shell-command and assume that it won't mess the match-data! > > I think we should decide to either get rid of the FIXME, or to take the > plunge and remove `save-match-data'. (Note that the latter has been > there since 1995.) Hm -- I originally thought that removing that save-match-data would lead to subtle errors in callers that depend on this behaviour. But... there's also code like (let ((handler (find-file-name-handler (directory-file-name default-directory) 'shell-command))) (if handler (funcall handler 'shell-command command output-buffer error-buffer) (if (and output-buffer (not (string-match "[ \t]*&[ \t]*\\'" command)) before that save-match-data, so the match data will be overwritten in many cases anyway. The code was (originally in 1991): +(defun shell-command (command &optional flag) + "Execute string COMMAND in inferior shell; display output, if any. +If COMMAND ends in ampersand, execute it asynchronously. + +Optional second arg non-nil (prefix arg, if interactive) +means insert output in current buffer after point (leave mark after it). +This cannot be done asynchronously." + (interactive (list (read-string "Shell command: " last-shell-command) + current-prefix-arg)) + (if flag + (progn (barf-if-buffer-read-only) + (push-mark) + ;; We do not use -f for csh; we will not support broken use of + ;; .cshrcs. Even the BSD csh manual says to use + ;; "if ($?prompt) exit" before things which are not useful + ;; non-interactively. Besides, if someone wants their other + ;; aliases for shell commands then they can still have them. + (call-process shell-file-name nil t nil + "-c" command) + (exchange-point-and-mark)) + ;; Preserve the match data in case called from a program. + (let ((data (match-data))) And here we see that the command does really preserve the match data in all circumstances -- but that has been lost over the years. So I think removing the save-match-data should probably not lead to any regressions, so I've now removed it.