branch: elpa/gnuplot
commit 59f7a9463f4285a3c4f4e554e2f473e2b4a7d7b1
Author: Jonathan Oddie <[email protected]>
Commit: joddie <[email protected]>
Better prompt tracking. Setup inline images on creating comint buffer.
- new constant: `gnuplot-prompt-regexp', recognizes "gnuplot>" and
"multiplot>"
- call (gnuplot-inline-image-mode) with right value in
`gnuplot-make-gnuplot-buffer', after creating process and buffer
---
gnuplot.el | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/gnuplot.el b/gnuplot.el
index 9d053be..119cd2a 100644
--- a/gnuplot.el
+++ b/gnuplot.el
@@ -2133,6 +2133,7 @@ buffer."
(process-kill-without-query gnuplot-process nil)
(with-current-buffer gnuplot-buffer
(gnuplot-comint-mode)
+ (gnuplot-inline-image-mode gnuplot-inline-image-mode)
(message "Starting gnuplot plotting program...Done")))))
(defun gnuplot-fetch-version-number ()
@@ -2191,6 +2192,10 @@ defaults to 3.7."
gnuplot-version gnuplot-program-version
(substitute-command-keys "\\[gnuplot-bug-report]")))
+(defvar gnuplot-prompt-regexp
+ (regexp-opt '("gnuplot> " "multiplot> "))
+ "Regexp for recognizing the GNUPLOT prompt")
+
(defun gnuplot-protect-prompt-fn (string)
"Prevent the Gnuplot prompt from being deleted or overwritten.
STRING is the text as originally inserted in the comint buffer."
@@ -2200,7 +2205,7 @@ STRING is the text as originally inserted in the comint
buffer."
(beginning-of-line)
(point)))
e)
- (if (re-search-forward "^gnuplot> " (point-max) t)
+ (if (re-search-forward gnuplot-prompt-regexp (point-max) t)
(progn
(setq e (point))
(put-text-property b e 'rear-nonsticky '(read-only intangible
face))
@@ -2299,16 +2304,24 @@ display."
(message "Plot output will be displayed in gnuplot buffer.")))))
(defun gnuplot-inline-image-set-output ()
- "Set GNUPLOT's output file to `gnuplot-inline-image-filename'."
+ "Set Gnuplot's output file to `gnuplot-inline-image-filename'."
(let ((tmp (make-temp-file "gnuplot")))
(setq gnuplot-inline-image-filename tmp)
(gnuplot-send-hiding-output (format "set output '%s'\n" tmp))))
(defun gnuplot-insert-inline-image-output (string)
+ "Insert Gnuplot graphical output in the gnuplot-comint buffer.
+
+Called via `comint-preoutput-filter-functions' hook when
+`gnuplot-inline-image-mode' is enabled. Checks the status of the
+file `gnuplot-inline-image-filename'; if it exists and has
+nonzero size, inserts it as an inline image, stores a new
+temporary filename in `gnuplot-inline-image-filename', and
+updates Gnuplot with the appropriate 'set output' command."
(save-excursion
(goto-char (point-max))
(beginning-of-line)
- (when (looking-at "^gnuplot> ")
+ (when (looking-at gnuplot-prompt-regexp)
(let* ((filename gnuplot-inline-image-filename)
(size (nth 7 (file-attributes filename))))
(if (and size (> size 0))
@@ -2337,7 +2350,7 @@ display."
(with-current-buffer
(get-buffer-create gnuplot-hidden-output-buffer)
(insert string)
- (when (looking-back "gnuplot> ")
+ (when (looking-back gnuplot-prompt-regexp)
(with-current-buffer gnuplot-buffer
(remove-hook 'comint-preoutput-filter-functions
'gnuplot-discard-output t))))