branch: elpa/gnuplot
commit b0beecdcf312e10078bb1f606ce2b24630d2cd55
Author: Jonathan Oddie <[email protected]>
Commit: Jonathan Oddie <[email protected]>
Improved gnuplot-send-string-to-gnuplot
- Use (with-current-buffer) instead of explicitly setting and restoring
with (other-window)
- New defun: gnuplot-display-and-recenter-gnuplot-buffer factors out
a couple of repeated lines in gnuplot-send-string-to-gnuplot
---
gnuplot.el | 58 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 28 deletions(-)
diff --git a/gnuplot.el b/gnuplot.el
index 3afa05e..19fc651 100644
--- a/gnuplot.el
+++ b/gnuplot.el
@@ -30,7 +30,7 @@
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; send bug reports to the author ([email protected])
+;; send bug reports to the author ([email protected])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Commentary:
;;
@@ -1633,6 +1633,8 @@ called by this function after all of STRING is sent to
gnuplot."
(gnuplot-fetch-version-number)
(sit-for 2)))
(setq gnuplot-comint-recent-buffer (current-buffer))
+
+ ;; Create a gnuplot frame if needed
(if (equal gnuplot-display-process 'frame)
(or (and gnuplot-process-frame
(frame-live-p gnuplot-process-frame))
@@ -1641,39 +1643,39 @@ called by this function after all of STRING is sent to
gnuplot."
(select-frame gnuplot-process-frame)
(switch-to-buffer gnuplot-buffer)
(delete-other-windows)
- (select-frame frame))) )
- (let ((buffer (current-buffer))
- (gbuffer (get-buffer gnuplot-buffer))
- (list (gnuplot-split-string string)))
- (set-buffer gbuffer)
- (goto-char (point-max))
- ;; bruce asks: what is this next line for?
- (set-marker (process-mark gnuplot-process) (point-marker))
- (sleep-for (* 20 gnuplot-delay))
- (while list
- (insert (car list))
- (comint-send-input)
- (sleep-for gnuplot-delay)
- (setq list (cdr list))
- (goto-char (point-max)))
- (set-buffer buffer)
+ (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 (* 20 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)
- (select-window (display-buffer gbuffer))
- (goto-char (point-max))
- (or (pos-visible-in-window-p (point) (selected-window))
- (recenter 5))
- (other-window 1))
+ (gnuplot-display-and-recenter-gnuplot-buffer))
((equal gnuplot-display-process 'frame)
;;(raise-frame gnuplot-process-frame)
- (select-frame gnuplot-process-frame)
- (display-buffer gbuffer)
- (goto-char (point-max))
- (or (pos-visible-in-window-p (point) (selected-window))
- (recenter 5))))
- ;;(process-send-string gnuplot-program string)
+ (with-selected-frame gnuplot-process-frame
+ (gnuplot-display-and-recenter-gnuplot-buffer))))
+
(setq gnuplot-recently-sent text)
(run-hooks 'gnuplot-after-plot-hook)))
+(defun gnuplot-display-and-recenter-gnuplot-buffer ()
+ "Make sure the gnuplot comint buffer is displayed, and
+move point to the end if necessary"
+ (save-selected-window
+ (select-window (display-buffer (get-buffer gnuplot-buffer)))
+ (goto-char (point-max))
+ (unless (pos-visible-in-window-p (point) (selected-window)) (recenter 5))))
+
(defun gnuplot-send-region-to-gnuplot (&optional begin end text)
"Sends a selected region to the gnuplot program.
If BEGIN and END are not specified, point and mark are used. TEXT