From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Davide Masserut via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter Date: Tue, 05 Jul 2022 20:59:01 +0200 Message-ID: <87pmijjsi2.fsf@mssdvd.com> Reply-To: Davide Masserut Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40699"; mail-complaints-to="usenet@ciao.gmane.io" To: 56406@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 05 21:01:06 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 1o8nnE-000ALe-51 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Jul 2022 21:01:04 +0200 Original-Received: from localhost ([::1]:35478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8nnC-00067D-Fr for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Jul 2022 15:01:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8nmF-0005nl-Fc for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2022 15:00:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8nmF-00078j-20 for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2022 15:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o8nmE-0003Zb-Vf for bug-gnu-emacs@gnu.org; Tue, 05 Jul 2022 15:00:02 -0400 X-Loop: help-debbugs@gnu.org 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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.165704755913650 (code B ref -1); Tue, 05 Jul 2022 19:00:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Jul 2022 18:59:19 +0000 Original-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 Original-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 Original-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 Original-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== 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-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:236164 Archived-At: --=-=-= 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 --=-=-=--