Function: gnuplot-send-string-to-gnuplot

gnuplot-send-string-to-gnuplot is a natively compiled function defined in gnuplot.el.

Signature

(gnuplot-send-string-to-gnuplot STRING TEXT)

Documentation

Sends STRING to the gnuplot program.

If no gnuplot process exists, a new one is created. TEXT indicates the type of text being sent to gnuplot and is typically one of nil, line, region, buffer, or file. TEXT may be useful for functions in gnuplot-after-plot-hook. gnuplot-after-plot-hook is called by this function after all of STRING is sent to gnuplot.

Source Code

;; Defined in /nix/store/xvcy7r1jiw71avhnh6kmin403kpqrdhc-emacs-packages-deps/share/emacs/site-lisp/elpa/gnuplot-20260623.1111/gnuplot.el
;; -- the calls to `sleep-for' are to allow enough time for gnuplot
;;    to write to the buffer before the next line is inserted
;; -- note that the input string is split into lines and each line is
;;    sent to gnuplot individually.  this is a bit slow, but it puts
;;    each line on the comint history.
(defun gnuplot-send-string-to-gnuplot (string text)
  "Sends STRING to the gnuplot program.
If no gnuplot process exists, a new one is created.  TEXT indicates
the type of text being sent to gnuplot and is typically one of
nil, `line', `region', `buffer', or `file'.  TEXT may be useful for
functions in `gnuplot-after-plot-hook'.  `gnuplot-after-plot-hook' is
called by this function after all of STRING is sent to gnuplot."
  (gnuplot--make-comint-buffer)         ; make sure a gnuplot buffer exists
  (setq gnuplot--comint-recent-buffer (current-buffer))

  ;; Create a gnuplot frame if needed
  (when (and (equal gnuplot-display-process 'frame)
             (not (frame-live-p gnuplot--process-frame)))
    (let ((frame (selected-frame)))
      (setq gnuplot--process-frame (make-frame))
      (select-frame gnuplot--process-frame)
      (switch-to-buffer gnuplot-buffer)
      (delete-other-windows)
      (select-frame frame)))

  (let ((list (gnuplot--split-string string)))
    (with-current-buffer (get-buffer gnuplot-buffer)
      (goto-char (point-max))
      ;; bruce asks: what is this next line for?
      (set-marker (process-mark gnuplot-process) (point-marker))
      (sleep-for (* 10 gnuplot-delay))
      (while list
        (insert (car list))
        (comint-send-input)
        (sleep-for gnuplot-delay)
        (setq list (cdr list))
        (goto-char (point-max))))

    (cond ((equal gnuplot-display-process 'window)
           (gnuplot--display-and-recenter-comint-buffer))
          ((equal gnuplot-display-process 'frame)
           ;;(raise-frame gnuplot--process-frame)
           (with-selected-frame gnuplot--process-frame
             (gnuplot--display-and-recenter-comint-buffer))))

    (setq gnuplot-recently-sent text)
    (run-hooks 'gnuplot-after-plot-hook)))