From 8d8f46c8b63f903f30739322870872574fabd2de Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 22 Mar 2012 07:45:48 +0100 Subject: [PATCH] follow OCaml's output only if we are at the end of the buffer Ignore-this: 739f69390b4952091f481cc8dfb3e144 darcs-hash:20120322064548-c41ad-a3383dfe0bfa362d15c06949cbf5c9b44c5a82d1 --- src/top/utop.el | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/top/utop.el b/src/top/utop.el index 96203f5..f81d055 100644 --- a/src/top/utop.el +++ b/src/top/utop.el @@ -63,12 +63,6 @@ If nil, `utop-command' will be used without modification." :type 'boolean :group 'utop) -(defcustom utop-follow-output t - "Whether to follow OCaml's output while it is executing a -phrase." - :type 'boolean - :group 'utop) - (defcustom utop-prompt 'utop-default-prompt "The function which create the prompt for utop." :type 'function @@ -406,22 +400,24 @@ it is started." (defun utop-insert-output (output &optional face) "Insert the given output before the prompt." - (save-excursion - (let ((line (concat output "\n"))) - ;; Apply the given face if provided - (when face (add-text-properties 0 (length line) (list 'face face) line)) - ;; Goto before the prompt - (goto-char utop-prompt-min) - ;; Insert the output - (insert line) - ;; Advance the prompt - (setq utop-prompt-min (+ utop-prompt-min (length line))) - (setq utop-prompt-max (+ utop-prompt-max (length line))) - ;; Make everything before the end prompt read-only - (add-text-properties (point-min) utop-prompt-max utop-non-editable-properties))) - ;; If OCaml is executing a phrase, follow its output - (when (and utop-follow-output (eq utop-state 'wait)) - (utop-goto-point-max-all-windows))) + (let ((point-at-max (eq (point) (point-max)))) + (save-excursion + (let ((line (concat output "\n"))) + ;; Apply the given face if provided + (when face (add-text-properties 0 (length line) (list 'face face) line)) + ;; Goto before the prompt + (goto-char utop-prompt-min) + ;; Insert the output + (insert line) + ;; Advance the prompt + (setq utop-prompt-min (+ utop-prompt-min (length line))) + (setq utop-prompt-max (+ utop-prompt-max (length line))) + ;; Make everything before the end prompt read-only + (add-text-properties (point-min) utop-prompt-max utop-non-editable-properties))) + ;; If we are at the end of the buffer and OCaml is executing a + ;; phrase, follow its output + (when (and point-at-max (eq utop-state 'wait)) + (utop-goto-point-max-all-windows)))) (defun utop-insert-prompt (prompt) "Insert the given prompt."