unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: JD Smith <jdsmith@as.arizona.edu>
Cc: emacs-devel@gnu.org
Subject: Re: comint-accumulate-marker
Date: Tue, 18 Apr 2006 12:10:45 -0700	[thread overview]
Message-ID: <C0710013-235A-42A3-9CC1-EFF918C03476@as.arizona.edu> (raw)
In-Reply-To: <E1FVpmA-0005vd-WE@fencepost.gnu.org>


On Apr 18, 2006, at 5:57 AM, Richard Stallman wrote:

> Please install it, and enable it by default.  The reason this
> is ok to install now is that the current behavior is wrong.

I will install it shortly, but wanted to run one more variant of the  
patch by everyone first.  This version is permanently enabled.  It  
also saves input even when you use M-r/M-s, and it binds "C-c C-g" to  
a new function `comint-restore-input',  so no matter where you are on  
the history ring, you can zap back to your stranded partial input  
with C-c C-g.  Let me know if that's a good binding (and where it  
should be documented).

JD


Index: comint.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/comint.el,v
retrieving revision 1.337
diff -c -r1.337 comint.el
*** comint.el	27 Mar 2006 08:50:20 -0000	1.337
--- comint.el	18 Apr 2006 19:06:05 -0000
***************
*** 465,470 ****
--- 465,471 ----
       (define-key map "\C-c\C-l" 	  'comint-dynamic-list-input-ring)
       (define-key map "\C-c\C-n" 	  'comint-next-prompt)
       (define-key map "\C-c\C-p" 	  'comint-previous-prompt)
+     (define-key map "\C-c\C-g" 	  'comint-restore-input)
       (define-key map "\C-c\C-d" 	  'comint-send-eof)
       (define-key map "\C-c\C-s" 	  'comint-write-output)
       (define-key map "\C-c." 	  'comint-insert-previous-argument)
***************
*** 558,563 ****
--- 559,567 ----
     "Non-nil if you are accumulating input lines to send as input  
together.
   The command \\[comint-accumulate] sets this.")

+ (defvar comint-stored-incomplete-input nil
+   "Stored input for history cycling.")
+
   (put 'comint-replace-by-expanded-history 'menu-enable 'comint- 
input-autoexpand)
   (put 'comint-input-ring 'permanent-local t)
   (put 'comint-input-ring-index 'permanent-local t)
***************
*** 638,643 ****
--- 642,648 ----
     (make-local-variable 'comint-scroll-to-bottom-on-input)
     (make-local-variable 'comint-move-point-for-output)
     (make-local-variable 'comint-scroll-show-maximum-output)
+   (make-local-variable 'comint-stored-incomplete-input)
     ;; This makes it really work to keep point at the bottom.
     (make-local-variable 'scroll-conservatively)
     (setq scroll-conservatively 10000)
***************
*** 1015,1020 ****
--- 1020,1035 ----
   	(t
   	 arg)))

+ (defun comint-restore-input ()
+   "Restore unfinished input."
+   (interactive)
+   (when comint-input-ring-index
+     (comint-delete-input)
+     (when (> (length comint-stored-incomplete-input) 0)
+       (insert comint-stored-incomplete-input)
+       (message "Input restored"))
+     (setq comint-input-ring-index nil)))
+
   (defun comint-search-start (arg)
     "Index to start a directional search, starting at `comint-input- 
ring-index'."
     (if comint-input-ring-index
***************
*** 1035,1043 ****
   				arg)))

   (defun comint-previous-input (arg)
!   "Cycle backwards through input history."
     (interactive "*p")
!   (comint-previous-matching-input "." arg))

   (defun comint-next-input (arg)
     "Cycle forwards through input history."
--- 1050,1067 ----
   				arg)))

   (defun comint-previous-input (arg)
!   "Cycle backwards through input history, saving input."
     (interactive "*p")
!   (if (and comint-input-ring-index
! 	   (or		       ;; leaving the "end" of the ring
! 	    (and (< arg 0)		; going down
! 		 (eq comint-input-ring-index 0))
! 	    (and (> arg 0)		; going up
! 		 (eq comint-input-ring-index
! 		     (1- (ring-length comint-input-ring)))))
! 	   comint-stored-incomplete-input)
!       (comint-restore-input)
!     (comint-previous-matching-input "." arg)))

   (defun comint-next-input (arg)
     "Cycle forwards through input history."
***************
*** 1077,1082 ****
--- 1101,1114 ----
       (if (string-match regexp (ring-ref comint-input-ring n))
   	n)))

