larsbrinkhoff / forth-mode

Wants to be the SLIME of Forth
GNU General Public License v3.0
61 stars 17 forks source link

C-c C-e echoes in minibuffer only #75

Open jpellegrini opened 5 years ago

jpellegrini commented 5 years ago

If I split an emacs frame in two windows, having a forth program (example.f) in one window and the other window having the Forth interaction buffer, *forth*, I'd expect that, if I press C-c C-e in the first window (after a Forth expression), the output would be echoed in the interaction buffer, but it goes to the minibuffer only. But the information in the minibuffer vanishes quickly, and it would be nice to have it also printed in the interacion buffer for later analysis and use.

jpellegrini commented 5 years ago

I see that C-c C-e does forth-eval-last-expression while C-x M-e does forth-eval-last-expression-display-output, which does send output to the interaction buffer.

However, when I do C-x M-e / forth-eval-last-expression-display-output, the expression is eval'ed and pushed into the stack -- and the result is inserted to the interaction buffer, and if I go there and hit enter, the result is sent to the Forth interpreter¸being pushed into the stack a second time.

It wpuld be nice if the result was printed to the interaction buffe but in a way that I could use one single command to eval-and-push-the-result (in the usual Forth way), keeping it available in the interaction buffer, but not in a way that if I hit enter there it will bepushed again.

jpellegrini commented 5 years ago

A quick hack, but it shows what I mean... maybe the "\\ => " string could be different.

(defun forth-eval-last-expression-display-output ()
  (interactive)
  (if forth-interaction-buffer
      (save-excursion
    (backward-sexp)
    (let ((start (point)))
      (forward-sexp)
      (let ((string (buffer-substring start (point))))
        (forth-switch-to-output-buffer)
        (insert (concat "\\ => " (forth-interaction-send string) "\n")))))
      (message "Forth not started.")))
jpellegrini commented 5 years ago

Ah. Do (comint-set-process-mark) after inserting in the interaction buffer. That fixes it.

jpellegrini commented 5 years ago

Pull request #78 fixes this. It also makes it optional for the user to be sent to the interaction buffer after doing forth-eval-last-expression-display-output (the patch also includes documentation for this).