]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Calc graph output on MS-Windows
authorEli Zaretskii <eliz@gnu.org>
Sun, 13 Jan 2019 15:50:16 +0000 (17:50 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sun, 13 Jan 2019 15:50:16 +0000 (17:50 +0200)
The previous code relied on "pgnuplot" executable, which is
no longer provided with Gnuplot 5.x.
* lisp/calc/calc.el (calc-gnuplot-name): Set to "pgnuplot" on
MS-Windows only if such an executable exists.
* lisp/calc/calc-graph.el (calc-graph-w32-p): New defsubst.
(calc-graph-plot, calc-graph-command, calc-gnuplot-command)
(calc-graph-init): Call calc-graph-w32-p wherever we need to
do something special for invoking gnuplot on MS-Windows,
instead of comparing against calc-gnuplot-name.
(calc-graph-plot): Set the terminal to "qt" on MS-Windows when
pgnuplot.exe is not available.
(calc-graph-kill): Delete the temporary files only after
killing the gnuplot process, otherwise the deletion might fail
on MS-Windows because the files are still in use.

lisp/calc/calc-graph.el
lisp/calc/calc.el

index ff7f12d9fafe296a56d9af378328844602df58b0..317f403ead6a712bf7e916690a6e3ab6078aa33c 100644 (file)
@@ -65,6 +65,9 @@
 (defvar calc-graph-no-wait nil)
 (defvar calc-gnuplot-trail-mark)
 
+(defsubst calc-graph-w32-p ()
+  (eq system-type 'windows-nt))
+
 (defun calc-graph-fast (many)
   (interactive "P")
   (let ((calc-graph-no-auto-view t))
                    ;; Check MS-Windows before X, in case they have
                    ;; $DISPLAY set for some reason (e.g., Cygwin or
                    ;; whatever)
-                   ((string= calc-gnuplot-name "pgnuplot")
-                    "windows")
+                    ((string= calc-gnuplot-name "pgnuplot")
+                     "windows")
+                    ;; Versions of gnuplot that come without pgnuplot
+                    ;; only work on MS-Windows with "qt" as the
+                    ;; terminal, for some reason.
+                   ((calc-graph-w32-p)
+                    "qt")
                    ((or (eq window-system 'x) (getenv "DISPLAY"))
                     "x11")
                    ((>= calc-gnuplot-version 3)
@@ -1321,14 +1329,13 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
    (calc-graph-init)
    (calc-graph-view-trail)
    (calc-gnuplot-command cmd)
-   (or (string= calc-gnuplot-name "pgnuplot")
+   (or (calc-graph-w32-p)
        (progn
         (accept-process-output)
         (calc-graph-view-trail)))))
 
 (defun calc-graph-kill (&optional no-view)
   (interactive)
-  (calc-graph-delete-temps)
   (if (calc-gnuplot-alive)
       (calc-wrapper
        (or no-view (calc-graph-view-trail))
@@ -1337,7 +1344,8 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
        (sit-for 1)
        (if (process-status calc-gnuplot-process)
           (delete-process calc-gnuplot-process))
-       (setq calc-gnuplot-process nil))))
+       (setq calc-gnuplot-process nil)))
+  (calc-graph-delete-temps))
 
 (defun calc-graph-quit ()
   (interactive)
@@ -1404,7 +1412,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
 (defun calc-gnuplot-command (&rest args)
   (calc-graph-init)
   (let ((cmd (concat (mapconcat 'identity args " ") "\n")))
-    (or (string= calc-gnuplot-name "pgnuplot")
+    (or (calc-graph-w32-p)
        (accept-process-output))
     (with-current-buffer calc-gnuplot-buffer
       (calc-gnuplot-check-for-errors)
@@ -1416,7 +1424,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
       (process-send-string calc-gnuplot-process cmd)
       (if (get-buffer-window calc-gnuplot-buffer)
          (calc-graph-view-trail))
-      (or (string= calc-gnuplot-name "pgnuplot")
+      (or (calc-graph-w32-p)
          (accept-process-output (and (not calc-graph-no-wait)
                                      calc-gnuplot-process)))
       (calc-gnuplot-check-for-errors)
@@ -1445,8 +1453,9 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
          (setq origin (point)))
        (setq calc-graph-last-device nil)
        (setq calc-graph-last-output nil)
-       (if (string= calc-gnuplot-name "pgnuplot")
-           (let ((version-str (shell-command-to-string "pgnuplot -V")))
+       (if (calc-graph-w32-p)
+           (let ((version-str
+                   (shell-command-to-string (concat calc-gnuplot-name " -V"))))
              (if (string-match "gnuplot \\([0-9]+\\)\\." version-str)
                  (setq calc-gnuplot-version (string-to-number
                                              (substring version-str
@@ -1457,11 +1466,11 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
            (let ((args (append (and calc-gnuplot-display
                                     (not (equal calc-gnuplot-display
                                                 (getenv "DISPLAY")))
-                                    (not (string= calc-gnuplot-name "pgnuplot"))
+                                     (not (calc-graph-w32-p))
                                     (list "-display"
                                           calc-gnuplot-display))
                                (and calc-gnuplot-geometry
-                                    (not (string= calc-gnuplot-name "pgnuplot"))
+                                    (not (calc-graph-w32-p))
                                     (list "-geometry"
                                           calc-gnuplot-geometry)))))
              (setq calc-gnuplot-process
@@ -1475,7 +1484,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
           (error "Sorry, can't find \"%s\" on your system"
                  calc-gnuplot-name)))
        (with-current-buffer calc-gnuplot-buffer
-         (while (and (not (string= calc-gnuplot-name "pgnuplot"))
+         (while (and (not (calc-graph-w32-p))
                      (not (save-excursion
                             (goto-char origin)
                             (search-forward "gnuplot> " nil t)))
@@ -1483,7 +1492,7 @@ This \"dumb\" driver will be present in Gnuplot 3.0."
            (accept-process-output calc-gnuplot-process))
          (or (memq (process-status calc-gnuplot-process) '(run stop))
              (error "Unable to start GNUPLOT process"))
-         (if (not (string= calc-gnuplot-name "pgnuplot"))
+         (if (not (calc-graph-w32-p))
              (if (save-excursion
                    (goto-char origin)
                    (re-search-forward
index ef850a44fe6015bdfa9b8f4c7270f6753fbb0295..1d403b739438ad354818e762f06132a001c0d4cc 100644 (file)
@@ -395,10 +395,17 @@ This is not required to be present for user-written mode annotations."
                                   (string :tag "Closing annotation delimiter"))))
 
 (defcustom calc-gnuplot-name
-  (if (eq system-type 'windows-nt) "pgnuplot" "gnuplot")
+  (if (and (eq system-type 'windows-nt)
+           ;; Gnuplot v4.x on MS-Windows came with a special
+           ;; pipe-enabled gnuplot executable for batch-mode
+           ;; execution; newer versions allow using gnuplot.exe.
+           (executable-find "pgnuplot"))
+      "pgnuplot"
+    "gnuplot")
   "Name of GNUPLOT program, for calc-graph features."
   :group 'calc
-  :type '(string))
+  :type '(string)
+  :version "26.2")
 
 (defcustom calc-gnuplot-plot-command
   nil