unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Davide Masserut via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 56406@debbugs.gnu.org
Subject: bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter
Date: Tue, 05 Jul 2022 20:59:01 +0200	[thread overview]
Message-ID: <87pmijjsi2.fsf@mssdvd.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

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 😀.



In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo 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=/etc --prefix=/usr --libexecdir=/usr/lib
 --localstatedir=/var --with-cairo --with-harfbuzz --with-libsystemd
 --with-modules --with-pgtk --with-native-compilation
 'CFLAGS=-march=native -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -g
 -ffile-prefix-map=/home/davide/src/emacs-mssdvd-git/src=/usr/src/debug'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Send-region-to-the-subshell-specified-by-the-current.patch --]
[-- Type: text/patch, Size: 2131 bytes --]

From 7a79d1e56593dc8fde56f7f950725f5e4f6c96a7 Mon Sep 17 00:00:00 2001
From: Davide Masserut <dm@mssdvd.com>
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


             reply	other threads:[~2022-07-05 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05 18:59 Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-07-06 11:46 ` bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmijjsi2.fsf@mssdvd.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=56406@debbugs.gnu.org \
    --cc=dm@mssdvd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).