From 6c41cd6c2e048306f50cfffb2b020f2b00a8ab84 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 28 Jul 2011 10:43:27 +0200 Subject: [PATCH] better handling of splitted commands in emacs mode Ignore-this: 4aa568707f943c1c4db5d19118fe49c darcs-hash:20110728084327-c41ad-deb3fd37185a8772fff4ad1e9d6acdcc64d6ba9e --- src/utop.el | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/utop.el b/src/utop.el index c9ebe2d..e9f4366 100644 --- a/src/utop.el +++ b/src/utop.el @@ -97,6 +97,9 @@ This hook is only run if exiting actually kills the buffer." (defvar utop-history-next nil "The history after the cursor.") +(defvar utop-pending nil + "The text not yet added to the history") + ;; +-----------------------------------------------------------------+ ;; | Utils | ;; +-----------------------------------------------------------------+ @@ -206,6 +209,17 @@ non-sticky mode." ;; A new prompt ((string= command "prompt") (let ((prompt (apply utop-prompt ()))) + ;; Check whether there is something to push to the history + (if (stringp utop-pending) + ;; Push pending input to the history if it is different + ;; from the top of the history + (unless (and (consp utop-history) (string= utop-pending (car utop-history))) + (push utop-pending utop-history))) + ;; Clear pending input + (setq utop-pending nil) + ;; Reset history + (setq utop-history-prev utop-history) + (setq utop-history-next nil) ;; Save current prompt (setq utop-last-prompt prompt) ;; Insert the new prompt @@ -214,6 +228,10 @@ non-sticky mode." (setq utop-command-number (+ utop-command-number 1)))) ;; Continuation of previous input ((string= command "continue") + ;; Reset history + (setq utop-history-prev utop-history) + (setq utop-history-next nil) + ;; Insert the last prompt (utop-insert-prompt utop-last-prompt))))) (defun utop-process-output (process output) @@ -233,7 +251,7 @@ non-sticky mode." (setq utop-output (car lines)))) ;; +-----------------------------------------------------------------+ -;; | Sending data to the utop sub-process | +;; | Sending data to the utop sub-process | ;; +-----------------------------------------------------------------+ (defun utop-send-input () @@ -241,14 +259,11 @@ non-sticky mode." sub-process." (interactive) (with-current-buffer utop-buffer-name - ;; Add current input to the history if it is different from the - ;; top of the history + ;; Push input to pending input (let ((input (buffer-substring-no-properties utop-prompt-max (point-max)))) - (unless (and (consp utop-history) (string= input (car utop-history))) - (push input utop-history))) - ;; Reset history - (setq utop-history-prev utop-history) - (setq utop-history-next nil) + (if (stringp utop-pending) + (setq utop-pending (concat utop-pending "\n" input)) + (setq utop-pending input))) ;; Goto the end of the buffer (goto-char (point-max)) ;; Terminate input by a newline @@ -360,6 +375,7 @@ sub-process." (make-local-variable 'utop-history) (make-local-variable 'utop-history-prev) (make-local-variable 'utop-history-next) + (make-local-variable 'utop-pending) ;; Set the major mode (setq major-mode 'utop-mode)