+ (defun comint-delete-input ()
+   "Delete all input between accumulation or process mark and point."
+   (delete-region
+    ;; Can't use kill-region as it sets this-command
+    (or  (marker-position comint-accum-marker)
+ 	(process-mark (get-buffer-process (current-buffer))))
+    (point-max)))
+
   (defun comint-previous-matching-input (regexp n)
     "Search backwards through input history for match for REGEXP.
   \(Previous history elements are earlier commands.)
***************
*** 1088,1100 ****
       ;; Has a match been found?
       (if (null pos)
   	(error "Not found")
         (setq comint-input-ring-index pos)
         (message "History item: %d" (1+ pos))
!       (delete-region
!        ;; Can't use kill-region as it sets this-command
!        (or  (marker-position comint-accum-marker)
! 	    (process-mark (get-buffer-process (current-buffer))))
!        (point))
         (insert (ring-ref comint-input-ring pos)))))

   (defun comint-next-matching-input (regexp n)
--- 1120,1132 ----
       ;; Has a match been found?
       (if (null pos)
   	(error "Not found")
+       ;; If leaving the edit line, save partial input
+       (if (null comint-input-ring-index)	;not yet on ring
+ 	  (setq comint-stored-incomplete-input
+ 		(funcall comint-get-old-input)))
         (setq comint-input-ring-index pos)
         (message "History item: %d" (1+ pos))
!       (comint-delete-input)
         (insert (ring-ref comint-input-ring pos)))))

   (defun comint-next-matching-input (regexp n)

  reply	other threads:[~2006-04-18 19:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-13 19:45 comint-accumulate-marker JD Smith
2006-04-16  0:19 ` comint-accumulate-marker Bob Portmann
2006-04-16  2:09 ` comint-accumulate-marker Richard Stallman
2006-04-17 18:06   ` comint-accumulate-marker JD Smith
2006-04-18  9:47     ` comint-accumulate-marker Nick Roberts
2006-04-18 11:25       ` comint-accumulate-marker Stefan Monnier
2006-04-18 20:50         ` comint-accumulate-marker Richard Stallman
2006-04-18 12:57     ` comint-accumulate-marker Richard Stallman
2006-04-18 19:10       ` JD Smith [this message]
2006-04-18 20:54         ` comint-accumulate-marker David Kastrup
2006-04-18 21:06           ` comint-accumulate-marker JD Smith
2006-04-18 23:25             ` comint-accumulate-marker Stuart D. Herring
2006-04-18 21:22         ` comint-accumulate-marker Nick Roberts
2006-04-18 21:38           ` comint-accumulate-marker JD Smith
2006-04-18 23:24             ` comint-accumulate-marker Nick Roberts
     [not found]               ` <1145403002.27500.42.camel@turtle.as.arizona.edu>
2006-04-19  0:01                 ` comint-accumulate-marker Nick Roberts
2006-04-19  0:01                 ` Bug in diff-mode? (was: Re: comint-accumulate-marker) Nick Roberts
2006-04-19 15:40                   ` Richard Stallman
2006-04-19 15:40             ` comint-accumulate-marker Richard Stallman
2006-04-20  7:25             ` comint-accumulate-marker David Kastrup
2006-04-20  7:45               ` comint-accumulate-marker Nick Roberts
2006-04-20 17:29               ` comint-accumulate-marker JD Smith
2006-04-18 22:21         ` comint-accumulate-marker Stuart D. Herring
2006-04-18 22:48           ` comint-accumulate-marker JD Smith
2006-04-18 23:39           ` comint-accumulate-marker Miles Bader
2006-04-19  0:02         ` comint-accumulate-marker JD Smith

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=C0710013-235A-42A3-9CC1-EFF918C03476@as.arizona.edu \
    --to=jdsmith@as.arizona.edu \
    --cc=emacs-devel@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 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).