GNU bug report logs - #61069
30.0.50; comint-copy-old-input should include continuation lines

Previous Next

Package: emacs;

Reported by: Bob Rogers <rogers <at> rgrjr.com>

Date: Thu, 26 Jan 2023 01:44:02 UTC

Severity: normal

Tags: fixed

Found in version 30.0.50

Fixed in version 30.1

Done: Robert Pluim <rpluim <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61069 in the body.
You can then email your comments to 61069 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 01:44:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bob Rogers <rogers <at> rgrjr.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 26 Jan 2023 01:44:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; comint-copy-old-input should include continuation lines
Date: Wed, 25 Jan 2023 17:43:02 -0800
[Message part 1 (text/plain, inline)]
   In a shell-mode buffer with lots of "make" output, there will often
appear commands with continuation lines.  To use them as new input
(e.g. while debugging some bit of makefile logic) requires either
marking and copying multiple lines, or multiple invocations of
comint-copy-old-input (C-RET in shell-mode) to get the complete command.
The attached patch against f0971f94fe42224b4d85bb8b6188d5d805689ddf in
master includes those continuation lines, which seems like a desirable
bit of dwimmery.  However, I may have misunderstood the purpose of the
line-end-position vs. field-end thing.  Also, this assumes shell syntax,
so it may be more appropriate to leave comint-get-old-input-default
alone and give shell-mode its own shell-get-old-input-default function.

					-- Bob Rogers
					   http://www.rgrjr.com/

