Initial release of Maemo 5 port of gnuplot
[gnuplot] / lisp / gnuplot.el.old
1 ;;
2 ;; $Id: gnuplot.el.old,v 1.1 1999/03/23 13:21:33 lhecking Exp $
3 ;;
4 ;;
5
6 ; gnu-plot.el - Definitions of GNU-PLOT mode for emacs editor.
7
8 ; Author:       Gershon Elber
9 ;               Computer Science Dept.
10 ;               University of Utah
11 ; Date: Tue May 14 1991
12 ; Copyright (c) 1991, 1992, Gershon Elber
13 ;
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.
29 ;
30
31 (defvar gnu-plot-program "gnuplot"
32   "*The executable to run for gnu-plot-program buffer.")
33
34 (defvar gnu-plot-echo-program t
35   "*Control echo of executed commands to gnu-plot-program buffer.")
36
37 (defvar gnu-plot-mode-map nil "")
38 (if gnu-plot-mode-map
39     ()
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))
43
44 ;;;
45 ;;; Define the gnu-plot-mode
46 ;;;
47 (defun gnu-plot-mode ()
48   "Major mode for editing and executing GNU-PLOT files.
49
50 see send-line-to-gnu-plot and send-region-to-gnu-plot for more."
51   (interactive)
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))
56
57 ;;;
58 ;;; Define send-line-to-gnu-plot - send from current cursor position to next
59 ;;; semicolin detected.
60 ;;;
61 (defun send-line-to-gnu-plot ()
62   "Sends one line of code from current buffer to the GNU-PLOT program.
63
64 Use to execute a line in the GNU-PLOT plotting program. The line sent is
65 the line the cursor (point) is on.
66
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.
69
70 The name of the gnu-plot program program to execute is stored in
71 gnu-plot-program variable and may be changed."
72   (interactive)
73   (if (equal major-mode 'gnu-plot-mode)
74     (progn
75       (make-gnu-plot-buffer)        ; In case we should start a new one.
76       (beginning-of-line)
77       (let ((start-mark (point-marker)))
78         (next-line 1)
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"))
83           (end-of-buffer)
84           (if gnu-plot-echo-program
85             (insert string-copy))
86           (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
87           (if (not (pos-visible-in-window-p))
88             (recenter 3))
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.")))
93
94 ;;;
95 ;;; Define send-region-to-gnu-plot - send from current cursor position to
96 ;;; current marker.
97 ;;;
98 (defun send-region-to-gnu-plot ()
99   "Sends a region of code from current buffer to the GNU-PLOT program.
100
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.
103
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.
106
107 The name of the gnu-plot program program to execute is stored in
108 gnu-plot-program variable and may be changed."
109   (interactive)
110   (if (equal major-mode 'gnu-plot-mode)
111     (progn
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"))
116         (end-of-buffer)
117         (if gnu-plot-echo-program
118           (yank))
119         (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
120         (if (not (pos-visible-in-window-p))
121           (recenter 3))
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.")))
125
126 ;;;
127 ;;; Switch to "gnu-plot-program" buffer if exists. If not, creates one and
128 ;;; execute the program defined by gnu-plot-program.
129 ;;;
130 (defun make-gnu-plot-buffer ()
131   "Switch to gnu-plot-program buffer or create one if none exists"
132   (interactive)
133   (if (get-buffer "gnu-plot-program")
134     (if (not (get-process "gnu-plot"))
135       (progn
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")
139         (message "Done.")))
140     (progn
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")
144       (message "Done."))))
145
146 ;;;
147 ;;; Autoload gnu-plot-mode on any file with gp extension. 
148 ;;;
149 (setq auto-mode-alist (append '(("\\.gp$" . gnu-plot-mode))
150                               auto-mode-alist))