2 ;; $Id: gnuplot.el.old,v 1.1 1999/03/23 13:21:33 lhecking Exp $
6 ; gnu-plot.el - Definitions of GNU-PLOT mode for emacs editor.
8 ; Author: Gershon Elber
9 ; Computer Science Dept.
11 ; Date: Tue May 14 1991
12 ; Copyright (c) 1991, 1992, Gershon Elber
14 ; This file defines an environment to run edit and execute GNU-PLOT programs.
15 ; Such a program should have a '.gp' extension in order it to be in
16 ; gnu-plot-mode major mode. Two new functions are provided to communicate
17 ; between the editted file and the plotting program:
18 ; 1. send-line-to-gnu-plot - sends a single line to the plotting program for
19 ; execution. The line sent is the line the cursor is on,
20 ; Bounded to Meta-E by default.
21 ; 2. send-region-to-gnu-plot - sends the region from the current mark
22 ; (mark-marker) to current position (point-marker) to the plotting program.
23 ; This function is convenient for sending a large block of commands.
24 ; Bounded to Meta-R by default.
25 ; Both functions checks for existance of a buffer named gnu-plot-program
26 ; and a process named "gnu-plot" hooked to it, and will restart a new process
27 ; or buffer if none exists. The program to execute as process "gnu-plot" is
28 ; defined by the gnu-plot-program constant below.
31 (defvar gnu-plot-program "gnuplot"
32 "*The executable to run for gnu-plot-program buffer.")
34 (defvar gnu-plot-echo-program t
35 "*Control echo of executed commands to gnu-plot-program buffer.")
37 (defvar gnu-plot-mode-map nil "")
40 (setq gnu-plot-mode-map (make-sparse-keymap))
41 (define-key gnu-plot-mode-map "\M-e" 'send-line-to-gnu-plot)
42 (define-key gnu-plot-mode-map "\M-r" 'send-region-to-gnu-plot))
45 ;;; Define the gnu-plot-mode
47 (defun gnu-plot-mode ()
48 "Major mode for editing and executing GNU-PLOT files.
50 see send-line-to-gnu-plot and send-region-to-gnu-plot for more."
52 (use-local-map gnu-plot-mode-map)
53 (setq major-mode 'gnu-plot-mode)
54 (setq mode-name "Gnu-Plot")
55 (run-hooks 'gnu-plot-mode-hook))
58 ;;; Define send-line-to-gnu-plot - send from current cursor position to next
59 ;;; semicolin detected.
61 (defun send-line-to-gnu-plot ()
62 "Sends one line of code from current buffer to the GNU-PLOT program.
64 Use to execute a line in the GNU-PLOT plotting program. The line sent is
65 the line the cursor (point) is on.
67 The GNU-PLOT plotting program buffer name is gnu-plot-program and the
68 process name is 'gnu-plot'. If none exists, a new one is created.
70 The name of the gnu-plot program program to execute is stored in
71 gnu-plot-program variable and may be changed."
73 (if (equal major-mode 'gnu-plot-mode)
75 (make-gnu-plot-buffer) ; In case we should start a new one.
77 (let ((start-mark (point-marker)))
79 (let* ((crnt-buffer (buffer-name))
80 (end-mark (point-marker))
81 (string-copy (buffer-substring start-mark end-mark)))
82 (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
84 (if gnu-plot-echo-program
86 (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
87 (if (not (pos-visible-in-window-p))
89 (switch-to-buffer-other-window (get-buffer crnt-buffer))
90 (process-send-region "gnu-plot" start-mark end-mark)
91 (goto-char end-mark))))
92 (message "Should be invoked in gnu-plot-mode only.")))
95 ;;; Define send-region-to-gnu-plot - send from current cursor position to
98 (defun send-region-to-gnu-plot ()
99 "Sends a region of code from current buffer to the GNU-PLOT program.
101 When this function is invoked on an GNU-PLOT file it send the region
102 from current point to current mark to the gnu-plot plotting program.
104 The GNU-PLOT plotting program buffer name is gnu-plot-program and the
105 process name is 'gnu-plot'. If none exists, a new one is created.
107 The name of the gnu-plot program program to execute is stored in
108 gnu-plot-program variable and may be changed."
110 (if (equal major-mode 'gnu-plot-mode)
112 (make-gnu-plot-buffer) ; In case we should start a new one.
113 (copy-region-as-kill (mark-marker) (point-marker))
114 (let ((crnt-buffer (buffer-name)))
115 (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
117 (if gnu-plot-echo-program
119 (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
120 (if (not (pos-visible-in-window-p))
122 (switch-to-buffer-other-window (get-buffer crnt-buffer))
123 (process-send-region "gnu-plot" (mark-marker) (point-marker))))
124 (message "Should be invoked in gnu-plot-mode only.")))
127 ;;; Switch to "gnu-plot-program" buffer if exists. If not, creates one and
128 ;;; execute the program defined by gnu-plot-program.
130 (defun make-gnu-plot-buffer ()
131 "Switch to gnu-plot-program buffer or create one if none exists"
133 (if (get-buffer "gnu-plot-program")
134 (if (not (get-process "gnu-plot"))
136 (message "Starting GNU-PLOT plotting program...")
137 (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
138 (process-send-string "gnu-plot" "\n")
141 (message "Starting GNU-PLOT plotting program...")
142 (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
143 (process-send-string "gnu-plot" "\n")
147 ;;; Autoload gnu-plot-mode on any file with gp extension.
149 (setq auto-mode-alist (append '(("\\.gp$" . gnu-plot-mode))