unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter
@ 2022-07-05 18:59 Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-06 11:46 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-05 18:59 UTC (permalink / raw)
  To: 56406

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter
  2022-07-05 18:59 bug#56406: [PATCH] Send region to the subshell specified by the current file interpreter Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-06 11:46 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-06 11:46 UTC (permalink / raw)
  To: Davide Masserut; +Cc: 56406

Davide Masserut <dm@mssdvd.com> 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 😀.

😄

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-06 11:46 UTC | newest]

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

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