From unknown Sun Jun 22 00:44:11 2025 X-Loop: help-debbugs@gnu.org Subject: bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter Resent-From: Davide Masserut Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Jul 2022 19:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56406 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 56406@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165704755913650 (code B ref -1); Tue, 05 Jul 2022 19:00:02 +0000 Received: (at submit) by debbugs.gnu.org; 5 Jul 2022 18:59:19 +0000 Received: from localhost ([127.0.0.1]:51662 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8nlX-0003Y6-Fe for submit@debbugs.gnu.org; Tue, 05 Jul 2022 14:59:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:58568) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8nlV-0003Xx-Hi for submit@debbugs.gnu.org; Tue, 05 Jul 2022 14:59:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8nlV-0004Az-7k for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2022 14:59:17 -0400 Received: from out0.migadu.com ([94.23.1.103]:18680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8nlS-00070z-CE for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2022 14:59:16 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssdvd.com; s=key1; t=1657047549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=KK3mqiDPz1g/xymhjoBCbtOtrPJJNbej1bEaQWZXAZ0=; b=ruJPpIqVwwrR5xx/W0GAQyLj+jftD0ZonOm50JbBhmgSiQ6NoNZvtwEZ2DUek68HNpRXVp 0xrEyerbvDW0LKxRWNu4WZ6Uo0w7iguMeFxqlQTgQRkNerKTAkVt/7M0W1Iwj8PXhyyqIL 8pZA/zOIQTvzEhAurwBFeZElLBfqZdE3eV1YP91ddRVBy3Ubw680YEDck0oKhjAvgPYlUG bNx4smJsdMZ3Y8RdjuPqorqhmFoPGNITonii7Hpr+I7xC35mXen/ysE3ekD9IfiIQpSFa7 +/o/33fn61lf5W4Tjq7e3YzrW5n6N1iikYJ1cB/fKK1jiCTf7fYjYPaH5SDuOg== From: Davide Masserut Date: Tue, 05 Jul 2022 20:59:01 +0200 Message-ID: <87pmijjsi2.fsf@mssdvd.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: mssdvd.com Received-SPF: pass client-ip=94.23.1.103; envelope-from=dm@mssdvd.com; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tags: patch This patch makes sh-execute-region to send the region to the subshell specified by the current file interpreter. Without it Emacs would run the region using the default user shell which is probably not what you would expect if you are editing scripts made for other shells. Beware that I have not tested it on Windows or TRAMP. BTW it is nice to edit code older than me =F0=9F=98=80. In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, c= airo version 1.17.6) of 2022-07-02 built on T480s Repository revision: b79cfaaf14a7aa7e8bb56fc4063bd007e0edc69a Repository branch: master System Description: Arch Linux Configured using: 'configure --sysconfdir=3D/etc --prefix=3D/usr --libexecdir=3D/usr/lib --localstatedir=3D/var --with-cairo --with-harfbuzz --with-libsystemd --with-modules --with-pgtk --with-native-compilation 'CFLAGS=3D-march=3Dnative -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3D2 -Wformat -Werror=3Dformat-security -fstack-clash-protection -fcf-protection -g -ffile-prefix-map=3D/home/davide/src/emacs-mssdvd-git/src=3D/usr/src/debug' LDFLAGS=3D-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Send-region-to-the-subshell-specified-by-the-current.patch >From 7a79d1e56593dc8fde56f7f950725f5e4f6c96a7 Mon Sep 17 00:00:00 2001 From: Davide Masserut Date: Tue, 5 Jul 2022 20:28:43 +0200 Subject: [PATCH] Send region to the subshell specified by the current file interpreter * sh-script.el (sh-execute-region): Send region to the subshell specified by the current file interpreter. --- lisp/progmodes/sh-script.el | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 75758fd39a..c3e93c397a 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -2410,6 +2410,8 @@ sh-execute-region The working directory is that of the buffer, and only environment variables are already set which is why you can mark a header within the script. +The executed subshell is `sh-shell-file'. + With a positive prefix ARG, instead of sending region, define header from beginning of buffer to point. With a negative prefix ARG, instead of sending region, clear header." @@ -2417,17 +2419,18 @@ sh-execute-region (if flag (setq sh-header-marker (if (> (prefix-numeric-value flag) 0) (point-marker))) - (if sh-header-marker - (save-excursion - (let (buffer-undo-list) - (goto-char sh-header-marker) - (append-to-buffer (current-buffer) start end) - (shell-command-on-region (point-min) - (setq end (+ sh-header-marker - (- end start))) - sh-shell-file) - (delete-region sh-header-marker end))) - (shell-command-on-region start end (concat sh-shell-file " -"))))) + (let ((shell-file-name sh-shell-file)) + (if sh-header-marker + (save-excursion + (let (buffer-undo-list) + (goto-char sh-header-marker) + (append-to-buffer (current-buffer) start end) + (shell-command-on-region (point-min) + (setq end (+ sh-header-marker + (- end start))) + sh-shell-file) + (delete-region sh-header-marker end))) + (shell-command-on-region start end (concat sh-shell-file " -")))))) (defun sh-remember-variable (var) -- 2.37.0 --=-=-=-- From unknown Sun Jun 22 00:44:11 2025 X-Loop: help-debbugs@gnu.org Subject: bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Jul 2022 11:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56406 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Davide Masserut Cc: 56406@debbugs.gnu.org Received: via spool by 56406-submit@debbugs.gnu.org id=B56406.165710797820984 (code B ref 56406); Wed, 06 Jul 2022 11:47:02 +0000 Received: (at 56406) by debbugs.gnu.org; 6 Jul 2022 11:46:18 +0000 Received: from localhost ([127.0.0.1]:52724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o93U2-0005SO-0f for submit@debbugs.gnu.org; Wed, 06 Jul 2022 07:46:18 -0400 Received: from quimby.gnus.org ([95.216.78.240]:54182) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o93U0-0005S8-2C for 56406@debbugs.gnu.org; Wed, 06 Jul 2022 07:46:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID :Date:References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: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=LzzQUPTzAzXpOettlSSkFpMlNbi6QfAGqBSuahCTFR0=; b=dILjOLaCsQtfBQ3M1FU7Y6mbGF CiLn98V5MFP0yBkFWVXAefpBdXXj1Km3Wz+aOObFnmM/USY613jnb471K1RBAO//RygT8HDdZ497u sPIEJ4a42DXF3Q7AUo3m3U8Iab7wflL4zxNFu5dSpzS79Xvc/PBeLllGYksDvBtp9BtQ=; 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 1o93Tr-0004rR-BY; Wed, 06 Jul 2022 13:46:10 +0200 From: Lars Ingebrigtsen In-Reply-To: <87pmijjsi2.fsf@mssdvd.com> (Davide Masserut's message of "Tue, 05 Jul 2022 20:59:01 +0200") References: <87pmijjsi2.fsf@mssdvd.com> X-Now-Playing: Laurie Anderson's _Mister Heartbreak_: "Sharkey's Day" Date: Wed, 06 Jul 2022 13:46:06 +0200 Message-ID: <87h73ujwg1.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Davide Masserut writes: > This patch makes sh-execute-region to send the region to the subshell > specified by the current file interpreter. > > Without it Emacs would run the region using the default user shell which > is p [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Davide Masserut writes: > This patch makes sh-execute-region to send the region to the subshell > specified by the current file interpreter. > > Without it Emacs would run the region using the default user shell which > is probably not what you would expect if you are editing scripts made > for other shells. Makes sense to me; pushed to Emacs 29. > BTW it is nice to edit code older than me =F0=9F=98=80. =F0=9F=98=84 --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 06 07:46:22 2022 Received: (at control) by debbugs.gnu.org; 6 Jul 2022 11:46:22 +0000 Received: from localhost ([127.0.0.1]:52727 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o93U6-0005Sf-7D for submit@debbugs.gnu.org; Wed, 06 Jul 2022 07:46:22 -0400 Received: from quimby.gnus.org ([95.216.78.240]:54196) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o93U4-0005SD-Fu for control@debbugs.gnu.org; Wed, 06 Jul 2022 07:46:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0cBCQOTWlhSB1rRkN7dpbkXzc+mMsn0CkQ1ULMWvfkY=; b=H2j+H4ayxch1rxWhNex1vQ4Ofi hz1sjVahfd55vBRTXpMeoynwsou5eQwD0OA5MQ2mGAF5AqV1i4pGfXdhwcZOPJJuDSy8BZyfDYYjO n0eFaJu5vuIDAgcfsDlR3XQGIvesCWEWlZdEn8Yz1Rwlw80/MX3AUEmCtbDGYw0LeHuo=; 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 1o93Tw-0004rb-Fc for control@debbugs.gnu.org; Wed, 06 Jul 2022 13:46:14 +0200 Date: Wed, 06 Jul 2022 13:46:12 +0200 Message-Id: <87fsjejwfv.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #56406 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 56406 29.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 56406 29.1 quit