[comint-get-old-input-default-continuation-lines-1.patch (text/x-patch, inline)]
diff --git a/lisp/comint.el b/lisp/comint.el
index c5589324a14..89c35149022 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2377,7 +2377,7 @@ comint-get-old-input-default
   "Default for `comint-get-old-input'.
 If `comint-use-prompt-regexp' is nil, then either
 return the current input field, if point is on an input field, or the
-current line, if point is on an output field.
+current line, with continuation lines, if point is on an output field.
 If `comint-use-prompt-regexp' is non-nil, then return
 the current line with any initial string matching the regexp
 `comint-prompt-regexp' removed."
@@ -2388,11 +2388,18 @@ comint-get-old-input-default
                                     (setq bof (field-beginning)) 'field))))
 	(field-string-no-properties bof)
       (comint-bol)
-      (buffer-substring-no-properties (point)
-                                      (if (or comint-use-prompt-regexp
-                                              (eq field-prop 'output))
-					  (line-end-position)
-					(field-end))))))
+      (let ((start (point)))
+        (cond ((or comint-use-prompt-regexp
+                   (eq field-prop 'output))
+               (goto-char (line-end-position))
+               ;; Include continuation lines as long as the current
+               ;; line ends with a backslash.
+               (while (and (not (eobp))
+                           (= (char-before) ?\\))
+                 (goto-char (line-end-position 2))))
+              (t
+	       (goto-char (field-end))))
+        (buffer-substring-no-properties start (point))))))
 
 (defun comint-copy-old-input ()
   "Insert after prompt old input at point as new input to be edited.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 07:05:01 GMT) Full text and rfc822 format available.

Message #8 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Thu, 26 Jan 2023 09:04:34 +0200
> From: Bob Rogers <rogers <at> rgrjr.com>
> Date: Wed, 25 Jan 2023 17:43:02 -0800
> 
>    In a shell-mode buffer with lots of "make" output, there will often
> appear commands with continuation lines.  To use them as new input
> (e.g. while debugging some bit of makefile logic) requires either
> marking and copying multiple lines, or multiple invocations of
> comint-copy-old-input (C-RET in shell-mode) to get the complete command.
> The attached patch against f0971f94fe42224b4d85bb8b6188d5d805689ddf in
> master includes those continuation lines, which seems like a desirable
> bit of dwimmery.  However, I may have misunderstood the purpose of the
> line-end-position vs. field-end thing.  Also, this assumes shell syntax,
> so it may be more appropriate to leave comint-get-old-input-default
> alone and give shell-mode its own shell-get-old-input-default function.

I don't understand: line-end-position already reports the entire line,
including continuation lines.  So could you explain the problem with
the current code in more detail, please?

> +               ;; Include continuation lines as long as the current
> +               ;; line ends with a backslash.
> +               (while (and (not (eobp))
> +                           (= (char-before) ?\\))
> +                 (goto-char (line-end-position 2))))

Or maybe I don't understand what is this "backslash" business is
about?  AFAICT, the "backslashes" shown for long lines of Make output
are those produced by the Emacs display, not by the shell, so the code
you want to change should already take care of that.

What am I missing?  Could you please show an example of "long Make
output" where the current code doesn't DTRT, so we'd be on the same
page wrt the problem?

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 07:34:02 GMT) Full text and rfc822 format available.

Message #11 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Wed, 25 Jan 2023 23:33:42 -0800
   From: Eli Zaretskii <eliz <at> gnu.org>
   Date: Thu, 26 Jan 2023 09:04:34 +0200

   > From: Bob Rogers <rogers <at> rgrjr.com>
   > Date: Wed, 25 Jan 2023 17:43:02 -0800
   > 
   >    In a shell-mode buffer with lots of "make" output, there will often
   > appear commands with continuation lines.  To use them as new input
   > (e.g. while debugging some bit of makefile logic) requires either
   > marking and copying multiple lines, or multiple invocations of
   > comint-copy-old-input (C-RET in shell-mode) to get the complete command.
   > The attached patch against f0971f94fe42224b4d85bb8b6188d5d805689ddf in
   > master includes those continuation lines, which seems like a desirable
   > bit of dwimmery.  However, I may have misunderstood the purpose of the
   > line-end-position vs. field-end thing.  Also, this assumes shell syntax,
   > so it may be more appropriate to leave comint-get-old-input-default
   > alone and give shell-mode its own shell-get-old-input-default function.

   I don't understand: line-end-position already reports the entire line,
   including continuation lines.  So could you explain the problem with
   the current code in more detail, please?

I'm speaking of shell continuation lines, where a command is broken
across multiple physical lines with backslashes.  Perhaps you think I am
referring to display line wrapping; is where we are miscommunicating?

   > +               ;; Include continuation lines as long as the current
   > +               ;; line ends with a backslash.
   > +               (while (and (not (eobp))
   > +                           (= (char-before) ?\\))
   > +                 (goto-char (line-end-position 2))))

   Or maybe I don't understand what is this "backslash" business is
   about?  AFAICT, the "backslashes" shown for long lines of Make output
   are those produced by the Emacs display, not by the shell, so the code
   you want to change should already take care of that.

   What am I missing?  Could you please show an example of "long Make
   output" where the current code doesn't DTRT, so we'd be on the same
   page wrt the problem?

   Thanks.

Here's an example from building emacs:

	. . .
	rm -f emacs && cp -f temacs emacs
	LC_ALL=C ./temacs -batch  -l loadup --temacs=pdump \
		--bin-dest /usr/local/bin/ --eln-dest /usr/local/lib64/emacs/30.0.50/
	Loading loadup.el (source)...
	Dump mode: pdump
	. . .

My thought is that C-RET on the "./temacs -batch" line in a *shell*
buffer should take both that line and the next.

					-- Bob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 08:13:02 GMT) Full text and rfc822 format available.

Message #14 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Thu, 26 Jan 2023 10:12:49 +0200
> From: Bob Rogers <rogers <at> rgrjr.com>
> Date: Wed, 25 Jan 2023 23:33:42 -0800
> Cc: 61069 <at> debbugs.gnu.org
> 
>    Or maybe I don't understand what is this "backslash" business is
>    about?  AFAICT, the "backslashes" shown for long lines of Make output
>    are those produced by the Emacs display, not by the shell, so the code
>    you want to change should already take care of that.
> 
>    What am I missing?  Could you please show an example of "long Make
>    output" where the current code doesn't DTRT, so we'd be on the same
>    page wrt the problem?
> 
>    Thanks.
> 
> Here's an example from building emacs:
> 
> 	. . .
> 	rm -f emacs && cp -f temacs emacs
> 	LC_ALL=C ./temacs -batch  -l loadup --temacs=pdump \
> 		--bin-dest /usr/local/bin/ --eln-dest /usr/local/lib64/emacs/30.0.50/
> 	Loading loadup.el (source)...
> 	Dump mode: pdump
> 	. . .

Oh, you mean the backslashes that come from the Makefile itself, like
the one after "=pdump"?

> My thought is that C-RET on the "./temacs -batch" line in a *shell*
> buffer should take both that line and the next.

That has to be an optional feature, probably off by default.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 08:40:02 GMT) Full text and rfc822 format available.

Message #17 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Thu, 26 Jan 2023 00:38:56 -0800
   From: Eli Zaretskii <eliz <at> gnu.org>
   Date: Thu, 26 Jan 2023 10:12:49 +0200

   > From: Bob Rogers <rogers <at> rgrjr.com>
   > Date: Wed, 25 Jan 2023 23:33:42 -0800
   > Cc: 61069 <at> debbugs.gnu.org

   > Here's an example from building emacs:
   > 
   > 	. . .
   > 	rm -f emacs && cp -f temacs emacs
   > 	LC_ALL=C ./temacs -batch  -l loadup --temacs=pdump \
   > 		--bin-dest /usr/local/bin/ --eln-dest /usr/local/lib64/emacs/30.0.50/
   > 	Loading loadup.el (source)...
   > 	Dump mode: pdump
   > 	. . .

   Oh, you mean the backslashes that come from the Makefile itself, like
   the one after "=pdump"?

Exactly.

   > My thought is that C-RET on the "./temacs -batch" line in a *shell*
   > buffer should take both that line and the next.

   That has to be an optional feature, probably off by default.

As you like.  Should this be a comint thing, or a shell thing?

					-- Bob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 26 Jan 2023 09:33:02 GMT) Full text and rfc822 format available.

Message #20 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Thu, 26 Jan 2023 11:32:52 +0200
> From: Bob Rogers <rogers <at> rgrjr.com>
> Date: Thu, 26 Jan 2023 00:38:56 -0800
> CC: 61069 <at> debbugs.gnu.org
> 
>    Oh, you mean the backslashes that come from the Makefile itself, like
>    the one after "=pdump"?
> 
> Exactly.
> 
>    > My thought is that C-RET on the "./temacs -batch" line in a *shell*
>    > buffer should take both that line and the next.
> 
>    That has to be an optional feature, probably off by default.
> 
> As you like.  Should this be a comint thing, or a shell thing?

The latter, I think.  Comint handles clients that don't necessarily
use the backslash convention for continuing lines.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Sat, 28 Jan 2023 03:46:02 GMT) Full text and rfc822 format available.

Message #23 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50;
 comint-copy-old-input should include continuation lines
Date: Fri, 27 Jan 2023 19:45:33 -0800
[Message part 1 (text/plain, inline)]
   From: Eli Zaretskii <eliz <at> gnu.org>
   Date: Thu, 26 Jan 2023 11:32:52 +0200

   > From: Bob Rogers <rogers <at> rgrjr.com>
   > Date: Thu, 26 Jan 2023 00:38:56 -0800
   > CC: 61069 <at> debbugs.gnu.org
   >
   > . . .
   > 
   >    > My thought is that C-RET on the "./temacs -batch" line in a
   >    > *shell* buffer should take both that line and the next.
   > 
   >    That has to be an optional feature, probably off by default.
   > 
   > As you like.  Should this be a comint thing, or a shell thing?

   The latter, I think.  Comint handles clients that don't necessarily
   use the backslash convention for continuing lines.

Then the following should fit the bill.  Given that this solution
introduces a defcustom, I imagine it should also have a NEWS item as
well . . .

					-- Bob

[shell-get-old-input-continuation-lines-1.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Mon, 30 Jan 2023 08:26:01 GMT) Full text and rfc822 format available.

Message #26 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Mon, 30 Jan 2023 09:25:19 +0100
>>>>> On Fri, 27 Jan 2023 19:45:33 -0800, Bob Rogers <rogers <at> rgrjr.com> said:
   Bob> Then the following should fit the bill.  Given that this solution
    Bob> introduces a defcustom, I imagine it should also have a NEWS item as
    Bob> well . . .

Yes. And a :version on the new defcustom itself.

    Bob> 					-- Bob

    Bob> * lisp/shell.el (shell-get-old-input-include-continuation-lines): New
    Bob> defcustom (default nil).
    Bob> (shell-get-old-input): Like comint-get-old-input-default but include
    Bob> all continuation lines if the above is true.
    Bob> (shell-mode): Install shell-get-old-input. (bug#61069)

Two spaces after '.'

    Bob> +(defcustom shell-get-old-input-include-continuation-lines nil
    Bob> +  "If non-nil, shell-get-old-input-default includes \"\\\" lines."
    Bob> +  :type 'boolean
    Bob> +  :group 'shell)
    Bob> +

"Whether `shell-get-old-input-default' includes \"\\\" lines."

    Bob> +(defun shell-get-old-input ()
    Bob> +  "Default for `comint-get-old-input' in shell-mode.
    Bob> +If `comint-use-prompt-regexp' is nil, then either
    Bob> +return the current input field, if point is on an input field, or the
    Bob> +current line, if point is on an output field.
    Bob> +If `comint-use-prompt-regexp' is non-nil, then return
    Bob> +the current line with any initial string matching the regexp
    Bob> +`comint-prompt-regexp' removed.  In either case, if
    Bob> +shell-get-old-input-include-continuation-lines is non-nil and the
    Bob> +current line ends with a backslash, the next line is also included and
    Bob> +examined for a backslash, ending with a final line without a backslash."
    Bob> +  (let (field-prop bof)
    Bob> +    (if (and (not comint-use-prompt-regexp)
    Bob> +             ;; Make sure we're in an input rather than output field.
    Bob> +             (not (setq field-prop (get-char-property
    Bob> +                                    (setq bof (field-beginning)) 'field))))
    Bob> +	(field-string-no-properties bof)

Emacs uses spaces only in elisp. We even have a .dir-locals.el
enforcing that.

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Mon, 30 Jan 2023 21:06:02 GMT) Full text and rfc822 format available.

Message #29 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Mon, 30 Jan 2023 13:05:42 -0800
[Message part 1 (text/plain, inline)]
   From: Robert Pluim <rpluim <at> gmail.com>
   Date: Mon, 30 Jan 2023 09:25:19 +0100

   >>>>> On Fri, 27 Jan 2023 19:45:33 -0800, Bob Rogers <rogers <at> rgrjr.com> said:
      Bob> Then the following should fit the bill.  Given that this solution
       Bob> introduces a defcustom, I imagine it should also have a NEWS item as
       Bob> well . . .

   Yes. And a :version on the new defcustom itself.

Right.

       Bob> 					-- Bob

       Bob> * lisp/shell.el (shell-get-old-input-include-continuation-lines): New
       Bob> defcustom (default nil).
       Bob> (shell-get-old-input): Like comint-get-old-input-default but include
       Bob> all continuation lines if the above is true.
       Bob> (shell-mode): Install shell-get-old-input. (bug#61069)

   Two spaces after '.'

Good; I prefer that as well.  (I see I chose a poor example as a commit
log message prototype.)

       Bob> +(defcustom shell-get-old-input-include-continuation-lines nil
       Bob> +  "If non-nil, shell-get-old-input-default includes \"\\\" lines."
       Bob> +  :type 'boolean
       Bob> +  :group 'shell)
       Bob> +

   "Whether `shell-get-old-input-default' includes \"\\\" lines."

Nice; I was wondering how to make that more concise.

       Bob> +(defun shell-get-old-input ()
       Bob> +  . . .
       Bob> +  (let (field-prop bof)
       Bob> +    (if (and (not comint-use-prompt-regexp)
       Bob> +             ;; Make sure we're in an input rather than output field.
       Bob> +             (not (setq field-prop (get-char-property
       Bob> +                                    (setq bof (field-beginning)) 'field))))
       Bob> +	(field-string-no-properties bof)

   Emacs uses spaces only in elisp. We even have a .dir-locals.el
   enforcing that.

   Robert
   -- 

I hadn't noticed that, actually -- either the .dir-locals.el or the
policy.  FWIW, I think both of these tabs are from cutting-and-pasting
from comint.el.

					-- Bob

[shell-get-old-input-continuation-lines-2.patch (text/x-patch, inline)]
* lisp/shell.el (shell-get-old-input-include-continuation-lines): New
defcustom (default nil).
(shell-get-old-input): Like comint-get-old-input-default but include
all continuation lines if the above is true.
(shell-mode): Install shell-get-old-input.  (bug#61069)

diff --git a/lisp/shell.el b/lisp/shell.el
index 5cf108bfa3b..31fb98c0176 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -366,6 +366,12 @@ shell-has-auto-cd
   :group 'shell-directories
   :version "28.1")
 
+(defcustom shell-get-old-input-include-continuation-lines nil
+  "Whether shell-get-old-input-default includes \"\\\" lines."
+  :type 'boolean
+  :group 'shell
+  :version "30.1")
+
 (defcustom shell-kill-buffer-on-exit nil
   "Kill a shell buffer after the shell process terminates."
   :type 'boolean
@@ -506,6 +512,38 @@ shell--parse-pcomplete-arguments
           (push (mapconcat #'identity (nreverse arg) "") args)))
       (cons (nreverse args) (nreverse begins)))))
 
+(defun shell-get-old-input ()
+  "Default for `comint-get-old-input' in shell-mode.
+If `comint-use-prompt-regexp' is nil, then either
+return the current input field, if point is on an input field, or the
+current line, if point is on an output field.
+If `comint-use-prompt-regexp' is non-nil, then return
+the current line with any initial string matching the regexp
+`comint-prompt-regexp' removed.  In either case, if
+shell-get-old-input-include-continuation-lines is non-nil and the
+current line ends with a backslash, the next line is also included and
+examined for a backslash, ending with a final line without a backslash."
+  (let (field-prop bof)
+    (if (and (not comint-use-prompt-regexp)
+             ;; Make sure we're in an input rather than output field.
+             (not (setq field-prop (get-char-property
+                                    (setq bof (field-beginning)) 'field))))
+        (field-string-no-properties bof)
+      (comint-bol)
+      (let ((start (point)))
+        (cond ((or comint-use-prompt-regexp
+                   (eq field-prop 'output))
+               (goto-char (line-end-position))
+               (when shell-get-old-input-include-continuation-lines
+                 ;; Include continuation lines as long as the current
+                 ;; line ends with a backslash.
+                 (while (and (not (eobp))
+                             (= (char-before) ?\\))
+                   (goto-char (line-end-position 2)))))
+              (t
+               (goto-char (field-end))))
+        (buffer-substring-no-properties start (point))))))
+
 ;;;###autoload
 (defun split-string-shell-command (string)
   "Split STRING (a shell command) into a list of strings.
@@ -642,6 +680,7 @@ shell-mode
   (setq-local font-lock-defaults '(shell-font-lock-keywords t))
   (setq-local shell-dirstack nil)
   (setq-local shell-last-dir nil)
+  (setq-local comint-get-old-input #'shell-get-old-input)
   ;; People expect Shell mode to keep the last line of output at
   ;; window bottom.
   (setq-local scroll-conservatively 101)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Tue, 31 Jan 2023 02:39:02 GMT) Full text and rfc822 format available.

Message #32 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Robert Pluim <rpluim <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>,
 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Mon, 30 Jan 2023 18:38:46 -0800
[Message part 1 (text/plain, inline)]
   From: Bob Rogers <rogers <at> rgrjr.com>
   Date: Mon, 30 Jan 2023 13:05:42 -0800

Oops; try this instead (forgot the NEWS item).

					-- Bob

[shell-get-old-input-continuation-lines-3.patch (text/x-patch, inline)]
* lisp/shell.el (shell-get-old-input-include-continuation-lines): New
defcustom (default nil).
(shell-get-old-input): Like comint-get-old-input-default but include
all continuation lines if the above is true.
(shell-mode): Install shell-get-old-input.  (bug#61069)
* etc/NEWS: Advertise the new defcustom.

diff --git a/etc/NEWS b/etc/NEWS
index 5b8ab06086c..46f0e8bffca 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -163,6 +163,13 @@ this to your configuration:
 After manually editing 'eshell-aliases-file', you can use this command
 to load the edited aliases.
 
+** Shell Mode
+
++++
+*** New variable 'shell-get-old-input-include-continuation-lines'.
+Users can set this variable to tell shell-get-old-input (C-RET) to
+include multiple shell "\" continuation lines from command output.
+
 ** Prog Mode
 
 +++
diff --git a/lisp/shell.el b/lisp/shell.el
index 5cf108bfa3b..31fb98c0176 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -366,6 +366,12 @@ shell-has-auto-cd
   :group 'shell-directories
   :version "28.1")
 
+(defcustom shell-get-old-input-include-continuation-lines nil
+  "Whether shell-get-old-input-default includes \"\\\" lines."
+  :type 'boolean
+  :group 'shell
+  :version "30.1")
+
 (defcustom shell-kill-buffer-on-exit nil
   "Kill a shell buffer after the shell process terminates."
   :type 'boolean
@@ -506,6 +512,38 @@ shell--parse-pcomplete-arguments
           (push (mapconcat #'identity (nreverse arg) "") args)))
       (cons (nreverse args) (nreverse begins)))))
 
+(defun shell-get-old-input ()
+  "Default for `comint-get-old-input' in shell-mode.
+If `comint-use-prompt-regexp' is nil, then either
+return the current input field, if point is on an input field, or the
+current line, if point is on an output field.
+If `comint-use-prompt-regexp' is non-nil, then return
+the current line with any initial string matching the regexp
+`comint-prompt-regexp' removed.  In either case, if
+shell-get-old-input-include-continuation-lines is non-nil and the
+current line ends with a backslash, the next line is also included and
+examined for a backslash, ending with a final line without a backslash."
+  (let (field-prop bof)
+    (if (and (not comint-use-prompt-regexp)
+             ;; Make sure we're in an input rather than output field.
+             (not (setq field-prop (get-char-property
+                                    (setq bof (field-beginning)) 'field))))
+        (field-string-no-properties bof)
+      (comint-bol)
+      (let ((start (point)))
+        (cond ((or comint-use-prompt-regexp
+                   (eq field-prop 'output))
+               (goto-char (line-end-position))
+               (when shell-get-old-input-include-continuation-lines
+                 ;; Include continuation lines as long as the current
+                 ;; line ends with a backslash.
+                 (while (and (not (eobp))
+                             (= (char-before) ?\\))
+                   (goto-char (line-end-position 2)))))
+              (t
+               (goto-char (field-end))))
+        (buffer-substring-no-properties start (point))))))
+
 ;;;###autoload
 (defun split-string-shell-command (string)
   "Split STRING (a shell command) into a list of strings.
@@ -642,6 +680,7 @@ shell-mode
   (setq-local font-lock-defaults '(shell-font-lock-keywords t))
   (setq-local shell-dirstack nil)
   (setq-local shell-last-dir nil)
+  (setq-local comint-get-old-input #'shell-get-old-input)
   ;; People expect Shell mode to keep the last line of output at
   ;; window bottom.
   (setq-local scroll-conservatively 101)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Tue, 31 Jan 2023 09:11:02 GMT) Full text and rfc822 format available.

Message #35 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Tue, 31 Jan 2023 10:10:38 +0100
>>>>> On Mon, 30 Jan 2023 18:38:46 -0800, Bob Rogers <rogers <at> rgrjr.com> said:

    Bob>    From: Bob Rogers <rogers <at> rgrjr.com>
    Bob>    Date: Mon, 30 Jan 2023 13:05:42 -0800

    Bob> Oops; try this instead (forgot the NEWS item).

    Bob> 					-- Bob

3 nits below

    Bob> * lisp/shell.el (shell-get-old-input-include-continuation-lines): New
    Bob> defcustom (default nil).

I normally say what the default is in the NEWS entry

    Bob> (shell-get-old-input): Like comint-get-old-input-default but include
    Bob> all continuation lines if the above is true.
    Bob> (shell-mode): Install shell-get-old-input.  (bug#61069)
    Bob> * etc/NEWS: Advertise the new defcustom.

    Bob> diff --git a/etc/NEWS b/etc/NEWS
    Bob> index 5b8ab06086c..46f0e8bffca 100644
    Bob> --- a/etc/NEWS
    Bob> +++ b/etc/NEWS
    Bob> @@ -163,6 +163,13 @@ this to your configuration:
    Bob>  After manually editing 'eshell-aliases-file', you can use this command
    Bob>  to load the edited aliases.
 
    Bob> +** Shell Mode
    Bob> +
    Bob> ++++
    Bob> +*** New variable 'shell-get-old-input-include-continuation-lines'.
    Bob> +Users can set this variable to tell shell-get-old-input (C-RET) to
    Bob> +include multiple shell "\" continuation lines from command output.
    Bob> +

We call defcustomʼd variables 'user option', not 'variable'

    Bob>  ** Prog Mode
 
    Bob>  +++
    Bob> diff --git a/lisp/shell.el b/lisp/shell.el
    Bob> index 5cf108bfa3b..31fb98c0176 100644
    Bob> --- a/lisp/shell.el
    Bob> +++ b/lisp/shell.el
    Bob> @@ -366,6 +366,12 @@ shell-has-auto-cd
    Bob>    :group 'shell-directories
    Bob>    :version "28.1")
 
    Bob> +(defcustom shell-get-old-input-include-continuation-lines nil
    Bob> +  "Whether shell-get-old-input-default includes \"\\\"
    Bob> lines."

If you say `shell-get-old-input-default', then that becomes a link
which users can follow

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Tue, 31 Jan 2023 19:46:02 GMT) Full text and rfc822 format available.

Message #38 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Tue, 31 Jan 2023 11:45:42 -0800
[Message part 1 (text/plain, inline)]
   From: Robert Pluim <rpluim <at> gmail.com>
   Date: Tue, 31 Jan 2023 10:10:38 +0100

   >>>>> On Mon, 30 Jan 2023 18:38:46 -0800, Bob Rogers <rogers <at> rgrjr.com> said:

       Bob>    From: Bob Rogers <rogers <at> rgrjr.com>
       Bob>    Date: Mon, 30 Jan 2023 13:05:42 -0800

       Bob> Oops; try this instead (forgot the NEWS item).

       Bob> 					-- Bob

   3 nits below

   . . .

   Robert
   -- 

All good nits.

					-- Bob

[shell-get-old-input-continuation-lines-4.patch (text/x-patch, inline)]
* lisp/shell.el (shell-get-old-input-include-continuation-lines): New
defcustom (default nil).
(shell-get-old-input): Like comint-get-old-input-default but include
all continuation lines if the above is true.
(shell-mode): Install shell-get-old-input.  (bug#61069)
* etc/NEWS: Advertise the new defcustom.

diff --git a/etc/NEWS b/etc/NEWS
index 5b8ab06086c..28cec94bea0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -163,6 +163,14 @@ this to your configuration:
 After manually editing 'eshell-aliases-file', you can use this command
 to load the edited aliases.
 
+** Shell Mode
+
++++
+*** New variable 'shell-get-old-input-include-continuation-lines'.
+Users can set this user option to tell shell-get-old-input (C-RET) to
+include multiple shell "\" continuation lines from command output.
+Default is nil.
+
 ** Prog Mode
 
 +++
diff --git a/lisp/shell.el b/lisp/shell.el
index 5cf108bfa3b..7e0cdce86ed 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -366,6 +366,12 @@ shell-has-auto-cd
   :group 'shell-directories
   :version "28.1")
 
+(defcustom shell-get-old-input-include-continuation-lines nil
+  "Whether `shell-get-old-input-default' includes \"\\\" lines."
+  :type 'boolean
+  :group 'shell
+  :version "30.1")
+
 (defcustom shell-kill-buffer-on-exit nil
   "Kill a shell buffer after the shell process terminates."
   :type 'boolean
@@ -506,6 +512,38 @@ shell--parse-pcomplete-arguments
           (push (mapconcat #'identity (nreverse arg) "") args)))
       (cons (nreverse args) (nreverse begins)))))
 
+(defun shell-get-old-input ()
+  "Default for `comint-get-old-input' in shell-mode.
+If `comint-use-prompt-regexp' is nil, then either
+return the current input field, if point is on an input field, or the
+current line, if point is on an output field.
+If `comint-use-prompt-regexp' is non-nil, then return
+the current line with any initial string matching the regexp
+`comint-prompt-regexp' removed.  In either case, if
+shell-get-old-input-include-continuation-lines is non-nil and the
+current line ends with a backslash, the next line is also included and
+examined for a backslash, ending with a final line without a backslash."
+  (let (field-prop bof)
+    (if (and (not comint-use-prompt-regexp)
+             ;; Make sure we're in an input rather than output field.
+             (not (setq field-prop (get-char-property
+                                    (setq bof (field-beginning)) 'field))))
+        (field-string-no-properties bof)
+      (comint-bol)
+      (let ((start (point)))
+        (cond ((or comint-use-prompt-regexp
+                   (eq field-prop 'output))
+               (goto-char (line-end-position))
+               (when shell-get-old-input-include-continuation-lines
+                 ;; Include continuation lines as long as the current
+                 ;; line ends with a backslash.
+                 (while (and (not (eobp))
+                             (= (char-before) ?\\))
+                   (goto-char (line-end-position 2)))))
+              (t
+               (goto-char (field-end))))
+        (buffer-substring-no-properties start (point))))))
+
 ;;;###autoload
 (defun split-string-shell-command (string)
   "Split STRING (a shell command) into a list of strings.
@@ -642,6 +680,7 @@ shell-mode
   (setq-local font-lock-defaults '(shell-font-lock-keywords t))
   (setq-local shell-dirstack nil)
   (setq-local shell-last-dir nil)
+  (setq-local comint-get-old-input #'shell-get-old-input)
   ;; People expect Shell mode to keep the last line of output at
   ;; window bottom.
   (setq-local scroll-conservatively 101)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Thu, 30 Mar 2023 19:53:02 GMT) Full text and rfc822 format available.

Message #41 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Robert Pluim <rpluim <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>,
 61069 <at> debbugs.gnu.org
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Thu, 30 Mar 2023 12:51:53 -0700
   From: Bob Rogers <rogers <at> rgrjr.com>
   Date: Tue, 31 Jan 2023 11:45:42 -0800

      From: Robert Pluim <rpluim <at> gmail.com>
      Date: Tue, 31 Jan 2023 10:10:38 +0100

      . . .

      3 nits below

      Robert
      -- 

   All good nits.

Ping?

					-- Bob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Fri, 31 Mar 2023 08:08:02 GMT) Full text and rfc822 format available.

Message #44 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Fri, 31 Mar 2023 10:07:08 +0200
>>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers <at> rgrjr.com> said:

    Bob> Ping?

    Bob> 					-- Bob

Sorry, I didnʼt realize you were waiting on us. Eli, I can commit this
to master later today.

Thanks

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Fri, 31 Mar 2023 10:52:02 GMT) Full text and rfc822 format available.

Message #47 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 61069 <at> debbugs.gnu.org, rogers <at> rgrjr.com
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Fri, 31 Mar 2023 13:51:37 +0300
> From: Robert Pluim <rpluim <at> gmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  61069 <at> debbugs.gnu.org
> Date: Fri, 31 Mar 2023 10:07:08 +0200
> 
> >>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers <at> rgrjr.com> said:
> 
>     Bob> Ping?
> 
>     Bob> 					-- Bob
> 
> Sorry, I didnʼt realize you were waiting on us. Eli, I can commit this
> to master later today.

Thanks, please do.  However, this:

> +(defcustom shell-get-old-input-include-continuation-lines nil
> +  "Whether `shell-get-old-input-default' includes \"\\\" lines."

seems to refer to a symbol that doesn't exist?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Fri, 31 Mar 2023 13:03:02 GMT) Full text and rfc822 format available.

Message #50 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61069 <at> debbugs.gnu.org, rogers <at> rgrjr.com
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Fri, 31 Mar 2023 15:01:48 +0200
>>>>> On Fri, 31 Mar 2023 13:51:37 +0300, Eli Zaretskii <eliz <at> gnu.org> said:

    >> From: Robert Pluim <rpluim <at> gmail.com>
    >> Cc: Eli Zaretskii <eliz <at> gnu.org>,  61069 <at> debbugs.gnu.org
    >> Date: Fri, 31 Mar 2023 10:07:08 +0200
    >> 
    >> >>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers <at> rgrjr.com> said:
    >> 
    Bob> Ping?
    >> 
    Bob> -- Bob
    >> 
    >> Sorry, I didnʼt realize you were waiting on us. Eli, I can commit this
    >> to master later today.

    Eli> Thanks, please do.  However, this:

    >> +(defcustom shell-get-old-input-include-continuation-lines nil
    >> +  "Whether `shell-get-old-input-default' includes \"\\\" lines."

    Eli> seems to refer to a symbol that doesn't exist?

Yes. I fixed that in my local copy already :-)

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Fri, 31 Mar 2023 13:24:02 GMT) Full text and rfc822 format available.

Message #53 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61069 <at> debbugs.gnu.org, rogers <at> rgrjr.com
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Fri, 31 Mar 2023 15:23:18 +0200
tags 61069 fixed
close 61069 30.1
quit

>>>>> On Fri, 31 Mar 2023 15:01:48 +0200, Robert Pluim <rpluim <at> gmail.com> said:

    Eli> seems to refer to a symbol that doesn't exist?

    Robert> Yes. I fixed that in my local copy already :-)


Closing.
Committed as 6f496105e39

Robert
-- 




Added tag(s) fixed. Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 31 Mar 2023 13:24:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 30.1, send any further explanations to 61069 <at> debbugs.gnu.org and Bob Rogers <rogers <at> rgrjr.com> Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 31 Mar 2023 13:24:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61069; Package emacs. (Sat, 01 Apr 2023 00:16:01 GMT) Full text and rfc822 format available.

Message #60 received at 61069 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 61069 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61069: 30.0.50; comint-copy-old-input should include
 continuation lines
Date: Fri, 31 Mar 2023 17:15:50 -0700
   From: Robert Pluim <rpluim <at> gmail.com>
   Date: Fri, 31 Mar 2023 10:07:08 +0200

   Sorry, I didnʼt realize you were waiting on us . . .

No worries.  (I don't have commit privileges.)

   ================
   From: Robert Pluim <rpluim <at> gmail.com>
   Date: Fri, 31 Mar 2023 15:23:18 +0200

   . . .

   Closing.
   Committed as 6f496105e39

   Robert

Thanks.

					-- Bob




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 29 Apr 2023 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 361 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.