Subject: bug#72778: 31.0.50; Calc: g f doesn't display gnuplot window after closing

From: Visuwesh <[email-masked]>
Date: Mon, 26 Aug 2024 11:32:19 +0530

[ஞாயிறு ஆகஸ்ட் 25, 2024] Michael Heerdegen wrote:

> Eli Zaretskii <[email-masked]> writes:
>
>> IME, gnuplot is notorious in changing its non-interactive behavior
>> from time to time, which might break the assumptions that Calc makes.
>> Suggest to look in the gnuplot's change log to see if they made some
>> change in the recent years, maybe this will give some ideas.
>
> I'm too ignorant to know what to look for.
>
> Some more data points, though:
>
>  - In *Gnuplot Trail* I see that gnuplot receives the command and emits
>    a new prompt even when the command is ignored.
>
>  - Executing (calc-gnuplot-command "set term wxt") (be sure that it is
>    not ignored!) fixes the problem for me.  I guess we don't want to do
>    that.
>
>  - I can't reproduce the issue with a terminal emulator even when
>    changing the gnuplot terminal to x11 (this is what Emacs uses for its
>    gnuplot process).
>
> I don't know much about process communication, excuse me if this is all
> irrelevant.

I am ignorant about process communication but I was able to reliably
make gnuplot open the terminal window every time by sending an extra
newline before the plot command.  Try

    M-: (process-send-string (get-buffer-process (current-buffer)) "\nplot sin(x)\n") RET

in the *Gnuplot Trail* buffer.  If you kill the gnuplot terminal window,
and reeval the same sexp, it opens again.  A naïve fix employing this
method would be

diff --git a/lisp/calc/calc-graph.el b/lisp/calc/calc-graph.el
index fb817b1bc3d..7b1ebc9f603 100644
--- a/lisp/calc/calc-graph.el
+++ b/lisp/calc/calc-graph.el
@@ -1417,7 +1417,7 @@ calc-gnuplot-command
   "Send ARGS to Gnuplot.
 Returns nil if Gnuplot signaled an error."
   (calc-graph-init)
-  (let ((cmd (concat (mapconcat 'identity args " ") "\n")))
+  (let ((cmd (concat "\n" (mapconcat 'identity args " ") "\n")))
     (or (calc-graph-w32-p)
 	(accept-process-output))
     (with-current-buffer calc-gnuplot-buffer

But it would be better if someone can explain why we require this
newline before CMD too.