[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multi-line input (was: Losing minibuffer input)

From: Juri Linkov
Subject: Multi-line input (was: Losing minibuffer input)
Date: Fri, 05 Dec 2014 02:38:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (x86_64-pc-linux-gnu)

> S-RET is a good idea; I've seen this keybinding used in lots of other
> programs for "insert a newline without executing an action".

Other problematic place where S-RET could help to insert a newline
is shell input.  What is worse in shell than in the minibuffer
typing RET accidentally in the middle of multi-line shell input
causes a mess: it sends the part before point, and leaves
the remaining lines dangling at the end of the shell buffer.

This patch gets the input until the end of the possibly multi-line
input field instead of only the end of the line:

diff --git a/lisp/comint.el b/lisp/comint.el
index da37827..da21d66 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -457,6 +457,7 @@ (defvar comint-mode-map
     (define-key map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
     (define-key map "\e\C-l"     'comint-show-output)
     (define-key map "\C-m"       'comint-send-input)
+    (define-key map [S-return]    'newline)
     (define-key map "\C-d"       'comint-delchar-or-maybe-eof)
     ;; The following two are standardly bound to delete-forward-char,
     ;; but they should never do EOF, just delete.
@@ -1781,7 +1782,7 @@ (defun comint-send-input (&optional no-newline artificial)
       (let* ((pmark (process-mark proc))
              (intxt (if (>= (point) (marker-position pmark))
-                        (progn (if comint-eol-on-send (end-of-line))
+                        (progn (if comint-eol-on-send (goto-char (field-end)))
                                (buffer-substring pmark (point)))
                       (let ((copy (funcall comint-get-old-input)))
                         (goto-char pmark)

While checking this, I also noticed a problem in searching the history of
multi-line entries.  `comint-line-beginning-position' operates only
on the current line, so it too should be replaced with `field-beginning':

diff --git a/lisp/comint.el b/lisp/comint.el
index da37827..da21d66 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1475,7 +1476,7 @@ (defun comint-history-isearch-search ()
        ;; 1. First try searching in the initial comint text
        (funcall search-fun string
-               (if isearch-forward bound (comint-line-beginning-position))
+               (if isearch-forward bound (field-beginning))
        ;; 2. If the above search fails, start putting next/prev history
        ;; elements in the comint successively, and search the string
@@ -1491,7 +1492,7 @@ (defun comint-history-isearch-search ()
                        (when (null comint-input-ring-index)
                          (error "End of history; no next item"))
                        (comint-next-input 1)
-                       (goto-char (comint-line-beginning-position)))
+                       (goto-char (field-beginning)))
                        ;; Signal an error here explicitly, because
                        ;; `comint-previous-input' doesn't signal an error.
@@ -1509,7 +1510,7 @@ (defun comint-history-isearch-search ()
                                      (unless isearch-forward
                                        ;; For backward search, don't search
                                        ;; in the comint prompt
-                                       (comint-line-beginning-position))
+                                       (field-beginning))
               ;; Return point of the new search result

reply via email to

[Prev in Thread] Current Thread [Next in Thread]