multiple updates:
[emacs-init.git] / gnuplot / gnuplot.el
1 ;;; gnuplot.el --- drive gnuplot from within emacs
2
3 ;; Copyright (C) 1998, 2011 Phil Type and Bruce Ravel, 1999-2002 Bruce Ravel
4
5 ;; Author:     Bruce Ravel <bruceravel1@gmail.com> and Phil Type
6 ;; Maintainer: Bruce Ravel <bruceravel1@gmail.com>
7 ;; Created:    June 28 1998
8 ;; Updated:    April 20 2012
9 ;; Version:    0.6.1
10 ;; Keywords:   gnuplot, plotting
11
12 ;; This file is not part of GNU Emacs.
13
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;; This program is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19 ;;
20 ;; This lisp script is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 ;;
24 ;; Permission is granted to distribute copies of this lisp script
25 ;; provided the copyright notice and this permission are preserved in
26 ;; all copies.
27 ;;
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with this program; if not, you can either send email to this
30 ;; program's maintainer or write to: The Free Software Foundation,
31 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; send bug reports to the author (bruceravel1@gmail.com)
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35
36 ;;; Commentary:
37
38 ;;
39 ;; This is a major mode for composing gnuplot scripts and displaying
40 ;; their results using gnuplot.  It is optimized for use with gnuplot
41 ;; 3.7 or one of the later patchlevels of "version 3.6".  It should
42 ;; also work very handily with version 3.5.  This mode offers several
43 ;; tools to help you compose your scripts, including syntax
44 ;; colorization using either font-lock or hilit19, a syntax table
45 ;; appropriate to gnuplot, key bindings, pull-down menus, indentation,
46 ;; keyword completions and variable customization using the Custom
47 ;; package.  Once the script is composed, there are several function
48 ;; for sending some or all of the script to gnuplot.  The interaction
49 ;; with the gnuplot process is within a comint buffer.
50 ;;
51 ;;    C-c C-l       send current line to gnuplot
52 ;;    C-c C-v       send current line to gnuplot and move forward 1 line
53 ;;    C-c C-r       send current region to gnuplot
54 ;;    C-c C-b       send entire buffer to gnuplot
55 ;;    C-c C-f       send a file to gnuplot
56 ;;    C-c C-i       insert filename at point
57 ;;    C-c C-n       negate set option on current line
58 ;;    C-c C-c       comment region
59 ;;    C-c C-o       set arguments for command at point
60 ;;   S-mouse-2      set arguments for command under mouse cursor
61 ;;    C-c C-h       read the gnuplot info file
62 ;;    C-c C-e       show-gnuplot-buffer
63 ;;    C-c C-k       kill gnuplot process
64 ;;    C-c C-u       submit a bug report about gnuplot-mode
65 ;; M-tab or M-ret   complete keyword before point
66 ;;      ret         newline and indent
67 ;;      tab         indent current line
68 ;;
69 ;; Gnuplot-mode adds two key bindings to the comint buffer:
70 ;;     M-C-p        plot the current script buffer line-by-line
71 ;;     M-C-f        save the current script buffer and load that file
72 ;;
73 ;; These two functions are useful for starting up gnuplot-mode.
74 ;;
75 ;; M-x gnuplot-mode
76 ;;         start gnuplot-mode in the current buffer
77 ;;
78 ;; M-x gnuplot-make-buffer
79 ;;         open a new buffer (which is not visiting a file) and start
80 ;;         gnuplot-mode in that buffer
81 ;;
82 ;; ---------------------------------------------------------------------
83 ;;
84 ;; Other lisp files used by gnuplot.el
85 ;;
86 ;; info-look.el (comes with GNU Emacs 20):
87 ;;   This provides the interface to the gnuplot-info file and provides
88 ;;   on-line help and keyword completion functionality.  The version
89 ;;   of info-look.el that comes with version 20.2 of Emacs contains a
90 ;;   bug that will impede its interaction with the gnuplot info file.
91 ;;   You should use the version from the gnuplot-mode homepage
92 ;;   instead.  info-look is not distributed with XEmacs and so should
93 ;;   be installed along with gnuplot-mode when using XEmacs.
94 ;;
95 ;; gnuplot-gui.el (written by Bruce):
96 ;;   Defines the GUI interface for setting setting arguments to
97 ;;   gnuplot options.  This uses the widget package extensively.
98 ;;
99 ;; ---------------------------------------------------------------------
100 ;;
101 ;; This mode was inspired by the original gnu-plot-mode by Gershon
102 ;; Elber, which is distributed with gnuplot itself and which dates
103 ;; back to the early 90's.  Although this mode encompasses the
104 ;; functionality of the original, the two share no code and the
105 ;; current implementation takes advantage of many features of modern
106 ;; versions of emacs and adheres (or so I intend) to the major mode
107 ;; conventions described in the emacs-lisp reference for version 19
108 ;; and later.
109 ;;
110 ;; ---------------------------------------------------------------------
111 ;;
112 ;;                         Installation
113 ;;                         ============
114 ;;
115 ;; A recent version of this file can be found at
116 ;;   http://github.com/bruceravel/gnuplot-mode/
117 ;;
118 ;; To autoload gnuplot-mode on any file with gp extension, put this in
119 ;; your .emacs file
120 ;;   (autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t)
121 ;;   (autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t)
122 ;;
123 ;; Something like
124 ;;   (setq auto-mode-alist (append '(("\\.gp$" . gnuplot-mode))
125 ;;                                 auto-mode-alist))
126 ;; is useful for having files ending in .gp start up in gnuplot-mode.
127 ;;
128 ;; Something like
129 ;;   (global-set-key [(f9)] 'gnuplot-make-buffer)
130 ;; may be useful.  This binds f9 to the function that opens a scratch
131 ;; buffer (i.e. one that is not visiting a file) in gnuplot-mode.
132 ;; This is handy for your quick 'n' dirty plotting chores.
133 ;;
134 ;; To use the `gnuplot-info-lookup-symbol' function, the file
135 ;; gnuplot.info MUST be installed somewhere that info can find it.
136 ;; This means you must either:
137 ;;   1.  Copy gnuplot.info to the normal info directory or
138 ;;   2.  Make sure info can find gnuplot.info by putting this in your
139 ;;       .emacs file:
140 ;;         (setenv "INFOPATH"
141 ;;            (concat (getenv "INFOPATH") ":"
142 ;;                    (expand-file-name "/path/to/file")))
143 ;;       where "/path/to/file" is the location of gnuplot.info
144 ;;
145 ;; This had been tested extensively with Emacs 19.34 and 20.2 and
146 ;; XEmacs 20.3 and in a limited manner with Emacs 19.30 and XEmacs
147 ;; 19.14.
148 ;;
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150
151 ;;; History:
152
153 ;;
154 ;;  0.1   Jun 25 1998 Finished with initial release.
155 ;;  0.2   Sep  4 1998 Added filename insertion, indentation, and
156 ;;        colorization/completion in comint buffer. <BR>
157 ;;  0.2a  Sep 11 1998 made `indent-line-function' buffer-local (whoops!)
158 ;;        and fixed some stuff in the installation script <BR>
159 ;;  0.3   Sep 12 1998 include insertions menu <BR>
160 ;;  0.3a  Sep 14 1998 fixed bug finding info file if missing, fixed bug
161 ;;        starting font-lock, fixed bug re overwriting files in
162 ;;        installation script <BR>
163 ;;  0.3b  Sep 15 1998 Added (require 'info) to `(eval-and-compile'
164 ;;        clause, Added (kill-all-local-variables) to `gnuplot-mode',
165 ;;        altered order of:-
166 ;;            (provide 'gnuplot)
167 ;;            (run-hooks 'gnuplot-load-hook)
168 ;;        at the end of the file in case something in the load hook
169 ;;        requires gnuplot (oh not that old one again...), added
170 ;;        `gnuplot-comint-setup-hook', corrected `gnuplot-mark-active'
171 ;;        which caused an error to be raised by (mark) when the mark
172 ;;        was inactive <DB>  Some changes to font-lock rules <LB>&<BR>
173 ;;  0.4   Nov 14 1998 <BR> Use info-look for info interface.  No
174 ;;        change to gnuplot-mode user interface, but cleaner code.
175 ;;        With info-look, the help funcion works regardless of the
176 ;;        version number of gnuplot.  Also, `gnuplot-keywords' (used
177 ;;        for help, keyword-completion, and hilit19 highlighting) is
178 ;;        now generated automatically.
179 ;;  0.4a  Nov 18 1998 <BR> info-look leaves a couple of really useless
180 ;;        buffers lying around so I cleaned them up.  Also fixed
181 ;;        font-lock rules so that things in quotes get highlighted
182 ;;        correctly and the surrounding text is unhighlighted.  Fixed
183 ;;        up font-lock rules for plot and splot.  Added
184 ;;        `gnuplot-send-line-and-forward' as suggested by <MD>.
185 ;;  0.4b  Nov 21 1998 <BR> added toolbar for xemacs -- see file
186 ;;        gnuplot-toolbar.el.  fixed error message in plot line
187 ;;        function when line is empty.  option added to display the
188 ;;        comint buffer showing the gnuplot process in a separate
189 ;;        frame
190 ;;  0.4c  Minor stuff: Nov 30 1998 <BR> fixed highlighting in comint
191 ;;        buffer.  fixed frame behavior.  added "[:]" to range
192 ;;        insertions.  added :link to defgroup.  Dec 1 1998 <BR> fixed
193 ;;        some mismatched defcustoms.  added a few lines to suppress
194 ;;        some compile-time warnings.  Dec 3 1998 <BR> Fixed behavior
195 ;;        of filename insertion function.  Added more :links to
196 ;;        defgroup.
197 ;;  0.4d  Dec 6 1998 <BR> Added function gnuplot-setup-info-look and
198 ;;        variable gnuplot-info-hook to handle various versions of the
199 ;;        gnuplot info file.
200 ;;  0.4e  Dec 12 1998 <BR> Split up gnuplot-insertions-menu for ease of
201 ;;        custimization, put menubar initialization in a function.
202 ;;  0.4f  Dec 14 1998 <BR> defcustom the insertions submenus, add
203 ;;        gnuplot-insertion-menu-flag, intelligent Makefile knows
204 ;;        which info-look to compile
205 ;;  0.5   Dec 27 1998 <BR> wrote initial draft of gnuplot-gui.el,
206 ;;        included it in insertions menu and in `gnuplot-insert'.
207 ;;        Negate option function, bound to C-c C-n. Dec 29 1998 <BR>
208 ;;        C-c C-h with no response goes to Commands menu.  Transparent
209 ;;        toolbar icons.  Replace kw-compl with a simple completion
210 ;;        function.  Put gnuplot-toolbar code in gnuplot.el.
211 ;;  0.5a  Jan 23 1999 <BR> send file uses the load command.  add
212 ;;        gnuplot-plot-from-comint and
213 ;;        gnuplot-save-and-plot-from-comint and keybindings in the
214 ;;        comint buffer.  do (process-kill-without-query
215 ;;        gnuplot-process nil).  `gnuplot-negate-option' checks if set
216 ;;        option has a negated form.
217 ;;  0.5b  `gnuplot-kill-gnuplot-buffer' made more robust.  fixed a bug
218 ;;        in `gnuplot-plot-from-comint'.  fixed description of
219 ;;        gnuplot-faces group.
220 ;;  0.5c  update copyright information, update gpelcard
221 ;;  0.5d  Mar 20 1999 <BR> adopt installation materials from <LH>.  Add
222 ;;        some support for hidden3d.  Use constants in types alists in
223 ;;        gui.  Various other minor improvements to the types alists.
224 ;;  0.5e  Apr 6 1999 <BR> at the suggestion of <SE> I did away with the
225 ;;        gnuplot-which-highlight variable and revamped how
226 ;;        colorization gets turned on.  This is a bit tricky since I
227 ;;        want it to work with font-lock under emacs and xemacs and
228 ;;        with hilit19.  Apr 11 1999 <BR> insert space at end of
229 ;;        unique completion.  add a few GUI types, rewrite some stuff
230 ;;        in the GUI interface.  primitive support for plot, splot,
231 ;;        and fit.  Fixed completion in file widget.
232 ;;  0.5f  May 15 1999 <BR> Add pgnuplot.c and Win9x install instructions
233 ;;        to the distribution.  Fixed a defface bug.  Added
234 ;;        `gnuplot-keywords-when' allowing deferral of parsing the
235 ;;        info file.
236 ;;  0.5g  May 27 1999 <BR> Fixed font-locking of strings and
237 ;;        comments.  Figure out gnuplot-version number from startup
238 ;;        message and set `gnuplot-echo-command-line-flag'
239 ;;        accordingly.  Added `gnuplot-program-version' variable.
240 ;;        Check that font-lock is actually a feature, as suggested by
241 ;;        <KL>
242 ;;  0.5h  Aug 15 1999 <BR> Added `gnuplot-determine-gnuplot-version' so
243 ;;        that the gnuplot version number and `comint-process-echos'
244 ;;        actually get set correctly.  Actually, the first time
245 ;;        something is plotted, the echoing might not work, but the
246 ;;        second time it will.
247 ;;  0.5i  Sep  2 1999 <BR> Once again changed how
248 ;;        `comint-process-echos' gets set.  Maybe I got it right this
249 ;;        time?  Also fixed certain situations where the info file
250 ;;        did notget properly loaded (insertion with info toggle on
251 ;;        and info button in GUI).
252 ;;  0.5j  Sep  9 1999 <BR> Do a more robust check for the gnuplot
253 ;;        process before killing the gnuplot buffer, as suggested by
254 ;;        <SE>.
255 ;;  0.5k  Sep 22 1999 <BR> make `gnuplot-send-line-and-forward' skip
256 ;;        over blank and comment lines as suggested by <SE>.  Jan 10
257 ;;        2000 Bound C-c C-j to `gnuplot-forward-script-line'.
258 ;;  0.5l  Nov 16 2000 <BR> support for pm3d in gnuplot-gui and in plot
259 ;;        options insertions menu.  mentioned pm3d in gpelcard. gui
260 ;;        support for x11 pm3d and vgagl terms.
261 ;;        `gnuplot-negate-option' works with new syntax.
262 ;;  0.5m  Nov 17 2000 <BR> add colorization and gui support for new
263 ;;        commands in 3.8.  gui support for emf term. gui support for
264 ;;        new "set style" syntax.  much better scheme for determining
265 ;;        gnuplot version number + make better use of it.
266 ;;  0.5n  Jan 4 2001 <BR> corrected a serious problem interacting with
267 ;;        speedbar
268 ;;  0.5o  skipped
269 ;;  0.5p  Mar 14 2001 <BR> fixed problem with toolbar creation and
270 ;;        speedbar clicking
271 ;;  0.5q  May 30 2001 <BR> added font-lock bindings for words associated
272 ;;        with plotting
273 ;;  0.5r  Oct 17 2001 <BR> Incorporate two suggestions by <RF>, bind
274 ;;        C-c C-c to comment-region and C-c C-o to the GUI, also make
275 ;;        C-c C-l respect continuation lines
276 ;;        April 12, 2002 <BR> added feature to trim length of gnuplot
277 ;;        process buffer
278 ;;  0.5s  Jun 7 2002 <BR> Yet again changed how `comint-process-echos'
279 ;;        gets set.  It really needs to be nil on NTEmacs 21.1 or
280 ;;        comint gets stuck in an infinate loop.
281 ;;  0.5t  Sep 16 2002 <BR> Fixed a problem with C-c C-v jumping
282 ;;        forward 2 lines at a time
283 ;;  0.6.0 Dec 13 2002 <BR> Changed numbering scheme to accommodate
284 ;;        gnuplot packaging requirements
285 ;;  0.6.1 Sep 13 2011 <BR> Moved to github, updated contact info
286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 ;;; Acknowledgements:
288 ;;    David Batty       <DB> (numerous corrections)
289 ;;    Laurent Bonnaud   <LB> (suggestions regarding font-lock rules)
290 ;;    Markus Dickebohm  <MD> (suggested `gnuplot-send-line-and-forward')
291 ;;    Stephen Eglan     <SE> (suggested the use of info-look,
292 ;;                            contributed a bug fix regarding shutting
293 ;;                            down the gnuplot process, improvement to
294 ;;                            `gnuplot-send-line-and-forward')
295 ;;    Robert Fenk       <RF> (suggested respecting continuation lines)
296 ;;    Michael Karbach   <MK> (suggested trimming the gnuplot process buffer)
297 ;;    Alex Chan Libchen <AL> (suggested font-lock for plotting words)
298 ;;    Kuang-Yu Liu      <KL> (pointed out buggy dependence on font-lock)
299 ;;    Hrvoje Niksic     <HN> (help with defcustom arguments for insertions)
300 ;;    Andreas Rechtsteiner <AR> (pointed out problem with C-c C-v)
301 ;;    Michael Sanders   <MS> (help with the info-look interface)
302 ;;    Jinwei Shen       <JS> (suggested functionality in comint buffer)
303 ;;    Michael M. Tung   <MT> (prompted me to add pm3d support)
304 ;;    Holger Wenzel     <HW> (suggested using `gnuplot-keywords-when')
305 ;;    Wolfgang Zocher   <WZ> (pointed out problem with gnuplot-mode + speedbar)
306 ;;  and especially to Lars Hecking <LH> for including gnuplot-mode
307 ;;  with the gnuplot 3.7-beta distribution and for providing me with
308 ;;  installation materials
309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310 ;;; To Do:
311 ;;
312 ;; 1. Since `gnuplot-display-process' can be nil, it would be
313 ;;    handy to have a function to put on
314 ;;    `gnuplot-after-plot-buffer-hook' to check and see if the script
315 ;;    executed properly.  Alas I am not sure how gnuplot signals its
316 ;;    errors.
317 ;; 2. improve plot, splot, fit in GUI
318 ;; 3. interface to setting bind command using `read-key-sequence'.
319 ;;    this is a pain because the nomenclature is really different in
320 ;;    gnuplot than in `read-key-sequence'
321 ;;
322 ;;
323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
324
325 ;;; Code:
326
327 (require 'comint)
328 (require 'easymenu)
329
330 \f
331 ;;; --- variable definitions + eval-and-compile clauses
332
333 ;; handle defcustom
334 (eval-and-compile
335   (condition-case ()
336       (require 'custom)
337     (error nil))
338   (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
339       nil ;; We've got what we needed
340     ;; We have the old custom-library, hack around it!
341     (if (fboundp 'defgroup)
342         nil
343       (defmacro defgroup (&rest args)
344         nil))
345     (if (fboundp 'defface)
346         nil
347       (defmacro defface (var values doc &rest args)
348         (` (progn
349              (defvar (, var) (quote (, var)))
350              ;; To make colors for your faces you need to set your .Xdefaults
351              ;; or set them up ahead of time in your .emacs file.
352              (make-face (, var))
353              ))))
354     (if (fboundp 'defcustom)
355         nil
356       (defmacro defcustom (var value doc &rest args)
357         (` (defvar (, var) (, value) (, doc)))))))
358
359 ;; (eval-and-compile
360 ;;   (condition-case ()
361 ;;       (require 'kw-compl)
362 ;;     (error nil)))
363 (eval-and-compile  ;; <DB>
364   (require 'info))
365 (eval-and-compile
366   (condition-case ()
367       (require 'info-look)
368     (error nil)))
369
370 ;; this just gets rid of an annoying compile time error message
371 ;; (eval-when-compile
372 ;;   (defun gnuplot-dummy ())
373 ;;   (defalias 'hilit-set-mode-patterns 'gnuplot-dummy))
374
375
376 (defconst gnuplot-xemacs-p (string-match "XEmacs" (emacs-version)))
377 (defconst gnuplot-ntemacs-p (string-match "msvc" (emacs-version)))
378 (defvar   gnuplot-three-eight-p "")
379
380 (defconst gnuplot-maintainer "Bruce Ravel")
381 (defconst gnuplot-maintainer-email "ravel@phys.washington.edu")
382 (defconst gnuplot-maintainer-url
383   "http://github.com/bruceravel/gnuplot-mode/")
384 (defconst gnuplot-version "0.6.1")
385
386 (defgroup gnuplot nil
387   "Gnuplot-mode for Emacs."
388   :prefix "gnuplot-"
389   :group 'processes
390   :group 'applications
391   :group 'local
392   :link '(emacs-library-link :tag "Lisp File" "gnuplot.el")
393   :link '(url-link :tag "Homepage"
394                    "http://github.com/bruceravel/gnuplot-mode/")
395   :link '(custom-manual "(gnuplot)Top")
396   :link '(emacs-commentary-link :tag "Commentary" "gnuplot.el") )
397 (defgroup gnuplot-insertions nil
398   "Insert commands into gnuplot-scripts from a pull-down menu."
399   :prefix "gnuplot-insertions-"
400   :group 'gnuplot)
401 (defgroup gnuplot-hooks nil
402   "Hook variables used by `gnuplot-mode'."
403   :prefix "gnuplot-"
404   :group 'gnuplot)
405
406 (defcustom gnuplot-mode-hook nil
407   "*Hook run when `gnuplot-mode' is entered."
408   :group 'gnuplot-hooks
409   :type 'hook)
410 (defcustom gnuplot-load-hook nil
411   "*Hook run when gnuplot.el is first loaded."
412   :group 'gnuplot-hooks
413   :type 'hook)
414 (defcustom gnuplot-after-plot-hook nil
415   "*Hook run after gnuplot plots something.
416 This is the last thing done by the functions for plotting a line, a
417 region, a buffer, or a file."
418   :group 'gnuplot-hooks
419   :type 'hook)
420
421 (defcustom gnuplot-info-hook nil
422   "*Hook run before setting up the info-look interface.
423 This hook is necessary to handle inconsistencies in versions of and
424 sources of the gnuplot info file.  If Gnuplot-mode can find the info
425 file generated from the 3.6beta patchlevel 347 (or later) release of
426 Gnuplot, then this hook probably is not necessary.  Some versions of
427 the info file may have a General Index session, which can be used by
428 info-look.  In that case the following (or something similar with the
429 value of `info-lookup-symbol-alist' altered appropriately) should be
430 placed in the .emacs file.
431
432 Emacs version 20.2 ships with a different version of info-look that
433 does 20.3.  If you use any version of Emacs 19, you must use the
434 version from 20.2.  Any version of XEmacs 20 or 21 should use the
435 version from 20.3 but can use either.  XEmacs 19 should use the
436 version 20.2.
437
438 For the newer version of info-look, do this:
439
440   (add-hook \'gnuplot-info-hook
441             \'(lambda ()
442                (let ((elem (assoc \'gnuplot-mode info-lookup-alist)))
443                  (delete elem info-lookup-alist)
444                  (info-lookup-maybe-add-help
445                   :mode 'gnuplot-mode :topic 'symbol
446                   :regexp \"[a-zA-Z][_a-zA-Z0-9]*\"
447                   :doc-spec '((\"(gnuplot)General Index\" nil
448                                \"[_a-zA-Z0-9]+\"))))))
449
450 For the older version of info-look, do this:
451
452   (add-hook \'gnuplot-info-hook
453             \'(lambda ()
454                (let ((elem (assoc \'gnuplot-mode info-lookup-alist)))
455                  (delete elem info-lookup-alist)
456                  (setq info-lookup-alist
457                        (append info-lookup-alist
458                                \'((gnuplot-mode
459                                   \"[a-zA-Z][_a-zA-Z0-9]*\" nil
460                                   ((\"(gnuplot)General Index\" nil
461                                     \"[_a-zA-Z0-9]+\" )))))))))"
462   :group 'gnuplot-hooks
463   :type 'hook)
464
465 ;; comint hook suggested by <DB>
466 (defcustom gnuplot-comint-setup-hook nil
467   "*Hook run after setting up the gnuplot buffer in comint mode.
468 So the configuration can be customised by the user."
469   :group 'gnuplot-hooks
470   :type 'hook)
471
472 (defcustom gnuplot-comint-mode-hook nil
473   "*Hook run after setting up the gnuplot buffer in gnuplot-comint-mode.
474 By default this runs the hook named `gnuplot-comint-setup-hook',
475 for backward compatibility."
476   :group 'gnuplot-hooks
477   :type 'hook)
478
479 (defvar gnuplot-recently-sent nil
480   "This is a record of the most recent kind of text sent to gnuplot.
481 It takes as its value nil, 'line, 'region, 'buffer, or 'file.  It is
482 useful for functions included in `gnuplot-after-plot-hook'.")
483 (make-variable-buffer-local 'gnuplot-recently-sent)
484
485 (defcustom gnuplot-program "gnuplot"
486   "*The name of the gnuplot executable."
487   :group 'gnuplot
488   :type 'string)
489 (defvar gnuplot-program-version nil
490   "Version number of gnuplot.
491 This is using `gnuplot-fetch-version-number'.")
492 (defvar gnuplot-program-major-version nil
493   "Major version number of gnuplot.
494 This is found using `gnuplot-fetch-version-number'.")
495 (defvar gnuplot-program-minor-version nil
496   "Minor version number of gnuplot.
497 This is found using `gnuplot-fetch-version-number'.")
498
499 (defcustom gnuplot-process-name "gnuplot"
500   "Name given to the gnuplot buffer and process."
501   :group 'gnuplot
502   :type 'string)
503 (defvar gnuplot-buffer nil
504   "*The name of the buffer displaying the gnuplot process.")
505 (defvar gnuplot-process nil
506   "Variable holding the process handle.")
507 (defvar gnuplot-process-frame nil
508   "The frame for displaying the gnuplot process.
509 This is used when `gnuplot-display-process' is equal to 'frame.")
510 (defvar gnuplot-comint-recent-buffer nil
511   "The most recently plotted gnuplot script buffer.
512 This is used by the function that plot from the comint buffer.  It is
513 reset every time something is plotted from a script buffer.")
514
515 (defcustom gnuplot-gnuplot-buffer "plot.gp"
516   "*The name of the gnuplot scratch buffer opened by 'gnuplot-make-buffer'."
517   :group 'gnuplot
518   :type 'string)
519
520 (defcustom gnuplot-display-process 'window
521   "This controls how the gnuplot process buffer is displayed.
522 The values are
523    'frame    display gnuplot process in a separate frame
524    'window   display gnuplot process in this frame but in another window
525    nil       `gnuplot-process' is in the current frame but not displayed"
526   :group 'gnuplot
527   :type '(radio (const :tag "Separate frame"  frame)
528                 (const :tag "Separate window" window)
529                 (const :tag "Not displayed"   nil)))
530 (defcustom gnuplot-info-display 'window
531   "*Determines how `gnuplot-info-lookup-symbol' displays the info file.
532 The values are
533    'frame    display info file in a separate frame
534    'window   display info file in another window
535    nil       display info file in the current window"
536   :group 'gnuplot
537   :type '(radio (const :tag "Separate frame"  frame)
538                 (const :tag "Separate window" window)
539                 (const :tag "This window"     nil)))
540
541 (defcustom gnuplot-echo-command-line-flag (not gnuplot-ntemacs-p)
542   "*This sets the fall-back value of `comint-process-echos'.
543 If `gnuplot-mode' cannot figure out what version number of gnuplot
544 this is, then the value of this variable will be used for
545 `comint-process-echos'.  It seems that gnuplot 3.5 wants this to be
546 nil and 3.7 wants it to be t.  If lines that you send to gnuplot from
547 the `gnuplot-mode' buffer are not appearing at the gnuplot prompt in
548 the process buffer, try toggling it.  Also see the document string for
549 `comint-process-echos'.  If you change this, kill the gnuplot process
550 and start it again."
551   :group 'gnuplot
552   :type 'boolean)
553 (defcustom gnuplot-insertions-show-help-flag nil
554   "*Non-nil means to display certain help messages automatically.
555 These messages are shown after menu insertion of gnuplot commands."
556   :group 'gnuplot-insertions
557   :type 'boolean)
558
559 (defcustom gnuplot-delay 0.01
560   "*Amount of time to delay before sending a new line to gnuplot.
561 This is needed so that the the line is not written in the gnuplot
562 buffer in advance of its prompt.  Increase this number if the
563 prompts and lines are displayed out of order."
564   :group 'gnuplot
565   :type 'number)
566 (defcustom gnuplot-buffer-max-size 1000
567   "*The maximum size in lines of the gnuplot process buffer.
568 Each time text is written in the gnuplot process buffer, lines are
569 trimmed from the beginning of the buffer so that the buffer is this
570 many lines long.  The lines are deleted after the most recent lines
571 were interpretted by gnuplot.  Setting to 0 turns off this feature
572 \(i.e. no lines get trimmed)."
573   :group 'gnuplot
574   :type 'integer)
575 (defcustom gnuplot-quote-character "\'"
576   "*Quotation character used for inserting quoted strings.
577 Gnuplot can use single or double quotes.  If you prefer to have the
578 filename insertion function never insert quotes for you, set this
579 to the empty string."
580   :group 'gnuplot
581   :type '(radio (const :tag "double quote"  "\"")
582                 (const :tag "single quote"  "\'")
583                 (const :tag "none"          ""  )))
584 ;; (defcustom gnuplot-gnuplot-version nil
585 ;;   "*Force gnuplot-mode to behave for this version of gnuplot."
586 ;;   :group 'gnuplot
587 ;;   :type '(radio (const :tag "unspecified"   nil)
588 ;;              (const :tag "3.8 or newer" "3.8")
589 ;;              (const :tag "3.7 or older" "3.7")))
590
591 (defvar gnuplot-info-frame nil)
592 (defvar gnuplot-info-nodes '())
593
594 (defvar gnuplot-first-call t)
595
596 ;; with info-look, there is no need to carry this list around -- it
597 ;; can be generated on the fly appropriate to the currently installed
598 ;; version of gnuplot.info
599 (defvar gnuplot-keywords nil
600   "A list of keywords used in GNUPLOT.
601 These are set by `gnuplot-set-keywords-list' from the values in
602 `info-lookup-cache'.")
603 (defvar gnuplot-keywords-alist nil) ;; For all-completions
604 (defvar gnuplot-keywords-pending t      ;; <HW>
605   "A boolean which gets toggled when the info file is probed.")
606 (defcustom gnuplot-keywords-when 'deferred ;; 'immediately
607   "This variable controls when the info file is parsed.
608 The choices are immediately upon starting gnuplot-mode or the first
609 time that data is needed.  If you use hilit19, then the info file is
610 parsed immediately regardless of the value of this variable.  But
611 you're not using that musty old thing, are you..."
612   :group 'gnuplot
613   :type
614   '(radio (const :tag "Parse info file when gnuplot-mode starts"    immediately)
615           (const :tag "Parse info file the first time it is needed" deferred)))
616
617 (defgroup gnuplot-faces nil
618   "Text faces used by gnuplot-mode."
619   :prefix "gnuplot-"
620   :group 'gnuplot)
621
622 (cond ((and (featurep 'custom) (fboundp 'custom-declare-variable))
623        (defface gnuplot-prompt-face '((((class color))
624                                        (:foreground "firebrick"))
625                                       (t
626                                        (:bold t :underline t)))
627          "Face used for the prompt in the gnuplot process buffer."
628          :group 'gnuplot-faces))
629       (t
630        (make-face 'gnuplot-prompt-face)
631        (set-face-foreground 'gnuplot-prompt-face "firebrick")))
632
633 \f
634 ;;; --- key bindings and menus
635
636 (defvar gnuplot-mode-map nil)
637 (unless gnuplot-mode-map
638   (setq gnuplot-mode-map (make-sparse-keymap))
639
640   (define-key gnuplot-mode-map "\C-c\C-b" 'gnuplot-send-buffer-to-gnuplot)
641   (define-key gnuplot-mode-map "\C-c\C-c" 'comment-region) ; <RF>
642   (define-key gnuplot-mode-map "\C-c\C-o" 'gnuplot-gui-set-options-and-insert)
643   (define-key gnuplot-mode-map "\C-c\C-d" 'gnuplot-show-version)
644   (define-key gnuplot-mode-map "\C-c\C-e" 'gnuplot-show-gnuplot-buffer)
645   (define-key gnuplot-mode-map "\C-c\C-f" 'gnuplot-send-file-to-gnuplot)
646   (define-key gnuplot-mode-map "\C-c\C-h"    'gnuplot-info-lookup-symbol)
647   (define-key gnuplot-mode-map "\C-c\C-i" 'gnuplot-insert-filename)
648   (define-key gnuplot-mode-map "\C-c\C-j" 'gnuplot-forward-script-line)
649   (define-key gnuplot-mode-map "\C-c\C-k" 'gnuplot-kill-gnuplot-buffer)
650   (define-key gnuplot-mode-map "\C-c\C-l" 'gnuplot-send-line-to-gnuplot)
651   (define-key gnuplot-mode-map "\C-c\C-n" 'gnuplot-negate-option)
652   (define-key gnuplot-mode-map "\C-c\C-p" 'gnuplot-show-gnuplot-version)
653   (define-key gnuplot-mode-map "\C-c\C-r" 'gnuplot-send-region-to-gnuplot)
654   ;;(define-key gnuplot-mode-map "\C-c\C-t" 'gnuplot-gui-swap-simple-complete)
655   (define-key gnuplot-mode-map "\C-c\C-u" 'gnuplot-bug-report)
656   (define-key gnuplot-mode-map "\C-c\C-v" 'gnuplot-send-line-and-forward)
657   (define-key gnuplot-mode-map "\C-c\C-z" 'gnuplot-customize)
658   (define-key gnuplot-mode-map "\C-i"     'indent-for-tab-command)
659   (define-key gnuplot-mode-map "\C-m"     'newline-and-indent)
660
661   (let ((completion-function
662          (if (featurep 'xemacs)
663              'gnuplot-xemacs-completion-at-point
664            'completion-at-point)))
665     (define-key gnuplot-mode-map "\M-\r"    completion-function)
666     (define-key gnuplot-mode-map "\M-\t"    completion-function))
667
668   ;;(define-key gnuplot-mode-map "\C-m"     'reindent-then-newline-and-indent)
669   ;;(if (featurep 'kw-compl)
670   ;;    (define-key gnuplot-mode-map "\M-\r" 'kw-compl-abbrev)))
671   (cond (gnuplot-xemacs-p
672          (define-key gnuplot-mode-map '(shift button2)
673            'gnuplot-gui-mouse-set))
674         (t
675          (define-key gnuplot-mode-map [S-mouse-2]
676            'gnuplot-gui-mouse-set))))
677
678 (defvar gnuplot-mode-menu nil)
679 (defvar gnuplot-menu nil
680   "Menu for `gnuplot-mode'.")
681 (setq gnuplot-menu
682       '("Gnuplot"
683         ["Send line to gnuplot"             gnuplot-send-line-to-gnuplot   t]
684         ["Send line & move forward"         gnuplot-send-line-and-forward (not (eobp))]
685         ["Send region to gnuplot"           gnuplot-send-region-to-gnuplot
686          (gnuplot-mark-active)]
687         ["Send buffer to gnuplot"           gnuplot-send-buffer-to-gnuplot t]
688         ["Send file to gnuplot"             gnuplot-send-file-to-gnuplot t]
689         "---"
690         ["Insert filename at point"         gnuplot-insert-filename t]
691         ["Negate set option"                gnuplot-negate-option t]
692         ;;["Set key binding"             gnuplot-set-binding gnuplot-three-eight-p]
693         ["Keyword help"                     gnuplot-info-lookup-symbol
694          (or gnuplot-keywords gnuplot-keywords-pending)]
695         ["Show gnuplot process buffer"      gnuplot-show-gnuplot-buffer t]
696         ["Set arguments at point"           gnuplot-gui-set-options-and-insert
697          (fboundp 'gnuplot-gui-set-options-and-insert)]
698         ["Swap plot/splot/fit lists in GUI" gnuplot-gui-swap-simple-complete
699          (fboundp 'gnuplot-gui-swap-simple-complete)]
700         "---"
701         ["Customize gnuplot"                gnuplot-customize t]
702         ["Submit bug report"                gnuplot-bug-report t]
703         ["Show gnuplot-mode version"        gnuplot-show-version t]
704         ["Show gnuplot version"             gnuplot-show-gnuplot-version t]
705         "---"
706         ["Kill gnuplot"                     gnuplot-kill-gnuplot-buffer t]
707         ))
708
709 \f
710 ;;; --- insertions variables and menus
711
712 ;;(load-library "gnuplot-insertions")
713 (defvar gnuplot-mode-insertions-menu nil)
714 (defvar gnuplot-insertions-menu nil
715   "Menu for insertions in `gnuplot-mode'.
716
717 The insertions menu is composed of several sub-menus.  The variables
718 describing the sub-menus are:
719   `gnuplot-insertions-adornments'
720   `gnuplot-insertions-plot-options'
721   `gnuplot-insertions-terminal'
722   `gnuplot-insertions-x-axis'
723   `gnuplot-insertions-y-axis'
724   `gnuplot-insertions-z-axis'
725   `gnuplot-insertions-x2-axis'
726   `gnuplot-insertions-y2-axis'
727   `gnuplot-insertions-parametric-plots'
728   `gnuplot-insertions-polar-plots'
729   `gnuplot-insertions-surface-plots'
730 These variables can be customized by the user.  For example, there are
731 many terminal types which are not in the terminal submenu but which
732 may be compiled into a user's copy of gnuplot.
733
734 Each of these variables is a list whose first element is a string and
735 all the rest are vectors as described in the document string for
736 `easy-menu-define'.  The callback used throughout these menus is
737 `gnuplot-insert' which inserts the appropriate set expression and,
738 optionally, looks up that item in the gnuplot info file.
739
740 The easiest way to customize the submenus is to use the custom
741 package.  Just type \\[gnuplot-customize] and follow your nose.
742
743 You can also add new items to any of these sub-menus by adding to the
744 `gnuplot-load-hook' in your .emacs file.  Here is an example of adding
745 the \"regis\" terminal type to the terminal sub-menu:
746
747  (add-hook
748   'gnuplot-load-hook
749   '(lambda ()
750       (setq gnuplot-insertions-terminal
751             (append gnuplot-insertions-terminal
752                     (list
753                      [\"regis\"
754                       (gnuplot-insert \"set terminal regis\")
755                        t])))))")
756
757 (defvar gnuplot-insertions-top ()
758   "Top part of insertions menu.
759 See the document string for `gnuplot-insertions-menu'")
760
761 (defcustom gnuplot-insertions-menu-flag t
762   "*Non-nil means to place the insertion menu in the menubar.
763 Changing this will not effect a change in any currently existing
764 `gnuplot-mode' buffer.  You will see the change the next time you
765 create a `gnuplot-mode' buffer."
766   :group 'gnuplot-insertions
767   :type 'boolean)
768
769 (defcustom gnuplot-insertions-adornments ; this is icky...
770   (if gnuplot-three-eight-p
771       '("adornments"
772         ["arrow"       (gnuplot-insert "set arrow ")          t]
773         ["bar"         (gnuplot-insert "set bar")             t]
774         ["border"      (gnuplot-insert "set border")          t]
775         ["boxwidth"    (gnuplot-insert "set boxwidth ")       t]
776         ["format"      (gnuplot-insert "set format ")         t]
777         ["grid"        (gnuplot-insert "set grid")            t]
778         ["key"         (gnuplot-insert "set key ")            t]
779         ["label"       (gnuplot-insert "set label ")          t]
780         ["pointsize"   (gnuplot-insert "set pointsize ")      t]
781         ["samples"     (gnuplot-insert "set samples ")        t]
782         ["size"        (gnuplot-insert "set size ")           t]
783         ["style"       (gnuplot-insert "set style ")          t]
784         ["tics"        (gnuplot-insert "set tics ")           t]
785         ["timefmt"     (gnuplot-insert "set timefmt ")        t]
786         ["timestamp"   (gnuplot-insert "set timestamp ")      t]
787         ["title"       (gnuplot-insert "set title ")          t]
788         ["zeroaxis"    (gnuplot-insert "set zeroaxis")        t] )
789     '("adornments"
790       ["data style"     (gnuplot-insert "set data style ")     t]
791       ["function style" (gnuplot-insert "set function style ") t]
792       ["arrow"          (gnuplot-insert "set arrow ")          t]
793       ["bar"            (gnuplot-insert "set bar")             t]
794       ["border"         (gnuplot-insert "set border")          t]
795       ["boxwidth"       (gnuplot-insert "set boxwidth ")       t]
796       ["format"         (gnuplot-insert "set format ")         t]
797       ["grid"           (gnuplot-insert "set grid")            t]
798       ["key"            (gnuplot-insert "set key ")            t]
799       ["label"          (gnuplot-insert "set label ")          t]
800       ["pointsize"      (gnuplot-insert "set pointsize ")      t]
801       ["samples"        (gnuplot-insert "set samples ")        t]
802       ["size"           (gnuplot-insert "set size ")           t]
803       ["tics"           (gnuplot-insert "set tics ")           t]
804       ["timefmt"        (gnuplot-insert "set timefmt ")        t]
805       ["timestamp"      (gnuplot-insert "set timestamp ")      t]
806       ["title"          (gnuplot-insert "set title ")          t]
807       ["zeroaxis"       (gnuplot-insert "set zeroaxis")        t] ))
808   "Adornments submenu in the insertions menu.
809 See the document string for `gnuplot-insertions-menu'
810 Changing this will not effect a change in any currently existing
811 `gnuplot-mode' buffer.  You will see the change the next time you
812 create a `gnuplot-mode' buffer."
813         :group 'gnuplot-insertions
814         :type '(list (string :tag "Title")
815                      (repeat :inline t
816                              (vector (string   :tag "Name")
817                                      (function :tag "Callback")
818                                      (boolean  :tag "Enabled" t)))))
819
820
821
822 (defcustom gnuplot-insertions-plot-options
823   '("plot options"
824     ["autoscale"  (gnuplot-insert "set autoscale ")          t]
825     ["clip"       (gnuplot-insert "set clip ")               t]
826     ["encoding"   (gnuplot-insert "set encoding ")           t]
827     ["locale"     (gnuplot-insert "set locale ")             t]
828     ["logscale"   (gnuplot-insert "set logscale ")           t]
829     ["multiplot"  (gnuplot-insert "set multiplot")           t]
830     ["missing"    (gnuplot-insert "set missing \"\"")        t]
831     ["palette"    (gnuplot-insert "set palette ")            t] ; <MT>
832     ["pm3d"       (gnuplot-insert "set pm3d ")               t]
833     ["offsets"    (gnuplot-insert "set offsets ")            t]
834     ["output"     (gnuplot-insert "set output ")             t]
835     ["zero"       (gnuplot-insert "set zero ")               t] )
836   "Plot options submenu in the insertions menu.
837 See the document string for `gnuplot-insertions-menu'
838 Changing this will not effect a change in any currently existing
839 `gnuplot-mode' buffer.  You will see the change the next time you
840 create a `gnuplot-mode' buffer."
841   :group 'gnuplot-insertions
842   :type '(list (string :tag "Title")
843                (repeat :inline t
844                        (vector (string   :tag "Name")
845                                (function :tag "Callback")
846                                (boolean  :tag "Enabled" t)))))
847
848
849 (defcustom gnuplot-insertions-terminal
850   '("terminal"
851     ["eepic"      (gnuplot-insert "set terminal eepic")      t]
852     ["fig"        (gnuplot-insert "set terminal fig")        t]
853     ["gpic"       (gnuplot-insert "set terminal gpic")       t]
854     ["latex"      (gnuplot-insert "set terminal latex")      t]
855     ["linux"      (gnuplot-insert "set terminal linux")      t]
856     ["pbm"        (gnuplot-insert "set terminal pbm")        t]
857     ["png"        (gnuplot-insert "set terminal png")        t]
858     ["postscript" (gnuplot-insert "set terminal postscript") t]
859     ["pslatex"    (gnuplot-insert "set terminal pslatex")    t]
860     ["table"      (gnuplot-insert "set terminal table")      t]
861     ["tek40xx"    (gnuplot-insert "set terminal tek40xx")    t]
862     ["tkcanvas"   (gnuplot-insert "set terminal tkcanvas")   t]
863     ["tpic"       (gnuplot-insert "set terminal tpic")       t]
864     ["vgagl"      (gnuplot-insert "set terminal vgagl")      t] ; for pm3d patch
865     ["vttek"      (gnuplot-insert "set terminal vttek")      t]
866     ["x11"        (gnuplot-insert "set terminal x11")        t] )
867   "Terminal submenu in the insertions menu.
868 See the document string for `gnuplot-insertions-menu'
869 Changing this will not effect a change in any currently existing
870 `gnuplot-mode' buffer.  You will see the change the next time you
871 create a `gnuplot-mode' buffer."
872   :group 'gnuplot-insertions
873   :type '(list (string :tag "Title")
874                (repeat :inline t
875                        (vector (string   :tag "Name")
876                                (function :tag "Callback")
877                                (boolean  :tag "Enabled" t)))))
878
879
880 (defcustom gnuplot-insertions-x-axis
881   '("x-axis"
882     ["xdata"      (gnuplot-insert "set xdata ")              t]
883     ["xlabel"     (gnuplot-insert "set xlabel ")             t]
884     ["xrange"     (gnuplot-insert "set xrange [:]")          t]
885     ["xtics"      (gnuplot-insert "set xtics ")              t]
886     ["mxtics"     (gnuplot-insert "set mxtics ")             t]
887     ["xzeroaxis"  (gnuplot-insert "set xzeroaxis ")          t]
888     ["xdtics"     (gnuplot-insert "set xdtics ")             t]
889     ["xmtics"     (gnuplot-insert "set xmtics ")             t])
890   "X-axis submenu in the insertions menu.
891 See the document string for `gnuplot-insertions-menu'
892 Changing this will not effect a change in any currently existing
893 `gnuplot-mode' buffer.  You will see the change the next time you
894 create a `gnuplot-mode' buffer."
895   :group 'gnuplot-insertions
896   :type '(list (string :tag "Title")
897                (repeat :inline t
898                        (vector (string   :tag "Name")
899                                (function :tag "Callback")
900                                (boolean  :tag "Enabled" t)))))
901
902
903 (defcustom gnuplot-insertions-x2-axis
904   '("x2-axis"
905     ["x2data"     (gnuplot-insert "set xdata ")              t]
906     ["x2label"    (gnuplot-insert "set xlabel ")             t]
907     ["x2range"    (gnuplot-insert "set xrange [:]")          t]
908     ["x2tics"     (gnuplot-insert "set xtics ")              t]
909     ["mx2tics"    (gnuplot-insert "set mxtics ")             t]
910     ["x2zeroaxis" (gnuplot-insert "set xzeroaxis ")          t]
911     ["x2dtics"    (gnuplot-insert "set xdtics ")             t]
912     ["x2mtics"    (gnuplot-insert "set xmtics ")             t])
913   "X2-axis submenu in the insertions menu.
914 See the document string for `gnuplot-insertions-menu'
915 Changing this will not effect a change in any currently existing
916 `gnuplot-mode' buffer.  You will see the change the next time you
917 create a `gnuplot-mode' buffer."
918   :group 'gnuplot-insertions
919   :type '(list (string :tag "Title")
920                (repeat :inline t
921                        (vector (string   :tag "Name")
922                                (function :tag "Callback")
923                                (boolean  :tag "Enabled" t)))))
924
925
926 (defcustom gnuplot-insertions-y-axis
927   '("y-axis"
928     ["ydata"      (gnuplot-insert "set ydata ")              t]
929     ["ylabel"     (gnuplot-insert "set ylabel ")             t]
930     ["ymtics"     (gnuplot-insert "set ymtics ")             t]
931     ["yrange"     (gnuplot-insert "set yrange [:]")          t]
932     ["ytics"      (gnuplot-insert "set ytics ")              t]
933     ["yzeroaxis"  (gnuplot-insert "set yzeroaxis ")          t]
934     ["ydtics"     (gnuplot-insert "set ydtics ")             t]
935     ["mytics"     (gnuplot-insert "set mytics ")             t])
936   "Y-axis submenu in the insertions menu.
937 See the document string for `gnuplot-insertions-menu'
938 Changing this will not effect a change in any currently existing
939 `gnuplot-mode' buffer.  You will see the change the next time you
940 create a `gnuplot-mode' buffer."
941   :group 'gnuplot-insertions
942   :type '(list (string :tag "Title")
943                (repeat :inline t
944                        (vector (string   :tag "Name")
945                                (function :tag "Callback")
946                                (boolean  :tag "Enabled" t)))))
947
948 (defcustom gnuplot-insertions-y2-axis
949   '("y2-axis"
950     ["y2data"     (gnuplot-insert "set ydata ")              t]
951     ["y2label"    (gnuplot-insert "set ylabel ")             t]
952     ["y2range"    (gnuplot-insert "set yrange [:]")          t]
953     ["y2tics"     (gnuplot-insert "set ytics ")              t]
954     ["my2tics"    (gnuplot-insert "set mytics ")             t]
955     ["y2zeroaxis"  (gnuplot-insert "set yzeroaxis ")         t]
956     ["y2mtics"    (gnuplot-insert "set ymtics ")             t]
957     ["y2dtics"    (gnuplot-insert "set ydtics ")             t])
958   "Y2-axis submenu in the insertions menu.
959 See the document string for `gnuplot-insertions-menu'
960 Changing this will not effect a change in any currently existing
961 `gnuplot-mode' buffer.  You will see the change the next time you
962 create a `gnuplot-mode' buffer."
963   :group 'gnuplot-insertions
964   :type '(list (string :tag "Title")
965                (repeat :inline t
966                        (vector (string   :tag "Name")
967                                (function :tag "Callback")
968                                (boolean  :tag "Enabled" t)))))
969
970
971
972 (defcustom gnuplot-insertions-z-axis
973   '("z-axis"
974     ["zdata"      (gnuplot-insert "set zdata ")              t]
975     ["zlabel"     (gnuplot-insert "set zlabel ")             t]
976     ["zrange"     (gnuplot-insert "set zrange [:]")          t]
977     ["ztics"      (gnuplot-insert "set ztics ")              t]
978     ["mztics"     (gnuplot-insert "set mztics ")             t]
979     ["zdtics"     (gnuplot-insert "set zdtics ")             t]
980     ["zmtics"     (gnuplot-insert "set zmtics ")             t] )
981   "Z-axis submenu in the insertions menu.
982 See the document string for `gnuplot-insertions-menu'
983 Changing this will not effect a change in any currently existing
984 `gnuplot-mode' buffer.  You will see the change the next time you
985 create a `gnuplot-mode' buffer."
986   :group 'gnuplot-insertions
987   :type '(list (string :tag "Title")
988                (repeat :inline t
989                        (vector (string   :tag "Name")
990                                (function :tag "Callback")
991                                (boolean  :tag "Enabled" t)))))
992
993
994 (defcustom gnuplot-insertions-parametric-plots
995   '("parametric plots"
996     ["parametric" (gnuplot-insert "set parametric")          t]
997     ["isosamples" (gnuplot-insert "set isosamples ")         t]
998     ["dummy"      (gnuplot-insert "set dummy ")              t]
999     ["trange"     (gnuplot-insert "set trange [:]")          t]
1000     ["urange"     (gnuplot-insert "set urange [:]")          t]
1001     ["vrange"     (gnuplot-insert "set vrange [:]")          t] )
1002   "Parametric plots submenu in the insertions menu.
1003 See the document string for `gnuplot-insertions-menu'
1004 Changing this will not effect a change in any currently existing
1005 `gnuplot-mode' buffer.  You will see the change the next time you
1006 create a `gnuplot-mode' buffer."
1007   :group 'gnuplot-insertions
1008   :type '(list (string :tag "Title")
1009                (repeat :inline t
1010                        (vector (string   :tag "Name")
1011                                (function :tag "Callback")
1012                                (boolean  :tag "Enabled" t)))))
1013
1014
1015 (defcustom gnuplot-insertions-polar-plots
1016   '("polar plots"
1017     ["polar"      (gnuplot-insert "set polar")               t]
1018     ["angles"     (gnuplot-insert "set angles ")             t]
1019     ["rrange"     (gnuplot-insert "set rrange [:]")          t] )
1020   "Polar plots submenu in the insertions menu.
1021 See the document string for `gnuplot-insertions-menu'
1022 Changing this will not effect a change in any currently existing
1023 `gnuplot-mode' buffer.  You will see the change the next time you
1024 create a `gnuplot-mode' buffer."
1025   :group 'gnuplot-insertions
1026   :type '(list (string :tag "Title")
1027                (repeat :inline t
1028                        (vector (string   :tag "Name")
1029                                (function :tag "Callback")
1030                                (boolean  :tag "Enabled" t)))))
1031
1032
1033 (defcustom gnuplot-insertions-surface-plots
1034   '("surface plots"
1035     ["clabel"     (gnuplot-insert "set clabel ")             t]
1036     ["cntrparam"  (gnuplot-insert "set cntrparam ")          t]
1037     ["contour"    (gnuplot-insert "set contour")             t]
1038     ["dgrid3d"    (gnuplot-insert "set dgrid3d ")            t]
1039     ["hidden3d"   (gnuplot-insert "set hidden3d ")           t]
1040     ["mapping"    (gnuplot-insert "set mapping ")            t]
1041     ["surface"    (gnuplot-insert "set surface ")            t]
1042     ["view"       (gnuplot-insert "set view ")               t] )
1043   "Surface plots submenu in the insertions menu.
1044 See the document string for `gnuplot-insertions-menu'
1045 Changing this will not effect a change in any currently existing
1046 `gnuplot-mode' buffer.  You will see the change the next time you
1047 create a `gnuplot-mode' buffer."
1048   :group 'gnuplot-insertions
1049   :type '(list (string :tag "Title")
1050                (repeat :inline t
1051                        (vector (string   :tag "Name")
1052                                (function :tag "Callback")
1053                                (boolean  :tag "Enabled" t)))))
1054
1055
1056
1057 (defvar gnuplot-insertions-bottom ()
1058   "Bottom part of the insertions menu.
1059 This part contains the toggle buttons for displaying info or
1060 opening an argument-setting popup.")
1061 (setq gnuplot-insertions-bottom
1062       '("---"
1063         ["Display of info with insertion" gnuplot-toggle-info-display
1064          :style toggle :selected gnuplot-insertions-show-help-flag]
1065         ["Display GUI popup with insertion" gnuplot-gui-toggle-popup
1066          :active (fboundp 'gnuplot-gui-toggle-popup)
1067          :style toggle :selected (and (fboundp 'gnuplot-gui-toggle-popup)
1068                                       gnuplot-gui-popup-flag)] ))
1069
1070
1071 ;; Regarding a comment by <DB>:
1072 ;;
1073 ;; This is from the header in easymenu.el distributed with XEmacs:
1074 ;;
1075 ;; ;; - Function: easy-menu-add MENU [ MAP ]
1076 ;; ;;     Add MENU to the current menubar in MAP.
1077 ;; ;;
1078 ;; ;; - Function: easy-menu-remove MENU
1079 ;; ;;     Remove MENU from the current menubar.
1080 ;; ;;
1081 ;; ;; Emacs 19 never uses `easy-menu-add' or `easy-menu-remove', menus
1082 ;; ;; automatically appear and disappear when the keymaps specified by
1083 ;; ;; the MAPS argument to `easy-menu-define' are activated.
1084 ;; ;;
1085 ;; ;; XEmacs will bind the map to button3 in each MAPS, but you must
1086 ;; ;; explicitly call `easy-menu-add' and `easy-menu-remove' to add and
1087 ;; ;; remove menus from the menu bar.
1088 ;;
1089 ;; in Emacs, easy-menu-add is defined like this:
1090 ;;      (defun easy-menu-add (menu &optional map))
1091
1092 (defun gnuplot-setup-menubar ()
1093   "Initial setup of gnuplot and insertions menus."
1094   (if gnuplot-insertions-menu-flag      ; set up insertions menu
1095       (progn
1096         (if gnuplot-xemacs-p
1097             (setq gnuplot-insertions-top
1098                   '("insert set expression" "--:doubleLine"))
1099           (setq gnuplot-insertions-top
1100                 '("insert set expression" "---")))
1101         (setq gnuplot-insertions-menu
1102               (append (list "Insertions")
1103                       gnuplot-insertions-top
1104                       (list gnuplot-insertions-adornments)
1105                       (list gnuplot-insertions-plot-options)
1106                       (list gnuplot-insertions-terminal)
1107                       (list gnuplot-insertions-x-axis)
1108                       (list gnuplot-insertions-y-axis)
1109                       (list gnuplot-insertions-z-axis)
1110                       (list gnuplot-insertions-x2-axis)
1111                       (list gnuplot-insertions-y2-axis)
1112                       (list gnuplot-insertions-parametric-plots)
1113                       (list gnuplot-insertions-polar-plots)
1114                       (list gnuplot-insertions-surface-plots)
1115                       gnuplot-insertions-bottom))
1116         (easy-menu-define gnuplot-mode-insertions-menu gnuplot-mode-map
1117                           "Insertions menu used in Gnuplot-mode"
1118                           gnuplot-insertions-menu)
1119         (easy-menu-add gnuplot-mode-insertions-menu gnuplot-mode-map)))
1120   (easy-menu-define                     ; set up gnuplot menu
1121    gnuplot-mode-menu gnuplot-mode-map "Menu used in gnuplot-mode"
1122    gnuplot-menu)
1123   (easy-menu-add gnuplot-mode-menu gnuplot-mode-map) )
1124
1125 ;; There is no `mark-active' variable in XEmacs.  Hassle!  This is not
1126 ;; only replicates mark-active, but it only returns true if the region
1127 ;; is of non-zero width.
1128 ;; Error checking suggested by <DB>
1129 (defun gnuplot-mark-active ()
1130   "Return non-nil if the mark is active and it is not equal to point."
1131   (condition-case nil
1132       (and (mark) (/= (mark) (point)))
1133     (error nil)))
1134
1135 \f
1136 ;;; --- XEmacs toolbar
1137
1138 (defgroup gnuplot-toolbar nil
1139   "Toolbar used by XEmacs."
1140   :prefix "gnuplot-toolbar-"
1141   :group 'gnuplot)
1142
1143 (defcustom gnuplot-toolbar-display-flag gnuplot-xemacs-p
1144   "*Non-nil means to display display a toolbar in XEmacs."
1145   :group 'gnuplot-toolbar
1146   :type 'boolean)
1147
1148 (defcustom gnuplot-toolbar-use-toolbar (if (featurep 'toolbar) 'left-toolbar nil)
1149   "*If nil, do not use a toolbar.
1150 If it is non-nil, it must be a toolbar.  The five legal values are
1151 `default-toolbar', `top-toolbar', `bottom-toolbar', `right-toolbar',
1152 and `left-toolbar', although choosing `default-toolbar' or
1153 `top-toolbar' may be a bad idea since either will make the GNUPLOT
1154 toolbar replace the standard toolbar.  Changing this will not change
1155 the toolbar in a currently existing buffer, but it will take effect
1156 the next time you use `gnuplot-mode' and emacs.
1157
1158 This is only used if a toolbar can be displayed, thus this is used in
1159 XEmacs and ignored in FSF Emacs."
1160   :type '(choice (const default-toolbar)
1161                  (const top-toolbar)
1162                  (const bottom-toolbar)
1163                  (const left-toolbar)
1164                  (const right-toolbar)
1165                  (const :tag "No toolbar" nil))
1166   :group 'gnuplot-toolbar)
1167
1168 (defvar gnuplot-toolbar-location "")
1169
1170 (defun gnuplot-toolbar-setup-toolbar (toolbar)
1171   "Setup function for the `gnuplot-mode' toolbar.
1172 TOOLBAR contains the toolbar specification.
1173 This is basically swiped from VM."
1174   (let ((width 46) (height 46)
1175         (buffer (current-buffer))
1176         (frame (selected-frame))
1177         (tag-set '(win)))
1178     (cond
1179      ((eq (symbol-value gnuplot-toolbar-use-toolbar) right-toolbar)
1180       (setq gnuplot-toolbar-location       "right")
1181       (set-specifier right-toolbar         toolbar buffer)
1182       (set-specifier right-toolbar-width   width frame  tag-set))
1183      ((eq (symbol-value gnuplot-toolbar-use-toolbar) left-toolbar)
1184       (setq gnuplot-toolbar-location       "left")
1185       (set-specifier left-toolbar          toolbar buffer)
1186       (set-specifier left-toolbar-width    width frame  tag-set))
1187      ((eq (symbol-value gnuplot-toolbar-use-toolbar) bottom-toolbar)
1188       (setq gnuplot-toolbar-location       "bottom")
1189       (set-specifier bottom-toolbar        toolbar buffer)
1190       (set-specifier bottom-toolbar-height height frame tag-set))
1191      ((eq (symbol-value gnuplot-toolbar-use-toolbar) top-toolbar)
1192       (setq gnuplot-toolbar-location       "top")
1193       (set-specifier top-toolbar           toolbar buffer)
1194       (set-specifier top-toolbar-height    height frame tag-set))) ))
1195
1196 (defvar gnuplot-line-xpm
1197   (if (featurep 'xpm)
1198       (toolbar-make-button-list
1199        "/* XPM */
1200 static char *line[] = {
1201 /* width height num_colors chars_per_pixel */
1202 \"    40    40        5           1\",
1203 /* colors */
1204 \". c #000000\",
1205 \"a c #bebebe s backgroundToolBarColor\",
1206 \"b c #2f4f4f\",
1207 \"c c #ff6347\",
1208 \"d c #0000ff\",
1209 /* pixels */
1210 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1211 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1212 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1213 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1214 \"aaaaaaaaaaaaa..a..aaaaaaaaaaaaaaaaaaaaaa\",
1215 \"aaaaaaaaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaa\",
1216 \"aaaaaaaaaaaa..a..a....aaa...aaaaaaaaaaaa\",
1217 \"aaaaaaaaaaaa..a..a..a..a..a..aaaaaaaaaaa\",
1218 \"aaaaaaaaaaaa..a..a.aa..a.....aaaaaaaaaaa\",
1219 \"aaaaaaaaaaa..a..a..a..a..aaaaaaaaaaaaaaa\",
1220 \"aaaaaaaaaaa..a..a..a..a..a..aaaaaaaaaaaa\",
1221 \"aaaaaaaaaaa..a..a..a..aa...aaaaaaaaaaaaa\",
1222 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1223 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1224 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1225 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1226 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1227 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
1228 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
1229 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
1230 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
1231 \"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
1232 \"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
1233 \"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
1234 \"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
1235 \"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
1236 \"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
1237 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1238 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1239 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1240 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1241 \"aaaaaa............................aaaaaa\",
1242 \"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
1243 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1244 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1245 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1246 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1247 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1248 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1249 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
1250   "XPM format image used for the \"plot line\" button"))
1251
1252 (defvar gnuplot-region-xpm
1253   (if (featurep 'xpm)
1254       (toolbar-make-button-list
1255        "/* XPM */
1256 static char *region[] = {
1257 /* width height num_colors chars_per_pixel */
1258 \"    40    40        5           1\",
1259 /* colors */
1260 \". c #000000\",
1261 \"a c #bebebe s backgroundToolBarColor\",
1262 \"b c #2f4f4f\",
1263 \"c c #ff6347\",
1264 \"d c #0000ff\",
1265 /* pixels */
1266 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1267 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1268 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1269 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1270 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1271 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1272 \"aaaaaaaaaaaaaaaaaaaaaaa..aaaaaaaaaaaaaaa\",
1273 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1274 \"aaaaaa.a..a...aaa....a..aa...aa....aaaaa\",
1275 \"aaaaaa...a..a..a..a..a..a..a..a..a..aaaa\",
1276 \"aaaaaa..aa.....a.aa..a....aa..a.aa..aaaa\",
1277 \"aaaaa..a...aaaa..aa.a..a..aa....a..aaaaa\",
1278 \"aaaaa..a...a..a..a..a..a..a..a..a..aaaaa\",
1279 \"aaaa..aaaa...aaa....a..aa...aa..a..aaaaa\",
1280 \"aaaaaaaaaaaaaaaaa..aaaaaaaaaaaaaaaaaaaaa\",
1281 \"aaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaa\",
1282 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1283 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
1284 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
1285 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
1286 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
1287 \"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
1288 \"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
1289 \"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
1290 \"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
1291 \"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
1292 \"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
1293 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1294 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1295 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1296 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1297 \"aaaaaa............................aaaaaa\",
1298 \"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
1299 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1300 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1301 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1302 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1303 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1304 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1305 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
1306   "XPM format image used for the \"plot region\" button"))
1307
1308 (defvar gnuplot-buffer-xpm
1309   (if (featurep 'xpm)
1310       (toolbar-make-button-list
1311        "/* XPM */
1312 static char *buffer[] = {
1313 /* width height num_colors chars_per_pixel */
1314 \"    40    40        5           1\",
1315 /* colors */
1316 \". c #000000\",
1317 \"a c #bebebe s backgroundToolBarColor\",
1318 \"b c #2f4f4f\",
1319 \"c c #ff6347\",
1320 \"d c #0000ff\",
1321 /* pixels */
1322 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1323 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1324 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1325 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1326 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1327 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1328 \"aaaaaaaa..aaaaaaaaaa......aaaaaaaaaaaaaa\",
1329 \"aaaaaaaa..aaaaaaaaa..a..aaaaaaaaaaaaaaaa\",
1330 \"aaaaaaa....aa..a.........a...aa.a.aaaaaa\",
1331 \"aaaaaaa..a..a..a..a..a..a..a..a...aaaaaa\",
1332 \"aaaaaaa.aa....aa..a..a..a.....a..aaaaaaa\",
1333 \"aaaaaa...a.a..a..a..a..a..aaaa..aaaaaaaa\",
1334 \"aaaaaa.....a..a..a..a..a..a..a..aaaaaaaa\",
1335 \"aaaaaa....aaa..a.a..a..aa...aa..aaaaaaaa\",
1336 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1337 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1338 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1339 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
1340 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
1341 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
1342 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
1343 \"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
1344 \"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
1345 \"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
1346 \"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
1347 \"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
1348 \"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
1349 \"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1350 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1351 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1352 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1353 \"aaaaaa............................aaaaaa\",
1354 \"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
1355 \"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1356 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1357 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1358 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1359 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1360 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1361 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
1362   "XPM format image used for the \"plot buffer\" button"))
1363
1364 (defvar gnuplot-doc-xpm
1365   (if (featurep 'xpm)
1366       (toolbar-make-button-list
1367        "/* XPM */
1368 static char *book_index[] = {
1369 /* width height num_colors chars_per_pixel */
1370 \"    40    40        6            1\",
1371 /* colors */
1372 \". c #000000\",
1373 \"a c #bebebe s backgroundToolBarColor\",
1374 \"b c #2f4f4f\",
1375 \"c c #ff0000\",
1376 \"d c #ffffff\",
1377 \"e c #708090\",
1378 /* pixels */
1379 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1380 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1381 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1382 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1383 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1384 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1385 \"aaaaaa.........bbeaaaebb..........aaaaaa\",
1386 \"aaaaaa.ddddddddaaebebeaaddddddddd.aaaaaa\",
1387 \"aaaa...dab.bddeebadbdaeebedeeeeed...aaaa\",
1388 \"aaaa.c.dbaddddebeedbdeebeedebebed.c.aaaa\",
1389 \"aaaa.c.d.de.edeebeabdbbeeddebbbed.c.aaaa\",
1390 \"aaaa.c.dbad.ddebeadbdeeebeddeeeed.c.aaaa\",
1391 \"aaaa.c.dab..ddeeeedbdebeeedebebed.c.aaaa\",
1392 \"aaaa.c.dddddddeebeabdebebedeebedd.c.aaaa\",
1393 \"aaaa.c.debebedebeedbdbebeedbeeeeb.c.aaaa\",
1394 \"aaaa.c.debeeedeeeaabdaaddddebedbb.c.aaaa\",
1395 \"aaaa.c.deebeddbebedbdbaa.adeeedeb.c.aaaa\",
1396 \"aaaa.c.ddeebedeeebaba.dd.dddeeedd.c.aaaa\",
1397 \"aaaa.c.debeebdbeeedbd....ddeebeed.c.aaaa\",
1398 \"aaaa.c.deebeedeebadbd.dd.ddeeeedd.c.aaaa\",
1399 \"aaaa.c.dbbebddeeeeabd.aa.adebebbd.c.aaaa\",
1400 \"aaaa.c.deeeeedeebeabaedddddeeeedd.c.aaaa\",
1401 \"aaaa.c.dbebbbdebeadbdaeeeedebeeed.c.aaaa\",
1402 \"aaaa.c.deeebddeeebdbdeebeedeebeed.c.aaaa\",
1403 \"aaaa.c.debeeedebeeabdebebedebeebd.c.aaaa\",
1404 \"aaaa.c.deebbedeeeedbdeeeeddeeeeed.c.aaaa\",
1405 \"aaaa.c.dddddddddaadbdaddddddddddd.c.aaaa\",
1406 \"aaaa.c..........beabaeb...........c.aaaa\",
1407 \"aaaa.c.bbbbbbbbbb.bbbbbbbbbbbbbbb.c.aaaa\",
1408 \"aaaa.c.bbbbbbbbbb..e.bbbbbbbbbbbb.c.aaaa\",
1409 \"aaaa.c.bbbbbbbbbb.b.bbbbbbbbbbbbb.c.aaaa\",
1410 \"aaaa.c............e.e.............c.aaaa\",
1411 \"aaaa.cccccccccccc.a.a.ccccccccccccc.aaaa\",
1412 \"aaaa................................aaaa\",
1413 \"aaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaa\",
1414 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1415 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1416 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1417 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1418 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
1419   "XPM format image used for the \"document\" button"))
1420
1421 (defvar gnuplot-help-xpm
1422   (if (featurep 'xpm)
1423       (toolbar-make-button-list
1424        "/* XPM */
1425 static char *help_btn[] = {
1426 /* width height num_colors chars_per_pixel */
1427 \"    40    40        3            1\",
1428 /* colors */
1429 \"a c #bebebe s backgroundToolBarColor\",
1430 \"b c #000000\",
1431 \"c c #ff0000\",
1432 /* pixels */
1433 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1434 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1435 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1436 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1437 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1438 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1439 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1440 \"aaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaa\",
1441 \"aaaaaaaaaaaaabbbccccccccbbbaaaaaaaaaaaaa\",
1442 \"aaaaaaaaaaabbccccccccccccccbbaaaaaaaaaaa\",
1443 \"aaaaaaaaaabccccccccccccccccccbaaaaaaaaaa\",
1444 \"aaaaaaaaabccccccccccccccccccccbaaaaaaaaa\",
1445 \"aaaaaaaabcccccccbbbbbbbbcccccccbaaaaaaaa\",
1446 \"aaaaaaaabccccbbbaaaaaaaabbbccccbaaaaaaaa\",
1447 \"aaaaaaabccccbaaaaaaaaaaaaaabccccbaaaaaaa\",
1448 \"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
1449 \"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
1450 \"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
1451 \"aaaaaaabbbbbaaaaaaaaaaaaaaabccccbaaaaaaa\",
1452 \"aaaaaaaaaaaaaaaaaaaaaaaabbbccccbaaaaaaaa\",
1453 \"aaaaaaaaaaaaaaaabbbbbbbbcccccccbaaaaaaaa\",
1454 \"aaaaaaaaaaaaaaaabcccccccccccccbaaaaaaaaa\",
1455 \"aaaaaaaaaaaaaaaabccccccccccccbaaaaaaaaaa\",
1456 \"aaaaaaaaaaaaaaaabccccccccccbbaaaaaaaaaaa\",
1457 \"aaaaaaaaaaaaaaaabccccbbbbbbaaaaaaaaaaaaa\",
1458 \"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
1459 \"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
1460 \"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
1461 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1462 \"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
1463 \"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
1464 \"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
1465 \"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
1466 \"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
1467 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1468 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1469 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1470 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1471 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1472 \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
1473   "XPM format image used for the \"help\" button"))
1474
1475 (defvar gnuplot-toolbar
1476   '([gnuplot-line-xpm
1477      gnuplot-line-fn     t     "Plot the line under point"]
1478     [gnuplot-region-xpm
1479      gnuplot-region-fn   t     "Plot the selected region"]
1480     [gnuplot-buffer-xpm
1481      gnuplot-buffer-fn   t     "Plot the entire buffer"]
1482     [:style 3d :size 8]
1483     [gnuplot-help-xpm
1484      gnuplot-help-fn     t     "Look at the gnuplot process buffer"]
1485     [gnuplot-doc-xpm
1486      gnuplot-doc-fn      t     "Look at the gnuplot document"])
1487   "The gnuplot toolbar.")
1488
1489 (fset 'gnuplot-line-fn   'gnuplot-send-line-and-forward)
1490 (fset 'gnuplot-region-fn 'gnuplot-send-region-to-gnuplot)
1491 (fset 'gnuplot-buffer-fn 'gnuplot-send-buffer-to-gnuplot)
1492 (fset 'gnuplot-help-fn   'gnuplot-show-gnuplot-buffer)
1493 (fset 'gnuplot-doc-fn    'gnuplot-info-lookup-symbol)
1494
1495 (defvar gnuplot-all-buttons-defined
1496   (and (listp gnuplot-line-xpm)   (listp gnuplot-region-xpm)
1497        (listp gnuplot-buffer-xpm) (listp gnuplot-doc-xpm)
1498        (listp gnuplot-help-xpm)))
1499
1500
1501 (defun gnuplot-make-toolbar-function ()
1502   (if (and gnuplot-xemacs-p gnuplot-all-buttons-defined)
1503       (progn
1504         ;;(remove-specifier gnuplot-toolbar-use-toolbar (current-buffer))
1505         (gnuplot-toolbar-setup-toolbar gnuplot-toolbar)
1506         (add-spec-to-specifier (symbol-value gnuplot-toolbar-use-toolbar)
1507                                gnuplot-toolbar
1508                                (current-buffer) ))))
1509
1510 ;;(defalias 'gnuplot-make-toolbar 'gnuplot-make-toolbar-function)
1511
1512
1513 \f
1514 ;;; --- syntax colorization, syntax table
1515
1516 (defvar gnuplot-mode-syntax-table
1517   (let ((table (make-syntax-table)))
1518     (modify-syntax-entry ?* "." table)
1519     (modify-syntax-entry ?+ "." table)
1520     (modify-syntax-entry ?- "." table)
1521     (modify-syntax-entry ?/ "." table)
1522     (modify-syntax-entry ?% "." table)
1523     (modify-syntax-entry ?= "." table)
1524     (modify-syntax-entry ?: "." table)
1525     (modify-syntax-entry ?& "." table ) ; rarely used
1526     (modify-syntax-entry ?^ "." table ) ; operators
1527     (modify-syntax-entry ?| "." table ) ; in gnuplot,
1528     (modify-syntax-entry ?& "." table ) ; (by me,
1529     (modify-syntax-entry ?? "." table ) ;  anyway...)
1530     (modify-syntax-entry ?~ "." table ) ;
1531
1532     (modify-syntax-entry ?_ "w" table )
1533
1534     ;; In GNU Emacs we scan for strings and comments ourselves in
1535     ;; `gnuplot-scan-after-change'.  I can't get this to work in xemacs,
1536     ;; so there we'll make ", ', and # delimiters as normal, and use the
1537     ;; built-in parser
1538     (if (featurep 'xemacs)
1539         (progn
1540           (modify-syntax-entry ?\' "\"" table)
1541           (modify-syntax-entry ?# "<" table)
1542           (modify-syntax-entry ?\n ">" table)
1543           (modify-syntax-entry ?\\ "\\" table))
1544
1545       ;; GNU Emacs: Make ", ', and # punctuation, so the built-in parser
1546       ;; doesn't interfere with them
1547       (modify-syntax-entry ?\" "." table)
1548       (modify-syntax-entry ?\' "." table)
1549       (modify-syntax-entry ?` "." table)
1550       (modify-syntax-entry ?\\ "." table))
1551
1552     table)
1553
1554   "Syntax table in use in `gnuplot-mode' buffers.
1555 This is the same as the standard syntax table except that ` and _
1556 are word characters, and math operators are punctuation
1557 characters.")
1558
1559 ;; Macro to generate efficient regexps for keyword matching
1560 ;;
1561 ;; These regular expressions treat the gnuplot vocabulary as complete
1562 ;; words.  Although gnuplot will recognise unique abbreviations, these
1563 ;; regular expressions will not.
1564 (defmacro gnuplot-make-regexp (list)
1565   `(regexp-opt ,list 'words))
1566
1567 ;; Lists of gnuplot keywords for syntax coloring etc.
1568 (defvar gnuplot-keywords-builtin-functions
1569   '("abs" "acosh" "acos" "arg" "asinh" "asin" "atan" "atanh" "atan2" "besj1" "besj0" "besy1" "besy0" "ceil" "column" "cosh" "cos" "erfc" "erf" "exp" "floor" "gamma" "ibeta" "igamma" "imag" "int" "inverf" "invnorm" "lgamma" "log" "log10" "norm" "rand" "real" "sgn" "sinh" "sin" "sqrt" "tanh" "tan" "tm_hour" "tm_mday" "tm_min" "tm_mon" "tm_sec" "tm_wday" "tm_yday" "tm_year" "valid")
1570   "List of GNUPLOT built-in functions, as strings.
1571
1572 These are highlighted using `font-lock-function-name-face'.")
1573
1574 (defvar gnuplot-keywords-plotting
1575   '("axes" "every" "index" "lw" "lt" "ls" "linestyle" "linetype" "linewidth" "notitle" "pt" "ps" "pointsize" "pointtype" "smooth" "thru" "title" "using" "with")
1576   "List of GNUPLOT keywords associated with plotting, as strings.
1577
1578 These are highlighted using `font-lock-type-face'.
1579 This list does not include plotting styles -- for that, see 
1580 `gnuplot-keywords-plotting-styles'")
1581
1582 (defvar gnuplot-keywords-plotting-styles
1583   '("boxerrorbars" "boxes" "boxxyerrorbars" "candlesticks" "dots" "errorbars" "financebars" "fsteps" "histeps" "impulses" "lines" "linespoints" "points" "steps" "vector" "xerrorbars" "xyerrorbars" "yerrorbars")
1584   "List of GNUPLOT plotting styles, as strings.
1585
1586 These are highlighted using `font-lock-function-name-face'.")
1587
1588 (defvar gnuplot-keywords-misc
1589   '("bind" "cd" "clear" "exit" "fit" "help" "history" "load" "pause" "print" "pwd" "quit" "replot" "save" "set" "show" "unset")
1590   "List of GNUPLOT miscellaneous commands, as strings.
1591
1592 These are highlighted using `font-lock-reference-face'.")
1593
1594 (defvar gnuplot-keywords-negatable-options
1595   '("arrow" "autoscale" "border" "clabel" "clip" "contour" "dgrid3d" "grid" "hidden3d" "historysize" "key" "label" "linestyle" "logscale" "mouse" "multiplot" "mx2tics" "mxtics" "my2tics" "mytics" "mztics" "offsets" "polar" "surface" "timestamp" "title" "x2dtics" "x2mtics" "x2tics" "x2zeroaxis" "xdtics" "xmtics" "xtics" "xzeroaxis" "y2dtics" "y2mtics" "y2tics" "y2zeroaxis" "ydtics" "ymtics" "ytics" "yzeroaxis" "zdtics" "zmtics" "ztics" "zzeroaxis")
1596
1597   "List of gnuplot options which can be negated using `gnuplot-negate-option'")
1598
1599 (defvar gnuplot-negatable-options-regexp
1600   (gnuplot-make-regexp gnuplot-keywords-negatable-options))
1601
1602 ;; Set up colorization for gnuplot.
1603 ;; This handles font-lock for emacs and xemacs.
1604 ;; hilit19 is handled in `gnuplot-mode'.
1605 (defvar gnuplot-font-lock-keywords nil)
1606 (defvar gnuplot-font-lock-syntactic-keywords nil)
1607 (defvar gnuplot-font-lock-defaults nil)
1608
1609 (when (featurep 'font-lock)             ; <KL>
1610   (setq gnuplot-font-lock-keywords
1611         (list
1612          ;; stuff in brackets, sugg. by <LB>
1613          '("\\[\\([^]]+\\)\\]" 1 font-lock-reference-face)
1614
1615          ;; variable/function definitions
1616          '("\\(\\(\\sw\\|\\s_\\)+\\s-*\\((\\s-*\\(\\sw\\|\\s_\\)*\\s-*\\(,\\s-*\\sw*\\)*\\s-*)\\)?\\s-*=\\)[^=]"
1617            1 font-lock-variable-name-face)
1618
1619          ;; built-in function names
1620          (cons (gnuplot-make-regexp gnuplot-keywords-builtin-functions)
1621                font-lock-function-name-face)
1622
1623          ;; reserved words associated with plotting <AL>
1624          (cons (gnuplot-make-regexp gnuplot-keywords-plotting)
1625                font-lock-type-face)
1626          (cons (gnuplot-make-regexp gnuplot-keywords-plotting-styles)
1627                font-lock-function-name-face)
1628
1629          ;; (s)plot -- also thing (s)plotted
1630          '("\\<s?plot\\>" . font-lock-keyword-face)
1631          ;; '("\\<s?plot\\s-+\\([^'\" ]+\\)[) \n,\\\\]"
1632          ;;   1 font-lock-variable-name-face)
1633
1634          ;; other common commands
1635          (cons (gnuplot-make-regexp gnuplot-keywords-misc)
1636                font-lock-reference-face)
1637          (cons "!.*$" font-lock-reference-face))) ; what is this for? jjo
1638       
1639   (setq gnuplot-font-lock-defaults 
1640         '(gnuplot-font-lock-keywords
1641           nil                           ; Use syntactic fontification
1642           t                             ; Use case folding
1643           nil                           ; No extra syntax
1644           ;; calls `gnuplot-beginning-of-continuation'
1645           ;; to find a safe place to begin syntactic highlighting
1646           beginning-of-defun))
1647   
1648   ;; Set up font-lock for Xemacs
1649   ;; For GNU Emacs, this is done in `gnuplot-mode'
1650   (if gnuplot-xemacs-p
1651       (put 'gnuplot-mode 'font-lock-defaults
1652            gnuplot-font-lock-defaults)))
1653
1654 ;; Gnuplot's shell-like strings and comments don't quite agree with
1655 ;; Emacs' built-in sexp parser:
1656 ;;
1657 ;; - strings can continue over several lines, but only by using a
1658 ;;   backslash to escape the newline
1659 ;; 
1660 ;; - double quoted strings can contain escaped quotes \" and escaped
1661 ;;   backslashes \\, while single quotes can escape the quote by
1662 ;;   doubling '' and backslash is not special (except at eol)
1663 ;; 
1664 ;; - strings can end at newline without needing a closing delimiter
1665 ;; 
1666 ;; - comments continue over continuation lines
1667 ;; 
1668 ;; Trying to write a regexp to match these rules is horrible, so we
1669 ;; use this matching function instead (in GNU Emacs - I can't figure out
1670 ;; how to do this in XEmacs.)
1671 (defun gnuplot-scan-after-change (begin end &optional unused)
1672   "Scan a gnuplot script buffer for strings and comments.
1673
1674 This is called once on the whole buffer when gnuplot-mode is turned on,
1675 and installed as a hook in `after-change-functions'."
1676   (save-excursion
1677     (setq end (progn
1678                 (goto-char end)
1679                 (gnuplot-point-at-end-of-continuation))
1680           begin (progn
1681                   (goto-char begin)
1682                   (gnuplot-beginning-of-continuation)
1683                   (point)))
1684
1685     (remove-text-properties begin (min (1+ end) (point-max))
1686                             '(syntax-table nil))
1687
1688     (while (gnuplot-scan-next-string-or-comment end))))
1689
1690 (defun gnuplot-scan-next-string-or-comment (limit)
1691   "Put appropriate syntax-table text properties on the next comment or string.
1692
1693 Scans forward from point as far as LIMIT (which should be at the
1694 end of a line). Leaves point at the end of the comment or string,
1695 or at LIMIT if nothing was found. Returns t if a comment or
1696 string was found, otherwise nil."
1697   (let ((begin (search-forward-regexp "[#'\"]" limit 'go-to-limit)))
1698     (if (not begin)
1699         nil
1700       (let* ((begin (1- begin))
1701              (end nil)
1702              (opener (match-string 0))
1703              (limit (point-at-eol))
1704              (end-at-eob-p nil)
1705              (re
1706               (cond ((string= opener "#") nil)
1707                     ((string= opener "'") "''?")
1708                     ((string= opener "\"") "\\\\\"\\|\\\\\\\\\\|\"")))) 
1709         (while (not end)
1710           (if (and (not (eobp)) (bolp) (eolp))  ; Empty continuation line:
1711               (setq end (point))        ; end at newline
1712             (if re
1713                 (setq end (search-forward-regexp re limit 'go-to-limit))
1714               (end-of-line))        ; Comments end only at end-of-line
1715             
1716             (if end
1717                 (when (and re
1718                            (let ((m (match-string 0)))
1719                              (or (string= m "\\\"")
1720                                  (string= m "\\\\")
1721                                  (string= m "''"))))
1722                   (setq end nil))   ; Skip over escapes and look again
1723               
1724               ;; We got to EOL without finding an ending delimiter
1725               (if (eobp)
1726                   (setq end (point)
1727                         end-at-eob-p t) ; string/comment ends at EOB
1728                 ;; Otherwise see if the line is continued with a backslash
1729                 (if (save-excursion (backward-char) (looking-at "\\\\"))
1730                     (progn              ; yes, check out next line
1731                       (beginning-of-line 2)
1732                       (setq limit (point-at-eol)))
1733                   (setq end (1+ (point-at-eol)))))))) ; no, string ends at EOL
1734
1735         ;; Set the syntax properties
1736         (let ((begin-marker             (copy-marker begin))
1737               (begin-quote-marker       (copy-marker (1+ begin)))
1738               (end-quote-marker         (copy-marker (1- end)))
1739               (end-marker               (copy-marker end)))
1740           
1741           (let ((syntax (if (string= opener "#") 
1742                             '(syntax-table (14))  ; 'comment fence'
1743                           '(syntax-table (15))))) ; 'string fence'
1744             (add-text-properties begin-marker begin-quote-marker syntax)
1745             (unless end-at-eob-p
1746               (add-text-properties end-quote-marker end-marker syntax)))
1747         
1748           ;; Mark multiline constructs for font-lock
1749           (add-text-properties begin-marker end-marker '(font-lock-multiline t))))
1750
1751       ;; We found something
1752       t)))
1753
1754
1755 ;; Parsing utilities to tell if we are inside a string or comment
1756
1757 ;; XEmacs doesn't have syntax-ppss
1758 (if (featurep 'xemacs)
1759     (defun gnuplot-syntax-ppss (&optional pos)
1760       (save-excursion
1761         (unless pos (setq pos (point)))
1762         (let ((begin
1763                (save-excursion
1764                  (goto-char pos)
1765                  (gnuplot-point-at-beginning-of-continuation))))
1766           (parse-partial-sexp begin pos))))
1767   (defalias 'gnuplot-syntax-ppss 'syntax-ppss))
1768
1769 (defun gnuplot-in-string (&optional where)
1770   "Returns non-nil if the text at WHERE is within a string.
1771
1772 If WHERE is omitted, defaults to text at point.
1773 This is a simple wrapper for `syntax-ppss'."
1774   (save-excursion
1775     (let ((parse-state (gnuplot-syntax-ppss where)))
1776       (nth 3 parse-state))))
1777
1778 (defun gnuplot-in-comment (&optional where)
1779   "Returns non-nil if the text at WHERE is within a comment.
1780
1781 If WHERE is omitted, defaults to text at point.
1782 This is a simple wrapper for `syntax-ppss'."
1783   (save-excursion
1784     (let ((parse-state (gnuplot-syntax-ppss where)))
1785       (nth 4 parse-state))))
1786
1787 (defun gnuplot-in-string-or-comment (&optional where)
1788   "Returns non-nil if the text at WHERE is within a string or comment.
1789
1790 If WHERE is omitted, defaults to text at point.
1791 This is a simple wrapper for `syntax-ppss'."
1792
1793   (save-excursion
1794     (let ((parse-state (gnuplot-syntax-ppss where)))
1795       (or (nth 3 parse-state)
1796           (nth 4 parse-state)))))
1797
1798 ;; these two lines get rid of an annoying compile time error
1799 ;; message.  that function gets non-trivially defalias-ed in
1800 ;; gnuplot-toolbar.el
1801 ;; (defun gnuplot-make-toolbar-dummy ())
1802 ;; (defalias 'gnuplot-make-toolbar 'gnuplot-make-toolbar-dummy)
1803
1804 \f
1805 ;;; --- functions for sending commands to gnuplot
1806
1807 (defun gnuplot-split-string (string)
1808   "Break STRING at each carriage return, returning a list of lines."
1809   (let ((list ()) (line "") (index 0))
1810     (while (< index (length string))
1811       (if (char-equal (elt string index) ?\n)
1812           (setq list (append list (list line))
1813                 line "")
1814         (setq line (concat line (char-to-string (elt string index)))))
1815       (setq index (1+ index)) )
1816     list))
1817
1818 ;; -- the calls to `sleep-for' are to allow enough time for gnuplot
1819 ;;    to write to the buffer before the next line is inserted
1820 ;; -- note that the input string is split into lines and each line is
1821 ;;    sent to gnuplot individually.  this is a bit slow, but it puts
1822 ;;    each line on the comint history.
1823 (defun gnuplot-send-string-to-gnuplot (string text)
1824   "Sends STRING to the gnuplot program.
1825 If no gnuplot process exists, a new one is created.  TEXT indicates
1826 the type of text being sent to gnuplot and is typically one of
1827 nil, 'line, 'region, 'buffer, or 'file.  TEXT may be useful for
1828 functions in `gnuplot-after-plot-hook'.  `gnuplot-after-plot-hook' is
1829 called by this function after all of STRING is sent to gnuplot."
1830   (gnuplot-make-gnuplot-buffer) ; make sure a gnuplot buffer exists
1831   (gnuplot-fetch-version-number)
1832   (setq gnuplot-comint-recent-buffer (current-buffer))
1833
1834   ;; Create a gnuplot frame if needed
1835   (if (equal gnuplot-display-process 'frame)
1836       (or (and gnuplot-process-frame
1837                (frame-live-p gnuplot-process-frame))
1838           (let ((frame (selected-frame)))
1839             (setq gnuplot-process-frame (make-frame))
1840             (select-frame gnuplot-process-frame)
1841             (switch-to-buffer gnuplot-buffer)
1842             (delete-other-windows)
1843             (select-frame frame))))
1844
1845   (let ((list (gnuplot-split-string string)))
1846     (with-current-buffer (get-buffer gnuplot-buffer)
1847       (goto-char (point-max))
1848       ;; bruce asks: what is this next line for?
1849       (set-marker (process-mark gnuplot-process) (point-marker))
1850       (sleep-for (* 20 gnuplot-delay))
1851       (while list
1852         (insert (car list))
1853         (comint-send-input)
1854         (sleep-for gnuplot-delay)
1855         (setq list (cdr list))
1856         (goto-char (point-max))))
1857
1858     (cond ((equal gnuplot-display-process 'window)
1859            (gnuplot-display-and-recenter-gnuplot-buffer))
1860           ((equal gnuplot-display-process 'frame)
1861            ;;(raise-frame gnuplot-process-frame)
1862            (with-selected-frame gnuplot-process-frame
1863              (gnuplot-display-and-recenter-gnuplot-buffer))))
1864
1865     (setq gnuplot-recently-sent text)
1866     (run-hooks 'gnuplot-after-plot-hook)))
1867
1868 (defun gnuplot-display-and-recenter-gnuplot-buffer ()
1869   "Make sure the gnuplot comint buffer is displayed, and
1870 move point to the end if necessary"
1871   (save-selected-window
1872     (select-window (display-buffer (get-buffer gnuplot-buffer)))
1873     (goto-char (point-max))
1874     (unless (pos-visible-in-window-p (point) (selected-window)) (recenter 5))))
1875
1876 (defun gnuplot-send-region-to-gnuplot (&optional begin end text)
1877   "Sends a selected region to the gnuplot program.
1878 If BEGIN and END are not specified, point and mark are used.  TEXT
1879 indicates the type of text being sent to gnuplot.  This will be
1880 'region unless explicitly set by a function calling this one.  Other
1881 typical values are of nil, 'line, 'buffer, or 'file.  TEXT may be
1882 useful for function in `gnuplot-after-plot-hook'."
1883   (interactive "r")
1884   (let (string (txt (or text 'region)))
1885     (cond ((equal major-mode 'gnuplot-mode)
1886            (setq string (buffer-substring-no-properties begin end))
1887            (if (string= (substring string -1) "\n") ()
1888              (setq string (concat string "\n")))
1889            (gnuplot-send-string-to-gnuplot string txt))
1890           (t
1891            (message (concat "You can only send regions from "
1892                             "gnuplot-mode buffers to gnuplot."))))))
1893
1894 (defun gnuplot-send-line-to-gnuplot ()
1895   "Sends the current line to the gnuplot program.
1896 Respects continuation lines.
1897 This sets `gnuplot-recently-sent' to 'line."
1898   (interactive)
1899   (cond ((equal major-mode 'gnuplot-mode)
1900          (let (start end)
1901            (save-excursion 
1902              ;; go to start of continued command, or beginning of line
1903              ;; if this is not a continuation of a previous line <JJO>
1904              (gnuplot-beginning-of-continuation)
1905              (setq start (point))
1906              (end-of-line)
1907              (while (save-excursion
1908                       (backward-char)
1909                       (looking-at "\\\\"))      ; go to end of last continuation line
1910                (end-of-line 2))
1911              (beginning-of-line 2)
1912              (setq end (point)))
1913            (if (not (string-match "\\`\\s-*\\'"
1914                                   (buffer-substring-no-properties start end)))
1915                (gnuplot-send-region-to-gnuplot start end 'line))
1916            end))
1917         (t
1918          (message "You can only send lines in gnuplot-mode buffers to gnuplot.")
1919          nil)))
1920
1921 ;; I chose a very easy to type but slightly non-mnemonic key-binding
1922 ;; for this (C-c C-v).  It seems like the kind of thing one would want
1923 ;; to do repeatedly without incurring RSI. 8^)
1924 (defun gnuplot-send-line-and-forward (&optional num)
1925   "Call `gnuplot-send-line-to-gnuplot' and move forward 1 line.
1926 You can use a numeric prefix to send more than one line.  Blank lines and
1927 lines with only comments are skipped when moving forward."
1928   (interactive "p")
1929   (let (end)
1930     (while (> num 0)
1931       (setq end (gnuplot-send-line-to-gnuplot))
1932       (goto-char end)
1933       (backward-char 1)                 ; <AR>
1934       (gnuplot-forward-script-line 1)
1935       (setq num (1- num)))))
1936
1937
1938 (defun gnuplot-forward-script-line (&optional num) ; <SE>
1939   "Move forward my NUM script lines.
1940 Blank lines and commented lines are not included in the NUM count."
1941   (interactive "p")
1942   (while (> num 0)
1943     (and (not (eobp)) (forward-line 1))
1944     (while (and (not (eobp))
1945                 (or (looking-at "^\\s-*$")
1946                     (looking-at "^\\s-*#")))
1947       (forward-line 1))
1948     (setq num (1- num))))
1949
1950 (defun gnuplot-send-buffer-to-gnuplot ()
1951   "Sends the entire buffer to the gnuplot program.
1952 This sets `gnuplot-recently-sent' to 'buffer."
1953   (interactive)
1954   (if (equal major-mode 'gnuplot-mode)
1955       (gnuplot-send-region-to-gnuplot (point-min) (point-max) 'buffer)
1956     (message "You can only send gnuplot-mode buffers to gnuplot.")))
1957
1958 (defun gnuplot-send-file-to-gnuplot ()
1959   "Sends a selected file to the gnuplot program using the \"load\" command.
1960 This sets `gnuplot-recently-sent' to 'file."
1961   (interactive)
1962   (let ((string (read-file-name "Name of file to send to gnuplot > " nil nil t)))
1963     (setq string (concat "load '" (expand-file-name string) "'\n"))
1964     (message "%S" string)
1965     (gnuplot-make-gnuplot-buffer)       ; make sure a gnuplot buffer exists
1966     (gnuplot-send-string-to-gnuplot string 'file)))
1967
1968 ;; suggested by <JS>
1969 (defun gnuplot-plot-from-comint ()
1970   "Send the contents of a script to gnuplot from the process buffer.
1971 This inserts the contents of the most recently used gnuplot script
1972 into the process buffer and sends those lines to gnuplot.  It does
1973 this by copying the script line by line."
1974   (interactive)
1975   (if (not (buffer-live-p gnuplot-comint-recent-buffer))
1976       (message "Script buffer has been deleted.")
1977     (let (string list (buffer (current-buffer)))
1978       (set-buffer gnuplot-comint-recent-buffer)
1979       (setq string (buffer-substring-no-properties (point-min) (point-max))
1980             string (concat string "\n")
1981             list   (gnuplot-split-string string))
1982       (set-buffer buffer)
1983       (while list
1984         (insert (car list))
1985         (comint-send-input)
1986         (sleep-for gnuplot-delay)
1987         (setq list (cdr list)))
1988       (comint-send-input))))
1989
1990 (defun gnuplot-save-and-plot-from-comint ()
1991   "Send a current script to gnuplot from the process buffer.
1992 This sends the most recently used gnuplot script to gnuplot using the
1993 \"load\" command.  This function first saves the script buffer to a
1994 file, prompting for a filename if one is not associated with the script
1995 buffer.  Then it sends a load command to gnuplot using the name of the
1996 file visited by the script buffer."
1997   (interactive)
1998   (if (not (buffer-live-p gnuplot-comint-recent-buffer))
1999       (message "Script buffer has been deleted.")
2000     (let (fname)
2001       (with-current-buffer gnuplot-comint-recent-buffer
2002         (save-buffer)
2003         (setq fname (buffer-file-name)))
2004       (goto-char (point-max))
2005       (insert (format "load '%s'" fname))
2006       (comint-send-input))))
2007
2008 (defun gnuplot-pop-to-recent-buffer ()
2009   "Switch to the most recently-plotted gnuplot script buffer."
2010   (interactive)
2011   (when (buffer-live-p gnuplot-comint-recent-buffer)
2012     (pop-to-buffer gnuplot-comint-recent-buffer)))
2013
2014 (defun gnuplot-trim-gnuplot-buffer ()
2015   "Trim lines from the beginning of the *gnuplot* buffer.
2016 This keeps that buffer from growing excessively in size.  Normally,
2017 this function is attached to `gnuplot-after-plot-hook'"
2018   (if (> gnuplot-buffer-max-size 0)
2019       (save-excursion
2020         (set-buffer gnuplot-buffer)
2021         (let ((nlines (count-lines (point-min) (point-max)))
2022               (kill-whole-line t))
2023           (while (> nlines gnuplot-buffer-max-size)
2024             (goto-char (point-min))
2025             (kill-line)
2026             (setq nlines (1- nlines)))
2027           (goto-char (point-max)) ))))
2028 (add-hook 'gnuplot-after-plot-hook 'gnuplot-trim-gnuplot-buffer nil nil)
2029
2030 \f
2031 ;;; --- functions controlling the gnuplot process
2032
2033 ;; Define gnuplot-comint-mode, the mode for the gnuplot process
2034 ;; buffer, by deriving from comint-mode    
2035 (define-derived-mode gnuplot-comint-mode comint-mode "Gnuplot interaction"
2036   "Major mode for interacting with a gnuplot process in a buffer.
2037
2038 This sets font-lock and keyword completion in the comint/gnuplot
2039 buffer."
2040
2041   (if gnuplot-xemacs-p                  ; deal with font-lock
2042       (if (fboundp 'turn-on-font-lock) (turn-on-font-lock))
2043     (progn
2044       (setq font-lock-defaults gnuplot-font-lock-defaults)
2045       (set (make-local-variable 'parse-sexp-lookup-properties) t)
2046       (add-hook 'after-change-functions 'gnuplot-scan-after-change nil t)))
2047
2048   ;; XEmacs needs the call to make-local-hook
2049   (when (and (featurep 'xemacs)
2050              (fboundp 'make-local-hook))
2051     (make-local-hook 'kill-buffer-hook))
2052   (add-hook 'kill-buffer-hook 'gnuplot-close-down nil t)
2053
2054   (add-hook 'comint-output-filter-functions
2055             'comint-postoutput-scroll-to-bottom
2056             nil t)
2057   (add-hook 'comint-output-filter-functions
2058             'gnuplot-protect-prompt-fn
2059             nil t)
2060
2061   (add-hook 'comint-dynamic-complete-functions 'gnuplot-comint-complete)
2062
2063   ;; Set up menu (see below)
2064   (easy-menu-define
2065    gnuplot-comint-mode-menu gnuplot-comint-mode-map "Menu used in gnuplot-comint-mode"
2066    gnuplot-comint-menu)
2067   (easy-menu-add gnuplot-comint-mode-menu gnuplot-comint-mode-map))
2068
2069 ;; Key bindings for gnuplot-comint-mode
2070 (define-key gnuplot-comint-mode-map "\M-\C-p"   'gnuplot-plot-from-comint)
2071 (define-key gnuplot-comint-mode-map "\M-\C-f"   'gnuplot-save-and-plot-from-comint)
2072 (define-key gnuplot-comint-mode-map "\C-d"      'gnuplot-delchar-or-maybe-eof)
2073 (define-key gnuplot-comint-mode-map "\M-\r"     'comint-dynamic-complete)
2074 (define-key gnuplot-comint-mode-map "\M-\t"     'comint-dynamic-complete)
2075 (define-key gnuplot-comint-mode-map "\C-c\C-d"  'gnuplot-show-version)
2076 (define-key gnuplot-comint-mode-map "\C-c\C-h"  'gnuplot-info-lookup-symbol)
2077 (define-key gnuplot-comint-mode-map "\C-c\C-i"  'gnuplot-insert-filename)
2078 (define-key gnuplot-comint-mode-map "\C-c\C-n"  'gnuplot-negate-option)
2079 (define-key gnuplot-comint-mode-map "\C-c\C-p"  'gnuplot-show-gnuplot-version)
2080 (define-key gnuplot-comint-mode-map "\C-c\C-u"  'gnuplot-bug-report)
2081 (define-key gnuplot-comint-mode-map "\C-c\C-z"  'gnuplot-customize)
2082 (define-key gnuplot-comint-mode-map "\C-c\C-e"  'gnuplot-pop-to-recent-buffer)
2083
2084 ;; Menu for gnuplot-comint-mode
2085 (defvar gnuplot-comint-mode-menu nil
2086   "Menu for `gnuplot-comint-mode'.")
2087 (defvar gnuplot-comint-menu nil)
2088 (setq gnuplot-comint-menu
2089       '("Gnuplot"
2090         ["Plot most recent gnuplot buffer"              gnuplot-plot-from-comint
2091          (buffer-live-p gnuplot-comint-recent-buffer)]
2092         ["Save and plot most recent gnuplot buffer"     gnuplot-save-and-plot-from-comint
2093          (buffer-live-p gnuplot-comint-recent-buffer)]
2094         "---"
2095         ["Insert filename at point"                     gnuplot-insert-filename t]
2096         ["Negate set option"                            gnuplot-negate-option t]
2097         ["Keyword help"                                 gnuplot-info-lookup-symbol
2098          (or gnuplot-keywords gnuplot-keywords-pending)]
2099         ["Switch to recent gnuplot script buffer"       gnuplot-pop-to-recent-buffer
2100          (buffer-live-p gnuplot-comint-recent-buffer)]
2101         "---"
2102         ["Customize gnuplot"                            gnuplot-customize t]
2103         ["Submit bug report"                            gnuplot-bug-report t]
2104         ["Show gnuplot-mode version"                    gnuplot-show-version t]
2105         ["Show gnuplot version"                         gnuplot-show-gnuplot-version t]
2106         "---"
2107         ["Kill gnuplot"                                 gnuplot-kill-gnuplot-buffer t]
2108         ))
2109
2110 ;; Switch to the gnuplot program buffer
2111 (defun gnuplot-make-gnuplot-buffer ()
2112   "Switch to the gnuplot program buffer or create one if none exists."
2113   (or (and gnuplot-process (get-process gnuplot-process)
2114            gnuplot-buffer (buffer-name gnuplot-buffer))
2115       (progn
2116         (message "Starting gnuplot plotting program...")
2117         (setq gnuplot-buffer (make-comint gnuplot-process-name gnuplot-program)
2118               gnuplot-process (get-process gnuplot-process-name))
2119         (process-kill-without-query gnuplot-process nil)
2120         (with-current-buffer gnuplot-buffer
2121           (gnuplot-comint-mode)
2122           (message "Starting gnuplot plotting program...Done")))))
2123
2124 (defun gnuplot-fetch-version-number ()
2125   "Determine the installed version of the gnuplot program.
2126
2127 If `gnuplot-program-version' is already set, does
2128 nothing. Otherwise, runs `gnuplot-program' and searches the text
2129 printed at startup for a string like \"Version N.N\".
2130
2131 Sets the variables `gnuplot-program-version',
2132 `gnuplot-program-major-version', `gnuplot-program-minor-version',
2133 and `gnuplot-three-eight-p'.
2134
2135 If the version number cannot be determined by this method, it
2136 defaults to 3.7."
2137   (unless gnuplot-program-version
2138     (message "gnuplot-mode %s -- determining gnuplot version ......"
2139              gnuplot-version)
2140     (with-temp-buffer
2141       (insert "show version")
2142       (call-process-region (point-min) (point-max)
2143                            gnuplot-program t (current-buffer))
2144       (goto-char (point-min))
2145       (if (and (re-search-forward "[Vv]ersion\\s-+" (point-max) t)
2146                (looking-at "\\([0-9]\\)\\.\\([0-9]+\\)"))
2147           (progn
2148             (setq gnuplot-program-version (match-string 0)
2149                   gnuplot-program-major-version (string-to-number
2150                                                  (match-string 1))
2151                   gnuplot-program-minor-version (string-to-number
2152                                                  (match-string 2))
2153                   gnuplot-three-eight-p
2154                   (>= (string-to-number gnuplot-program-version) 3.8)))
2155
2156         ;; Guess v3.7 if something went wrong
2157         (message "Warning: could not determine gnuplot version, guessing 3.7")
2158         (setq gnuplot-program-version "3.7"
2159               gnuplot-program-major-version 3
2160               gnuplot-program-minor-version 7
2161               gnuplot-three-eight-p nil)))
2162     
2163     ;; Setup stuff that depends on version number
2164     (gnuplot-setup-menu-and-toolbar)))
2165
2166 (defun gnuplot-setup-menu-and-toolbar ()
2167   ;; set up the menubar (possibly dependent on version number)
2168   (gnuplot-setup-menubar)
2169   ;; set up the toolbar (possibly dependent on version number)
2170   (if (and gnuplot-xemacs-p gnuplot-toolbar-display-flag)
2171       (condition-case ()                ; deal with the toolbar
2172           (and (require 'toolbar)
2173                (require 'xpm)
2174                (gnuplot-make-toolbar-function))
2175         (error nil)))
2176   (message "gnuplot-mode %s (gnuplot %s) -- report bugs with %S"
2177            gnuplot-version gnuplot-program-version
2178            (substitute-command-keys "\\[gnuplot-bug-report]")))
2179
2180 (defun gnuplot-protect-prompt-fn (string)
2181   "Prevent the Gnuplot prompt from being deleted or overwritten.
2182 STRING is the text as originally inserted in the comint buffer."
2183   (save-excursion
2184     (let ((b (progn
2185                (goto-char (point-max))
2186                (beginning-of-line)
2187                (point)))
2188           e)
2189       (if (re-search-forward "^gnuplot> " (point-max) t)
2190           (progn
2191             (setq e (point))
2192             (put-text-property b e 'rear-nonsticky '(read-only intangible face))
2193             (put-text-property b e 'intangible t)
2194             (put-text-property b e 'face 'gnuplot-prompt-face)
2195             ;;(put-text-property b e 'read-only t)
2196             )) )))
2197
2198 (defun gnuplot-close-down ()
2199   "Tidy up when deleting the gnuplot buffer."
2200   (if (and gnuplot-process
2201            (eq (process-status gnuplot-process) 'run)) ; <SE>
2202       (kill-process gnuplot-process))
2203   (setq gnuplot-process nil
2204         gnuplot-buffer nil))
2205
2206 (defun gnuplot-delchar-or-maybe-eof (arg)
2207   "Delete ARG characters forward, or (if at eob) send an EOF to subprocess.
2208 This is very similar to `comint-delchar-or-maybe-eof'."
2209   (interactive "p")
2210   (if (eobp)
2211       (gnuplot-kill-gnuplot-buffer)
2212     (delete-char arg)))
2213
2214 (defun gnuplot-kill-gnuplot-buffer ()
2215   "Kill the gnuplot process and its display buffers."
2216   (interactive)
2217   (if (and gnuplot-process
2218            (eq (process-status gnuplot-process) 'run))  ;; <SE>
2219       (kill-process gnuplot-process))
2220   (if (and gnuplot-buffer (get-buffer gnuplot-buffer))
2221       (progn
2222         (if (one-window-p) ()
2223           (delete-window (get-buffer-window gnuplot-buffer)))
2224         (kill-buffer gnuplot-buffer)))
2225   (setq gnuplot-process nil
2226         gnuplot-buffer nil))
2227
2228
2229 (defun gnuplot-show-gnuplot-buffer ()
2230   "Switch to the buffer containing the gnuplot process.
2231 When `gnuplot-display-process' is nil this will switch to
2232 the gnuplot process buffer.  When that variable is non-nil, the
2233 gnuplot process buffer will be displayed in a window."
2234   (interactive)
2235   (unless (and gnuplot-buffer (get-buffer gnuplot-buffer))
2236     (gnuplot-make-gnuplot-buffer))
2237   (cond ((equal gnuplot-display-process 'window)
2238          (switch-to-buffer-other-window gnuplot-buffer))
2239         ((equal gnuplot-display-process 'frame)
2240          (or (and gnuplot-process-frame
2241                   (frame-live-p gnuplot-process-frame))
2242              (setq gnuplot-process-frame (make-frame)))
2243          (raise-frame gnuplot-process-frame)
2244          (select-frame gnuplot-process-frame)
2245          (switch-to-buffer gnuplot-buffer))
2246         (t
2247          (switch-to-buffer gnuplot-buffer))))
2248
2249 \f
2250 ;;; --- miscellaneous functions: insert file name, indentation, negation
2251
2252 (defun gnuplot-insert-filename ()
2253   "Insert a filename at point, prompting for name in the minibuffer.
2254 This inserts a filename relative to the buffer's default directory.
2255 Uses completion and the value of `gnuplot-quote-character'.
2256 Bound to \\[gnuplot-insert-filename]"
2257   (interactive)
2258   (insert gnuplot-quote-character
2259           (file-relative-name (read-file-name "Filename > " "")
2260                               default-directory)
2261           gnuplot-quote-character) )
2262
2263
2264 ;; Adjust indentation for the line containing point
2265 (defun gnuplot-indent-line ()
2266   "Set indentation in gnuplot buffer.
2267 For most lines, set indentation to previous level of indentation.
2268 Add additional indentation for continuation lines."
2269   (interactive)
2270   (let (indent)
2271     (if (gnuplot-in-string (point-at-bol))
2272         ;; Continued strings begin at left margin
2273         (setq indent 0)
2274       (save-excursion 
2275         (if (gnuplot-continuation-line-p)
2276             ;; This is a continuation line. Indent to the same level as
2277             ;; the second word on the line beginning this command (i.e.,
2278             ;; the first non-whitespace character after whitespace)
2279             (progn
2280               (gnuplot-beginning-of-continuation)
2281               (back-to-indentation) 
2282               (re-search-forward "\\S-+\\s-+" (point-at-eol) 'end-at-limit)
2283               (setq indent (- (point) (point-at-bol))))
2284
2285           ;; Not a continuation line; go back to the first non-blank,
2286           ;; non-continuation line and indent to the same level
2287           (beginning-of-line 0)
2288           (while (and (not (bobp))
2289                       (or (gnuplot-continuation-line-p)
2290                           (looking-at "\\s-*$")))
2291             (beginning-of-line 0))
2292           (if (bobp)
2293               (setq indent 0)
2294             (setq indent (current-indentation))))))
2295     
2296     ;; Set indentation
2297     (save-excursion 
2298       (indent-line-to indent))
2299
2300     (let ((point-at-indent (+ (point-at-bol) indent)))
2301       (when (< (point) point-at-indent) (goto-char point-at-indent)))))
2302
2303 ;;
2304 ;; Functions for finding the start and end of continuation blocks
2305 ;;
2306
2307 ;; Check if line containing point is a continuation
2308 (defun gnuplot-continuation-line-p ()
2309   "Return t if the line containing point is a continuation of the previous line."
2310   (save-excursion
2311     (condition-case ()
2312         (progn
2313           (end-of-line 0)
2314           (backward-char)
2315           (looking-at "\\\\"))
2316       (error nil))))
2317
2318 ;; Move point to start of continuation block
2319 (defun gnuplot-beginning-of-continuation ()
2320   "Move point to the beginning of the continuation lines containing point.
2321
2322 If not in a continuation line, move point to beginning of line."
2323   (beginning-of-line)
2324   (while (gnuplot-continuation-line-p)
2325     (beginning-of-line 0)))
2326
2327 ;; Move point to end of continuation block
2328 (defun gnuplot-end-of-continuation ()
2329   "Move point to the end of the continuation lines containing point.
2330
2331 If there are no continuation lines, move point to end-of-line."
2332   (end-of-line)
2333   (unless (bobp)
2334     (catch 'eob
2335       (while (save-excursion (backward-char)
2336                              (looking-at "\\\\"))
2337         (end-of-line 2)
2338         (if (eobp) (throw 'eob nil))))))
2339
2340 ;; Save-excursion wrappers for the above to return point at beginning
2341 ;; or end of continuation
2342 (defun gnuplot-point-at-beginning-of-continuation ()
2343   "Return value of point at beginning of the continued block containing point.
2344
2345 If there are no continuation lines, returns point-at-bol."
2346   (save-excursion
2347     (gnuplot-beginning-of-continuation)
2348     (point)))
2349
2350 (defun gnuplot-point-at-end-of-continuation ()
2351   "Return value of point at the end of the continued block containing point.
2352
2353 If there are no continuation lines, returns point-at-eol."
2354   (save-excursion
2355     (gnuplot-end-of-continuation)
2356     (point)))
2357
2358 ;; We also treat a block of continuation lines as a 'defun' for
2359 ;; movement purposes
2360 (defun gnuplot-beginning-of-defun (&optional arg)
2361   (if (not arg) (setq arg 1))
2362   (if (> arg 0)                         
2363       (catch 'bob               ; go to beginning of ARGth prev. defun
2364         (dotimes (n arg)
2365           (when (= (point)
2366                    (gnuplot-point-at-beginning-of-continuation))
2367             (forward-line -1)
2368             (if (bobp) (throw 'bob t))
2369             (while (looking-at "^\\s-*$")
2370               (forward-line -1)
2371               (if (bobp) (throw 'bob t))))
2372           (gnuplot-beginning-of-continuation))
2373         t)
2374
2375     (catch 'eob           ; find beginning of (-ARG)th following defun
2376       (dotimes (n (- arg))
2377         (gnuplot-end-of-continuation)
2378         (forward-line)
2379         (if (eobp) (throw 'eob t))
2380         (while (looking-at "^\\s-*$")
2381           (forward-line)
2382           (if (eobp) (throw 'eob t)))))))
2383
2384 ;; Movement to start or end of command, including multiple commands
2385 ;; separated by semicolons
2386 (defun gnuplot-beginning-of-command ()
2387   "Move point to beginning of command containing point."
2388   (let ((limit (gnuplot-point-at-beginning-of-continuation)))
2389     (while
2390         (and
2391          (search-backward ";" limit 'lim)
2392          (gnuplot-in-string-or-comment)))
2393     (skip-chars-forward ";")
2394     (skip-syntax-forward "-")))
2395
2396 (defun gnuplot-end-of-command ()
2397   "Move point to end of command containing point."
2398   (let ((limit (gnuplot-point-at-end-of-continuation)))
2399     (while
2400         (and
2401          (search-forward ";" limit 'lim)
2402          (gnuplot-in-string-or-comment)))
2403     (skip-chars-backward ";")
2404     (skip-syntax-backward "-")))
2405
2406 (defun gnuplot-point-at-beginning-of-command ()
2407   "Return position at the beginning of command containing point."
2408   (save-excursion (gnuplot-beginning-of-command) (point)))
2409
2410 (defun gnuplot-point-at-end-of-command ()
2411   "Return position at the end of command containing point."
2412   (save-excursion (gnuplot-end-of-command) (point)))
2413
2414 (defun gnuplot-negate-option ()
2415   "Append \"no\" to or remove \"no\" from the set option on the current line.
2416 This checks if the set option is one which has a negated form.
2417
2418 Negatable options are defined in `gnuplot-keywords-negatable-options'."
2419   (interactive)
2420   (gnuplot-fetch-version-number)
2421   (let ((begin (gnuplot-point-at-beginning-of-command))
2422         (end   (gnuplot-point-at-end-of-command))
2423         (regex gnuplot-negatable-options-regexp))
2424     (save-excursion
2425       (goto-char begin)
2426       (skip-syntax-forward "-" end)
2427       (if (looking-at "\\(un\\)?set\\s-+")
2428           (cond ((> (string-to-number gnuplot-program-version) 3.7)
2429                  (cond ((looking-at "unset")
2430                         (delete-char 2))
2431                        ((looking-at (concat "set\\s-+\\(" regex "\\)"))
2432                         (insert "un"))
2433                        (t
2434                         (message "There is not a negatable set option on this line"))))
2435                 (t
2436                  (goto-char (match-end 0))
2437                  (if (> (point) end) (goto-char end))
2438                  (cond ((looking-at "no")
2439                         (delete-char 2))
2440                        ((looking-at regex)
2441                         (insert "no"))
2442                        (t
2443                         (message "There is not a negatable set option on this line")))))
2444         (message "There is not a set option on this line")) )))
2445
2446 ;; (defun gnuplot-set-binding ()
2447 ;;   "Interactively select a key sequence for binding to a plot function.
2448 ;; This is only useful in gnuplot 3.8 and for plot terminals which support
2449 ;; key bindings (i.e. those covered by pm3d)."
2450 ;;   (interactive)
2451 ;;   (let ((keyseq (read-key-sequence "Choose a key sequence now"))
2452 ;;      (command (read-string "Bind to this command > ")))
2453 ;;     (setq keyseq (format "%S" keyseq))
2454 ;;     (string-match "keypress-event\\s-+" keyseq)
2455 ;;     (setq keyseq (substring keyseq (match-end 0) -2))
2456 ;;     ;; need to convert from emacs nomenclature to gnuplot.  what a pain.
2457 ;;     (let* ((alist '(("backspace" . "Backspace") ("tab" . "Tab") ("linefeed" . "Linefeed")
2458 ;;                  ("clear" . "Clear") ("return" . "Return") ("pause" . "Pause")
2459 ;;                  ("scroll-lock" . "Scroll_Lock") ("SysReq" . "sys-req")
2460 ;;                  ("escape" . "Escape") ("delete" . "Delete") ("home" . "Home")
2461 ;;                  ("left" . "Left") ("right" . "Right") ("up" . "Up") ("down" . "Down")
2462 ;;                  ("prior" . "PageUp") ("next" . "PageDown") ("end" . "End")
2463 ;;                  ("begin". "Begin")))
2464 ;;         (match (assoc keyseq alist)))
2465 ;;       (if match (setq keyseq (cdr match)))
2466 ;;
2467 ;;     (insert (format "bind \"%s\" \"%s\"" keyseq command)))))
2468
2469
2470 (defun gnuplot-customize ()
2471   "Customize `gnuplot-mode'."
2472   (interactive)
2473   (if (fboundp 'customize-group)
2474       (customize-group "gnuplot")
2475     (message "The Custom library is not installed.")))
2476
2477
2478 \f
2479 ;;; --- help from the info file, keyword list + completion, insert function
2480
2481
2482 ;; set up stuff for info-look (as suggested by <SE>)
2483 ;; modified with suggestion from <MS>
2484 (defun gnuplot-setup-info-look ()
2485   "Setup info-look in the gnuplot buffer.
2486
2487 Also set the variable `gnuplot-keywords' and do something sensible if
2488 info-look was not available.
2489 See the comments in `gnuplot-info-hook'."
2490   (interactive)
2491   (setq gnuplot-keywords-pending nil)
2492   (if (featurep 'info-look)
2493       (progn 
2494         (gnuplot-fetch-version-number)
2495
2496         ;; In the absence of evidence to the contrary, I'm guessing
2497         ;; the info file layout changed with gnuplot version 4 <jjo>
2498          (let ((doc-spec
2499                (if (>= (string-to-number gnuplot-program-version) 4.0)
2500                    ;; New info-file layout - works with gnuplot 4.4
2501                    '(("(gnuplot)Command_Index"   nil "[_a-zA-Z0-9]+")
2502                      ("(gnuplot)Options_Index"   nil "[_a-zA-Z0-9]+")
2503                      ("(gnuplot)Function_Index"  nil "[_a-zA-Z0-9]+")
2504                      ("(gnuplot)Terminal_Index"  nil "[_a-zA-Z0-9]+"))
2505
2506                  ;; Old info-file layout
2507                  '(("(gnuplot)Top"           nil "[_a-zA-Z0-9]+")
2508                    ("(gnuplot)Commands"      nil "[_a-zA-Z0-9]+")
2509                    ("(gnuplot)Functions"     nil "[_a-zA-Z0-9]+")
2510                    ("(gnuplot)plot"          nil "[_a-zA-Z0-9]+")
2511                    ("(gnuplot)set-show"      nil "[_a-zA-Z0-9]+")
2512                    ("(gnuplot)data-file"     nil "[_a-zA-Z0-9]+")
2513                    ("(gnuplot)smooth"        nil "[_a-zA-Z0-9]+")
2514                    ("(gnuplot)style"         nil "[_a-zA-Z0-9]+")
2515                    ("(gnuplot)terminal"      nil "[_a-zA-Z0-9]+")))))
2516           (cond ((boundp 'info-lookup-symbol-alist) ; older info-lookup version
2517                  (setq info-lookup-symbol-alist
2518                        (append
2519                         info-lookup-symbol-alist
2520                         `((gnuplot-mode
2521                            "[a-zA-Z][_a-zA-Z0-9]*" nil
2522                            ,doc-spec "[_a-zA-Z0-9]+" )))))
2523                 (t                      ; newer version
2524                  (info-lookup-add-help
2525                   :mode 'gnuplot-mode :topic 'symbol
2526                   :regexp "[a-zA-Z][_a-zA-Z0-9]*"
2527                   :doc-spec doc-spec)
2528                  ;; allow help lookup from the comint buffer as well <jjo>
2529                  (info-lookup-add-help
2530                   :mode 'gnuplot-comint-mode :topic 'symbol
2531                   :regexp "[a-zA-Z][_a-zA-Z0-9]*"
2532                   :doc-spec doc-spec)
2533                 (message "hi dere"))))
2534
2535         ;; this hook is my best way of working with info-look and
2536         ;; allowing multiple versions of the gnuplot-info file.
2537         ;; yes, this is a hassle.
2538         (run-hooks 'gnuplot-info-hook)
2539         (let ((there (bufferp (get-buffer "*info*"))))
2540           (info-lookup-setup-mode 'symbol 'gnuplot-mode)
2541           (or there (and (get-buffer "*info*") (kill-buffer "*info*")))
2542           ;; why are these buffers here?  I think that the general
2543           ;; user will not want them lying around
2544           (and (get-buffer "info dir")    (kill-buffer "info dir"))
2545           (and (get-buffer "info dir<2>") (kill-buffer "info dir<2>")))
2546         (setq gnuplot-keywords (gnuplot-set-keywords-list))
2547         (setq gnuplot-keywords-alist    ; needed for all-completions
2548               (mapcar 'list gnuplot-keywords)))
2549
2550     ;; or do something sensible if info-look is not installed
2551     (defun info-lookup-interactive-arguments (symbol)
2552       (message
2553        "Help is not available.  info-look.el is not installed.")
2554       (list nil nil))))
2555
2556
2557 (defun gnuplot-set-keywords-list ()
2558   "Set `gnuplot-keywords' from `info-lookup-cache'.
2559 Return a list of keywords."
2560   (let* ((list (cdr (assoc 'symbol info-lookup-cache)))
2561          (list (cdr (cdr (assoc 'gnuplot-mode list))))
2562          (list (car list))
2563          (store ()) item)
2564     (while list
2565       (setq item (car (car list))
2566             item (format "%s" item) ; keep this line for the sake of
2567             store (append (list item) store) ; info-look.el w/o my patch
2568             list  (cdr list)))
2569     (delete "nil" store)
2570     store ))
2571
2572 (defun gnuplot-xemacs-completion-at-point ()
2573   "Perform completion on keyword preceding point.
2574
2575 This binds `comint-dynamic-complete-functions' to
2576 `gnuplot-comint-complete' and uses `comint-dynamic-complete' to do the
2577 real work."
2578   ;; This actually would work in GNU Emacs too, but that seems a bit
2579   ;; hackish when completion-at-point exists
2580   (interactive)
2581   (let ((comint-dynamic-complete-functions
2582          '(gnuplot-comint-complete)))
2583     (comint-dynamic-complete)))
2584
2585 (defun gnuplot-completion-at-point ()
2586   "Return completions of keyword preceding point.
2587
2588 Uses the cache of keywords generated by info-lookup. See
2589 `gnuplot-setup-info-look'. If not nil, the return value is in the form
2590 \(BEGIN END COMPLETIONS) where BEGIN and END are buffer 
2591 positions and COMPLETIONS is a list."
2592  
2593   (if gnuplot-keywords-pending          ; <HW>
2594       (gnuplot-setup-info-look))
2595   (let* ((end (point))
2596          (beg (unwind-protect (save-excursion (backward-sexp 1) (point))))
2597          (patt (buffer-substring beg end))
2598          (pattern (if (string-match "\\([^ \t]*\\)\\s-+$" patt)
2599                       (match-string 1 patt) patt))
2600          (completions (all-completions pattern gnuplot-keywords-alist)))
2601     (if completions
2602         (list beg end completions)
2603       (message "No gnuplot keywords complete '%s'" pattern)
2604       nil))) 
2605
2606 (defun gnuplot-comint-complete ()
2607   "Complete the keyword preceding point in the gnuplot comint buffer.
2608
2609 Uses the cache of keywords generated by info-lookup and
2610 `comint-dynamic-simple-complete' to handle the actual
2611 completion."
2612   (if gnuplot-keywords-pending          ; <HW>
2613       (gnuplot-setup-info-look))
2614   (let ((completions (gnuplot-completion-at-point)))
2615     (if completions
2616         (let* ((beg (nth 0 completions))
2617                (end (nth 1 completions))
2618                (candidates (nth 2 completions))
2619                (completion-base-position (list beg end)))
2620           (comint-dynamic-simple-complete
2621            (buffer-substring-no-properties beg end)
2622            candidates))
2623       nil)))
2624
2625 (defun gnuplot-info-lookup-symbol (symbol &optional mode)
2626   "Wrapper for `info-lookup-symbol'.
2627 Takes SYMBOL and MODE as arguments exactly as `info-lookup-symbol'.
2628 After doing the info lookup, this displays the info file in a window
2629 frame as specified by the value of `gnuplot-info-display'.  If
2630 `gnuplot-info-display' is 'window, then the window will be shrunk to
2631 the size of the info entry if it is smaller than half the height of
2632 the frame."
2633   (interactive
2634    (cond (gnuplot-keywords
2635           (info-lookup-interactive-arguments 'symbol))
2636          (gnuplot-keywords-pending      ; <HW>
2637           (gnuplot-setup-info-look)
2638           (info-lookup-interactive-arguments 'symbol))
2639          (t
2640           (list nil (message
2641        "Help is not available.  The gnuplot info file could not be found.")))))
2642
2643   (if (and (featurep 'info-look) gnuplot-keywords)
2644       (let ((buff (current-buffer))
2645             (info-lookup-other-window-flag
2646              (if gnuplot-info-display t nil)))
2647         (if symbol () (setq symbol "Commands"))
2648         (info-lookup-symbol symbol mode)
2649         (cond ((equal gnuplot-info-display 'window) 
2650                ;; Adjust window height only if the frame is split 
2651                ;; horizontally, so as not to mess up the minibuffer <jjo>
2652                ;; we can't use shrink-window-if-larger-than-buffer here
2653                ;; because it doesn't work with Info mode's narrowing
2654                (with-selected-window (get-buffer-window "*info*")
2655                  (unless (gnuplot-window-full-height-p)
2656                    (enlarge-window
2657                     (min (- (count-lines (point-min) (point-max)) (window-height) -1)
2658                          (- (/ (frame-height) 2) (window-height)))))))
2659
2660               ((equal gnuplot-info-display 'frame)
2661                (switch-to-buffer buff)
2662                (delete-other-windows)
2663                (or (and gnuplot-info-frame
2664                         (frame-live-p gnuplot-info-frame))
2665                    (setq gnuplot-info-frame (make-frame)))
2666                (select-frame gnuplot-info-frame)
2667                (raise-frame gnuplot-info-frame)
2668                (if gnuplot-xemacs-p (setq toolbar-info-frame gnuplot-info-frame))
2669                (switch-to-buffer "*info*"))))))
2670
2671 ;; XEmacs doesn't have window-full-height-p
2672 (if (featurep 'xemacs)
2673     ;; The below is taken from GNU Emacs window.el
2674     (defun gnuplot-window-full-height-p (&optional window)
2675       (unless window
2676         (setq window (selected-window)))
2677       (= (window-height window)
2678          (window-height (frame-root-window (window-frame window)))))
2679   (defalias 'gnuplot-window-full-height-p 'window-full-height-p))
2680
2681 (defun gnuplot-insert (string)
2682   "Insert STRING at point and display help for for STRING.
2683 Help is not shown if `gnuplot-insertions-show-help-flag' is nil.  The
2684 help shown is for STRING unless STRING begins with the word \"set\" or
2685 \"show\", in which case help is shown for the thing being set or
2686 shown."
2687   (interactive)
2688   (cond ((and (not gnuplot-three-eight-p)
2689               (string-match "\\(emf\\|p\\(alette\\|m3d\\)\\|vgagl\\)" string))
2690          (message "%S is an option introduced in gnuplot 3.8 (You are using %s)"
2691                   string gnuplot-program-version) )
2692         (t
2693          (insert string)
2694          (let ((topic string) term)
2695            (if (string-match
2696                 "\\(set\\|show\\)[ \t]+\\([^ \t]+\\)\\(\\s-+\\([^ \t]+\\)\\)?"
2697                 string)
2698                (progn
2699                  (setq topic (downcase (match-string 2 string))
2700                        term            (match-string 4 string))
2701                  (if (string= topic "terminal") (setq topic (downcase term)))))
2702            (cond ((and (fboundp 'gnuplot-gui-set-options-and-insert)
2703                        gnuplot-gui-popup-flag)
2704                   (gnuplot-gui-set-options-and-insert))
2705                  (gnuplot-insertions-show-help-flag
2706                   (if gnuplot-keywords-pending          ; <HW>
2707                       (gnuplot-setup-info-look))
2708                   (gnuplot-info-lookup-symbol topic)) ) )) ) )
2709
2710 (defun gnuplot-toggle-info-display ()
2711   (interactive)
2712   (setq gnuplot-insertions-show-help-flag (not gnuplot-insertions-show-help-flag))
2713   (message (if gnuplot-insertions-show-help-flag
2714                "Help will be displayed after insertions."
2715              "Help no longer displayed after insertions.")))
2716
2717 \f
2718 ;;; --- bug reports
2719 ;; grep '(defcustom' gnuplot.el gnuplot-gui.el | awk '{print $2}'
2720 (defun gnuplot-bug-report ()
2721   "Submit a bug report about `gnuplot-mode' by email.
2722 Please do not send any bug reports about gnuplot itself to the
2723 maintainer of `gnuplot-mode'."
2724   (interactive)
2725   (let ((line (make-string 62 ?-)))
2726     (require 'reporter)
2727     (and (y-or-n-p
2728           "Do you really want to submit an email report about gnuplot? ")
2729          (y-or-n-p
2730           (concat "Variable values will be written to the message.  "
2731                   "Don't erase them.  OK? "))
2732          (reporter-submit-bug-report
2733           (format "%s <%s>" gnuplot-maintainer gnuplot-maintainer-email)
2734           (format "gnuplot-mode (version %s)" gnuplot-version)
2735           (append      ; variables to display values of in mail
2736            '(gnuplot-mode-hook
2737              gnuplot-load-hook
2738              gnuplot-after-plot-hook
2739              gnuplot-info-hook
2740              gnuplot-comint-setup-hook
2741              gnuplot-program
2742              gnuplot-program-version
2743              gnuplot-process-name
2744              gnuplot-gnuplot-buffer
2745              gnuplot-display-process
2746              gnuplot-info-display
2747              gnuplot-echo-command-line-flag
2748              gnuplot-insertions-show-help-flag
2749              gnuplot-delay
2750              gnuplot-quote-character
2751              gnuplot-keywords-when
2752              ;;gnuplot-insertions-menu-flag
2753              ;;gnuplot-insertions-adornments
2754              ;;gnuplot-insertions-plot-options
2755              ;;gnuplot-insertions-terminal
2756              ;;gnuplot-insertions-x-axis
2757              ;;gnuplot-insertions-x2-axis
2758              ;;gnuplot-insertions-y-axis
2759              ;;gnuplot-insertions-y2-axis
2760              ;;gnuplot-insertions-z-axis
2761              ;;gnuplot-insertions-parametric-plots
2762              ;;gnuplot-insertions-polar-plots
2763              ;;gnuplot-insertions-surface-plots
2764              gnuplot-toolbar-display-flag
2765              gnuplot-toolbar-use-toolbar
2766              gnuplot-gui-popup-flag
2767              gnuplot-gui-frame-plist
2768              gnuplot-gui-frame-parameters
2769              gnuplot-gui-fontname-list
2770              gnuplot-gui-plot-splot-fit-style
2771              ;; plus a few more...
2772              gnuplot-comint-recent-buffer
2773              gnuplot-version
2774              Info-directory-list
2775              exec-path
2776              features ))
2777           nil                           ; pre-hooks
2778           nil                           ; post-hooks
2779           (concat line                  ; salutation
2780            "\nInsert your description of the gnuplot-mode bug here.\n"
2781            "Please be as specific as possible.\n\n"
2782            "There are several known shortcomings of gnuplot-mode.\n"
2783            "Many of these have to do with the complicated and inconsistent\n"
2784            "syntax of gnuplot itself.  See the document string for the\n"
2785            "function `gnuplot-mode' (use `"
2786            (substitute-command-keys "\\[describe-function]")
2787            "') for details.\n\n"
2788            "Note that this bug report form should be used for problems\n"
2789            "with gnuplot-mode only.  Problems with gnuplot itself should\n"
2790            "be addressed directly to the developers of gnuplot.\n"
2791            "The maintainer of gnuplot-mode will not field questions about\n"
2792            "gnuplot itself.  Thank you.\n"
2793            line)
2794           ))))
2795
2796
2797 \f
2798 ;;; --- autoloaded functions: gnuplot-mode and gnuplot-make-buffer
2799
2800 ;;;###autoload
2801 (defun gnuplot-mode ()
2802   "Major mode for editing and executing GNUPLOT scripts.
2803 This was written with version 3.7 of gnuplot in mind but it should
2804 work fine with version 3.5 and the various 3.6 beta versions.
2805
2806 Report bugs in `gnuplot-mode' using \\[gnuplot-bug-report].
2807
2808                             ------O------
2809
2810 The help functions, keyword completion, and several other features
2811 depend upon having the info file properly installed.  The info file
2812 can be made in the document directory of the gnuplot distribution or
2813 is available at the `gnuplot-mode' web page:
2814     http://github.com/bruceravel/gnuplot-mode/
2815
2816 If the help function does not work properly, you may have an older
2817 version of the gnuplot info file.  Try the suggestion in the document
2818 string for the variable `gnuplot-info-hook'.  See the `gnuplot-mode'
2819 web page for more details.
2820
2821                             ------O------
2822
2823 There are several known shortcomings of `gnuplot-mode', version 0.5g
2824 and up.  Many of the shortcomings involve the graphical interface
2825 \(refered to as the GUI) to setting arguments to plot options.  Here is
2826 a list:
2827
2828  1.  Currently there is no way for `gnuplot-mode' to know if information
2829      sent to gnuplot was correctly plotted.
2830  2.  Indentation is sometimes a bit flaky.
2831  3.  \"plot\", \"splot\", and \"fit\" are handled in the GUI, but are
2832      a bit flaky.  Their arguments may not be read correctly from
2833      existing text, and continuation lines (common for plot and splot)
2834      are not supported.
2835  4.  The GUI does not know how to read from continuation lines.
2836  5.  Comma separated position arguments to plot options are
2837      unsupported in the GUI.  Colon separated datafile modifiers (used
2838      for plot, splot, and fit) are not supported either.  Arguments
2839      not yet supported by the GUI generate messages printed in grey
2840      text.
2841  6.  The GUI handling of \"hidden3d\" is flaky and \"cntrparam\" is
2842      unsupported.
2843
2844                             ------O------
2845
2846  Key bindings:
2847  \\{gnuplot-mode-map}"
2848   (interactive)
2849   (kill-all-local-variables)
2850   (use-local-map gnuplot-mode-map)
2851   (setq major-mode 'gnuplot-mode
2852         mode-name "Gnuplot")
2853   (set (make-local-variable 'comment-start) "# ")
2854   (set (make-local-variable 'comment-end) "")
2855   (set (make-local-variable 'comment-column) 32)
2856   (set (make-local-variable 'comment-start-skip) "#[ \t]*")
2857   (set (make-local-variable 'indent-line-function) 'gnuplot-indent-line)
2858
2859   (set (make-local-variable 'beginning-of-defun-function) 'gnuplot-beginning-of-defun)
2860   (set (make-local-variable 'end-of-defun-function) 'gnuplot-end-of-continuation)
2861
2862   (unless (featurep 'xemacs)
2863     (add-hook 'completion-at-point-functions 'gnuplot-completion-at-point nil t))
2864
2865   (set-syntax-table gnuplot-mode-syntax-table)
2866
2867   (if (or (fboundp 'hilit-set-mode-patterns)
2868           (equal gnuplot-keywords-when 'immediately)) ; <HW>
2869       (gnuplot-setup-info-look)) ;; <SE>
2870
2871   (if (fboundp 'hilit-set-mode-patterns) ; deal with hilit19 (ho hum!)
2872       (let ((keywords (concat "\\b\\(" (mapconcat 'identity
2873                                                   gnuplot-keywords "\\|")
2874                               "\\)\\b")))
2875         (hilit-set-mode-patterns
2876          'gnuplot-mode
2877          `(("#.*$" nil comment)
2878            ("\\([a-zA-Z0-9_-]+\\)\\(([^)]*)\\)?\\s *=" nil define)
2879            ,(list keywords 'nil 'keyword)
2880            (hilit-string-find ?\\ string)))))
2881
2882   (if gnuplot-xemacs-p                  ; deal with font-lock
2883       (when (fboundp 'turn-on-font-lock)
2884         (turn-on-font-lock))
2885     (progn
2886       (gnuplot-scan-after-change (point-min) (point-max))
2887       (add-hook 'after-change-functions 'gnuplot-scan-after-change nil t)
2888       (setq font-lock-defaults gnuplot-font-lock-defaults)
2889       (set (make-local-variable 'font-lock-multiline) t)
2890       (set (make-local-variable 'parse-sexp-lookup-properties) t)))
2891
2892
2893   (if (fboundp 'widget-create)          ; gnuplot-gui
2894       (condition-case ()
2895           (require 'gnuplot-gui)
2896         (error nil)))
2897   (setq gnuplot-first-call nil          ; a few more details ...
2898         gnuplot-comint-recent-buffer (current-buffer)
2899         comint-process-echoes        gnuplot-echo-command-line-flag)
2900   (run-hooks 'gnuplot-mode-hook)
2901   ;; the first time we need to figure out which gnuplot we are running
2902   (if gnuplot-program-version
2903       (gnuplot-setup-menu-and-toolbar)
2904     (gnuplot-fetch-version-number)))
2905
2906 ;;;###autoload
2907 (defun gnuplot-make-buffer ()
2908   "Open a new buffer in `gnuplot-mode'.
2909 When invoked, it switches to a new, empty buffer visiting no file
2910 and then starts `gnuplot-mode'.
2911
2912 It is convenient to bind this function to a global key sequence.  For
2913 example, to make the F10 key open a gnuplot script buffer, put the
2914 following in your .emacs file:
2915      (autoload 'gnuplot-make-buffer \"gnuplot\"
2916                \"open a buffer in gnuplot mode\" t)
2917      (global-set-key [(f10)] 'gnuplot-make-buffer)"
2918   (interactive)
2919   (switch-to-buffer gnuplot-gnuplot-buffer)
2920   (gnuplot-mode))
2921
2922 (defun gnuplot-show-version ()
2923   "Show version number in echo area"
2924   (interactive)
2925   (message "gnuplot-mode %s -- URL: %s" gnuplot-version gnuplot-maintainer-url))
2926
2927 (defun gnuplot-show-gnuplot-version ()
2928   "Show gnuplot program and version number in echo area"
2929   (interactive)
2930   (gnuplot-fetch-version-number)
2931   (message "You are calling gnuplot %s as %s" gnuplot-program-version gnuplot-program))
2932
2933
2934 ;;; That's it! ----------------------------------------------------------------
2935
2936 \f
2937 ;;; --- final chores: provide 'gnuplot and run load-hook
2938 ;; provide before run-hooks suggested by <DB>
2939 (provide 'gnuplot)
2940 (run-hooks 'gnuplot-load-hook)
2941
2942 ;;;============================================================================
2943 ;;;
2944
2945 ;;; gnuplot.el ends here