better handling of splitted commands in emacs mode

Ignore-this: 4aa568707f943c1c4db5d19118fe49c

darcs-hash:20110728084327-c41ad-deb3fd37185a8772fff4ad1e9d6acdcc64d6ba9e
This commit is contained in:
Jeremie Dimino 2011-07-28 10:43:27 +02:00
parent 726cd685f3
commit 6c41cd6c2e
1 changed files with 24 additions and 8 deletions

View File

@ -97,6 +97,9 @@ This hook is only run if exiting actually kills the buffer."
(defvar utop-history-next nil (defvar utop-history-next nil
"The history after the cursor.") "The history after the cursor.")
(defvar utop-pending nil
"The text not yet added to the history")
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Utils | ;; | Utils |
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
@ -206,6 +209,17 @@ non-sticky mode."
;; A new prompt ;; A new prompt
((string= command "prompt") ((string= command "prompt")
(let ((prompt (apply utop-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 ;; Save current prompt
(setq utop-last-prompt prompt) (setq utop-last-prompt prompt)
;; Insert the new prompt ;; Insert the new prompt
@ -214,6 +228,10 @@ non-sticky mode."
(setq utop-command-number (+ utop-command-number 1)))) (setq utop-command-number (+ utop-command-number 1))))
;; Continuation of previous input ;; Continuation of previous input
((string= command "continue") ((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))))) (utop-insert-prompt utop-last-prompt)))))
(defun utop-process-output (process output) (defun utop-process-output (process output)
@ -241,14 +259,11 @@ non-sticky mode."
sub-process." sub-process."
(interactive) (interactive)
(with-current-buffer utop-buffer-name (with-current-buffer utop-buffer-name
;; Add current input to the history if it is different from the ;; Push input to pending input
;; top of the history
(let ((input (buffer-substring-no-properties utop-prompt-max (point-max)))) (let ((input (buffer-substring-no-properties utop-prompt-max (point-max))))
(unless (and (consp utop-history) (string= input (car utop-history))) (if (stringp utop-pending)
(push input utop-history))) (setq utop-pending (concat utop-pending "\n" input))
;; Reset history (setq utop-pending input)))
(setq utop-history-prev utop-history)
(setq utop-history-next nil)
;; Goto the end of the buffer ;; Goto the end of the buffer
(goto-char (point-max)) (goto-char (point-max))
;; Terminate input by a newline ;; Terminate input by a newline
@ -360,6 +375,7 @@ sub-process."
(make-local-variable 'utop-history) (make-local-variable 'utop-history)
(make-local-variable 'utop-history-prev) (make-local-variable 'utop-history-prev)
(make-local-variable 'utop-history-next) (make-local-variable 'utop-history-next)
(make-local-variable 'utop-pending)
;; Set the major mode ;; Set the major mode
(setq major-mode 'utop-mode) (setq major-mode 'utop-mode)