[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#61069: 30.0.50; comint-copy-old-input should include continuation li
From: |
Bob Rogers |
Subject: |
bug#61069: 30.0.50; comint-copy-old-input should include continuation lines |
Date: |
Mon, 30 Jan 2023 13:05:42 -0800 |
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
* 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)
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/25
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Eli Zaretskii, 2023/01/26
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/26
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Eli Zaretskii, 2023/01/26
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/26
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Eli Zaretskii, 2023/01/26
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/27
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Robert Pluim, 2023/01/30
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines,
Bob Rogers <=
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/30
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Robert Pluim, 2023/01/31
- bug#61069: 30.0.50; comint-copy-old-input should include continuation lines, Bob Rogers, 2023/01/31