unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
@ 2023-01-26  1:43 Bob Rogers
  2023-01-26  7:04 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-26  1:43 UTC (permalink / raw)
  To: 61069

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 817 bytes --]

   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/


[-- Attachment #2: Type: text/x-patch, Size: 1683 bytes --]

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.

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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  1:43 bug#61069: 30.0.50; comint-copy-old-input should include continuation lines Bob Rogers
@ 2023-01-26  7:04 ` Eli Zaretskii
  2023-01-26  7:33   ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2023-01-26  7:04 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069

> From: Bob Rogers <rogers@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.





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  7:04 ` Eli Zaretskii
@ 2023-01-26  7:33   ` Bob Rogers
  2023-01-26  8:12     ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-26  7:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61069

   From: Eli Zaretskii <eliz@gnu.org>
   Date: Thu, 26 Jan 2023 09:04:34 +0200

   > From: Bob Rogers <rogers@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





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  7:33   ` Bob Rogers
@ 2023-01-26  8:12     ` Eli Zaretskii
  2023-01-26  8:38       ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2023-01-26  8:12 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069

> From: Bob Rogers <rogers@rgrjr.com>
> Date: Wed, 25 Jan 2023 23:33:42 -0800
> Cc: 61069@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.





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  8:12     ` Eli Zaretskii
@ 2023-01-26  8:38       ` Bob Rogers
  2023-01-26  9:32         ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-26  8:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61069

   From: Eli Zaretskii <eliz@gnu.org>
   Date: Thu, 26 Jan 2023 10:12:49 +0200

   > From: Bob Rogers <rogers@rgrjr.com>
   > Date: Wed, 25 Jan 2023 23:33:42 -0800
   > Cc: 61069@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





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  8:38       ` Bob Rogers
@ 2023-01-26  9:32         ` Eli Zaretskii
  2023-01-28  3:45           ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2023-01-26  9:32 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069

> From: Bob Rogers <rogers@rgrjr.com>
> Date: Thu, 26 Jan 2023 00:38:56 -0800
> CC: 61069@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.





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-26  9:32         ` Eli Zaretskii
@ 2023-01-28  3:45           ` Bob Rogers
  2023-01-30  8:25             ` Robert Pluim
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-28  3:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61069

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 789 bytes --]

   From: Eli Zaretskii <eliz@gnu.org>
   Date: Thu, 26 Jan 2023 11:32:52 +0200

   > From: Bob Rogers <rogers@rgrjr.com>
   > Date: Thu, 26 Jan 2023 00:38:56 -0800
   > CC: 61069@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


[-- Attachment #2: Type: application/octet-stream, Size: 3002 bytes --]

* 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..877c48097a8 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -366,6 +366,11 @@ shell-has-auto-cd
   :group 'shell-directories
   :version "28.1")
 
+(defcustom shell-get-old-input-include-continuation-lines nil
+  "If non-nil, shell-get-old-input-default includes \"\\\" lines."
+  :type 'boolean
+  :group 'shell)
+
 (defcustom shell-kill-buffer-on-exit nil
   "Kill a shell buffer after the shell process terminates."
   :type 'boolean
@@ -506,6 +511,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 +679,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)

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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-28  3:45           ` Bob Rogers
@ 2023-01-30  8:25             ` Robert Pluim
  2023-01-30 21:05               ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Pluim @ 2023-01-30  8:25 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069, Eli Zaretskii

>>>>> On Fri, 27 Jan 2023 19:45:33 -0800, Bob Rogers <rogers@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
-- 





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-30  8:25             ` Robert Pluim
@ 2023-01-30 21:05               ` Bob Rogers
  2023-01-31  2:38                 ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-30 21:05 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 61069, Eli Zaretskii

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 1948 bytes --]

   From: Robert Pluim <rpluim@gmail.com>
   Date: Mon, 30 Jan 2023 09:25:19 +0100

   >>>>> On Fri, 27 Jan 2023 19:45:33 -0800, Bob Rogers <rogers@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


