all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bob Rogers <rogers@rgrjr.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 61069@debbugs.gnu.org
Subject: bug#61069: 30.0.50; comint-copy-old-input should include continuation lines
Date: Fri, 27 Jan 2023 19:45:33 -0800	[thread overview]
Message-ID: <25556.39517.23330.591366@orion.rgrjr.com> (raw)
In-Reply-To: <83fsbxej3v.fsf@gnu.org>

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

  reply	other threads:[~2023-01-28  3:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

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

  git send-email \
    --in-reply-to=25556.39517.23330.591366@orion.rgrjr.com \
    --to=rogers@rgrjr.com \
    --cc=61069@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.