[-- Attachment #2: Type: text/x-patch, Size: 3032 bytes --]

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

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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-30 21:05               ` Bob Rogers
@ 2023-01-31  2:38                 ` Bob Rogers
  2023-01-31  9:10                   ` Robert Pluim
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-31  2:38 UTC (permalink / raw)
  To: Robert Pluim, Eli Zaretskii, 61069

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 142 bytes --]

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

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

					-- Bob


[-- Attachment #2: Type: text/x-patch, Size: 3575 bytes --]

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

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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-31  2:38                 ` Bob Rogers
@ 2023-01-31  9:10                   ` Robert Pluim
  2023-01-31 19:45                     ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Pluim @ 2023-01-31  9:10 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069, Eli Zaretskii

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

    Bob>    From: Bob Rogers <rogers@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
-- 





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-31  9:10                   ` Robert Pluim
@ 2023-01-31 19:45                     ` Bob Rogers
  2023-03-30 19:51                       ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-01-31 19:45 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 61069, Eli Zaretskii

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 429 bytes --]

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

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

       Bob>    From: Bob Rogers <rogers@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


[-- Attachment #2: Type: text/x-patch, Size: 3597 bytes --]

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

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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-01-31 19:45                     ` Bob Rogers
@ 2023-03-30 19:51                       ` Bob Rogers
  2023-03-31  8:07                         ` Robert Pluim
  0 siblings, 1 reply; 18+ messages in thread
From: Bob Rogers @ 2023-03-30 19:51 UTC (permalink / raw)
  To: Robert Pluim, Eli Zaretskii, 61069

   From: Bob Rogers <rogers@rgrjr.com>
   Date: Tue, 31 Jan 2023 11:45:42 -0800

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

      . . .

      3 nits below

      Robert
      -- 

   All good nits.

Ping?

					-- Bob





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-03-30 19:51                       ` Bob Rogers
@ 2023-03-31  8:07                         ` Robert Pluim
  2023-03-31 10:51                           ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Pluim @ 2023-03-31  8:07 UTC (permalink / raw)
  To: Bob Rogers; +Cc: 61069, Eli Zaretskii

>>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers@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
-- 





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-03-31  8:07                         ` Robert Pluim
@ 2023-03-31 10:51                           ` Eli Zaretskii
  2023-03-31 13:01                             ` Robert Pluim
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2023-03-31 10:51 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 61069, rogers

> From: Robert Pluim <rpluim@gmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>,  61069@debbugs.gnu.org
> Date: Fri, 31 Mar 2023 10:07:08 +0200
> 
> >>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers@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?





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-03-31 10:51                           ` Eli Zaretskii
@ 2023-03-31 13:01                             ` Robert Pluim
  2023-03-31 13:23                               ` Robert Pluim
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Pluim @ 2023-03-31 13:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61069, rogers

>>>>> On Fri, 31 Mar 2023 13:51:37 +0300, Eli Zaretskii <eliz@gnu.org> said:

    >> From: Robert Pluim <rpluim@gmail.com>
    >> Cc: Eli Zaretskii <eliz@gnu.org>,  61069@debbugs.gnu.org
    >> Date: Fri, 31 Mar 2023 10:07:08 +0200
    >> 
    >> >>>>> On Thu, 30 Mar 2023 12:51:53 -0700, Bob Rogers <rogers@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
-- 





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-03-31 13:01                             ` Robert Pluim
@ 2023-03-31 13:23                               ` Robert Pluim
  2023-04-01  0:15                                 ` Bob Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Pluim @ 2023-03-31 13:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61069, rogers

tags 61069 fixed
close 61069 30.1
quit

>>>>> On Fri, 31 Mar 2023 15:01:48 +0200, Robert Pluim <rpluim@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
-- 





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

* bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
  2023-03-31 13:23                               ` Robert Pluim
@ 2023-04-01  0:15                                 ` Bob Rogers
  0 siblings, 0 replies; 18+ messages in thread
From: Bob Rogers @ 2023-04-01  0:15 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 61069, Eli Zaretskii

   From: Robert Pluim <rpluim@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@gmail.com>
   Date: Fri, 31 Mar 2023 15:23:18 +0200

   . . .

   Closing.
   Committed as 6f496105e39

   Robert

Thanks.

					-- Bob





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

end of thread, other threads:[~2023-04-01  0:15 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-26  1:43 bug#61069: 30.0.50; comint-copy-old-input should include continuation lines Bob Rogers
2023-01-26  7:04 ` Eli Zaretskii
2023-01-26  7:33   ` Bob Rogers
2023-01-26  8:12     ` Eli Zaretskii
2023-01-26  8:38       ` Bob Rogers
2023-01-26  9:32         ` Eli Zaretskii
2023-01-28  3:45           ` Bob Rogers
2023-01-30  8:25             ` Robert Pluim
2023-01-30 21:05               ` Bob Rogers
2023-01-31  2:38                 ` Bob Rogers
2023-01-31  9:10                   ` Robert Pluim
2023-01-31 19:45                     ` Bob Rogers
2023-03-30 19:51                       ` Bob Rogers
2023-03-31  8:07                         ` Robert Pluim
2023-03-31 10:51                           ` Eli Zaretskii
2023-03-31 13:01                             ` Robert Pluim
2023-03-31 13:23                               ` Robert Pluim
2023-04-01  0:15                                 ` Bob Rogers

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