]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
update gnuplot
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Thu, 23 Nov 2023 19:17:46 +0000 (20:17 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Thu, 23 Nov 2023 19:17:46 +0000 (20:17 +0100)
Signed-off-by: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
elpa/gnuplot-20191212.1801/gnuplot-autoloads.el [deleted file]
elpa/gnuplot-20191212.1801/gnuplot-context.el [deleted file]
elpa/gnuplot-20191212.1801/gnuplot-gui.el [deleted file]
elpa/gnuplot-20191212.1801/gnuplot-pkg.el [deleted file]
elpa/gnuplot-20191212.1801/gnuplot.el [deleted file]
elpa/gnuplot-20230323.1400/gnuplot-autoloads.el [new file with mode: 0644]
elpa/gnuplot-20230323.1400/gnuplot-context.el [new file with mode: 0644]
elpa/gnuplot-20230323.1400/gnuplot-gui.el [new file with mode: 0644]
elpa/gnuplot-20230323.1400/gnuplot-pkg.el [new file with mode: 0644]
elpa/gnuplot-20230323.1400/gnuplot.el [new file with mode: 0644]

diff --git a/elpa/gnuplot-20191212.1801/gnuplot-autoloads.el b/elpa/gnuplot-20191212.1801/gnuplot-autoloads.el
deleted file mode 100644 (file)
index cf93e52..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-;;; gnuplot-autoloads.el --- automatically extracted autoloads
-;;
-;;; Code:
-
-(add-to-list 'load-path (directory-file-name
-                         (or (file-name-directory #$) (car load-path))))
-
-\f
-;;;### (autoloads nil "gnuplot" "gnuplot.el" (0 0 0 0))
-;;; Generated autoloads from gnuplot.el
-
-(autoload 'gnuplot-mode "gnuplot" "\
-Major mode for editing and executing GNUPLOT scripts.
-This was written with version 4.6 of gnuplot in mind, but should
-work with newer and older versions.
-
-Report bugs at https://github.com/emacsorphanage/gnuplot/issues
-
-                           ------O------
-
-Gnuplot-mode includes two different systems for keyword
-completion and documentation lookup: a newer one,
-`gnuplot-context-sensitive-mode' (enabled by default), and a
-older one which extracts keywords from gnuplot's Info file.  Both
-systems allow looking up documentation in the Info file.  The
-older system also depends having the info file properly installed
-to make a list of keywords.
-
-The info file should be installed by default with the Gnuplot
-distribution, or is available at the `gnuplot-mode' web page:
-https://github.com/emacsorphanage/gnuplot/
-
-With the new context-sensitive mode active, gnuplot-mode can also
-provide `eldoc-mode' syntax hints as you type.  This requires a
-separate file of strings, `gnuplot-eldoc.el', which is also
-provided by recent Gnuplot distributions.
-
-                           ------O------
-
-There are several known shortcomings of `gnuplot-mode', version 0.5g
-and up.  Many of the shortcomings involve the graphical interface
-\(refered to as the GUI) to setting arguments to plot options.  Here is
-a list:
-
- 1.  Currently there is no way for `gnuplot-mode' to know if information
-     sent to gnuplot was correctly plotted.
- 2.  \"plot\", \"splot\", and \"fit\" are handled in the GUI, but are
-     a bit flaky.  Their arguments may not be read correctly from
-     existing text, and continuation lines (common for plot and splot)
-     are not supported.
- 3.  The GUI does not know how to read from continuation lines.
- 4.  Comma separated position arguments to plot options are
-     unsupported in the GUI.  Colon separated datafile modifiers (used
-     for plot, splot, and fit) are not supported either.  Arguments
-     not yet supported by the GUI generate messages printed in grey
-     text.
- 5.  The GUI handling of \"hidden3d\" is flaky and \"cntrparam\" is
-     unsupported.
-
-                           ------O------
-
- Key bindings:
- \\{gnuplot-mode-map}
-
-\(fn)" t nil)
-
-(autoload 'gnuplot-make-buffer "gnuplot" "\
-Open a new buffer in `gnuplot-mode'.
-When invoked, it switches to a new, empty buffer visiting no file
-and then starts `gnuplot-mode'.
-
-It is convenient to bind this function to a global key sequence.  For
-example, to make the F10 key open a gnuplot script buffer, put the
-following in your .emacs file:
-     (autoload 'gnuplot-make-buffer \"gnuplot\"
-               \"open a buffer in gnuplot mode\" t)
-     (global-set-key [(f10)] 'gnuplot-make-buffer)
-
-\(fn)" t nil)
-
-(autoload 'run-gnuplot "gnuplot" "\
-Run an inferior Gnuplot process.
-
-\(fn)" t nil)
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "gnuplot" '("gnuplot-")))
-
-;;;***
-\f
-;;;### (autoloads nil "gnuplot-context" "gnuplot-context.el" (0 0
-;;;;;;  0 0))
-;;; Generated autoloads from gnuplot-context.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "gnuplot-context" '("gnuplot-")))
-
-;;;***
-\f
-;;;### (autoloads nil "gnuplot-gui" "gnuplot-gui.el" (0 0 0 0))
-;;; Generated autoloads from gnuplot-gui.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "gnuplot-gui" '("gnuplot-")))
-
-;;;***
-\f
-;;;### (autoloads nil nil ("gnuplot-pkg.el") (0 0 0 0))
-
-;;;***
-\f
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; coding: utf-8
-;; End:
-;;; gnuplot-autoloads.el ends here
diff --git a/elpa/gnuplot-20191212.1801/gnuplot-context.el b/elpa/gnuplot-20191212.1801/gnuplot-context.el
deleted file mode 100644 (file)
index d290eab..0000000
+++ /dev/null
@@ -1,2225 +0,0 @@
-;;; gnuplot-context.el -- context-sensitive help and completion for gnuplot
-
-;; Copyright (C) 2012-2013 Jon Oddie <jonxfieldNOSPAMgmail.com>
-
-;; Author:     Jon Oddie <jonxfieldNOSPAMgmail.com>
-;; Maintainer: Jon Oddie <jonxfieldNOSPAMgmail.com>
-;; Created:    Wednesday, 08 February 2012
-;; Updated:    Friday, 07 February 2013
-;; Version:    0.7.0
-;; Keywords:   gnuplot, plotting
-
-;; This file is not part of GNU Emacs.
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
-;;
-;; This lisp script is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-;;
-;; Permission is granted to distribute copies of this lisp script
-;; provided the copyright notice and this permission are preserved in
-;; all copies.
-;;
-;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; send bug reports to the author (jonxfieldNOSPAMgmail.com) or report via
-;; github (https://github.com/emacsorphanage/gnuplot)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;; Commentary:
-
-;;
-;; This file enhances gnuplot-mode with context-sensitive completion,
-;; ElDoc support, and info page lookup for gnuplot script and shell
-;; buffers.
-;; 
-;; Usage 
-;; =====
-;;
-;; Make sure to byte-compile this file, or things will be noticeably
-;; slow.
-;;
-;; Summary of key bindings:
-;;     C-c C-d            read info page for construction at point
-;;     C-u C-c C-d        prompt for info page to read
-;;     C-c M-h, C-c C-/   pop up multi-line ElDoc string for construction
-;;                          at point
-;;
-;; Gnuplot's context sensitive mode is best controlled using Customize
-;; (M-x customize-group gnuplot): simply enable the
-;; `gnuplot-context-sensitive-mode' setting. On recent Emacs (>= 23),
-;; you may also want to turn on `gnuplot-tab-completion' so that the
-;; TAB key does auto-completion on lines which are already
-;; indented. (This just sets the Emacs variable `tab-always-indent' to
-;; `complete' in Gnuplot buffers).
-;;
-;; If you need to turn context sensitivity on or off from Lisp code
-;; for some reason, call the function
-;; `gnuplot-context-sensitive-mode', which behaves like a minor mode.
-;;
-;; With `eldoc-mode' support, gnuplot-mode will show one-line syntax
-;; hints automatically in the echo area.  Whether eldoc-mode is active
-;; or not, you can always pop up a longer description of syntax using
-;; `gnuplot-help-function' (C-c C-/ or C-c M-h).  ElDoc support also
-;; requires an additional file of help strings, `gnuplot-eldoc.el',
-;; which should be included in recent Gnuplot releases. If it didn't
-;; come with your Gnuplot installation, you'll need to grab a recent
-;; source distribution of Gnuplot from http://gnuplot.info, and use
-;; the `doc2texi.el' program in the docs/ directory to create it.  So
-;; long as the file is on your Emacs load path somewhere it will be
-;; loaded automatically when needed.
-;;
-;; You can customize gnuplot-mode to turn on eldoc mode automatically
-;; using variable `gnuplot-eldoc-mode'.  Simply calling `eldoc-mode'
-;; will also work.
-;;
-;; Internal details
-;; ================
-;; 
-;; Gnuplot's command language has a fair amount of syntactic
-;; complexity, and the only way I could think of to support these
-;; features was to do a complete parse of the command line. So that's
-;; what this package does. Instead of building a parse tree, it
-;; matches up until the token at point, and then either makes a list
-;; of possible completions, or sets the variables `gnuplot-eldoc' and
-;; `gnuplot-info-at-point' based on where it is in the grammar at that
-;; point.
-;;
-;; The parsing/matching process happens in two phases: tokenizing
-;; (`gnuplot-tokenize') and matching (`gnuplot-match-pattern').  In
-;; order to be able to construct a full list of possible completions
-;; via backtracking, the matching algorithm simulates a simple stack
-;; machine with continuations.  At byte-compile time, the PEG-like
-;; grammar in S-expression notation (`gnuplot-grammar') is compiled
-;; down into a vector of "machine code" for the parsing machine (see
-;; `gnuplot-compile-pattern', `gnuplot-compile-grammar' and
-;; `gnuplot-compiled-grammar'). This is complicated, but it seems to
-;; work well enough, and it saves on the Emacs call stack.
-;;
-;; Compiling the grammar does require increasing `max-lisp-eval-depth'
-;; modestly. This shouldn't cause any problems on modern machines, and
-;; it only needs to be done once, at byte-compilation time.
-;;
-;; The parsing machine and compiler are partially based on the
-;; description in Medeiros and Ierusalimschy 2008, "A Parsing Machine
-;; for PEGs" (http://dl.acm.org/citation.cfm?doid=1408681.1408683).
-;;
-;; The pattern-matching language
-;; =============================
-;;
-;; The gnuplot-mode grammar (see `gnuplot-compiled-grammar') is a list
-;; of rules (RULE PATTERN), with each pattern written in S-expression
-;; notation as follows:
-;;
-;;    any
-;;     Match any token
-;;
-;;    name, number, string, separator
-;;     Match a token of the given type. "Separator" is semicolon, the
-;;     statement separator.
-;;
-;;    Any other symbol
-;;     Match another named rule in the grammar. May be recursive.
-;;
-;;    "STRING"
-;;     Match literally: a token with exactly the text "STRING".
-;;
-;;   (kw KEYWORD ALIASES ...)
-;;     Match abbreviated Gnuplot keywords. KEYWORD can be a string or
-;;     a cons (PREFIX . SUFFIX). In the latter case, this pattern
-;;     will match PREFIX plus any number of characters from the
-;;     beginning of SUFFIX.  Any literal string from ALIASES will
-;;     also match. The token-id of the matching token is mutated to
-;;     the canonical value of KEYWORD. 
-;;     Example:
-;;      (kw ("linew" ."idth") "lw") matches "linew", "linewi",
-;;     ... "linewidth" as well as "lw". Any of these tokens will
-;;     appear as "linewidth" in subsequent processing. (This is
-;;     important for the "info-keyword" form, see below).
-;;
-;; The other pattern forms combine simpler patterns, much like regular
-;; expressions or PEGs (parsing expression grammars):
-;;
-;;    (sequence { (:eldoc "eldoc string") }
-;;              { (:info "info page") }
-;;              { (:no-info) }
-;;          PATTERN PATTERN... )
-;;     Match all the PATTERNs in sequence or fail. Sequences can also
-;;     have optional ElDoc strings and info pages associated with
-;;     them; the innermost ElDoc or info page around point is the one
-;;     shown to the user. Alternatively, either property may be a
-;;     symbol, which should be a function to be called to get the
-;;     real value.  Finally, if no ElDoc string is specified but the
-;;     variable `gnuplot-eldoc-hash' contains a value for the name of
-;;     the info page at point, that value is used as the ElDoc string
-;;     instead.
-;;
-;;     For better readability, sequence forms can also be written as
-;;     a vector, omitting the `sequence': [PATTERN PATTERN ...]
-;;      
-;;    (either PATTERN PATTERN...)
-;;     Match the first PATTERN to succeed, or fail if none
-;;     matches. Like regexp `|'.
-;;
-;;    (many PATTERN)
-;;     Match PATTERN zero or more times, greedily; like regexp
-;;     `*'. Unlike a regular expression matcher, the parsing machine
-;;     will not backtrack and try to match fewer times if a later
-;;     part of the pattern fails. This applies equally to the other
-;;     non-deterministic forms "either" and "maybe".
-;;
-;;    (maybe PATTERN)
-;;     Match PATTERN zero or one times, like regexp `?'.
-;;
-;;    (capture NAME PATTERN)
-;;     Match PATTERN, capturing the tokens in a capture group named
-;;     NAME. Capture groups are stored in `gnuplot-captures'
-;;     and can be retrieved using `gnuplot-capture-group'. This is
-;;     used to store the plotting style, which we need in order to
-;;     give the correct ElDoc string for "using" clauses, and for
-;;     info keywords (see below)
-;;     
-;;    (info-keyword PATTERN)
-;;     Match PATTERN, and use whatever the value of the first token
-;;     it matches is to look up info pages for this pattern. Most
-;;     Gnuplot info pages have the same name as the keyword they
-;;     document, so by using this we only have to put :info
-;;     properties on the few that don't, such as "set".
-;;  
-;;    For convenience, "many", "maybe", "capture" and "info-keyword"
-;;    wrap the rest of their arguments in an implicit "sequence" form,
-;;    so we can write (maybe "," expression) instead of
-;;    (maybe (sequence "," expression))
-;;
-;;    (delimited-list PATTERN SEPARATOR)
-;;     Match a list of PATTERNs separated by SEPARATOR. Sugar for:
-;;     (sequence PATTERN (many (sequence SEPARATOR PATTERN)))
-;;
-;;   (assert LISP-FORM)
-;;     Evaluate LISP-FORM and fail if it returns NIL. We need this in
-;;     the patterns for "plot" and "splot" to check whether the
-;;     command at point should be parsed in parametric mode or
-;;     not. See `gnuplot-guess-parametric-p'.
-;;
-;;
-;; Bugs, TODOs, etc.
-;; =======================
-;;
-;; It would be useful to complete on user-defined functions and
-;; variables as well as built-ins.
-;;
-;; Completion probably will not work in continuation lines entered
-;; into the gnuplot interaction buffer.
-;;
-;; It would be better to pop up longer syntax descriptions in a
-;; temporary window, rather than making the echo area grow to fit
-;; many lines.
-;;
-;; In ElDoc mode, we parse the whole line every time the user stops
-;; typing. This is wasteful; should cache things in text properties
-;; instead.
-;;
-;; The pattern matching engine uses backtracking, which can take
-;; exponential time. So far it seems "fast enough" in actual use.
-;;
-;; The patterns don't really distinguish between "plot" and "splot"
-;; for things like plot styles, binary arguments, etc.
-;;
-;; Some other the patterns are probably not quite right, especially for
-;; things like abbreviated keywords, and features that I don't use
-;; myself like "fit". Hopefully anyone bothered by this will submit
-;; patches ;-)
-;;
-;; It would be possible to provide more helpful ElDoc strings for
-;; sub-parts of complicated options like "cntrparam". This is a time
-;; and maintenance issue rather than a technical one.
-
-;;; Code:
-
-\f
-;; Library dependencies
-(eval-when-compile
-  (require 'cl)
-
-  ;; Prevent compiler warnings about undefined functions
-  (require 'gnuplot))
-
-;; We need ElDoc support
-(require 'eldoc)
-
-;; Compatibility for Emacs version < 23
-(eval-when-compile
-  (when (not (fboundp 'string-match-p))
-    (defmacro string-match-p (&rest args)
-      `(save-match-data (string-match ,@args)))))
-
-\f
-;;;; The tokenizer.
-
-(defstruct gnuplot-token
-  start            ; Buffer start position
-  end      ; Buffer end position
-  id       ; Text
-  type)            ; a symbol: name, number, string, operator, separator
-
-(defvar gnuplot-operator-regexp
-  (eval-when-compile
-    (regexp-opt
-     '("(" ")" "(" ")" "{" "," "}" "[" ":" "]" "!" "**" "-" "+" "~" "!" "*" "/"
-       "%" "+" "-" "." "<" "<=" ">" ">=" "==" "!=" "eq" "ne" "&" "^" "|" "&&" "||"
-       "?" ":" "=" "$")))
-  "Regexp to match Gnuplot operators for tokenizing.")
-
-(eval-when-compile
-  (defmacro gnuplot-tokenize-by-regexps (&rest rules)
-    `(cond ,@(mapcar
-             (lambda (rule)
-               (let ((regexp (car rule))
-                     (token-type (cadr rule)))
-                 `((looking-at ,regexp)
-                   (let ((str (match-string-no-properties 0)))
-                     (forward-char (length str))
-                     (make-gnuplot-token :id str
-                                         :type ',token-type
-                                         :start (match-beginning 0)
-                                         :end (match-end 0))))))
-             rules))))
-
-(defun gnuplot-tokenize (&optional completing-p)
-  "Tokenize the Gnuplot command at point. Returns a list of `gnuplot-token' objects.
-
-If COMPLETING-P is non-nil, omits the token at point if it is a
-name; otherwise continues tokenizing up to the token at point. FIXME"
-  (let ((tokens '())
-       (stop-point (min (point)
-                        (gnuplot-point-at-end-of-command))))
-    (save-excursion
-      (if (save-excursion               ; HACK FIXME
-            (gnuplot-beginning-of-continuation)
-            (looking-at "\\s-*if\\s-*("))
-          (gnuplot-beginning-of-continuation)
-        (gnuplot-beginning-of-command))
-      (while
-         ;; Skip whitespace and continuation lines
-         (progn
-           (skip-syntax-forward "-" stop-point)
-           (while (looking-at "\\\\\n")
-             (forward-line)
-             (skip-syntax-forward "-" stop-point))
-           ;; Don't tokenize anything starting after point
-           (and (not (looking-at "#"))
-                (< (point) stop-point)))
-       (let* ((from (point))
-              (token
-               (cond  
-                ((gnuplot-tokenize-by-regexps
-                  ("[A-Za-z_][A-Za-z0-9_]*" name)
-                  ("[0-9]+\\(\\.[0-9]*\\)?\\([eE][+-]?[0-9]+\\)?\\|\\.[0-9]+\\([eE][+-]?[0-9]+\\)?" number)
-                  (gnuplot-operator-regexp operator)
-                   (";" separator)))
-
-                ((looking-at "['\"]")
-                 (let* ((bounds (bounds-of-thing-at-point 'sexp))
-                        (to (or (cdr bounds) stop-point)))
-                   (goto-char to)
-                   (make-gnuplot-token
-                    :id (buffer-substring-no-properties from to)
-                    :type 'string
-                    :start from :end to)))
-
-                (t (error
-                    "gnuplot-tokenize: bad token beginning %s"
-                    (buffer-substring-no-properties (point) stop-point))))))
-         
-         (push token tokens))))
-    
-    ;; If we are looking for completions, AND if the last token
-    ;; read is a name, AND if point is within the bounds of the
-    ;; last token, then discard it. The matching function
-    ;; generates a list of all possible tokens that could appear
-    ;; in that position for completion.
-    (if (and completing-p
-            tokens
-            (eq (gnuplot-token-type (car tokens)) 'name)
-            (<= (point) (gnuplot-token-end (car tokens))))
-       (pop tokens))
-    
-    (nreverse tokens)))
-
-
-\f
-;;;; The pattern and grammar compiler
-;;
-;; These functions compile the source S-expression grammar into a
-;; vector of instructions for the parsing machine,
-;; `gnuplot-match-pattern'. Its state consists of a program counter
-;; (PC), a position in the list of tokens, a call stack, and a second
-;; stack of backtracking entries (continuations). Its "machine
-;; instructions" are the following:
-;;
-;;    (any)
-;;     Match any token (fails only at end of command).
-;;
-;;    (literal LITERAL NO-COMPLETE)
-;;     Match token with `gnuplot-token-id' LITERAL or fail. If we
-;;     have reached the token before point, include LITERAL in the
-;;     completion list unless NO-COMPLETE is non-`nil'.
-;;
-;;    (token-type TYPE)
-;;     Match a token with `gnuplot-token-type' TYPE, or fail.
-;;
-;;    (keyword REGEXP NAME)
-;;     Match any token whose `gnuplot-token-id' matches REGEXP. Use
-;;     NAME for the completion list.
-;;
-;;    (jump OFFSET FIXED)
-;;     Jump to (set PC to) OFFSET if FIXED is non-nil, otherwise to
-;;     PC + OFFSET
-;;
-;;    (call OFFSET FIXED) 
-;;     Like "jump", but push a return address onto the stack for
-;;     (return). (The compiler adds the name of the rule being called
-;;     as a fourth element on the end of the list, but this is just a
-;;     comment for debugging purposes).
-;;
-;;    (return) 
-;;     Return to the PC address on top of the stack, or finish
-;;     matching if stack is empty. (Usually this doesn't happen,
-;;     because the machine stops as soon as it gets to the token at
-;;     point).
-;;
-;;    (choice OFFSET)
-;;     Push a backtracking entry for location PC + OFFSET onto the
-;;     backtracking stack. Backtracking entries save the contents of
-;;     the call stack, position in the token list, the values of
-;;     capture groups, and the record of loop progress (see below).
-;;
-;;    (check-progress)
-;;      Break out of infinite loops, like (many (many ...)).  Checks
-;;      an alist of conses (pc . tokens) for the position in the token
-;;      stream the last time this instruction was reached, and breaks
-;;      out of the loop if stuck in the same place; otherwise pushes a
-;;      new entry onto the list.
-;;
-;;    (fail)
-;;     Pop the most recent backtracking entry and continue from
-;;     there, or fail the whole match if out of backtrack
-;;     points. Failing to match returns the remainder of the token
-;;     list, although we don't currently use this for anything.
-;;
-;;    (commit OFFSET)
-;;     Discard one backtracking point and jump to PC + OFFSET. This
-;;     is used to make the (either) form non-deterministic.
-;;
-;;    (push TYPE VALUE)
-;;     Push an entry for an eldoc or info string (specified by TYPE)
-;;     onto the stack.
-;;
-;;    (pop TYPE)
-;;     Pop something off the stack; checks that it has the expected
-;;     TYPE, for safety.
-;;
-;;    (save-start NAME)
-;;     Open a capture group named NAME. Pushes an entry onto
-;;     `gnuplot-captures' with current position in token list as the
-;;     start of the group.
-;;
-;;    (save-end NAME)
-;;     Close the capture group named NAME. Finds the topmost entry in
-;;     `gnuplot-captures' with this name and sets its endpoint to the
-;;     current position in token list. Error if no group with that
-;;     name is found.
-;;
-;;    (label NAME)
-;;     This should never be reached and will cause an error. The
-;;     compiler inserts it at the beginning of compiled rules only
-;;     for debugging purposes.
-;;
-
-
-(eval-and-compile
-  ;; Compile a single pattern into a list of instructions. Leaves
-  ;; calls to other rules as symbolic instructions (call SYMBOL) and
-  ;; jumps, commits etc. as relative offsets; these are resolved into
-  ;; absolute locations by `gnuplot-compile-grammar', below.
-  (defun gnuplot-compile-pattern (pat)
-    (cond
-     ;; Strings match a single token literally
-     ((stringp pat)
-      ;; Don't add non-words to completion lists
-      (let ((wordp (string-match-p "^\\sw\\(\\sw\\|\\s_\\)*$" pat)))
-       `((literal ,pat ,(not wordp)))))
-     
-     ;; Symbols match token types or calls to other patterns
-     ((symbolp pat)
-      (case pat
-       ((any) `((any)))
-       ((name number string separator) `((token-type ,pat)))
-       (t `((call ,pat)))))
-     
-     ;; Syntactic sugar: write sequences (sequence ...) as vectors [...]
-     ((vectorp pat)
-      (gnuplot-compile-pattern
-       (append '(sequence) pat '())))
-
-     ;; Other forms combine simpler patterns
-     (t
-      (let ((type (car pat)))
-       (case type
-         ;; (sequence...): concatenate patterns, with optional eldoc
-         ;; and info strings
-         ((sequence)
-          (destructuring-bind
-              (subpats eldoc info)
-              (gnuplot-filter-arg-list (cdr pat))
-            (let ((eldoc-push '()) (eldoc-pop '())
-                  (info-push '()) (info-pop '())
-                  (compiled
-                   (mapcar 'gnuplot-compile-pattern subpats)))
-              (if eldoc
-                  (setq eldoc-push `((push eldoc ,eldoc))
-                        eldoc-pop `((pop eldoc))))
-              (if info
-                  (if (eq info :no-info)
-                      (setq info-push '((push no-scan t))
-                            info-pop '((pop no-scan)))
-                    (setq info-push `((push info ,info))
-                          info-pop `((pop info)))))
-              (apply 'append
-                     `(,info-push
-                       ,eldoc-push
-                       ,@compiled
-                       ,eldoc-pop
-                       ,info-pop)))))
-
-         ;; (either...): choose between patterns
-         ((either)
-          (cond
-           ((= (length pat) 2)         ; trivial case
-            (gnuplot-compile-pattern (cadr pat)))
-
-           ((> (length pat) 3)         ; could be more efficient...
-            (gnuplot-compile-pattern (gnuplot-either-helper pat)))
-
-           (t                          ; two patterns
-            (let* ((pat1 (cadr pat))
-                   (pat2 (caddr pat))
-                   (pat1-c (gnuplot-compile-pattern pat1))
-                   (pat2-c (gnuplot-compile-pattern pat2))
-                   (pat1-l (length pat1-c))
-                   (pat2-l (length pat2-c)))
-              `((choice ,(+ pat1-l 2))
-                ,@pat1-c
-                (commit ,(+ pat2-l 1))
-                ,@pat2-c)))))
-
-         ;; Repetition (*)
-         ((many)
-          (let* ((pat1 (cons 'sequence (cdr pat)))
-                 (pat1-c (gnuplot-compile-pattern pat1))
-                 (pat1-l (length pat1-c)))
-            `((choice ,(+ pat1-l 3))
-              (check-progress)         ; bail out of infinite loops
-              ,@pat1-c
-              (commit ,(- (+ pat1-l 2))))))
-
-         ;; Repetition (+)
-         ((many1)
-          (let* ((pat1 (cdr pat)))
-            (gnuplot-compile-pattern
-             `(sequence ,@pat1 (many ,@pat1)))))
-                 
-
-         ;; Optional (?)
-         ((maybe)
-          (let* ((pat1 (cons 'sequence (cdr pat)))
-                 (pat1-c (gnuplot-compile-pattern pat1))
-                 (pat1-l (length pat1-c)))
-            `((choice ,(+ pat1-l 1))
-              ,@pat1-c)))
-
-         ;; Syntactic sugar for delimited lists
-         ((delimited-list)
-          (let* ((item (cadr pat))
-                 (sep (caddr pat)))
-            (gnuplot-compile-pattern
-             `(sequence ,item (many (sequence ,sep ,item))))))
-
-         ;; keywords
-         ((kw)
-          (destructuring-bind (regex name)
-              (gnuplot-keyword-helper (cdr pat))
-            `((keyword ,regex ,name))))
-
-         ;; Capturing groups
-         ((capture)
-          (let* ((name (cadr pat))
-                 (pat1 (cons 'sequence (cddr pat)))
-                 (pat1-c (gnuplot-compile-pattern pat1)))
-            `((save-start ,name)
-              ,@pat1-c
-              (save-end ,name))))
-         
-         ;; Use the first token as an info keyword
-         ((info-keyword)
-          (let* ((pat1 (cons 'sequence (cdr pat)))
-                 (pat1-c (gnuplot-compile-pattern pat1)))
-            `((push info first-token)
-              ,@pat1-c
-              (pop info))))
-
-         ;; Assertions
-         ((assert)
-          (let* ((form (cadr pat)))
-            `((assert ,form))))
-
-         (t
-          (error "gnuplot-compile-pattern: bad pattern form %s" pat)))))))
-
-  ;; Helper function for destructuring (sequence ...) forms in patterns
-  ;; Takes the cdr of the sequence form, returns a list (PATTERNS ELDOC
-  ;; INFO).
-  (defun gnuplot-filter-arg-list (args)  
-    (let ((accum '())
-         (eldoc nil) (info nil))
-      (dolist (item args)
-       (let ((type (car-safe item)))
-         (case type
-           ((:eldoc) (setq eldoc (cadr item)))
-           ((:no-info) (setq info :no-info)) ; inhibit stack scanning
-           ((:info) (setq info (cadr item)))
-           (t (push item accum)))))
-      (list (reverse accum) eldoc info)))
-
-  ;; Helper function for compiling (kw...) patterns
-  ;; Takes the cdr of the kw form, returns a list (REGEXP KEYWORD)
-  (defun gnuplot-keyword-helper (args)
-    (let ((keyword (car args)) (aliases (cdr args)))
-      (when (consp keyword)
-       (let ((pre (car keyword)) (suf (cdr keyword)))
-         (setq keyword (concat pre suf))
-         (while (progn
-                  (push pre aliases)
-                  (not (zerop (length suf))))
-           (setq pre (concat pre (substring suf 0 1))
-                 suf (substring suf 1)))))
-      (let ((regex
-            (concat "^"
-                    (regexp-opt (cons keyword aliases))
-                    "$")))
-       (list regex keyword))))
-
-  ;; Helper function for compiling (either ...) patterns. Rewrites
-  ;; alternates (either A B C) into (either A (either B (either C D)))
-  (defun gnuplot-either-helper (pat)
-    (if (= (length pat) 3)
-       pat
-      `(either ,(cadr pat)
-              ,(gnuplot-either-helper
-                (cons 'either (cddr pat))))))
-  
-  ;; Compile the grammar (a list of rule-pattern pairs (RULE PATTERN))
-  ;; into a single vector of matching-machine instructions. Compiles
-  ;; each pattern individually, then "links" them into one vector,
-  ;; converting symbolic (call ...) instructions into numeric offsets
-  (defun gnuplot-compile-grammar (grammar start-symbol)
-    (let ((compiled-pats '())        ; Alist of (name . instructions)
-         ;; Reserve space for a jump to the start symbol
-         (code-length 1))
-
-      ;; Compile each rule and find the total number of instructions
-      (dolist (item grammar)
-       (let* ((name (car item))
-              (pat (cadr item))
-              (code (gnuplot-compile-pattern pat)))
-         (push (cons name code) compiled-pats)
-         ;; Reserve space for a label at the beginning and (return) at
-         ;; the end
-         (setq code-length (+ code-length 2 (length code)))))
-
-      ;; Copy instructions into a single vector
-      (let ((object-code (make-vector code-length nil))
-           (name->offset (make-hash-table))
-           (i 1))
-       (setf (aref object-code 0) `(jump ,start-symbol))
-       (dolist (chunk compiled-pats)
-         (let ((name (car chunk))
-               (code (cdr chunk)))
-           (setf (aref object-code i) `(label ,name))
-           (incf i)
-           (puthash name i name->offset)
-           (while code
-             (setf (aref object-code i) (car code)
-                   code (cdr code)
-                   i (1+ i)))
-           (setf (aref object-code i) '(return)
-                 i (1+ i))))
-
-       ;; Resolve symbolic and relative jumps 
-       (let ((pattern-name nil))
-         (dotimes (i (length object-code))
-           (let ((inst (aref object-code i)))
-             (case (car inst)
-               ((label)
-                (setq pattern-name (cadr inst)))
-
-               ((jump call choice commit)
-                (cond
-                 ((symbolp (cadr inst))
-                  (let* ((name (cadr inst))
-                         (location (gethash name name->offset)))
-                    (if (not location)
-                        (error
-                         (concat "gnuplot-compile-grammar: "
-                                 "No rule found for symbol `%s' in pattern `%s'")
-                         name pattern-name))
-                    (setcdr inst `(,location ,name))))
-
-                 ((numberp (cadr inst))
-                  (let* ((offset (cadr inst))
-                         (location (+ offset i)))
-                    (setcdr inst `(,location))))
-
-                 (t
-                  (error "gnuplot-compile-grammar: bad instruction %s" inst))))))))
-       object-code))))
-
-;;; The grammar.
-(defvar gnuplot-compiled-grammar
-  (eval-when-compile
-    (let ((max-lisp-eval-depth 600))
-      (gnuplot-compile-grammar
-       '((expression
-         [infix-expression (maybe "?" expression ":" expression)])
-        
-        (prefix-operator
-         (either "!" "~" "-" "+"))
-
-        (infix-operator
-         (either "**" "*" "/" "%" "+" "-" "." "<" "<=" ">" ">=" "==" "!=" "eq" "ne"
-                 "&" "^" "|" "&&" "||"))
-
-        (infix-expression
-         [(many prefix-operator)
-          primary-expression
-          (many infix-operator expression)])
-
-        (primary-expression
-         [(either number string parenthesized-expression
-                  column-ref complex-number function-call name)
-          (many "!")
-          (maybe "**" infix-expression)
-          (maybe substring-range)])
-
-        (function-call
-         (either
-          (info-keyword
-           [(either "abs" "acos" "acosh" "arg" "asin" "asinh" "atan" "atan2" "atanh"
-                    "besj0" "besj1" "besy0" "besy1" "ceil" "column" "columnhead"
-                    "cos" "cosh" "defined" "erf" "erfc" "exists" "exp" "floor"
-                    "gamma" "gprintf" "ibeta" "igamma" "imag" "int" "inverf"
-                    "invnorm" "lambertw" "lgamma" "log" "log10" "norm" "real"
-                    "sgn" "sin" "sinh" "sprintf" "sqrt" "strftime" "stringcolumn"
-                    "strlen" "strptime" "strstrt" "substr" "tan" "tanh" "timecolumn"
-                    "tm_hour" "tm_mday" "tm_min" "tm_mon" "tm_sec" "tm_wday"
-                    "tm_yday" "tm_year" "valid" "value" "word" "words" "rand")
-            parenthesized-expression])
-          [(:info "elliptic_integrals")
-           (either "EllipticK" "EllipticE" "EllipticPi")
-           parenthesized-expression]
-          [name
-           parenthesized-expression]))
-
-        (parenthesized-expression
-         ["(" comma-list ")"])
-
-        (complex-number
-         ["{" (maybe "-") number "," (maybe "-") number "}"])
-
-        (column-ref
-         ["$" number])
-
-        (substring-range-component
-         (maybe (either "*" expression)))
-
-        (substring-range
-         ["[" (delimited-list substring-range-component ":" 2 2) "]"])
-
-;;; Assignments
-        (lhs
-         [name (maybe "(" (delimited-list name "," 1) ")")])
-
-        (assignment
-         [lhs "=" (either assignment expression)])
-
-;;; Lists of expressions
-        (comma-list
-         (delimited-list (either assignment expression) ","))
-
-        (colon-list
-         (delimited-list expression ":"))
-
-        (tuple
-         ["(" (delimited-list expression "," 2 3) ")"])
-
-;;; Commands
-        (command
-         (info-keyword
-          (either plot-command splot-command replot-command fit-command print-command
-                  set-command cd-command call-command simple-command
-                  eval-command load-command lower-raise-command pause-command
-                  save-command system-command test-command undefine-command
-                  update-command assignment if-command new-if-command do-command)))
-
-         (command-list
-          (delimited-list command separator))
-
-         (block ["{" command-list (maybe separator) "}"])
-
-;;; old-style one-line if(..) command
-         (if-command
-          (info-keyword
-           "if" parenthesized-expression command-list
-           (maybe separator "else" command-list)))
-
-;;; new-style block-structured if
-         (new-if-command
-          (info-keyword
-           "if" parenthesized-expression block
-           (maybe "else" block)))
-
-;;; block-structured "do"
-         (do-command
-          (info-keyword "do" iteration-spec block))
-
-;;; PLOT, SPLOT commands
-        (plot-command
-         [(kw ("pl" . "ot"))
-          
-          (either
-           ;; Parametric ranges
-           [(assert (gnuplot-guess-parametric-p))
-            (maybe t-axis-range) (maybe x-axis-range) (maybe y-axis-range)]
-
-           ;; Non-parametric ranges
-           [(maybe x-axis-range) (maybe y-axis-range)])
-
-          plot-body])
-
-        (splot-command
-         [ ;; This capturing group lets `gnuplot-find-using-eldoc' know
-          ;; that this is an splot command
-          (capture :splot-command (kw ("spl" . "ot")))
-
-          (either
-           ;; Parametric ranges
-           [(assert (gnuplot-guess-parametric-p))
-            (maybe u-axis-range) (maybe v-axis-range)
-            (maybe x-axis-range) (maybe y-axis-range) (maybe z-axis-range)]
-
-           ;; Non-parametric ranges
-           [(maybe x-axis-range) (maybe y-axis-range) (maybe z-axis-range)])
-
-          plot-body])
-
-         (replot-command [(kw "replot") plot-body])
-        
-        ;; Axis ranges
-        (axis-range-component
-         (maybe (either "*" expression)))
-
-        (axis-range-body
-         (delimited-list axis-range-component ":" 2 3))
-        
-        (axis-range
-         [(:info "ranges")
-          "[" (maybe (maybe name "=") axis-range-body) "]"])
-        
-        (x-axis-range [(:eldoc "X RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-        (y-axis-range [(:eldoc "Y RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-        (z-axis-range [(:eldoc "Z RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-        (t-axis-range [(:eldoc "T RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-        (u-axis-range [(:eldoc "U RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-        (v-axis-range [(:eldoc "V RANGE: [{<dummy>=}<min>:<max>]") axis-range])
-
-        ;; Body of a plot/splot command. Should really be different for
-        ;; parametric vs non-parametric, but that's too hard.
-        (plot-body
-         (delimited-list
-          [(maybe iteration-spec) plot-expression plot-modifiers]
-          ","))
-
-        ;; Iteration: for [... ]
-        (iteration-spec
-         [(:info "iteration")
-          (many1
-            "for" "[" name
-            (either ["=" (delimited-list expression ":")]
-                    ["in" expression])
-            "]")])
-        
-        ;; Expressions to plot can be preceded by any number of
-        ;; assignments, with or without commas
-        (plot-expression
-         [(many [(:no-info) assignment (maybe ",")])
-          expression])
-
-;;; Plot/splot modifiers
-        ;; These should probably be more different for plot and splot ...
-        (plot-modifiers (many (either plot-modifier datafile-modifier)))
-
-        (plot-modifier
-         (info-keyword
-          (either
-           ;; simple one-word modifiers
-           (kw "nohidden3d") (kw "nocontours") (kw "nosurface")
-           
-           ;; word followed by expression
-           [(either
-             (kw ("lines" . "tyle") "ls")
-             (kw ("linet" . "ype") "lt")
-             (kw ("linew" . "idth") "lw")
-             (kw ("pointt" . "ype") "pt")
-             (kw ("points" . "ize") "ps")
-             (kw ("pointi" . "nterval") "pi"))
-            expression]
-
-           ;; others defined below
-           title-modifier notitle-modifier axes-modifier with-modifier
-           linecolor-modifier fillstyle-modifier)))
-
-        (title-modifier
-         [(kw ("t" . "itle")) expression])
-        
-        (notitle-modifier
-         [(:info "title")
-          (kw ("not" . "itle"))
-          (maybe string)])
-
-        (axes-modifier
-         [(kw ("ax" . "es")) (either "x1y1" "x1y2" "x2y1" "x2y2")])
-
-        (linecolor-modifier
-         [(kw ("linec" . "olor") "lc") color-spec])
-
-        (fillstyle-modifier
-         [(kw "fillstyle" "fs")
-          ;; fill-style also used by "set style fill"
-          fill-style])
-        
-        (fill-style
-         [(either
-           "empty"
-           [(maybe "transparent")
-            (either "pattern" "solid")
-            (maybe (either fill-style-border-clause expression))])
-          (maybe fill-style-border-clause)])
-
-        (fill-style-border-clause
-         (either "noborder" [(kw ("bo" . "rder")) expression]))
-
-        (color-spec
-         [(:info "colorspec")
-          (either
-           (kw ("var" . "iable"))
-
-           [(kw ("pal" . "ette"))
-            (either "z"
-                    [(either "frac" "cb") expression])]
-
-           [(kw ("rgb" . "color"))
-            (either (kw ("var" . "iable")) string)])])
-
-        (with-modifier
-         [(:info "plotting_styles")
-          (kw ("w" . "ith"))
-          
-          ;; plotting-style also used for "set style data"
-          (capture :with-style plotting-style)])
-
-        (plotting-style
-         (info-keyword
-          (either
-           ;; Simple styles that take no arguments
-           (kw ("l" . "ines")) (kw ("i" . "mpulses")) (kw ("p" . "oints"))
-           (kw ("linesp" . "oints") "lp") (kw ("d" . "ots")) (kw ("yerrorl" . "ines"))
-           (kw ("errorl" . "ines")) (kw ("xerrorl" . "ines")) (kw ("xyerrorl" . "ines"))
-           (kw ("ye" . "rrorbars")) (kw ("e" . "rrorbars")) (kw ("xe" . "rrorbars"))
-           (kw ("xye" . "rrorbars")) (kw "boxes") (kw ("hist" . "ograms"))
-           (kw ("boxer" . "rorbars")) (kw ("boxx" . "yerrorbars")) (kw ("st" . "eps"))
-           (kw ("fs" . "teps")) (kw ("his" . "teps")) (kw ("fin" . "ancebars"))
-           (kw ("can" . "dlesticks")) (kw ("pm" . "3d"))
-           (kw ("cir" . "cles"))
-           
-           ;; Image styles all use the same info page
-           [(:info "image")
-            (either (kw ("ima" . "ge"))
-                    (kw ("rgbima" . "ge"))
-                    (kw ("rgba" . "lpha")))]
-           
-           ;; More complicated styles defined below
-           labels-style-clause
-           filledcurves-style-clause
-           vectors-style-clause)))
-
-        (labels-style-clause
-         [(kw "labels")
-          (maybe textcolor-spec)])
-          
-        (filledcurves-style-clause
-         [(kw ("filledc" . "urves"))
-          (maybe
-           (either
-            "closed"
-            
-            ["xy" "=" expression "," expression]
-
-            [(maybe (either "above" "below"))
-             (maybe [(either "x1" "x2" "y1" "y2")
-                     (maybe "=" expression)])]))])
-
-        (vectors-style-clause
-         [(kw ("vec" . "tors"))
-          (many
-           (either
-            "nohead" "head" "heads" "filled" "empty" "nofilled" "front" "back"
-            [(kw "arrowstyle" "as") expression]
-            ["size" (delimited-list expression ",")]
-            linestyle-spec))])
-
-;;; Various style specifiers, used in different places
-        (linestyle-spec
-         (many1
-          (either
-           [(kw ("lines" . "tyle") "ls") expression]
-           [(kw ("linet" . "ype") "lt") expression]
-           [(kw ("linew" . "idth") "lw") expression])))
-        
-        (textcolor-spec
-         [(kw "textcolor" "tc")
-          (either "default"
-                  ["lt" expression]
-                  color-spec)])
-
-        (pointsize-spec [(kw "pointsize" "ps") expression])
-
-;;; Datafile modifiers
-        (datafile-modifier
-         (info-keyword
-          (either binary-modifier
-                  [(maybe "nonuniform") (kw ("mat" . "rix"))]
-                  index-modifier every-modifier
-                  thru-modifier using-modifier
-                  smooth-modifier
-                  "volatile" "noautoscale")))
-        
-        (index-modifier
-         [(kw ("i" . "ndex"))
-          (either string (delimited-list expression ":" 0 2))])
-
-        (every-modifier
-         [(kw ("ev" . "ery")) (delimited-list (maybe expression) ":")])
-        
-        (thru-modifier
-         [(kw "thru") expression])
-        
-        (using-modifier
-         [(:eldoc gnuplot-find-using-eldoc) 
-          (kw ("u" . "sing"))
-          (either
-           string
-           [colon-list (maybe string)])])
-
-        (smooth-modifier
-         [(kw ("s" . "mooth"))
-          (either (kw ("a" . "csplines")) (kw ("b" . "ezier")) (kw ("c" . "splines"))
-                  (kw ("s" . "bezier")) (kw ("u" . "nique")) (kw ("f" . "requency"))
-                  (kw ("cum" . "ulative")) (kw ("k" . "density")))])
-
-;;; Binary datafile modifiers
-        (binary-modifier 
-         ["binary" (many binary-keyword)])
-
-        (binary-keyword
-         (either
-          ;; All of these binary keywords are described on the same
-          ;; info page
-          [(:info "keywords")
-           (either
-            "transpose" "flipx" "flipy" "flipz"
-            ["flip" "=" (either "x" "y" "z")]
-            ["scan" "=" name]
-            [(either "dx" "dy" "dz") "=" number]
-            [(either "origin" "center" "perpendicular") "="
-             (delimited-list tuple ":")]
-            [(kw ("rot" . "ate") "rotation") "="
-             (sequence expression (maybe (kw ("d" . "eg")) (kw ("p" . "i"))))])]
-
-          ;; remaining binary keywords have their own info pages
-          (info-keyword
-           (either
-            [(either "array" "record")
-             "="
-             (delimited-list expression ":")]
-
-            [(either "skip")
-             "="
-             (delimited-list expression ":")]
-           
-            [(either "format" "endian" "filetype")
-             "="
-             expression]))))
-        
-;;; "fit" command
-        (fit-command
-         [(:info "fit")
-          (kw "fit")
-          (many axis-range)
-          expression
-          string
-          (many plot-modifier)
-          (kw "via")
-          (either string (delimited-list name ","))])
-
-;;; print command
-        (print-command
-         [(kw ("pr" . "int")) (delimited-list expression ",")])
-
-;;; set commands
-        (set-command
-         [(:eldoc "set ...")
-          (:info "set-show")
-          (either (kw "set") (kw "unset") (kw "show"))
-          (maybe iteration-spec)
-          (info-keyword
-           (either set-angles-clause set-arrow-clause
-                   set-autoscale-clause set-bars-clause
-                   set-border-clause set-boxwidth-clause
-                   set-clabel-clause set-clip-clause
-                   set-cntrparam-clause set-colorbox-clause
-                   set-contour-clause set-datafile-clause
-                   set-decimalsign-clause set-dgrid3d-clause
-                   set-dummy-clause set-encoding-clause
-                   set-fit-clause set-fontpath-clause
-                   set-format-clause set-grid-clause
-                   set-hidden3d-clause set-historysize-clause
-                   set-isosamples-clause set-key-clause
-                   set-label-clause set-loadpath-clause
-                   set-locale-clause set-logscale-clause
-                   set-mapping-clause set-margin-clause
-                   set-multiplot-clause set-mxtics-clause
-                   set-object-clause set-offsets-clause
-                   set-origin-clause set-output-clause
-                   set-parametric-clause set-pm3d-clause
-                   set-palette-clause set-pointsize-clause
-                   set-polar-clause set-print-clause
-                   set-samples-clause set-size-clause
-                   set-style-clause
-                   set-surface-clause set-table-clause
-                   set-terminal-clause set-termoption-clause
-                   set-tics-clause set-tics-clause-2
-                   set-xtics-clause
-                   set-timestamp-clause set-timefmt-clause
-                   set-title-clause set-view-clause
-                   set-data-clause set-dtics-clause
-                   set-xlabel-clause
-                   set-mtics-clause set-range-clause
-                   set-xyplane-clause set-zero-clause
-                   set-zeroaxis-clause))])
-        
-;;; positions and coordinate systems for set options
-        (position-system
-         (either "first" "second" "graph" "screen" "character"))
-
-        (dimension [(maybe position-system) expression])
-        
-        (position
-         [dimension "," dimension (maybe "," dimension)])
-        
-        (to (either "to" "rto"))
-        
-;;; all the different "set ... " options
-        (set-angles-clause
-         ["angles" (either "degrees" "radians")])
-        
-        (set-arrow-clause
-         ["arrow" (maybe number) 
-          (many
-           (either ["from" position] [to position]
-                   [(kw "arrowstyle" "as") expression]
-                   "nohead" "head" "backhead" "heads"
-                   ["size" dimension "," expression (maybe "," expression)]
-                   "filled" "empty" "nofilled" "front" "back"
-                   linecolor-modifier linestyle-spec))])
-
-        (set-autoscale-clause
-         ["autoscale"
-          (either "fix"
-                  "keepfix"
-                  "x" "y" "z" "cb" "x2" "y2" "xy"
-                  "xmin" "ymin" "zmin" "cbmin" "x2min" "y2min" 
-                  "xmax" "ymax" "zmax" "cbmax" "x2max" "y2max" 
-                  "xfix" "yfix" "zfix" "cbfix" "x2fix" "y2fix"
-                  "xfixmax" "yfixmax" "zfixmax" "cbfixmax" "x2fixmax" "y2fixmax"
-                  "xfixmin" "yfixmin" "zfixmin" "cbfixmin" "x2fixmin" "y2fixmin")])
-
-        (set-bars-clause
-         ["bars"
-          (either expression "small" "large" "fullwidth")
-          (either "front" "back")])
-
-        (set-border-clause
-         ["border"
-          (maybe number)
-          (maybe (either "front" "back"))
-          (maybe (kw "linewidth" "lw") expression)
-          (maybe
-           (either (kw "linestyle" "ls") (kw "linetype" "lt"))
-           expression)])
-
-        (set-boxwidth-clause
-         ["boxwidth"
-          (maybe expression)
-          (maybe (either (kw ("abs" . "olute")) "relative"))])
-
-        (set-clabel-clause
-         ["clabel" (maybe string)])
-
-        (set-clip-clause
-         ["clip" (maybe (either "points" "one" "two"))])
-
-        (set-cntrparam-clause
-         [(kw "cntrparam")
-          (either
-           "linear" "cubicspline" "bspline"
-           
-           [(either "points" "order") number]
-           
-           [(kw "levels")
-            (either
-             number
-             (sequence (kw "auto") (maybe number))
-             (sequence
-              (kw "discrete") comma-list)
-             (sequence
-              (kw "incremental") (delimited-list expression "," 2 3)))])])
-
-        (set-colorbox-clause
-         [(:info "color_box")
-          (kw ("colorb" . "ox"))
-          (many
-           (either
-            (kw ("vert" . "ical")) (kw ("horiz" . "ontal"))
-            "default" "user"
-            ["origin" expression "," expression]
-            ["size" expression "," expression]
-            "front" "back"
-            "noborder" "bdefault"
-            ["border" expression]))])
-
-        (set-contour-clause
-         ["contour" (either "base" "surface" "both")])
-
-        (set-datafile-clause
-         ["datafile"
-          (either [(:info "set_datafile_fortran")
-                   "fortran"]
-                  [(:info "set_datafile_nofpe_trap")
-                   "nofpe_trap"]
-                  [(:info "set_datafile_missing")
-                   "missing" (maybe string)]
-                  [(:info "set_datafile_separator")
-                   "separator" (either "whitespace" string)]
-                  [(:info "set_datafile_commentschars")
-                   "commentschars" (maybe string)]
-                  [(:info "set_datafile_binary")
-                   "binary" (many binary-keyword)])])
-
-        (set-decimalsign-clause
-         ["decimalsign"
-          (either string ["locale" (maybe string)])])
-
-        (set-dgrid3d-clause
-         ["dgrid3d"
-          (maybe expression)           ; fixme
-          (maybe "," expression)
-          (either
-           "splines"
-           ["qnorm" expression]
-           [(either "gauss" "cauchy" "exp" "box" "hann")
-            (maybe expression)
-            (maybe "," expression)])])
-
-        (set-dummy-clause
-         ["dummy"
-          name (maybe "," name)])
-
-        (set-encoding-clause
-         ["encoding"
-          (either "default" "iso_8859_1" "iso_8859_15" "iso_8859_2" "iso_8859_9"
-                  "koi8r" "koi8u" "cp437" "cp850" "cp852" "cp1250" "cp1251" "cp1254"
-                  "utf8" "locale")])
-
-        (set-fit-clause
-         [(:info "fit_")
-          "fit"
-          (either
-           ["logfile" string]
-           "errorvariables" "noerrorvariables")])
-
-        (set-fontpath-clause
-         ["fontpath" (many string)])
-
-        (set-format-clause
-         [(:info "format_")
-          "format"
-          (maybe (either "x" "y" "xy" "x2" "y2" "z" "cb"))
-          string])
-
-        (set-grid-clause
-         ["grid"
-          (either "nomxtics" "mxtics" "noxtics" "xtics" "nomytics" "mytics"
-                  "noytics" "ytics" "nomztics" "mztics" "noztics" "ztics"
-                  "nomx2tics" "mx2tics" "nox2tics" "x2tics" "nomy2tics"
-                  "my2tics" "noy2tics" "y2tics" "nomcbtics" "mcbtics"
-                  "nocbtics" "cbtics" "layerdefault" "front" "back"
-                  [linestyle-spec (maybe "," linestyle-spec)])])
-
-        (set-hidden3d-clause
-         [(kw ("hidden" . "3d"))
-          (many
-           (either
-            "defaults" "front" "back"
-            ["offset" expression] "nooffset"
-            ["trianglepattern"
-             (either "0" "1" "2" "3" "4" "5" "6" "7")]
-            ["undefined" (either "1" "2" "3")]
-            ["noundefined"]
-            "altdiagonal" "noaltdiagonal"
-            "bentover" "nobentover"))])
-        
-        (set-historysize-clause
-         ["historysize" number])
-
-        (set-isosamples-clause
-         [(kw ("isosam" . "ples")) number (maybe "," number)])
-
-        (set-key-clause
-         ["key"
-          (many
-           (either "on" "off" "default"
-                   [(either "inside" "outside")
-                    (either "lmargin" "rmargin" "tmargin" "bmargin")]
-                   ["at" expression "," expression]
-                   "left" "right" "center" "top" "bottom" "vertical"
-                   "horizontal" "Left" "Right" "reverse" "noreverse" "invert"
-                   "noinvert" "above" "over" "below" "under"
-                   ["samplen" number]
-                   ["spacing" number]
-                   ["width" number]
-                   [(either "autotitle" "noautotitle") (maybe "columnheader")]
-                   ["title" expression] "enhanced" "noenhanced" ["font" string]
-                   textcolor-spec
-                   [(either "box" "nobox") linestyle-spec]
-                   ["maxcols" (either expression "auto")]
-                   ["maxrows" (either expression "auto")]))])
-
-        (set-label-clause
-         ["label"
-          (maybe expression)
-          (either label-clause-component expression)
-          (many label-clause-component)])
-
-        (label-clause-component
-         (either
-          ["at" position]
-          "left" "center" "right"
-          (either "norotate" ["rotate" "by" expression])
-          ["font" string]
-          "noenhanced"
-          "front" "back"
-          textcolor-spec
-          "nopoint" ["point" (many (either pointsize-spec linestyle-spec))]
-          ["offset" position]))
-
-        (set-loadpath-clause
-         ["loadpath" (many string)])
-
-        (set-locale-clause
-         ["locale" (maybe string)])
-
-        (set-logscale-clause
-         ["logscale"
-          (either "x" "y" "xy" "x2" "y2" "z" "cb" name)])
-
-        (set-mapping-clause
-         ["mapping" (either "cartesian" "spherical" "cylindrical")])
-
-        (set-margin-clause
-         [(either "bmargin" "lmargin" "rmargin" "tmargin")
-          (maybe "at" "screen") expression])
-
-        ;; TODO: set-mouse-clause
-
-        (set-multiplot-clause
-         ["multiplot"
-          (maybe
-           ["layout" number "," number
-            (maybe (either "rowsfirst" "columnsfirst"))
-            (maybe (either "downwards" "upwards"))
-            (maybe "title" string)
-            (maybe "scale" number (maybe "," number))
-            (maybe "offset" number (maybe "," number))])])
-
-        (set-mxtics-clause
-         [(:info "mxtics")
-          (either "mxtics" "mytics" "mztics" "mx2tics" "my2tics" "mcbtics")
-          (either "default" number)])
-
-        ;; "set object", objects, dimensions, positions
-        (set-object-clause
-         ["object"
-          (maybe number)
-          (info-keyword
-           (either rectangle-object ellipse-object circle-object polygon-object))
-          (maybe (either "front" "back" "behind"))
-          (maybe (kw "fillcolor" "fc") color-spec)
-          (maybe "fs" expression)
-          (maybe "default")
-          (maybe (kw "linewidth" "lw") expression)])
-        
-        (rectangle-object
-         [(kw ("rect" . "angle"))
-          (maybe
-           (either
-            ["from" position (either "to" "rto") position]
-            ["center" position "size" dimension "," dimension]
-            ["at" position "size" dimension "," dimension]))])
-
-        (ellipse-object
-         ["ellipse"
-          (either "at" "center") position
-          "size" dimension "," dimension
-          (maybe "angle" number)])
-
-        (circle-object
-         ["circle"
-          (either "at" "center") position
-          "size" dimension
-          (maybe "arc" "[" number ":" number "]")])
-
-        (polygon-object
-         ["polygon"
-          "from" position (many (either "to" "rto") position)])
-
-        ;; "set offsets"
-        (set-offsets-clause
-         ["offsets"
-          (delimited-list [(maybe "graph") expression] "," 4 4)])
-
-        (set-origin-clause
-         ["origin" expression "," expression])
-
-        (set-output-clause
-         ["output" (maybe string)])
-
-        (set-parametric-clause
-         [(:info "parametric_")
-          (kw ("param" . "etric"))])
-
-        (set-pm3d-clause
-         ["pm3d"
-          (many
-           (either
-            ["at" name]
-            ["interpolate" number "," number]
-            (either "scansautomatic" "scansforward" "scansbackward" "depthorder")
-            ["flush" (either "begin" "center" "end")]
-            (either "ftriangles" "noftriangles")
-            (either "clip1in" "clip4in")
-            ["corners2color"
-             (either "mean" "geomean" "median" "min" "max" "c1" "c2" "c3" "c4")]
-            ["hidden3d" number]
-            "nohidden3d"
-            "implicit" "explicit" "map"))])
-
-        (set-palette-clause
-         ["palette"
-          (many
-           (either
-            "gray" "color"
-            ["gamma" number]
-            ["rgbformulae" number "," number "," number]
-            "defined"                  ; not complete
-            ["functions" expression "," expression "," expression]
-            ["file" string (many datafile-modifier)]
-            "RGB" "HSV" "CMY" "YIQ" "XYZ"
-            "positive" "negative"
-            "nops_allcF" "ps_allcF"
-            ["maxcolors" number]))])
-
-        (set-pointsize-clause pointsize-spec)
-
-        (set-polar-clause "polar")
-
-        (set-print-clause
-         [(:info "print_")
-          "print"
-          (maybe string)])
-
-        (set-samples-clause
-         ["samples" expression (maybe "," expression)])
-
-        (set-size-clause
-         ["size"
-          (either
-           "square" "nosquare"
-           ["ratio" expression]
-           "noratio"
-           [expression "," expression])])
-
-        (set-style-clause
-         ["style"
-          (either style-arrow-clause style-data-clause style-fill-clause
-                  style-function-clause style-increment-clause
-                  style-line-clause style-circle-clause style-rectangle-clause)])
-
-        ;; begin subclauses of "set style ..."
-        (style-arrow-clause
-         [(:info "set_style_arrow")
-          "arrow"
-          number
-          (either
-           "default"
-           (many
-            (either "nohead" "head" "heads"
-                    "filled" "empty" "nofilled"
-                    "front" "back"
-                    ["size" dimension "," number (maybe "," number)]
-                    linestyle-spec)))])
-
-        (style-data-clause
-         [(:info "set_style_data")
-          "data" plotting-style])
-
-        (style-fill-clause
-         [(:info "set_style_fill")
-          "fill" fill-style])
-
-        (style-function-clause
-         [(:info "set_style_function")
-          "function" plotting-style])
-
-        (style-increment-clause
-         [(:info "set_style_increment")
-          "increment"
-          (either (kw ("d" . "efault")) (kw ("u" . "serstyles")))])
-
-        (style-line-clause
-         [(:info "set_style_line")
-          "line"
-          expression
-          (either
-           "default"
-           (many
-            (either
-             "palette"
-             [(kw ("linet" . "ype") "lt")
-              (either expression color-spec)]
-             [(kw ("linec" . "olor") "lc") color-spec]
-             [(either (kw ("linew" . "idth") "lw")
-                      (kw ("pointt" . "ype") "pt")
-                      (kw ("points" . "ize") "ps")
-                      (kw ("pointi" . "nterval") "pi"))
-              expression])))])
-
-        (style-circle-clause
-         [(:info "set_style_circle")
-          "circle" "radius" dimension])
-
-        (style-rectangle-clause
-         [(:info "set_style_rectangle")
-          "rectangle"
-          (many
-           (either
-            "front" "back"
-            [(kw ("linew" . "idth") "lw") expression]
-            [(kw "fillcolor" "fc") color-spec]
-            ["fs" expression]))])
-        ;; end of "set style ..." clauses
-
-        (set-surface-clause "surface")
-        
-        (set-table-clause ["table" (maybe string)])
-
-        (set-terminal-clause           ; not sure how to do this...
-         ["terminal" (maybe (either "push" "pop"))])
-
-        (set-termoption-clause
-         ["termoption"
-          (either
-           "enhanced" "noenhanced"
-           ["font" string]
-           "solid" "dashed"
-           [(kw "linewidth" "lw") expression])])
-
-        (set-tics-clause
-         ["tics"
-          (many
-           (either
-            "axis" "border" "mirror" "nomirror" "in" "out"
-            ["scale" (either "default" [expression (maybe "," expression)])]
-            [(either "rotate" "norotate") (maybe "by" expression)]
-            ["offset" expression] "nooffset"
-            ["format" string]
-            ["font" string]
-            textcolor-spec))])
-
-        (set-tics-clause-2
-         ["tics" (either "front" "back")])
-        
-        (set-xtics-clause
-         [(:info "xtics")
-          (either "xtics" "ytics" "ztics" "x2tics" "y2tics" "cbtics")
-          (many
-           (either
-            "axis" "border" "mirror" "nomirror" "in" "out"
-            ["scale" (either "default" [expression (maybe "," expression)])]
-            [(either "rotate" "norotate") (maybe "by" expression)]
-            ["offset" position] "nooffset"
-            "add" "autofreq"
-            ["(" (delimited-list [(maybe string) expression (maybe number)] ",") ")"]
-            ["format" string]
-            ["font" string]
-            "rangelimited"
-            textcolor-spec
-            (delimited-list expression ",")))])
-
-        (set-timestamp-clause
-         ["timestamp"
-          (maybe string)
-          (maybe (either "top" "bottom"))
-          (maybe (either "rotate" "norotate"))
-          (maybe "offset" position)
-          (maybe "font" string)])
-
-        (set-timefmt-clause
-         ["timefmt" string])
-
-        (set-title-clause
-         [(:info "title_")
-          "title" 
-          (maybe expression)
-          (many
-           (either
-            ["offset" position] 
-            ["font" string]
-            textcolor-spec
-            "enhanced" "noenhanced"))])
-
-        (set-view-clause
-         ["view"
-          (either
-           "map"
-           [(either "equal" "noequal") (maybe (either "xy" "xyz"))]
-           (delimited-list (maybe expression) ","))])
-
-        (set-data-clause
-         [(:info "xdata")
-          (either "xdata" "ydata" "zdata" "x2data" "y2data" "cbdata")
-          (maybe (either "time" "geographic"))])
-
-        (set-dtics-clause
-         [(:info "xdtics")
-          (either "xdtics" "ydtics" "zdtics" "x2dtics" "y2dtics" "cbdtics")])
-
-        (set-xlabel-clause
-         [(:info "xlabel")
-          (either (kw ("xlab" . "el")) (kw ("ylab" . "el"))
-                  (kw ("zlab" . "el")) (kw ("x2lab" . "el"))
-                  (kw ("y2lab" . "el")) (kw ("cblab" . "el")))
-          (maybe expression)
-          (many
-           (either
-            ["offset" position] 
-            ["font" string]
-            textcolor-spec
-            "enhanced" "noenhanced"))])
-        
-        (set-mtics-clause
-         [(:info "xmtics")
-          (either "xmtics" "ymtics" "zmtics" "x2mtics" "y2mtics" "cbmtics")])
-        
-        (set-range-clause
-         [(:info "xrange")
-          (either (kw ("xr" . "ange")) (kw ("yr" . "ange"))
-                   (kw ("x2r" . "ange")) (kw ("y2r" . "ange"))
-                  (kw ("zr" . "ange")) (kw ("tr" . "ange"))
-                  (kw ("ur" . "ange")) (kw ("vr" . "ange"))
-                  (kw ("rr" . "ange")) (kw ("cbr" . "ange")))
-          (either
-           "restore"
-           ["[" (maybe
-                 [(maybe axis-range-component) ":"
-                  (maybe axis-range-component)])
-            "]"
-            (many (either "reverse" "noreverse" "writeback" "nowriteback"))])])
-            
-        (set-xyplane-clause
-         ["xyplane" (either "at" "relative") expression])
-
-        (set-zero-clause
-         ["zero" expression])
-
-        (set-zeroaxis-clause
-         [(:info "zeroaxis")
-          (either "zeroaxis" "xzeroaxis" "x2zeroaxis" "yzeroaxis" "y2zeroaxis"
-                  "zzeroaxis")
-          (maybe linestyle-spec)])
-        
-
-;;; Other commands
-        (cd-command
-         ["cd" string])
-
-        (call-command
-         ["call" string (many expression)])
-
-        (simple-command
-         (either "clear" "exit" "quit" "pwd" "refresh" "reread" "reset"
-                 "shell"))
-
-        (eval-command
-         ["eval" expression])
-
-        (load-command
-         ["load" string])
-
-        (lower-raise-command [(either "lower" "raise") number])
-
-        (pause-command
-         ["pause"
-          (either
-           expression
-           ["mouse" (maybe endcondition (maybe "," endcondition))])
-          string])
-
-        (endcondition (either "keypress" "button1" "button2" "button3" "close" "any"))
-
-        (save-command
-         ["save"
-          (either "functions" "variables" "terminal" "set")
-          string])
-
-        (system-command
-         ["system" string])
-
-        (test-command
-         ["test"
-          (either
-           "terminal"
-           ["palette"
-            (maybe
-             (either "rgb" "rbg" "grb" "gbr" "brg" "bgr"))])])
-
-        (undefine-command
-         ["undefine" (many name)])
-
-        (update-command
-         ["update" string (maybe string)]))
-       
-       ;; This is the start symbol
-       'command))))
-
-\f
-;; The following macros are used for debugging; load
-;; gnuplot-debug-context.el and then re-load this file to enable
-;; them. For normal use, they compile to no-ops.
-(eval-when-compile
-  (when (not (featurep 'gnuplot-debug-context))
-    (defmacro with-gnuplot-trace-buffer (&rest args) "No-op." '(progn nil))
-    (defmacro gnuplot-trace (&rest args) "No-op." '(progn nil))
-    (defmacro gnuplot-debug (&rest args) "No-op." '(progn nil))))
-
-
-\f
-;;;; Variables to be set via pattern matching
-(defvar gnuplot-completions nil
-  "List of possible gnuplot-mode completions at point.
-This is filled in by `gnuplot-match-pattern' when it reaches the
-token before point.")
-
-(defvar gnuplot-info-at-point nil
-  "Relevant page of the Gnuplot info manual for the construction at point.
-
-Set by `gnuplot-match-pattern' using information from
-`gnuplot-compiled-grammar'. `gnuplot-match-pattern' pushes ElDoc
-and info strings onto the stack as it runs, and scans the stack
-for the topmost entry when it reaches the token at point.")
-
-(defvar gnuplot-eldoc nil
-  "ElDoc documentation string for the Gnuplot construction at point.
-
-Set by `gnuplot-match-pattern'. See also `gnuplot-info-at-point'.")
-
-(defvar gnuplot-captures nil
-  "Alist of named capture groups for gnuplot-mode completion code.
-
-Each entry is of the form (NAME BEGIN END), where NAME is the
-name specified in the (capture NAME PATTERN) form in the
-`gnuplot-compiled-grammar' source, BEGIN is the tail of the token
-list beginning the capture group, and END is the tail of the
-token list just after the end of the capture group.")
-
-\f
-;;;; The pattern matching machine 
-(defun gnuplot-match-pattern (instructions tokens completing-p
-                                  &optional start-symbol)
-  "Parse TOKENS, setting completions, info and ElDoc information.
-
-This function parses TOKENS by simulating a stack machine with
-unlimited backtracking. If COMPLETING-P is non-nil, it stops
-before the token at point and collects a list of the next tokens
-that it would accept in `gnuplot-completions'. If COMPLETING-P is
-nil, it parses up to the token at point and sets `gnuplot-eldoc'
-and `gnuplot-info-at-point' based on the contents of the stack
-there."
-  (catch 'return
-    (let ((pc 0)                       ; Program counter
-         ;; Stack of return addresses (return PC), eldoc strings
-         ;; (eldoc STRING) and info pages (info STRING)
-         (stack '())
-         ;; Stack of backtracking records:
-         ;; ((STACK TOKENS RESUME-PC CAPTURES PROGRESS) ...)
-         (backtrack '())
-         ;; Match failure flag, set to `t' to cause backtracking
-         (fail nil)
-         ;; Flag set by JUMP and CALL instructions to stop PC advance
-         (jump nil)
-         ;; Record of progress made within (many ...) loops, an alist
-         ;; of conses (pc . tokens)
-         (progress '()))
-
-      (with-gnuplot-trace-buffer (erase-buffer))
-
-      (when start-symbol               ; HACK FIXME
-       (let ((look-for `(label ,start-symbol)))
-         (while (not (equal (aref instructions pc) look-for))
-           (incf pc))
-         (incf pc)))
-
-      (setq gnuplot-completions nil
-           gnuplot-eldoc nil
-           gnuplot-info-at-point nil
-           gnuplot-captures nil)
-
-      (flet ((advance
-             ()
-             (pop tokens)
-             (if (and (null tokens) (not completing-p))
-                 (gnuplot-scan-stack stack tokens)))
-            (fail () (setq fail t)))
-       
-       ;; Main loop
-       (while t
-         (let* ((inst (aref instructions pc))
-                (opcode (car inst))
-                (token (car tokens))
-                (end-of-tokens (null tokens)))
-           (gnuplot-trace "%s\t%s\t%s\n" pc inst (and token (gnuplot-token-id token)))
-           
-           (case opcode
-             ;; (literal LITERAL NO-COMPLETE)
-             ((literal)
-              (let ((expect (cadr inst))
-                    (no-complete (caddr inst)))
-                (cond (end-of-tokens
-                       (unless no-complete
-                         (gnuplot-trace "\tpushing \"%s\" to completions\n" expect)
-                         (push expect gnuplot-completions))
-                       (fail))
-                      
-                      ((not (equal (gnuplot-token-id token) expect))
-                       (fail))
-
-                      ;; otherwise succeed
-                      (t (advance)))))
-
-             ;; (token-type TYPE)
-             ((token-type)
-              (let ((expect (cadr inst)))
-                (if (or end-of-tokens
-                        (not (eq (gnuplot-token-type token) expect)))
-                    (fail)
-                  (advance))))
-
-             ;; (keyword REGEXP NAME): match any token whose ID
-             ;; regexp-matches REGEXP, use NAME for completions
-             ((keyword)
-              (let ((regexp (cadr inst))
-                    (name (caddr inst)))
-                (cond (end-of-tokens
-                       (gnuplot-trace "\tpushing \"%s\" to completions\n" name)
-                       (push name gnuplot-completions)
-                       (fail))
-                      
-                      ((not (string-match-p regexp (gnuplot-token-id token)))
-                       (fail))
-
-                      ;; otherwise succeed
-                      (t
-                       (setf (gnuplot-token-id token) name)
-                       (advance)))))
-
-             ;; (any): match any token
-             ((any)
-              (if end-of-tokens
-                  (fail)
-                (advance)))
-             
-             ;; (jump LOCATION): jump to instruction at LOCATION
-             ((jump)
-              (let ((location (cadr inst)))
-                (setq jump location)))
-
-             ;; (call LOCATION): push the next instruction as a
-             ;; return location and jump
-             ((call)
-              (let ((location (cadr inst)))
-                (push `(return ,(+ pc 1)) stack)
-                (setq jump location)))
-
-             ;; (return): return to address at topmost RETURN record on
-             ;; stack, or stop matching and return if stack is empty
-             ((return)
-              (while (and stack
-                          (not (eq (caar stack) 'return)))
-                (pop stack))
-              (if (not stack)
-                  ;; Successful match
-                  (throw 'return (list tokens))
-                ;; Otherwise, return to caller
-                (let* ((r (pop stack))
-                       (r-pc (cadr r)))
-                  (setq jump r-pc))))
-
-             ;; (choice LOCATION): push LOCATION onto the stack of
-             ;; backtracking points and continue at next instruction
-             ((choice)
-              (let ((location (cadr inst)))
-                (push `(,stack ,tokens ,location ,gnuplot-captures
-                               ,progress)
-                      backtrack)))
-
-             ;; (commit LOCATION): discard most recent backtrack point
-             ;; and jump to LOCATION
-             ((commit)
-              (let ((location (cadr inst)))
-                (if (not backtrack)
-                    (error "no more backtrack points in commit"))
-                (pop backtrack)
-                (setq jump location)))
-
-             ;; (fail): force this match to fail, going back to most
-             ;; recent backtrack point
-             ((fail)
-              (fail))
-
-             ;; (assert): run Lisp code and fail if it returns NIL
-             ((assert)
-              (let ((form (cadr inst)))
-                (if (not (eval form)) (fail))))
-
-             ;; (push TYPE VALUE): push an info page or eldoc string
-             ;; onto the stack
-             ((push)
-              (let* ((type (cadr inst))
-                     (value (caddr inst)))
-                (push `(,type ,value ,tokens) stack)))
-
-             ;; (pop TYPE): pop something off the stack
-             ((pop)
-              (let ((type (cadr inst)))
-                (if (not (and stack
-                              (eq (caar stack) type)))
-                    (error "Expected a %s on the stack but found %s" type stack))
-                (pop stack)))
-
-             ;; (save-start NAME): save current token pointer as
-             ;; beginning of capture group NAME
-             ((save-start)
-              (let ((name (cadr inst)))
-                (push `(,name ,tokens nil) gnuplot-captures)))
-
-             ;; (save-end NAME): save current token pointer as end of
-             ;; capture group NAME
-             ((save-end)
-              (let* ((name (cadr inst))
-                     (record (assoc name gnuplot-captures)))
-                (if (not record)
-                    (error "gnuplot-match-tokens: no open capture group named %s" name)
-                  (setf (caddr record) tokens)
-                  (gnuplot-debug (gnuplot-dump-captures)))))
-
-             ;; (check-progress): make sure not stuck in an infinite loop
-             ((check-progress)
-              (let ((prev-progress (cdr (assoc pc progress))))
-                (if (and prev-progress (eq prev-progress tokens))
-                    (fail)
-                  (push (cons pc tokens) progress))))
-
-             (t
-              (error "bad instruction: %s" inst)))
-
-           ;; Increment PC or jump
-           (setq pc (or jump (1+ pc))
-                 jump nil)
-                 
-           ;; Backtrack on failure
-           (when fail
-             (if (not backtrack)       ; Out of backtracking stack: failed match
-                 (throw 'return nil)
-               (gnuplot-trace "\t*fail*\t%s\n" (length backtrack))
-               (gnuplot-debug (gnuplot-dump-backtrack backtrack))
-               ;; If we got as far as token-at-point before failing,
-               ;; scan the stack for eldoc and info strings
-               (when (and end-of-tokens (not completing-p))
-                 (gnuplot-scan-stack stack tokens))
-               
-               (destructuring-bind
-                   (bt-stack bt-tokens bt-pc bt-captures bt-progress)
-                   (pop backtrack)
-                 (setq stack bt-stack
-                       tokens bt-tokens
-                       pc bt-pc
-                       gnuplot-captures bt-captures
-                       progress bt-progress
-                       fail nil)
-                 (gnuplot-debug (gnuplot-dump-progress progress)))))))))))
-
-(defun gnuplot-scan-stack (stack tokens)
-  "Scan STACK for the most recently pushed eldoc and info strings"
-  (gnuplot-trace "\t* scanning stack *\n")
-  (gnuplot-debug (gnuplot-backtrace))
-  (gnuplot-debug (gnuplot-dump-captures))
-
-  (catch 'no-scan
-    (while (and stack
-               (not (and gnuplot-info-at-point gnuplot-eldoc)))
-      (let* ((item (car stack))
-            (type (car item))
-            (position (caddr item))) ; must progress by at least one token
-       (if (and (memq type '(info eldoc no-scan))
-                (not (eq position tokens)))
-           (case type
-             ((no-scan)
-              (throw 'no-scan nil))
-
-             ((info)
-              (when (not gnuplot-info-at-point)
-                (let ((info (cadr item)))
-                  (setq gnuplot-info-at-point
-                        (cond
-                         ((eq info 'first-token)
-                          (gnuplot-token-id (car position)))
-                         ((functionp info) (funcall info))
-                         (t info)))
-                  (when gnuplot-info-at-point
-                    (gnuplot-trace "\tset info to \"%s\"\n" gnuplot-info-at-point)
-                    (when (and (not gnuplot-eldoc) gnuplot-eldoc-hash)
-                       (let ((eldoc
-                              (car (gethash gnuplot-info-at-point gnuplot-eldoc-hash))))
-                         (when eldoc
-                          (setq gnuplot-eldoc eldoc)
-                          (gnuplot-trace "\tand set eldoc to \"%s\"\n" eldoc))))))))
-
-             ((eldoc)
-              (when (not gnuplot-eldoc)
-                (let ((eldoc (cadr item)))
-                  (setq gnuplot-eldoc
-                        (if (functionp eldoc) (funcall eldoc) eldoc))
-                  (gnuplot-trace "\tset eldoc to \"%s\"\n" gnuplot-eldoc)))))))
-      (pop stack))))
-
-(defun gnuplot-capture-group (name)
-  "Return capture group NAME from the most recent parse, as a list of tokens."
-  (let ((record (assoc name gnuplot-captures)))
-    (if (not record) nil
-      (let ((begin (cadr record))
-           (end (caddr record))
-           (accum '()))
-       (while (and begin (not (eq begin end)))
-         (push (pop begin) accum))
-       (nreverse accum)))))
-
-(defun gnuplot-capture-group->string (name)
-  (let ((tokens (gnuplot-capture-group name)))
-    (and tokens
-        (mapconcat 'gnuplot-token-id tokens " "))))
-
-\f
-;;; Interface to the matching machine
-(defun gnuplot-parse-at-point (completing-p)
-  (let ((tokens (gnuplot-tokenize completing-p)))
-    (gnuplot-match-pattern gnuplot-compiled-grammar tokens completing-p)))
-
-;; Completions
-(defun gnuplot-completions ()
-  (gnuplot-parse-at-point t)
-  (if (featurep 'xemacs)                ; Need an alist
-      (mapcar (lambda (s) (cons s nil)) gnuplot-completions)
-    gnuplot-completions))
-
-(defun gnuplot-context-completion-at-point ()
-  "Return completions of keyword preceding point, using context."
-  (let* ((end (point))
-        (beg
-         (save-excursion
-           (skip-syntax-backward "w_" (gnuplot-point-at-beginning-of-command))
-           (point)))
-        (word nil)
-        (completions (gnuplot-completions)))
-    
-    (setq word (buffer-substring beg end)
-          completions (all-completions word completions))
-
-    (if completions
-       (list beg end completions)
-      (if (not (equal "" word))
-          (message "No gnuplot keywords complete '%s'" word)
-        (message "No completions at point"))
-      nil)))
-
-;; Eldoc help
-(defun gnuplot-eldoc-function ()
-  "Return the ElDoc string for the Gnuplot construction at point."
-  (gnuplot-parse-at-point nil)  
-  gnuplot-eldoc)
-
-(defun gnuplot-help-function ()
-  "Pop up the extended documentation for the construction at point."
-  (interactive)
-  (gnuplot-parse-at-point nil)
-  (if (and gnuplot-info-at-point gnuplot-eldoc-hash)
-      (let ((eldoc
-            (cadr (gethash gnuplot-info-at-point gnuplot-eldoc-hash))))
-       (if eldoc (message eldoc)))))
-
-;; Info lookup
-(defun gnuplot-info-at-point (&optional query)
-  "Open the relevant gnuplot info page for the construction at point."
-  (interactive "P")
-  (setq gnuplot-info-at-point nil)
-  (unless query
-    (gnuplot-parse-at-point nil))
-  (if (or query (not gnuplot-info-at-point))
-      (let ((info
-            (info-lookup-interactive-arguments 'symbol)))
-       (setq gnuplot-info-at-point (car info))))
-  (when gnuplot-info-at-point
-    (gnuplot--find-info-node gnuplot-info-at-point)))
-
-(defun gnuplot--find-info-node (node)
-  (save-window-excursion
-    (if (>= emacs-major-version 23)
-        (info (format "(gnuplot)%s" node))
-      (info)
-      (Info-find-node "gnuplot" node)))
-  (gnuplot--adjust-info-display))
-
-\f
-;;; Some context-sensitive hacks 
-
-;; ElDoc strings for "using" specs, which depend on other information
-;; from the parsed command
-
-(defvar gnuplot-using-eldoc
-  '(("boxerrorbars" . "x:y:ydelta{:xdelta} | x:y:ylow:yhigh{:xdelta}")
-    ("boxes" . "x:y{:x_width}")
-    ("boxxyerrorbars" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh")
-    ("candlesticks" . "x:box_min:whisker_min:whisker_high:box_high | date:open:low:high:close")
-    ("circles" . "x:y:radius")
-    ("dots" . "x{:y{:z}}")
-    ("filledcurves" . "x:y | x:y1:y2")
-    ("financebars" . "date:open:low:high:close")
-    ("fsteps" . "y | x:y")
-    ("histeps" . "y | x:y")
-    ("histograms" . "y:yerr | y:ymin:ymax")
-    ("image" . "x:y:value")
-    ("rgbimage" . "x:y:r:g:b")
-    ("rgbalpha" . "x:y:r:g:b:a")
-    ("impulses" . "x{:y{:z}}")
-    ("labels" . "x:y:string")
-    ("lines" . "y | x:y")
-    ("steps" . "y | x:y")
-    ("vectors" . "x:y:xdelta:ydelta")
-    ("xerrorbars" . "x:y:xdelta | x:y:xlow:xhigh")
-    ("xyerrorbars" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh")
-    ("yerrorbars" . "x:y:ydelta | x:y:ylow:yhigh")
-    ("yerrorlines" . "x:y:ydelta | x:y:ylow:yhigh")
-    ("xerrorlines" "x:y:xdelta | x:y:xlow:xhigh")
-    ("xyerrorlines" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh"))
-  "Alist of ElDoc strings for Gnuplot \"using\" clauses in \"plot\" commands.")
-
-(defvar gnuplot-using-3d-eldoc
-  (append
-   '(("fsteps" . "z | x:y:z")
-     ("histeps" . "z | x:y:z")
-     ("histograms" . "y:yerr | y:ymin:ymax")
-     ("image" . "x:y:z:value")
-     ("rgbimage" . "x:y:z:r:g:b")
-     ("rgbalpha" . "x:y:z:r:g:b:a")
-     ("labels" . "x:y:z:string")
-     ("lines" . "z | x:y:z")
-     ("steps" . "z | x:y:z")
-     ("vectors" . "x:y:z:xdelta:ydelta:zdelta"))
-   gnuplot-using-eldoc)
-  "Alist of ElDoc strings for Gnuplot \"using\" clauses in \"splot\" commands.")
-
-(defun gnuplot-find-using-eldoc ()
-  "Return ElDoc string for a Gnuplot \"using\" clause, based on plotting style.
-
-This will fail if the \"using\" clause comes before the \"with\"
-clause."
-  (let ((with-style (gnuplot-capture-group :with-style))
-       (3d-p (gnuplot-capture-group :splot-command))
-       (column-description nil))
-    (if with-style
-       (let ((with-style-string (gnuplot-token-id (car with-style))))
-         (setq column-description
-               (or (and 3d-p
-                        (cdr (assoc with-style-string gnuplot-using-3d-eldoc)))
-                   (cdr (assoc with-style-string gnuplot-using-eldoc))
-                   "<columns>"))))
-    (format "using %s {'format'}" column-description)))
-
-;;; Needed for correctly parsing plot commands
-(defun gnuplot-guess-parametric-p (&optional start)
-  "Guess whether the command beginning at START is in parametric mode.
-
-Searches backward in current buffer for an \"(un)set parametric\"
-command."
-  (save-excursion
-    (and start (goto-char start))
-    (catch 'result
-      (while
-         (search-backward-regexp "reset\\|set\\s-+parametric" (point-min) t)
-       (gnuplot-beginning-of-command)
-       (cond ((looking-at "reset\\|unset\\s-+parametric") (throw 'result nil))
-             ((looking-at "set\\s-+parametric") (throw 'result t))))
-      nil)))
-
-
-\f
-;;; All done!
-(provide 'gnuplot-context)
-
-;;; gnuplot-context.el ends here
diff --git a/elpa/gnuplot-20191212.1801/gnuplot-gui.el b/elpa/gnuplot-20191212.1801/gnuplot-gui.el
deleted file mode 100644 (file)
index 02960b0..0000000
+++ /dev/null
@@ -1,1748 +0,0 @@
-;;;; gnuplot-gui.el -- GUI interface to setting options in gnuplot-mode
-
-;; Copyright (C) 1998-2000 Bruce Ravel
-
-;; Author:     Bruce Ravel <ravelNOSPAMphys.washington.edu>
-;; Maintainer: Bruce Ravel <ravelNOSPAMphys.washington.edu>
-;; Created:    19 December 1998
-;; Updated:    16 November 2000
-;; Version:    (same as gnuplot.el)
-;; Keywords:   gnuplot, plotting, interactive, GUI
-
-;; This file is not part of GNU Emacs.
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
-;;
-;; This lisp script is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-;;
-;; Permission is granted to distribute copies of this lisp script
-;; provided the copyright notice and this permission are preserved in
-;; all copies.
-;;
-;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; send bug reports to the authors (ravelNOSPAMphys.washington.edu)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;
-;;; Commentary:
-;;
-;; This file provides a graphical user interface to setting arguments
-;; to gnuplot commands.  Positioning point near a command and invoking
-;; `gnuplot-gui-set-options-and-insert' (C-c C-c or shift-mouse-2)
-;; will pop open a frame with widgets for setting the various
-;; arguments appropriate the the item that was near point.  The goal
-;; is to provide point-and-click functionality to gnuplot-mode.
-;;
-;; gnuplot-gui is designed for gnuplot 3.7, but since much of 3.7 is
-;; backward compatible to 3.5, it will work well for that version
-;; also.
-;;
-;; gnuplot-gui.el was developed using Emacs 19.34 and is known to work
-;; on Emacs 20.x and XEmacs 20.x.  I do not know what is the earliest
-;; version for which it will work, but I make no guarantees for
-;; versions before 19.34.  Note that this makes heavy use of the
-;; widget package, so this will not work on Emacs 19.34 unless you
-;; install the widget package separately.
-;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;
-;;; To do:
-;;
-;; Widgets I need:
-;; -- 'position: two or three comma separated numbers used to denote a
-;;               position or a tic start/end/increment (see arrow,
-;;               need a prefix)
-;; -- 'modifier: colon separated fields used for datafile modifiers
-;;
-;; command types which are currently unsupported or contain mistakes
-;; -- unsupported: cntrparam
-;; -- plot, splot, fit: rather lame
-;; -- label: position information missing
-;; -- label: font string handled in overly simple manner
-;; -- hidden3d: not really suited to 'list, but all options are exclusive...
-;; -- pointstyle argument to "set label"
-;;
-;; overall:
-;; -- continuation lines (ugh!)
-;; -- multiple frames end up displaying same window after setting options
-;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; Code:
-
-(require 'gnuplot)
-(eval-and-compile
-  (condition-case ()
-      (progn
-       (require 'widget)
-       (require 'wid-edit))
-    (error nil)))
-(require 'cl)
-(eval-when-compile                     ; suppress some compiler warnings
-  (defvar gnuplot-xemacs-p nil)
-  (defvar gnuplot-quote-character nil)
-  (defvar gnuplot-info-display nil)
-  (defvar gnuplot-mode-map nil))
-
-;; (eval-when-compile
-;;   (require 'wid-edit))
-
-(eval-and-compile                      ; I need this!
-  (if (fboundp 'split-string)
-      ()
-    (defun split-string (string &optional pattern)
-      "Return a list of substrings of STRING which are separated by PATTERN.
-If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
-      (or pattern
-         (setq pattern "[ \f\t\n\r\v]+"))
-      ;; The FSF version of this function takes care not to cons in case
-      ;; of infloop.  Maybe we should synch?
-      (let (parts (start 0))
-       (while (string-match pattern string start)
-         (setq parts (cons (substring string start (match-beginning 0)) parts)
-               start (match-end 0)))
-       (nreverse (cons (substring string start) parts)))) ))
-
-
-\f
-;;; customizable variables
-
-(defgroup gnuplot-gui nil
-  "Graphical interface to setting arguments in gnuplot scrips."
-  :prefix "gnuplot-gui-"
-  :group 'gnuplot)
-
-(defcustom gnuplot-gui-popup-flag nil
-  "*Non-nil means to open arguments pop-ups automatically.
-This would be done after menu insertion of Gnuplot commands."
-  :group 'gnuplot-gui
-  :type 'boolean)
-
-(defvar gnuplot-gui-frame nil
-  "Frame used to hold the buffer for setting options.")
-(defcustom gnuplot-gui-frame-plist
-  '(height 18 width 65 border-width 0
-          user-position t top 150 left 150
-          internal-border-width 0 unsplittable t
-          default-toolbar-visible-p nil has-modeline-p nil
-          menubar-visible-p nil)
-  "Frame plist for the input run-time display frame in XEmacs."
-  :type '(repeat (group :inline t
-                       (symbol :tag "Property")
-                       (sexp :tag "Value")))
-  :group 'gnuplot-gui)
-(defcustom gnuplot-gui-frame-parameters
-  '((height . 18)
-    (width . 65)
-    (user-position . t)
-    (top . 150)
-    (left . 150)
-    (border-width . 0)
-    (menu-bar-lines . 0)
-    (unsplittable . t))
-  "Frame parameters for the input run-time display frame in Emacs."
-  :group 'gnuplot-gui
-  :type '(repeat (sexp :tag "Parameter:")))
-
-(defcustom gnuplot-gui-fontname-list
-  '(" " "\"Helvetica\"" "\"Times-Roman\"")
-  "List of known font names.
-These *must* be quoted, like so \"\\\"Helvetica\\\"\".  This allows
-for fonts with names like \"\\\"Arial Bold Italic\\\"\" to be treated
-as single entries in the menu-buttons.  And it is really important that
-the first entry in the list be a blank string."
-  :group 'gnuplot-gui
-  :type '(repeat (string :tag "Font name:")))
-
-;; some global variables
-(defvar gnuplot-current-frame nil)
-(defvar gnuplot-current-buffer nil)
-(defvar gnuplot-current-buffer-point nil)
-(defvar gnuplot-gui-alist nil)
-(defvar gnuplot-gui-current-string nil)
-
-\f
-;;; various tools for handling data structures and text in the buffer
-
-;; tools for accessing the elements of the lists in `gnuplot-gui-all-types'
-(defsubst gnuplot-gui-type-tag     (obj) (elt obj 0))
-(defsubst gnuplot-gui-type-symbol  (obj) (elt obj 1))
-(defsubst gnuplot-gui-type-default (obj) (elt obj 2))
-(defsubst gnuplot-gui-type-prefix  (obj) (elt obj 3)) ; also 'range seperator
-(defsubst gnuplot-gui-type-fourth  (obj) (elt obj 4))
-(defsubst gnuplot-gui-type-list    (obj) (cddr obj))
-
-(defun gnuplot-this-word ()
-  "Return the word under point."
-  (let ((begin (save-excursion (beginning-of-line) (point-marker)))
-       (end   (save-excursion (end-of-line)       (point-marker))))
-    (save-excursion
-      (or (looking-at "\\<") (= (current-column) 0) (forward-word -1))
-      (if (> (point) begin) (setq begin (point-marker)))
-      (forward-word 1)
-      (if (> (point) end) (goto-char end))
-      (buffer-substring-no-properties begin (point)))))
-
-
-\f
-;;; data structures containing regarding options in Gnuplot 3.7
-
-;; various constants used for options that take the same sorts of arguments
-(defconst gnuplot-gui-mtics-list
-  '(("FREQUENCY"   'number " ")
-    ("DEFAULT"     'list " " "default")))
-(defconst gnuplot-gui-data-list
-  '(("DATA TYPE"   'list " " "time")))
-(defconst gnuplot-gui-label-list
-  '(("LABEL"       'string " ")
-    ("POSITION"    'position " " "" 2)
-    ("FONTNAME"    'list " " gnuplot-gui-fontname-list)
-    ("FONTSIZE"    'fontsize " ")))
-(defconst gnuplot-gui-range-list
-  '(("RANGE"       'range (" " . " ") ":")
-    ("REVERSE"     'list " " "reverse" "noreverse")
-    ("WRITEBACK"   'list " " "writeback" "nowriteback")))
-(defconst gnuplot-gui-tics-list
-  '(("WHERE"       'list " " "axis" "border")
-    ("MIRROR"      'list " " "mirror" "nomirror")
-    ("ROTATE"      'list " " "rotate" "norotate")
-    ("SERIES"      'position " " "" 3)
-    ("LABEL ARRAY" 'labels () )))
-(defconst gnuplot-gui-zeroaxis-list
-  '(("LINETYPE"    'number " ")))
-
-(defvar gnuplot-gui-terminal-types nil
-  "Associated list of terminal descriptions.
-See the doc-string for `gnuplot-gui-all-types'.")
-(setq gnuplot-gui-terminal-types
-      (list (cons "aifm"
-                 '(("COLOR"     'list " " "monochrome" "gray" "color")
-                   ("FONTNAME"  'list " " gnuplot-gui-fontname-list)
-                   ("FONTSIZE"  'fontsize " ")))
-           (cons "cgm"
-                 '(("MODE"      'list   " " "landscape" "portrait" "default")
-                   ("COLOR"     'list   " " "color" "monochrome")
-                   ("ROTATION"  'list   " " "rotate" "norotate")
-                   ("WIDTH"     'number " " "width")
-                   ("LINEWIDTH" 'number " " "linewidth")
-                   ("FONTNAME"  'list   " " "\"Arial\"" "\"Arial Italic\""
-                    "\"Arial Bold\"" "\"Arial Bold Italic\""
-                    "\"Times Roman\"" "\"Times Roman Italic\""
-                    "\"Times Roman Bold\"" "\"Times Roman Bold Italic\""
-                    "\"Helvetica\"" "\"Roman\"")
-                   ("FONTSIZE"  'fontsize " ")))
-           (cons "corel"
-                 '(("COLOR"            'list " " "default" "color" "monochrome")
-                   ("FONTNAME"         'list " " "\"SwitzerlandLight\""
-                    "\"Helvetica\"" "\"Times-Roman\"")
-                   ("FONTSIZE "        'number " ")
-                   ("X-SIZE   "        'number " ")
-                   ("Y-SIZE   "        'number " ")
-                   ("LINEWIDTH"        'number " ")))
-           (cons "dumb"
-                 '(("LINEFEED"         'list   " " "feed" "nofeed")
-                   ("X-SIZE"           'number " ")
-                   ("Y-SIZE"           'number " ")))
-           (cons "emf"
-                 '(("COLOR"            'list " " "color" "monochrome")
-                   ("LINE"             'list " " "solid" "dashed")
-                   ("FONTNAME"         'string " ")
-                   ("FONTSIZE"         'number " ")))
-           (cons "emtex"
-                 '(("FONTNAME"         'list     " " "courier" "roman")
-                   ("FONTSIZE"         'fontsize " ")))
-           (cons "fig"
-                 '(("COLOR"            'list   " " "color" "monochrome")
-                   ("FRAMESIZE"        'list   " " "small" "big")
-                   ("POINTSMAX"        'number " " "pointsmax")
-                   ("ORIENTATION"      'list   " " "landscape" "portrait")
-                   ("UNITS"            'list   " " "metric" "inches")
-                   ("FONT SIZE"        'number " " "fontsize")
-                   ("SIZE"             'pair   (" " . " ") "size")
-                   ("LINE THICKNESS"   'number " " "thickness")
-                   ("LAYER DEPTH"      'number " " "depth")))
-           (cons "hp500c"
-                 '(("RESOLUTION"       'list " " "75" "100" "150" "300")
-                   ("COMPRESSION"      'list " " "rle" "tiff")))
-           (cons "hpgl"
-                 '(("PENS"             'number " ")
-                   ("EJECT"            'list   " " "eject")))
-           (cons "hpdj"
-                 '(("RESOLUTION"       'list " " "75" "100" "150" "300")))
-           (cons "hpljii"
-                 '(("RESOLUTION"       'list " " "75" "100" "150" "300")))
-           (cons "hppj"
-                 '(("FONT"             'list " " "FNT9X17" "FNT5X9" "FNT13X25")))
-           (cons "imagen"
-                 '(("FONT SIZE"        'number " ")
-                   ("LAYOUT"           'list   " " "portrait" "landscape")
-                   ("NUMBER OF GRAPHS" 'range (" " . " ") ",")))
-           (cons "gpic"
-                 '(("X ORIGIN"         'number " ")
-                   ("Y ORIGIN"         'number " " ",")))
-           (cons "latex"
-                 '(("FONTNAME"         'list " " "courier" "roman")
-                   ("FONTSIZE"         'fontsize " ")))
-           (cons "mif"
-                 '(("COLOUR"           'list " " "colour" "monochrome")
-                   ("LINETYPE"         'list " " "polyline" "vectors")))
-           (cons "nec-cp6"
-                 '(("MODE"             'list " " "monochrome" "colour" "draft")))
-           (cons "pbm"
-                 '(("SIZE"      'list " " "small" "medium" "large")
-                   ("COLOR"     'list " " "monochrome" "gray" "color")))
-           (cons "pcl5L"
-                 '(("MODE"      'list " " "landscape" "portrait")
-                   ("FONTNAME"  'list " " "stick" "univers" "cg_times")
-                   ("FONTSIZE"  'fontsize " ")))
-           (cons "png"
-                 '(("SIZE"      'list " " "small" "medium" "large")
-                   ("COLOR"     'list " " "monochrome" "gray" "color")))
-           (cons "postscript"
-                 '(("MODE"      'list " " "landscape" "portrait" "eps" "default")
-                   ("ENHANCED"  'list " " "enhanced" "noenhanced")
-                   ("COLOR"     'list " " "color" "monochrome")
-                   ("SOLID"     'list " " "solid" "dashed")
-                   ("DUPLEXING" 'list " " "defaultplex" "simplex" "duplex")
-                   ("FONTNAME"  'list " " gnuplot-gui-fontname-list)
-                   ("FONTSIZE"  'fontsize " ")))
-           (cons "pslatex"
-                 '(("COLOR"     'list " " "monochrome" "color")
-                   ("DASHED"    'list " " "dashed")
-                   ("ROTATION"  'list " " "rotate" "norotate")
-                   ("AUXFILE"   'list " " "auxfile")))
-           (cons "pstex"
-                 '(("COLOR"     'list " " "monochrome" "color")
-                   ("DASHED"    'list " " "dashed")
-                   ("ROTATION"  'list " " "rotate" "norotate")
-                   ("AUXFILE"   'list " " "auxfile")))
-           (cons "pstricks"
-                 '(("HACK TEXT"        'list " " "hacktext" "nohacktext")
-                   ("PLOT SCALING"     'list " " "nounit" "unit")))
-           (cons "regis"
-                 '(("COLOR DEPTH"      'list "4" "16")))
-           (cons "tgif"
-                 '(("LAYOUT"           'list   " " "portrait" "landscape")
-                   ("NUMBER OF GRAPHS" 'range (" " . " ") ",")
-                   ("LINE TYPE"        'list " " "solid" "dashed")
-                   ("FONTNAME"         'list " " gnuplot-gui-fontname-list)
-                   ("FONTSIZE"         'fontsize " ")))
-           (cons "tpic"
-                 '(("POINTSIZE"        'number " ")
-                   ("LINEWIDTH"        'number " ")
-                   ("INTERVAL "        'number " ")))
-           (cons "vgagl"               ; for pm3d patch (also persist, raise in x11) <MT>
-                 '(("BACKGROUND"       'position  " " "background" 3)
-                   ("INTERPOLATION"    'list " " "uniform" "interpolate")
-                   ("DUMP"             'file " ")
-                   ("MODE"             'string  " " "")))
-           (cons "x11"
-                 '(("RESET"            'list " " "reset")
-                   ("TERMINAL NUMBER"  'number " ")
-                   ("PERSIST"          'list " " "persist" "nopersist")
-                   ("RAISE"            'list " " "raise" "noraise"))) ))
-
-(defvar gnuplot-gui-terminal-list nil)
-(setq gnuplot-gui-terminal-list
-      (append (list " ") (mapcar 'car gnuplot-gui-terminal-types)))
-
-(defvar gnuplot-gui-set-types nil
-  "Associated list of set option descriptions.
-See the doc-string for `gnuplot-gui-all-types'.")
-(setq gnuplot-gui-set-types
-      (list (cons "angles"
-                 '(("UNITS" 'list " " "degrees" "radians")))
-           (cons "arrow"
-                 '(("TAG"       'tag " ")
-                   ("FROM"      'position " " "from" 3)
-                   ("TO"        'position " " "to" 3)
-                   ("HEAD"      'list " " "head" "nohead")
-                   ("LINESTYLE" 'number " " "ls")
-                   ("LINETYPE " 'number " " "lt")
-                   ("LINEWIDTH" 'number " " "lw")))
-           (cons "noarrow"
-                 '(("TAG" 'tag " ")))
-           (cons "autoscale"
-                 '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
-                    "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
-                    "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
-           (cons "noautoscale"
-                 '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
-                    "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
-                    "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
-           (cons "bar"
-                 '(("SIZE" 'list " " "small" "large")))
-           (cons "border"
-                 '(("BORDER CODE" 'number " ")
-                   ("LINE STYLE"  'list   " " "lines"
-                    "dots" "points" "linespoints")
-                   ("LINESTYLE"   'number " " "ls")
-                   ("LINETYPE"    'number " " "lt")
-                   ("LINEWIDTH"   'number " " "lw")
-                   ))
-           (cons "boxwidth"
-                 '(("WIDTH" 'number " ")))
-           (cons "clabel"
-                 '(("FORMAT" 'format " ")))
-           (cons "clip"
-                 '(("CLIP TYPE" 'list " " "points" "one" "two")))
-           (cons "noclip"
-                 '(("CLIP TYPE" 'list " " "points" "one" "two")))
-           ;;(cons "cntrparam"
-               ;;  '(("INTERPOLATION" 'list " " "linear" "cubicspline" "bspline")
-               ;;    ("POINTS" 'number " " "points")
-               ;;    ("ORDER"  'number " " "order")))
-           (cons "contour"
-                 '(("WHERE"     'list " " "base" "surface" "both")))
-           (cons "dgrid3d"
-                  '(("ROW,COLUMN,NORM" 'position " " "" 3)))
-           (cons "encoding"
-                 '(("ENCODING" 'list " " "default" "iso_8859_1"
-                    "cp850" "cp437")))
-           (cons "format"
-                 '(("AXIS"   'list " " "x" "y" "z" "xy" "x2" "y2")
-                   ("FORMAT" 'format  " ")))
-           (cons "dummy"
-                 '(("VAR 1" 'string " " "")
-                   ("VAR 2" 'string " " ",")))
-           (cons "grid"
-                 '(("XTICS"  'list " " "xtics" "mxtics" "noxtics" "nomxtics")
-                   ("YTICS"  'list " " "ytics" "mytics" "noytics" "nomytics")
-                   ("ZTICS"  'list " " "ztics" "mztics" "noztics" "nomztics")
-                   ("X2TICS" 'list " " "x2tics" "mx2tics" "nox2tics" "nomx2tics")
-                   ("Y2TICS" 'list " " "y2tics" "my2tics" "noy2tics" "nomy2tics")
-                   ("POLAR"  'number " " "polar")
-                   ("MAJOR LINETYPE" 'number " ")
-                   ("MINOR LINETYPE" 'number " ")))
-           (cons "hidden3d"
-                 '(("ALGORITHM" 'list " " "defaults"
-                    "offset"
-                   "nooffset"
-                    ;;"trianglepattern  # bitpattern between 0 and 7"
-                   "trianglepattern 0" "trianglepattern 1"
-                    "trianglepattern 2" "trianglepattern 3"
-                    "trianglepattern 4" "trianglepattern 5"
-                    "trianglepattern 6" "trianglepattern 7"
-                    ;;"undefined        # level between 0 and 3"
-                   "undefined 0" "undefined 1" "undefined 2" "undefined 3"
-                   "noundefined" "altdiagonal" "noaltdiagonal"
-                   "bentover" "nobentover")))
-           (cons "historysize"
-                 '(("SIZE" 'number " ")))
-           (cons "isosamples"
-                 '(("ISO_U LINES" 'number " ")
-                   ("ISO_V LINES" 'number " " ",")))
-           (cons "key"
-                 '(("LOCATION"      'list " " "left" "right" "top" "bottom"
-                                          "outside" "below")
-                   ("POSITION"      'position  " " "" 3)
-                   ("JUSTIFICATION" 'list " " "Left" "Right")
-                   ("REVERSE"       'list " " "reverse" "noreverse")
-                   ("SAMPLE LENGTH" 'number " " "samplen")
-                   ("SPACING"       'number " " "spacing")
-                   ("WIDTH"         'number " " "width")
-                   ("TITLE"         'string " " "title ")
-                   ("BOX LINETYPE"  'number " " "box") ;; linetype data
-                   ("NOBOX"         'list   " " "nobox")))
-           (cons "label"
-                 '(("TAG" 'tag " ")
-                   ("LABEL TEXT" 'string " ")
-                   ("POSITION"   'position " " "at" 3)
-                   ;; first, second, graph, screen
-                   ("JUSTIFICATION" 'list " " "left" "right" "center")
-                   ("ROTATE"        'list " " "rotate" "norotate")
-                   ("FONT"          'string " " "font"))) ;; font "name,size"
-           (cons "nolabel"
-                 '(("TAG"        'tag " ")))
-           (cons "linestyle"
-                 '(("TAG      "  'tag " ")
-                   ("LINE STYLE" 'list " " "boxerrorbars" "boxes"
-                    "boxxyerrorbars" "candlesticks" "dots"
-                    "financebars" "fsteps" "histeps" "impulses"
-                    "lines" "linespoints" "points" "steps" "vector"
-                    "xerrorbars" "xyerrorbars" "yerrorbars")
-                   ("LINETYPE " 'number " " "lt")
-                   ("LINEWIDTH" 'number " " "lw")
-                   ("POINTTYPE" 'number " " "pt")
-                   ("POINTSIZE" 'number " " "ps")))
-           (cons "locale"
-                 '(("LOCALE" 'string " ")))
-           (cons "logscale"
-                 '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
-                    "x2" "y2")
-                   ("BASE" 'number " ")))
-           (cons "nologscale"
-                 '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
-                    "x2" "y2")))
-           (cons "mapping"
-                 '(("COORDINATE SYSTEM" 'list " " "cartesian" "spherical"
-                    "cylindrical")))
-                                       ; _margin
-           (cons "bmargin"
-                 '(("BOTTOM MARGIN" 'number " ")))
-           (cons "lmargin"
-                 '(("LEFT MARGIN"   'number " ")))
-           (cons "rmargin"
-                 '(("RIGHT MARGIN"  'number " ")))
-           (cons "tmargin"
-                 '(("TOP MARGIN"    'number " ")))
-
-           (cons "missing"
-                 '(("CHARACTER" 'string " " 1)))
-                                       ; m_tics
-           (cons "mxtics"  gnuplot-gui-mtics-list)
-           (cons "mytics"  gnuplot-gui-mtics-list)
-           (cons "mztics"  gnuplot-gui-mtics-list)
-           (cons "mx2tics" gnuplot-gui-mtics-list)
-           (cons "my2tics" gnuplot-gui-mtics-list)
-
-                                       ; pm3d additions <MT>
-           (cons "mouse"
-                 '(("DOUBLECLICK"     'number " " "doubleclick")
-                   ("ZOOM"            'list   " " "zoomcoordinates" "nozoomcoordinates")
-                   ("POLAR"           'list   " " "polarcoordinates" "nopolarcoordinates")
-                   ("FORMAT"          'string " " "format")
-                   ("CLIPBOARDFORMAT" 'string " " "clipboardformat")
-                   ("MOUSEFORMAT"     'string " " "mouseformat")
-                   ("LABELS"          'list   " " "labels" "nolabels")
-                   ("LABELOPTIONS"    'string " " "labeloptions")
-                   ("ZOOMJUMP"        'list   " " "zoomjump" "nozoomjump")
-                   ("VERBOSE"         'list   " " "verbose" "noverbose")))
-           (cons "palette"
-                 '(("COLOR"       'list     " " "gray" "color")
-                   ("RGBFORMULAE" 'position " " "rgbformulae" 3)
-                   ("PARITY"      'list     " " "positive" "negative")
-                   ("FORMULAE"    'list     " " "nops_allcF" "ps_allcF")
-                   ("MAXCOLORS"   'number   " ")
-                   ("COLOR_BOX"   'list     " " "nocb" "cbdefault" "cbuser")
-                   ("ORIENTATION" 'list     " " "cbvertical" "cbhorizontal")
-                   ("ORIGIN"      'position " " "origin" 2)
-                   ("SIZE"        'position " " "size" 2)
-                   ("BORDER"      'number   " ")
-                   ("NOBORDER"    'list     " " "bdefault" "noborder")))
-           (cons "pm3d"
-                 '(("AT"         'list*  " " "b" "s" "t" "bs" "bt" "st" "bst")
-                   ("SCANS"      'list   " " "scansautomatic" "scansforward" "scansbackward")
-                   ("FLUSH"      'list*  " " "begin" "center" "end")
-                   ("CLIP"       'list   " " "clip1in" "clip4in")
-                   ("ZRANGE"     'range (" " . " ") ":")
-                   ("HIDDEN3D"   'number " ")
-                   ("NOHIDDEN3D" 'list   " " "nohidden3d")
-                   ("FILLING"    'list   " " "transparent" "solid")
-                   ("MAP"        'list   " " "map")))
-
-           (cons "offsets"
-                 '(("LEFT  " 'number " ")
-                   ("RIGHT " 'number " " ",")
-                   ("TOP   " 'number " " ",")
-                   ("BOTTOM" 'number " " ",")))
-           (cons "origin"
-                 '(("X ORIGIN"   'number " ")
-                   ("Y ORIGIN"   'number " " ",")))
-           (cons "output"
-                 '(("FILENAME"   'file " ")))
-           (cons "pointsize"
-                 '(("MULTIPLIER" 'number " ")))
-           (cons "samples"
-                 '(("2D PLOT"    'number " ")
-                   ("3D PLOT"    'number " " ",")))
-           (cons "size"
-                 '(("ASPECT"           'list " " "square" "nosquare"
-                                                 "ratio" "noratio")
-                   ("X-SCALE OR RATIO" 'number " ")
-                   ("Y-SCALE"          'number " " ",")))
-           (cons "style"
-                 '(("DATA TYPE"  'list " " "data" "function")
-                   ("PLOT STYLE" 'list " " "boxerrorbars" "boxes"
-                    "boxxyerrorbars" "candlesticks" "dots"
-                    "financebars" "fsteps" "histeps" "impulses"
-                    "lines" "linespoints" "points" "steps" "vector"
-                    "xerrorbars" "xyerrorbars" "yerrorbars")))
-           (cons "terminal"
-                 '(("TERMINAL TYPE" 'list " " gnuplot-gui-terminal-list)))
-           (cons "tics"
-                 '(("DIRECTION"  'list " " "in" "out")))
-           (cons "ticslevel"
-                 '(("RELATIVE HEIGHT" 'number " ")))
-           (cons "ticscale"
-                 '(("MAJOR" 'number " ")
-                   ("MINOR" 'number " ")))
-           (cons "timestamp"
-                 '(("FORMAT STRING" 'format " ")
-                   ("WHERE"         'list " " "top" "bottom")
-                   ("ROTATE"        'list " " "rotate" "norotate")
-                   ("X-OFFSET"      'number " ")
-                   ("Y-OFFSET"      'number " " ",")
-                   ("FONTNAME"      'list " " gnuplot-gui-fontname-list)))
-           (cons "timefmt"
-                 '(("FORMAT STRING" 'string " ")))
-           (cons "title"
-                 '(("TITLE" 'string " ")))
-           (cons "view"
-                 '(("X-ROTATION" 'number " ")
-                   ("Z-ROTATION" 'number " " ",")
-                   ("SCALE"      'number " " ",")
-                   ("Z-SCALE"    'number " " ",")))
-           ;; ("SCALE" 'position " " "," 4)
-                                       ; _data
-           (cons "xdata"      gnuplot-gui-data-list)
-           (cons "ydata"      gnuplot-gui-data-list)
-           (cons "zdata"      gnuplot-gui-data-list)
-           (cons "x2data"     gnuplot-gui-data-list)
-           (cons "y2data"     gnuplot-gui-data-list)
-                                       ; _label
-           (cons "xlabel"     gnuplot-gui-label-list)
-           (cons "ylabel"     gnuplot-gui-label-list)
-           (cons "zlabel"     gnuplot-gui-label-list)
-           (cons "x2label"    gnuplot-gui-label-list)
-           (cons "y2label"    gnuplot-gui-label-list)
-                                       ; _range, note that the [] syntax for
-                                       ;         the writeback argument is
-                                       ;         not properly supported
-           (cons "xrange"     gnuplot-gui-range-list)
-           (cons "yrange"     gnuplot-gui-range-list)
-           (cons "zrange"     gnuplot-gui-range-list)
-           (cons "x2range"    gnuplot-gui-range-list)
-           (cons "y2range"    gnuplot-gui-range-list)
-           (cons "trange"     gnuplot-gui-range-list)
-           (cons "rrange"     gnuplot-gui-range-list)
-           (cons "urange"     gnuplot-gui-range-list)
-           (cons "vrange"     gnuplot-gui-range-list)
-                                       ; _tics
-           (cons "xtics"      gnuplot-gui-tics-list)
-           (cons "ytics"      gnuplot-gui-tics-list)
-           (cons "ztics"      gnuplot-gui-tics-list)
-           (cons "x2tics"     gnuplot-gui-tics-list)
-           (cons "y2tics"     gnuplot-gui-tics-list)
-                                       ; zeroaxis
-           (cons "zeroaxis"   gnuplot-gui-zeroaxis-list)
-           (cons "xzeroaxis"  gnuplot-gui-zeroaxis-list)
-           (cons "yzeroaxis"  gnuplot-gui-zeroaxis-list)
-           (cons "y2zeroaxis" gnuplot-gui-zeroaxis-list)
-           (cons "x2zeroaxis" gnuplot-gui-zeroaxis-list)
-
-           (cons "zero"
-                 '(("THRESHOLD" 'number " ")))
-           ))
-
-(defvar gnuplot-gui-command-types nil
-  "Associated list of command descriptions.
-See the doc-string for `gnuplot-gui-all-types'.")
-(setq gnuplot-gui-command-types
-      (list (cons "cd"
-                 '(("FILENAME"       'file   " ")))
-           (cons "call"
-                 '(("INPUT FILE"     'file   " ")
-                   ("PARAMETER LIST" 'string " ")))
-           (cons "load"
-                 '(("INPUT FILE"     'file   " ")))
-           (cons "pause"
-                 '(("TIME"           'number " ")
-                   ("MESSAGE"        'string " ")))
-           (cons "print"
-                 '(("EXPRESSION"     'string " ")))
-           (cons "save"
-                 '(("SAVE"           'list   " " "functions" "variables" "set")
-                   ("FILE"           'file   " ")))
-           (cons "update"
-                 '(("INITIAL FILE"   'file   " " t)
-                   ("UPDATED FILE"   'file   " " t))) ))
-
-
-(defcustom gnuplot-gui-plot-splot-fit-style 'simple
-  "Control the complexity of the GUI display for plot, splot, and fit.
-The values are 'simple, which causes a limited set of plot, splot, or
-fit options to be displayed, and 'complete, which attempts to display
-all options.  The 'complete setting is prone to making errors when
-parsing values already in the script buffer."
-  :group 'gnuplot-gui
-  :type '(radio (const :tag "Simple listing"   simple)
-               (const :tag "Complete listing" complete)))
-
-
-(defconst gnuplot-gui-plot-simple-list
-  '(("X RANGE"     'range (" " . " ") ":")
-    ("Y RANGE"     'range (" " . " ") ":")
-    ("DATA FILE"   'file   " ")
-    ("THRU"        'string* " " "thru")
-    ("USING"       'modifier " ")
-    ("TITLE"       'string " ")
-    ("WITH"        'list* " " "boxerrorbars" "boxes"
-     "boxxyerrorbars" "candlesticks" "dots" "financebars"
-     "fsteps" "histeps" "impulses" "lines" "linespoints"
-     "points" "steps" "vector" "xerrorbars" "xyerrorbars"
-     "yerrorbars")))
-(defconst gnuplot-gui-plot-full-list
-  '(;;("T RANGE"     'range (" " . " ") ":")
-    ("X RANGE"     'range (" " . " ") ":")
-    ("Y RANGE"     'range (" " . " ") ":")
-    ("xa"          'text   "\t---------------------")
-    ("FUNCTION"    'string " ")
-    ("xc"          'text   "   or")
-    ("DATA FILE"   'file   " ")
-    ("INDEX"       'modifier " ")
-    ("EVERY"       'modifier " ")
-    ("THRU"        'string* " " "thru")
-    ("USING"       'modifier " ")
-    ("SMOOTH"      'list* " " "unique" "csplines" "acsplines"
-     "bezier" "sbezier")
-    ;; datafile modifiers
-    ("AXES"        'list* " " "x1y1" "x2y2" "x1y2" "x2y1")
-    ("TITLE"       'string " ")
-    ("NOTITLE"     'list   " " "notitle")
-    ("xf"          'text   "\t---------------------")
-    ("xi"          'text   "Select a standard plotting style")
-    ("WITH"        'list* " " "boxerrorbars" "boxes"
-     "boxxyerrorbars" "candlesticks" "dots" "financebars"
-     "fsteps" "histeps" "impulses" "lines" "linespoints"
-     "points" "steps" "vector" "xerrorbars" "xyerrorbars"
-     "yerrorbars")
-    ("xo"          'text   "     or a previously defined style")
-    ("LINE STYLE " 'number " " "ls")
-    ("xr"          'text   "     or specify a style in-line")
-    ("LINE TYPE  " 'number " " "lt")
-    ("LINE WIDTH " 'number " " "lw")
-    ("POINT TYPE " 'number " " "pt")
-    ("POINT STYLE" 'number " " "ps")
-    ))
-(defconst gnuplot-gui-splot-simple-list
-  '(("DATA FILE"   'file   " ")
-    ("TITLE"       'string " ")
-    ("WITH"        'list* " " "lines" "linespoints" "points" "dots" "impulses")))
-(defconst gnuplot-gui-splot-full-list
-  '(;;("U RANGE"     'range (" " . " ") ":")
-    ;;("V RANGE"     'range (" " . " ") ":")
-    ("X RANGE"     'range (" " . " ") ":")
-    ("Y RANGE"     'range (" " . " ") ":")
-    ("Z RANGE"     'range (" " . " ") ":")
-    ("xa"          'text   "\t---------------------")
-    ("FUNCTION"    'string " ")
-    ("xc"          'text   "   or")
-    ("DATA FILE"   'file   " ")
-    ("INDEX"       'modifier " ")
-    ("EVERY"       'modifier " ")
-    ("THRU"        'string* " " "thru")
-    ("USING"       'modifier " ")
-    ("SMOOTH"      'list* " " "unique" "csplines" "acsplines"
-     "bezier" "sbezier")
-    ("TITLE"       'string " ")
-    ("NOTITLE"     'list   " " "notitle")
-    ("WITH"        'list* " " "lines" "linespoints" "points" "dots" "impulses")))
-(defconst gnuplot-gui-fit-simple-list
-  '(("FUNCTION"     'string* " " "")
-    ("DATA FILE"    'file    " ")
-    ("VIA (params)" 'string* " " "via") ))
-(defconst gnuplot-gui-fit-full-list
-  '(("X RANGE"      'range  (" " . " ") ":")
-    ("Y RANGE"      'range  (" " . " ") ":")
-    ("xa"           'text    "----- fitting functionn and file --------")
-    ("FUNCTION"     'string* " " "")
-    ("DATA FILE"    'file    " ")
-    ("xb"           'text    "----- datafile modifiers ----------------")
-    ("INDEX"        'modifier " ")
-    ("EVERY"        'modifier " ")
-    ("THRU"         'string* " " "thru")
-    ("USING"        'modifier " ")
-    ("SMOOTH"       'list* " " "unique" "csplines" "acsplines"
-     "bezier" "sbezier")
-    ("xc"           'text    "----- parameters (file or parameters) ---")
-    ("VIA (file)"   'string  " " "via")
-    ("VIA (params)" 'string* " " "via") ))
-
-(defvar gnuplot-gui-plot-splot-fit nil
-  "Associated list of plot, splot, and fit descriptions.
-See the doc-string for `gnuplot-gui-all-types'.")
-(setq gnuplot-gui-plot-splot-fit
-      (list (cons "plot"  (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
-                             gnuplot-gui-plot-full-list
-                           gnuplot-gui-plot-simple-list))
-           (cons "splot" (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
-                             gnuplot-gui-splot-full-list
-                           gnuplot-gui-splot-simple-list))
-           (cons "fit"   (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
-                             gnuplot-gui-fit-full-list
-                           gnuplot-gui-fit-simple-list))) )
-
-
-(defvar gnuplot-gui-test-type nil)
-(setq gnuplot-gui-test-type
-      (list (cons "test"
-                 '(("TAG"      'tag      " ")
-                   ("LIST"     'list     " " "1" "2" "3")
-                   ("LIST*"    'list*    " " "1" "2" "3")
-                   ("NUMBER"   'number   " " "number")
-                   ("RANGE"    'range   (" " . " ") ":")
-                   ("PAIR"     'pair    (" " . " ") "pair")
-                   ("LABELS"   'labels   ())
-                   ("FILE"     'file     " ")
-                   ("TEXT"     'text     "this is text")
-                   ("STRING"   'string   " ")
-                   ("STRING*"  'string*  " " "string*")
-                   ("FORMAT"   'format   " ")
-                   ("POSITION" 'position " " "at" 3)
-                   ("FONTSIZE" 'fontsize " ") ))))
-
-(defvar gnuplot-gui-all-types nil
-    "Associated list of terminal, set option, and command arguments.
-
-Each entry in the list is a cons cell of the form
-      (OPTION . ALIST)
-where OPTION is one of the recognized options in Gnuplot, either a
-command, something that is set, or a terminal type.  Only those
-commands, set options, and terminal types that actually take arguments
-are in this associated list.
-
-ALIST is itself an associated list where each entry is of the form:
-
-      (TAG TYPE DEFAULT REST)
-
-TAG is the name used on the widget and indicates one of the options
-for this command, set option, or terminal type.
-
-TYPE is one of
-     'list       a menu-list of strings
-     'list*      a menu-list of strings with a prefix
-     'number     a number with an optional prefix
-     'tag        like number but must be the first argument
-     'fontsize   like number but must be the last argument
-     'range      a pair of numbers like [#,#] or [#:#]
-     'pair       a pair of numbers with no punctuation and a prefix
-     'file       a quoted string and a file browser
-     'string     a quoted string with an optional prefix
-     'string*    an unquoted string with a prefix
-     'format     a quoted string and an info-link to (gnuplot)format
-     'labels     an array as needed for xtics, ytics, etc
-     'position   2 or 3 comma separated numbers with an optional prefix
-
-DEFAULT is the default value for this option.  Note that the default
-for 'range and 'pair is a cons cell and the default for 'labels is a
-list.  For most things, the best choice of DEFAULT is a string of
-white space or a cons cell of two strings of white space.  Strings of
-white space are better defaults than empty strings or nil.
-
-The value of REST depends upon TYPE:
-
-  For 'list &    REST is the list of options that will go into the
-      'list*       menu-button.  This can also be a symbol which
-                   evaluates to a list containing the options to go into
-                   the menu-button.  This list variable must contain the
-                   DEFAULT.
-  For 'number    REST is the prefix string (if it exists) for that number.
-  For 'range     REST is the separator, \":\" for plot ranges and
-                   \",\" for plot dimensions (see for example the tgif
-                   terminal type)
-  For 'string &  REST may a number denoting the width of the editable-text
-      'string*     field or it may be a string denoting a prefix.  By
-                   default, the width is half the width of the frame
-                   and there is no prefix.  It may be useful to
-                   specify \"1\" when the input is a single character
-                   as in 'set missing'.
-  For 'file      REST determines the label placed before the file insertion
-                   field.  If non-nil, then TAG is used.  If nil, then
-                   the default \"File\" is used.
-  For 'position  REST is the prefix and the number of comma separated numbers
-  For others     REST is not used.
-
-Here is an example entry for the png terminal type:
-
-  (cons \"png\"
-       '((\"SIZE\"  'list \" \" \"small\" \"medium\" \"large\")
-         (\"COLOR\" 'list \" \" \"monochrome\" \"gray\" \"color\")))
-
-This alist is formed at load time by appending together
-`gnuplot-gui-terminal-types', `gnuplot-gui-set-types' and
-`gnuplot-gui-command-types'.")
-
-(setq gnuplot-gui-all-types (append gnuplot-gui-terminal-types
-                                   gnuplot-gui-set-types
-                                   gnuplot-gui-command-types
-                                   gnuplot-gui-plot-splot-fit
-                                   gnuplot-gui-test-type
-                                   ))
-
-
-(defun gnuplot-gui-swap-simple-complete ()
-  (interactive)
-  (setq gnuplot-gui-plot-splot-fit-style
-       (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
-           'simple 'complete))
-  (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
-      (progn
-       (setcdr (assoc "plot"  gnuplot-gui-all-types) gnuplot-gui-plot-full-list)
-       (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-full-list)
-       (setcdr (assoc "fit"   gnuplot-gui-all-types) gnuplot-gui-fit-full-list))
-    (setcdr (assoc "plot"  gnuplot-gui-all-types) gnuplot-gui-plot-simple-list)
-    (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-simple-list)
-    (setcdr (assoc "fit"   gnuplot-gui-all-types) gnuplot-gui-fit-simple-list))
-  (message "Using %s lists for plot, splot, and fit."
-          gnuplot-gui-plot-splot-fit-style) )
-
-
-
-\f
-;;; user interface to the widget-y stuff
-
-(defun gnuplot-gui-mouse-set (event)
-  "Use the mouse to begin setting options using a GUI interface.
-EVENT is a mouse event.  Bound to \\[gnuplot-gui-mouse-set]
-Note that \"plot\", \"splot\", \"fit\", and \"cntrparam\" are not
-currently supported."
-  (interactive "@e")
-  (when (fboundp 'widget-create)
-    (save-excursion
-      (mouse-set-point event)
-      (gnuplot-gui-set-options-and-insert))))
-
-(defun gnuplot-gui-get-frame-param (param)
-  (if gnuplot-xemacs-p
-      (plist-get gnuplot-gui-frame-plist param)
-    (cdr (assoc param gnuplot-gui-frame-parameters))))
-(defun gnuplot-gui-set-frame-param (param value)
-  (if gnuplot-xemacs-p
-      (plist-put gnuplot-gui-frame-plist param value)
-    (setcdr (assoc param gnuplot-gui-frame-parameters) value)))
-
-(defun gnuplot-gui-set-options-and-insert ()
-  "Insert arguments using a GUI interface.
-Determine contents of current line and set up the appropriate GUI
-frame.  Bound to \\[gnuplot-gui-set-options-and-insert]
-Note that \"cntrparam\" is not currently supported."
-  (interactive)
-  (when (fboundp 'widget-create)
-    (let ((begin  (gnuplot-point-at-beginning-of-command))
-         (end    (save-excursion (end-of-line)       (point-marker)))
-         (termin (concat "\\(,\\s-*" (regexp-quote "\\") "\\|;\\)"))
-         (set nil) (term nil))
-      (save-excursion
-       ;; there can be more then one command per line
-       (if (re-search-forward termin end "to_limit")
-           (progn (backward-char (length (match-string 1)))
-                  (setq end (point-marker))))
-       (goto-char begin)
-       (skip-syntax-forward "-" end)
-       ;; various constructions are recognized here. at the end of this
-       ;; cond, point should be just after the word whose arguments are
-       ;; to be set
-       (cond ((looking-at "set\\s-+")
-              (setq set t)
-              (goto-char (match-end 0))
-              (if (looking-at "\\sw+") (goto-char (match-end 0)))
-              (when (string-match "^ter" (gnuplot-this-word)) ; terminal?
-                (setq term t)
-                (forward-word 1))
-              (when (string-match "^\\(da\\|fu\\)" (gnuplot-this-word))
-                (unless (looking-at "\\s-+st")
-                  (insert " style") (forward-word 1))
-                (forward-word 1)))
-             ((looking-at (concat "\\(cd\\|ca\\|lo\\|pa\\|pr\\|sa\\|u\\)"
-                                  "\\w*"
-                                  "[\\s-\\']"))
-              (forward-word 1))
-             ;;(goto-char (match-end 0)))
-             (t
-              (forward-word 1)))
-       (if (> (point) end) (goto-char end))
-       (let* ((w (gnuplot-this-word))
-              (wd (try-completion w gnuplot-gui-all-types))
-              (word "") wrd list)
-         (cond ((equal wd t)                     (setq word w))
-               ((equal wd nil)                   (setq word w))
-               ((assoc wd gnuplot-gui-all-types) (setq word wd))
-               (t                                (setq wd nil)))
-         (cond ((equal (string-match "^\\s-*$" w) 0)
-                (message "Blank line"))
-               ((and wd (stringp word))
-                (gnuplot-gui-correct-command word set term begin)
-                (setq gnuplot-gui-alist nil
-                      gnuplot-gui-current-string
-                      (buffer-substring-no-properties (point) end))
-                (gnuplot-gui-set-alist word gnuplot-gui-current-string)
-                (let* ((old-height (gnuplot-gui-get-frame-param 'height))
-                       (old-top    (gnuplot-gui-get-frame-param 'top)))
-                  (when (or
-                         (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
-                              (member* word '("plot" "splot" "fit")
-                                       :test 'string=))
-                         (equal word "test"))
-                    (gnuplot-gui-set-frame-param 'height 32)
-                    (gnuplot-gui-set-frame-param 'top    50))
-                  (gnuplot-gui-prompt-for-frame word)
-                  (when (or
-                         (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
-                              (member* word '("plot" "splot" "fit")
-                                       :test 'string=))
-                         (equal word "test"))
-                    (gnuplot-gui-set-frame-param 'height old-height)
-                    (gnuplot-gui-set-frame-param 'top    old-top)) ))
-               ((setq wrd (car (all-completions w '(("cntrparam")))))
-                (message
-                 "Setting arguments for %S is currently unsuported in gnuplot-mode"
-                 wrd))
-               ((setq list (all-completions w gnuplot-gui-all-types))
-                (message "%S could be one of %S" w list))
-               (t
-                (message
-                 "%S is not a gnuplot command which takes options" w)))) ))))
-
-(defun gnuplot-gui-toggle-popup ()
-  (interactive)
-  (setq gnuplot-gui-popup-flag (not gnuplot-gui-popup-flag))
-  (message (if gnuplot-gui-popup-flag
-              "Argument popup will appear after insertions."
-            "Argument popup will no longer appear after insertions.")))
-
-
-(defun gnuplot-gui-y-n (foo))
-(if gnuplot-xemacs-p
-    (defalias 'gnuplot-gui-y-n 'y-or-n-p-maybe-dialog-box)
-  (defalias 'gnuplot-gui-y-n 'y-or-n-p))
-
-(defun gnuplot-gui-correct-command (word set term begin)
-  "Check syntax of set command and terminal specifications.
-WORD is the item being set. SET and TERM are non-nil if the words
-\"set\" and \"terminal\" were found preceding WORD in the buffer.
-BEGIN is the beginning of the command."
-  (save-excursion
-    (cond ((assoc word gnuplot-gui-terminal-types)
-          (when (and (not (and set term))
-                     (gnuplot-gui-y-n
-                      (format
-                       "%S must be preceded by \"set terminal\".  Add it? "
-                       word)))
-            (backward-word 1)
-            (let ((e (point-marker)))
-              (goto-char begin)
-              (skip-syntax-forward "-" e)
-              (delete-region (point) e)
-              (insert "set terminal "))))
-         ((assoc word gnuplot-gui-set-types)
-          (when (and (not set)
-                     (gnuplot-gui-y-n
-                      (format
-                       "%S must be preceded by \"set\".  Add \"set\"? " word)))
-            (backward-word 1)
-            (let ((e (point-marker)))
-              (goto-char begin)
-              (skip-syntax-forward "-" e)
-              (delete-region (point) e)
-              (insert "set "))))))
-  (message nil))
-
-
-\f
-;;; handle the actual arguments
-
-(defun gnuplot-gui-fix-arg-list (list)
-  "Correct the result of splitting `gnuplot-gui-current-string'.
-LIST is the split string.  This removes empty and all-blank strings
-from the list and concatenates the strings that are part of a quoted
-argument, for example an axis label or a font name.  It also replaces
-bounding single quotes with double quotes, since double quotes are
-used in `gnuplot-gui-all-types'."
-  (let (fixed-list quote quoted)       ; remove blanks
-    (setq list (remove* "\\s-+" list :test 'string-match)
-         list (remove* ""      list :test 'string=))
-    (while list                                ; concatinate parts of quoted string
-      (if (not (string-match "^\\([\]\[()'\"]\\)" (car list)))
-         (setq fixed-list (append fixed-list (list (car list))))
-       (setq quote (match-string 1 (car list))
-             quoted (car list))
-       (if (string= quote "[") (setq quote "]"))
-       (if (string= quote "(") (setq quote ")"))
-       (while (and list
-                   (or (equal (length quoted) 1)
-                       (not (string-match (concat (regexp-quote quote) "$")
-                                          quoted))))
-         (setq quoted (concat quoted " " (cadr list))
-               list (cdr list)))
-       (if (string= quote "'")
-           (setq quoted (concat "\"" (substring quoted 1))
-                 quoted (concat (substring quoted 0 -1) "\"")))
-       (setq fixed-list (append fixed-list (list quoted))))
-      (setq list (cdr list)) )
-    fixed-list))
-
-(defun gnuplot-gui-set-alist (word string)
-  "Set defaults for arguments, using text from buffer if appropriate.
-WORD is the Gnuplot expression whose arguments are being set.  STRING
-is text from the buffer containing the previous values for WORD's
-arguments."
-  (let ((alist    (cdr (assoc word gnuplot-gui-all-types)))
-       (arg-list (gnuplot-gui-fix-arg-list (split-string string)) ))
-    ;; arg-list contains the arguments taken from the buffer
-    (setq gnuplot-gui-alist nil)
-    (while alist
-      (let* ((list      (car alist))
-            (tag       (gnuplot-gui-type-tag     list))
-            (symbol    (eval (gnuplot-gui-type-symbol list)))
-            (default   (gnuplot-gui-type-default list))
-            (prefix    (gnuplot-gui-type-prefix  list))
-            (values    (gnuplot-gui-type-list    list))
-            (this-cons (cond ((stringp default) (cons tag default))
-                             ((consp default) ; set cons valued default w/care
-                              (cons tag (cons (car default) (cdr default))))
-                             (t (cons tag default))))
-            (temp-list arg-list) )
-       ;;(message "%S" temp-list)      ; want to lop values off arg-list
-                                       ; as they are found
-       (if (symbolp (cadr values))
-         (setq values (symbol-value (cadr values))))
-       ;; check if an argument of this type is in arg-list
-       ;; set the current cons cell if it is
-       (while temp-list
-         (cond
-          ;; ---------------------------- list
-          ((member* symbol '(list list*) :test 'equal)
-           (let* ((case-fold-search nil)
-                  (match-cons (member* (concat "^" (car temp-list))
-                                       values :test 'string-match)))
-             (if (and (car match-cons) ; " " may be first elem. of list
-                      (not (string= " " (car match-cons))))
-                 (setq this-cons (cons tag (car match-cons))
-                       arg-list (remove* (car temp-list) arg-list
-                                         :test 'string= :count 1)
-                       temp-list nil)
-               (setq temp-list (cdr temp-list)))))
-          ;; ---------------------------- tag (first number in list)
-          ((equal symbol 'tag)
-           (if (string-match "^[-0-9.]+$" (car arg-list))
-               (setq this-cons (cons  tag (car arg-list))
-                     temp-list nil)
-             (setq temp-list (cdr temp-list))) )
-          ;; ---------------------------- fontsize (last number in list)
-          ((equal symbol 'fontsize)
-           (if (string-match "^[-0-9.]+$" (car (last arg-list)))
-               (setq this-cons (cons  tag (car (last arg-list)))
-                     temp-list nil)
-             (setq temp-list (cdr temp-list))) )
-          ;; ---------------------------- number with prefix
-          ((equal symbol 'number)
-           (cond ((and (string= prefix (car temp-list))
-                       (string-match "^[-0-9.]+$" (cadr temp-list)))
-                  (setq this-cons (cons tag (cadr temp-list))
-                        arg-list (remove* (car temp-list) arg-list
-                                          :test 'string= :count 1)
-                        arg-list (remove* (cadr temp-list) arg-list
-                                          :test 'string= :count 1)
-                        temp-list nil))
-                 ;; --------------------- number without prefix
-                 ((and (not prefix)
-                       (string-match "^[-0-9.]+$" (car temp-list)))
-                  (setq this-cons (cons tag (car temp-list))
-                        arg-list (remove* (car temp-list) arg-list
-                                          :test 'string= :count 1)
-                        temp-list nil))
-                 (t
-                  (setq temp-list (cdr temp-list)))))
-          ;; ---------------------------- pair with prefix
-          ((equal symbol 'pair)
-           (if (and (string= prefix (car temp-list))
-                    (string-match "^[-0-9.]+$" (cadr temp-list)))
-               (let ((this-car (cadr temp-list))
-                     (this-cdr (if (string-match "^[-0-9.]+$" (caddr temp-list))
-                                   (caddr temp-list) "")))
-                 (setq this-cons (cons tag (cons this-car this-cdr))
-                       temp-list nil))
-             (setq temp-list (cdr temp-list))))
-          ;; ---------------------------- range
-          ((equal symbol 'range)
-           (if (string-match (concat "\\[\\s-*" ; opening bracket
-                                     "\\([^:, \t]*\\)" ; first argument
-                                     "\\s-*[:,]\\s-*" ; separator
-                                     "\\([^\] \t]*\\)" ; second argument
-                                     "\\s-*\\]") ; closing bracket
-                             (car temp-list))
-               (setq this-cons
-                     (cons tag (cons (match-string 1 (car temp-list))
-                                     (match-string 2 (car temp-list))))
-                     arg-list (remove* (car temp-list) arg-list
-                                       :test 'string= :count 1)
-                     temp-list nil)
-             (setq temp-list (cdr temp-list)) ))
-          ;; ---------------------------- labels
-          ((equal symbol 'labels)
-           (if (string-match (concat "(" ; opening paren
-                                     "\\([^\)]*\\)" ; string
-                                     ")") ; closing paren
-                             (car temp-list))
-               (let* ((list (split-string (car temp-list) "[ \t(),]+"))
-                      (list (remove* "" list :test 'string=))
-                      (return ()))
-                 (while list
-                   (if (string-match "['\"]\\([^'\"]*\\)['\"]" (car list))
-                       (setq return (append return
-                                            (list (match-string 1 (car list))))
-                             list (cdr list)
-                             return (append return (list (car list))) )
-                     (setq return (append return (list "" (car list)))))
-                   (setq list (cdr list)) )
-                 (setq this-cons (cons tag return)
-                       arg-list (remove* (car temp-list) arg-list
-                                         :test 'string= :count 1)
-                       temp-list nil))
-             (setq temp-list (cdr temp-list))) )
-          ;; ---------------------------- string, file, format
-          ((member* symbol '(string file format) :test 'equal)
-           (if (string-match (concat "['\"]" ; opening quote
-                                     "\\([^'\"]*\\)" ; string
-                                     "['\"]") ; closing quote
-                             (car temp-list))
-               (setq this-cons (cons tag (match-string 0 (car temp-list)))
-                     arg-list (remove* (car temp-list) arg-list
-                                       :test 'string= :count 1)
-                     temp-list nil)
-             (setq temp-list (cdr temp-list)) ))
-          ;; ---------------------------- string*
-          ((equal symbol 'string*)
-           (if (string= prefix (car temp-list))
-               (setq this-cons (cons tag (cadr temp-list))
-                     arg-list (remove* (car temp-list) arg-list
-                                       :test 'string= :count 1)
-                     arg-list (remove* (cadr temp-list) arg-list
-                                       :test 'string= :count 1)
-                     temp-list nil)
-             (setq temp-list (cdr temp-list)) ) )
-          ;; ---------------------------- other or unknown
-          (t
-           (setq temp-list nil))
-          ))
-       (setq gnuplot-gui-alist
-             (append gnuplot-gui-alist (list this-cons))))
-      (setq alist (cdr alist))) ))
-
-
-(defun gnuplot-gui-post-process-alist (type)
-  "A few types need some additional processing.
-'range, 'pair, and 'labels are cons or list valued and need to b made
-into strings.  This is called right before inserting the arguments
-into the buffer.  TYPE is the object whose arguments are being set."
-  (let ((alist gnuplot-gui-alist)
-       (types (cdr (assoc type gnuplot-gui-all-types))) )
-    (while alist  ;; loop thru alist looking for tyeps needing post-processing
-      (let* ((list   (assoc (caar alist) types))
-            (value  (cdr (assoc (caar alist) gnuplot-gui-alist)))
-            (prefix (gnuplot-gui-type-prefix list))
-            (symb   (gnuplot-gui-type-symbol list)) )
-       (cond
-        ;;-------------------------- flat text
-        ((equal (eval symb) 'text)
-         (setcdr (assoc (caar alist) gnuplot-gui-alist) ""))
-        ;;-------------------------- range [#:#] or [#,#]
-        ((equal (eval symb) 'range)
-         (if (and (string-match "^\\s-*$" (car value))
-                  (string-match "^\\s-*$" (cdr value)))
-             (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
-           (setcdr (assoc (caar alist) gnuplot-gui-alist)
-                   (concat "[" (car value) prefix (cdr value) "]")) ) )
-        ;;-------------------------- pair
-        ((equal (eval symb) 'pair)
-         (if (and (string-match "^\\s-*$" (car value))
-                  (string-match "^\\s-*$" (cdr value)))
-             (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
-           (setcdr (assoc (caar alist) gnuplot-gui-alist)
-                   (concat prefix " " (car value) " " (cdr value) )) ) )
-        ;;-------------------------- labels
-        ((equal (eval symb) 'labels)
-         (if (consp value)
-             (let ((word "") (list value))
-               (while list
-                 (if (string-match "^\\s-*$" (car list))
-                     (setq word (concat word (format "%s, " (cadr list))))
-                   (setq word (concat word (format "%S %s, " (car list)
-                                                   (cadr list)))))
-                 (setq list (cddr list)) )
-               (setq value (concat "(" (substring word 0 -2) ")")))
-           (setq value "") )
-         (setcdr (assoc (caar alist) gnuplot-gui-alist) value) ))
-
-       (setq alist (cdr alist))) )))
-
-\f
-;;; GUI frames
-
-(defun gnuplot-gui-prompt-for-frame (&optional option save-frame)
-  (setq option (or option (completing-read "Option: " gnuplot-gui-all-types
-                                          nil t nil t)))
-  (gnuplot-gui-make-frame
-   option (cdr (assoc option gnuplot-gui-all-types)) save-frame) )
-
-
-(defface gnuplot-gui-error-face '((((class color) (background light))
-                                 (:foreground "grey30"))
-                                (((class color) (background dark))
-                                 (:foreground "grey70")))
-  "Face used to display message about unknown widget types."
-  :group 'gnuplot-faces)
-
-(defface gnuplot-gui-flat-text-face '((((class color) (background light))
-                                      (:foreground "MediumBlue"))
-                                     (((class color) (background dark))
-                                      (:foreground "LightSteelBlue")))
-  "Face used to display message about unknown widget types."
-  :group 'gnuplot-faces)
-
-(defun gnuplot-gui-make-frame (item alist &optional save-frame)
-  "Open the frame and populate it with widgets.
-ITEM is the object for which arguments are being set.  ALIST is
-the alist of arguments for ITEM taken from `gnuplot-gui-all-types'.
-SAVE-FRAME is non-nil when the widgets are being reset."
-  (unless save-frame
-    (setq gnuplot-current-frame (selected-frame)
-         gnuplot-current-buffer (current-buffer)
-         gnuplot-current-buffer-point (point-marker))
-    (unless (and gnuplot-gui-frame (frame-live-p gnuplot-gui-frame))
-      (setq gnuplot-gui-frame (if gnuplot-xemacs-p
-                                 (make-frame gnuplot-gui-frame-plist)
-                               (make-frame gnuplot-gui-frame-parameters))))
-    (select-frame gnuplot-gui-frame)
-    ;;(set-frame-position gnuplot-gui-frame 150 150) ;; so herky-jerky
-    (if gnuplot-xemacs-p
-       (set-mouse-position (selected-window) 0 0)
-      (set-mouse-position gnuplot-gui-frame 0 0)))
-  (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
-  (switch-to-buffer (get-buffer-create "*Gnuplot GUI*"))
-  (kill-all-local-variables)
-  (if gnuplot-xemacs-p
-      (progn
-       (set (make-local-variable 'frame-title-format)
-            "Set Gnuplot Options")
-       (set (make-local-variable 'frame-icon-title-format)
-            "Set Gnuplot Options"))
-    (modify-frame-parameters (selected-frame)
-                            '((title . "Set Gnuplot Options"))) )
-  (widget-insert "\nSet options for \"" item "\"  ")
-  (let (tag help val)
-    (cond ((string-match "^[xyz]2?tics" item)
-          (setq tag  "info on tic labels"
-                help "Open a frame displaying the info entry for tic labels"
-                val  "xtics"))
-         ((string-match "^no" item)
-          (setq tag  (concat "info on " (substring item 2))
-                help (format "Open a frame displaying the info entry for %S"
-                             item)
-                val  item))
-         (t
-          (setq tag  (concat "info on " item)
-                help (format "Open a frame displaying the info entry for %S"
-                             item)
-                val  item)))
-    (widget-create 'gnuplot-gui-info-link :tag tag :help-echo help :value val))
-
-  (widget-insert "\n\n")
-  (while alist
-    (let* ((this    (car   alist))
-          (tag     (gnuplot-gui-type-tag    this))
-          (wtype   (gnuplot-gui-type-symbol this))
-          (prefix  (gnuplot-gui-type-prefix this))
-          (default (cdr (assoc tag gnuplot-gui-alist)))
-          (list    (gnuplot-gui-type-list   this)))
-      (if (symbolp (cadr list))
-         (setq list (symbol-value (cadr list))))
-      (widget-insert "\t")             ; insert the appropriate widget
-      (cond
-       ;;------------------------------ list, list* ------------
-       ((member* (eval wtype) '(list list*) :test 'equal)
-       (let ((starred (if (equal (eval wtype) 'list*) t nil)))
-         (gnuplot-gui-menu-choice tag default list starred)))
-       ;;------------------------------ number, tag, fontsize --
-       ((member* (eval wtype) '(number tag fontsize) :test 'equal)
-       (gnuplot-gui-number tag default prefix))
-       ;;------------------------------ position ---------------
-       ;;------------------------------ range, pair ------------
-       ((member* (eval wtype) '(range pair) :test 'equal)
-       (let ((is-range (equal (eval wtype) 'range)))
-         (gnuplot-gui-range tag default prefix is-range)))
-       ;;------------------------------ string, string* --------
-       ((member* (eval wtype) '(string string*) :test 'equal)
-       (let ((starred (if (equal (eval wtype) 'string) nil t)))
-         (gnuplot-gui-string tag default prefix starred)))
-       ;;------------------------------ format -----------------
-       ((equal (eval wtype) 'format)
-       (gnuplot-gui-format tag default))
-       ;;------------------------------ file -------------------
-       ((equal (eval wtype) 'file)
-       (gnuplot-gui-file tag default prefix))
-       ;;------------------------------ labels -----------------
-       ((equal (eval wtype) 'labels)
-       (gnuplot-gui-labels tag default))
-       ;;------------------------------ text -------------------
-       ((equal (eval wtype) 'text)
-       (let ((str (gnuplot-gui-type-default this)))
-         (put-text-property 0 (length str) 'face 'gnuplot-gui-flat-text-face str)
-         (widget-insert str "\n")))
-       ;;------------------------------ unknown ----------------
-       (t
-       (let ((str (concat "<" (downcase tag) "> ('"
-                          (symbol-name (eval wtype))
-                          " arguments are not yet supported)\n")))
-         (put-text-property 0 (length str) 'face 'gnuplot-gui-error-face str)
-         (widget-insert str)) )))
-    (setq alist (cdr alist)))
-  ;; insert control buttons: [Set options]   [Reset]   [Clear]   [Cancel]
-  (widget-insert "\n\t")
-  (widget-create 'push-button
-                :value "Set options"
-                :doc item
-                :button-face 'gnuplot-gui-button-face
-                :help-echo "Push this button to set options"
-                :notify
-                (lambda (widget &rest ignore)
-                  (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
-                  (delete-frame)
-                  (select-frame gnuplot-current-frame)
-                  (switch-to-buffer gnuplot-current-buffer)
-                  (goto-char gnuplot-current-buffer-point)
-                  (gnuplot-gui-post-process-alist
-                   (widget-get widget :doc))
-                  (let ((alist gnuplot-gui-alist) marker
-                        (eol (save-excursion (end-of-line) (point-marker) )) )
-                    (if (re-search-forward ";" eol "to_limit")
-                        (backward-char 1))
-                    (delete-region gnuplot-current-buffer-point (point-marker))
-                    (delete-horizontal-space)
-                    (setq marker (point-marker))
-                    (while alist
-                      (let ((val (cdar alist)))
-                        (if (string-match "^\\s-+$" val) ()
-                          (if (string-match "^['\"]\\(.*\\)['\"]$" val)
-                              (setq val (concat gnuplot-quote-character
-                                                (match-string 1 val)
-                                                gnuplot-quote-character)))
-                          (insert (format " %s" val))))
-                      (setq alist (cdr alist)))
-                    (setq eol (point-marker))
-                    (goto-char marker)
-                    (while (< (point) eol) ; a few odd cases
-                      (unless (looking-at (concat "[" (regexp-quote "(")
-                                                  (regexp-quote "*") ",]"))
-                        (just-one-space))
-                      (forward-sexp)))
-                  (delete-horizontal-space)
-                  (if (string= "terminal" (widget-get widget :doc))
-                      (gnuplot-gui-set-options-and-insert)) ))
-  (widget-insert "   ")
-  (widget-create 'push-button :value "Reset"
-                :help-echo "Push this button to reset all values"
-                :button-face 'gnuplot-gui-button-face
-                :doc item
-                :notify
-                (lambda (widget &rest ignore)
-                  (let ((word (widget-get widget :doc)))
-                    (gnuplot-gui-set-alist word gnuplot-gui-current-string)
-                    (gnuplot-gui-prompt-for-frame word t))))
-  (widget-insert "   ")
-  (widget-create 'push-button :value "Clear"
-                :help-echo "Push this button to clear all values"
-                :button-face 'gnuplot-gui-button-face
-                :doc item
-                :notify
-                (lambda (widget &rest ignore)
-                  (let* ((word (widget-get widget :doc))
-                         (alist (cdr (assoc word gnuplot-gui-all-types))))
-                    (while alist
-                      (setcdr (assoc (gnuplot-gui-type-tag (car alist))
-                                     gnuplot-gui-alist)
-                              (gnuplot-gui-type-default (car alist)))
-                      (setq alist (cdr alist)))
-                    (gnuplot-gui-prompt-for-frame word t))) )
-  (widget-insert "   ")
-  (widget-create 'push-button :value "Cancel"
-                :help-echo "Quit setting options and dismiss frame"
-                :button-face 'gnuplot-gui-button-face
-                :notify (lambda (widget &rest ignore)
-                          (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
-                          (setq gnuplot-gui-alist nil
-                                gnuplot-gui-current-string nil)
-                          (delete-frame)
-                          (select-frame gnuplot-current-frame)))
-  (goto-char (point-min))
-  (use-local-map widget-keymap)
-  (widget-setup))
-
-\f
-;;; widgets
-
-(defface gnuplot-gui-menu-face '((((class color) (background light))
-                                 (:bold t :foreground "darkolivegreen"))
-                                (((class color) (background dark))
-                                 (:bold t :foreground "seagreen"))
-                                (t
-                                 (:italic t)))
-  "Face used for menu-buttons."
-  :group 'gnuplot-faces)
-(defface gnuplot-gui-button-face '((((class color) (background light))
-                                 (:bold t :foreground "sienna"))
-                                (((class color) (background dark))
-                                 (:bold t :foreground "tan"))
-                                (t
-                                 (:italic t)))
-  "Face used for push-buttons.
-Only used in Emacs.  XEmacs displays push-buttons with a pixmap."
-  :group 'gnuplot-faces)
-(defface gnuplot-gui-labels-face '((((class color) (background light))
-                                   (:bold t :foreground "darkslateblue"))
-                                  (((class color) (background dark))
-                                   (:bold t :foreground "lightslateblue"))
-                                  (t
-                                   (:italic t)))
-  "Face used for insert and delete button in the labels widget."
-  :group 'gnuplot-faces)
-
-(defun gnuplot-gui-menu-choice (item default list &optional starred)
-  "Create a menu widget for the Gnuplot GUI.
-ITEM is the object whose arguments are set by this widget, DEFAULT
-is the default argument value, LIST contains the items for the pop-up
-menu.  STARRED is true if this a 'list* widget."
-  (let ((widget
-        (apply 'widget-create
-               'menu-choice :value default :tag item :doc starred
-               :button-face 'gnuplot-gui-menu-face
-               :button-prefix "[" :button-suffix "]"
-               :help-echo (format "Mouse-2 to view the %S menu" (downcase item))
-               :notify
-               (lambda (widget &rest ignore)
-                 (let ((lab (if (widget-get widget :doc)
-                                (concat (downcase (widget-get widget :tag)) " ")
-                              "" )))
-                   (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
-                           (if (string= (widget-value widget) " ") ""
-                             (format "%s%s" lab (widget-value widget))) )))
-               (mapcar (lambda (x) (list 'item :value x))
-                       list))))
-    (widget-value-set widget default)
-    (if (and starred (not (string-match "^\\s-*$" default)))
-       (setcdr (assoc item gnuplot-gui-alist)
-               (format "%s %s" (downcase item) default)))
-    widget))
-
-(defun gnuplot-gui-number (item default &optional prefix)
-  "Create a number widget for the Gnuplot GUI.
-ITEM is the object whose arguments are set by this widget, DEFAULT
-is the default value for the widget, PREFIX is a text string preceding
-the numerical argument."
-  (let ((help-label (or prefix (downcase item))))
-    (widget-insert (capitalize item) ": ")
-    (widget-create 'editable-field
-                  :size 2 :tag item :value default :doc prefix
-                  :help-echo (format "Insert new value of %S here" help-label)
-                  :notify (lambda (widget &rest ignore)
-                            (let ((val (widget-value widget))
-                                  (pre (concat (widget-get widget :doc) " ")))
-                              (setcdr (assoc (widget-get widget :tag)
-                                             gnuplot-gui-alist)
-                                      (if (string-match
-                                           "^\\s-*[-0-9.*]+\\s-*$" val)
-                                          (format "%s%s" pre val) "") )))))
-  (unless (string-match "^\\s-*$" default)
-    (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" prefix default)))
-  (widget-insert " " (make-string (- 40 (current-column)) ?.)
-                " (numeric value)\n"))
-
-(defun gnuplot-gui-string (item default &optional width_or_prefix starred)
-  "Create a string widget for the Gnuplot GUI.
-ITEM is the object whose arguments are set by this widget, DEFAULT is
-the default value for the widget, and WIDTH_OR_PREFIX is the width of
-the text entry field (which defaults to half the frame width) or the
-prefix for the string.  STARRED is t if quotes are not to be used."
-  (let ((help-label (downcase item)) width (prefix "") (pp ""))
-    (cond ((stringp width_or_prefix)
-          (setq prefix width_or_prefix
-                pp prefix)
-          (if starred (setq prefix (concat prefix "_star"))) )
-         ((numberp width_or_prefix)
-          (setq width width_or_prefix)))
-    (setq width (or width (/ (frame-width) 2)))
-    (if (string-match "^['\"]" default)
-       (setq default (replace-match "" nil nil default)))
-    (if (string-match "['\"]$" default)
-       (setq default (replace-match "" nil nil default)))
-    (widget-insert (capitalize item) ": ")
-    (widget-create
-     'editable-field
-     :size width :tag item :doc prefix :value default
-     :help-echo (format "Insert new value of %S here" help-label)
-     :notify (lambda (widget &rest ignore)
-              (let ((val (widget-value widget))
-                    (q gnuplot-quote-character)
-                    (p (widget-get widget :doc)) )
-                (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
-                        (if (string-match "^\\s-*$" val)
-                            ""
-                          (progn
-                            (if (string-match "_star$" p)
-                                (setq p (concat (substring p 0 -5) " ")
-                                      q ""))
-                            (if (string-match "^\\s-+" val)
-                                (setq val (replace-match "" nil nil val)))
-                            (if (string-match "\\s-+$" val)
-                                (setq val (replace-match "" nil nil val)))
-                            (format "%s%s%s%s" p q val q)))))))
-    (unless (string-match "^\\s-*$" default)
-      (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" pp default)))
-    (widget-insert "\n")))
-
-(defun gnuplot-gui-format (item default)
-  "Create a string widget for the Gnuplot GUI.
-ITEM is the object whose arguments are set by this widget, DEFAULT is
-the default value for the widget, and WIDTH_OR_PREFIX is the width of
-the text entry field (which defaults to half the frame width) or the
-prefix for the string."
-  (if (string-match "^['\"]" default)
-      (setq default (replace-match "" nil nil default)))
-  (if (string-match "['\"]$" default)
-      (setq default (replace-match "" nil nil default)))
-  (widget-insert (capitalize item) ": ")
-  (widget-create 'editable-field
-                :size (/ (frame-width) 3) :tag item :value default
-                :help-echo (format "Insert new format string here")
-                :notify (lambda (widget &rest ignore)
-                          (let ((val (widget-value widget)))
-                            (setcdr (assoc (widget-get widget :tag)
-                                           gnuplot-gui-alist)
-                                    (format "%s%s%s"
-                                            gnuplot-quote-character
-                                            val
-                                            gnuplot-quote-character)))))
-  (widget-insert "   ")
-  (widget-create 'gnuplot-gui-info-link
-                :tag (concat "info on format")
-                :help-echo "Open a frame displaying the info entry for format"
-                :value "format")
-  (widget-insert "\n"))
-
-
-;; swiped from widget-color-complete
-(defun gnuplot-gui-file-completion (widget)
-  "Complete the filename in WIDGET."
-  (let* ((str (buffer-substring-no-properties (widget-field-start widget)
-                                             (point)))
-        (file (or (file-name-nondirectory str) ""))
-        (dir  (or (file-name-directory str) "./"))
-        (val  (file-name-completion file dir)) )
-    (cond ((eq val t)
-          (message "Exact match"))
-         ((null val)
-          (error "Can't find completion for \"%s\"" str))
-         ((not (string-equal str val))
-          (insert (substring val (length file))))
-         (t
-          (message "Making completion list...")
-          (let ((list (file-name-all-completions file dir)))
-            (with-output-to-temp-buffer "*Completions*"
-              (display-completion-list list)))
-          (message "Making completion list...done")))))
-
-(defun gnuplot-gui-file (item default &optional tag)
-  "Create a file widget for the Gnuplot GUI.
-ITEM is the object whose arguments is set by this widget, DEFAULT is
-the default value for the argument.  TAG is non-nil if ITEM rather than
-\"File:\" is to be used as the tag."
-  (setq tag (if tag (capitalize item) "File"))
-  (if (string-match "^['\"]" default)
-      (setq default (replace-match "" nil nil default)))
-  (if (string-match "['\"]$" default)
-      (setq default (replace-match "" nil nil default)))
-  (let ((widg (widget-create
-              'file
-              :value default :tag tag
-              :size (- (/ (frame-width) 2) 3)
-              :doc item :help-echo "Insert a filename here"
-              :complete 'gnuplot-gui-file-completion
-              :notify
-              (lambda (widget &rest ignore)
-                (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
-                        (format "%s%s%s" gnuplot-quote-character
-                                (widget-value widget)
-                                gnuplot-quote-character)) )) ))
-    (widget-insert " ")
-    (widget-create
-     'push-button :value "Browse"
-     :doc item :help-echo "Browse directories for a filename."
-     :parent widg
-     :notify (lambda (widget &rest ignore)
-              (let ((fname (file-relative-name (read-file-name "File: ")
-                                               default-directory))
-                    (q gnuplot-quote-character))
-                (widget-value-set (widget-get widget :parent) fname)
-                (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
-                        (format "%s%s%s" q fname q))
-                (widget-setup))))
-    (widget-insert "\n")))
-
-(defun gnuplot-gui-labels (item default)
-  "Create a labels widget for the Gnuplot GUI.
-ITEM is the object whose arguments is set by this widget, DEFAULT is
-the default value for the argument."
-  (widget-create
-   '(editable-list
-     (list :inline t :tag "Tic label"
-          (string :tag "label" :size 10
-                  :help-echo "Enter the tic label here" )
-          (string :tag "  position" :size 10
-                  :help-echo "Enter an expression for the tic location here" )))
-                :tag (capitalize item)
-                :value default
-                :format "%{%t%}:\n%v\t  %i\n"
-                :entry-format "\t  %i %d %v\n"
-                :button-face 'gnuplot-gui-labels-face
-                :notify (lambda (widget &rest ignore)
-                          (setcdr (assoc (upcase (widget-get widget :tag))
-                                         gnuplot-gui-alist)
-                                  (widget-value widget)))))
-
-(defun gnuplot-gui-range (item default separator is-range)
-  "Create a range or pair widget for the Gnuplot GUI.
-ITEM is the object whose arguments are set by this widget, DEFAULT is
-the default value for the widget, SEPARATOR is a text string preceding
-the numerical argument, or the prefix for a pair operator.  IS-RANGE
-is non-nil if this is a 'range widget."
-  (widget-insert (capitalize item) ": ")
-  (if is-range (widget-insert "["))
-  (widget-create 'editable-field
-                :size 4 :tag item :value (car default)
-                :help-echo (format "Insert the first value of the %S here"
-                                   (downcase item))
-                :notify (lambda (widget &rest ignore)
-                          (setcar (cdr (assoc (widget-get widget :tag)
-                                              gnuplot-gui-alist))
-                                  (format "%s" (widget-value widget)))))
-  (if is-range (widget-insert separator) (widget-insert "  "))
-  (widget-create 'editable-field
-                :size 4 :tag item :value (cdr default)
-                :help-echo (format "Insert the second value of the %S here"
-                                   (downcase item))
-                :notify (lambda (widget &rest ignore)
-                          (setcdr (cdr (assoc (widget-get widget :tag)
-                                              gnuplot-gui-alist))
-                                  (format "%s" (widget-value widget)))))
-  (if is-range (widget-insert "]"))
-  (widget-insert " " (make-string (- 39 (current-column)) ?.)
-                " (numeric values)\n"))
-
-
-;; suppress compiler warning
-;;(eval-when-compile (defun gnuplot-info-lookup-symbol (sym mode)))
-(define-widget 'gnuplot-gui-info-link 'info-link
-  "A link to an info file for the Gnuplot GUI."
-  :action '(lambda (widget &optional event)
-            (let ((gnuplot-info-display 'frame))
-              (if gnuplot-keywords-pending             ; <HW>
-                  (gnuplot-setup-info-look))
-              (gnuplot-info-lookup-symbol (widget-value widget)
-                                          'gnuplot-mode))))
-
-\f
-;;; just about done
-
-(provide 'gnuplot-gui)
-;;;============================================================================
-;;;
-;;; gnuplot-gui.el ends here
diff --git a/elpa/gnuplot-20191212.1801/gnuplot-pkg.el b/elpa/gnuplot-20191212.1801/gnuplot-pkg.el
deleted file mode 100644 (file)
index 971afcb..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-(define-package "gnuplot" "20191212.1801" "drive gnuplot from within emacs" 'nil :keywords
-  '("gnuplot" "plotting")
-  :authors
-  '(("Jon Oddie")
-    ("Bruce Ravel")
-    ("Phil Type"))
-  :maintainer
-  '("Bruce Ravel" . "bruceravel1NOSPAMgmail.com"))
-;; Local Variables:
-;; no-byte-compile: t
-;; End:
diff --git a/elpa/gnuplot-20191212.1801/gnuplot.el b/elpa/gnuplot-20191212.1801/gnuplot.el
deleted file mode 100644 (file)
index 212a4fa..0000000
+++ /dev/null
@@ -1,3262 +0,0 @@
-;;; gnuplot.el --- drive gnuplot from within emacs
-
-;; Copyright (C) 1998, 2011 Phil Type and Bruce Ravel, 1999-2012 Bruce Ravel
-
-;; Author: Jon Oddie
-;;         Bruce Ravel
-;;         Phil Type
-;; Maintainer: Bruce Ravel <bruceravel1NOSPAMgmail.com>
-;; Created:    June 28 1998
-;; Updated:    November 1 2012
-;; Version:    0.7.0
-;; Keywords:   gnuplot, plotting
-
-;; This file is not part of GNU Emacs.
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
-;;
-;; This lisp script is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-;;
-;; Permission is granted to distribute copies of this lisp script
-;; provided the copyright notice and this permission are preserved in
-;; all copies.
-;;
-;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, you can either send email to this
-;; program's maintainer or write to: The Free Software Foundation,
-;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Report bugs at https://github.com/emacsorphanage/gnuplot/issues
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;; Commentary:
-
-;;
-;; This is a major mode for composing gnuplot scripts and displaying
-;; their results using gnuplot.  It supports features of recent
-;; Gnuplot versions (4.4 and up), but should also work fine with older
-;; versions.
-;;
-;; This version of gnuplot-mode has been tested mostly on GNU Emacs 23
-;; and 24, but should also work with older GNU Emacs versions back to
-;; Emacs 21, and XEmacs 21.
-;; 
-;; This mode offers several tools to help you compose your scripts,
-;; including font-lock syntax colorization, a syntax table appropriate
-;; to gnuplot, key bindings, pull-down menus, indentation, keyword
-;; completions and variable customization using the Custom package.
-;; Once the script is composed, there are several function for sending
-;; some or all of the script to gnuplot.  The interaction with the
-;; gnuplot process is within a comint buffer.  Plots can optionally be
-;; displayed within Emacs.
-;;
-;;    C-c C-l       send current line to gnuplot
-;;    C-c C-v       send current line to gnuplot and move forward 1 line
-;;    C-c C-r       send current region to gnuplot
-;;    C-c C-b       send entire buffer to gnuplot
-;;    C-c C-f       send a file to gnuplot
-;;    C-c C-i       insert filename at point
-;;    C-c C-n       negate set option on current line
-;;    C-c C-c       comment region
-;;    C-c C-o       set arguments for command at point
-;;   S-mouse-2      set arguments for command under mouse cursor
-;;    C-c C-d       read the gnuplot info file
-;;    C-c C-e       show-gnuplot-buffer
-;;    C-c C-k       kill gnuplot process
-;;    C-c C-u       submit a bug report about gnuplot-mode
-;;    C-c C-z       customize gnuplot-mode
-;; M-tab or M-ret   complete keyword before point
-;;      ret         newline and indent
-;;      tab         indent current line
-;;    C-c M-i       toggle inline plot display in comint buffer
-;;
-;; With the exception of the commands for sending commands to Gnuplot,
-;; most of the above commands also work in the Gnuplot comint buffer,
-;; in addition to the following:
-;;     M-C-p        plot the most recent script buffer line-by-line
-;;     M-C-f        save the current script buffer and load that file
-;;    C-c C-e       pop back to most recent script buffer
-;;
-;; These two functions are useful for starting up gnuplot-mode:
-;;
-;; M-x gnuplot-mode
-;;         start gnuplot-mode in the current buffer
-;;
-;; M-x gnuplot-make-buffer
-;;         open a new buffer (which is not visiting a file) and start
-;;         gnuplot-mode in that buffer
-;;
-;; Gnuplot-mode now includes context-sensitive support for keyword
-;; completion and, optionally, eldoc-mode help text.  See the
-;; commentary in gnuplot-context.el for more information.  If you
-;; don't find it useful, it can be turned off by customizing
-;; `gnuplot-context-sensitive-mode'.
-;;
-;;
-;; ---------------------------------------------------------------------
-;;
-;; Other lisp files used by gnuplot.el
-;;
-;; gnuplot-gui.el (written by Bruce):
-;;   Defines the GUI interface for setting setting arguments to
-;;   gnuplot options.  This uses the widget package extensively.
-;;
-;; gnuplot-context.el (written by Jonathan, j.j.oddieNOSPAMgmail.com)
-;;   Context-sensitive completion, help lookup and eldoc
-;;   strings for gnuplot buffers. Should be byte-compiled before
-;;   using. 
-;;
-;; ---------------------------------------------------------------------
-;;
-;; This mode was inspired by the original gnu-plot-mode by Gershon
-;; Elber, which is distributed with gnuplot itself and which dates
-;; back to the early 90's.  Although this mode encompasses the
-;; functionality of the original, the two share no code and the
-;; current implementation takes advantage of many features of modern
-;; versions of emacs and adheres (or so I intend) to the major mode
-;; conventions described in the emacs-lisp reference for version 19
-;; and later.
-;;
-;; ---------------------------------------------------------------------
-;;
-;;                         Installation
-;;                         ============
-;;
-;; A recent version of this file can be found at
-;;   https://github.com/emacsorphanage/gnuplot/
-;;
-;; To autoload gnuplot-mode on any file with gp extension, put this in
-;; your .emacs file
-;;   (autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t)
-;;   (autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t)
-;;
-;; Something like
-;;   (setq auto-mode-alist (append '(("\\.gp$" . gnuplot-mode))
-;;                                auto-mode-alist))
-;; is useful for having files ending in .gp start up in gnuplot-mode.
-;;
-;; Something like
-;;   (global-set-key [(f9)] 'gnuplot-make-buffer)
-;; may be useful.  This binds f9 to the function that opens a scratch
-;; buffer (i.e. one that is not visiting a file) in gnuplot-mode.
-;; This is handy for your quick 'n' dirty plotting chores.
-;;
-;; To use the `gnuplot-info-lookup-symbol' function, the file
-;; gnuplot.info MUST be installed somewhere that info can find it.
-;; This means you must either:
-;;   1.  Copy gnuplot.info to the normal info directory or
-;;   2.  Make sure info can find gnuplot.info by putting this in your
-;;       .emacs file:
-;;         (setenv "INFOPATH"
-;;           (concat (getenv "INFOPATH") ":"
-;;                    (expand-file-name "/path/to/file")))
-;;       where "/path/to/file" is the location of gnuplot.info
-;;
-;; This mode has been tested extensively with GNU Emacs 23 and 24, and
-;; in a limited manner with GNU Emacs 22 and XEmacs 21.
-;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;; History:
-
-;;
-;;  0.1   Jun 25 1998 Finished with initial release.
-;;  0.2   Sep  4 1998 Added filename insertion, indentation, and
-;;        colorization/completion in comint buffer. <BR>
-;;  0.2a  Sep 11 1998 made `indent-line-function' buffer-local (whoops!)
-;;        and fixed some stuff in the installation script <BR>
-;;  0.3   Sep 12 1998 include insertions menu <BR>
-;;  0.3a  Sep 14 1998 fixed bug finding info file if missing, fixed bug
-;;        starting font-lock, fixed bug re overwriting files in
-;;        installation script <BR>
-;;  0.3b  Sep 15 1998 Added (require 'info) to `(eval-and-compile'
-;;        clause, Added (kill-all-local-variables) to `gnuplot-mode',
-;;        altered order of:-
-;;            (provide 'gnuplot)
-;;            (run-hooks 'gnuplot-load-hook)
-;;        at the end of the file in case something in the load hook
-;;        requires gnuplot (oh not that old one again...), added
-;;        `gnuplot-comint-setup-hook', corrected `gnuplot-mark-active'
-;;        which caused an error to be raised by (mark) when the mark
-;;        was inactive <DB>  Some changes to font-lock rules <LB>&<BR>
-;;  0.4   Nov 14 1998 <BR> Use info-look for info interface.  No
-;;        change to gnuplot-mode user interface, but cleaner code.
-;;        With info-look, the help funcion works regardless of the
-;;        version number of gnuplot.  Also, `gnuplot-keywords' (used
-;;        for help, keyword-completion, and hilit19 highlighting) is
-;;        now generated automatically.
-;;  0.4a  Nov 18 1998 <BR> info-look leaves a couple of really useless
-;;        buffers lying around so I cleaned them up.  Also fixed
-;;        font-lock rules so that things in quotes get highlighted
-;;        correctly and the surrounding text is unhighlighted.  Fixed
-;;        up font-lock rules for plot and splot.  Added
-;;        `gnuplot-send-line-and-forward' as suggested by <MD>.
-;;  0.4b  Nov 21 1998 <BR> added toolbar for xemacs -- see file
-;;        gnuplot-toolbar.el.  fixed error message in plot line
-;;        function when line is empty.  option added to display the
-;;        comint buffer showing the gnuplot process in a separate
-;;        frame
-;;  0.4c  Minor stuff: Nov 30 1998 <BR> fixed highlighting in comint
-;;        buffer.  fixed frame behavior.  added "[:]" to range
-;;        insertions.  added :link to defgroup.  Dec 1 1998 <BR> fixed
-;;        some mismatched defcustoms.  added a few lines to suppress
-;;        some compile-time warnings.  Dec 3 1998 <BR> Fixed behavior
-;;        of filename insertion function.  Added more :links to
-;;        defgroup.
-;;  0.4d  Dec 6 1998 <BR> Added function gnuplot-setup-info-look and
-;;        variable gnuplot-info-hook to handle various versions of the
-;;        gnuplot info file.
-;;  0.4e  Dec 12 1998 <BR> Split up gnuplot-insertions-menu for ease of
-;;        custimization, put menubar initialization in a function.
-;;  0.4f  Dec 14 1998 <BR> defcustom the insertions submenus, add
-;;        gnuplot-insertion-menu-flag, intelligent Makefile knows
-;;        which info-look to compile
-;;  0.5   Dec 27 1998 <BR> wrote initial draft of gnuplot-gui.el,
-;;        included it in insertions menu and in `gnuplot-insert'.
-;;        Negate option function, bound to C-c C-n. Dec 29 1998 <BR>
-;;        C-c C-h with no response goes to Commands menu.  Transparent
-;;        toolbar icons.  Replace kw-compl with a simple completion
-;;        function.  Put gnuplot-toolbar code in gnuplot.el.
-;;  0.5a  Jan 23 1999 <BR> send file uses the load command.  add
-;;        gnuplot-plot-from-comint and
-;;        gnuplot-save-and-plot-from-comint and keybindings in the
-;;        comint buffer.  do (process-kill-without-query
-;;        gnuplot-process nil).  `gnuplot-negate-option' checks if set
-;;        option has a negated form.
-;;  0.5b  `gnuplot-kill-gnuplot-buffer' made more robust.  fixed a bug
-;;        in `gnuplot-plot-from-comint'.  fixed description of
-;;        gnuplot-faces group.
-;;  0.5c  update copyright information, update gpelcard
-;;  0.5d  Mar 20 1999 <BR> adopt installation materials from <LH>.  Add
-;;        some support for hidden3d.  Use constants in types alists in
-;;        gui.  Various other minor improvements to the types alists.
-;;  0.5e  Apr 6 1999 <BR> at the suggestion of <SE> I did away with the
-;;        gnuplot-which-highlight variable and revamped how
-;;        colorization gets turned on.  This is a bit tricky since I
-;;        want it to work with font-lock under emacs and xemacs and
-;;        with hilit19.  Apr 11 1999 <BR> insert space at end of
-;;        unique completion.  add a few GUI types, rewrite some stuff
-;;        in the GUI interface.  primitive support for plot, splot,
-;;        and fit.  Fixed completion in file widget.
-;;  0.5f  May 15 1999 <BR> Add pgnuplot.c and Win9x install instructions
-;;        to the distribution.  Fixed a defface bug.  Added
-;;        `gnuplot-keywords-when' allowing deferral of parsing the
-;;        info file.
-;;  0.5g  May 27 1999 <BR> Fixed font-locking of strings and
-;;        comments.  Figure out gnuplot-version number from startup
-;;        message and set `gnuplot-echo-command-line-flag'
-;;        accordingly.  Added `gnuplot-program-version' variable.
-;;        Check that font-lock is actually a feature, as suggested by
-;;        <KL>
-;;  0.5h  Aug 15 1999 <BR> Added `gnuplot-determine-gnuplot-version' so
-;;        that the gnuplot version number and `comint-process-echos'
-;;        actually get set correctly.  Actually, the first time
-;;        something is plotted, the echoing might not work, but the
-;;        second time it will.
-;;  0.5i  Sep  2 1999 <BR> Once again changed how
-;;        `comint-process-echos' gets set.  Maybe I got it right this
-;;        time?  Also fixed certain situations where the info file
-;;        did notget properly loaded (insertion with info toggle on
-;;        and info button in GUI).
-;;  0.5j  Sep  9 1999 <BR> Do a more robust check for the gnuplot
-;;        process before killing the gnuplot buffer, as suggested by
-;;        <SE>.
-;;  0.5k  Sep 22 1999 <BR> make `gnuplot-send-line-and-forward' skip
-;;        over blank and comment lines as suggested by <SE>.  Jan 10
-;;        2000 Bound C-c C-j to `gnuplot-forward-script-line'.
-;;  0.5l  Nov 16 2000 <BR> support for pm3d in gnuplot-gui and in plot
-;;        options insertions menu.  mentioned pm3d in gpelcard. gui
-;;        support for x11 pm3d and vgagl terms.
-;;        `gnuplot-negate-option' works with new syntax.
-;;  0.5m  Nov 17 2000 <BR> add colorization and gui support for new
-;;        commands in 3.8.  gui support for emf term. gui support for
-;;        new "set style" syntax.  much better scheme for determining
-;;        gnuplot version number + make better use of it.
-;;  0.5n  Jan 4 2001 <BR> corrected a serious problem interacting with
-;;        speedbar
-;;  0.5o  skipped
-;;  0.5p  Mar 14 2001 <BR> fixed problem with toolbar creation and
-;;        speedbar clicking
-;;  0.5q  May 30 2001 <BR> added font-lock bindings for words associated
-;;        with plotting
-;;  0.5r  Oct 17 2001 <BR> Incorporate two suggestions by <RF>, bind
-;;        C-c C-c to comment-region and C-c C-o to the GUI, also make
-;;        C-c C-l respect continuation lines
-;;        April 12, 2002 <BR> added feature to trim length of gnuplot
-;;        process buffer
-;;  0.5s  Jun 7 2002 <BR> Yet again changed how `comint-process-echos'
-;;        gets set.  It really needs to be nil on NTEmacs 21.1 or
-;;        comint gets stuck in an infinate loop.
-;;  0.5t  Sep 16 2002 <BR> Fixed a problem with C-c C-v jumping
-;;        forward 2 lines at a time
-;;  0.6.0 Dec 13 2002 <BR> Changed numbering scheme to accommodate
-;;        gnuplot packaging requirements
-;;  0.6.1 Sep 13 2011 <BR> Moved to github, updated contact info
-;;  0.7.0 Oct 20 2012 <jjo> Contextual completion & help, inline plots,
-;;        some other stuff
- 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; Acknowledgements:
-;;    David Batty       <DB> (numerous corrections)
-;;    Laurent Bonnaud   <LB> (suggestions regarding font-lock rules)
-;;    Markus Dickebohm  <MD> (suggested `gnuplot-send-line-and-forward')
-;;    Stephen Eglan     <SE> (suggested the use of info-look,
-;;                            contributed a bug fix regarding shutting
-;;                            down the gnuplot process, improvement to
-;;                            `gnuplot-send-line-and-forward')
-;;    Robert Fenk       <RF> (suggested respecting continuation lines)
-;;    Michael Karbach   <MK> (suggested trimming the gnuplot process buffer)
-;;    Alex Chan Libchen <AL> (suggested font-lock for plotting words)
-;;    Kuang-Yu Liu      <KL> (pointed out buggy dependence on font-lock)
-;;    Hrvoje Niksic     <HN> (help with defcustom arguments for insertions)
-;;    Andreas Rechtsteiner <AR> (pointed out problem with C-c C-v)
-;;    Michael Sanders   <MS> (help with the info-look interface)
-;;    Jinwei Shen       <JS> (suggested functionality in comint buffer)
-;;    Michael M. Tung   <MT> (prompted me to add pm3d support)
-;;    Holger Wenzel     <HW> (suggested using `gnuplot-keywords-when')
-;;    Wolfgang Zocher   <WZ> (pointed out problem with gnuplot-mode + speedbar)
-;;    Jon Oddie        <jjo> (indentation, inline images, context mode)
-;;
-;;  and especially to Lars Hecking <LH> for including gnuplot-mode
-;;  with the gnuplot 3.7-beta distribution and for providing me with
-;;  installation materials
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; To Do:
-;;
-;; 1. Since `gnuplot-display-process' can be nil, it would be
-;;    handy to have a function to put on
-;;    `gnuplot-after-plot-buffer-hook' to check and see if the script
-;;    executed properly.  Alas I am not sure how gnuplot signals its
-;;    errors.
-;; 2. improve plot, splot, fit in GUI
-;; 3. interface to setting bind command using `read-key-sequence'.
-;;    this is a pain because the nomenclature is really different in
-;;    gnuplot than in `read-key-sequence'
-;;
-;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;; Code:
-
-(require 'comint)
-(require 'easymenu)
-(eval-when-compile (require 'cl))
-
-(declare-function 'eldoc-add-command "eldoc")
-
-\f
-;;; --- variable definitions + eval-and-compile clauses
-
-;; We no longer hack around ancient versions of Customize with macros
-(require 'custom)
-
-(eval-and-compile  ;; <DB>
-  (require 'info))
-
-(eval-and-compile
-  (condition-case ()
-      (require 'info-look)
-    (error nil)))
-
-;; Workaround missing `completion-at-point' in (X)Emacs < 22
-(if (not (fboundp 'completion-at-point))
-    (defun gnuplot-xemacs-completion-at-point ()
-      "Perform completion on keyword preceding point.
-
-This binds `comint-dynamic-complete-functions' to
-`gnuplot-comint-complete' and uses `comint-dynamic-complete' to do the
-real work."
-      (interactive)
-      (let ((comint-dynamic-complete-functions
-             '(gnuplot-comint-complete)))
-        (comint-dynamic-complete))))
-
-;; Work around missing `window-full-height-p'
-(if (fboundp 'window-full-height-p)
-    (defalias 'gnuplot-window-full-height-p 'window-full-height-p)
-  ;; The below is taken from window.el in GNU Emacs
-  (defun gnuplot-window-full-height-p (&optional window)
-      (unless window
-       (setq window (selected-window)))
-      (= (window-height window)
-        (window-height (frame-root-window (window-frame window))))))
-
-;; Workaround obsolete `process-kill-without-query'
-(if (fboundp 'set-process-query-on-exit-flag)
-    (defalias 'gnuplot-set-process-query-on-exit-flag 'set-process-query-on-exit-flag)
-  (defalias 'gnuplot-set-process-query-on-exit-flag 'process-kill-without-query))
-
-;; Workaround for missing syntax-ppss in XEmacs
-(if (fboundp 'syntax-ppss)
-    (defalias 'gnuplot-syntax-ppss 'syntax-ppss)
-  (defun gnuplot-syntax-ppss (&optional pos)
-      (save-excursion
-       (unless pos (setq pos (point)))
-       (let ((begin
-              (save-excursion
-                (goto-char pos)
-                (gnuplot-point-at-beginning-of-continuation))))
-         (parse-partial-sexp begin pos)))))
-
-\f
-;;;;
-(defconst gnuplot-xemacs-p (string-match "XEmacs" (emacs-version)))
-(defconst gnuplot-ntemacs-p (string-match "msvc" (emacs-version)))
-(defvar   gnuplot-three-eight-p "")
-
-(defconst gnuplot-maintainer "Jon Oddie")
-(defconst gnuplot-maintainer-url
-  "https://github.com/emacsorphanage/gnuplot/")
-(defconst gnuplot-version "0.7-beta")
-
-(defgroup gnuplot nil
-  "Gnuplot-mode for Emacs."
-  :prefix "gnuplot-"
-  :group 'processes
-  :group 'applications
-  :group 'local
-  :link '(emacs-library-link :tag "Lisp File" "gnuplot.el")
-  :link '(url-link :tag "Homepage"
-                  "https://github.com/emacsorphanage/gnuplot/")
-  :link '(custom-manual "(gnuplot)Top")
-  :link '(emacs-commentary-link :tag "Commentary" "gnuplot.el") )
-(defgroup gnuplot-insertions nil
-  "Insert commands into gnuplot-scripts from a pull-down menu."
-  :prefix "gnuplot-insertions-"
-  :group 'gnuplot)
-(defgroup gnuplot-hooks nil
-  "Hook variables used by `gnuplot-mode'."
-  :prefix "gnuplot-"
-  :group 'gnuplot)
-
-(defcustom gnuplot-mode-hook nil
-  "*Hook run when `gnuplot-mode' is entered."
-  :group 'gnuplot-hooks
-  :type 'hook)
-(defcustom gnuplot-load-hook nil
-  "*Hook run when gnuplot.el is first loaded."
-  :group 'gnuplot-hooks
-  :type 'hook)
-(defcustom gnuplot-after-plot-hook nil
-  "*Hook run after gnuplot plots something.
-This is the last thing done by the functions for plotting a line, a
-region, a buffer, or a file."
-  :group 'gnuplot-hooks
-  :type 'hook)
-
-
-(defcustom gnuplot-info-hook nil
-  "*Hook run before setting up the info-look interface.
-This hook is necessary to handle inconsistencies in versions of and
-sources of the gnuplot info file.  If Gnuplot-mode can find the info
-file generated from the 3.6beta patchlevel 347 (or later) release of
-Gnuplot, then this hook probably is not necessary.  Some versions of
-the info file may have a General Index session, which can be used by
-info-look.  In that case the following (or something similar with the
-value of `info-lookup-symbol-alist' altered appropriately) should be
-placed in the .emacs file.
-
-Emacs version 20.2 ships with a different version of info-look that
-does 20.3.  If you use any version of Emacs 19, you must use the
-version from 20.2.  Any version of XEmacs 20 or 21 should use the
-version from 20.3 but can use either.  XEmacs 19 should use the
-version 20.2.
-
-For the newer version of info-look, do this:
-
-  (add-hook \'gnuplot-info-hook
-           \'(lambda ()
-              (let ((elem (assoc \'gnuplot-mode info-lookup-alist)))
-                (delete elem info-lookup-alist)
-                (info-lookup-maybe-add-help
-                 :mode 'gnuplot-mode :topic 'symbol
-                 :regexp \"[a-zA-Z][_a-zA-Z0-9]*\"
-                 :doc-spec '((\"(gnuplot)General Index\" nil
-                              \"[_a-zA-Z0-9]+\"))))))
-
-For the older version of info-look, do this:
-
-  (add-hook \'gnuplot-info-hook
-           \'(lambda ()
-              (let ((elem (assoc \'gnuplot-mode info-lookup-alist)))
-                (delete elem info-lookup-alist)
-                (setq info-lookup-alist
-                      (append info-lookup-alist
-                              \'((gnuplot-mode
-                                 \"[a-zA-Z][_a-zA-Z0-9]*\" nil
-                                 ((\"(gnuplot)General Index\" nil
-                                   \"[_a-zA-Z0-9]+\" )))))))))"
-  :group 'gnuplot-hooks
-  :type 'hook)
-
-;; comint hook suggested by <DB>
-(defcustom gnuplot-comint-setup-hook nil
-  "*Hook run after setting up the gnuplot buffer in comint mode.
-So the configuration can be customised by the user."
-  :group 'gnuplot-hooks
-  :type 'hook)
-
-(defcustom gnuplot-comint-mode-hook nil
-  "*Hook run after setting up the gnuplot buffer in gnuplot-comint-mode.
-By default this runs the hook named `gnuplot-comint-setup-hook',
-for backward compatibility."
-  :group 'gnuplot-hooks
-  :type 'hook)
-
-(defvar gnuplot-recently-sent nil
-  "This is a record of the most recent kind of text sent to gnuplot.
-It takes as its value nil, 'line, 'region, 'buffer, or 'file.  It is
-useful for functions included in `gnuplot-after-plot-hook'.")
-(make-variable-buffer-local 'gnuplot-recently-sent)
-
-(defcustom gnuplot-program "gnuplot"
-  "*The name of the gnuplot executable."
-  :group 'gnuplot
-  :type 'string)
-(defvar gnuplot-program-version nil
-  "Version number of gnuplot.
-This is using `gnuplot-fetch-version-number'.")
-(defvar gnuplot-program-major-version nil
-  "Major version number of gnuplot.
-This is found using `gnuplot-fetch-version-number'.")
-(defvar gnuplot-program-minor-version nil
-  "Minor version number of gnuplot.
-This is found using `gnuplot-fetch-version-number'.")
-
-(defcustom gnuplot-process-name "gnuplot"
-  "Name given to the gnuplot buffer and process."
-  :group 'gnuplot
-  :type 'string)
-(defvar gnuplot-buffer nil
-  "*The name of the buffer displaying the gnuplot process.")
-(defvar gnuplot-process nil
-  "Variable holding the process handle.")
-(defvar gnuplot-process-frame nil
-  "The frame for displaying the gnuplot process.
-This is used when `gnuplot-display-process' is equal to 'frame.")
-(defvar gnuplot-comint-recent-buffer nil
-  "The most recently plotted gnuplot script buffer.
-This is used by the function that plot from the comint buffer.  It is
-reset every time something is plotted from a script buffer.")
-
-(defcustom gnuplot-gnuplot-buffer "plot.gp"
-  "*The name of the gnuplot scratch buffer opened by 'gnuplot-make-buffer'."
-  :group 'gnuplot
-  :type 'string)
-
-(defcustom gnuplot-display-process 'window
-  "This controls how the gnuplot process buffer is displayed.
-The values are
-   'frame    display gnuplot process in a separate frame
-   'window   display gnuplot process in this frame but in another window
-   nil       `gnuplot-process' is in the current frame but not displayed"
-  :group 'gnuplot
-  :type '(radio (const :tag "Separate frame"  frame)
-               (const :tag "Separate window" window)
-               (const :tag "Not displayed"   nil)))
-(defcustom gnuplot-info-display 'window
-  "*Determines how `gnuplot-info-lookup-symbol' displays the info file.
-The values are
-   'frame    display info file in a separate frame
-   'window   display info file in another window
-   nil       display info file in the current window"
-  :group 'gnuplot
-  :type '(radio (const :tag "Separate frame"  frame)
-               (const :tag "Separate window" window)
-               (const :tag "This window"     nil)))
-
-(defcustom gnuplot-echo-command-line-flag (not gnuplot-ntemacs-p)
-  "*This sets the fall-back value of `comint-process-echos'.
-If `gnuplot-mode' cannot figure out what version number of gnuplot
-this is, then the value of this variable will be used for
-`comint-process-echos'.  It seems that gnuplot 3.5 wants this to be
-nil and 3.7 wants it to be t.  If lines that you send to gnuplot from
-the `gnuplot-mode' buffer are not appearing at the gnuplot prompt in
-the process buffer, try toggling it.  Also see the document string for
-`comint-process-echos'.  If you change this, kill the gnuplot process
-and start it again."
-  :group 'gnuplot
-  :type 'boolean)
-(defcustom gnuplot-insertions-show-help-flag nil
-  "*Non-nil means to display certain help messages automatically.
-These messages are shown after menu insertion of gnuplot commands."
-  :group 'gnuplot-insertions
-  :type 'boolean)
-
-(defcustom gnuplot-delay 0.01
-  "*Amount of time to delay before sending a new line to gnuplot.
-This is needed so that the the line is not written in the gnuplot
-buffer in advance of its prompt.  Increase this number if the
-prompts and lines are displayed out of order."
-  :group 'gnuplot
-  :type 'number)
-(defcustom gnuplot-buffer-max-size 1000
-  "*The maximum size in lines of the gnuplot process buffer.
-Each time text is written in the gnuplot process buffer, lines are
-trimmed from the beginning of the buffer so that the buffer is this
-many lines long.  The lines are deleted after the most recent lines
-were interpretted by gnuplot.  Setting to 0 turns off this feature
-\(i.e. no lines get trimmed)."
-  :group 'gnuplot
-  :type 'integer)
-(defcustom gnuplot-quote-character "\'"
-  "*Quotation character used for inserting quoted strings.
-Gnuplot can use single or double quotes.  If you prefer to have the
-filename insertion function never insert quotes for you, set this
-to the empty string."
-  :group 'gnuplot
-  :type '(radio (const :tag "double quote"  "\"")
-               (const :tag "single quote"  "\'")
-               (const :tag "none"          ""  )))
-(defcustom gnuplot-basic-offset 4
-  "Number of columns to indent lines inside a do- or if-else-block.
-
-This applies only to new-style do- and if-statements using
-braces. Commands continued over a linebreak using a backslash are
-always indented to line up with the second word on the line
-beginning the continued command."
-  :group 'gnuplot
-  :type 'integer)
-
-;; (defcustom gnuplot-gnuplot-version nil
-;;   "*Force gnuplot-mode to behave for this version of gnuplot."
-;;   :group 'gnuplot
-;;   :type '(radio (const :tag "unspecified"   nil)
-;;             (const :tag "3.8 or newer" "3.8")
-;;             (const :tag "3.7 or older" "3.7")))
-
-(defvar gnuplot-info-frame nil)
-(defvar gnuplot-info-nodes '())
-
-(defvar gnuplot-first-call t)
-
-;; with info-look, there is no need to carry this list around -- it
-;; can be generated on the fly appropriate to the currently installed
-;; version of gnuplot.info
-(defvar gnuplot-keywords nil
-  "A list of keywords used in GNUPLOT.
-These are set by `gnuplot-set-keywords-list' from the values in
-`info-lookup-cache'.")
-(defvar gnuplot-keywords-alist nil) ;; For all-completions
-(defvar gnuplot-keywords-pending t     ;; <HW>
-  "A boolean which gets toggled when the info file is probed.")
-(defcustom gnuplot-keywords-when 'deferred ;; 'immediately
-  "This variable controls when the info file is parsed.
-The choices are immediately upon starting gnuplot-mode or the first
-time that data is needed."
-  :group 'gnuplot
-  :type
-  '(radio (const :tag "Parse info file when gnuplot-mode starts"    immediately)
-         (const :tag "Parse info file the first time it is needed" deferred)))
-
-(defun gnuplot-set-context-sensitive-completion (_variable value)
-  "Customize :set function for `gnuplot-use-context-sensitive-completion'."
-  (dolist (buffer (buffer-list))
-    (with-current-buffer buffer
-      (when (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
-        (gnuplot-context-sensitive-mode
-         (if value 1 0))))))
-
-(defcustom gnuplot-use-context-sensitive-completion t
-  "Non-nil if `gnuplot-context-sensitive-mode' should be enabled by default. 
-
-In context-sensitive mode, gnuplot-mode parses the current
-command line to provide smarter completion and documentation
-suggestions."
-  :group 'gnuplot
-  :type 'boolean
-  :initialize 'custom-set-default
-  :set 'gnuplot-set-context-sensitive-completion
-  :link '(emacs-commentary-link "gnuplot-context"))
-
-(defcustom gnuplot-eldoc-mode nil
-  "Non-nil if ElDoc mode should be enabled by default in Gnuplot buffers.
-ElDoc support requires `gnuplot-context-sensitive-mode' to be
-on."
-  :group 'gnuplot
-  :type 'boolean)
-  
-(defcustom gnuplot-tab-completion nil
-  "Non-nil if TAB should perform completion in gnuplot-mode buffers.
-
-Setting this to `t' sets the `tab-always-indent' variable to the
-symbol `complete' in gnuplot-mode buffers."
-  :group 'gnuplot
-  :type 'boolean)
-
-(defun gnuplot-set-display-mode (variable value &rest args)
-  "Customize :set function for `gnuplot-inline-image-mode'."
-  (if (and (eq variable 'gnuplot-inline-image-mode)
-           value
-           (not (gnuplot-display-images-p)))
-      (progn
-        (message "Displaying images is not supported.")
-        (set variable nil))
-    (set variable value))
-  (gnuplot-setup-comint-for-image-mode))
-
-(defcustom gnuplot-inline-image-mode nil
-  "Whether to display Gnuplot output in Emacs.
-
-Possible values are nil, `inline' and `dedicated'.
-
-When this is `nil', Gnuplot output is handled outside of Emacs in
-the normal way.  Otherwise, Emacs attempts to capture Gnuplot's
-output and display it in a buffer.  Output is inserted inline in
-the Gnuplot interaction buffer it this is `inline', in a
-separate dedicated buffer if it is `dedicated'.
-
-Use Customize to set this variable, or the commands
-`gnuplot-external-display-mode', `gnuplot-inline-display-mode',
-and `gnuplot-dedicated-display-mode'."
-  :group 'gnuplot
-  :type '(radio
-          (const :tag "No" nil)
-          (const :tag "In Comint buffer" inline)
-          (const :tag "In dedicated buffer" dedicated))
-  :initialize 'custom-initialize-default
-  :set 'gnuplot-set-display-mode)
-
-(defcustom gnuplot-image-format "png"
-  "Image format to use for displaying images within Emacs.
-
-This will be sent directly to Gnuplot as a command of the form
-\"set terminal <FORMAT>\".  Common values are \"png\" and
-\"svg\".
-
-This only has an effect when `gnuplot-inline-image-mode' is
-non-nil."
-  :group 'gnuplot
-  :type 'string
-  :initialize 'custom-initialize-default
-  :set 'gnuplot-set-display-mode)
-
-(defgroup gnuplot-faces nil
-  "Text faces used by gnuplot-mode."
-  :prefix "gnuplot-"
-  :group 'gnuplot)
-
-(defface gnuplot-prompt-face '((((class color))
-                                (:foreground "firebrick"))
-                               (t
-                                (:bold t :underline t)))
-  "Face used for the prompt in the gnuplot process buffer."
-  :group 'gnuplot-faces)
-
-\f
-;;; --- key bindings and menus
-
-(defvar gnuplot-mode-map
-  (let ((map (make-sparse-keymap))
-        (completion-function
-           (if (fboundp 'completion-at-point)
-               'completion-at-point
-             'gnuplot-xemacs-completion-at-point)))
-    (define-key map "\C-c\C-b"    'gnuplot-send-buffer-to-gnuplot)
-    (define-key map "\C-c\C-c"    'comment-region) ; <RF>
-    (define-key map "\C-c\C-o"    'gnuplot-gui-set-options-and-insert)
-    (define-key map "\C-c\C-w"    'gnuplot-show-version)
-    (define-key map "\C-c\C-e"    'gnuplot-show-gnuplot-buffer)
-    (define-key map "\C-c\C-f"    'gnuplot-send-file-to-gnuplot)
-    (define-key map "\C-c\C-d"    'gnuplot-info-lookup-symbol)
-    (define-key map "\C-c\C-i"    'gnuplot-insert-filename)
-    (define-key map "\C-c\C-j"    'gnuplot-forward-script-line)
-    (define-key map "\C-c\C-k"    'gnuplot-kill-gnuplot-buffer)
-    (define-key map "\C-c\C-l"    'gnuplot-send-line-to-gnuplot)
-    (define-key map "\C-c\C-n"    'gnuplot-negate-option)
-    (define-key map "\C-c\C-p"    'gnuplot-show-gnuplot-version)
-    (define-key map "\C-c\C-r"    'gnuplot-send-region-to-gnuplot)
-    (define-key map (kbd "C-M-x") 'gnuplot-send-line-to-gnuplot)
-    (define-key map "\C-c\C-v"    'gnuplot-send-line-and-forward)
-    (define-key map "\C-c\C-z"    'gnuplot-customize)
-    (define-key map "\C-i"        'indent-for-tab-command)
-    (define-key map "\C-m"        'newline-and-indent)
-    (define-key map "\C-c\M-i"    'gnuplot-inline-image-mode)
-    (define-key map (kbd "}")     'gnuplot-electric-insert)
-    (define-key map "\M-\r" completion-function)
-    (define-key map "\M-\t" completion-function)
-
-    (if gnuplot-xemacs-p
-        (define-key map '(shift button2) 'gnuplot-gui-mouse-set)
-      (define-key map [S-mouse-2] 'gnuplot-gui-mouse-set))
-
-    map))
-
-(defvar gnuplot-mode-menu nil)
-
-(defvar gnuplot-display-options-menu
-  (flet ((make-image-setter (type)
-           `[,(concat (upcase type) " images")
-              (lambda () (interactive) (gnuplot-set-image-format ,type))
-              :style toggle
-              :selected (eq gnuplot-image-format ,type)]))
-    `("Display plot output"
-      ["Externally" gnuplot-external-display-mode
-       :style toggle
-       :selected (null gnuplot-inline-image-mode)]
-      ["In Comint buffer" gnuplot-inline-display-mode
-       :active (gnuplot-display-images-p)
-       :style toggle
-       :selected (eq gnuplot-inline-image-mode 'comint)]
-      ["In dedicated buffer" gnuplot-dedicated-display-mode
-       :style toggle
-       :selected (eq gnuplot-inline-image-mode 'dedicated)]
-      "---"
-      ,@(mapcar #'make-image-setter (list "png" "jpeg" "svg"))
-      ["Other image type..." gnuplot-set-image-format])))
-
-(defvar gnuplot-menu
-  `("Gnuplot"
-    ["Send line to gnuplot"             gnuplot-send-line-to-gnuplot   t]
-    ["Send line & move forward"         gnuplot-send-line-and-forward (not (eobp))]
-    ["Send region to gnuplot"           gnuplot-send-region-to-gnuplot
-     (gnuplot-mark-active)]
-    ["Send buffer to gnuplot"           gnuplot-send-buffer-to-gnuplot t]
-    ["Send file to gnuplot"             gnuplot-send-file-to-gnuplot t]
-    "---"
-    ,gnuplot-display-options-menu
-    ["Contextual completion and help"   gnuplot-context-sensitive-mode
-     :style toggle
-     :selected gnuplot-context-sensitive-mode]
-    ["Echo area help (eldoc-mode)" eldoc-mode
-     :active gnuplot-context-sensitive-mode
-     :style toggle
-     :selected eldoc-mode]
-    "---"
-    ["Insert filename at point"         gnuplot-insert-filename t]
-    ["Negate set option"                gnuplot-negate-option t]
-    ;;["Set key binding"                gnuplot-set-binding gnuplot-three-eight-p]
-    ["Keyword help"                     gnuplot-info-lookup-symbol
-     (or gnuplot-keywords gnuplot-keywords-pending)]
-    ["Quick help for thing at point"    gnuplot-help-function
-     gnuplot-context-sensitive-mode]
-    ["Info documentation on thing at point"
-     gnuplot-info-at-point
-     gnuplot-context-sensitive-mode]
-    ["Show gnuplot process buffer"      gnuplot-show-gnuplot-buffer t]
-    ["Set arguments at point"           gnuplot-gui-set-options-and-insert
-     (fboundp 'gnuplot-gui-set-options-and-insert)]
-    ["Swap plot/splot/fit lists in GUI" gnuplot-gui-swap-simple-complete
-     (fboundp 'gnuplot-gui-swap-simple-complete)]
-    "---"
-    ["Customize gnuplot"                gnuplot-customize t]
-    ["Show gnuplot-mode version"        gnuplot-show-version t]
-    ["Show gnuplot version"             gnuplot-show-gnuplot-version t]
-    "---"
-    ["Kill gnuplot"                     gnuplot-kill-gnuplot-buffer t]
-    )
-  "Menu for `gnuplot-mode'.")
-
-
-\f
-;;; --- insertions variables and menus
-
-;;(load-library "gnuplot-insertions")
-(defvar gnuplot-mode-insertions-menu nil)
-(defvar gnuplot-insertions-menu nil
-  "Menu for insertions in `gnuplot-mode'.
-
-The insertions menu is composed of several sub-menus.  The variables
-describing the sub-menus are:
-  `gnuplot-insertions-adornments'
-  `gnuplot-insertions-plot-options'
-  `gnuplot-insertions-terminal'
-  `gnuplot-insertions-x-axis'
-  `gnuplot-insertions-y-axis'
-  `gnuplot-insertions-z-axis'
-  `gnuplot-insertions-x2-axis'
-  `gnuplot-insertions-y2-axis'
-  `gnuplot-insertions-parametric-plots'
-  `gnuplot-insertions-polar-plots'
-  `gnuplot-insertions-surface-plots'
-These variables can be customized by the user.  For example, there are
-many terminal types which are not in the terminal submenu but which
-may be compiled into a user's copy of gnuplot.
-
-Each of these variables is a list whose first element is a string and
-all the rest are vectors as described in the document string for
-`easy-menu-define'.  The callback used throughout these menus is
-`gnuplot-insert' which inserts the appropriate set expression and,
-optionally, looks up that item in the gnuplot info file.
-
-The easiest way to customize the submenus is to use the custom
-package.  Just type \\[gnuplot-customize] and follow your nose.
-
-You can also add new items to any of these sub-menus by adding to the
-`gnuplot-load-hook' in your .emacs file.  Here is an example of adding
-the \"regis\" terminal type to the terminal sub-menu:
-
- (add-hook
-  'gnuplot-load-hook
-  '(lambda ()
-      (setq gnuplot-insertions-terminal
-           (append gnuplot-insertions-terminal
-                   (list
-                    [\"regis\"
-                      (gnuplot-insert \"set terminal regis\")
-                       t])))))")
-
-(defvar gnuplot-insertions-top ()
-  "Top part of insertions menu.
-See the document string for `gnuplot-insertions-menu'")
-
-(defcustom gnuplot-insertions-menu-flag t
-  "*Non-nil means to place the insertion menu in the menubar.
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type 'boolean)
-
-(defcustom gnuplot-insertions-adornments ; this is icky...
-  (if gnuplot-three-eight-p
-      '("adornments"
-       ["arrow"       (gnuplot-insert "set arrow ")          t]
-       ["bar"         (gnuplot-insert "set bar")             t]
-       ["border"      (gnuplot-insert "set border")          t]
-       ["boxwidth"    (gnuplot-insert "set boxwidth ")       t]
-       ["format"      (gnuplot-insert "set format ")         t]
-       ["grid"        (gnuplot-insert "set grid")            t]
-       ["key"         (gnuplot-insert "set key ")            t]
-       ["label"       (gnuplot-insert "set label ")          t]
-       ["pointsize"   (gnuplot-insert "set pointsize ")      t]
-       ["samples"     (gnuplot-insert "set samples ")        t]
-       ["size"        (gnuplot-insert "set size ")           t]
-       ["style"       (gnuplot-insert "set style ")          t]
-       ["tics"        (gnuplot-insert "set tics ")           t]
-       ["timefmt"     (gnuplot-insert "set timefmt ")        t]
-       ["timestamp"   (gnuplot-insert "set timestamp ")      t]
-       ["title"       (gnuplot-insert "set title ")          t]
-       ["zeroaxis"    (gnuplot-insert "set zeroaxis")        t] )
-    '("adornments"
-      ["data style"     (gnuplot-insert "set data style ")     t]
-      ["function style" (gnuplot-insert "set function style ") t]
-      ["arrow"          (gnuplot-insert "set arrow ")         t]
-      ["bar"           (gnuplot-insert "set bar")             t]
-      ["border"         (gnuplot-insert "set border")         t]
-      ["boxwidth"       (gnuplot-insert "set boxwidth ")       t]
-      ["format"         (gnuplot-insert "set format ")        t]
-      ["grid"          (gnuplot-insert "set grid")            t]
-      ["key"           (gnuplot-insert "set key ")            t]
-      ["label"          (gnuplot-insert "set label ")         t]
-      ["pointsize"      (gnuplot-insert "set pointsize ")      t]
-      ["samples"        (gnuplot-insert "set samples ")               t]
-      ["size"           (gnuplot-insert "set size ")          t]
-      ["tics"           (gnuplot-insert "set tics ")          t]
-      ["timefmt"        (gnuplot-insert "set timefmt ")        t]
-      ["timestamp"      (gnuplot-insert "set timestamp ")      t]
-      ["title"          (gnuplot-insert "set title ")         t]
-      ["zeroaxis"       (gnuplot-insert "set zeroaxis")        t] ))
-  "Adornments submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-       :group 'gnuplot-insertions
-       :type '(list (string :tag "Title")
-                    (repeat :inline t
-                            (vector (string   :tag "Name")
-                                    (function :tag "Callback")
-                                    (boolean  :tag "Enabled" t)))))
-
-
-
-(defcustom gnuplot-insertions-plot-options
-  '("plot options"
-    ["autoscale"  (gnuplot-insert "set autoscale ")         t]
-    ["clip"      (gnuplot-insert "set clip ")               t]
-    ["encoding"   (gnuplot-insert "set encoding ")          t]
-    ["locale"     (gnuplot-insert "set locale ")            t]
-    ["logscale"          (gnuplot-insert "set logscale ")           t]
-    ["multiplot"  (gnuplot-insert "set multiplot")          t]
-    ["missing"   (gnuplot-insert "set missing \"\"")        t]
-    ["palette"    (gnuplot-insert "set palette ")            t]        ; <MT>
-    ["pm3d"       (gnuplot-insert "set pm3d ")               t]
-    ["offsets"   (gnuplot-insert "set offsets ")            t]
-    ["output"     (gnuplot-insert "set output ")            t]
-    ["zero"      (gnuplot-insert "set zero ")               t] )
-  "Plot options submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-terminal
-  '("terminal"
-    ["eepic"      (gnuplot-insert "set terminal eepic")      t]
-    ["fig"        (gnuplot-insert "set terminal fig")        t]
-    ["gpic"       (gnuplot-insert "set terminal gpic")       t]
-    ["latex"      (gnuplot-insert "set terminal latex")      t]
-    ["linux"      (gnuplot-insert "set terminal linux")      t]
-    ["pbm"        (gnuplot-insert "set terminal pbm")        t]
-    ["png"        (gnuplot-insert "set terminal png")        t]
-    ["postscript" (gnuplot-insert "set terminal postscript") t]
-    ["pslatex"    (gnuplot-insert "set terminal pslatex")    t]
-    ["table"      (gnuplot-insert "set terminal table")      t]
-    ["tek40xx"    (gnuplot-insert "set terminal tek40xx")    t]
-    ["tkcanvas"   (gnuplot-insert "set terminal tkcanvas")   t]
-    ["tpic"       (gnuplot-insert "set terminal tpic")       t]
-    ["vgagl"      (gnuplot-insert "set terminal vgagl")      t]        ; for pm3d patch
-    ["vttek"      (gnuplot-insert "set terminal vttek")      t]
-    ["x11"        (gnuplot-insert "set terminal x11")        t] )
-  "Terminal submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-x-axis
-  '("x-axis"
-    ["xdata"     (gnuplot-insert "set xdata ")              t]
-    ["xlabel"    (gnuplot-insert "set xlabel ")             t]
-    ["xrange"    (gnuplot-insert "set xrange [:]")          t]
-    ["xtics"     (gnuplot-insert "set xtics ")              t]
-    ["mxtics"    (gnuplot-insert "set mxtics ")             t]
-    ["xzeroaxis"  (gnuplot-insert "set xzeroaxis ")         t]
-    ["xdtics"    (gnuplot-insert "set xdtics ")             t]
-    ["xmtics"    (gnuplot-insert "set xmtics ")             t])
-  "X-axis submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-x2-axis
-  '("x2-axis"
-    ["x2data"    (gnuplot-insert "set xdata ")              t]
-    ["x2label"   (gnuplot-insert "set xlabel ")             t]
-    ["x2range"   (gnuplot-insert "set xrange [:]")          t]
-    ["x2tics"    (gnuplot-insert "set xtics ")              t]
-    ["mx2tics"   (gnuplot-insert "set mxtics ")             t]
-    ["x2zeroaxis" (gnuplot-insert "set xzeroaxis ")         t]
-    ["x2dtics"   (gnuplot-insert "set xdtics ")             t]
-    ["x2mtics"   (gnuplot-insert "set xmtics ")             t])
-  "X2-axis submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-y-axis
-  '("y-axis"
-    ["ydata"     (gnuplot-insert "set ydata ")              t]
-    ["ylabel"    (gnuplot-insert "set ylabel ")             t]
-    ["ymtics"    (gnuplot-insert "set ymtics ")             t]
-    ["yrange"    (gnuplot-insert "set yrange [:]")          t]
-    ["ytics"     (gnuplot-insert "set ytics ")              t]
-    ["yzeroaxis"  (gnuplot-insert "set yzeroaxis ")         t]
-    ["ydtics"    (gnuplot-insert "set ydtics ")             t]
-    ["mytics"    (gnuplot-insert "set mytics ")             t])
-  "Y-axis submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-(defcustom gnuplot-insertions-y2-axis
-  '("y2-axis"
-    ["y2data"    (gnuplot-insert "set ydata ")              t]
-    ["y2label"   (gnuplot-insert "set ylabel ")             t]
-    ["y2range"   (gnuplot-insert "set yrange [:]")          t]
-    ["y2tics"    (gnuplot-insert "set ytics ")              t]
-    ["my2tics"   (gnuplot-insert "set mytics ")             t]
-    ["y2zeroaxis"  (gnuplot-insert "set yzeroaxis ")        t]
-    ["y2mtics"   (gnuplot-insert "set ymtics ")             t]
-    ["y2dtics"   (gnuplot-insert "set ydtics ")             t])
-  "Y2-axis submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-
-(defcustom gnuplot-insertions-z-axis
-  '("z-axis"
-    ["zdata"     (gnuplot-insert "set zdata ")              t]
-    ["zlabel"    (gnuplot-insert "set zlabel ")             t]
-    ["zrange"    (gnuplot-insert "set zrange [:]")          t]
-    ["ztics"     (gnuplot-insert "set ztics ")              t]
-    ["mztics"    (gnuplot-insert "set mztics ")             t]
-    ["zdtics"    (gnuplot-insert "set zdtics ")             t]
-    ["zmtics"    (gnuplot-insert "set zmtics ")             t] )
-  "Z-axis submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-parametric-plots
-  '("parametric plots"
-    ["parametric" (gnuplot-insert "set parametric")         t]
-    ["isosamples" (gnuplot-insert "set isosamples ")        t]
-    ["dummy"     (gnuplot-insert "set dummy ")              t]
-    ["trange"    (gnuplot-insert "set trange [:]")          t]
-    ["urange"    (gnuplot-insert "set urange [:]")          t]
-    ["vrange"    (gnuplot-insert "set vrange [:]")          t] )
-  "Parametric plots submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-polar-plots
-  '("polar plots"
-    ["polar"     (gnuplot-insert "set polar")               t]
-    ["angles"    (gnuplot-insert "set angles ")             t]
-    ["rrange"    (gnuplot-insert "set rrange [:]")          t] )
-  "Polar plots submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-(defcustom gnuplot-insertions-surface-plots
-  '("surface plots"
-    ["clabel"    (gnuplot-insert "set clabel ")             t]
-    ["cntrparam"  (gnuplot-insert "set cntrparam ")         t]
-    ["contour"   (gnuplot-insert "set contour")             t]
-    ["dgrid3d"   (gnuplot-insert "set dgrid3d ")            t]
-    ["hidden3d"          (gnuplot-insert "set hidden3d ")           t]
-    ["mapping"   (gnuplot-insert "set mapping ")            t]
-    ["surface"   (gnuplot-insert "set surface ")            t]
-    ["view"      (gnuplot-insert "set view ")               t] )
-  "Surface plots submenu in the insertions menu.
-See the document string for `gnuplot-insertions-menu'
-Changing this will not effect a change in any currently existing
-`gnuplot-mode' buffer.  You will see the change the next time you
-create a `gnuplot-mode' buffer."
-  :group 'gnuplot-insertions
-  :type '(list (string :tag "Title")
-              (repeat :inline t
-                      (vector (string   :tag "Name")
-                              (function :tag "Callback")
-                              (boolean  :tag "Enabled" t)))))
-
-
-
-(defvar gnuplot-insertions-bottom ()
-  "Bottom part of the insertions menu.
-This part contains the toggle buttons for displaying info or
-opening an argument-setting popup.")
-(setq gnuplot-insertions-bottom
-      '("---"
-       ["Display of info with insertion" gnuplot-toggle-info-display
-        :style toggle :selected gnuplot-insertions-show-help-flag]
-       ["Display GUI popup with insertion" gnuplot-gui-toggle-popup
-        :active (fboundp 'gnuplot-gui-toggle-popup)
-        :style toggle :selected (and (fboundp 'gnuplot-gui-toggle-popup)
-                                     gnuplot-gui-popup-flag)] ))
-
-
-;; Regarding a comment by <DB>:
-;;
-;; This is from the header in easymenu.el distributed with XEmacs:
-;;
-;; ;; - Function: easy-menu-add MENU [ MAP ]
-;; ;;     Add MENU to the current menubar in MAP.
-;; ;;
-;; ;; - Function: easy-menu-remove MENU
-;; ;;     Remove MENU from the current menubar.
-;; ;;
-;; ;; Emacs 19 never uses `easy-menu-add' or `easy-menu-remove', menus
-;; ;; automatically appear and disappear when the keymaps specified by
-;; ;; the MAPS argument to `easy-menu-define' are activated.
-;; ;;
-;; ;; XEmacs will bind the map to button3 in each MAPS, but you must
-;; ;; explicitly call `easy-menu-add' and `easy-menu-remove' to add and
-;; ;; remove menus from the menu bar.
-;;
-;; in Emacs, easy-menu-add is defined like this:
-;;      (defun easy-menu-add (menu &optional map))
-
-(defun gnuplot-setup-menubar ()
-  "Initial setup of gnuplot and insertions menus."
-  (if gnuplot-insertions-menu-flag     ; set up insertions menu
-      (progn
-       (if gnuplot-xemacs-p
-           (setq gnuplot-insertions-top
-                 '("insert set expression" "--:doubleLine"))
-         (setq gnuplot-insertions-top
-               '("insert set expression" "---")))
-       (setq gnuplot-insertions-menu
-             (append (list "Insertions")
-                     gnuplot-insertions-top
-                     (list gnuplot-insertions-adornments)
-                     (list gnuplot-insertions-plot-options)
-                     (list gnuplot-insertions-terminal)
-                     (list gnuplot-insertions-x-axis)
-                     (list gnuplot-insertions-y-axis)
-                     (list gnuplot-insertions-z-axis)
-                     (list gnuplot-insertions-x2-axis)
-                     (list gnuplot-insertions-y2-axis)
-                     (list gnuplot-insertions-parametric-plots)
-                     (list gnuplot-insertions-polar-plots)
-                     (list gnuplot-insertions-surface-plots)
-                     gnuplot-insertions-bottom))
-       (easy-menu-define gnuplot-mode-insertions-menu gnuplot-mode-map
-                         "Insertions menu used in Gnuplot-mode"
-                         gnuplot-insertions-menu)
-       (easy-menu-add gnuplot-mode-insertions-menu gnuplot-mode-map)))
-  (easy-menu-define                    ; set up gnuplot menu
-   gnuplot-mode-menu gnuplot-mode-map "Menu used in gnuplot-mode"
-   gnuplot-menu)
-  (easy-menu-add gnuplot-mode-menu gnuplot-mode-map) )
-
-;; There is no `mark-active' variable in XEmacs.  Hassle!  This is not
-;; only replicates mark-active, but it only returns true if the region
-;; is of non-zero width.
-;; Error checking suggested by <DB>
-(defun gnuplot-mark-active ()
-  "Return non-nil if the mark is active and it is not equal to point."
-  (condition-case nil
-      (and (mark) (/= (mark) (point)))
-    (error nil)))
-
-\f
-;;; --- XEmacs toolbar
-
-(defgroup gnuplot-toolbar nil
-  "Toolbar used by XEmacs."
-  :prefix "gnuplot-toolbar-"
-  :group 'gnuplot)
-
-(defcustom gnuplot-toolbar-display-flag gnuplot-xemacs-p
-  "*Non-nil means to display display a toolbar in XEmacs."
-  :group 'gnuplot-toolbar
-  :type 'boolean)
-
-(defcustom gnuplot-toolbar-use-toolbar (if (featurep 'toolbar) 'left-toolbar nil)
-  "*If nil, do not use a toolbar.
-If it is non-nil, it must be a toolbar.  The five legal values are
-`default-toolbar', `top-toolbar', `bottom-toolbar', `right-toolbar',
-and `left-toolbar', although choosing `default-toolbar' or
-`top-toolbar' may be a bad idea since either will make the GNUPLOT
-toolbar replace the standard toolbar.  Changing this will not change
-the toolbar in a currently existing buffer, but it will take effect
-the next time you use `gnuplot-mode' and emacs.
-
-This is only used if a toolbar can be displayed, thus this is used in
-XEmacs and ignored in FSF Emacs."
-  :type '(choice (const default-toolbar)
-                (const top-toolbar)
-                (const bottom-toolbar)
-                (const left-toolbar)
-                (const right-toolbar)
-                (const :tag "No toolbar" nil))
-  :group 'gnuplot-toolbar)
-
-(defvar gnuplot-toolbar-location "")
-
-(defun gnuplot-toolbar-setup-toolbar (toolbar)
-  "Setup function for the `gnuplot-mode' toolbar.
-TOOLBAR contains the toolbar specification.
-This is basically swiped from VM."
-  (let ((width 46) (height 46)
-       (buffer (current-buffer))
-       (frame (selected-frame))
-       (tag-set '(win)))
-    (cond
-     ((eq (symbol-value gnuplot-toolbar-use-toolbar) right-toolbar)
-      (setq gnuplot-toolbar-location       "right")
-      (set-specifier right-toolbar         toolbar buffer)
-      (set-specifier right-toolbar-width   width frame  tag-set))
-     ((eq (symbol-value gnuplot-toolbar-use-toolbar) left-toolbar)
-      (setq gnuplot-toolbar-location       "left")
-      (set-specifier left-toolbar          toolbar buffer)
-      (set-specifier left-toolbar-width    width frame  tag-set))
-     ((eq (symbol-value gnuplot-toolbar-use-toolbar) bottom-toolbar)
-      (setq gnuplot-toolbar-location       "bottom")
-      (set-specifier bottom-toolbar        toolbar buffer)
-      (set-specifier bottom-toolbar-height height frame tag-set))
-     ((eq (symbol-value gnuplot-toolbar-use-toolbar) top-toolbar)
-      (setq gnuplot-toolbar-location       "top")
-      (set-specifier top-toolbar           toolbar buffer)
-      (set-specifier top-toolbar-height    height frame tag-set))) ))
-
-(defvar gnuplot-line-xpm
-  (if (featurep 'xpm)
-      (toolbar-make-button-list
-       "/* XPM */
-static char *line[] = {
-/* width height num_colors chars_per_pixel */
-\"    40    40        5           1\",
-/* colors */
-\". c #000000\",
-\"a c #bebebe s backgroundToolBarColor\",
-\"b c #2f4f4f\",
-\"c c #ff6347\",
-\"d c #0000ff\",
-/* pixels */
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaa..a..aaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaa..a..a....aaa...aaaaaaaaaaaa\",
-\"aaaaaaaaaaaa..a..a..a..a..a..aaaaaaaaaaa\",
-\"aaaaaaaaaaaa..a..a.aa..a.....aaaaaaaaaaa\",
-\"aaaaaaaaaaa..a..a..a..a..aaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaa..a..a..a..a..a..aaaaaaaaaaaa\",
-\"aaaaaaaaaaa..a..a..a..aa...aaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
-\"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
-\"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
-\"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
-\"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
-\"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaa............................aaaaaa\",
-\"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
-  "XPM format image used for the \"plot line\" button"))
-
-(defvar gnuplot-region-xpm
-  (if (featurep 'xpm)
-      (toolbar-make-button-list
-       "/* XPM */
-static char *region[] = {
-/* width height num_colors chars_per_pixel */
-\"    40    40        5           1\",
-/* colors */
-\". c #000000\",
-\"a c #bebebe s backgroundToolBarColor\",
-\"b c #2f4f4f\",
-\"c c #ff6347\",
-\"d c #0000ff\",
-/* pixels */
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaa..aaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaa.a..a...aaa....a..aa...aa....aaaaa\",
-\"aaaaaa...a..a..a..a..a..a..a..a..a..aaaa\",
-\"aaaaaa..aa.....a.aa..a....aa..a.aa..aaaa\",
-\"aaaaa..a...aaaa..aa.a..a..aa....a..aaaaa\",
-\"aaaaa..a...a..a..a..a..a..a..a..a..aaaaa\",
-\"aaaa..aaaa...aaa....a..aa...aa..a..aaaaa\",
-\"aaaaaaaaaaaaaaaaa..aaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
-\"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
-\"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
-\"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
-\"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
-\"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaa............................aaaaaa\",
-\"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
-  "XPM format image used for the \"plot region\" button"))
-
-(defvar gnuplot-buffer-xpm
-  (if (featurep 'xpm)
-      (toolbar-make-button-list
-       "/* XPM */
-static char *buffer[] = {
-/* width height num_colors chars_per_pixel */
-\"    40    40        5           1\",
-/* colors */
-\". c #000000\",
-\"a c #bebebe s backgroundToolBarColor\",
-\"b c #2f4f4f\",
-\"c c #ff6347\",
-\"d c #0000ff\",
-/* pixels */
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa..aaaaaaaaaa......aaaaaaaaaaaaaa\",
-\"aaaaaaaa..aaaaaaaaa..a..aaaaaaaaaaaaaaaa\",
-\"aaaaaaa....aa..a.........a...aa.a.aaaaaa\",
-\"aaaaaaa..a..a..a..a..a..a..a..a...aaaaaa\",
-\"aaaaaaa.aa....aa..a..a..a.....a..aaaaaaa\",
-\"aaaaaa...a.a..a..a..a..a..aaaa..aaaaaaaa\",
-\"aaaaaa.....a..a..a..a..a..a..a..aaaaaaaa\",
-\"aaaaaa....aaa..a.a..a..aa...aa..aaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaadaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaadaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaadaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaadaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaacaaaadaadaaaaaaaaaaaa\",
-\"aaaaaaaa.caaadaaaccaccadaddaaaaaccaaaaaa\",
-\"aaaaaaa..accdaddcaaaaaccaaaaaaccaaaaaaaa\",
-\"aaaaaaaa.aadcaccdaaaadaaccaaccaaaaaaaaaa\",
-\"aaaaaaaa.adaacaaaddadaaaaaccaaaaaaaaaaaa\",
-\"aaaaaaaa.daaaaaaaaadaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaa..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaa............................aaaaaa\",
-\"aaaaaaaa.aaaa.aaaa.aaaa.aaaa.aaaaaaaaaaa\",
-\"aaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
-  "XPM format image used for the \"plot buffer\" button"))
-
-(defvar gnuplot-doc-xpm
-  (if (featurep 'xpm)
-      (toolbar-make-button-list
-       "/* XPM */
-static char *book_index[] = {
-/* width height num_colors chars_per_pixel */
-\"    40    40        6            1\",
-/* colors */
-\". c #000000\",
-\"a c #bebebe s backgroundToolBarColor\",
-\"b c #2f4f4f\",
-\"c c #ff0000\",
-\"d c #ffffff\",
-\"e c #708090\",
-/* pixels */
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaa.........bbeaaaebb..........aaaaaa\",
-\"aaaaaa.ddddddddaaebebeaaddddddddd.aaaaaa\",
-\"aaaa...dab.bddeebadbdaeebedeeeeed...aaaa\",
-\"aaaa.c.dbaddddebeedbdeebeedebebed.c.aaaa\",
-\"aaaa.c.d.de.edeebeabdbbeeddebbbed.c.aaaa\",
-\"aaaa.c.dbad.ddebeadbdeeebeddeeeed.c.aaaa\",
-\"aaaa.c.dab..ddeeeedbdebeeedebebed.c.aaaa\",
-\"aaaa.c.dddddddeebeabdebebedeebedd.c.aaaa\",
-\"aaaa.c.debebedebeedbdbebeedbeeeeb.c.aaaa\",
-\"aaaa.c.debeeedeeeaabdaaddddebedbb.c.aaaa\",
-\"aaaa.c.deebeddbebedbdbaa.adeeedeb.c.aaaa\",
-\"aaaa.c.ddeebedeeebaba.dd.dddeeedd.c.aaaa\",
-\"aaaa.c.debeebdbeeedbd....ddeebeed.c.aaaa\",
-\"aaaa.c.deebeedeebadbd.dd.ddeeeedd.c.aaaa\",
-\"aaaa.c.dbbebddeeeeabd.aa.adebebbd.c.aaaa\",
-\"aaaa.c.deeeeedeebeabaedddddeeeedd.c.aaaa\",
-\"aaaa.c.dbebbbdebeadbdaeeeedebeeed.c.aaaa\",
-\"aaaa.c.deeebddeeebdbdeebeedeebeed.c.aaaa\",
-\"aaaa.c.debeeedebeeabdebebedebeebd.c.aaaa\",
-\"aaaa.c.deebbedeeeedbdeeeeddeeeeed.c.aaaa\",
-\"aaaa.c.dddddddddaadbdaddddddddddd.c.aaaa\",
-\"aaaa.c..........beabaeb...........c.aaaa\",
-\"aaaa.c.bbbbbbbbbb.bbbbbbbbbbbbbbb.c.aaaa\",
-\"aaaa.c.bbbbbbbbbb..e.bbbbbbbbbbbb.c.aaaa\",
-\"aaaa.c.bbbbbbbbbb.b.bbbbbbbbbbbbb.c.aaaa\",
-\"aaaa.c............e.e.............c.aaaa\",
-\"aaaa.cccccccccccc.a.a.ccccccccccccc.aaaa\",
-\"aaaa................................aaaa\",
-\"aaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
-  "XPM format image used for the \"document\" button"))
-
-(defvar gnuplot-help-xpm
-  (if (featurep 'xpm)
-      (toolbar-make-button-list
-       "/* XPM */
-static char *help_btn[] = {
-/* width height num_colors chars_per_pixel */
-\"    40    40        3            1\",
-/* colors */
-\"a c #bebebe s backgroundToolBarColor\",
-\"b c #000000\",
-\"c c #ff0000\",
-/* pixels */
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaabbbccccccccbbbaaaaaaaaaaaaa\",
-\"aaaaaaaaaaabbccccccccccccccbbaaaaaaaaaaa\",
-\"aaaaaaaaaabccccccccccccccccccbaaaaaaaaaa\",
-\"aaaaaaaaabccccccccccccccccccccbaaaaaaaaa\",
-\"aaaaaaaabcccccccbbbbbbbbcccccccbaaaaaaaa\",
-\"aaaaaaaabccccbbbaaaaaaaabbbccccbaaaaaaaa\",
-\"aaaaaaabccccbaaaaaaaaaaaaaabccccbaaaaaaa\",
-\"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
-\"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
-\"aaaaaaabcccbaaaaaaaaaaaaaaaabcccbaaaaaaa\",
-\"aaaaaaabbbbbaaaaaaaaaaaaaaabccccbaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaabbbccccbaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabbbbbbbbcccccccbaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabcccccccccccccbaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccccccccccbaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccccccccbbaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbbbbbbaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabccccbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaabbbbbbaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
-\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};")
-  "XPM format image used for the \"help\" button"))
-
-(defvar gnuplot-toolbar
-  '([gnuplot-line-xpm
-     gnuplot-line-fn     t     "Plot the line under point"]
-    [gnuplot-region-xpm
-     gnuplot-region-fn   t     "Plot the selected region"]
-    [gnuplot-buffer-xpm
-     gnuplot-buffer-fn   t     "Plot the entire buffer"]
-    [:style 3d :size 8]
-    [gnuplot-help-xpm
-     gnuplot-help-fn     t     "Look at the gnuplot process buffer"]
-    [gnuplot-doc-xpm
-     gnuplot-doc-fn      t     "Look at the gnuplot document"])
-  "The gnuplot toolbar.")
-
-(fset 'gnuplot-line-fn   'gnuplot-send-line-and-forward)
-(fset 'gnuplot-region-fn 'gnuplot-send-region-to-gnuplot)
-(fset 'gnuplot-buffer-fn 'gnuplot-send-buffer-to-gnuplot)
-(fset 'gnuplot-help-fn   'gnuplot-show-gnuplot-buffer)
-(fset 'gnuplot-doc-fn    'gnuplot-info-lookup-symbol)
-
-(defvar gnuplot-all-buttons-defined
-  (and (listp gnuplot-line-xpm)   (listp gnuplot-region-xpm)
-       (listp gnuplot-buffer-xpm) (listp gnuplot-doc-xpm)
-       (listp gnuplot-help-xpm)))
-
-
-(defun gnuplot-make-toolbar-function ()
-  (if (and gnuplot-xemacs-p gnuplot-all-buttons-defined)
-      (progn
-       ;;(remove-specifier gnuplot-toolbar-use-toolbar (current-buffer))
-       (gnuplot-toolbar-setup-toolbar gnuplot-toolbar)
-       (add-spec-to-specifier (symbol-value gnuplot-toolbar-use-toolbar)
-                              gnuplot-toolbar
-                              (current-buffer) ))))
-
-;;(defalias 'gnuplot-make-toolbar 'gnuplot-make-toolbar-function)
-
-
-\f
-;;; --- syntax colorization, syntax table
-
-(defvar gnuplot-mode-syntax-table
-  (let ((table (make-syntax-table)))
-    (modify-syntax-entry ?* "." table)
-    (modify-syntax-entry ?+ "." table)
-    (modify-syntax-entry ?- "." table)
-    (modify-syntax-entry ?/ "." table)
-    (modify-syntax-entry ?% "." table)
-    (modify-syntax-entry ?= "." table)
-    (modify-syntax-entry ?: "." table)
-    (modify-syntax-entry ?& "." table ) ; rarely used
-    (modify-syntax-entry ?^ "." table ) ; operators
-    (modify-syntax-entry ?| "." table ) ; in gnuplot,
-    (modify-syntax-entry ?& "." table ) ; (by me,
-    (modify-syntax-entry ?? "." table ) ;  anyway...)
-    (modify-syntax-entry ?~ "." table ) ;
-
-    (modify-syntax-entry ?_ "w" table )
-
-    ;; In GNU Emacs >=24 we can use `syntax-propertize-function' to
-    ;; accurately scan for strings and comments (see
-    ;; `gnuplot-syntax-propertize').  If there's no
-    ;; `syntax-propertize', fall back to using the built-in parser and
-    ;; making ", ', and # string or comment delimiters as normal.
-    (if (not (boundp 'syntax-propertize-function))
-       (progn
-         (modify-syntax-entry ?\' "\"" table)
-         (modify-syntax-entry ?# "<" table)
-         (modify-syntax-entry ?\n ">" table)
-         (modify-syntax-entry ?\\ "\\" table))
-
-      ;; When syntax-propertize is available, ", ', and # should be
-      ;; punctuation so that the built-in parser doesn't interfere
-      ;; with the syntax-propertize search.
-      (modify-syntax-entry ?\" "." table)
-      (modify-syntax-entry ?\' "." table)
-      (modify-syntax-entry ?` "." table)
-      (modify-syntax-entry ?\\ "." table))
-
-    table)
-
-  "Syntax table in use in `gnuplot-mode' buffers.
-This is the same as the standard syntax table except that ` and _
-are word characters, and math operators are punctuation
-characters.")
-
-;; Macro to generate efficient regexps for keyword matching
-;;
-;; These regular expressions treat the gnuplot vocabulary as complete
-;; words.  Although gnuplot will recognise unique abbreviations, these
-;; regular expressions will not.
-(defmacro gnuplot-make-regexp (list)
-  `(regexp-opt ,list 'words))
-
-;; Lists of gnuplot keywords for syntax coloring etc.
-(defvar gnuplot-keywords-builtin-functions
-  '("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" "EllipticPi" "EllipticE" "EllipticK" "words" "word" "value"
-    "timecolumn" "substr" "strstrt" "strptime" "strlen" "stringcolumn"
-    "strftime" "sprintf" "lambertw" "gprintf" "exists" "defined" "columnhead")
-
-  "List of GNUPLOT built-in functions, as strings.
-
-These are highlighted using `font-lock-function-name-face'.")
-
-(defvar gnuplot-keywords-plotting
-  '("axes" "every" "index" "lw" "lt" "ls" "linestyle" "linetype" "linewidth"
-    "notitle" "pt" "ps" "pointsize" "pointtype" "smooth" "thru" "title" "using"
-    "with" "noautoscale" "volatile" "matrix" "nonuniform" "binary" "fillstyle"
-    "linecolor" "pointinterval" "nosurface" "nocontours" "nohidden3d")
-  "List of GNUPLOT keywords associated with plotting, as strings.
-
-These are highlighted using `font-lock-type-face'.
-This list does not include plotting styles -- for that, see 
-`gnuplot-keywords-plotting-styles'")
-
-(defvar gnuplot-keywords-plotting-styles
-  '("boxerrorbars" "boxes" "boxxyerrorbars" "candlesticks" "dots" "errorbars"
-    "financebars" "fsteps" "histeps" "impulses" "lines" "linespoints" "points"
-    "steps" "vector" "xerrorbars" "xyerrorbars" "yerrorbars" "vectors"
-    "filledcurves" "labels" "rgbalpha" "rgbimage" "image" "circles" "pm3d"
-    "histograms" "xyerrorlines" "xerrorlines" "errorlines" "yerrorlines")
-
-  "List of GNUPLOT plotting styles, as strings.
-
-These are highlighted using `font-lock-function-name-face'.")
-
-(defvar gnuplot-keywords-misc
-  '("bind" "cd" "clear" "exit" "fit" "help" "history" "load" "pause" "print"
-    "pwd" "quit" "replot" "save" "set" "show" "unset" "if" "else" "do" "update"
-    "undefine" "test" "system" "raise" "lower" "eval" "shell" "reset" "reread"
-    "refresh" "call")
-  "List of GNUPLOT miscellaneous commands, as strings.
-
-These are highlighted using `font-lock-constant-face'.")
-
-(defvar gnuplot-keywords-negatable-options
-  '("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")
-
-  "List of gnuplot options which can be negated using `gnuplot-negate-option'")
-
-(defvar gnuplot-negatable-options-regexp
-  (gnuplot-make-regexp gnuplot-keywords-negatable-options))
-
-;; Set up colorization for gnuplot.
-;; This handles font-lock for emacs and xemacs.
-(defvar gnuplot-font-lock-keywords nil)
-(defvar gnuplot-font-lock-syntactic-keywords nil)
-(defvar gnuplot-font-lock-defaults nil)
-
-(when (featurep 'font-lock)            ; <KL>
-  (setq gnuplot-font-lock-keywords
-       (list
-        ;; stuff in brackets, sugg. by <LB>
-        '("\\[\\([^]]+\\)\\]" 1 font-lock-constant-face)
-
-        ;; variable/function definitions
-        '("\\(\\(\\sw\\|\\s_\\)+\\s-*\\((\\s-*\\(\\sw\\|\\s_\\)*\\s-*\\(,\\s-*\\sw*\\)*\\s-*)\\)?\\s-*=\\)[^=]"
-          1 font-lock-variable-name-face)
-
-        ;; built-in function names
-        (cons (gnuplot-make-regexp gnuplot-keywords-builtin-functions)
-              font-lock-function-name-face)
-
-        ;; reserved words associated with plotting <AL>
-        (cons (gnuplot-make-regexp gnuplot-keywords-plotting)
-              font-lock-type-face)
-        (cons (gnuplot-make-regexp gnuplot-keywords-plotting-styles)
-              font-lock-function-name-face)
-
-        ;; (s)plot -- also thing (s)plotted
-        '("\\<s?plot\\>" . font-lock-keyword-face)
-        ;; '("\\<s?plot\\s-+\\([^'\" ]+\\)[) \n,\\\\]"
-        ;;   1 font-lock-variable-name-face)
-
-        ;; other common commands
-        (cons (gnuplot-make-regexp gnuplot-keywords-misc)
-              font-lock-constant-face)
-        (cons "!.*$" font-lock-constant-face))) ; what is this for? jjo
-      
-  (setq gnuplot-font-lock-defaults 
-       '(gnuplot-font-lock-keywords
-         nil                           ; Use syntactic fontification
-         t                             ; Use case folding
-         nil                           ; No extra syntax
-         ;; calls `gnuplot-beginning-of-continuation'
-         ;; to find a safe place to begin syntactic highlighting
-         beginning-of-defun))
-  
-  ;; Set up font-lock for Xemacs
-  ;; For GNU Emacs, this is done in `gnuplot-mode'
-  (if gnuplot-xemacs-p
-      (put 'gnuplot-mode 'font-lock-defaults
-          gnuplot-font-lock-defaults)))
-
-;; Some corner cases in Gnuplot's comment and string syntax are
-;; difficult to handle accurately using Emacs's built-in syntax tables
-;; and parser:
-;;
-;; - strings can continue over several lines, but only by using a
-;;   backslash to escape the newline
-;; 
-;; - double-quoted strings can contain escaped quotes, \", and escaped
-;;   backslashes, \\; but in single-quoted strings the quote is
-;;   escaped by doubling it, '', and backslash is only special at
-;;   end-of-line
-;; 
-;; - either type of string can end at newline without needing a
-;; - closing delimiter
-;; 
-;; - comments continue over continuation lines
-;;
-;; The following syntax-propertize rules should accurately mark string
-;; and comment boundaries using the "generic string fence" and
-;; "generic comment fence" syntax properties.  When syntax-propertize
-;; is unavailable (on Emacs versions <24), we fall back to using the
-;; normal syntax-table parser, which is accurate enough for most
-;; normal cases. (See the definition of `gnuplot-mode-syntax-table'.)
-(defalias 'gnuplot-syntax-propertize
-    (when (fboundp 'syntax-propertize-rules)
-      (syntax-propertize-rules
-       ;; Double quoted strings
-       ((rx
-         (group "\"")
-         (* (or (seq "\\" anything)
-                (not (any "\"" "\n"))))
-         (group (or "\"" "\n" buffer-end)))
-        (1 "|") (2 "|"))
-
-       ;; Single quoted strings
-       ((rx
-         (group "'")
-         (* (or (seq "\\" "\n")
-                "''"
-                (not (any "'" "\n"))))
-         (group (or "'" "\n" buffer-end)))
-        (1 "|") (2 "|"))
-
-       ;; Comments
-       ((rx
-         (group "#")
-         (* (or (seq "\\" "\n")
-                any))
-         (or (group "\n") buffer-end))
-        (1 "!") (2 "!")))))
-
-(defun gnuplot-syntax-propertize-extend-region (start end)
-  "Expand the region to syntax-propertize for strings and comments.
-
-Ensures that the region being searched begins and ends outside of
-any lines continued with a backslash.
-
-This function is added to
-`syntax-propertize-extend-region-functions' in gnuplot-mode
-buffers."
-  (let ((continuation-start
-         (min start
-              (gnuplot-point-at-beginning-of-continuation start)))
-        (continuation-end
-         (max end
-              (gnuplot-point-at-end-of-continuation end))))
-    (if (and (= continuation-start start)
-             (= continuation-end end))
-        nil
-      (cons continuation-start continuation-end))))
-
-;; Parsing utilities to tell if we are inside a string or comment
-(defun gnuplot-in-string (&optional where)
-  "Returns non-nil if the text at WHERE is within a string.
-
-If WHERE is omitted, defaults to text at point.
-This is a simple wrapper for `syntax-ppss'."
-  (save-excursion
-    (let ((parse-state (gnuplot-syntax-ppss where)))
-      (nth 3 parse-state))))
-
-(defun gnuplot-in-comment (&optional where)
-  "Returns non-nil if the text at WHERE is within a comment.
-
-If WHERE is omitted, defaults to text at point.
-This is a simple wrapper for `syntax-ppss'."
-  (save-excursion
-    (let ((parse-state (gnuplot-syntax-ppss where)))
-      (nth 4 parse-state))))
-
-(defun gnuplot-in-string-or-comment (&optional where)
-  "Returns non-nil if the text at WHERE is within a string or comment.
-
-If WHERE is omitted, defaults to text at point.
-This is a simple wrapper for `syntax-ppss'."
-
-  (save-excursion
-    (let ((parse-state (gnuplot-syntax-ppss where)))
-      (or (nth 3 parse-state)
-         (nth 4 parse-state)))))
-
-;; these two lines get rid of an annoying compile time error
-;; message.  that function gets non-trivially defalias-ed in
-;; gnuplot-toolbar.el
-;; (defun gnuplot-make-toolbar-dummy ())
-;; (defalias 'gnuplot-make-toolbar 'gnuplot-make-toolbar-dummy)
-
-\f
-;;; --- functions for sending commands to gnuplot
-
-(defun gnuplot-split-string (string)
-  "Break STRING at each carriage return, returning a list of lines."
-  (let ((list ()) (line "") (index 0))
-    (while (< index (length string))
-      (if (char-equal (elt string index) ?\n)
-         (setq list (append list (list line))
-               line "")
-       (setq line (concat line (char-to-string (elt string index)))))
-      (setq index (1+ index)) )
-    list))
-
-;; -- the calls to `sleep-for' are to allow enough time for gnuplot
-;;    to write to the buffer before the next line is inserted
-;; -- note that the input string is split into lines and each line is
-;;    sent to gnuplot individually.  this is a bit slow, but it puts
-;;    each line on the comint history.
-(defun gnuplot-send-string-to-gnuplot (string text)
-  "Sends STRING to the gnuplot program.
-If no gnuplot process exists, a new one is created.  TEXT indicates
-the type of text being sent to gnuplot and is typically one of
-nil, 'line, 'region, 'buffer, or 'file.  TEXT may be useful for
-functions in `gnuplot-after-plot-hook'.  `gnuplot-after-plot-hook' is
-called by this function after all of STRING is sent to gnuplot."
-  (gnuplot-make-gnuplot-buffer)        ; make sure a gnuplot buffer exists
-  (gnuplot-fetch-version-number)
-  (setq gnuplot-comint-recent-buffer (current-buffer))
-
-  ;; Create a gnuplot frame if needed
-  (if (equal gnuplot-display-process 'frame)
-      (or (and gnuplot-process-frame
-              (frame-live-p gnuplot-process-frame))
-         (let ((frame (selected-frame)))
-           (setq gnuplot-process-frame (make-frame))
-           (select-frame gnuplot-process-frame)
-           (switch-to-buffer gnuplot-buffer)
-           (delete-other-windows)
-           (select-frame frame))))
-
-  (let ((list (gnuplot-split-string string)))
-    (with-current-buffer (get-buffer gnuplot-buffer)
-      (goto-char (point-max))
-      ;; bruce asks: what is this next line for?
-      (set-marker (process-mark gnuplot-process) (point-marker))
-      (sleep-for (* 20 gnuplot-delay))
-      (while list
-       (insert (car list))
-       (comint-send-input)
-       (sleep-for gnuplot-delay)
-       (setq list (cdr list))
-       (goto-char (point-max))))
-
-    (cond ((equal gnuplot-display-process 'window)
-          (gnuplot-display-and-recenter-gnuplot-buffer))
-         ((equal gnuplot-display-process 'frame)
-          ;;(raise-frame gnuplot-process-frame)
-          (with-selected-frame gnuplot-process-frame
-            (gnuplot-display-and-recenter-gnuplot-buffer))))
-
-    (setq gnuplot-recently-sent text)
-    (run-hooks 'gnuplot-after-plot-hook)))
-
-(defun gnuplot-display-and-recenter-gnuplot-buffer ()
-  "Make sure the gnuplot comint buffer is displayed, and
-move point to the end if necessary"
-  (save-selected-window
-    (select-window (display-buffer (get-buffer gnuplot-buffer)))
-    (goto-char (point-max))
-    (unless (pos-visible-in-window-p (point) (selected-window)) (recenter 5))))
-
-(defun gnuplot-send-region-to-gnuplot (&optional begin end text)
-  "Sends a selected region to the gnuplot program.
-If BEGIN and END are not specified, point and mark are used.  TEXT
-indicates the type of text being sent to gnuplot.  This will be
-'region unless explicitly set by a function calling this one.  Other
-typical values are of nil, 'line, 'buffer, or 'file.  TEXT may be
-useful for function in `gnuplot-after-plot-hook'."
-  (interactive "r")
-  (let (string (txt (or text 'region)))
-    (cond ((equal major-mode 'gnuplot-mode)
-          (setq string (buffer-substring-no-properties begin end))
-          (if (string= (substring string -1) "\n") ()
-            (setq string (concat string "\n")))
-          (gnuplot-send-string-to-gnuplot string txt))
-         (t
-          (message (concat "You can only send regions from "
-                           "gnuplot-mode buffers to gnuplot."))))))
-
-(defun gnuplot-send-line-to-gnuplot ()
-  "Sends the current line to the gnuplot program.
-Respects continuation lines.
-This sets `gnuplot-recently-sent' to 'line."
-  (interactive)
-  (cond ((equal major-mode 'gnuplot-mode)
-        (let (start end)
-          (save-excursion 
-            ;; go to start of continued command, or beginning of line
-            ;; if this is not a continuation of a previous line <JJO>
-            (gnuplot-beginning-of-continuation)
-            (setq start (point))
-            (end-of-line)
-            (while (save-excursion
-                     (backward-char)
-                     (looking-at "\\\\"))      ; go to end of last continuation line
-              (end-of-line 2))
-            (beginning-of-line 2)
-            (setq end (point)))
-          (if (not (string-match "\\`\\s-*\\'"
-                                 (buffer-substring-no-properties start end)))
-              (gnuplot-send-region-to-gnuplot start end 'line))
-          end))
-       (t
-        (message "You can only send lines in gnuplot-mode buffers to gnuplot.")
-        nil)))
-
-;; I chose a very easy to type but slightly non-mnemonic key-binding
-;; for this (C-c C-v).  It seems like the kind of thing one would want
-;; to do repeatedly without incurring RSI. 8^)
-(defun gnuplot-send-line-and-forward (&optional num)
-  "Call `gnuplot-send-line-to-gnuplot' and move forward 1 line.
-You can use a numeric prefix to send more than one line.  Blank lines and
-lines with only comments are skipped when moving forward."
-  (interactive "p")
-  (let (end)
-    (while (> num 0)
-      (setq end (gnuplot-send-line-to-gnuplot))
-      (goto-char end)
-      (backward-char 1)                        ; <AR>
-      (gnuplot-forward-script-line 1)
-      (setq num (1- num)))))
-
-(defun gnuplot-send-line-and-newline ()
-  "Call `gnuplot-send-line-to-gnuplot' and insert a new line."
-  (interactive)
-  (end-of-line)
-  (gnuplot-send-line-to-gnuplot)
-  (insert "\n"))
-
-(defun gnuplot-forward-script-line (&optional num) ; <SE>
-  "Move forward my NUM script lines.
-Blank lines and commented lines are not included in the NUM count."
-  (interactive "p")
-  (while (> num 0)
-    (and (not (eobp)) (forward-line 1))
-    (while (and (not (eobp))
-               (or (looking-at "^\\s-*$")
-                   (looking-at "^\\s-*#")))
-      (forward-line 1))
-    (setq num (1- num))))
-
-(defun gnuplot-send-buffer-to-gnuplot ()
-  "Sends the entire buffer to the gnuplot program.
-This sets `gnuplot-recently-sent' to 'buffer."
-  (interactive)
-  (if (equal major-mode 'gnuplot-mode)
-      (gnuplot-send-region-to-gnuplot (point-min) (point-max) 'buffer)
-    (message "You can only send gnuplot-mode buffers to gnuplot.")))
-
-(defun gnuplot-send-file-to-gnuplot ()
-  "Sends a selected file to the gnuplot program using the \"load\" command.
-This sets `gnuplot-recently-sent' to 'file."
-  (interactive)
-  (let ((string (read-file-name "Name of file to send to gnuplot > " nil nil t)))
-    (setq string (concat "load '" (expand-file-name string) "'\n"))
-    (message "%S" string)
-    (gnuplot-make-gnuplot-buffer)      ; make sure a gnuplot buffer exists
-    (gnuplot-send-string-to-gnuplot string 'file)))
-
-;; suggested by <JS>
-(defun gnuplot-plot-from-comint ()
-  "Send the contents of a script to gnuplot from the process buffer.
-This inserts the contents of the most recently used gnuplot script
-into the process buffer and sends those lines to gnuplot.  It does
-this by copying the script line by line."
-  (interactive)
-  (if (not (buffer-live-p gnuplot-comint-recent-buffer))
-      (message "Script buffer has been deleted.")
-    (let (string list (buffer (current-buffer)))
-      (set-buffer gnuplot-comint-recent-buffer)
-      (setq string (buffer-substring-no-properties (point-min) (point-max))
-           string (concat string "\n")
-           list   (gnuplot-split-string string))
-      (set-buffer buffer)
-      (while list
-       (insert (car list))
-       (comint-send-input)
-       (sleep-for gnuplot-delay)
-       (setq list (cdr list)))
-      (comint-send-input))))
-
-(defun gnuplot-save-and-plot-from-comint ()
-  "Send a current script to gnuplot from the process buffer.
-This sends the most recently used gnuplot script to gnuplot using the
-\"load\" command.  This function first saves the script buffer to a
-file, prompting for a filename if one is not associated with the script
-buffer.  Then it sends a load command to gnuplot using the name of the
-file visited by the script buffer."
-  (interactive)
-  (if (not (buffer-live-p gnuplot-comint-recent-buffer))
-      (message "Script buffer has been deleted.")
-    (let (fname)
-      (with-current-buffer gnuplot-comint-recent-buffer
-       (save-buffer)
-       (setq fname (buffer-file-name)))
-      (goto-char (point-max))
-      (insert (format "load '%s'" fname))
-      (comint-send-input))))
-
-(defun gnuplot-pop-to-recent-buffer ()
-  "Switch to the most recently-plotted gnuplot script buffer."
-  (interactive)
-  (when (buffer-live-p gnuplot-comint-recent-buffer)
-    (pop-to-buffer gnuplot-comint-recent-buffer)))
-
-(defun gnuplot-trim-gnuplot-buffer ()
-  "Trim lines from the beginning of the *gnuplot* buffer.
-This keeps that buffer from growing excessively in size.  Normally,
-this function is attached to `gnuplot-after-plot-hook'"
-  (if (> gnuplot-buffer-max-size 0)
-      (with-current-buffer gnuplot-buffer
-       (let ((nlines (count-lines (point-min) (point-max)))
-             (kill-whole-line t))
-         (while (> nlines gnuplot-buffer-max-size)
-           (goto-char (point-min))
-           (kill-line)
-           (setq nlines (1- nlines)))
-         (goto-char (point-max)) ))))
-(add-hook 'gnuplot-after-plot-hook 'gnuplot-trim-gnuplot-buffer nil nil)
-
-\f
-;;; --- functions controlling the gnuplot process
-
-;; Menu for the comint-mode buffer
-(defvar gnuplot-comint-menu
-  `("Gnuplot"
-    ["Plot most recent gnuplot buffer"         gnuplot-plot-from-comint
-     (buffer-live-p gnuplot-comint-recent-buffer)]
-    ["Save and plot most recent gnuplot buffer"        gnuplot-save-and-plot-from-comint
-     (buffer-live-p gnuplot-comint-recent-buffer)]
-    "---"
-    ,gnuplot-display-options-menu
-    ["Contextual completion and help"           gnuplot-context-sensitive-mode
-     :style toggle
-     :selected gnuplot-context-sensitive-mode]
-    ["Echo area help (eldoc-mode)" eldoc-mode
-     :active gnuplot-context-sensitive-mode
-     :style toggle
-     :selected eldoc-mode]
-    "---"
-    ["Insert filename at point"                        gnuplot-insert-filename t]
-    ["Negate set option"                       gnuplot-negate-option t]
-    ["Keyword help"                            gnuplot-info-lookup-symbol
-     (or gnuplot-keywords gnuplot-keywords-pending)]
-    ["Quick help for thing at point"            gnuplot-help-function
-     gnuplot-context-sensitive-mode]
-    ["Info documentation on thing at point"
-     gnuplot-info-at-point
-     gnuplot-context-sensitive-mode]
-    ["Switch to recent gnuplot script buffer"  gnuplot-pop-to-recent-buffer
-     (buffer-live-p gnuplot-comint-recent-buffer)]
-    "---"
-    ["Customize gnuplot"                       gnuplot-customize t]
-    ["Show gnuplot-mode version"               gnuplot-show-version t]
-    ["Show gnuplot version"                    gnuplot-show-gnuplot-version t]
-    "---"
-    ["Kill gnuplot"                            gnuplot-kill-gnuplot-buffer t]
-    ))
-
-;; Major mode `gnuplot-comint-mode' for the interaction buffer
-(define-derived-mode gnuplot-comint-mode comint-mode "Gnuplot interaction"
-  "Major mode for interacting with a gnuplot process in a buffer.
-
-This sets font-lock and keyword completion in the comint/gnuplot
-buffer."
-
-  (set-syntax-table gnuplot-mode-syntax-table)
-
-  (if gnuplot-xemacs-p                 ; deal with font-lock
-      (if (fboundp 'turn-on-font-lock) (turn-on-font-lock))
-    (progn
-      (setq font-lock-defaults gnuplot-font-lock-defaults)
-      (set (make-local-variable 'parse-sexp-lookup-properties) t)
-      (set (make-local-variable 'syntax-propertize-function)
-           #'gnuplot-syntax-propertize)))
-
-  ;; XEmacs needs the call to make-local-hook
-  (when (and (featurep 'xemacs)
-            (fboundp 'make-local-hook))
-    (make-local-hook 'kill-buffer-hook))
-  (add-hook 'kill-buffer-hook 'gnuplot-close-down nil t)
-
-  (add-hook 'comint-output-filter-functions
-           'comint-postoutput-scroll-to-bottom
-           nil t)
-  (add-hook 'comint-output-filter-functions
-           'gnuplot-protect-prompt-fn
-           nil t)
-
-  ;; Set up completion, using completion-at-point in recent Emacs,
-  ;; comint-dynamic-complete in older Emacs
-  (if (and (>= emacs-major-version 24)
-           (>= emacs-minor-version 1))
-      (add-hook 'completion-at-point-functions #'gnuplot-completion-at-point nil t)
-    (add-hook 'comint-dynamic-complete-functions 'gnuplot-comint-complete nil t))
-
-  ;; Set up menu (see below)
-  (easy-menu-define
-   gnuplot-comint-mode-menu gnuplot-comint-mode-map "Menu used in gnuplot-comint-mode"
-   gnuplot-comint-menu)
-  (easy-menu-add gnuplot-comint-mode-menu gnuplot-comint-mode-map))
-
-;; Key bindings for gnuplot-comint-mode
-(define-key gnuplot-comint-mode-map "\M-\C-p"  'gnuplot-plot-from-comint)
-(define-key gnuplot-comint-mode-map "\M-\C-f"  'gnuplot-save-and-plot-from-comint)
-(define-key gnuplot-comint-mode-map "\C-d"     'gnuplot-delchar-or-maybe-eof)
-(let ((completion-function
-       (if (and (>= emacs-major-version 24)
-                (>= emacs-minor-version 1))
-           'completion-at-point
-         'comint-dynamic-complete)))
-  (define-key gnuplot-comint-mode-map "\M-\r"  completion-function)
-  (define-key gnuplot-comint-mode-map "\M-\t"  completion-function))
-(define-key gnuplot-comint-mode-map "\C-c\C-d"  'gnuplot-info-lookup-symbol)
-(define-key gnuplot-comint-mode-map "\C-c\C-w" 'gnuplot-show-version)
-(define-key gnuplot-comint-mode-map "\C-c\C-i" 'gnuplot-insert-filename)
-(define-key gnuplot-comint-mode-map "\C-c\C-n" 'gnuplot-negate-option)
-(define-key gnuplot-comint-mode-map "\C-c\C-p" 'gnuplot-show-gnuplot-version)
-(define-key gnuplot-comint-mode-map "\C-c\C-z" 'gnuplot-customize)
-(define-key gnuplot-comint-mode-map "\C-c\C-e" 'gnuplot-pop-to-recent-buffer)
-(define-key gnuplot-comint-mode-map "\C-c\M-i"  'gnuplot-inline-image-mode)
-
-;; Menu for gnuplot-comint-mode
-(defvar gnuplot-comint-mode-menu nil
-  "Menu for `gnuplot-comint-mode'.")
-
-;; Switch to the gnuplot program buffer
-(defun gnuplot-make-gnuplot-buffer ()
-  "Switch to the gnuplot program buffer or create one if none exists."
-  (unless (and gnuplot-process (eq (process-status gnuplot-process) 'run)
-               gnuplot-buffer (buffer-live-p gnuplot-buffer))
-    (message "Starting gnuplot plotting program...")
-    (setq gnuplot-buffer (make-comint gnuplot-process-name gnuplot-program)
-          gnuplot-process (get-buffer-process gnuplot-buffer))
-    (gnuplot-set-process-query-on-exit-flag gnuplot-process nil)
-    (with-current-buffer gnuplot-buffer
-      (gnuplot-comint-mode)
-      (when gnuplot-inline-image-mode
-        (sleep-for gnuplot-delay)
-        (gnuplot-setup-comint-for-image-mode)))
-    (message "Starting gnuplot plotting program...Done")))
-
-
-(defun gnuplot-fetch-version-number ()
-  "Determine the installed version of the gnuplot program.
-
-If `gnuplot-program-version' is already set, does
-nothing. Otherwise, runs `gnuplot-program' and searches the text
-printed at startup for a string like \"Version N.N\".
-
-Sets the variables `gnuplot-program-version',
-`gnuplot-program-major-version', `gnuplot-program-minor-version',
-and `gnuplot-three-eight-p'.
-
-If the version number cannot be determined by this method, it
-defaults to 3.7."
-  (unless gnuplot-program-version
-    (message "gnuplot-mode %s -- determining gnuplot version ......"
-            gnuplot-version)
-    (with-temp-buffer
-      (insert "show version")
-      (call-process-region (point-min) (point-max)
-                          gnuplot-program t (current-buffer))
-      (goto-char (point-min))
-      (if (and (re-search-forward "[Vv]ersion\\s-+" (point-max) t)
-              (looking-at "\\([0-9]\\)\\.\\([0-9]+\\)"))
-         (progn
-           (setq gnuplot-program-version (match-string 0)
-                 gnuplot-program-major-version (string-to-number
-                                                (match-string 1))
-                 gnuplot-program-minor-version (string-to-number
-                                                (match-string 2))
-                 gnuplot-three-eight-p
-                 (>= (string-to-number gnuplot-program-version) 3.8)))
-
-       ;; Guess v3.7 if something went wrong
-       (message "Warning: could not determine gnuplot version, guessing 3.7")
-       (setq gnuplot-program-version "3.7"
-             gnuplot-program-major-version 3
-             gnuplot-program-minor-version 7
-             gnuplot-three-eight-p nil)))
-    
-    ;; Setup stuff that depends on version number
-    (gnuplot-setup-menu-and-toolbar)))
-
-(defun gnuplot-setup-menu-and-toolbar ()
-  ;; set up the menubar (possibly dependent on version number)
-  (gnuplot-setup-menubar)
-  ;; set up the toolbar (possibly dependent on version number)
-  (if (and gnuplot-xemacs-p gnuplot-toolbar-display-flag)
-      (condition-case ()               ; deal with the toolbar
-         (and (require 'toolbar)
-              (require 'xpm)
-              (gnuplot-make-toolbar-function))
-       (error nil)))
-  (message "gnuplot-mode %s (gnuplot %s) -- report bugs as issues at %s"
-          gnuplot-version gnuplot-program-version
-          gnuplot-maintainer-url))
-
-(defvar gnuplot-prompt-regexp
-  (regexp-opt '("gnuplot> " "multiplot> "))
-  "Regexp for recognizing the GNUPLOT prompt")
-
-(defun gnuplot-protect-prompt-fn (string)
-  "Prevent the Gnuplot prompt from being deleted or overwritten.
-STRING is the text as originally inserted in the comint buffer."
-  (save-excursion
-    (let ((b (progn
-               (goto-char (point-max))
-               (beginning-of-line)
-               (point)))
-          e)
-      (if (re-search-forward gnuplot-prompt-regexp (point-max) t)
-          (progn
-            (setq e (point))
-            (put-text-property b e 'rear-nonsticky '(read-only intangible face))
-            (put-text-property b e 'intangible t)
-            (put-text-property b e 'face 'gnuplot-prompt-face)
-            ;;(put-text-property b e 'read-only t)
-           )) )))
-
-(defun gnuplot-close-down ()
-  "Tidy up when deleting the gnuplot buffer."
-  (if (and gnuplot-process
-          (eq (process-status gnuplot-process) 'run)) ; <SE>
-      (kill-process gnuplot-process))
-  (setq gnuplot-process nil
-        gnuplot-buffer nil))
-
-(defun gnuplot-delchar-or-maybe-eof (arg)
-  "Delete ARG characters forward, or (if at eob) send an EOF to subprocess.
-This is very similar to `comint-delchar-or-maybe-eof'."
-  (interactive "p")
-  (if (eobp)
-      (gnuplot-kill-gnuplot-buffer)
-    (delete-char arg)))
-
-(defun gnuplot-kill-gnuplot-buffer ()
-  "Kill the gnuplot process and its display buffers."
-  (interactive)
-  (if (and gnuplot-process
-          (eq (process-status gnuplot-process) 'run))  ;; <SE>
-      (kill-process gnuplot-process))
-  (if (and gnuplot-buffer (get-buffer gnuplot-buffer))
-      (progn
-       (if (one-window-p) ()
-         (delete-window (get-buffer-window gnuplot-buffer)))
-       (kill-buffer gnuplot-buffer)))
-  (setq gnuplot-process nil
-        gnuplot-buffer nil))
-
-
-(defun gnuplot-show-gnuplot-buffer ()
-  "Switch to the buffer containing the gnuplot process.
-When `gnuplot-display-process' is nil this will switch to
-the gnuplot process buffer.  When that variable is non-nil, the
-gnuplot process buffer will be displayed in a window."
-  (interactive)
-  (unless (and gnuplot-buffer (get-buffer gnuplot-buffer))
-    (gnuplot-make-gnuplot-buffer))
-  (cond ((equal gnuplot-display-process 'window)
-        (switch-to-buffer-other-window gnuplot-buffer))
-       ((equal gnuplot-display-process 'frame)
-        (or (and gnuplot-process-frame
-                 (frame-live-p gnuplot-process-frame))
-            (setq gnuplot-process-frame (make-frame)))
-        (raise-frame gnuplot-process-frame)
-        (select-frame gnuplot-process-frame)
-        (switch-to-buffer gnuplot-buffer))
-       (t
-        (switch-to-buffer gnuplot-buffer))))
-
-\f
-;;; Support for displaying plotted images within Emacs
-
-(defvar gnuplot-inline-image-filename nil
-  "Name of the current Gnuplot output file.")
-
-(defvar gnuplot-image-buffer-name "*gnuplot output*")
-
-(defun gnuplot-display-images-p ()
-  ;; Inline images require GNU Emacs.
-  (and (not (featurep 'xemacs))
-       (fboundp 'display-images-p)
-       (display-images-p)))
-
-(defun gnuplot-external-display-mode ()
-  (interactive)
-  (gnuplot-set-display-mode 'gnuplot-inline-image-mode nil))
-
-(defun gnuplot-inline-display-mode ()
-  (interactive)
-  (gnuplot-set-display-mode 'gnuplot-inline-image-mode 'inline))
-
-(defun gnuplot-dedicated-display-mode ()
-  (interactive)
-  (gnuplot-set-display-mode 'gnuplot-inline-image-mode 'dedicated))
-
-(defun gnuplot-set-image-format (format)
-  (interactive "sGnuplot image format: ")
-  (gnuplot-set-display-mode 'gnuplot-image-format format)
-  (unless gnuplot-inline-image-mode
-    (message "Setting will take effect when plots are displayed in Emacs")))
-
-(defun gnuplot-setup-comint-for-image-mode ()
-  (when (and gnuplot-buffer (buffer-live-p gnuplot-buffer)
-             (get-buffer-process gnuplot-buffer))
-    (with-current-buffer gnuplot-buffer
-      (if gnuplot-inline-image-mode
-          (progn
-            (gnuplot-send-hiding-output
-             (format "set terminal %s\n" gnuplot-image-format))
-            (gnuplot-inline-image-set-output)
-            (add-hook 'comint-output-filter-functions
-                      'gnuplot-insert-inline-image-output nil t))
-        (gnuplot-send-hiding-output "set terminal pop\n")
-        (remove-hook 'comint-output-filter-functions
-                     'gnuplot-insert-inline-image-output t)))))
-
-(defun gnuplot-inline-image-set-output ()
-  "Set Gnuplot's output file to `gnuplot-inline-image-filename'."
-  (let ((tmp (make-temp-file "gnuplot")))
-    (setq gnuplot-inline-image-filename tmp)
-    (gnuplot-send-hiding-output (format "set output '%s'\n" tmp))))
-
-(defvar gnuplot-inhibit-filter nil)
-
-(defun gnuplot-insert-inline-image-output (string)
-  "Insert Gnuplot graphical output in the gnuplot-comint buffer.
-
-Called via `comint-preoutput-filter-functions' hook when
-`gnuplot-inline-image-mode' is enabled. Checks the status of the
-file `gnuplot-inline-image-filename'; if it exists and has
-nonzero size, inserts it as an inline image, stores a new
-temporary filename in `gnuplot-inline-image-filename', and
-updates Gnuplot with the appropriate 'set output' command."
-  (unless gnuplot-inhibit-filter        ; Prevent recursively entering this filter
-    (let ((gnuplot-inhibit-filter t))   ; (causing an infinite loop)
-      (save-excursion
-        (goto-char (point-max))
-        (beginning-of-line)
-        (when (looking-at gnuplot-prompt-regexp)
-          (let* ((filename gnuplot-inline-image-filename)
-                 (size (nth 7 (file-attributes filename))))
-            (when (and size (> size 0))
-              (gnuplot-send-hiding-output "set output\n") ; Flush output file
-              (sit-for 0.1)             ; Hack: wait for Gnuplot IO to finish
-              (ecase gnuplot-inline-image-mode
-                (nil nil)
-                (inline
-                 (ignore-errors
-                   (let ((image (create-image filename)))
-                     (beginning-of-line)
-                     (insert-image image)
-                     (insert "\n")
-                     (gnuplot-inline-image-set-output))))
-                (dedicated
-                 (with-current-buffer
-                     (get-buffer-create gnuplot-image-buffer-name)
-                   (let ((inhibit-read-only t))
-                     (erase-buffer)
-                     (insert-file-contents filename)
-                     (ignore-errors (normal-mode))
-                     (display-buffer (current-buffer))
-                     (gnuplot-inline-image-set-output))))))))))))
-
-;;; Send commands to GNUPLOT silently & without generating an extra prompt
-(defvar gnuplot-hidden-output-buffer " *gnuplot output*")
-  
-(defun gnuplot-send-hiding-output (string)
-  "Send STRING to the running Gnuplot process invisibly."
-  (with-current-buffer gnuplot-buffer
-    (add-hook 'comint-preoutput-filter-functions
-             'gnuplot-discard-output nil t))
-  (with-current-buffer (get-buffer-create gnuplot-hidden-output-buffer)
-    (erase-buffer))
-  (comint-send-string (get-buffer-process gnuplot-buffer) string))
-
-(defun gnuplot-discard-output (string)
-  ;; Temporary preoutput filter for hiding Gnuplot output & prompt.
-  ;; Accumulates output in a buffer until it finds the next prompt,
-  ;; then removes itself from comint-preoutput-filter-functions.
-  (with-current-buffer
-      (get-buffer-create gnuplot-hidden-output-buffer)
-    (insert string)
-    (when (looking-back gnuplot-prompt-regexp)
-      (with-current-buffer gnuplot-buffer
-       (remove-hook 'comint-preoutput-filter-functions
-                    'gnuplot-discard-output t))))
-  "")
-
-
-\f
-;;; --- miscellaneous functions: insert file name, indentation, negation
-
-(defun gnuplot-insert-filename ()
-  "Insert a filename at point, prompting for name in the minibuffer.
-This inserts a filename relative to the buffer's default directory.
-Uses completion and the value of `gnuplot-quote-character'.
-Bound to \\[gnuplot-insert-filename]"
-  (interactive)
-  (insert gnuplot-quote-character
-         (file-relative-name (read-file-name "Filename > " "")
-                             default-directory)
-         gnuplot-quote-character) )
-
-
-;; Adjust indentation for the line containing point
-(defun gnuplot-indent-line ()
-  "Set indentation in gnuplot buffer.
-For most lines, set indentation to previous level of indentation.
-Add additional indentation for continuation lines."
-  (interactive)
-  (let (indent)
-    (if (gnuplot-in-string (point-at-bol))
-       ;; Continued strings begin at left margin
-       (setq indent 0)
-      (save-excursion 
-       (if (gnuplot-continuation-line-p)
-           ;; This is a continuation line. Indent to the same level as
-           ;; the second word on the line beginning this command (i.e.,
-           ;; the first non-whitespace character after whitespace)
-           (progn
-             (gnuplot-beginning-of-continuation)
-             (back-to-indentation) 
-             (re-search-forward "\\S-+\\s-+" (point-at-eol) 'end-at-limit)
-             (setq indent (- (point) (point-at-bol))))
-
-          ;; Not a continuation line; indent according to block
-          ;; nesting depth
-          (save-excursion
-            (condition-case nil
-                (progn
-                  (beginning-of-line)
-                  (skip-syntax-forward "-" (point-at-eol))
-                  (if (looking-at "\\s)") (forward-char))
-                  (backward-up-list)
-                  (gnuplot-beginning-of-continuation)
-                  (setq indent (+ gnuplot-basic-offset (current-indentation))))
-              (error
-               (setq indent 0)))))))
-
-    ;; Set indentation
-    (save-excursion 
-      (indent-line-to indent))
-
-    ;; Move point after indentation when at beginning of line
-    (let ((point-at-indent (+ (point-at-bol) indent)))
-      (when (< (point) point-at-indent) (goto-char point-at-indent)))))
-
-;; Adjust indentation on inserting a close brace
-;; The blink-paren fix is stolen from cc-mode
-(defun gnuplot-electric-insert (arg)
-  (interactive "*p")
-  (let ((old-blink-paren blink-paren-function)
-        (blink-paren-function nil))
-    (self-insert-command arg)
-    (gnuplot-indent-line)
-    (when old-blink-paren (funcall old-blink-paren))))
-
-;;
-;; Functions for finding the start and end of continuation blocks
-;;
-
-;; Check if line containing point is a continuation
-(defun gnuplot-continuation-line-p ()
-  "Return t if the line containing point is a continuation of the previous line."
-  (save-excursion
-    (condition-case ()
-       (progn
-         (end-of-line 0)
-         (backward-char)
-         (looking-at "\\\\"))
-      (error nil))))
-
-;; Move point to start of continuation block
-(defun gnuplot-beginning-of-continuation ()
-  "Move point to the beginning of the continuation lines containing point.
-
-If not in a continuation line, move point to beginning of line."
-  (beginning-of-line)
-  (while (gnuplot-continuation-line-p)
-    (beginning-of-line 0)))
-
-;; Move point to end of continuation block
-(defun gnuplot-end-of-continuation ()
-  "Move point to the end of the continuation lines containing point.
-
-If there are no continuation lines, move point to end-of-line."
-  (end-of-line)
-  (unless (bobp)
-    (catch 'eob
-      (while (save-excursion (backward-char)
-                            (looking-at "\\\\"))
-       (end-of-line 2)
-       (if (eobp) (throw 'eob nil))))))
-
-;; Save-excursion wrappers for the above to return point at beginning
-;; or end of continuation
-(defun gnuplot-point-at-beginning-of-continuation (&optional pos)
-  "Return value of point at beginning of the continued block containing point.
-
-If there are no continuation lines, returns point-at-bol."
-  (save-excursion
-    (when pos (goto-char pos))
-    (gnuplot-beginning-of-continuation)
-    (point)))
-
-(defun gnuplot-point-at-end-of-continuation (&optional pos)
-  "Return value of point at the end of the continued block containing point.
-
-If there are no continuation lines, returns point-at-eol."
-  (save-excursion
-    (when pos (goto-char pos))
-    (gnuplot-end-of-continuation)
-    (point)))
-
-;; We also treat a block of continuation lines as a 'defun' for
-;; movement purposes
-(defun gnuplot-beginning-of-defun (&optional arg)
-  (if (not arg) (setq arg 1))
-  (if (> arg 0)                        
-      (catch 'bob              ; go to beginning of ARGth prev. defun
-       (dotimes (n arg)
-         (when (= (point)
-                  (gnuplot-point-at-beginning-of-continuation))
-           (forward-line -1)
-           (if (bobp) (throw 'bob t))
-           (while (looking-at "^\\s-*$")
-             (forward-line -1)
-             (if (bobp) (throw 'bob t))))
-         (gnuplot-beginning-of-continuation))
-       t)
-
-    (catch 'eob                  ; find beginning of (-ARG)th following defun
-      (dotimes (n (- arg))
-       (gnuplot-end-of-continuation)
-       (forward-line)
-       (if (eobp) (throw 'eob t))
-       (while (looking-at "^\\s-*$")
-         (forward-line)
-         (if (eobp) (throw 'eob t)))))))
-
-;; Movement to start or end of command, including multiple commands
-;; separated by semicolons
-(defun gnuplot-beginning-of-command ()
-  "Move point to beginning of command containing point."
-  (let ((limit (gnuplot-point-at-beginning-of-continuation)))
-    (while
-       (and
-        (search-backward ";" limit 'lim)
-        (gnuplot-in-string-or-comment)))
-    (skip-chars-forward ";")
-    (skip-syntax-forward "-")))
-
-(defun gnuplot-end-of-command ()
-  "Move point to end of command containing point."
-  (let ((limit (gnuplot-point-at-end-of-continuation)))
-    (while
-       (and
-        (search-forward ";" limit 'lim)
-        (gnuplot-in-string-or-comment)))
-    (skip-chars-backward ";")
-    (skip-syntax-backward "-")))
-
-(defun gnuplot-point-at-beginning-of-command ()
-  "Return position at the beginning of command containing point."
-  (save-excursion (gnuplot-beginning-of-command) (point)))
-
-(defun gnuplot-point-at-end-of-command ()
-  "Return position at the end of command containing point."
-  (save-excursion (gnuplot-end-of-command) (point)))
-
-(defun gnuplot-negate-option ()
-  "Append \"no\" to or remove \"no\" from the set option on the current line.
-This checks if the set option is one which has a negated form.
-
-Negatable options are defined in `gnuplot-keywords-negatable-options'."
-  (interactive)
-  (gnuplot-fetch-version-number)
-  (let ((begin (gnuplot-point-at-beginning-of-command))
-       (end   (gnuplot-point-at-end-of-command))
-       (regex gnuplot-negatable-options-regexp))
-    (save-excursion
-      (goto-char begin)
-      (skip-syntax-forward "-" end)
-      (if (looking-at "\\(un\\)?set\\s-+")
-         (cond ((> (string-to-number gnuplot-program-version) 3.7)
-                (cond ((looking-at "unset")
-                       (delete-char 2))
-                      ((looking-at (concat "set\\s-+\\(" regex "\\)"))
-                       (insert "un"))
-                      (t
-                       (message "There is not a negatable set option on this line"))))
-               (t
-                (goto-char (match-end 0))
-                (if (> (point) end) (goto-char end))
-                (cond ((looking-at "no")
-                       (delete-char 2))
-                      ((looking-at regex)
-                       (insert "no"))
-                      (t
-                       (message "There is not a negatable set option on this line")))))
-       (message "There is not a set option on this line")) )))
-
-;; (defun gnuplot-set-binding ()
-;;   "Interactively select a key sequence for binding to a plot function.
-;; This is only useful in gnuplot 3.8 and for plot terminals which support
-;; key bindings (i.e. those covered by pm3d)."
-;;   (interactive)
-;;   (let ((keyseq (read-key-sequence "Choose a key sequence now"))
-;;     (command (read-string "Bind to this command > ")))
-;;     (setq keyseq (format "%S" keyseq))
-;;     (string-match "keypress-event\\s-+" keyseq)
-;;     (setq keyseq (substring keyseq (match-end 0) -2))
-;;     ;; need to convert from emacs nomenclature to gnuplot.  what a pain.
-;;     (let* ((alist '(("backspace" . "Backspace") ("tab" . "Tab") ("linefeed" . "Linefeed")
-;;                 ("clear" . "Clear") ("return" . "Return") ("pause" . "Pause")
-;;                 ("scroll-lock" . "Scroll_Lock") ("SysReq" . "sys-req")
-;;                 ("escape" . "Escape") ("delete" . "Delete") ("home" . "Home")
-;;                 ("left" . "Left") ("right" . "Right") ("up" . "Up") ("down" . "Down")
-;;                 ("prior" . "PageUp") ("next" . "PageDown") ("end" . "End")
-;;                 ("begin". "Begin")))
-;;        (match (assoc keyseq alist)))
-;;       (if match (setq keyseq (cdr match)))
-;;
-;;     (insert (format "bind \"%s\" \"%s\"" keyseq command)))))
-
-
-(defun gnuplot-customize ()
-  "Customize `gnuplot-mode'."
-  (interactive)
-  (if (fboundp 'customize-group)
-      (customize-group "gnuplot")
-    (message "The Custom library is not installed.")))
-
-
-\f
-;;; --- help from the info file, keyword list + completion, insert function
-
-
-;; set up stuff for info-look (as suggested by <SE>)
-;; modified with suggestion from <MS>
-(defun gnuplot-setup-info-look ()
-  "Setup info-look in the gnuplot buffer.
-
-Also set the variable `gnuplot-keywords' and do something sensible if
-info-look was not available.
-See the comments in `gnuplot-info-hook'."
-  (interactive)
-  (setq gnuplot-keywords-pending nil)
-  (if (featurep 'info-look)
-      (progn 
-       (gnuplot-fetch-version-number)
-
-       ;; In the absence of evidence to the contrary, I'm guessing
-       ;; the info file layout changed with gnuplot version 4 <jjo>
-        (let ((doc-spec
-              (if (>= (string-to-number gnuplot-program-version) 4.0)
-                  ;; New info-file layout - works with gnuplot 4.4
-                  '(("(gnuplot)Command_Index"   nil "[_a-zA-Z0-9]+")
-                    ("(gnuplot)Options_Index"   nil "[_a-zA-Z0-9]+")
-                    ("(gnuplot)Function_Index"  nil "[_a-zA-Z0-9]+")
-                    ("(gnuplot)Terminal_Index"  nil "[_a-zA-Z0-9]+"))
-
-                ;; Old info-file layout
-                '(("(gnuplot)Top"           nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)Commands"      nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)Functions"     nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)plot"          nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)set-show"      nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)data-file"     nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)smooth"        nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)style"         nil "[_a-zA-Z0-9]+")
-                  ("(gnuplot)terminal"      nil "[_a-zA-Z0-9]+")))))
-         (cond ((boundp 'info-lookup-symbol-alist) ; older info-lookup version
-                (setq info-lookup-symbol-alist
-                      (append
-                       info-lookup-symbol-alist
-                       `((gnuplot-mode
-                          "[a-zA-Z][_a-zA-Z0-9]*" nil
-                          ,doc-spec "[_a-zA-Z0-9]+" )))))
-               (t                      ; newer version
-                (info-lookup-add-help
-                 :mode 'gnuplot-mode :topic 'symbol
-                 :regexp "[a-zA-Z][_a-zA-Z0-9]*"
-                 :doc-spec doc-spec)
-                ;; allow help lookup from the comint buffer as well <jjo>
-                (info-lookup-add-help
-                 :mode 'gnuplot-comint-mode :topic 'symbol
-                 :regexp "[a-zA-Z][_a-zA-Z0-9]*"
-                 :doc-spec doc-spec))))
-
-       ;; this hook is my best way of working with info-look and
-       ;; allowing multiple versions of the gnuplot-info file.
-       ;; yes, this is a hassle.
-       (run-hooks 'gnuplot-info-hook)
-       (let ((there (bufferp (get-buffer "*info*"))))
-         (info-lookup-setup-mode 'symbol 'gnuplot-mode)
-         (or there (and (get-buffer "*info*") (kill-buffer "*info*")))
-         ;; why are these buffers here?  I think that the general
-         ;; user will not want them lying around
-         (and (get-buffer "info dir")    (kill-buffer "info dir"))
-         (and (get-buffer "info dir<2>") (kill-buffer "info dir<2>")))
-       (setq gnuplot-keywords (gnuplot-set-keywords-list))
-       (setq gnuplot-keywords-alist    ; needed for all-completions
-             (mapcar 'list gnuplot-keywords)))
-
-    ;; or do something sensible if info-look is not installed
-    (defun info-lookup-interactive-arguments (symbol)
-      (message
-       "Help is not available.  info-look.el is not installed.")
-      (list nil nil))))
-
-
-(defun gnuplot-set-keywords-list ()
-  "Set `gnuplot-keywords' from `info-lookup-cache'.
-Return a list of keywords."
-  (let* ((list (cdr (assoc 'symbol info-lookup-cache)))
-        (list (cdr (cdr (assoc 'gnuplot-mode list))))
-        (list (car list))
-        (store ()) item)
-    (while list
-      (setq item (car (car list))
-           item (format "%s" item) ; keep this line for the sake of
-           store (append (list item) store) ; info-look.el w/o my patch
-           list  (cdr list)))
-    (delete "nil" store)
-    store ))
-
-\f
-;;;; Completion at point and Eldoc.
-
-;; There are two alternative completion-at-point mechanisms: the old
-;; one using info-look and the new one (enabled by default) which
-;; parses the command line to provide smarter completions.
-
-;; `gnuplot-completion-at-point-function' defines which one is
-;; used. `gnuplot-context-sensitive-mode' toggles between the two.
-
-(defvar gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look
-  "Function to call to perform completion in Gnuplot buffers.")
-
-(defun gnuplot-completion-at-point ()
-  (funcall gnuplot-completion-at-point-function))
-
-(defvar gnuplot-eldoc-hash nil
-  "ElDoc strings for gnuplot-mode.
-
-These have to be compiled from the Gnuplot source tree using
-`doc2texi.el'.")
-
-;; Enable and disable context-sensitive completion
-(define-minor-mode gnuplot-context-sensitive-mode
-  "Use context-sensitive completion and help in gnuplot-mode.
-
-When context-sensitive mode is enabled, gnuplot-mode tries to
-provide more useful completions and help suggestions for built-in
-keywords and functions by parsing each command as you type.  It
-attempts to take into account Gnuplot's many abbreviated
-keywords.  For example, with point at the end of a line reading
-\"plot 'datafile' w \", typing \\[completion-at-point] will pop
-up a list of plotting styles.
-
-Key bindings:
-
-\\[completion-at-point] will complete the keyword at point based
-on its context in the command. To make keyword completion work on
-pressing TAB, set `tab-always-indent' to `complete', or customize
-`gnuplot-tab-completion' to make this automatic in gnuplot-mode
-buffers.
-
-\\[gnuplot-info-at-point] will try to find the most relevant
-Gnuplot info node for the construction at point, prompting for a
-node name if nothing is found.
-
-\\[gnuplot-help-function] will pop up a brief summary of the
-syntax at point in the minibuffer. To have one-line syntax
-summaries appear in the echo area as you type, toggle
-`eldoc-mode' or customize `gnuplot-eldoc-mode'.
-
-To choose whether to use this mode by default in Gnuplot buffers,
-customize the variable
-`gnuplot-use-context-sensitive-completion'.
-
-Note: help strings for eldoc-mode and \\[gnuplot-help-function]
-need to be provided in an Emacs-readable form by the Gnuplot
-distribution. See gnuplot-context.el for details."
-  :keymap
-  `((,(kbd "C-c C-/") . gnuplot-help-function)
-    (,(kbd "C-c C-d") . gnuplot-info-at-point))
-  (unless (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
-    (message "Gnuplot context-sensitive mode works only in Gnuplot-mode buffers")
-    (setq gnuplot-context-sensitive-mode nil))
-  (if gnuplot-context-sensitive-mode
-      ;; Turn on
-      (progn
-        (load-library "gnuplot-context")
-        (load-library "eldoc")
-        (setq gnuplot-completion-at-point-function #'gnuplot-context-completion-at-point)
-
-        ;; Setup Eldoc
-        (set (make-local-variable 'eldoc-documentation-function)
-             'gnuplot-eldoc-function)
-        (eldoc-add-command 'completion-at-point)     ; Check for eldoc after completion
-        (when (fboundp 'comint-dynamic-complete)
-          (eldoc-add-command 'comint-dynamic-complete))
-
-        ;; Try to load Eldoc strings
-        (when gnuplot-eldoc-mode
-          (unless gnuplot-eldoc-hash
-            (condition-case nil
-                (load-library "gnuplot-eldoc")
-              (error
-               (message "gnuplot-eldoc.el not found. Install it from the Gnuplot distribution.")
-               (setq gnuplot-eldoc-hash nil
-                     gnuplot-eldoc-mode nil))))
-
-          (if gnuplot-eldoc-hash
-              (eldoc-mode 1)
-            (eldoc-mode 0)))
-
-        ;; Set up tab-to-complete
-        (when gnuplot-tab-completion
-          (set (make-local-variable 'tab-always-indent) 'complete))
-
-       (message "Gnuplot context-sensitive help & completion enabled."))
-
-    ;; Turn off
-    (setq gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look)
-    (setq eldoc-documentation-function nil)
-    (eldoc-mode 0)
-    (message "Gnuplot context-sensitive help & completion disabled.")))
-
-;; Older completion method using info-look
-(defun gnuplot-completion-at-point-info-look ()
-  "Return completions of keyword preceding point.
-
-Uses the cache of keywords generated by info-lookup. See
-`gnuplot-setup-info-look'. If not nil, the return value is in the form
-\(BEGIN END COMPLETIONS) where BEGIN and END are buffer 
-positions and COMPLETIONS is a list."
- 
-  (if gnuplot-keywords-pending         ; <HW>
-      (gnuplot-setup-info-look))
-  (let* ((end (point))
-        (beg (unwind-protect (save-excursion (backward-sexp 1) (point))))
-        (patt (buffer-substring beg end))
-        (pattern (if (string-match "\\([^ \t]*\\)\\s-+$" patt)
-                     (match-string 1 patt) patt))
-        (completions (all-completions pattern gnuplot-keywords-alist)))
-    (if completions
-       (list beg end completions)
-      (message "No gnuplot keywords complete '%s'" pattern)
-      nil))) 
-
-(defun gnuplot-comint-complete ()
-  "Complete the keyword preceding point in the gnuplot comint buffer.
-
-This is only used in Emacs versions before 24.1."
-  (let ((completions (gnuplot-completion-at-point)))
-    (if completions
-       (let* ((beg (nth 0 completions))
-              (end (nth 1 completions))
-              (candidates (nth 2 completions))
-              (completion-base-position (list beg end)))
-         (comint-dynamic-simple-complete
-          (buffer-substring-no-properties beg end)
-          candidates))
-      nil)))
-
-\f
-(defun gnuplot-info-lookup-symbol (symbol &optional mode)
-  "Wrapper for `info-lookup-symbol'.
-Takes SYMBOL and MODE as arguments exactly as
-`info-lookup-symbol'.  After doing the info lookup, calls
-`gnuplot--adjust-info-display' to display the info buffer
-according to the value of `gnuplot-info-display'."
-  (interactive
-   (cond (gnuplot-keywords
-         (info-lookup-interactive-arguments 'symbol))
-        (gnuplot-keywords-pending      ; <HW>
-         (gnuplot-setup-info-look)
-         (info-lookup-interactive-arguments 'symbol))
-        (t
-         (list nil (message
-       "Help is not available.  The gnuplot info file could not be found.")))))
-
-  (when (and (featurep 'info-look) gnuplot-keywords)
-    (unless symbol (setq symbol "Commands"))
-    (save-window-excursion
-      (info-lookup-symbol symbol mode))
-    (gnuplot--adjust-info-display)))
-
-(defun gnuplot--adjust-info-display ()
-  "Displays the *info* buffer in a window or frame as specified
-by the value of `gnuplot-info-display'.  If
-`gnuplot-info-display' is 'window, then the window will be shrunk
-to the size of the info entry if it is smaller than half the
-height of the frame.
-
-The *info* buffer should already exist when this function is
-called."
-  (case gnuplot-info-display
-    (window
-     (switch-to-buffer-other-window "*info*")
-     ;; Adjust window height only if the frame is split 
-     ;; horizontally, so as not to mess up the minibuffer <jjo>
-     ;; we can't use shrink-window-if-larger-than-buffer here
-     ;; because it doesn't work with Info mode's narrowing
-     (with-selected-window (get-buffer-window "*info*")
-       (unless (gnuplot-window-full-height-p)
-         (enlarge-window
-          (min (- (count-lines (point-min) (point-max)) (window-height) -1)
-               (- (/ (frame-height) 2) (window-height)))))))
-
-    (frame
-     (unless (and gnuplot-info-frame
-                  (frame-live-p gnuplot-info-frame))
-       (setq gnuplot-info-frame (make-frame)))
-     (select-frame gnuplot-info-frame)
-     (raise-frame gnuplot-info-frame)
-     (if gnuplot-xemacs-p (setq toolbar-info-frame gnuplot-info-frame))
-     (switch-to-buffer "*info*"))
-
-    (t
-     (switch-to-buffer "*info*"))))
-
-(defun gnuplot-insert (string)
-  "Insert STRING at point and display help for for STRING.
-Help is not shown if `gnuplot-insertions-show-help-flag' is nil.  The
-help shown is for STRING unless STRING begins with the word \"set\" or
-\"show\", in which case help is shown for the thing being set or
-shown."
-  (interactive)
-  (cond ((and (not gnuplot-three-eight-p)
-             (string-match "\\(emf\\|p\\(alette\\|m3d\\)\\|vgagl\\)" string))
-        (message "%S is an option introduced in gnuplot 3.8 (You are using %s)"
-                 string gnuplot-program-version) )
-       (t
-        (insert string)
-        (let ((topic string) term)
-          (if (string-match
-               "\\(set\\|show\\)[ \t]+\\([^ \t]+\\)\\(\\s-+\\([^ \t]+\\)\\)?"
-               string)
-              (progn
-                (setq topic (downcase (match-string 2 string))
-                      term            (match-string 4 string))
-                (if (string= topic "terminal") (setq topic (downcase term)))))
-          (cond ((and (fboundp 'gnuplot-gui-set-options-and-insert)
-                      gnuplot-gui-popup-flag)
-                 (gnuplot-gui-set-options-and-insert))
-                (gnuplot-insertions-show-help-flag
-                 (if gnuplot-keywords-pending          ; <HW>
-                     (gnuplot-setup-info-look))
-                 (gnuplot-info-lookup-symbol topic)) ) )) ) )
-
-(defun gnuplot-toggle-info-display ()
-  (interactive)
-  (setq gnuplot-insertions-show-help-flag (not gnuplot-insertions-show-help-flag))
-  (message (if gnuplot-insertions-show-help-flag
-              "Help will be displayed after insertions."
-            "Help no longer displayed after insertions.")))
-
-\f
-;;; --- autoloaded functions: gnuplot-mode and gnuplot-make-buffer
-
-;;;###autoload
-(defun gnuplot-mode ()
-  "Major mode for editing and executing GNUPLOT scripts.
-This was written with version 4.6 of gnuplot in mind, but should
-work with newer and older versions.
-
-Report bugs at https://github.com/emacsorphanage/gnuplot/issues
-
-                           ------O------
-
-Gnuplot-mode includes two different systems for keyword
-completion and documentation lookup: a newer one,
-`gnuplot-context-sensitive-mode' (enabled by default), and a
-older one which extracts keywords from gnuplot's Info file.  Both
-systems allow looking up documentation in the Info file.  The
-older system also depends having the info file properly installed
-to make a list of keywords.
-
-The info file should be installed by default with the Gnuplot
-distribution, or is available at the `gnuplot-mode' web page:
-https://github.com/emacsorphanage/gnuplot/
-
-With the new context-sensitive mode active, gnuplot-mode can also
-provide `eldoc-mode' syntax hints as you type.  This requires a
-separate file of strings, `gnuplot-eldoc.el', which is also
-provided by recent Gnuplot distributions.
-
-                           ------O------
-
-There are several known shortcomings of `gnuplot-mode', version 0.5g
-and up.  Many of the shortcomings involve the graphical interface
-\(refered to as the GUI) to setting arguments to plot options.  Here is
-a list:
-
- 1.  Currently there is no way for `gnuplot-mode' to know if information
-     sent to gnuplot was correctly plotted.
- 2.  \"plot\", \"splot\", and \"fit\" are handled in the GUI, but are
-     a bit flaky.  Their arguments may not be read correctly from
-     existing text, and continuation lines (common for plot and splot)
-     are not supported.
- 3.  The GUI does not know how to read from continuation lines.
- 4.  Comma separated position arguments to plot options are
-     unsupported in the GUI.  Colon separated datafile modifiers (used
-     for plot, splot, and fit) are not supported either.  Arguments
-     not yet supported by the GUI generate messages printed in grey
-     text.
- 5.  The GUI handling of \"hidden3d\" is flaky and \"cntrparam\" is
-     unsupported.
-
-                           ------O------
-
- Key bindings:
- \\{gnuplot-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map gnuplot-mode-map)
-  (setq major-mode 'gnuplot-mode
-       mode-name "Gnuplot")
-  (set (make-local-variable 'comment-start) "# ")
-  (set (make-local-variable 'comment-end) "")
-  (set (make-local-variable 'comment-column) 32)
-  (set (make-local-variable 'comment-start-skip) "#[ \t]*")
-  (set (make-local-variable 'indent-line-function) 'gnuplot-indent-line)
-
-  (set (make-local-variable 'beginning-of-defun-function) 'gnuplot-beginning-of-defun)
-  (set (make-local-variable 'end-of-defun-function) 'gnuplot-end-of-continuation)
-
-  (unless (featurep 'xemacs)
-    (add-hook 'completion-at-point-functions 'gnuplot-completion-at-point nil t))
-
-  (set-syntax-table gnuplot-mode-syntax-table)
-
-  (when (eq gnuplot-keywords-when 'immediately) ; <HW>
-    (gnuplot-setup-info-look)) ;; <SE>
-
-  (if gnuplot-xemacs-p                 ; deal with font-lock
-      (when (fboundp 'turn-on-font-lock)
-       (turn-on-font-lock))
-    (progn
-      ;; Add syntax-propertizing functions to search for strings and comments
-      (set (make-local-variable 'syntax-propertize-function)
-           #'gnuplot-syntax-propertize)
-      (add-hook 'syntax-propertize-extend-region-functions
-                #'gnuplot-syntax-propertize-extend-region nil t)
-
-      ;; Set up font-lock 
-      (setq font-lock-defaults gnuplot-font-lock-defaults)
-      (set (make-local-variable 'font-lock-multiline) t)
-      (set (make-local-variable 'parse-sexp-lookup-properties) t)))
-
-  (if (fboundp 'widget-create)         ; gnuplot-gui
-      (condition-case ()
-         (require 'gnuplot-gui)
-       (error nil)))
-  (setq gnuplot-first-call nil         ; a few more details ...
-       gnuplot-comint-recent-buffer (current-buffer)
-        comint-process-echoes        gnuplot-echo-command-line-flag)
-  (run-hooks 'gnuplot-mode-hook)
-  ;; the first time we need to figure out which gnuplot we are running
-  (if gnuplot-program-version
-      (gnuplot-setup-menu-and-toolbar)
-    (gnuplot-fetch-version-number)))
-
-;;;###autoload
-(defun gnuplot-make-buffer ()
-  "Open a new buffer in `gnuplot-mode'.
-When invoked, it switches to a new, empty buffer visiting no file
-and then starts `gnuplot-mode'.
-
-It is convenient to bind this function to a global key sequence.  For
-example, to make the F10 key open a gnuplot script buffer, put the
-following in your .emacs file:
-     (autoload 'gnuplot-make-buffer \"gnuplot\"
-               \"open a buffer in gnuplot mode\" t)
-     (global-set-key [(f10)] 'gnuplot-make-buffer)"
-  (interactive)
-  (switch-to-buffer gnuplot-gnuplot-buffer)
-  (gnuplot-mode))
-
-;;;###autoload
-(defun run-gnuplot ()
-  "Run an inferior Gnuplot process."
-  (interactive)
-  (gnuplot-make-gnuplot-buffer)
-  (pop-to-buffer gnuplot-buffer))
-
-(defun gnuplot-show-version ()
-  "Show version number in echo area"
-  (interactive)
-  (message "gnuplot-mode %s -- URL: %s" gnuplot-version gnuplot-maintainer-url))
-
-(defun gnuplot-show-gnuplot-version ()
-  "Show gnuplot program and version number in echo area"
-  (interactive)
-  (gnuplot-fetch-version-number)
-  (message "You are calling gnuplot %s as %s" gnuplot-program-version gnuplot-program))
-
-
-;;; That's it! ----------------------------------------------------------------
-
-\f
-;;; --- final chores: provide 'gnuplot and run load-hook
-;; provide before run-hooks suggested by <DB>
-(provide 'gnuplot)
-(run-hooks 'gnuplot-load-hook)
-
-;;;============================================================================
-;;;
-
-;;; gnuplot.el ends here
diff --git a/elpa/gnuplot-20230323.1400/gnuplot-autoloads.el b/elpa/gnuplot-20230323.1400/gnuplot-autoloads.el
new file mode 100644 (file)
index 0000000..ab8ca90
--- /dev/null
@@ -0,0 +1,180 @@
+;;; gnuplot-autoloads.el --- automatically extracted autoloads  -*- lexical-binding: t -*-
+;;
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+                         (or (file-name-directory #$) (car load-path))))
+
+\f
+;;;### (autoloads nil "gnuplot" "gnuplot.el" (0 0 0 0))
+;;; Generated autoloads from gnuplot.el
+
+(autoload 'gnuplot-mode "gnuplot" "\
+Major mode for editing and executing GNUPLOT scripts.
+This was written with version 4.6 of gnuplot in mind, but should
+work with newer and older versions.
+
+Report bugs at https://github.com/emacs-gnuplot/gnuplot/issues
+
+                            ------O------
+
+Gnuplot-mode includes two different systems for keyword
+completion and documentation lookup: a newer one,
+`gnuplot-context-sensitive-mode' (enabled by default), and a
+older one which extracts keywords from gnuplot's Info file.  Both
+systems allow looking up documentation in the Info file.  The
+older system also depends having the info file properly installed
+to make a list of keywords.
+
+The info file should be installed by default with the Gnuplot
+distribution, or is available at the `gnuplot-mode' web page:
+https://github.com/emacs-gnuplot/gnuplot/
+
+With the new context-sensitive mode active, `gnuplot-mode' can also
+provide function/`eldoc-mode' syntax hints as you type.  This requires a
+separate file of strings, `gnuplot-eldoc.el', which is also
+provided by recent Gnuplot distributions.
+
+                            ------O------
+
+There are several known shortcomings of `gnuplot-mode', version 0.5g
+and up.  Many of the shortcomings involve the graphical interface
+\(refered to as the GUI) to setting arguments to plot options.  Here is
+a list:
+
+ 1.  Currently there is no way for `gnuplot-mode' to know if information
+     sent to gnuplot was correctly plotted.
+ 2.  \"plot\", \"splot\", and \"fit\" are handled in the GUI, but are
+     a bit flaky.  Their arguments may not be read correctly from
+     existing text, and continuation lines (common for plot and splot)
+     are not supported.
+ 3.  The GUI does not know how to read from continuation lines.
+ 4.  Comma separated position arguments to plot options are
+     unsupported in the GUI.  Colon separated datafile modifiers (used
+     for plot, splot, and fit) are not supported either.  Arguments
+     not yet supported by the GUI generate messages printed in grey
+     text.
+ 5.  The GUI handling of \"hidden3d\" is flaky and \"cntrparam\" is
+     unsupported.
+
+                            ------O------
+
+ Key bindings:
+ \\{gnuplot-mode-map}" t nil)
+
+(autoload 'gnuplot-make-buffer "gnuplot" "\
+Open a new buffer in `gnuplot-mode'.
+When invoked, it switches to a new, empty buffer visiting no file
+and then starts `gnuplot-mode'.
+
+It is convenient to bind this function to a global key sequence.  For
+example, to make the F10 key open a gnuplot script buffer, put the
+following in your .emacs file:
+     (autoload 'gnuplot-make-buffer \"gnuplot\"
+               \"open a buffer in gnuplot mode\" t)
+     (global-set-key [(f10)] 'gnuplot-make-buffer)" t nil)
+
+(autoload 'run-gnuplot "gnuplot" "\
+Run an inferior Gnuplot process." t nil)
+
+(register-definition-prefixes "gnuplot" '("gnuplot-"))
+
+;;;***
+\f
+;;;### (autoloads nil "gnuplot-context" "gnuplot-context.el" (0 0
+;;;;;;  0 0))
+;;; Generated autoloads from gnuplot-context.el
+
+(autoload 'gnuplot-context-sensitive-mode "gnuplot-context" "\
+Use context-sensitive completion and help in `gnuplot-mode'.
+
+This is a minor mode.  If called interactively, toggle the
+`Gnuplot-Context-Sensitive mode' mode.  If the prefix argument is
+positive, enable the mode, and if it is zero or negative, disable
+the mode.
+
+If called from Lisp, toggle the mode if ARG is `toggle'.  Enable
+the mode if ARG is nil, omitted, or is a positive number.
+Disable the mode if ARG is a negative number.
+
+To check whether the minor mode is enabled in the current buffer,
+evaluate `gnuplot-context-sensitive-mode'.
+
+The mode's hook is called both when the mode is enabled and when
+it is disabled.
+
+When context-sensitive mode is enabled, `gnuplot-mode' tries to
+provide more useful completions and help suggestions for built-in
+keywords and functions by parsing each command as you type.  It
+attempts to take into account Gnuplot's many abbreviated
+keywords.  For example, with point at the end of a line reading
+\"plot 'datafile' w \", typing \\[completion-at-point] will pop
+up a list of plotting styles.
+
+Key bindings:
+
+\\[completion-at-point] will complete the keyword at point based
+on its context in the command. To make keyword completion work on
+pressing TAB, set `tab-always-indent' to `complete', or customize
+`gnuplot-tab-completion' to make this automatic in gnuplot-mode
+buffers.
+
+\\[gnuplot-info-at-point] will try to find the most relevant
+Gnuplot info node for the construction at point, prompting for a
+node name if nothing is found.
+
+\\[gnuplot-help-function] will pop up a brief summary of the
+syntax at point in the minibuffer. To have one-line syntax
+summaries appear in the echo area as you type, toggle
+`eldoc-mode' or customize `gnuplot-eldoc-mode'.
+
+To choose whether to use this mode by default in Gnuplot buffers,
+customize the variable
+`gnuplot-use-context-sensitive-completion'.
+
+Note: help strings for eldoc-mode and \\[gnuplot-help-function]
+need to be provided in an Emacs-readable form by the Gnuplot
+distribution. See gnuplot-context.el for details.
+
+\(fn &optional ARG)" t nil)
+
+(register-definition-prefixes "gnuplot-context" '("gnuplot-"))
+
+;;;***
+\f
+;;;### (autoloads nil "gnuplot-gui" "gnuplot-gui.el" (0 0 0 0))
+;;; Generated autoloads from gnuplot-gui.el
+
+(autoload 'gnuplot-gui-swap-simple-complete "gnuplot-gui" nil t nil)
+
+(autoload 'gnuplot-gui-mouse-set "gnuplot-gui" "\
+Use the mouse to begin setting options using a GUI interface.
+EVENT is a mouse event.  Bound to \\[gnuplot-gui-mouse-set]
+Note that \"plot\", \"splot\", \"fit\", and \"cntrparam\" are not
+currently supported.
+
+\(fn EVENT)" t nil)
+
+(autoload 'gnuplot-gui-set-options-and-insert "gnuplot-gui" "\
+Insert arguments using a GUI interface.
+Determine contents of current line and set up the appropriate GUI
+frame.  Bound to \\[gnuplot-gui-set-options-and-insert]
+Note that \"cntrparam\" is not currently supported." t nil)
+
+(autoload 'gnuplot-gui-toggle-popup "gnuplot-gui" nil t nil)
+
+(register-definition-prefixes "gnuplot-gui" '("gnuplot-"))
+
+;;;***
+\f
+;;;### (autoloads nil nil ("gnuplot-pkg.el") (0 0 0 0))
+
+;;;***
+\f
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8
+;; End:
+;;; gnuplot-autoloads.el ends here
diff --git a/elpa/gnuplot-20230323.1400/gnuplot-context.el b/elpa/gnuplot-20230323.1400/gnuplot-context.el
new file mode 100644 (file)
index 0000000..dfa2019
--- /dev/null
@@ -0,0 +1,2267 @@
+;;; gnuplot-context.el -- context-sensitive help and completion for gnuplot -*- lexical-binding: t -*-
+
+;; Copyright (C) 2012-2013 Jon Oddie <jonxfieldNOSPAMgmail.com>
+
+;; Author:     Jon Oddie <jonxfieldNOSPAMgmail.com>
+;; URL:        https://github.com/emacs-gnuplot/gnuplot
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+;; This file enhances gnuplot-mode with context-sensitive completion,
+;; ElDoc support, and info page lookup for gnuplot script and shell
+;; buffers.
+;;
+;; Usage
+;; =====
+;;
+;; Make sure to byte-compile this file, or things will be noticeably
+;; slow.
+;;
+;; Summary of key bindings:
+;;     C-c C-d            read info page for construction at point
+;;     C-u C-c C-d        prompt for info page to read
+;;     C-c M-h, C-c C-/   pop up multi-line ElDoc string for construction
+;;                          at point
+;;
+;; Gnuplot's context sensitive mode is best controlled using Customize
+;; (M-x customize-group gnuplot): simply enable the
+;; `gnuplot-context-sensitive-mode' setting. You may also want to turn
+;; on `gnuplot-tab-completion' so that the TAB key does auto-completion
+;; on lines which are already indented. (This just sets the Emacs
+;; variable `tab-always-indent' to `complete' in Gnuplot buffers).
+;;
+;; If you need to turn context sensitivity on or off from Lisp code
+;; for some reason, call the function
+;; `gnuplot-context-sensitive-mode', which behaves like a minor mode.
+;;
+;; With `eldoc-mode' support, gnuplot-mode will show one-line syntax
+;; hints automatically in the echo area.  Whether eldoc-mode is active
+;; or not, you can always pop up a longer description of syntax using
+;; `gnuplot-help-function' (C-c C-/ or C-c M-h).  ElDoc support also
+;; requires an additional file of help strings, `gnuplot-eldoc.el',
+;; which should be included in recent Gnuplot releases.  If it didn't
+;; come with your Gnuplot installation, you'll need to grab a recent
+;; source distribution of Gnuplot from http://gnuplot.info, and use
+;; the `doc2texi.el' program in the docs/ directory to create it.  So
+;; long as the file is on your Emacs load path somewhere it will be
+;; loaded automatically when needed.
+;;
+;; You can customize gnuplot-mode to turn on eldoc mode automatically
+;; using variable `gnuplot-eldoc-mode'.  Simply calling `eldoc-mode'
+;; will also work.
+;;
+;; Internal details
+;; ================
+;;
+;; Gnuplot's command language has a fair amount of syntactic
+;; complexity, and the only way I could think of to support these
+;; features was to do a complete parse of the command line.  So that's
+;; what this package does.  Instead of building a parse tree, it
+;; matches up until the token at point, and then either makes a list
+;; of possible completions, or sets the variables `gnuplot-eldoc' and
+;; `gnuplot-info-at-point' based on where it is in the grammar at that
+;; point.
+;;
+;; The parsing/matching process happens in two phases: tokenizing
+;; (`gnuplot-tokenize') and matching (`gnuplot-match-pattern').  In
+;; order to be able to construct a full list of possible completions
+;; via backtracking, the matching algorithm simulates a simple stack
+;; machine with continuations.  At byte-compile time, the PEG-like
+;; grammar in S-expression notation (`gnuplot-grammar') is compiled
+;; down into a vector of "machine code" for the parsing machine (see
+;; `gnuplot-compile-pattern', `gnuplot-compile-grammar' and
+;; `gnuplot-compiled-grammar'). This is complicated, but it seems to
+;; work well enough, and it saves on the Emacs call stack.
+;;
+;; Compiling the grammar does require increasing `max-lisp-eval-depth'
+;; modestly.  This shouldn't cause any problems on modern machines, and
+;; it only needs to be done once, at byte-compilation time.
+;;
+;; The parsing machine and compiler are partially based on the
+;; description in Medeiros and Ierusalimschy 2008, "A Parsing Machine
+;; for PEGs" (http://dl.acm.org/citation.cfm?doid=1408681.1408683).
+;;
+;; The pattern-matching language
+;; =============================
+;;
+;; The gnuplot-mode grammar (see `gnuplot-compiled-grammar') is a list
+;; of rules (RULE PATTERN), with each pattern written in S-expression
+;; notation as follows:
+;;
+;;    any
+;;      Match any token
+;;
+;;    name, number, string, separator
+;;      Match a token of the given type.  "Separator" is semicolon, the
+;;      statement separator.
+;;
+;;    Any other symbol
+;;      Match another named rule in the grammar.  May be recursive.
+;;
+;;    "STRING"
+;;      Match literally: a token with exactly the text "STRING".
+;;
+;;   (kw KEYWORD ALIASES ...)
+;;  Match abbreviated Gnuplot keywords.  KEYWORD can be a string or
+;;  a cons (PREFIX . SUFFIX).  In the latter case, this pattern
+;;  will match PREFIX plus any number of characters from the
+;;  beginning of SUFFIX.  Any literal string from ALIASES will
+;;  also match.  The token-id of the matching token is mutated to
+;;  the canonical value of KEYWORD.
+;;  Example:
+;;   (kw ("linew" ."idth") "lw") matches "linew", "linewi",
+;;  ... "linewidth" as well as "lw".  Any of these tokens will
+;;  appear as "linewidth" in subsequent processing.  (This is
+;;  important for the "info-keyword" form, see below).
+;;
+;; The other pattern forms combine simpler patterns, much like regular
+;; expressions or PEGs (parsing expression grammars):
+;;
+;;    (sequence { (:eldoc "eldoc string") }
+;;              { (:info "info page") }
+;;              { (:no-info) }
+;;           PATTERN PATTERN... )
+;;      Match all the PATTERNs in sequence or fail.  Sequences can also
+;;      have optional ElDoc strings and info pages associated with
+;;      them; the innermost ElDoc or info page around point is the one
+;;      shown to the user.  Alternatively, either property may be a
+;;      symbol, which should be a function to be called to get the
+;;      real value.  Finally, if no ElDoc string is specified but the
+;;      variable `gnuplot-eldoc-hash' contains a value for the name of
+;;      the info page at point, that value is used as the ElDoc string
+;;      instead.
+;;
+;;  For better readability, sequence forms can also be written as
+;;  a vector, omitting the `sequence': [PATTERN PATTERN ...]
+;;
+;;    (either PATTERN PATTERN...)
+;;      Match the first PATTERN to succeed, or fail if none
+;;      matches.  Like regexp `|'.
+;;
+;;    (many PATTERN)
+;;  Match PATTERN zero or more times, greedily; like regexp
+;;  `*'.  Unlike a regular expression matcher, the parsing machine
+;;  will not backtrack and try to match fewer times if a later
+;;  part of the pattern fails.  This applies equally to the other
+;;  non-deterministic forms "either" and "maybe".
+;;
+;;    (maybe PATTERN)
+;;      Match PATTERN zero or one times, like regexp `?'.
+;;
+;;    (capture NAME PATTERN)
+;;      Match PATTERN, capturing the tokens in a capture group named
+;;      NAME.  Capture groups are stored in `gnuplot-captures'
+;;      and can be retrieved using `gnuplot-capture-group'.  This is
+;;      used to store the plotting style, which we need in order to
+;;      give the correct ElDoc string for "using" clauses, and for
+;;      info keywords (see below)
+;;
+;;    (info-keyword PATTERN)
+;;      Match PATTERN, and use whatever the value of the first token
+;;      it matches is to look up info pages for this pattern.  Most
+;;      Gnuplot info pages have the same name as the keyword they
+;;      document, so by using this we only have to put :info
+;;      properties on the few that don't, such as "set".
+;;
+;;    For convenience, "many", "maybe", "capture" and "info-keyword"
+;;    wrap the rest of their arguments in an implicit "sequence" form,
+;;    so we can write (maybe "," expression) instead of
+;;    (maybe (sequence "," expression))
+;;
+;;    (delimited-list PATTERN SEPARATOR)
+;;      Match a list of PATTERNs separated by SEPARATOR.  Sugar for:
+;;      (sequence PATTERN (many (sequence SEPARATOR PATTERN)))
+;;
+;;   (assert LISP-FORM)
+;;  Evaluate LISP-FORM and fail if it returns NIL.  We need this in
+;;  the patterns for "plot" and "splot" to check whether the
+;;  command at point should be parsed in parametric mode or
+;;  not.  See `gnuplot-guess-parametric-p'.
+;;
+;;
+;; Bugs, TODOs, etc.
+;; =======================
+;;
+;; It would be useful to complete on user-defined functions and
+;; variables as well as built-ins.
+;;
+;; Completion probably will not work in continuation lines entered
+;; into the gnuplot interaction buffer.
+;;
+;; It would be better to pop up longer syntax descriptions in a
+;; temporary window, rather than making the echo area grow to fit
+;; many lines.
+;;
+;; In ElDoc mode, we parse the whole line every time the user stops
+;; typing.  This is wasteful; should cache things in text properties
+;; instead.
+;;
+;; The pattern matching engine uses backtracking, which can take
+;; exponential time.  So far it seems "fast enough" in actual use.
+;;
+;; The patterns don't really distinguish between "plot" and "splot"
+;; for things like plot styles, binary arguments, etc.
+;;
+;; Some other the patterns are probably not quite right, especially for
+;; things like abbreviated keywords, and features that I don't use
+;; myself like "fit".  Hopefully anyone bothered by this will submit
+;; patches ;-)
+;;
+;; It would be possible to provide more helpful ElDoc strings for
+;; sub-parts of complicated options like "cntrparam".  This is a time
+;; and maintenance issue rather than a technical one.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'gnuplot)
+(require 'eldoc)
+(require 'info)
+(require 'info-look)
+
+\f
+;;;; The tokenizer.
+
+(cl-defstruct gnuplot-token
+  start     ; Buffer start position
+  end       ; Buffer end position
+  id        ; Text
+  type)     ; a symbol: name, number, string, operator, separator
+
+(defvar gnuplot-operator-regexp
+  (eval-when-compile
+    (regexp-opt
+     '("(" ")" "(" ")" "{" "," "}" "[" ":" "]" "!" "**" "-" "+" "~" "!" "*" "/"
+       "%" "+" "-" "." "<" "<=" ">" ">=" "==" "!=" "eq" "ne" "&" "^" "|" "&&" "||"
+       "?" ":" "=" "$")))
+  "Regexp to match Gnuplot operators for tokenizing.")
+
+(eval-when-compile
+  (defmacro gnuplot-tokenize-by-regexps (&rest rules)
+    `(cond ,@(mapcar
+              (lambda (rule)
+                (let ((regexp (car rule))
+                      (token-type (cadr rule)))
+                  `((looking-at ,regexp)
+                    (let ((str (match-string-no-properties 0)))
+                      (forward-char (length str))
+                      (make-gnuplot-token :id str
+                                          :type ',token-type
+                                          :start (match-beginning 0)
+                                          :end (match-end 0))))))
+              rules))))
+
+(defun gnuplot-tokenize (&optional completing-p)
+  "Tokenize the Gnuplot command at point.
+Return a list of `gnuplot-token' objects.
+
+If COMPLETING-P is non-nil, omits the token at point if it is a
+name; otherwise continues tokenizing up to the token at point.  FIXME."
+  (let ((tokens '())
+        (stop-point (min (point)
+                         (gnuplot-point-at-end-of-command))))
+    (save-excursion
+      (if (save-excursion               ; HACK FIXME
+            (gnuplot-beginning-of-continuation)
+            (looking-at "\\s-*if\\s-*("))
+          (gnuplot-beginning-of-continuation)
+        (gnuplot-beginning-of-command))
+      (while
+          ;; Skip whitespace and continuation lines
+          (progn
+            (skip-syntax-forward "-" stop-point)
+            (while (looking-at "\\\\\n")
+              (forward-line)
+              (skip-syntax-forward "-" stop-point))
+            ;; Don't tokenize anything starting after point
+            (and (not (looking-at "#"))
+                 (< (point) stop-point)))
+        (let* ((from (point))
+               (token
+                (cond
+                 ((gnuplot-tokenize-by-regexps
+                   ("[[:alpha:]_][[:alpha:]0-9_]*" name)
+                   ("[0-9]+\\(\\.[0-9]*\\)?\\([eE][+-]?[0-9]+\\)?\\|\\.[0-9]+\\([eE][+-]?[0-9]+\\)?" number)
+                   (gnuplot-operator-regexp operator)
+                   (";" separator)))
+
+                 ((looking-at "['\"]")
+                  (let* ((bounds (bounds-of-thing-at-point 'sexp))
+                         (to (or (cdr bounds) stop-point)))
+                    (goto-char to)
+                    (make-gnuplot-token
+                     :id (buffer-substring-no-properties from to)
+                     :type 'string
+                     :start from :end to)))
+
+                 (t (error
+                     "Gnuplot-tokenize: bad token beginning %s"
+                     (buffer-substring-no-properties (point) stop-point))))))
+
+          (push token tokens))))
+
+    ;; If we are looking for completions, AND if the last token
+    ;; read is a name, AND if point is within the bounds of the
+    ;; last token, then discard it. The matching function
+    ;; generates a list of all possible tokens that could appear
+    ;; in that position for completion.
+    (if (and completing-p
+             tokens
+             (eq (gnuplot-token-type (car tokens)) 'name)
+             (<= (point) (gnuplot-token-end (car tokens))))
+        (pop tokens))
+
+    (nreverse tokens)))
+
+
+\f
+;;;; The pattern and grammar compiler
+;;
+;; These functions compile the source S-expression grammar into a
+;; vector of instructions for the parsing machine,
+;; `gnuplot-match-pattern'. Its state consists of a program counter
+;; (PC), a position in the list of tokens, a call stack, and a second
+;; stack of backtracking entries (continuations). Its "machine
+;; instructions" are the following:
+;;
+;;    (any)
+;;      Match any token (fails only at end of command).
+;;
+;;    (literal LITERAL NO-COMPLETE)
+;;      Match token with `gnuplot-token-id' LITERAL or fail. If we
+;;      have reached the token before point, include LITERAL in the
+;;      completion list unless NO-COMPLETE is non-`nil'.
+;;
+;;    (token-type TYPE)
+;;      Match a token with `gnuplot-token-type' TYPE, or fail.
+;;
+;;    (keyword REGEXP NAME)
+;;      Match any token whose `gnuplot-token-id' matches REGEXP. Use
+;;      NAME for the completion list.
+;;
+;;    (jump OFFSET FIXED)
+;;      Jump to (set PC to) OFFSET if FIXED is non-nil, otherwise to
+;;      PC + OFFSET
+;;
+;;    (call OFFSET FIXED)
+;;      Like "jump", but push a return address onto the stack for
+;;      (return). (The compiler adds the name of the rule being called
+;;      as a fourth element on the end of the list, but this is just a
+;;      comment for debugging purposes).
+;;
+;;    (return)
+;;      Return to the PC address on top of the stack, or finish
+;;      matching if stack is empty. (Usually this doesn't happen,
+;;      because the machine stops as soon as it gets to the token at
+;;      point).
+;;
+;;    (choice OFFSET)
+;;      Push a backtracking entry for location PC + OFFSET onto the
+;;      backtracking stack. Backtracking entries save the contents of
+;;      the call stack, position in the token list, the values of
+;;      capture groups, and the record of loop progress (see below).
+;;
+;;    (check-progress)
+;;      Break out of infinite loops, like (many (many ...)).  Checks
+;;      an alist of conses (pc . tokens) for the position in the token
+;;      stream the last time this instruction was reached, and breaks
+;;      out of the loop if stuck in the same place; otherwise pushes a
+;;      new entry onto the list.
+;;
+;;    (fail)
+;;      Pop the most recent backtracking entry and continue from
+;;      there, or fail the whole match if out of backtrack
+;;      points. Failing to match returns the remainder of the token
+;;      list, although we don't currently use this for anything.
+;;
+;;    (commit OFFSET)
+;;      Discard one backtracking point and jump to PC + OFFSET. This
+;;      is used to make the (either) form non-deterministic.
+;;
+;;    (push TYPE VALUE)
+;;      Push an entry for an eldoc or info string (specified by TYPE)
+;;      onto the stack.
+;;
+;;    (pop TYPE)
+;;      Pop something off the stack; checks that it has the expected
+;;      TYPE, for safety.
+;;
+;;    (save-start NAME)
+;;      Open a capture group named NAME. Pushes an entry onto
+;;      `gnuplot-captures' with current position in token list as the
+;;      start of the group.
+;;
+;;    (save-end NAME)
+;;      Close the capture group named NAME. Finds the topmost entry in
+;;      `gnuplot-captures' with this name and sets its endpoint to the
+;;      current position in token list. Error if no group with that
+;;      name is found.
+;;
+;;    (label NAME)
+;;      This should never be reached and will cause an error. The
+;;      compiler inserts it at the beginning of compiled rules only
+;;      for debugging purposes.
+;;
+
+
+(eval-and-compile
+  ;; Compile a single pattern into a list of instructions. Leaves
+  ;; calls to other rules as symbolic instructions (call SYMBOL) and
+  ;; jumps, commits etc. as relative offsets; these are resolved into
+  ;; absolute locations by `gnuplot-compile-grammar', below.
+  (defun gnuplot-compile-pattern (pat)
+    (cond
+     ;; Strings match a single token literally
+     ((stringp pat)
+      ;; Don't add non-words to completion lists
+      (let ((wordp (string-match-p "^\\sw\\(\\sw\\|\\s_\\)*$" pat)))
+        `((literal ,pat ,(not wordp)))))
+
+     ;; Symbols match token types or calls to other patterns
+     ((symbolp pat)
+      (cl-case pat
+        ((any) `((any)))
+        ((name number string separator) `((token-type ,pat)))
+        (t `((call ,pat)))))
+
+     ;; Syntactic sugar: write sequences (sequence ...) as vectors [...]
+     ((vectorp pat)
+      (gnuplot-compile-pattern
+       (append '(sequence) pat '())))
+
+     ;; Other forms combine simpler patterns
+     (t
+      (let ((type (car pat)))
+        (cl-case type
+          ;; (sequence...): concatenate patterns, with optional eldoc
+          ;; and info strings
+          ((sequence)
+           (cl-destructuring-bind
+               (subpats eldoc info)
+               (gnuplot-filter-arg-list (cdr pat))
+             (let ((eldoc-push '()) (eldoc-pop '())
+                   (info-push '()) (info-pop '())
+                   (compiled
+                    (mapcar 'gnuplot-compile-pattern subpats)))
+               (if eldoc
+                   (setq eldoc-push `((push eldoc ,eldoc))
+                         eldoc-pop `((pop eldoc))))
+               (if info
+                   (if (eq info :no-info)
+                       (setq info-push '((push no-scan t))
+                             info-pop '((pop no-scan)))
+                     (setq info-push `((push info ,info))
+                           info-pop `((pop info)))))
+               (apply 'append
+                      `(,info-push
+                        ,eldoc-push
+                        ,@compiled
+                        ,eldoc-pop
+                        ,info-pop)))))
+
+          ;; (either...): choose between patterns
+          ((either)
+           (cond
+            ((= (length pat) 2)         ; trivial case
+             (gnuplot-compile-pattern (cadr pat)))
+
+            ((> (length pat) 3)         ; could be more efficient...
+             (gnuplot-compile-pattern (gnuplot-either-helper pat)))
+
+            (t              ; two patterns
+             (let* ((pat1 (cadr pat))
+                    (pat2 (cl-caddr pat))
+                    (pat1-c (gnuplot-compile-pattern pat1))
+                    (pat2-c (gnuplot-compile-pattern pat2))
+                    (pat1-l (length pat1-c))
+                    (pat2-l (length pat2-c)))
+               `((choice ,(+ pat1-l 2))
+                 ,@pat1-c
+                 (commit ,(+ pat2-l 1))
+                 ,@pat2-c)))))
+
+          ;; Repetition (*)
+          ((many)
+           (let* ((pat1 (cons 'sequence (cdr pat)))
+                  (pat1-c (gnuplot-compile-pattern pat1))
+                  (pat1-l (length pat1-c)))
+             `((choice ,(+ pat1-l 3))
+               (check-progress)         ; bail out of infinite loops
+               ,@pat1-c
+               (commit ,(- (+ pat1-l 2))))))
+
+          ;; Repetition (+)
+          ((many1)
+           (let* ((pat1 (cdr pat)))
+             (gnuplot-compile-pattern
+              `(sequence ,@pat1 (many ,@pat1)))))
+
+
+          ;; Optional (?)
+          ((maybe)
+           (let* ((pat1 (cons 'sequence (cdr pat)))
+                  (pat1-c (gnuplot-compile-pattern pat1))
+                  (pat1-l (length pat1-c)))
+             `((choice ,(+ pat1-l 1))
+               ,@pat1-c)))
+
+          ;; Syntactic sugar for delimited lists
+          ((delimited-list)
+           (let* ((item (cadr pat))
+                  (sep (cl-caddr pat)))
+             (gnuplot-compile-pattern
+              `(sequence ,item (many (sequence ,sep ,item))))))
+
+          ;; keywords
+          ((kw)
+           (cl-destructuring-bind (regex name)
+               (gnuplot-keyword-helper (cdr pat))
+             `((keyword ,regex ,name))))
+
+          ;; Capturing groups
+          ((capture)
+           (let* ((name (cadr pat))
+                  (pat1 (cons 'sequence (cddr pat)))
+                  (pat1-c (gnuplot-compile-pattern pat1)))
+             `((save-start ,name)
+               ,@pat1-c
+               (save-end ,name))))
+
+          ;; Use the first token as an info keyword
+          ((info-keyword)
+           (let* ((pat1 (cons 'sequence (cdr pat)))
+                  (pat1-c (gnuplot-compile-pattern pat1)))
+             `((push info first-token)
+               ,@pat1-c
+               (pop info))))
+
+          ;; Assertions
+          ((assert)
+           (let* ((form (cadr pat)))
+             `((assert ,form))))
+
+          (t
+           (error "Gnuplot-compile-pattern: bad pattern form %s" pat)))))))
+
+  ;; Helper function for destructuring (sequence ...) forms in patterns
+  ;; Takes the cdr of the sequence form, returns a list (PATTERNS ELDOC
+  ;; INFO).
+  (defun gnuplot-filter-arg-list (args)
+    (let ((accum '())
+          (eldoc nil) (info nil))
+      (dolist (item args)
+        (let ((type (car-safe item)))
+          (cl-case type
+            ((:eldoc) (setq eldoc (cadr item)))
+            ((:no-info) (setq info :no-info)) ; inhibit stack scanning
+            ((:info) (setq info (cadr item)))
+            (t (push item accum)))))
+      (list (reverse accum) eldoc info)))
+
+  ;; Helper function for compiling (kw...) patterns
+  ;; Takes the cdr of the kw form, returns a list (REGEXP KEYWORD)
+  (defun gnuplot-keyword-helper (args)
+    (let ((keyword (car args)) (aliases (cdr args)))
+      (when (consp keyword)
+        (let ((pre (car keyword)) (suf (cdr keyword)))
+          (setq keyword (concat pre suf))
+          (while (progn
+                   (push pre aliases)
+                   (not (zerop (length suf))))
+            (setq pre (concat pre (substring suf 0 1))
+                  suf (substring suf 1)))))
+      (let ((regex
+             (concat "^"
+                     (regexp-opt (cons keyword aliases))
+                     "$")))
+        (list regex keyword))))
+
+  ;; Helper function for compiling (either ...) patterns. Rewrites
+  ;; alternates (either A B C) into (either A (either B (either C D)))
+  (defun gnuplot-either-helper (pat)
+    (if (= (length pat) 3)
+        pat
+      `(either ,(cadr pat)
+               ,(gnuplot-either-helper
+                 (cons 'either (cddr pat))))))
+
+  ;; Compile the grammar (a list of rule-pattern pairs (RULE PATTERN))
+  ;; into a single vector of matching-machine instructions. Compiles
+  ;; each pattern individually, then "links" them into one vector,
+  ;; converting symbolic (call ...) instructions into numeric offsets
+  (defun gnuplot-compile-grammar (grammar start-symbol)
+    (let ((compiled-pats '())         ; Alist of (name . instructions)
+          ;; Reserve space for a jump to the start symbol
+          (code-length 1))
+
+      ;; Compile each rule and find the total number of instructions
+      (dolist (item grammar)
+        (let* ((name (car item))
+               (pat (cadr item))
+               (code (gnuplot-compile-pattern pat)))
+          (push (cons name code) compiled-pats)
+          ;; Reserve space for a label at the beginning and (return) at
+          ;; the end
+          (setq code-length (+ code-length 2 (length code)))))
+
+      ;; Copy instructions into a single vector
+      (let ((object-code (make-vector code-length nil))
+            (name->offset (make-hash-table))
+            (i 1))
+        (setf (aref object-code 0) `(jump ,start-symbol))
+        (dolist (chunk compiled-pats)
+          (let ((name (car chunk))
+                (code (cdr chunk)))
+            (setf (aref object-code i) `(label ,name))
+            (cl-incf i)
+            (puthash name i name->offset)
+            (while code
+              (setf (aref object-code i) (car code)
+                    code (cdr code)
+                    i (1+ i)))
+            (setf (aref object-code i) '(return)
+                  i (1+ i))))
+
+        ;; Resolve symbolic and relative jumps
+        (let ((pattern-name nil))
+          (dotimes (i (length object-code))
+            (let ((inst (aref object-code i)))
+              (cl-case (car inst)
+                ((label)
+                 (setq pattern-name (cadr inst)))
+
+                ((jump call choice commit)
+                 (cond
+                  ((symbolp (cadr inst))
+                   (let* ((name (cadr inst))
+                          (location (gethash name name->offset)))
+                     (if (not location)
+                         (error
+                          (concat "gnuplot-compile-grammar: "
+                                  "No rule found for symbol `%s' in pattern `%s'")
+                          name pattern-name))
+                     (setcdr inst `(,location ,name))))
+
+                  ((numberp (cadr inst))
+                   (let* ((offset (cadr inst))
+                          (location (+ offset i)))
+                     (setcdr inst `(,location))))
+
+                  (t
+                   (error "Gnuplot-compile-grammar: bad instruction %s" inst))))))))
+        object-code))))
+
+;;; The grammar.
+(defvar gnuplot-compiled-grammar
+  (eval-when-compile
+    (let ((max-lisp-eval-depth 600))
+      (gnuplot-compile-grammar
+       '((expression
+          [infix-expression (maybe "?" expression ":" expression)])
+
+         (prefix-operator
+          (either "!" "~" "-" "+"))
+
+         (infix-operator
+          (either "**" "*" "/" "%" "+" "-" "." "<" "<=" ">" ">=" "==" "!=" "eq" "ne"
+                  "&" "^" "|" "&&" "||"))
+
+         (infix-expression
+          [(many prefix-operator)
+           primary-expression
+           (many infix-operator expression)])
+
+         (primary-expression
+          [(either number string parenthesized-expression
+                   column-ref complex-number function-call name)
+           (many "!")
+           (maybe "**" infix-expression)
+           (maybe substring-range)])
+
+         (function-call
+          (either
+           (info-keyword
+            [(either "abs" "acos" "acosh" "arg" "asin" "asinh" "atan" "atan2" "atanh"
+                     "besj0" "besj1" "besy0" "besy1" "ceil" "column" "columnhead"
+                     "cos" "cosh" "defined" "erf" "erfc" "exists" "exp" "floor"
+                     "gamma" "gprintf" "ibeta" "igamma" "imag" "int" "inverf"
+                     "invnorm" "lambertw" "lgamma" "log" "log10" "norm" "real"
+                     "sgn" "sin" "sinh" "sprintf" "sqrt" "strftime" "stringcolumn"
+                     "strlen" "strptime" "strstrt" "substr" "tan" "tanh" "timecolumn"
+                     "tm_hour" "tm_mday" "tm_min" "tm_mon" "tm_sec" "tm_wday"
+                     "tm_yday" "tm_year" "valid" "value" "word" "words" "rand")
+             parenthesized-expression])
+           [(:info "elliptic_integrals")
+            (either "EllipticK" "EllipticE" "EllipticPi")
+            parenthesized-expression]
+           [name
+            parenthesized-expression]))
+
+         (parenthesized-expression
+          ["(" comma-list ")"])
+
+         (complex-number
+          ["{" (maybe "-") number "," (maybe "-") number "}"])
+
+         (column-ref
+          ["$" number])
+
+         (substring-range-component
+          (maybe (either "*" expression)))
+
+         (substring-range
+          ["[" (delimited-list substring-range-component ":" 2 2) "]"])
+
+;;; Assignments
+         (lhs
+          [name (maybe "(" (delimited-list name "," 1) ")")])
+
+         (assignment
+          [lhs "=" (either assignment expression)])
+
+;;; Lists of expressions
+         (comma-list
+          (delimited-list (either assignment expression) ","))
+
+         (colon-list
+          (delimited-list expression ":"))
+
+         (tuple
+          ["(" (delimited-list expression "," 2 3) ")"])
+
+;;; Commands
+         (command
+          (info-keyword
+           (either plot-command splot-command replot-command fit-command print-command
+                   set-command cd-command call-command simple-command
+                   eval-command load-command lower-raise-command pause-command
+                   save-command system-command test-command undefine-command
+                   update-command assignment if-command new-if-command do-command)))
+
+         (command-list
+          (delimited-list command separator))
+
+         (block ["{" command-list (maybe separator) "}"])
+
+;;; old-style one-line if(..) command
+         (if-command
+          (info-keyword
+           "if" parenthesized-expression command-list
+           (maybe separator "else" command-list)))
+
+;;; new-style block-structured if
+         (new-if-command
+          (info-keyword
+           "if" parenthesized-expression block
+           (maybe "else" block)))
+
+;;; block-structured "do"
+         (do-command
+          (info-keyword "do" iteration-spec block))
+
+;;; PLOT, SPLOT commands
+         (plot-command
+          [(kw ("pl" . "ot"))
+
+           (either
+            ;; Parametric ranges
+            [(assert (gnuplot-guess-parametric-p))
+             (maybe t-axis-range) (maybe x-axis-range) (maybe y-axis-range)]
+
+            ;; Non-parametric ranges
+            [(maybe x-axis-range) (maybe y-axis-range)])
+
+           plot-body])
+
+         (splot-command
+          [ ;; This capturing group lets `gnuplot-find-using-eldoc' know
+           ;; that this is an splot command
+           (capture :splot-command (kw ("spl" . "ot")))
+
+           (either
+            ;; Parametric ranges
+            [(assert (gnuplot-guess-parametric-p))
+             (maybe u-axis-range) (maybe v-axis-range)
+             (maybe x-axis-range) (maybe y-axis-range) (maybe z-axis-range)]
+
+            ;; Non-parametric ranges
+            [(maybe x-axis-range) (maybe y-axis-range) (maybe z-axis-range)])
+
+           plot-body])
+
+         (replot-command [(kw "replot") plot-body])
+
+         ;; Axis ranges
+         (axis-range-component
+          (maybe (either "*" expression)))
+
+         (axis-range-body
+          (delimited-list axis-range-component ":" 2 3))
+
+         (axis-range
+          [(:info "ranges")
+           "[" (maybe (maybe name "=") axis-range-body) "]"])
+
+         (x-axis-range [(:eldoc "X RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+         (y-axis-range [(:eldoc "Y RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+         (z-axis-range [(:eldoc "Z RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+         (t-axis-range [(:eldoc "T RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+         (u-axis-range [(:eldoc "U RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+         (v-axis-range [(:eldoc "V RANGE: [{<dummy>=}<min>:<max>]") axis-range])
+
+         ;; Body of a plot/splot command. Should really be different for
+         ;; parametric vs non-parametric, but that's too hard.
+         (plot-body
+          (delimited-list
+           [(maybe iteration-spec) plot-expression plot-modifiers]
+           ","))
+
+         ;; Iteration: for [... ]
+         (iteration-spec
+          [(:info "iteration")
+           (many1
+            "for" "[" name
+            (either ["=" (delimited-list expression ":")]
+                    ["in" expression])
+            "]")])
+
+         ;; Expressions to plot can be preceded by any number of
+         ;; assignments, with or without commas
+         (plot-expression
+          [(many [(:no-info) assignment (maybe ",")])
+           expression])
+
+;;; Plot/splot modifiers
+         ;; These should probably be more different for plot and splot ...
+         (plot-modifiers (many (either plot-modifier datafile-modifier)))
+
+         (plot-modifier
+          (info-keyword
+           (either
+            ;; simple one-word modifiers
+            (kw "nohidden3d") (kw "nocontours") (kw "nosurface")
+
+            ;; word followed by expression
+            [(either
+              (kw ("lines" . "tyle") "ls")
+              (kw ("linet" . "ype") "lt")
+              (kw ("linew" . "idth") "lw")
+              (kw ("pointt" . "ype") "pt")
+              (kw ("points" . "ize") "ps")
+              (kw ("pointi" . "nterval") "pi"))
+             expression]
+
+            ;; others defined below
+            title-modifier notitle-modifier axes-modifier with-modifier
+            linecolor-modifier fillstyle-modifier)))
+
+         (title-modifier
+          [(kw ("t" . "itle")) expression])
+
+         (notitle-modifier
+          [(:info "title")
+           (kw ("not" . "itle"))
+           (maybe string)])
+
+         (axes-modifier
+          [(kw ("ax" . "es")) (either "x1y1" "x1y2" "x2y1" "x2y2")])
+
+         (linecolor-modifier
+          [(kw ("linec" . "olor") "lc") color-spec])
+
+         (fillstyle-modifier
+          [(kw "fillstyle" "fs")
+           ;; fill-style also used by "set style fill"
+           fill-style])
+
+         (fill-style
+          [(either
+            "empty"
+            [(maybe "transparent")
+             (either "pattern" "solid")
+             (maybe (either fill-style-border-clause expression))])
+           (maybe fill-style-border-clause)])
+
+         (fill-style-border-clause
+          (either "noborder" [(kw ("bo" . "rder")) expression]))
+
+         (color-spec
+          [(:info "colorspec")
+           (either
+            (kw ("var" . "iable"))
+
+            [(kw ("pal" . "ette"))
+             (either "z"
+                     [(either "frac" "cb") expression])]
+
+            [(kw ("rgb" . "color"))
+             (either (kw ("var" . "iable")) string)])])
+
+         (with-modifier
+          [(:info "plotting_styles")
+           (kw ("w" . "ith"))
+
+           ;; plotting-style also used for "set style data"
+           (capture :with-style plotting-style)])
+
+         (plotting-style
+          (info-keyword
+           (either
+            ;; Simple styles that take no arguments
+            (kw ("l" . "ines")) (kw ("i" . "mpulses")) (kw ("p" . "oints"))
+            (kw ("linesp" . "oints") "lp") (kw ("d" . "ots")) (kw ("yerrorl" . "ines"))
+            (kw ("errorl" . "ines")) (kw ("xerrorl" . "ines")) (kw ("xyerrorl" . "ines"))
+            (kw ("ye" . "rrorbars")) (kw ("e" . "rrorbars")) (kw ("xe" . "rrorbars"))
+            (kw ("xye" . "rrorbars")) (kw "boxes") (kw ("hist" . "ograms"))
+            (kw ("boxer" . "rorbars")) (kw ("boxx" . "yerrorbars")) (kw ("st" . "eps"))
+            (kw ("fs" . "teps")) (kw ("his" . "teps")) (kw ("fin" . "ancebars"))
+            (kw ("can" . "dlesticks")) (kw ("pm" . "3d"))
+            (kw ("cir" . "cles"))
+
+            ;; Image styles all use the same info page
+            [(:info "image")
+             (either (kw ("ima" . "ge"))
+                     (kw ("rgbima" . "ge"))
+                     (kw ("rgba" . "lpha")))]
+
+            ;; More complicated styles defined below
+            labels-style-clause
+            filledcurves-style-clause
+            vectors-style-clause)))
+
+         (labels-style-clause
+          [(kw "labels")
+           (maybe textcolor-spec)])
+
+         (filledcurves-style-clause
+          [(kw ("filledc" . "urves"))
+           (maybe
+            (either
+             "closed"
+
+             ["xy" "=" expression "," expression]
+
+             [(maybe (either "above" "below"))
+              (maybe [(either "x1" "x2" "y1" "y2")
+                      (maybe "=" expression)])]))])
+
+         (vectors-style-clause
+          [(kw ("vec" . "tors"))
+           (many
+            (either
+             "nohead" "head" "heads" "filled" "empty" "nofilled" "front" "back"
+             [(kw "arrowstyle" "as") expression]
+             ["size" (delimited-list expression ",")]
+             linestyle-spec))])
+
+;;; Various style specifiers, used in different places
+         (linestyle-spec
+          (many1
+           (either
+            [(kw ("lines" . "tyle") "ls") expression]
+            [(kw ("linet" . "ype") "lt") expression]
+            [(kw ("linew" . "idth") "lw") expression])))
+
+         (textcolor-spec
+          [(kw "textcolor" "tc")
+           (either "default"
+                   ["lt" expression]
+                   color-spec)])
+
+         (pointsize-spec [(kw "pointsize" "ps") expression])
+
+;;; Datafile modifiers
+         (datafile-modifier
+          (info-keyword
+           (either binary-modifier
+                   [(maybe "nonuniform") (kw ("mat" . "rix"))]
+                   index-modifier every-modifier
+                   thru-modifier using-modifier
+                   smooth-modifier
+                   "volatile" "noautoscale")))
+
+         (index-modifier
+          [(kw ("i" . "ndex"))
+           (either string (delimited-list expression ":" 0 2))])
+
+         (every-modifier
+          [(kw ("ev" . "ery")) (delimited-list (maybe expression) ":")])
+
+         (thru-modifier
+          [(kw "thru") expression])
+
+         (using-modifier
+          [(:eldoc gnuplot-find-using-eldoc)
+           (kw ("u" . "sing"))
+           (either
+            string
+            [colon-list (maybe string)])])
+
+         (smooth-modifier
+          [(kw ("s" . "mooth"))
+           (either (kw ("a" . "csplines")) (kw ("b" . "ezier")) (kw ("c" . "splines"))
+                   (kw ("s" . "bezier")) (kw ("u" . "nique")) (kw ("f" . "requency"))
+                   (kw ("cum" . "ulative")) (kw ("k" . "density")))])
+
+;;; Binary datafile modifiers
+         (binary-modifier
+          ["binary" (many binary-keyword)])
+
+         (binary-keyword
+          (either
+           ;; All of these binary keywords are described on the same
+           ;; info page
+           [(:info "keywords")
+            (either
+             "transpose" "flipx" "flipy" "flipz"
+             ["flip" "=" (either "x" "y" "z")]
+             ["scan" "=" name]
+             [(either "dx" "dy" "dz") "=" number]
+             [(either "origin" "center" "perpendicular") "="
+              (delimited-list tuple ":")]
+             [(kw ("rot" . "ate") "rotation") "="
+              (sequence expression (maybe (kw ("d" . "eg")) (kw ("p" . "i"))))])]
+
+           ;; remaining binary keywords have their own info pages
+           (info-keyword
+            (either
+             [(either "array" "record")
+              "="
+              (delimited-list expression ":")]
+
+             [(either "skip")
+              "="
+              (delimited-list expression ":")]
+
+             [(either "format" "endian" "filetype")
+              "="
+              expression]))))
+
+;;; "fit" command
+         (fit-command
+          [(:info "fit")
+           (kw "fit")
+           (many axis-range)
+           expression
+           string
+           (many plot-modifier)
+           (kw "via")
+           (either string (delimited-list name ","))])
+
+;;; print command
+         (print-command
+          [(kw ("pr" . "int")) (delimited-list expression ",")])
+
+;;; set commands
+         (set-command
+          [(:eldoc "set ...")
+           (:info "set-show")
+           (either (kw "set") (kw "unset") (kw "show"))
+           (maybe iteration-spec)
+           (info-keyword
+            (either set-angles-clause set-arrow-clause
+                    set-autoscale-clause set-bars-clause
+                    set-border-clause set-boxwidth-clause
+                    set-clabel-clause set-clip-clause
+                    set-cntrparam-clause set-colorbox-clause
+                    set-contour-clause set-datafile-clause
+                    set-decimalsign-clause set-dgrid3d-clause
+                    set-dummy-clause set-encoding-clause
+                    set-fit-clause set-fontpath-clause
+                    set-format-clause set-grid-clause
+                    set-hidden3d-clause set-historysize-clause
+                    set-isosamples-clause set-key-clause
+                    set-label-clause set-loadpath-clause
+                    set-locale-clause set-logscale-clause
+                    set-mapping-clause set-margin-clause
+                    set-multiplot-clause set-mxtics-clause
+                    set-object-clause set-offsets-clause
+                    set-origin-clause set-output-clause
+                    set-parametric-clause set-pm3d-clause
+                    set-palette-clause set-pointsize-clause
+                    set-polar-clause set-print-clause
+                    set-samples-clause set-size-clause
+                    set-style-clause
+                    set-surface-clause set-table-clause
+                    set-terminal-clause set-termoption-clause
+                    set-tics-clause set-tics-clause-2
+                    set-xtics-clause
+                    set-timestamp-clause set-timefmt-clause
+                    set-title-clause set-view-clause
+                    set-data-clause set-dtics-clause
+                    set-xlabel-clause
+                    set-mtics-clause set-range-clause
+                    set-xyplane-clause set-zero-clause
+                    set-zeroaxis-clause))])
+
+;;; positions and coordinate systems for set options
+         (position-system
+          (either "first" "second" "graph" "screen" "character"))
+
+         (dimension [(maybe position-system) expression])
+
+         (position
+          [dimension "," dimension (maybe "," dimension)])
+
+         (to (either "to" "rto"))
+
+;;; all the different "set ... " options
+         (set-angles-clause
+          ["angles" (either "degrees" "radians")])
+
+         (set-arrow-clause
+          ["arrow" (maybe number)
+           (many
+            (either ["from" position] [to position]
+                    [(kw "arrowstyle" "as") expression]
+                    "nohead" "head" "backhead" "heads"
+                    ["size" dimension "," expression (maybe "," expression)]
+                    "filled" "empty" "nofilled" "front" "back"
+                    linecolor-modifier linestyle-spec))])
+
+         (set-autoscale-clause
+          ["autoscale"
+           (either "fix"
+                   "keepfix"
+                   "x" "y" "z" "cb" "x2" "y2" "xy"
+                   "xmin" "ymin" "zmin" "cbmin" "x2min" "y2min"
+                   "xmax" "ymax" "zmax" "cbmax" "x2max" "y2max"
+                   "xfix" "yfix" "zfix" "cbfix" "x2fix" "y2fix"
+                   "xfixmax" "yfixmax" "zfixmax" "cbfixmax" "x2fixmax" "y2fixmax"
+                   "xfixmin" "yfixmin" "zfixmin" "cbfixmin" "x2fixmin" "y2fixmin")])
+
+         (set-bars-clause
+          ["bars"
+           (either expression "small" "large" "fullwidth")
+           (either "front" "back")])
+
+         (set-border-clause
+          ["border"
+           (maybe number)
+           (maybe (either "front" "back"))
+           (maybe (kw "linewidth" "lw") expression)
+           (maybe
+            (either (kw "linestyle" "ls") (kw "linetype" "lt"))
+            expression)])
+
+         (set-boxwidth-clause
+          ["boxwidth"
+           (maybe expression)
+           (maybe (either (kw ("abs" . "olute")) "relative"))])
+
+         (set-clabel-clause
+          ["clabel" (maybe string)])
+
+         (set-clip-clause
+          ["clip" (maybe (either "points" "one" "two"))])
+
+         (set-cntrparam-clause
+          [(kw "cntrparam")
+           (either
+            "linear" "cubicspline" "bspline"
+
+            [(either "points" "order") number]
+
+            [(kw "levels")
+             (either
+              number
+              (sequence (kw "auto") (maybe number))
+              (sequence
+               (kw "discrete") comma-list)
+              (sequence
+               (kw "incremental") (delimited-list expression "," 2 3)))])])
+
+         (set-colorbox-clause
+          [(:info "color_box")
+           (kw ("colorb" . "ox"))
+           (many
+            (either
+             (kw ("vert" . "ical")) (kw ("horiz" . "ontal"))
+             "default" "user"
+             ["origin" expression "," expression]
+             ["size" expression "," expression]
+             "front" "back"
+             "noborder" "bdefault"
+             ["border" expression]))])
+
+         (set-contour-clause
+          ["contour" (either "base" "surface" "both")])
+
+         (set-datafile-clause
+          ["datafile"
+           (either [(:info "set_datafile_fortran")
+                    "fortran"]
+                   [(:info "set_datafile_nofpe_trap")
+                    "nofpe_trap"]
+                   [(:info "set_datafile_missing")
+                    "missing" (maybe string)]
+                   [(:info "set_datafile_separator")
+                    "separator" (either "whitespace" string)]
+                   [(:info "set_datafile_commentschars")
+                    "commentschars" (maybe string)]
+                   [(:info "set_datafile_binary")
+                    "binary" (many binary-keyword)])])
+
+         (set-decimalsign-clause
+          ["decimalsign"
+           (either string ["locale" (maybe string)])])
+
+         (set-dgrid3d-clause
+          ["dgrid3d"
+           (maybe expression)       ; fixme
+           (maybe "," expression)
+           (either
+            "splines"
+            ["qnorm" expression]
+            [(either "gauss" "cauchy" "exp" "box" "hann")
+             (maybe expression)
+             (maybe "," expression)])])
+
+         (set-dummy-clause
+          ["dummy"
+           name (maybe "," name)])
+
+         (set-encoding-clause
+          ["encoding"
+           (either "default" "iso_8859_1" "iso_8859_15" "iso_8859_2" "iso_8859_9"
+                   "koi8r" "koi8u" "cp437" "cp850" "cp852" "cp1250" "cp1251" "cp1254"
+                   "utf8" "locale")])
+
+         (set-fit-clause
+          [(:info "fit_")
+           "fit"
+           (either
+            ["logfile" string]
+            "errorvariables" "noerrorvariables")])
+
+         (set-fontpath-clause
+          ["fontpath" (many string)])
+
+         (set-format-clause
+          [(:info "format_")
+           "format"
+           (maybe (either "x" "y" "xy" "x2" "y2" "z" "cb"))
+           string])
+
+         (set-grid-clause
+          ["grid"
+           (either "nomxtics" "mxtics" "noxtics" "xtics" "nomytics" "mytics"
+                   "noytics" "ytics" "nomztics" "mztics" "noztics" "ztics"
+                   "nomx2tics" "mx2tics" "nox2tics" "x2tics" "nomy2tics"
+                   "my2tics" "noy2tics" "y2tics" "nomcbtics" "mcbtics"
+                   "nocbtics" "cbtics" "layerdefault" "front" "back"
+                   [linestyle-spec (maybe "," linestyle-spec)])])
+
+         (set-hidden3d-clause
+          [(kw ("hidden" . "3d"))
+           (many
+            (either
+             "defaults" "front" "back"
+             ["offset" expression] "nooffset"
+             ["trianglepattern"
+              (either "0" "1" "2" "3" "4" "5" "6" "7")]
+             ["undefined" (either "1" "2" "3")]
+             ["noundefined"]
+             "altdiagonal" "noaltdiagonal"
+             "bentover" "nobentover"))])
+
+         (set-historysize-clause
+          ["historysize" number])
+
+         (set-isosamples-clause
+          [(kw ("isosam" . "ples")) number (maybe "," number)])
+
+         (set-key-clause
+          ["key"
+           (many
+            (either "on" "off" "default"
+                    [(either "inside" "outside")
+                     (either "lmargin" "rmargin" "tmargin" "bmargin")]
+                    ["at" expression "," expression]
+                    "left" "right" "center" "top" "bottom" "vertical"
+                    "horizontal" "Left" "Right" "reverse" "noreverse" "invert"
+                    "noinvert" "above" "over" "below" "under"
+                    ["samplen" number]
+                    ["spacing" number]
+                    ["width" number]
+                    [(either "autotitle" "noautotitle") (maybe "columnheader")]
+                    ["title" expression] "enhanced" "noenhanced" ["font" string]
+                    textcolor-spec
+                    [(either "box" "nobox") linestyle-spec]
+                    ["maxcols" (either expression "auto")]
+                    ["maxrows" (either expression "auto")]))])
+
+         (set-label-clause
+          ["label"
+           (maybe expression)
+           (either label-clause-component expression)
+           (many label-clause-component)])
+
+         (label-clause-component
+          (either
+           ["at" position]
+           "left" "center" "right"
+           (either "norotate" ["rotate" "by" expression])
+           ["font" string]
+           "noenhanced"
+           "front" "back"
+           textcolor-spec
+           "nopoint" ["point" (many (either pointsize-spec linestyle-spec))]
+           ["offset" position]))
+
+         (set-loadpath-clause
+          ["loadpath" (many string)])
+
+         (set-locale-clause
+          ["locale" (maybe string)])
+
+         (set-logscale-clause
+          ["logscale"
+           (either "x" "y" "xy" "x2" "y2" "z" "cb" name)])
+
+         (set-mapping-clause
+          ["mapping" (either "cartesian" "spherical" "cylindrical")])
+
+         (set-margin-clause
+          [(either "bmargin" "lmargin" "rmargin" "tmargin")
+           (maybe "at" "screen") expression])
+
+         ;; TODO: set-mouse-clause
+
+         (set-multiplot-clause
+          ["multiplot"
+           (maybe
+            ["layout" number "," number
+             (maybe (either "rowsfirst" "columnsfirst"))
+             (maybe (either "downwards" "upwards"))
+             (maybe "title" string)
+             (maybe "scale" number (maybe "," number))
+             (maybe "offset" number (maybe "," number))])])
+
+         (set-mxtics-clause
+          [(:info "mxtics")
+           (either "mxtics" "mytics" "mztics" "mx2tics" "my2tics" "mcbtics")
+           (either "default" number)])
+
+         ;; "set object", objects, dimensions, positions
+         (set-object-clause
+          ["object"
+           (maybe number)
+           (info-keyword
+            (either rectangle-object ellipse-object circle-object polygon-object))
+           (maybe (either "front" "back" "behind"))
+           (maybe (kw "fillcolor" "fc") color-spec)
+           (maybe "fs" expression)
+           (maybe "default")
+           (maybe (kw "linewidth" "lw") expression)])
+
+         (rectangle-object
+          [(kw ("rect" . "angle"))
+           (maybe
+            (either
+             ["from" position (either "to" "rto") position]
+             ["center" position "size" dimension "," dimension]
+             ["at" position "size" dimension "," dimension]))])
+
+         (ellipse-object
+          ["ellipse"
+           (either "at" "center") position
+           "size" dimension "," dimension
+           (maybe "angle" number)])
+
+         (circle-object
+          ["circle"
+           (either "at" "center") position
+           "size" dimension
+           (maybe "arc" "[" number ":" number "]")])
+
+         (polygon-object
+          ["polygon"
+           "from" position (many (either "to" "rto") position)])
+
+         ;; "set offsets"
+         (set-offsets-clause
+          ["offsets"
+           (delimited-list [(maybe "graph") expression] "," 4 4)])
+
+         (set-origin-clause
+          ["origin" expression "," expression])
+
+         (set-output-clause
+          ["output" (maybe string)])
+
+         (set-parametric-clause
+          [(:info "parametric_")
+           (kw ("param" . "etric"))])
+
+         (set-pm3d-clause
+          ["pm3d"
+           (many
+            (either
+             ["at" name]
+             ["interpolate" number "," number]
+             (either "scansautomatic" "scansforward" "scansbackward" "depthorder")
+             ["flush" (either "begin" "center" "end")]
+             (either "ftriangles" "noftriangles")
+             (either "clip1in" "clip4in")
+             ["corners2color"
+              (either "mean" "geomean" "median" "min" "max" "c1" "c2" "c3" "c4")]
+             ["hidden3d" number]
+             "nohidden3d"
+             "implicit" "explicit" "map"))])
+
+         (set-palette-clause
+          ["palette"
+           (many
+            (either
+             "gray" "color"
+             ["gamma" number]
+             ["rgbformulae" number "," number "," number]
+             "defined"          ; not complete
+             ["functions" expression "," expression "," expression]
+             ["file" string (many datafile-modifier)]
+             "RGB" "HSV" "CMY" "YIQ" "XYZ"
+             "positive" "negative"
+             "nops_allcF" "ps_allcF"
+             ["maxcolors" number]))])
+
+         (set-pointsize-clause pointsize-spec)
+
+         (set-polar-clause "polar")
+
+         (set-print-clause
+          [(:info "print_")
+           "print"
+           (maybe string)])
+
+         (set-samples-clause
+          ["samples" expression (maybe "," expression)])
+
+         (set-size-clause
+          ["size"
+           (either
+            "square" "nosquare"
+            ["ratio" expression]
+            "noratio"
+            [expression "," expression])])
+
+         (set-style-clause
+          ["style"
+           (either style-arrow-clause style-data-clause style-fill-clause
+                   style-function-clause style-increment-clause
+                   style-line-clause style-circle-clause style-rectangle-clause)])
+
+         ;; begin subclauses of "set style ..."
+         (style-arrow-clause
+          [(:info "set_style_arrow")
+           "arrow"
+           number
+           (either
+            "default"
+            (many
+             (either "nohead" "head" "heads"
+                     "filled" "empty" "nofilled"
+                     "front" "back"
+                     ["size" dimension "," number (maybe "," number)]
+                     linestyle-spec)))])
+
+         (style-data-clause
+          [(:info "set_style_data")
+           "data" plotting-style])
+
+         (style-fill-clause
+          [(:info "set_style_fill")
+           "fill" fill-style])
+
+         (style-function-clause
+          [(:info "set_style_function")
+           "function" plotting-style])
+
+         (style-increment-clause
+          [(:info "set_style_increment")
+           "increment"
+           (either (kw ("d" . "efault")) (kw ("u" . "serstyles")))])
+
+         (style-line-clause
+          [(:info "set_style_line")
+           "line"
+           expression
+           (either
+            "default"
+            (many
+             (either
+              "palette"
+              [(kw ("linet" . "ype") "lt")
+               (either expression color-spec)]
+              [(kw ("linec" . "olor") "lc") color-spec]
+              [(either (kw ("linew" . "idth") "lw")
+                       (kw ("pointt" . "ype") "pt")
+                       (kw ("points" . "ize") "ps")
+                       (kw ("pointi" . "nterval") "pi"))
+               expression])))])
+
+         (style-circle-clause
+          [(:info "set_style_circle")
+           "circle" "radius" dimension])
+
+         (style-rectangle-clause
+          [(:info "set_style_rectangle")
+           "rectangle"
+           (many
+            (either
+             "front" "back"
+             [(kw ("linew" . "idth") "lw") expression]
+             [(kw "fillcolor" "fc") color-spec]
+             ["fs" expression]))])
+         ;; end of "set style ..." clauses
+
+         (set-surface-clause "surface")
+
+         (set-table-clause ["table" (maybe string)])
+
+         (set-terminal-clause       ; not sure how to do this...
+          ["terminal" (maybe (either "push" "pop"))])
+
+         (set-termoption-clause
+          ["termoption"
+           (either
+            "enhanced" "noenhanced"
+            ["font" string]
+            "solid" "dashed"
+            [(kw "linewidth" "lw") expression])])
+
+         (set-tics-clause
+          ["tics"
+           (many
+            (either
+             "axis" "border" "mirror" "nomirror" "in" "out"
+             ["scale" (either "default" [expression (maybe "," expression)])]
+             [(either "rotate" "norotate") (maybe "by" expression)]
+             ["offset" expression] "nooffset"
+             ["format" string]
+             ["font" string]
+             textcolor-spec))])
+
+         (set-tics-clause-2
+          ["tics" (either "front" "back")])
+
+         (set-xtics-clause
+          [(:info "xtics")
+           (either "xtics" "ytics" "ztics" "x2tics" "y2tics" "cbtics")
+           (many
+            (either
+             "axis" "border" "mirror" "nomirror" "in" "out"
+             ["scale" (either "default" [expression (maybe "," expression)])]
+             [(either "rotate" "norotate") (maybe "by" expression)]
+             ["offset" position] "nooffset"
+             "add" "autofreq"
+             ["(" (delimited-list [(maybe string) expression (maybe number)] ",") ")"]
+             ["format" string]
+             ["font" string]
+             "rangelimited"
+             textcolor-spec
+             (delimited-list expression ",")))])
+
+         (set-timestamp-clause
+          ["timestamp"
+           (maybe string)
+           (maybe (either "top" "bottom"))
+           (maybe (either "rotate" "norotate"))
+           (maybe "offset" position)
+           (maybe "font" string)])
+
+         (set-timefmt-clause
+          ["timefmt" string])
+
+         (set-title-clause
+          [(:info "title_")
+           "title"
+           (maybe expression)
+           (many
+            (either
+             ["offset" position]
+             ["font" string]
+             textcolor-spec
+             "enhanced" "noenhanced"))])
+
+         (set-view-clause
+          ["view"
+           (either
+            "map"
+            [(either "equal" "noequal") (maybe (either "xy" "xyz"))]
+            (delimited-list (maybe expression) ","))])
+
+         (set-data-clause
+          [(:info "xdata")
+           (either "xdata" "ydata" "zdata" "x2data" "y2data" "cbdata")
+           (maybe (either "time" "geographic"))])
+
+         (set-dtics-clause
+          [(:info "xdtics")
+           (either "xdtics" "ydtics" "zdtics" "x2dtics" "y2dtics" "cbdtics")])
+
+         (set-xlabel-clause
+          [(:info "xlabel")
+           (either (kw ("xlab" . "el")) (kw ("ylab" . "el"))
+                   (kw ("zlab" . "el")) (kw ("x2lab" . "el"))
+                   (kw ("y2lab" . "el")) (kw ("cblab" . "el")))
+           (maybe expression)
+           (many
+            (either
+             ["offset" position]
+             ["font" string]
+             textcolor-spec
+             "enhanced" "noenhanced"))])
+
+         (set-mtics-clause
+          [(:info "xmtics")
+           (either "xmtics" "ymtics" "zmtics" "x2mtics" "y2mtics" "cbmtics")])
+
+         (set-range-clause
+          [(:info "xrange")
+           (either (kw ("xr" . "ange")) (kw ("yr" . "ange"))
+                   (kw ("x2r" . "ange")) (kw ("y2r" . "ange"))
+                   (kw ("zr" . "ange")) (kw ("tr" . "ange"))
+                   (kw ("ur" . "ange")) (kw ("vr" . "ange"))
+                   (kw ("rr" . "ange")) (kw ("cbr" . "ange")))
+           (either
+            "restore"
+            ["[" (maybe
+                  [(maybe axis-range-component) ":"
+                   (maybe axis-range-component)])
+             "]"
+             (many (either "reverse" "noreverse" "writeback" "nowriteback"))])])
+
+         (set-xyplane-clause
+          ["xyplane" (either "at" "relative") expression])
+
+         (set-zero-clause
+          ["zero" expression])
+
+         (set-zeroaxis-clause
+          [(:info "zeroaxis")
+           (either "zeroaxis" "xzeroaxis" "x2zeroaxis" "yzeroaxis" "y2zeroaxis"
+                   "zzeroaxis")
+           (maybe linestyle-spec)])
+
+
+;;; Other commands
+         (cd-command
+          ["cd" string])
+
+         (call-command
+          ["call" string (many expression)])
+
+         (simple-command
+          (either "clear" "exit" "quit" "pwd" "refresh" "reread" "reset"
+                  "shell"))
+
+         (eval-command
+          ["eval" expression])
+
+         (load-command
+          ["load" string])
+
+         (lower-raise-command [(either "lower" "raise") number])
+
+         (pause-command
+          ["pause"
+           (either
+            expression
+            ["mouse" (maybe endcondition (maybe "," endcondition))])
+           string])
+
+         (endcondition (either "keypress" "button1" "button2" "button3" "close" "any"))
+
+         (save-command
+          ["save"
+           (either "functions" "variables" "terminal" "set")
+           string])
+
+         (system-command
+          ["system" string])
+
+         (test-command
+          ["test"
+           (either
+            "terminal"
+            ["palette"
+             (maybe
+              (either "rgb" "rbg" "grb" "gbr" "brg" "bgr"))])])
+
+         (undefine-command
+          ["undefine" (many name)])
+
+         (update-command
+          ["update" string (maybe string)]))
+
+       ;; This is the start symbol
+       'command))))
+
+\f
+;; The following macros are used for debugging; load
+;; gnuplot-debug-context.el and then re-load this file to enable
+;; them. For normal use, they compile to no-ops.
+(eval-when-compile
+  (when (not (featurep 'gnuplot-debug-context))
+    (defmacro with-gnuplot-trace-buffer (&rest _) "No-op." '(progn nil))
+    (defmacro gnuplot-trace (&rest _) "No-op." '(progn nil))
+    (defmacro gnuplot-debug (&rest _) "No-op." '(progn nil))))
+
+
+\f
+;;;; Variables to be set via pattern matching
+(defvar gnuplot-completions nil
+  "List of possible `gnuplot-mode' completions at point.
+This is filled in by `gnuplot-match-pattern' when it reaches the
+token before point.")
+
+(defvar gnuplot-info-at-point nil
+  "Relevant page of the Gnuplot info manual for the construction at point.
+
+Set by `gnuplot-match-pattern' using information from
+`gnuplot-compiled-grammar'.  `gnuplot-match-pattern' pushes ElDoc
+and info strings onto the stack as it runs, and scans the stack
+for the topmost entry when it reaches the token at point.")
+
+(defvar gnuplot-eldoc nil
+  "ElDoc documentation string for the Gnuplot construction at point.
+
+Set by `gnuplot-match-pattern'.  See also `gnuplot-info-at-point'.")
+
+(defvar gnuplot-captures nil
+  "Alist of named capture groups for `gnuplot-mode' completion code.
+
+Each entry is of the form (NAME BEGIN END), where NAME is the
+name specified in the (capture NAME PATTERN) form in the
+`gnuplot-compiled-grammar' source, BEGIN is the tail of the token
+list beginning the capture group, and END is the tail of the
+token list just after the end of the capture group.")
+
+(defvar gnuplot-eldoc-hash nil
+  "ElDoc strings for `gnuplot-mode'.
+
+These have to be compiled from the Gnuplot source tree using
+`doc2texi.el'.")
+
+\f
+;;;; The pattern matching machine
+(defun gnuplot-match-pattern (instructions tokens completing-p
+                                           &optional start-symbol)
+  "Parse TOKENS, setting completions, info and ElDoc information.
+
+This function parses TOKENS by simulating a stack machine with
+unlimited backtracking.  If COMPLETING-P is non-nil, it stops
+before the token at point and collects a list of the next tokens
+that it would accept in `gnuplot-completions'.  If COMPLETING-P is
+nil, it parses up to the token at point and sets `gnuplot-eldoc'
+and `gnuplot-info-at-point' based on the contents of the stack
+there."
+  (catch 'return
+    (let ((pc 0)            ; Program counter
+          ;; Stack of return addresses (return PC), eldoc strings
+          ;; (eldoc STRING) and info pages (info STRING)
+          (stack '())
+          ;; Stack of backtracking records:
+          ;; ((STACK TOKENS RESUME-PC CAPTURES PROGRESS) ...)
+          (backtrack '())
+          ;; Match failure flag, set to `t' to cause backtracking
+          (fail nil)
+          ;; Flag set by JUMP and CALL instructions to stop PC advance
+          (jump nil)
+          ;; Record of progress made within (many ...) loops, an alist
+          ;; of conses (pc . tokens)
+          (progress '()))
+
+      (with-gnuplot-trace-buffer (erase-buffer))
+
+      (when start-symbol        ; HACK FIXME
+        (let ((look-for `(label ,start-symbol)))
+          (while (not (equal (aref instructions pc) look-for))
+            (cl-incf pc))
+          (cl-incf pc)))
+
+      (setq gnuplot-completions nil
+            gnuplot-eldoc nil
+            gnuplot-info-at-point nil
+            gnuplot-captures nil)
+
+      (cl-flet ((advance
+              ()
+              (pop tokens)
+              (if (and (null tokens) (not completing-p))
+                  (gnuplot-scan-stack stack tokens)))
+             (fail () (setq fail t)))
+
+        ;; Main loop
+        (while t
+          (let* ((inst (aref instructions pc))
+                 (opcode (car inst))
+                 (token (car tokens))
+                 (end-of-tokens (null tokens)))
+            (gnuplot-trace "%s\t%s\t%s\n" pc inst (and token (gnuplot-token-id token)))
+
+            (cl-case opcode
+              ;; (literal LITERAL NO-COMPLETE)
+              ((literal)
+               (let ((expect (cadr inst))
+                     (no-complete (cl-caddr inst)))
+                 (cond (end-of-tokens
+                        (unless no-complete
+                          (gnuplot-trace "\tpushing \"%s\" to completions\n" expect)
+                          (push expect gnuplot-completions))
+                        (fail))
+
+                       ((not (equal (gnuplot-token-id token) expect))
+                        (fail))
+
+                       ;; otherwise succeed
+                       (t (advance)))))
+
+              ;; (token-type TYPE)
+              ((token-type)
+               (let ((expect (cadr inst)))
+                 (if (or end-of-tokens
+                         (not (eq (gnuplot-token-type token) expect)))
+                     (fail)
+                   (advance))))
+
+              ;; (keyword REGEXP NAME): match any token whose ID
+              ;; regexp-matches REGEXP, use NAME for completions
+              ((keyword)
+               (let ((regexp (cadr inst))
+                     (name (cl-caddr inst)))
+                 (cond (end-of-tokens
+                        (gnuplot-trace "\tpushing \"%s\" to completions\n" name)
+                        (push name gnuplot-completions)
+                        (fail))
+
+                       ((not (string-match-p regexp (gnuplot-token-id token)))
+                        (fail))
+
+                       ;; otherwise succeed
+                       (t
+                        (setf (gnuplot-token-id token) name)
+                        (advance)))))
+
+              ;; (any): match any token
+              ((any)
+               (if end-of-tokens
+                   (fail)
+                 (advance)))
+
+              ;; (jump LOCATION): jump to instruction at LOCATION
+              ((jump)
+               (let ((location (cadr inst)))
+                 (setq jump location)))
+
+              ;; (call LOCATION): push the next instruction as a
+              ;; return location and jump
+              ((call)
+               (let ((location (cadr inst)))
+                 (push `(return ,(+ pc 1)) stack)
+                 (setq jump location)))
+
+              ;; (return): return to address at topmost RETURN record on
+              ;; stack, or stop matching and return if stack is empty
+              ((return)
+               (while (and stack
+                           (not (eq (caar stack) 'return)))
+                 (pop stack))
+               (if (not stack)
+                   ;; Successful match
+                   (throw 'return (list tokens))
+                 ;; Otherwise, return to caller
+                 (let* ((r (pop stack))
+                        (r-pc (cadr r)))
+                   (setq jump r-pc))))
+
+              ;; (choice LOCATION): push LOCATION onto the stack of
+              ;; backtracking points and continue at next instruction
+              ((choice)
+               (let ((location (cadr inst)))
+                 (push `(,stack ,tokens ,location ,gnuplot-captures
+                                ,progress)
+                       backtrack)))
+
+              ;; (commit LOCATION): discard most recent backtrack point
+              ;; and jump to LOCATION
+              ((commit)
+               (let ((location (cadr inst)))
+                 (if (not backtrack)
+                     (error "No more backtrack points in commit"))
+                 (pop backtrack)
+                 (setq jump location)))
+
+              ;; (fail): force this match to fail, going back to most
+              ;; recent backtrack point
+              ((fail)
+               (fail))
+
+              ;; (assert): run Lisp code and fail if it returns NIL
+              ((assert)
+               (let ((form (cadr inst)))
+                 (if (not (eval form)) (fail))))
+
+              ;; (push TYPE VALUE): push an info page or eldoc string
+              ;; onto the stack
+              ((push)
+               (let* ((type (cadr inst))
+                      (value (cl-caddr inst)))
+                 (push `(,type ,value ,tokens) stack)))
+
+              ;; (pop TYPE): pop something off the stack
+              ((pop)
+               (let ((type (cadr inst)))
+                 (if (not (and stack
+                               (eq (caar stack) type)))
+                     (error "Expected a %s on the stack but found %s" type stack))
+                 (pop stack)))
+
+              ;; (save-start NAME): save current token pointer as
+              ;; beginning of capture group NAME
+              ((save-start)
+               (let ((name (cadr inst)))
+                 (push `(,name ,tokens nil) gnuplot-captures)))
+
+              ;; (save-end NAME): save current token pointer as end of
+              ;; capture group NAME
+              ((save-end)
+               (let* ((name (cadr inst))
+                      (record (assoc name gnuplot-captures)))
+                 (if (not record)
+                     (error "Gnuplot-match-tokens: no open capture group named %s" name)
+                   (setf (cl-caddr record) tokens)
+                   (gnuplot-debug (gnuplot-dump-captures)))))
+
+              ;; (check-progress): make sure not stuck in an infinite loop
+              ((check-progress)
+               (let ((prev-progress (cdr (assoc pc progress))))
+                 (if (and prev-progress (eq prev-progress tokens))
+                     (fail)
+                   (push (cons pc tokens) progress))))
+
+              (t
+               (error "Bad instruction: %s" inst)))
+
+            ;; Increment PC or jump
+            (setq pc (or jump (1+ pc))
+                  jump nil)
+
+            ;; Backtrack on failure
+            (when fail
+              (if (not backtrack)   ; Out of backtracking stack: failed match
+                  (throw 'return nil)
+                (gnuplot-trace "\t*fail*\t%s\n" (length backtrack))
+                (gnuplot-debug (gnuplot-dump-backtrack backtrack))
+                ;; If we got as far as token-at-point before failing,
+                ;; scan the stack for eldoc and info strings
+                (when (and end-of-tokens (not completing-p))
+                  (gnuplot-scan-stack stack tokens))
+
+                (cl-destructuring-bind
+                    (bt-stack bt-tokens bt-pc bt-captures bt-progress)
+                    (pop backtrack)
+                  (setq stack bt-stack
+                        tokens bt-tokens
+                        pc bt-pc
+                        gnuplot-captures bt-captures
+                        progress bt-progress
+                        fail nil)
+                  (gnuplot-debug (gnuplot-dump-progress progress)))))))))))
+
+(defun gnuplot-scan-stack (stack tokens)
+  "Scan STACK for the most recently pushed eldoc and info strings."
+  (gnuplot-trace "\t* scanning stack *\n")
+  (gnuplot-debug (gnuplot-backtrace stack))
+  (gnuplot-debug (gnuplot-dump-captures))
+
+  (catch 'no-scan
+    (while (and stack
+                (not (and gnuplot-info-at-point gnuplot-eldoc)))
+      (let* ((item (car stack))
+             (type (car item))
+             (position (cl-caddr item))) ; must progress by at least one token
+        (if (and (memq type '(info eldoc no-scan))
+                 (not (eq position tokens)))
+            (cl-case type
+              ((no-scan)
+               (throw 'no-scan nil))
+
+              ((info)
+               (when (not gnuplot-info-at-point)
+                 (let ((info (cadr item)))
+                   (setq gnuplot-info-at-point
+                         (cond
+                          ((eq info 'first-token)
+                           (gnuplot-token-id (car position)))
+                          ((functionp info) (funcall info))
+                          (t info)))
+                   (when gnuplot-info-at-point
+                     (gnuplot-trace "\tset info to \"%s\"\n" gnuplot-info-at-point)
+                     (when (and (not gnuplot-eldoc) gnuplot-eldoc-hash)
+                       (let ((eldoc
+                              (car (gethash gnuplot-info-at-point gnuplot-eldoc-hash))))
+                         (when eldoc
+                           (setq gnuplot-eldoc eldoc)
+                           (gnuplot-trace "\tand set eldoc to \"%s\"\n" eldoc))))))))
+
+              ((eldoc)
+               (when (not gnuplot-eldoc)
+                 (let ((eldoc (cadr item)))
+                   (setq gnuplot-eldoc
+                         (if (functionp eldoc) (funcall eldoc) eldoc))
+                   (gnuplot-trace "\tset eldoc to \"%s\"\n" gnuplot-eldoc)))))))
+      (pop stack))))
+
+(defun gnuplot-capture-group (name)
+  "Return capture group NAME from the most recent parse, as a list of tokens."
+  (let ((record (assoc name gnuplot-captures)))
+    (if (not record) nil
+      (let ((begin (cadr record))
+            (end (cl-caddr record))
+            (accum '()))
+        (while (and begin (not (eq begin end)))
+          (push (pop begin) accum))
+        (nreverse accum)))))
+
+(defun gnuplot-capture-group->string (name)
+  (let ((tokens (gnuplot-capture-group name)))
+    (and tokens
+         (mapconcat 'gnuplot-token-id tokens " "))))
+
+\f
+;;; Interface to the matching machine
+(defun gnuplot-parse-at-point (completing-p)
+  (let ((tokens (gnuplot-tokenize completing-p)))
+    (gnuplot-match-pattern gnuplot-compiled-grammar tokens completing-p)))
+
+;; Completions
+(defun gnuplot-completions ()
+  (gnuplot-parse-at-point t)
+  gnuplot-completions)
+
+(defun gnuplot-context-completion-at-point ()
+  "Return completions of keyword preceding point, using context."
+  (list (save-excursion
+          (skip-syntax-backward "w_" (gnuplot-point-at-beginning-of-command))
+          (point))
+        (point)
+        (gnuplot-completions)))
+
+;; Eldoc help
+(defun gnuplot-eldoc-function ()
+  "Return the ElDoc string for the Gnuplot construction at point."
+  (gnuplot-parse-at-point nil)
+  gnuplot-eldoc)
+
+(defun gnuplot-help-function ()
+  "Pop up the extended documentation for the construction at point."
+  (interactive)
+  (gnuplot-parse-at-point nil)
+  (if (and gnuplot-info-at-point gnuplot-eldoc-hash)
+      (let ((eldoc
+             (cadr (gethash gnuplot-info-at-point gnuplot-eldoc-hash))))
+        (if eldoc (message eldoc)))))
+
+;; Info lookup
+(defun gnuplot-info-at-point (&optional query)
+  "Open the relevant gnuplot info page for the construction at point."
+  (interactive "P")
+  (setq gnuplot-info-at-point nil)
+  (unless query
+    (gnuplot-parse-at-point nil))
+  (if (or query (not gnuplot-info-at-point))
+      (let ((info
+             (info-lookup-interactive-arguments 'symbol)))
+        (setq gnuplot-info-at-point (car info))))
+  (when gnuplot-info-at-point
+    (gnuplot--find-info-node gnuplot-info-at-point)))
+
+(defun gnuplot--find-info-node (node)
+  (save-window-excursion
+    (info (format "(gnuplot)%s" node)))
+  (gnuplot--adjust-info-display))
+
+\f
+;;; Some context-sensitive hacks
+
+;; ElDoc strings for "using" specs, which depend on other information
+;; from the parsed command
+
+(defvar gnuplot-using-eldoc
+  '(("boxerrorbars" . "x:y:ydelta{:xdelta} | x:y:ylow:yhigh{:xdelta}")
+    ("boxes" . "x:y{:x_width}")
+    ("boxxyerrorbars" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh")
+    ("candlesticks" . "x:box_min:whisker_min:whisker_high:box_high | date:open:low:high:close")
+    ("circles" . "x:y:radius")
+    ("dots" . "x{:y{:z}}")
+    ("filledcurves" . "x:y | x:y1:y2")
+    ("financebars" . "date:open:low:high:close")
+    ("fsteps" . "y | x:y")
+    ("histeps" . "y | x:y")
+    ("histograms" . "y:yerr | y:ymin:ymax")
+    ("image" . "x:y:value")
+    ("rgbimage" . "x:y:r:g:b")
+    ("rgbalpha" . "x:y:r:g:b:a")
+    ("impulses" . "x{:y{:z}}")
+    ("labels" . "x:y:string")
+    ("lines" . "y | x:y")
+    ("steps" . "y | x:y")
+    ("vectors" . "x:y:xdelta:ydelta")
+    ("xerrorbars" . "x:y:xdelta | x:y:xlow:xhigh")
+    ("xyerrorbars" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh")
+    ("yerrorbars" . "x:y:ydelta | x:y:ylow:yhigh")
+    ("yerrorlines" . "x:y:ydelta | x:y:ylow:yhigh")
+    ("xerrorlines" "x:y:xdelta | x:y:xlow:xhigh")
+    ("xyerrorlines" . "x:y:xdelta:ydelta | x:y:xlow:xhigh:ylow:yhigh"))
+  "Alist of ElDoc strings for Gnuplot \"using\" clauses in \"plot\" commands.")
+
+(defvar gnuplot-using-3d-eldoc
+  (append
+   '(("fsteps" . "z | x:y:z")
+     ("histeps" . "z | x:y:z")
+     ("histograms" . "y:yerr | y:ymin:ymax")
+     ("image" . "x:y:z:value")
+     ("rgbimage" . "x:y:z:r:g:b")
+     ("rgbalpha" . "x:y:z:r:g:b:a")
+     ("labels" . "x:y:z:string")
+     ("lines" . "z | x:y:z")
+     ("steps" . "z | x:y:z")
+     ("vectors" . "x:y:z:xdelta:ydelta:zdelta"))
+   gnuplot-using-eldoc)
+  "Alist of ElDoc strings for Gnuplot \"using\" clauses in \"splot\" commands.")
+
+(defun gnuplot-find-using-eldoc ()
+  "Return ElDoc string for a Gnuplot \"using\" clause, based on plotting style.
+
+This will fail if the \"using\" clause comes before the \"with\"
+clause."
+  (let ((with-style (gnuplot-capture-group :with-style))
+        (3d-p (gnuplot-capture-group :splot-command))
+        (column-description nil))
+    (if with-style
+        (let ((with-style-string (gnuplot-token-id (car with-style))))
+          (setq column-description
+                (or (and 3d-p
+                         (cdr (assoc with-style-string gnuplot-using-3d-eldoc)))
+                    (cdr (assoc with-style-string gnuplot-using-eldoc))
+                    "<columns>"))))
+    (format "using %s {'format'}" column-description)))
+
+;;; Needed for correctly parsing plot commands
+(defun gnuplot-guess-parametric-p (&optional start)
+  "Guess whether the command beginning at START is in parametric mode.
+
+Searches backward in current buffer for an \"(un)set parametric\"
+command."
+  (save-excursion
+    (and start (goto-char start))
+    (catch 'result
+      (while
+          (search-backward-regexp "reset\\|set\\s-+parametric" (point-min) t)
+        (gnuplot-beginning-of-command)
+        (cond ((looking-at "reset\\|unset\\s-+parametric") (throw 'result nil))
+              ((looking-at "set\\s-+parametric") (throw 'result t))))
+      nil)))
+
+
+;;;###autoload
+(define-minor-mode gnuplot-context-sensitive-mode
+  "Use context-sensitive completion and help in `gnuplot-mode'.
+
+When context-sensitive mode is enabled, `gnuplot-mode' tries to
+provide more useful completions and help suggestions for built-in
+keywords and functions by parsing each command as you type.  It
+attempts to take into account Gnuplot's many abbreviated
+keywords.  For example, with point at the end of a line reading
+\"plot 'datafile' w \", typing \\[completion-at-point] will pop
+up a list of plotting styles.
+
+Key bindings:
+
+\\[completion-at-point] will complete the keyword at point based
+on its context in the command. To make keyword completion work on
+pressing TAB, set `tab-always-indent' to `complete', or customize
+`gnuplot-tab-completion' to make this automatic in gnuplot-mode
+buffers.
+
+\\[gnuplot-info-at-point] will try to find the most relevant
+Gnuplot info node for the construction at point, prompting for a
+node name if nothing is found.
+
+\\[gnuplot-help-function] will pop up a brief summary of the
+syntax at point in the minibuffer. To have one-line syntax
+summaries appear in the echo area as you type, toggle
+`eldoc-mode' or customize `gnuplot-eldoc-mode'.
+
+To choose whether to use this mode by default in Gnuplot buffers,
+customize the variable
+`gnuplot-use-context-sensitive-completion'.
+
+Note: help strings for eldoc-mode and \\[gnuplot-help-function]
+need to be provided in an Emacs-readable form by the Gnuplot
+distribution. See gnuplot-context.el for details."
+  :keymap
+  `((,(kbd "C-c C-/") . gnuplot-help-function)
+    (,(kbd "C-c C-d") . gnuplot-info-at-point))
+  (unless (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
+    (message "Gnuplot context-sensitive mode works only in Gnuplot-mode buffers")
+    (setq gnuplot-context-sensitive-mode nil))
+  (if gnuplot-context-sensitive-mode
+      ;; Turn on
+      (progn
+        (setq gnuplot-completion-at-point-function #'gnuplot-context-completion-at-point)
+
+        ;; Setup Eldoc
+        (setq-local eldoc-documentation-function #'gnuplot-eldoc-function)
+        (eldoc-add-command 'completion-at-point)     ; Check for eldoc after completion
+
+        ;; Try to load Eldoc strings
+        (when gnuplot-eldoc-mode
+          (unless gnuplot-eldoc-hash
+            (condition-case nil
+                (load-library "gnuplot-eldoc")
+              (error
+               (message "gnuplot-eldoc.el not found. Install it from the Gnuplot distribution.")
+               (setq gnuplot-eldoc-hash nil
+                     gnuplot-eldoc-mode nil))))
+
+          (if gnuplot-eldoc-hash
+              (eldoc-mode 1)
+            (eldoc-mode 0)))
+
+        ;; Set up tab-to-complete
+        (when gnuplot-tab-completion
+          (setq-local tab-always-indent 'complete)))
+
+    ;; Turn off
+    (setq gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look)
+    (setq eldoc-documentation-function nil)
+    (eldoc-mode 0)))
+
+\f
+;;; All done!
+(provide 'gnuplot-context)
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+
+;;; gnuplot-context.el ends here
diff --git a/elpa/gnuplot-20230323.1400/gnuplot-gui.el b/elpa/gnuplot-20230323.1400/gnuplot-gui.el
new file mode 100644 (file)
index 0000000..6276e8b
--- /dev/null
@@ -0,0 +1,1671 @@
+;;;; gnuplot-gui.el -- GUI interface to setting options in gnuplot-mode -*- lexical-binding: t -*-
+
+;; Copyright (C) 1998-2000 Bruce Ravel
+
+;; Author:     Bruce Ravel <ravelNOSPAMphys.washington.edu>
+;; URL:        https://github.com/emacs-gnuplot/gnuplot
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; This file provides a graphical user interface to setting arguments
+;; to gnuplot commands.  Positioning point near a command and invoking
+;; `gnuplot-gui-set-options-and-insert' (C-c C-c or shift-mouse-2)
+;; will pop open a frame with widgets for setting the various
+;; arguments appropriate the the item that was near point.  The goal
+;; is to provide point-and-click functionality to gnuplot-mode.
+;;
+;; gnuplot-gui.el was developed using GNU Emacs 25 and should be
+;; compatible with GNU Emacs 24.3 and above.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; To do:
+;;
+;; Widgets I need:
+;; -- 'position: two or three comma separated numbers used to denote a
+;;               position or a tic start/end/increment (see arrow,
+;;               need a prefix)
+;; -- 'modifier: colon separated fields used for datafile modifiers
+;;
+;; command types which are currently unsupported or contain mistakes
+;; -- unsupported: cntrparam
+;; -- plot, splot, fit: rather lame
+;; -- label: position information missing
+;; -- label: font string handled in overly simple manner
+;; -- hidden3d: not really suited to 'list, but all options are exclusive...
+;; -- pointstyle argument to "set label"
+;;
+;; overall:
+;; -- continuation lines (ugh!)
+;; -- multiple frames end up displaying same window after setting options
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Code:
+
+(require 'gnuplot)
+(require 'widget)
+(require 'wid-edit)
+(require 'cl-lib)
+
+\f
+;;; customizable variables
+
+(defgroup gnuplot-gui nil
+  "Graphical interface to setting arguments in gnuplot scrips."
+  :prefix "gnuplot-gui-"
+  :group 'gnuplot)
+
+(defcustom gnuplot-gui-popup-flag nil
+  "Non-nil means to open arguments pop-ups automatically.
+This would be done after menu insertion of Gnuplot commands."
+  :group 'gnuplot-gui
+  :type 'boolean)
+
+(defvar gnuplot-gui-frame nil
+  "Frame used to hold the buffer for setting options.")
+
+(defcustom gnuplot-gui-frame-parameters
+  '((height . 18)
+    (width . 65)
+    (user-position . t)
+    (top . 150)
+    (left . 150)
+    (border-width . 0)
+    (menu-bar-lines . 0)
+    (unsplittable . t))
+  "Frame parameters for the input run-time display frame in Emacs."
+  :group 'gnuplot-gui
+  :type '(repeat (sexp :tag "Parameter:")))
+
+(defcustom gnuplot-gui-fontname-list
+  '(" " "\"Helvetica\"" "\"Times-Roman\"")
+  "List of known font names.
+These *must* be quoted, like so \"\\\"Helvetica\\\"\".  This allows
+for fonts with names like \"\\\"Arial Bold Italic\\\"\" to be treated
+as single entries in the menu-buttons.  And it is really important that
+the first entry in the list be a blank string."
+  :group 'gnuplot-gui
+  :type '(repeat (string :tag "Font name:")))
+
+;; some global variables
+(defvar gnuplot-current-frame nil)
+(defvar gnuplot-current-buffer nil)
+(defvar gnuplot-current-buffer-point nil)
+(defvar gnuplot-gui-alist nil)
+(defvar gnuplot-gui-current-string nil)
+
+\f
+;;; various tools for handling data structures and text in the buffer
+
+;; tools for accessing the elements of the lists in `gnuplot-gui-all-types'
+(defsubst gnuplot-gui-type-tag     (obj) (elt obj 0))
+(defsubst gnuplot-gui-type-symbol  (obj) (elt obj 1))
+(defsubst gnuplot-gui-type-default (obj) (elt obj 2))
+(defsubst gnuplot-gui-type-prefix  (obj) (elt obj 3)) ; also 'range seperator
+(defsubst gnuplot-gui-type-fourth  (obj) (elt obj 4))
+(defsubst gnuplot-gui-type-list    (obj) (cddr obj))
+
+(defun gnuplot-this-word ()
+  "Return the word under point."
+  (let ((begin (save-excursion (beginning-of-line) (point-marker)))
+        (end   (save-excursion (end-of-line)       (point-marker))))
+    (save-excursion
+      (or (looking-at "\\<") (= (current-column) 0) (forward-word -1))
+      (if (> (point) begin) (setq begin (point-marker)))
+      (forward-word 1)
+      (if (> (point) end) (goto-char end))
+      (buffer-substring-no-properties begin (point)))))
+
+
+\f
+;;; data structures containing regarding options in Gnuplot 3.7
+
+;; various constants used for options that take the same sorts of arguments
+(defconst gnuplot-gui-mtics-list
+  '(("FREQUENCY"   'number " ")
+    ("DEFAULT"     'list " " "default")))
+(defconst gnuplot-gui-data-list
+  '(("DATA TYPE"   'list " " "time")))
+(defconst gnuplot-gui-label-list
+  '(("LABEL"       'string " ")
+    ("POSITION"    'position " " "" 2)
+    ("FONTNAME"    'list " " gnuplot-gui-fontname-list)
+    ("FONTSIZE"    'fontsize " ")))
+(defconst gnuplot-gui-range-list
+  '(("RANGE"       'range (" " . " ") ":")
+    ("REVERSE"     'list " " "reverse" "noreverse")
+    ("WRITEBACK"   'list " " "writeback" "nowriteback")))
+(defconst gnuplot-gui-tics-list
+  '(("WHERE"       'list " " "axis" "border")
+    ("MIRROR"      'list " " "mirror" "nomirror")
+    ("ROTATE"      'list " " "rotate" "norotate")
+    ("SERIES"      'position " " "" 3)
+    ("LABEL ARRAY" 'labels () )))
+(defconst gnuplot-gui-zeroaxis-list
+  '(("LINETYPE"    'number " ")))
+
+(defvar gnuplot-gui-terminal-types nil
+  "Associated list of terminal descriptions.
+See the doc-string for `gnuplot-gui-all-types'.")
+(setq gnuplot-gui-terminal-types
+      (list (cons "aifm"
+                  '(("COLOR"     'list " " "monochrome" "gray" "color")
+                    ("FONTNAME"  'list " " gnuplot-gui-fontname-list)
+                    ("FONTSIZE"  'fontsize " ")))
+            (cons "cgm"
+                  '(("MODE"      'list   " " "landscape" "portrait" "default")
+                    ("COLOR"     'list   " " "color" "monochrome")
+                    ("ROTATION"  'list   " " "rotate" "norotate")
+                    ("WIDTH"     'number " " "width")
+                    ("LINEWIDTH" 'number " " "linewidth")
+                    ("FONTNAME"  'list   " " "\"Arial\"" "\"Arial Italic\""
+                     "\"Arial Bold\"" "\"Arial Bold Italic\""
+                     "\"Times Roman\"" "\"Times Roman Italic\""
+                     "\"Times Roman Bold\"" "\"Times Roman Bold Italic\""
+                     "\"Helvetica\"" "\"Roman\"")
+                    ("FONTSIZE"  'fontsize " ")))
+            (cons "corel"
+                  '(("COLOR"            'list " " "default" "color" "monochrome")
+                    ("FONTNAME"         'list " " "\"SwitzerlandLight\""
+                     "\"Helvetica\"" "\"Times-Roman\"")
+                    ("FONTSIZE "        'number " ")
+                    ("X-SIZE   "        'number " ")
+                    ("Y-SIZE   "        'number " ")
+                    ("LINEWIDTH"        'number " ")))
+            (cons "dumb"
+                  '(("LINEFEED"         'list   " " "feed" "nofeed")
+                    ("X-SIZE"           'number " ")
+                    ("Y-SIZE"           'number " ")))
+            (cons "emf"
+                  '(("COLOR"            'list " " "color" "monochrome")
+                    ("LINE"             'list " " "solid" "dashed")
+                    ("FONTNAME"         'string " ")
+                    ("FONTSIZE"         'number " ")))
+            (cons "emtex"
+                  '(("FONTNAME"         'list     " " "courier" "roman")
+                    ("FONTSIZE"         'fontsize " ")))
+            (cons "fig"
+                  '(("COLOR"            'list   " " "color" "monochrome")
+                    ("FRAMESIZE"        'list   " " "small" "big")
+                    ("POINTSMAX"        'number " " "pointsmax")
+                    ("ORIENTATION"      'list   " " "landscape" "portrait")
+                    ("UNITS"            'list   " " "metric" "inches")
+                    ("FONT SIZE"        'number " " "fontsize")
+                    ("SIZE"             'pair   (" " . " ") "size")
+                    ("LINE THICKNESS"   'number " " "thickness")
+                    ("LAYER DEPTH"      'number " " "depth")))
+            (cons "hp500c"
+                  '(("RESOLUTION"       'list " " "75" "100" "150" "300")
+                    ("COMPRESSION"      'list " " "rle" "tiff")))
+            (cons "hpgl"
+                  '(("PENS"             'number " ")
+                    ("EJECT"            'list   " " "eject")))
+            (cons "hpdj"
+                  '(("RESOLUTION"       'list " " "75" "100" "150" "300")))
+            (cons "hpljii"
+                  '(("RESOLUTION"       'list " " "75" "100" "150" "300")))
+            (cons "hppj"
+                  '(("FONT"             'list " " "FNT9X17" "FNT5X9" "FNT13X25")))
+            (cons "imagen"
+                  '(("FONT SIZE"        'number " ")
+                    ("LAYOUT"           'list   " " "portrait" "landscape")
+                    ("NUMBER OF GRAPHS" 'range (" " . " ") ",")))
+            (cons "gpic"
+                  '(("X ORIGIN"         'number " ")
+                    ("Y ORIGIN"         'number " " ",")))
+            (cons "latex"
+                  '(("FONTNAME"         'list " " "courier" "roman")
+                    ("FONTSIZE"         'fontsize " ")))
+            (cons "mif"
+                  '(("COLOUR"           'list " " "colour" "monochrome")
+                    ("LINETYPE"         'list " " "polyline" "vectors")))
+            (cons "nec-cp6"
+                  '(("MODE"             'list " " "monochrome" "colour" "draft")))
+            (cons "pbm"
+                  '(("SIZE"      'list " " "small" "medium" "large")
+                    ("COLOR"     'list " " "monochrome" "gray" "color")))
+            (cons "pcl5L"
+                  '(("MODE"      'list " " "landscape" "portrait")
+                    ("FONTNAME"  'list " " "stick" "univers" "cg_times")
+                    ("FONTSIZE"  'fontsize " ")))
+            (cons "png"
+                  '(("SIZE"      'list " " "small" "medium" "large")
+                    ("COLOR"     'list " " "monochrome" "gray" "color")))
+            (cons "postscript"
+                  '(("MODE"      'list " " "landscape" "portrait" "eps" "default")
+                    ("ENHANCED"  'list " " "enhanced" "noenhanced")
+                    ("COLOR"     'list " " "color" "monochrome")
+                    ("SOLID"     'list " " "solid" "dashed")
+                    ("DUPLEXING" 'list " " "defaultplex" "simplex" "duplex")
+                    ("FONTNAME"  'list " " gnuplot-gui-fontname-list)
+                    ("FONTSIZE"  'fontsize " ")))
+            (cons "pslatex"
+                  '(("COLOR"     'list " " "monochrome" "color")
+                    ("DASHED"    'list " " "dashed")
+                    ("ROTATION"  'list " " "rotate" "norotate")
+                    ("AUXFILE"   'list " " "auxfile")))
+            (cons "pstex"
+                  '(("COLOR"     'list " " "monochrome" "color")
+                    ("DASHED"    'list " " "dashed")
+                    ("ROTATION"  'list " " "rotate" "norotate")
+                    ("AUXFILE"   'list " " "auxfile")))
+            (cons "pstricks"
+                  '(("HACK TEXT"        'list " " "hacktext" "nohacktext")
+                    ("PLOT SCALING"     'list " " "nounit" "unit")))
+            (cons "regis"
+                  '(("COLOR DEPTH"      'list "4" "16")))
+            (cons "tgif"
+                  '(("LAYOUT"           'list   " " "portrait" "landscape")
+                    ("NUMBER OF GRAPHS" 'range (" " . " ") ",")
+                    ("LINE TYPE"        'list " " "solid" "dashed")
+                    ("FONTNAME"         'list " " gnuplot-gui-fontname-list)
+                    ("FONTSIZE"         'fontsize " ")))
+            (cons "tpic"
+                  '(("POINTSIZE"        'number " ")
+                    ("LINEWIDTH"        'number " ")
+                    ("INTERVAL "        'number " ")))
+            (cons "vgagl"       ; for pm3d patch (also persist, raise in x11) <MT>
+                  '(("BACKGROUND"       'position  " " "background" 3)
+                    ("INTERPOLATION"    'list " " "uniform" "interpolate")
+                    ("DUMP"             'file " ")
+                    ("MODE"             'string  " " "")))
+            (cons "x11"
+                  '(("RESET"            'list " " "reset")
+                    ("TERMINAL NUMBER"  'number " ")
+                    ("PERSIST"          'list " " "persist" "nopersist")
+                    ("RAISE"            'list " " "raise" "noraise"))) ))
+
+(defvar gnuplot-gui-terminal-list nil)
+(setq gnuplot-gui-terminal-list
+      (append (list " ") (mapcar 'car gnuplot-gui-terminal-types)))
+
+(defvar gnuplot-gui-set-types nil
+  "Associated list of set option descriptions.
+See the doc-string for `gnuplot-gui-all-types'.")
+(setq gnuplot-gui-set-types
+      (list (cons "angles"
+                  '(("UNITS" 'list " " "degrees" "radians")))
+            (cons "arrow"
+                  '(("TAG"       'tag " ")
+                    ("FROM"      'position " " "from" 3)
+                    ("TO"        'position " " "to" 3)
+                    ("HEAD"      'list " " "head" "nohead")
+                    ("LINESTYLE" 'number " " "ls")
+                    ("LINETYPE " 'number " " "lt")
+                    ("LINEWIDTH" 'number " " "lw")))
+            (cons "noarrow"
+                  '(("TAG" 'tag " ")))
+            (cons "autoscale"
+                  '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
+                     "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
+                     "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
+            (cons "noautoscale"
+                  '(("AXIS" 'list " " "x" "y" "z" "x2" "y2" "xy"
+                     "xmin" "ymin" "zmin" "x2min" "y2min" "xymin"
+                     "xmax" "ymax" "zmax" "x2max" "y2max" "xymax")))
+            (cons "bar"
+                  '(("SIZE" 'list " " "small" "large")))
+            (cons "border"
+                  '(("BORDER CODE" 'number " ")
+                    ("LINE STYLE"  'list   " " "lines"
+                     "dots" "points" "linespoints")
+                    ("LINESTYLE"   'number " " "ls")
+                    ("LINETYPE"    'number " " "lt")
+                    ("LINEWIDTH"   'number " " "lw")))
+            (cons "boxwidth"
+                  '(("WIDTH" 'number " ")))
+            (cons "clabel"
+                  '(("FORMAT" 'format " ")))
+            (cons "clip"
+                  '(("CLIP TYPE" 'list " " "points" "one" "two")))
+            (cons "noclip"
+                  '(("CLIP TYPE" 'list " " "points" "one" "two")))
+            ;;(cons "cntrparam"
+            ;;  '(("INTERPOLATION" 'list " " "linear" "cubicspline" "bspline")
+            ;;    ("POINTS" 'number " " "points")
+            ;;    ("ORDER"  'number " " "order")))
+            (cons "contour"
+                  '(("WHERE"     'list " " "base" "surface" "both")))
+            (cons "dgrid3d"
+                  '(("ROW,COLUMN,NORM" 'position " " "" 3)))
+            (cons "encoding"
+                  '(("ENCODING" 'list " " "default" "iso_8859_1"
+                     "cp850" "cp437")))
+            (cons "format"
+                  '(("AXIS"   'list " " "x" "y" "z" "xy" "x2" "y2")
+                    ("FORMAT" 'format  " ")))
+            (cons "dummy"
+                  '(("VAR 1" 'string " " "")
+                    ("VAR 2" 'string " " ",")))
+            (cons "grid"
+                  '(("XTICS"  'list " " "xtics" "mxtics" "noxtics" "nomxtics")
+                    ("YTICS"  'list " " "ytics" "mytics" "noytics" "nomytics")
+                    ("ZTICS"  'list " " "ztics" "mztics" "noztics" "nomztics")
+                    ("X2TICS" 'list " " "x2tics" "mx2tics" "nox2tics" "nomx2tics")
+                    ("Y2TICS" 'list " " "y2tics" "my2tics" "noy2tics" "nomy2tics")
+                    ("POLAR"  'number " " "polar")
+                    ("MAJOR LINETYPE" 'number " ")
+                    ("MINOR LINETYPE" 'number " ")))
+            (cons "hidden3d"
+                  '(("ALGORITHM" 'list " " "defaults"
+                     "offset"
+                     "nooffset"
+                     ;;"trianglepattern  # bitpattern between 0 and 7"
+                     "trianglepattern 0" "trianglepattern 1"
+                     "trianglepattern 2" "trianglepattern 3"
+                     "trianglepattern 4" "trianglepattern 5"
+                     "trianglepattern 6" "trianglepattern 7"
+                     ;;"undefined        # level between 0 and 3"
+                     "undefined 0" "undefined 1" "undefined 2" "undefined 3"
+                     "noundefined" "altdiagonal" "noaltdiagonal"
+                     "bentover" "nobentover")))
+            (cons "historysize"
+                  '(("SIZE" 'number " ")))
+            (cons "isosamples"
+                  '(("ISO_U LINES" 'number " ")
+                    ("ISO_V LINES" 'number " " ",")))
+            (cons "key"
+                  '(("LOCATION"      'list " " "left" "right" "top" "bottom"
+                     "outside" "below")
+                    ("POSITION"      'position  " " "" 3)
+                    ("JUSTIFICATION" 'list " " "Left" "Right")
+                    ("REVERSE"       'list " " "reverse" "noreverse")
+                    ("SAMPLE LENGTH" 'number " " "samplen")
+                    ("SPACING"       'number " " "spacing")
+                    ("WIDTH"         'number " " "width")
+                    ("TITLE"         'string " " "title ")
+                    ("BOX LINETYPE"  'number " " "box") ;; linetype data
+                    ("NOBOX"         'list   " " "nobox")))
+            (cons "label"
+                  '(("TAG" 'tag " ")
+                    ("LABEL TEXT" 'string " ")
+                    ("POSITION"   'position " " "at" 3)
+                    ;; first, second, graph, screen
+                    ("JUSTIFICATION" 'list " " "left" "right" "center")
+                    ("ROTATE"        'list " " "rotate" "norotate")
+                    ("FONT"          'string " " "font"))) ;; font "name,size"
+            (cons "nolabel"
+                  '(("TAG"        'tag " ")))
+            (cons "linestyle"
+                  '(("TAG      "  'tag " ")
+                    ("LINE STYLE" 'list " " "boxerrorbars" "boxes"
+                     "boxxyerrorbars" "candlesticks" "dots"
+                     "financebars" "fsteps" "histeps" "impulses"
+                     "lines" "linespoints" "points" "steps" "vector"
+                     "xerrorbars" "xyerrorbars" "yerrorbars")
+                    ("LINETYPE " 'number " " "lt")
+                    ("LINEWIDTH" 'number " " "lw")
+                    ("POINTTYPE" 'number " " "pt")
+                    ("POINTSIZE" 'number " " "ps")))
+            (cons "locale"
+                  '(("LOCALE" 'string " ")))
+            (cons "logscale"
+                  '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
+                     "x2" "y2")
+                    ("BASE" 'number " ")))
+            (cons "nologscale"
+                  '(("AXIS" 'list " " "x" "y" "z" "xy" "xz" "yz" "xyz"
+                     "x2" "y2")))
+            (cons "mapping"
+                  '(("COORDINATE SYSTEM" 'list " " "cartesian" "spherical"
+                     "cylindrical")))
+                                        ; _margin
+            (cons "bmargin"
+                  '(("BOTTOM MARGIN" 'number " ")))
+            (cons "lmargin"
+                  '(("LEFT MARGIN"   'number " ")))
+            (cons "rmargin"
+                  '(("RIGHT MARGIN"  'number " ")))
+            (cons "tmargin"
+                  '(("TOP MARGIN"    'number " ")))
+
+            (cons "missing"
+                  '(("CHARACTER" 'string " " 1)))
+                                        ; m_tics
+            (cons "mxtics"  gnuplot-gui-mtics-list)
+            (cons "mytics"  gnuplot-gui-mtics-list)
+            (cons "mztics"  gnuplot-gui-mtics-list)
+            (cons "mx2tics" gnuplot-gui-mtics-list)
+            (cons "my2tics" gnuplot-gui-mtics-list)
+
+                                        ; pm3d additions <MT>
+            (cons "mouse"
+                  '(("DOUBLECLICK"     'number " " "doubleclick")
+                    ("ZOOM"            'list   " " "zoomcoordinates" "nozoomcoordinates")
+                    ("POLAR"           'list   " " "polarcoordinates" "nopolarcoordinates")
+                    ("FORMAT"          'string " " "format")
+                    ("CLIPBOARDFORMAT" 'string " " "clipboardformat")
+                    ("MOUSEFORMAT"     'string " " "mouseformat")
+                    ("LABELS"          'list   " " "labels" "nolabels")
+                    ("LABELOPTIONS"    'string " " "labeloptions")
+                    ("ZOOMJUMP"        'list   " " "zoomjump" "nozoomjump")
+                    ("VERBOSE"         'list   " " "verbose" "noverbose")))
+            (cons "palette"
+                  '(("COLOR"       'list     " " "gray" "color")
+                    ("RGBFORMULAE" 'position " " "rgbformulae" 3)
+                    ("PARITY"      'list     " " "positive" "negative")
+                    ("FORMULAE"    'list     " " "nops_allcF" "ps_allcF")
+                    ("MAXCOLORS"   'number   " ")
+                    ("COLOR_BOX"   'list     " " "nocb" "cbdefault" "cbuser")
+                    ("ORIENTATION" 'list     " " "cbvertical" "cbhorizontal")
+                    ("ORIGIN"      'position " " "origin" 2)
+                    ("SIZE"        'position " " "size" 2)
+                    ("BORDER"      'number   " ")
+                    ("NOBORDER"    'list     " " "bdefault" "noborder")))
+            (cons "pm3d"
+                  '(("AT"         'list*  " " "b" "s" "t" "bs" "bt" "st" "bst")
+                    ("SCANS"      'list   " " "scansautomatic" "scansforward" "scansbackward")
+                    ("FLUSH"      'list*  " " "begin" "center" "end")
+                    ("CLIP"       'list   " " "clip1in" "clip4in")
+                    ("ZRANGE"     'range (" " . " ") ":")
+                    ("HIDDEN3D"   'number " ")
+                    ("NOHIDDEN3D" 'list   " " "nohidden3d")
+                    ("FILLING"    'list   " " "transparent" "solid")
+                    ("MAP"        'list   " " "map")))
+
+            (cons "offsets"
+                  '(("LEFT  " 'number " ")
+                    ("RIGHT " 'number " " ",")
+                    ("TOP   " 'number " " ",")
+                    ("BOTTOM" 'number " " ",")))
+            (cons "origin"
+                  '(("X ORIGIN"   'number " ")
+                    ("Y ORIGIN"   'number " " ",")))
+            (cons "output"
+                  '(("FILENAME"   'file " ")))
+            (cons "pointsize"
+                  '(("MULTIPLIER" 'number " ")))
+            (cons "samples"
+                  '(("2D PLOT"    'number " ")
+                    ("3D PLOT"    'number " " ",")))
+            (cons "size"
+                  '(("ASPECT"           'list " " "square" "nosquare"
+                     "ratio" "noratio")
+                    ("X-SCALE OR RATIO" 'number " ")
+                    ("Y-SCALE"          'number " " ",")))
+            (cons "style"
+                  '(("DATA TYPE"  'list " " "data" "function")
+                    ("PLOT STYLE" 'list " " "boxerrorbars" "boxes"
+                     "boxxyerrorbars" "candlesticks" "dots"
+                     "financebars" "fsteps" "histeps" "impulses"
+                     "lines" "linespoints" "points" "steps" "vector"
+                     "xerrorbars" "xyerrorbars" "yerrorbars")))
+            (cons "terminal"
+                  '(("TERMINAL TYPE" 'list " " gnuplot-gui-terminal-list)))
+            (cons "tics"
+                  '(("DIRECTION"  'list " " "in" "out")))
+            (cons "ticslevel"
+                  '(("RELATIVE HEIGHT" 'number " ")))
+            (cons "ticscale"
+                  '(("MAJOR" 'number " ")
+                    ("MINOR" 'number " ")))
+            (cons "timestamp"
+                  '(("FORMAT STRING" 'format " ")
+                    ("WHERE"         'list " " "top" "bottom")
+                    ("ROTATE"        'list " " "rotate" "norotate")
+                    ("X-OFFSET"      'number " ")
+                    ("Y-OFFSET"      'number " " ",")
+                    ("FONTNAME"      'list " " gnuplot-gui-fontname-list)))
+            (cons "timefmt"
+                  '(("FORMAT STRING" 'string " ")))
+            (cons "title"
+                  '(("TITLE" 'string " ")))
+            (cons "view"
+                  '(("X-ROTATION" 'number " ")
+                    ("Z-ROTATION" 'number " " ",")
+                    ("SCALE"      'number " " ",")
+                    ("Z-SCALE"    'number " " ",")))
+            ;; ("SCALE" 'position " " "," 4)
+                                        ; _data
+            (cons "xdata"      gnuplot-gui-data-list)
+            (cons "ydata"      gnuplot-gui-data-list)
+            (cons "zdata"      gnuplot-gui-data-list)
+            (cons "x2data"     gnuplot-gui-data-list)
+            (cons "y2data"     gnuplot-gui-data-list)
+                                        ; _label
+            (cons "xlabel"     gnuplot-gui-label-list)
+            (cons "ylabel"     gnuplot-gui-label-list)
+            (cons "zlabel"     gnuplot-gui-label-list)
+            (cons "x2label"    gnuplot-gui-label-list)
+            (cons "y2label"    gnuplot-gui-label-list)
+                                        ; _range, note that the [] syntax for
+                                        ;         the writeback argument is
+                                        ;         not properly supported
+            (cons "xrange"     gnuplot-gui-range-list)
+            (cons "yrange"     gnuplot-gui-range-list)
+            (cons "zrange"     gnuplot-gui-range-list)
+            (cons "x2range"    gnuplot-gui-range-list)
+            (cons "y2range"    gnuplot-gui-range-list)
+            (cons "trange"     gnuplot-gui-range-list)
+            (cons "rrange"     gnuplot-gui-range-list)
+            (cons "urange"     gnuplot-gui-range-list)
+            (cons "vrange"     gnuplot-gui-range-list)
+                                        ; _tics
+            (cons "xtics"      gnuplot-gui-tics-list)
+            (cons "ytics"      gnuplot-gui-tics-list)
+            (cons "ztics"      gnuplot-gui-tics-list)
+            (cons "x2tics"     gnuplot-gui-tics-list)
+            (cons "y2tics"     gnuplot-gui-tics-list)
+                                        ; zeroaxis
+            (cons "zeroaxis"   gnuplot-gui-zeroaxis-list)
+            (cons "xzeroaxis"  gnuplot-gui-zeroaxis-list)
+            (cons "yzeroaxis"  gnuplot-gui-zeroaxis-list)
+            (cons "y2zeroaxis" gnuplot-gui-zeroaxis-list)
+            (cons "x2zeroaxis" gnuplot-gui-zeroaxis-list)
+
+            (cons "zero"
+                  '(("THRESHOLD" 'number " ")))))
+
+(defvar gnuplot-gui-command-types nil
+  "Associated list of command descriptions.
+See the doc-string for `gnuplot-gui-all-types'.")
+(setq gnuplot-gui-command-types
+      (list (cons "cd"
+                  '(("FILENAME"       'file   " ")))
+            (cons "call"
+                  '(("INPUT FILE"     'file   " ")
+                    ("PARAMETER LIST" 'string " ")))
+            (cons "load"
+                  '(("INPUT FILE"     'file   " ")))
+            (cons "pause"
+                  '(("TIME"           'number " ")
+                    ("MESSAGE"        'string " ")))
+            (cons "print"
+                  '(("EXPRESSION"     'string " ")))
+            (cons "save"
+                  '(("SAVE"           'list   " " "functions" "variables" "set")
+                    ("FILE"           'file   " ")))
+            (cons "update"
+                  '(("INITIAL FILE"   'file   " " t)
+                    ("UPDATED FILE"   'file   " " t))) ))
+
+
+(defcustom gnuplot-gui-plot-splot-fit-style 'simple
+  "Control the complexity of the GUI display for plot, splot, and fit.
+The values are 'simple, which causes a limited set of plot, splot, or
+fit options to be displayed, and 'complete, which attempts to display
+all options.  The 'complete setting is prone to making errors when
+parsing values already in the script buffer."
+  :group 'gnuplot-gui
+  :type '(radio (const :tag "Simple listing"   simple)
+                (const :tag "Complete listing" complete)))
+
+
+(defconst gnuplot-gui-plot-simple-list
+  '(("X RANGE"     'range (" " . " ") ":")
+    ("Y RANGE"     'range (" " . " ") ":")
+    ("DATA FILE"   'file   " ")
+    ("THRU"        'string* " " "thru")
+    ("USING"       'modifier " ")
+    ("TITLE"       'string " ")
+    ("WITH"        'list* " " "boxerrorbars" "boxes"
+     "boxxyerrorbars" "candlesticks" "dots" "financebars"
+     "fsteps" "histeps" "impulses" "lines" "linespoints"
+     "points" "steps" "vector" "xerrorbars" "xyerrorbars"
+     "yerrorbars")))
+(defconst gnuplot-gui-plot-full-list
+  '(;;("T RANGE"     'range (" " . " ") ":")
+    ("X RANGE"     'range (" " . " ") ":")
+    ("Y RANGE"     'range (" " . " ") ":")
+    ("xa"          'text   "\t---------------------")
+    ("FUNCTION"    'string " ")
+    ("xc"          'text   "   or")
+    ("DATA FILE"   'file   " ")
+    ("INDEX"       'modifier " ")
+    ("EVERY"       'modifier " ")
+    ("THRU"        'string* " " "thru")
+    ("USING"       'modifier " ")
+    ("SMOOTH"      'list* " " "unique" "csplines" "acsplines"
+     "bezier" "sbezier")
+    ;; datafile modifiers
+    ("AXES"        'list* " " "x1y1" "x2y2" "x1y2" "x2y1")
+    ("TITLE"       'string " ")
+    ("NOTITLE"     'list   " " "notitle")
+    ("xf"          'text   "\t---------------------")
+    ("xi"          'text   "Select a standard plotting style")
+    ("WITH"        'list* " " "boxerrorbars" "boxes"
+     "boxxyerrorbars" "candlesticks" "dots" "financebars"
+     "fsteps" "histeps" "impulses" "lines" "linespoints"
+     "points" "steps" "vector" "xerrorbars" "xyerrorbars"
+     "yerrorbars")
+    ("xo"          'text   "     or a previously defined style")
+    ("LINE STYLE " 'number " " "ls")
+    ("xr"          'text   "     or specify a style in-line")
+    ("LINE TYPE  " 'number " " "lt")
+    ("LINE WIDTH " 'number " " "lw")
+    ("POINT TYPE " 'number " " "pt")
+    ("POINT STYLE" 'number " " "ps")))
+(defconst gnuplot-gui-splot-simple-list
+  '(("DATA FILE"   'file   " ")
+    ("TITLE"       'string " ")
+    ("WITH"        'list* " " "lines" "linespoints" "points" "dots" "impulses")))
+(defconst gnuplot-gui-splot-full-list
+  '(;;("U RANGE"     'range (" " . " ") ":")
+    ;;("V RANGE"     'range (" " . " ") ":")
+    ("X RANGE"     'range (" " . " ") ":")
+    ("Y RANGE"     'range (" " . " ") ":")
+    ("Z RANGE"     'range (" " . " ") ":")
+    ("xa"          'text   "\t---------------------")
+    ("FUNCTION"    'string " ")
+    ("xc"          'text   "   or")
+    ("DATA FILE"   'file   " ")
+    ("INDEX"       'modifier " ")
+    ("EVERY"       'modifier " ")
+    ("THRU"        'string* " " "thru")
+    ("USING"       'modifier " ")
+    ("SMOOTH"      'list* " " "unique" "csplines" "acsplines"
+     "bezier" "sbezier")
+    ("TITLE"       'string " ")
+    ("NOTITLE"     'list   " " "notitle")
+    ("WITH"        'list* " " "lines" "linespoints" "points" "dots" "impulses")))
+(defconst gnuplot-gui-fit-simple-list
+  '(("FUNCTION"     'string* " " "")
+    ("DATA FILE"    'file    " ")
+    ("VIA (params)" 'string* " " "via") ))
+(defconst gnuplot-gui-fit-full-list
+  '(("X RANGE"      'range  (" " . " ") ":")
+    ("Y RANGE"      'range  (" " . " ") ":")
+    ("xa"           'text    "----- fitting functionn and file --------")
+    ("FUNCTION"     'string* " " "")
+    ("DATA FILE"    'file    " ")
+    ("xb"           'text    "----- datafile modifiers ----------------")
+    ("INDEX"        'modifier " ")
+    ("EVERY"        'modifier " ")
+    ("THRU"         'string* " " "thru")
+    ("USING"        'modifier " ")
+    ("SMOOTH"       'list* " " "unique" "csplines" "acsplines"
+     "bezier" "sbezier")
+    ("xc"           'text    "----- parameters (file or parameters) ---")
+    ("VIA (file)"   'string  " " "via")
+    ("VIA (params)" 'string* " " "via") ))
+
+(defvar gnuplot-gui-plot-splot-fit nil
+  "Associated list of plot, splot, and fit descriptions.
+See the doc-string for `gnuplot-gui-all-types'.")
+(setq gnuplot-gui-plot-splot-fit
+      (list (cons "plot"  (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
+                              gnuplot-gui-plot-full-list
+                            gnuplot-gui-plot-simple-list))
+            (cons "splot" (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
+                              gnuplot-gui-splot-full-list
+                            gnuplot-gui-splot-simple-list))
+            (cons "fit"   (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
+                              gnuplot-gui-fit-full-list
+                            gnuplot-gui-fit-simple-list))) )
+
+
+(defvar gnuplot-gui-test-type nil)
+(setq gnuplot-gui-test-type
+      (list (cons "test"
+                  '(("TAG"      'tag      " ")
+                    ("LIST"     'list     " " "1" "2" "3")
+                    ("LIST*"    'list*    " " "1" "2" "3")
+                    ("NUMBER"   'number   " " "number")
+                    ("RANGE"    'range   (" " . " ") ":")
+                    ("PAIR"     'pair    (" " . " ") "pair")
+                    ("LABELS"   'labels   ())
+                    ("FILE"     'file     " ")
+                    ("TEXT"     'text     "this is text")
+                    ("STRING"   'string   " ")
+                    ("STRING*"  'string*  " " "string*")
+                    ("FORMAT"   'format   " ")
+                    ("POSITION" 'position " " "at" 3)
+                    ("FONTSIZE" 'fontsize " ") ))))
+
+(defvar gnuplot-gui-all-types nil
+  "Associated list of terminal, set option, and command arguments.
+
+Each entry in the list is a cons cell of the form
+      (OPTION . ALIST)
+where OPTION is one of the recognized options in Gnuplot, either a
+command, something that is set, or a terminal type.  Only those
+commands, set options, and terminal types that actually take arguments
+are in this associated list.
+
+ALIST is itself an associated list where each entry is of the form:
+
+      (TAG TYPE DEFAULT REST)
+
+TAG is the name used on the widget and indicates one of the options
+for this command, set option, or terminal type.
+
+TYPE is one of
+     'list       a menu-list of strings
+     'list*      a menu-list of strings with a prefix
+     'number     a number with an optional prefix
+     'tag        like number but must be the first argument
+     'fontsize   like number but must be the last argument
+     'range      a pair of numbers like [#,#] or [#:#]
+     'pair       a pair of numbers with no punctuation and a prefix
+     'file       a quoted string and a file browser
+     'string     a quoted string with an optional prefix
+     'string*    an unquoted string with a prefix
+     'format     a quoted string and an info-link to (gnuplot)format
+     'labels     an array as needed for xtics, ytics, etc
+     'position   2 or 3 comma separated numbers with an optional prefix
+
+DEFAULT is the default value for this option.  Note that the default
+for 'range and 'pair is a cons cell and the default for 'labels is a
+list.  For most things, the best choice of DEFAULT is a string of
+white space or a cons cell of two strings of white space.  Strings of
+white space are better defaults than empty strings or nil.
+
+The value of REST depends upon TYPE:
+
+  For 'list &    REST is the list of options that will go into the
+      'list*       menu-button.  This can also be a symbol which
+                   evaluates to a list containing the options to go into
+                   the menu-button.  This list variable must contain the
+                   DEFAULT.
+  For 'number    REST is the prefix string (if it exists) for that number.
+  For 'range     REST is the separator, \":\" for plot ranges and
+                   \",\" for plot dimensions (see for example the tgif
+                   terminal type)
+  For 'string &  REST may a number denoting the width of the editable-text
+      'string*     field or it may be a string denoting a prefix.  By
+                   default, the width is half the width of the frame
+                   and there is no prefix.  It may be useful to
+                   specify \"1\" when the input is a single character
+                   as in 'set missing'.
+  For 'file      REST determines the label placed before the file insertion
+                   field.  If non-nil, then TAG is used.  If nil, then
+                   the default \"File\" is used.
+  For 'position  REST is the prefix and the number of comma separated numbers
+  For others     REST is not used.
+
+Here is an example entry for the png terminal type:
+
+  (cons \"png\"
+    '((\"SIZE\"  'list \" \" \"small\" \"medium\" \"large\")
+      (\"COLOR\" 'list \" \" \"monochrome\" \"gray\" \"color\")))
+
+This alist is formed at load time by appending together
+`gnuplot-gui-terminal-types', `gnuplot-gui-set-types' and
+`gnuplot-gui-command-types'.")
+
+(setq gnuplot-gui-all-types (append gnuplot-gui-terminal-types
+                                    gnuplot-gui-set-types
+                                    gnuplot-gui-command-types
+                                    gnuplot-gui-plot-splot-fit
+                                    gnuplot-gui-test-type))
+
+
+;;;###autoload
+(defun gnuplot-gui-swap-simple-complete ()
+  (interactive)
+  (setq gnuplot-gui-plot-splot-fit-style
+        (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
+            'simple 'complete))
+  (if (equal gnuplot-gui-plot-splot-fit-style 'complete)
+      (progn
+        (setcdr (assoc "plot"  gnuplot-gui-all-types) gnuplot-gui-plot-full-list)
+        (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-full-list)
+        (setcdr (assoc "fit"   gnuplot-gui-all-types) gnuplot-gui-fit-full-list))
+    (setcdr (assoc "plot"  gnuplot-gui-all-types) gnuplot-gui-plot-simple-list)
+    (setcdr (assoc "splot" gnuplot-gui-all-types) gnuplot-gui-splot-simple-list)
+    (setcdr (assoc "fit"   gnuplot-gui-all-types) gnuplot-gui-fit-simple-list))
+  (message "Using %s lists for plot, splot, and fit."
+           gnuplot-gui-plot-splot-fit-style) )
+
+
+
+\f
+;;; user interface to the widget-y stuff
+
+;;;###autoload
+(defun gnuplot-gui-mouse-set (event)
+  "Use the mouse to begin setting options using a GUI interface.
+EVENT is a mouse event.  Bound to \\[gnuplot-gui-mouse-set]
+Note that \"plot\", \"splot\", \"fit\", and \"cntrparam\" are not
+currently supported."
+  (interactive "@e")
+  (save-excursion
+    (mouse-set-point event)
+    (gnuplot-gui-set-options-and-insert)))
+
+(defun gnuplot-gui-get-frame-param (param)
+  (cdr (assoc param gnuplot-gui-frame-parameters)))
+
+(defun gnuplot-gui-set-frame-param (param value)
+  (setcdr (assoc param gnuplot-gui-frame-parameters) value))
+
+;;;###autoload
+(defun gnuplot-gui-set-options-and-insert ()
+  "Insert arguments using a GUI interface.
+Determine contents of current line and set up the appropriate GUI
+frame.  Bound to \\[gnuplot-gui-set-options-and-insert]
+Note that \"cntrparam\" is not currently supported."
+  (interactive)
+  (let ((begin  (gnuplot-point-at-beginning-of-command))
+        (end    (save-excursion (end-of-line)       (point-marker)))
+        (termin (concat "\\(,\\s-*" (regexp-quote "\\") "\\|;\\)"))
+        (set nil) (term nil))
+    (save-excursion
+      ;; there can be more then one command per line
+      (if (re-search-forward termin end "to_limit")
+          (progn (backward-char (length (match-string 1)))
+                 (setq end (point-marker))))
+      (goto-char begin)
+      (skip-syntax-forward "-" end)
+      ;; various constructions are recognized here. at the end of this
+      ;; cond, point should be just after the word whose arguments are
+      ;; to be set
+      (cond ((looking-at "set\\s-+")
+             (setq set t)
+             (goto-char (match-end 0))
+             (if (looking-at "\\sw+") (goto-char (match-end 0)))
+             (when (string-match "^ter" (gnuplot-this-word)) ; terminal?
+               (setq term t)
+               (forward-word 1))
+             (when (string-match "^\\(da\\|fu\\)" (gnuplot-this-word))
+               (unless (looking-at "\\s-+st")
+                 (insert " style") (forward-word 1))
+               (forward-word 1)))
+            ((looking-at (concat "\\(cd\\|ca\\|lo\\|pa\\|pr\\|sa\\|u\\)"
+                                 "\\w*"
+                                 "[\\s-\\']"))
+             (forward-word 1))
+            ;;(goto-char (match-end 0)))
+            (t
+             (forward-word 1)))
+      (if (> (point) end) (goto-char end))
+      (let* ((w (gnuplot-this-word))
+             (wd (try-completion w gnuplot-gui-all-types))
+             (word "") wrd list)
+        (cond ((equal wd t)                     (setq word w))
+              ((equal wd nil)                   (setq word w))
+              ((assoc wd gnuplot-gui-all-types) (setq word wd))
+              (t                                (setq wd nil)))
+        (cond ((equal (string-match "^\\s-*$" w) 0)
+               (message "Blank line"))
+              ((and wd (stringp word))
+               (gnuplot-gui-correct-command word set term begin)
+               (setq gnuplot-gui-alist nil
+                     gnuplot-gui-current-string
+                     (buffer-substring-no-properties (point) end))
+               (gnuplot-gui-set-alist word gnuplot-gui-current-string)
+               (let* ((old-height (gnuplot-gui-get-frame-param 'height))
+                      (old-top    (gnuplot-gui-get-frame-param 'top)))
+                 (when (or
+                        (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
+                             (cl-member word '("plot" "splot" "fit")
+                                        :test 'string=))
+                        (equal word "test"))
+                   (gnuplot-gui-set-frame-param 'height 32)
+                   (gnuplot-gui-set-frame-param 'top    50))
+                 (gnuplot-gui-prompt-for-frame word)
+                 (when (or
+                        (and (equal gnuplot-gui-plot-splot-fit-style 'complete)
+                             (cl-member word '("plot" "splot" "fit")
+                                        :test 'string=))
+                        (equal word "test"))
+                   (gnuplot-gui-set-frame-param 'height old-height)
+                   (gnuplot-gui-set-frame-param 'top    old-top)) ))
+              ((setq wrd (car (all-completions w '(("cntrparam")))))
+               (message
+                "Setting arguments for %S is currently unsuported in gnuplot-mode"
+                wrd))
+              ((setq list (all-completions w gnuplot-gui-all-types))
+               (message "%S could be one of %S" w list))
+              (t
+               (message
+                "%S is not a gnuplot command which takes options" w)))) )))
+
+;;;###autoload
+(defun gnuplot-gui-toggle-popup ()
+  (interactive)
+  (setq gnuplot-gui-popup-flag (not gnuplot-gui-popup-flag))
+  (message (if gnuplot-gui-popup-flag
+               "Argument popup will appear after insertions."
+             "Argument popup will no longer appear after insertions.")))
+
+
+(defalias 'gnuplot-gui-y-n 'y-or-n-p)
+
+(defun gnuplot-gui-correct-command (word set term begin)
+  "Check syntax of set command and terminal specifications.
+WORD is the item being set. SET and TERM are non-nil if the words
+\"set\" and \"terminal\" were found preceding WORD in the buffer.
+BEGIN is the beginning of the command."
+  (save-excursion
+    (cond ((assoc word gnuplot-gui-terminal-types)
+           (when (and (not (and set term))
+                      (gnuplot-gui-y-n
+                       (format
+                        "%S must be preceded by \"set terminal\".  Add it? "
+                        word)))
+             (backward-word 1)
+             (let ((e (point-marker)))
+               (goto-char begin)
+               (skip-syntax-forward "-" e)
+               (delete-region (point) e)
+               (insert "set terminal "))))
+          ((assoc word gnuplot-gui-set-types)
+           (when (and (not set)
+                      (gnuplot-gui-y-n
+                       (format
+                        "%S must be preceded by \"set\".  Add \"set\"? " word)))
+             (backward-word 1)
+             (let ((e (point-marker)))
+               (goto-char begin)
+               (skip-syntax-forward "-" e)
+               (delete-region (point) e)
+               (insert "set "))))))
+  (message nil))
+
+
+\f
+;;; handle the actual arguments
+
+(defun gnuplot-gui-fix-arg-list (list)
+  "Correct the result of splitting `gnuplot-gui-current-string'.
+LIST is the split string.  This removes empty and all-blank strings
+from the list and concatenates the strings that are part of a quoted
+argument, for example an axis label or a font name.  It also replaces
+bounding single quotes with double quotes, since double quotes are
+used in `gnuplot-gui-all-types'."
+  (let (fixed-list quote quoted)    ; remove blanks
+    (setq list (cl-remove "\\s-+" list :test 'string-match)
+          list (cl-remove ""      list :test 'string=))
+    (while list             ; concatinate parts of quoted string
+      (if (not (string-match "^\\([\]\[()'\"]\\)" (car list)))
+          (setq fixed-list (append fixed-list (list (car list))))
+        (setq quote (match-string 1 (car list))
+              quoted (car list))
+        (if (string= quote "[") (setq quote "]"))
+        (if (string= quote "(") (setq quote ")"))
+        (while (and list
+                    (or (equal (length quoted) 1)
+                        (not (string-match (concat (regexp-quote quote) "$")
+                                           quoted))))
+          (setq quoted (concat quoted " " (cadr list))
+                list (cdr list)))
+        (if (string= quote "'")
+            (setq quoted (concat "\"" (substring quoted 1))
+                  quoted (concat (substring quoted 0 -1) "\"")))
+        (setq fixed-list (append fixed-list (list quoted))))
+      (setq list (cdr list)) )
+    fixed-list))
+
+(defun gnuplot-gui-set-alist (word string)
+  "Set defaults for arguments, using text from buffer if appropriate.
+WORD is the Gnuplot expression whose arguments are being set.  STRING
+is text from the buffer containing the previous values for WORD's
+arguments."
+  (let ((alist    (cdr (assoc word gnuplot-gui-all-types)))
+        (arg-list (gnuplot-gui-fix-arg-list (split-string string)) ))
+    ;; arg-list contains the arguments taken from the buffer
+    (setq gnuplot-gui-alist nil)
+    (while alist
+      (let* ((list      (car alist))
+             (tag       (gnuplot-gui-type-tag     list))
+             (symbol    (eval (gnuplot-gui-type-symbol list)))
+             (default   (gnuplot-gui-type-default list))
+             (prefix    (gnuplot-gui-type-prefix  list))
+             (values    (gnuplot-gui-type-list    list))
+             (this-cons (cond ((stringp default) (cons tag default))
+                              ((consp default) ; set cons valued default w/care
+                               (cons tag (cons (car default) (cdr default))))
+                              (t (cons tag default))))
+             (temp-list arg-list) )
+        ;;(message "%S" temp-list)  ; want to lop values off arg-list
+                                        ; as they are found
+        (if (symbolp (cadr values))
+            (setq values (symbol-value (cadr values))))
+        ;; check if an argument of this type is in arg-list
+        ;; set the current cons cell if it is
+        (while temp-list
+          (cond
+           ;; ---------------------------- list
+           ((cl-member symbol '(list list*) :test 'equal)
+            (let* ((case-fold-search nil)
+                   (match-cons (cl-member (concat "^" (car temp-list))
+                                        values :test 'string-match)))
+              (if (and (car match-cons) ; " " may be first elem. of list
+                       (not (string= " " (car match-cons))))
+                  (setq this-cons (cons tag (car match-cons))
+                        arg-list (cl-remove (car temp-list) arg-list
+                                          :test 'string= :count 1)
+                        temp-list nil)
+                (setq temp-list (cdr temp-list)))))
+           ;; ---------------------------- tag (first number in list)
+           ((equal symbol 'tag)
+            (if (string-match "^[-0-9.]+$" (car arg-list))
+                (setq this-cons (cons  tag (car arg-list))
+                      temp-list nil)
+              (setq temp-list (cdr temp-list))) )
+           ;; ---------------------------- fontsize (last number in list)
+           ((equal symbol 'fontsize)
+            (if (string-match "^[-0-9.]+$" (car (last arg-list)))
+                (setq this-cons (cons  tag (car (last arg-list)))
+                      temp-list nil)
+              (setq temp-list (cdr temp-list))) )
+           ;; ---------------------------- number with prefix
+           ((equal symbol 'number)
+            (cond ((and (string= prefix (car temp-list))
+                        (string-match "^[-0-9.]+$" (cadr temp-list)))
+                   (setq this-cons (cons tag (cadr temp-list))
+                         arg-list (cl-remove (car temp-list) arg-list
+                                           :test 'string= :count 1)
+                         arg-list (cl-remove (cadr temp-list) arg-list
+                                           :test 'string= :count 1)
+                         temp-list nil))
+                  ;; --------------------- number without prefix
+                  ((and (not prefix)
+                        (string-match "^[-0-9.]+$" (car temp-list)))
+                   (setq this-cons (cons tag (car temp-list))
+                         arg-list (cl-remove (car temp-list) arg-list
+                                           :test 'string= :count 1)
+                         temp-list nil))
+                  (t
+                   (setq temp-list (cdr temp-list)))))
+           ;; ---------------------------- pair with prefix
+           ((equal symbol 'pair)
+            (if (and (string= prefix (car temp-list))
+                     (string-match "^[-0-9.]+$" (cadr temp-list)))
+                (let ((this-car (cadr temp-list))
+                      (this-cdr (if (string-match "^[-0-9.]+$" (cl-caddr temp-list))
+                                    (cl-caddr temp-list) "")))
+                  (setq this-cons (cons tag (cons this-car this-cdr))
+                        temp-list nil))
+              (setq temp-list (cdr temp-list))))
+           ;; ---------------------------- range
+           ((equal symbol 'range)
+            (if (string-match (concat "\\[\\s-*" ; opening bracket
+                                      "\\([^:, \t]*\\)" ; first argument
+                                      "\\s-*[:,]\\s-*" ; separator
+                                      "\\([^\] \t]*\\)" ; second argument
+                                      "\\s-*\\]") ; closing bracket
+                              (car temp-list))
+                (setq this-cons
+                      (cons tag (cons (match-string 1 (car temp-list))
+                                      (match-string 2 (car temp-list))))
+                      arg-list (cl-remove (car temp-list) arg-list
+                                        :test 'string= :count 1)
+                      temp-list nil)
+              (setq temp-list (cdr temp-list)) ))
+           ;; ---------------------------- labels
+           ((equal symbol 'labels)
+            (if (string-match (concat "(" ; opening paren
+                                      "\\([^\)]*\\)" ; string
+                                      ")") ; closing paren
+                              (car temp-list))
+                (let* ((list (split-string (car temp-list) "[ \t(),]+"))
+                       (list (cl-remove "" list :test 'string=))
+                       (return ()))
+                  (while list
+                    (if (string-match "['\"]\\([^'\"]*\\)['\"]" (car list))
+                        (setq return (append return
+                                             (list (match-string 1 (car list))))
+                              list (cdr list)
+                              return (append return (list (car list))) )
+                      (setq return (append return (list "" (car list)))))
+                    (setq list (cdr list)) )
+                  (setq this-cons (cons tag return)
+                        arg-list (cl-remove (car temp-list) arg-list
+                                          :test 'string= :count 1)
+                        temp-list nil))
+              (setq temp-list (cdr temp-list))) )
+           ;; ---------------------------- string, file, format
+           ((cl-member symbol '(string file format) :test 'equal)
+            (if (string-match (concat "['\"]" ; opening quote
+                                      "\\([^'\"]*\\)" ; string
+                                      "['\"]") ; closing quote
+                              (car temp-list))
+                (setq this-cons (cons tag (match-string 0 (car temp-list)))
+                      arg-list (cl-remove (car temp-list) arg-list
+                                        :test 'string= :count 1)
+                      temp-list nil)
+              (setq temp-list (cdr temp-list)) ))
+           ;; ---------------------------- string*
+           ((equal symbol 'string*)
+            (if (string= prefix (car temp-list))
+                (setq this-cons (cons tag (cadr temp-list))
+                      arg-list (cl-remove (car temp-list) arg-list
+                                        :test 'string= :count 1)
+                      arg-list (cl-remove (cadr temp-list) arg-list
+                                        :test 'string= :count 1)
+                      temp-list nil)
+              (setq temp-list (cdr temp-list)) ) )
+           ;; ---------------------------- other or unknown
+           (t
+            (setq temp-list nil))))
+        (setq gnuplot-gui-alist
+              (append gnuplot-gui-alist (list this-cons))))
+      (setq alist (cdr alist))) ))
+
+
+(defun gnuplot-gui-post-process-alist (type)
+  "A few types need some additional processing.
+'range, 'pair, and 'labels are cons or list valued and need to b made
+into strings.  This is called right before inserting the arguments
+into the buffer.  TYPE is the object whose arguments are being set."
+  (let ((alist gnuplot-gui-alist)
+        (types (cdr (assoc type gnuplot-gui-all-types))) )
+    (while alist  ;; loop thru alist looking for tyeps needing post-processing
+      (let* ((list   (assoc (caar alist) types))
+             (value  (cdr (assoc (caar alist) gnuplot-gui-alist)))
+             (prefix (gnuplot-gui-type-prefix list))
+             (symb   (gnuplot-gui-type-symbol list)) )
+        (cond
+         ;;-------------------------- flat text
+         ((equal (eval symb) 'text)
+          (setcdr (assoc (caar alist) gnuplot-gui-alist) ""))
+         ;;-------------------------- range [#:#] or [#,#]
+         ((equal (eval symb) 'range)
+          (if (and (string-match "^\\s-*$" (car value))
+                   (string-match "^\\s-*$" (cdr value)))
+              (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
+            (setcdr (assoc (caar alist) gnuplot-gui-alist)
+                    (concat "[" (car value) prefix (cdr value) "]")) ) )
+         ;;-------------------------- pair
+         ((equal (eval symb) 'pair)
+          (if (and (string-match "^\\s-*$" (car value))
+                   (string-match "^\\s-*$" (cdr value)))
+              (setcdr (assoc (caar alist) gnuplot-gui-alist) "")
+            (setcdr (assoc (caar alist) gnuplot-gui-alist)
+                    (concat prefix " " (car value) " " (cdr value) )) ) )
+         ;;-------------------------- labels
+         ((equal (eval symb) 'labels)
+          (if (consp value)
+              (let ((word "") (list value))
+                (while list
+                  (if (string-match "^\\s-*$" (car list))
+                      (setq word (concat word (format "%s, " (cadr list))))
+                    (setq word (concat word (format "%S %s, " (car list)
+                                                    (cadr list)))))
+                  (setq list (cddr list)) )
+                (setq value (concat "(" (substring word 0 -2) ")")))
+            (setq value "") )
+          (setcdr (assoc (caar alist) gnuplot-gui-alist) value) ))
+
+        (setq alist (cdr alist))) )))
+
+\f
+;;; GUI frames
+
+(defun gnuplot-gui-prompt-for-frame (&optional option save-frame)
+  (setq option (or option (completing-read "Option: " gnuplot-gui-all-types
+                                           nil t nil t)))
+  (gnuplot-gui-make-frame
+   option (cdr (assoc option gnuplot-gui-all-types)) save-frame) )
+
+
+(defface gnuplot-gui-error-face '((((class color) (background light))
+                                   (:foreground "grey30"))
+                                  (((class color) (background dark))
+                                   (:foreground "grey70")))
+  "Face used to display message about unknown widget types."
+  :group 'gnuplot-faces)
+
+(defface gnuplot-gui-flat-text-face '((((class color) (background light))
+                                       (:foreground "MediumBlue"))
+                                      (((class color) (background dark))
+                                       (:foreground "LightSteelBlue")))
+  "Face used to display message about unknown widget types."
+  :group 'gnuplot-faces)
+
+(defun gnuplot-gui-make-frame (item alist &optional save-frame)
+  "Open the frame and populate it with widgets.
+ITEM is the object for which arguments are being set.  ALIST is
+the alist of arguments for ITEM taken from `gnuplot-gui-all-types'.
+SAVE-FRAME is non-nil when the widgets are being reset."
+  (unless save-frame
+    (setq gnuplot-current-frame (selected-frame)
+          gnuplot-current-buffer (current-buffer)
+          gnuplot-current-buffer-point (point-marker))
+    (unless (and gnuplot-gui-frame (frame-live-p gnuplot-gui-frame))
+      (setq gnuplot-gui-frame (make-frame gnuplot-gui-frame-parameters)))
+    (select-frame gnuplot-gui-frame)
+    ;;(set-frame-position gnuplot-gui-frame 150 150) ;; so herky-jerky
+    (set-mouse-position gnuplot-gui-frame 0 0))
+  (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
+  (switch-to-buffer (get-buffer-create "*Gnuplot GUI*"))
+  (kill-all-local-variables)
+  (modify-frame-parameters (selected-frame)
+                           '((title . "Set Gnuplot Options")))
+  (widget-insert "\nSet options for \"" item "\"  ")
+  (let (tag help val)
+    (cond ((string-match "^[xyz]2?tics" item)
+           (setq tag  "info on tic labels"
+                 help "Open a frame displaying the info entry for tic labels"
+                 val  "xtics"))
+          ((string-match "^no" item)
+           (setq tag  (concat "info on " (substring item 2))
+                 help (format "Open a frame displaying the info entry for %S"
+                              item)
+                 val  item))
+          (t
+           (setq tag  (concat "info on " item)
+                 help (format "Open a frame displaying the info entry for %S"
+                              item)
+                 val  item)))
+    (widget-create 'gnuplot-gui-info-link :tag tag :help-echo help :value val))
+
+  (widget-insert "\n\n")
+  (while alist
+    (let* ((this    (car   alist))
+           (tag     (gnuplot-gui-type-tag    this))
+           (wtype   (gnuplot-gui-type-symbol this))
+           (prefix  (gnuplot-gui-type-prefix this))
+           (default (cdr (assoc tag gnuplot-gui-alist)))
+           (list    (gnuplot-gui-type-list   this)))
+      (if (symbolp (cadr list))
+          (setq list (symbol-value (cadr list))))
+      (widget-insert "\t")      ; insert the appropriate widget
+      (cond
+       ;;------------------------------ list, list* ------------
+       ((cl-member (eval wtype) '(list list*) :test 'equal)
+        (let ((starred (if (equal (eval wtype) 'list*) t nil)))
+          (gnuplot-gui-menu-choice tag default list starred)))
+       ;;------------------------------ number, tag, fontsize --
+       ((cl-member (eval wtype) '(number tag fontsize) :test 'equal)
+        (gnuplot-gui-number tag default prefix))
+       ;;------------------------------ position ---------------
+       ;;------------------------------ range, pair ------------
+       ((cl-member (eval wtype) '(range pair) :test 'equal)
+        (let ((is-range (equal (eval wtype) 'range)))
+          (gnuplot-gui-range tag default prefix is-range)))
+       ;;------------------------------ string, string* --------
+       ((cl-member (eval wtype) '(string string*) :test 'equal)
+        (let ((starred (if (equal (eval wtype) 'string) nil t)))
+          (gnuplot-gui-string tag default prefix starred)))
+       ;;------------------------------ format -----------------
+       ((equal (eval wtype) 'format)
+        (gnuplot-gui-format tag default))
+       ;;------------------------------ file -------------------
+       ((equal (eval wtype) 'file)
+        (gnuplot-gui-file tag default prefix))
+       ;;------------------------------ labels -----------------
+       ((equal (eval wtype) 'labels)
+        (gnuplot-gui-labels tag default))
+       ;;------------------------------ text -------------------
+       ((equal (eval wtype) 'text)
+        (let ((str (gnuplot-gui-type-default this)))
+          (put-text-property 0 (length str) 'face 'gnuplot-gui-flat-text-face str)
+          (widget-insert str "\n")))
+       ;;------------------------------ unknown ----------------
+       (t
+        (let ((str (concat "<" (downcase tag) "> ('"
+                           (symbol-name (eval wtype))
+                           " arguments are not yet supported)\n")))
+          (put-text-property 0 (length str) 'face 'gnuplot-gui-error-face str)
+          (widget-insert str)) )))
+    (setq alist (cdr alist)))
+  ;; insert control buttons: [Set options]   [Reset]   [Clear]   [Cancel]
+  (widget-insert "\n\t")
+  (widget-create 'push-button
+                 :value "Set options"
+                 :doc item
+                 :button-face 'gnuplot-gui-button-face
+                 :help-echo "Push this button to set options"
+                 :notify
+                 (lambda (widget &rest _ignore)
+                   (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
+                   (delete-frame)
+                   (select-frame gnuplot-current-frame)
+                   (switch-to-buffer gnuplot-current-buffer)
+                   (goto-char gnuplot-current-buffer-point)
+                   (gnuplot-gui-post-process-alist
+                    (widget-get widget :doc))
+                   (let ((alist gnuplot-gui-alist) marker
+                         (eol (save-excursion (end-of-line) (point-marker) )) )
+                     (if (re-search-forward ";" eol "to_limit")
+                         (backward-char 1))
+                     (delete-region gnuplot-current-buffer-point (point-marker))
+                     (delete-horizontal-space)
+                     (setq marker (point-marker))
+                     (while alist
+                       (let ((val (cdar alist)))
+                         (if (string-match "^\\s-+$" val) ()
+                           (if (string-match "^['\"]\\(.*\\)['\"]$" val)
+                               (setq val (concat gnuplot-quote-character
+                                                 (match-string 1 val)
+                                                 gnuplot-quote-character)))
+                           (insert (format " %s" val))))
+                       (setq alist (cdr alist)))
+                     (setq eol (point-marker))
+                     (goto-char marker)
+                     (while (< (point) eol) ; a few odd cases
+                       (unless (looking-at (concat "[" (regexp-quote "(")
+                                                   (regexp-quote "*") ",]"))
+                         (just-one-space))
+                       (forward-sexp)))
+                   (delete-horizontal-space)
+                   (if (string= "terminal" (widget-get widget :doc))
+                       (gnuplot-gui-set-options-and-insert)) ))
+  (widget-insert "   ")
+  (widget-create 'push-button :value "Reset"
+                 :help-echo "Push this button to reset all values"
+                 :button-face 'gnuplot-gui-button-face
+                 :doc item
+                 :notify
+                 (lambda (widget &rest _ignore)
+                   (let ((word (widget-get widget :doc)))
+                     (gnuplot-gui-set-alist word gnuplot-gui-current-string)
+                     (gnuplot-gui-prompt-for-frame word t))))
+  (widget-insert "   ")
+  (widget-create 'push-button :value "Clear"
+                 :help-echo "Push this button to clear all values"
+                 :button-face 'gnuplot-gui-button-face
+                 :doc item
+                 :notify
+                 (lambda (widget &rest _ignore)
+                   (let* ((word (widget-get widget :doc))
+                          (alist (cdr (assoc word gnuplot-gui-all-types))))
+                     (while alist
+                       (setcdr (assoc (gnuplot-gui-type-tag (car alist))
+                                      gnuplot-gui-alist)
+                               (gnuplot-gui-type-default (car alist)))
+                       (setq alist (cdr alist)))
+                     (gnuplot-gui-prompt-for-frame word t))) )
+  (widget-insert "   ")
+  (widget-create 'push-button :value "Cancel"
+                 :help-echo "Quit setting options and dismiss frame"
+                 :button-face 'gnuplot-gui-button-face
+                 :notify (lambda (_widget &rest _ignore)
+                           (kill-buffer (get-buffer-create "*Gnuplot GUI*"))
+                           (setq gnuplot-gui-alist nil
+                                 gnuplot-gui-current-string nil)
+                           (delete-frame)
+                           (select-frame gnuplot-current-frame)))
+  (goto-char (point-min))
+  (use-local-map widget-keymap)
+  (widget-setup))
+
+\f
+;;; widgets
+
+(defface gnuplot-gui-menu-face '((((class color) (background light))
+                                  (:bold t :foreground "darkolivegreen"))
+                                 (((class color) (background dark))
+                                  (:bold t :foreground "seagreen"))
+                                 (t
+                                  (:italic t)))
+  "Face used for menu-buttons."
+  :group 'gnuplot-faces)
+(defface gnuplot-gui-button-face '((((class color) (background light))
+                                    (:bold t :foreground "sienna"))
+                                   (((class color) (background dark))
+                                    (:bold t :foreground "tan"))
+                                   (t
+                                    (:italic t)))
+  "Face used for push-buttons."
+  :group 'gnuplot-faces)
+(defface gnuplot-gui-labels-face '((((class color) (background light))
+                                    (:bold t :foreground "darkslateblue"))
+                                   (((class color) (background dark))
+                                    (:bold t :foreground "lightslateblue"))
+                                   (t
+                                    (:italic t)))
+  "Face used for insert and delete button in the labels widget."
+  :group 'gnuplot-faces)
+
+(defun gnuplot-gui-menu-choice (item default list &optional starred)
+  "Create a menu widget for the Gnuplot GUI.
+ITEM is the object whose arguments are set by this widget, DEFAULT
+is the default argument value, LIST contains the items for the pop-up
+menu.  STARRED is true if this a 'list* widget."
+  (let ((widget
+         (apply 'widget-create
+                'menu-choice :value default :tag item :doc starred
+                :button-face 'gnuplot-gui-menu-face
+                :button-prefix "[" :button-suffix "]"
+                :help-echo (format "Mouse-2 to view the %S menu" (downcase item))
+                :notify
+                (lambda (widget &rest _ignore)
+                  (let ((lab (if (widget-get widget :doc)
+                                 (concat (downcase (widget-get widget :tag)) " ")
+                               "" )))
+                    (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
+                            (if (string= (widget-value widget) " ") ""
+                              (format "%s%s" lab (widget-value widget))) )))
+                (mapcar (lambda (x) (list 'item :value x))
+                        list))))
+    (widget-value-set widget default)
+    (if (and starred (not (string-match "^\\s-*$" default)))
+        (setcdr (assoc item gnuplot-gui-alist)
+                (format "%s %s" (downcase item) default)))
+    widget))
+
+(defun gnuplot-gui-number (item default &optional prefix)
+  "Create a number widget for the Gnuplot GUI.
+ITEM is the object whose arguments are set by this widget, DEFAULT
+is the default value for the widget, PREFIX is a text string preceding
+the numerical argument."
+  (let ((help-label (or prefix (downcase item))))
+    (widget-insert (capitalize item) ": ")
+    (widget-create 'editable-field
+                   :size 2 :tag item :value default :doc prefix
+                   :help-echo (format "Insert new value of %S here" help-label)
+                   :notify (lambda (widget &rest _ignore)
+                             (let ((val (widget-value widget))
+                                   (pre (concat (widget-get widget :doc) " ")))
+                               (setcdr (assoc (widget-get widget :tag)
+                                              gnuplot-gui-alist)
+                                       (if (string-match
+                                            "^\\s-*[-0-9.*]+\\s-*$" val)
+                                           (format "%s%s" pre val) "") )))))
+  (unless (string-match "^\\s-*$" default)
+    (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" prefix default)))
+  (widget-insert " " (make-string (- 40 (current-column)) ?.)
+                 " (numeric value)\n"))
+
+(defun gnuplot-gui-string (item default &optional width_or_prefix starred)
+  "Create a string widget for the Gnuplot GUI.
+ITEM is the object whose arguments are set by this widget, DEFAULT is
+the default value for the widget, and WIDTH_OR_PREFIX is the width of
+the text entry field (which defaults to half the frame width) or the
+prefix for the string.  STARRED is t if quotes are not to be used."
+  (let ((help-label (downcase item)) width (prefix "") (pp ""))
+    (cond ((stringp width_or_prefix)
+           (setq prefix width_or_prefix
+                 pp prefix)
+           (if starred (setq prefix (concat prefix "_star"))) )
+          ((numberp width_or_prefix)
+           (setq width width_or_prefix)))
+    (setq width (or width (/ (frame-width) 2)))
+    (if (string-match "^['\"]" default)
+        (setq default (replace-match "" nil nil default)))
+    (if (string-match "['\"]$" default)
+        (setq default (replace-match "" nil nil default)))
+    (widget-insert (capitalize item) ": ")
+    (widget-create
+     'editable-field
+     :size width :tag item :doc prefix :value default
+     :help-echo (format "Insert new value of %S here" help-label)
+     :notify (lambda (widget &rest _ignore)
+               (let ((val (widget-value widget))
+                     (q gnuplot-quote-character)
+                     (p (widget-get widget :doc)) )
+                 (setcdr (assoc (widget-get widget :tag) gnuplot-gui-alist)
+                         (if (string-match "^\\s-*$" val)
+                             ""
+                           (progn
+                             (if (string-match "_star$" p)
+                                 (setq p (concat (substring p 0 -5) " ")
+                                       q ""))
+                             (if (string-match "^\\s-+" val)
+                                 (setq val (replace-match "" nil nil val)))
+                             (if (string-match "\\s-+$" val)
+                                 (setq val (replace-match "" nil nil val)))
+                             (format "%s%s%s%s" p q val q)))))))
+    (unless (string-match "^\\s-*$" default)
+      (setcdr (assoc item gnuplot-gui-alist) (format "%s %s" pp default)))
+    (widget-insert "\n")))
+
+(defun gnuplot-gui-format (item default)
+  "Create a string widget for the Gnuplot GUI.
+ITEM is the object whose arguments are set by this widget, DEFAULT is
+the default value for the widget, and WIDTH_OR_PREFIX is the width of
+the text entry field (which defaults to half the frame width) or the
+prefix for the string."
+  (if (string-match "^['\"]" default)
+      (setq default (replace-match "" nil nil default)))
+  (if (string-match "['\"]$" default)
+      (setq default (replace-match "" nil nil default)))
+  (widget-insert (capitalize item) ": ")
+  (widget-create 'editable-field
+                 :size (/ (frame-width) 3) :tag item :value default
+                 :help-echo (format "Insert new format string here")
+                 :notify (lambda (widget &rest _ignore)
+                           (let ((val (widget-value widget)))
+                             (setcdr (assoc (widget-get widget :tag)
+                                            gnuplot-gui-alist)
+                                     (format "%s%s%s"
+                                             gnuplot-quote-character
+                                             val
+                                             gnuplot-quote-character)))))
+  (widget-insert "   ")
+  (widget-create 'gnuplot-gui-info-link
+                 :tag (concat "info on format")
+                 :help-echo "Open a frame displaying the info entry for format"
+                 :value "format")
+  (widget-insert "\n"))
+
+
+;; swiped from widget-color-complete
+(defun gnuplot-gui-file-completion (widget)
+  "Complete the filename in WIDGET."
+  (let* ((str (buffer-substring-no-properties (widget-field-start widget)
+                                              (point)))
+         (file (or (file-name-nondirectory str) ""))
+         (dir  (or (file-name-directory str) "./"))
+         (val  (file-name-completion file dir)) )
+    (cond ((eq val t)
+           (message "Exact match"))
+          ((null val)
+           (error "Can't find completion for \"%s\"" str))
+          ((not (string-equal str val))
+           (insert (substring val (length file))))
+          (t
+           (message "Making completion list...")
+           (let ((list (file-name-all-completions file dir)))
+             (with-output-to-temp-buffer "*Completions*"
+               (display-completion-list list)))
+           (message "Making completion list...done")))))
+
+(defun gnuplot-gui-file (item default &optional tag)
+  "Create a file widget for the Gnuplot GUI.
+ITEM is the object whose arguments is set by this widget, DEFAULT is
+the default value for the argument.  TAG is non-nil if ITEM rather than
+\"File:\" is to be used as the tag."
+  (setq tag (if tag (capitalize item) "File"))
+  (if (string-match "^['\"]" default)
+      (setq default (replace-match "" nil nil default)))
+  (if (string-match "['\"]$" default)
+      (setq default (replace-match "" nil nil default)))
+  (let ((widg (widget-create
+               'file
+               :value default :tag tag
+               :size (- (/ (frame-width) 2) 3)
+               :doc item :help-echo "Insert a filename here"
+               :complete 'gnuplot-gui-file-completion
+               :notify
+               (lambda (widget &rest _ignore)
+                 (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
+                         (format "%s%s%s" gnuplot-quote-character
+                                 (widget-value widget)
+                                 gnuplot-quote-character)) )) ))
+    (widget-insert " ")
+    (widget-create
+     'push-button :value "Browse"
+     :doc item :help-echo "Browse directories for a filename."
+     :parent widg
+     :notify (lambda (widget &rest _ignore)
+               (let ((fname (file-relative-name (read-file-name "File: ")
+                                                default-directory))
+                     (q gnuplot-quote-character))
+                 (widget-value-set (widget-get widget :parent) fname)
+                 (setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
+                         (format "%s%s%s" q fname q))
+                 (widget-setup))))
+    (widget-insert "\n")))
+
+(defun gnuplot-gui-labels (item default)
+  "Create a labels widget for the Gnuplot GUI.
+ITEM is the object whose arguments is set by this widget, DEFAULT is
+the default value for the argument."
+  (widget-create
+   '(editable-list
+     (list :inline t :tag "Tic label"
+           (string :tag "label" :size 10
+                   :help-echo "Enter the tic label here" )
+           (string :tag "  position" :size 10
+                   :help-echo "Enter an expression for the tic location here" )))
+   :tag (capitalize item)
+   :value default
+   :format "%{%t%}:\n%v\t  %i\n"
+   :entry-format "\t  %i %d %v\n"
+   :button-face 'gnuplot-gui-labels-face
+   :notify (lambda (widget &rest _ignore)
+             (setcdr (assoc (upcase (widget-get widget :tag))
+                            gnuplot-gui-alist)
+                     (widget-value widget)))))
+
+(defun gnuplot-gui-range (item default separator is-range)
+  "Create a range or pair widget for the Gnuplot GUI.
+ITEM is the object whose arguments are set by this widget, DEFAULT is
+the default value for the widget, SEPARATOR is a text string preceding
+the numerical argument, or the prefix for a pair operator.  IS-RANGE
+is non-nil if this is a 'range widget."
+  (widget-insert (capitalize item) ": ")
+  (if is-range (widget-insert "["))
+  (widget-create 'editable-field
+                 :size 4 :tag item :value (car default)
+                 :help-echo (format "Insert the first value of the %S here"
+                                    (downcase item))
+                 :notify (lambda (widget &rest _ignore)
+                           (setcar (cdr (assoc (widget-get widget :tag)
+                                               gnuplot-gui-alist))
+                                   (format "%s" (widget-value widget)))))
+  (if is-range (widget-insert separator) (widget-insert "  "))
+  (widget-create 'editable-field
+                 :size 4 :tag item :value (cdr default)
+                 :help-echo (format "Insert the second value of the %S here"
+                                    (downcase item))
+                 :notify (lambda (widget &rest _ignore)
+                           (setcdr (cdr (assoc (widget-get widget :tag)
+                                               gnuplot-gui-alist))
+                                   (format "%s" (widget-value widget)))))
+  (if is-range (widget-insert "]"))
+  (widget-insert " " (make-string (- 39 (current-column)) ?.)
+                 " (numeric values)\n"))
+
+
+;; suppress compiler warning
+;;(eval-when-compile (defun gnuplot-info-lookup-symbol (sym mode)))
+(define-widget 'gnuplot-gui-info-link 'info-link
+  "A link to an info file for the Gnuplot GUI."
+  :action '(lambda (widget &optional event)
+             (let ((gnuplot-info-display 'frame))
+               (if gnuplot-keywords-pending     ; <HW>
+                   (gnuplot-setup-info-look))
+               (gnuplot-info-lookup-symbol (widget-value widget)
+                                           'gnuplot-mode))))
+
+\f
+;;; just about done
+
+(provide 'gnuplot-gui)
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+
+;;; gnuplot-gui.el ends here
diff --git a/elpa/gnuplot-20230323.1400/gnuplot-pkg.el b/elpa/gnuplot-20230323.1400/gnuplot-pkg.el
new file mode 100644 (file)
index 0000000..d05b3ba
--- /dev/null
@@ -0,0 +1,14 @@
+(define-package "gnuplot" "20230323.1400" "Major-mode and interactive frontend for gnuplot"
+  '((emacs "25.1"))
+  :commit "f99effa21f85a4c0963fec6a38e9112a8157d27e" :authors
+  '(("Jon Oddie, Bruce Ravel, Phil Type"))
+  :maintainers
+  '(("Maxime Tréca <maximeNOSPAMgmail.com>, Daniel Mendler" . "mailNOSPAMdaniel-mendler.de"))
+  :maintainer
+  '("Maxime Tréca <maximeNOSPAMgmail.com>, Daniel Mendler" . "mailNOSPAMdaniel-mendler.de")
+  :keywords
+  '("data" "gnuplot" "plotting")
+  :url "https://github.com/emacs-gnuplot/gnuplot")
+;; Local Variables:
+;; no-byte-compile: t
+;; End:
diff --git a/elpa/gnuplot-20230323.1400/gnuplot.el b/elpa/gnuplot-20230323.1400/gnuplot.el
new file mode 100644 (file)
index 0000000..f83df93
--- /dev/null
@@ -0,0 +1,2096 @@
+;;; gnuplot.el --- Major-mode and interactive frontend for gnuplot -*- lexical-binding: t -*-
+
+;; Copyright (C) 1998, 2011 Phil Type and Bruce Ravel, 1999-2012 Bruce Ravel
+
+;; Author:           Jon Oddie, Bruce Ravel, Phil Type
+;; Maintainer:       Maxime Tréca <maximeNOSPAMgmail.com>, Daniel Mendler <mailNOSPAMdaniel-mendler.de>
+;; Created:          1998
+;; Version:          0.8.1
+;; Keywords:         data gnuplot plotting
+;; URL:              https://github.com/emacs-gnuplot/gnuplot
+;; Package-Requires: ((emacs "25.1"))
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This is a major mode for composing gnuplot scripts and displaying
+;; their results using gnuplot.  It supports features of recent Gnuplot
+;; versions (5.0 and up), but should also work fine with older
+;; versions.
+;;
+;; This version of gnuplot-mode has been tested mostly on GNU Emacs
+;; 25.
+;;
+;; Gnuplot-mode now includes context-sensitive support for keyword
+;; completion and, optionally, eldoc-mode help text.  See the
+;; commentary in gnuplot-context.el for more information.  If you
+;; don't find it useful, it can be turned off by customizing
+;; `gnuplot-context-sensitive-mode'.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Acknowledgements:
+;;    David Batty       <DB> (numerous corrections)
+;;    Laurent Bonnaud   <LB> (suggestions regarding font-lock rules)
+;;    Markus Dickebohm  <MD> (suggested `gnuplot-send-line-and-forward')
+;;    Stephen Eglan     <SE> (suggested the use of info-look,
+;;                            contributed a bug fix regarding shutting
+;;                            down the gnuplot process, improvement to
+;;                            `gnuplot-send-line-and-forward')
+;;    Robert Fenk       <RF> (suggested respecting continuation lines)
+;;    Michael Karbach   <MK> (suggested trimming the gnuplot process buffer)
+;;    Alex Chan Libchen <AL> (suggested font-lock for plotting words)
+;;    Kuang-Yu Liu      <KL> (pointed out buggy dependence on font-lock)
+;;    Hrvoje Niksic     <HN> (help with defcustom arguments for insertions)
+;;    Andreas Rechtsteiner <AR> (pointed out problem with C-c C-v)
+;;    Michael Sanders   <MS> (help with the info-look interface)
+;;    Jinwei Shen       <JS> (suggested functionality in comint buffer)
+;;    Michael M. Tung   <MT> (prompted me to add pm3d support)
+;;    Holger Wenzel     <HW> (suggested using `gnuplot-keywords-when')
+;;    Wolfgang Zocher   <WZ> (pointed out problem with gnuplot-mode + speedbar)
+;;    Jon Oddie         <jjo> (indentation, inline images, context mode)
+;;    Maxime F. Treca   <MFT> (package update, XEmacs deprecation)
+;;
+;;  and especially to Lars Hecking <LH> for including gnuplot-mode
+;;  with the gnuplot 3.7-beta distribution and for providing me with
+;;  installation materials
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'comint)
+(require 'custom)
+(require 'easymenu)
+(require 'info)
+(require 'info-look)
+
+(declare-function 'eldoc-add-command "eldoc")
+
+(defgroup gnuplot nil
+  "Gnuplot-mode for Emacs."
+  :prefix "gnuplot-"
+  :group 'processes
+  :group 'applications
+  :group 'local
+  :link '(emacs-library-link :tag "Lisp File" "gnuplot.el")
+  :link '(url-link :tag "Homepage"
+                   "https://github.com/emacs-gnuplot/gnuplot/")
+  :link '(custom-manual "(gnuplot)Top")
+  :link '(emacs-commentary-link :tag "Commentary" "gnuplot.el"))
+
+(defgroup gnuplot-insertions nil
+  "Insert commands into gnuplot-scripts from a pull-down menu."
+  :prefix "gnuplot-insertions-"
+  :group 'gnuplot)
+
+(defgroup gnuplot-hooks nil
+  "Hook variables used by `gnuplot-mode'."
+  :prefix "gnuplot-"
+  :group 'gnuplot)
+
+(defcustom gnuplot-mode-hook nil
+  "Hook run when `gnuplot-mode' is entered."
+  :group 'gnuplot-hooks
+  :type 'hook)
+
+(defcustom gnuplot-after-plot-hook (list #'gnuplot-trim-gnuplot-buffer)
+  "Hook run after gnuplot plots something.
+This is the last thing done by the functions for plotting a line, a
+region, a buffer, or a file."
+  :group 'gnuplot-hooks
+  :type 'hook)
+
+;; comint hook suggested by <DB>
+(defcustom gnuplot-comint-setup-hook nil
+  "Hook run after setting up the gnuplot buffer in comint mode.
+So the configuration can be customised by the user."
+  :group 'gnuplot-hooks
+  :type 'hook)
+
+(defcustom gnuplot-comint-mode-hook nil
+  "Hook run after setting up the gnuplot buffer in `gnuplot-comint-mode'.
+By default this runs the hook named `gnuplot-comint-setup-hook',
+for backward compatibility."
+  :group 'gnuplot-hooks
+  :type 'hook)
+
+(defvar-local gnuplot-recently-sent nil
+  "This is a record of the most recent kind of text sent to gnuplot.
+It takes as its value nil, `line', `region', `buffer', or `file'.  It is
+useful for functions included in `gnuplot-after-plot-hook'.")
+
+(defcustom gnuplot-program "gnuplot"
+  "The name of the gnuplot executable."
+  :group 'gnuplot
+  :type 'string)
+
+(defcustom gnuplot-program-args nil
+  "Whitespace-separated flags to pass to the gnuplot executable."
+  :group 'gnuplot
+  :type 'string)
+
+(defcustom gnuplot-process-name "gnuplot"
+  "Name given to the gnuplot buffer and process."
+  :group 'gnuplot
+  :type 'string)
+
+(defvar gnuplot-buffer nil
+  "The name of the buffer displaying the gnuplot process.")
+
+(defvar gnuplot-process nil
+  "Variable holding the process handle.")
+
+(defvar gnuplot-process-frame nil
+  "The frame for displaying the gnuplot process.
+This is used when `gnuplot-display-process' is equal to `frame'.")
+
+(defvar gnuplot-comint-recent-buffer nil
+  "The most recently plotted gnuplot script buffer.
+This is used by the function that plot from the comint buffer.  It is
+reset every time something is plotted from a script buffer.")
+
+(defcustom gnuplot-gnuplot-buffer "plot.gp"
+  "The name of the gnuplot scratch buffer opened by `gnuplot-make-buffer'."
+  :group 'gnuplot
+  :type 'string)
+
+(defcustom gnuplot-display-process 'window
+  "This controls how the gnuplot process buffer is displayed.
+The values are
+   \\='frame    display gnuplot process in a separate frame
+   \\='window   display gnuplot process in this frame but in another window
+   nil       `gnuplot-process' is in the current frame but not displayed"
+  :group 'gnuplot
+  :type '(radio (const :tag "Separate frame"  frame)
+                (const :tag "Separate window" window)
+                (const :tag "Not displayed"   nil)))
+
+(defcustom gnuplot-info-display 'window
+  "Determines how `gnuplot-info-lookup-symbol' displays the info file.
+The values are
+   \\='frame    display info file in a separate frame
+   \\='window   display info file in another window
+   nil       display info file in the current window"
+  :group 'gnuplot
+  :type '(radio (const :tag "Separate frame"  frame)
+                (const :tag "Separate window" window)
+                (const :tag "This window"     nil)))
+
+(defcustom gnuplot-echo-command-line-flag
+  (not (string-match "msvc" (emacs-version)))
+  "Non-nil means the gnuplot subprocess echoes any input.
+This sets the fall-back value of `comint-process-echoes'.
+If `gnuplot-mode' cannot figure out what version number of gnuplot
+this is, then the value of this variable will be used for
+`comint-process-echos'.  It seems that gnuplot 3.5 wants this to be
+nil and 3.7 wants it to be t.  If lines that you send to gnuplot from
+the `gnuplot-mode' buffer are not appearing at the gnuplot prompt in
+the process buffer, try toggling it.  Also see the document string for
+`comint-process-echos'.  If you change this, kill the gnuplot process
+and start it again."
+  :group 'gnuplot
+  :type 'boolean)
+
+(defcustom gnuplot-insertions-show-help-flag nil
+  "Non-nil means to display certain help messages automatically.
+These messages are shown after menu insertion of gnuplot commands."
+  :group 'gnuplot-insertions
+  :type 'boolean)
+
+(defcustom gnuplot-delay 0.01
+  "Amount of time to delay before sending a new line to gnuplot.
+This is needed so that the the line is not written in the gnuplot
+buffer in advance of its prompt.  Increase this number if the
+prompts and lines are displayed out of order."
+  :group 'gnuplot
+  :type 'number)
+
+(defcustom gnuplot-buffer-max-size 1000
+  "The maximum size in lines of the gnuplot process buffer.
+Each time text is written in the gnuplot process buffer, lines are
+trimmed from the beginning of the buffer so that the buffer is this
+many lines long.  The lines are deleted after the most recent lines
+were interpretted by gnuplot.  Setting to 0 turns off this feature."
+  :group 'gnuplot
+  :type 'integer)
+
+(defcustom gnuplot-quote-character "\'"
+  "Quotation character used for inserting quoted strings.
+Gnuplot can use single or double quotes.  If you prefer to have the
+filename insertion function never insert quotes for you, set this
+to the empty string."
+  :group 'gnuplot
+  :type '(radio (const :tag "double quote"  "\"")
+                (const :tag "single quote"  "\'")
+                (const :tag "none"          ""  )))
+(defcustom gnuplot-basic-offset 4
+  "Number of columns to indent lines inside a do- or if-else-block.
+
+This applies only to new-style do- and if-statements using
+braces.  Commands continued over a linebreak using a backslash
+are always indented to line up with the second word on the line
+beginning the continued command."
+  :group 'gnuplot
+  :type 'integer)
+
+(defvar gnuplot-info-frame nil)
+
+;; with info-look, there is no need to carry this list around -- it
+;; can be generated on the fly appropriate to the currently installed
+;; version of gnuplot.info
+(defvar gnuplot-keywords nil
+  "A list of keywords used in GNUPLOT.
+These are set by `gnuplot-set-keywords-list' from the values in
+`info-lookup-cache'.")
+(defvar gnuplot-keywords-pending t      ;; <HW>
+  "A boolean which gets toggled when the info file is probed.")
+(defcustom gnuplot-keywords-when 'deferred ;; 'immediately
+  "This variable controls when the info file is parsed.
+The choices are immediately upon starting `gnuplot-mode' or the first
+time that data is needed."
+  :group 'gnuplot
+  :type
+  '(radio (const :tag "Parse info file when gnuplot-mode starts"    immediately)
+          (const :tag "Parse info file the first time it is needed" deferred)))
+
+(defcustom gnuplot-use-context-sensitive-completion t
+  "Non-nil if `gnuplot-context-sensitive-mode' should be enabled by default.
+
+In context-sensitive mode, `gnuplot-mode' parses the current
+command line to provide smarter completion and documentation
+suggestions."
+  :group 'gnuplot
+  :type 'boolean
+  :set (lambda (sym value)
+         (set sym value)
+         (cond
+          (value
+           (add-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode nil nil)
+           (add-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode nil nil))
+          (t
+           (remove-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode)
+           (remove-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode)))
+         (dolist (buffer (buffer-list))
+           (with-current-buffer buffer
+             (when (and (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
+                        (fboundp 'gnuplot-context-sensitive-mode))
+               (gnuplot-context-sensitive-mode (if value 1 0))))))
+  :link '(emacs-commentary-link "gnuplot-context"))
+
+(defcustom gnuplot-eldoc-mode nil
+  "Non-nil if ElDoc mode should be enabled by default in Gnuplot buffers.
+ElDoc support requires `gnuplot-context-sensitive-mode' to be
+on."
+  :group 'gnuplot
+  :type 'boolean)
+
+(defcustom gnuplot-tab-completion nil
+  "Non-nil if TAB should perform completion in `gnuplot-mode' buffers.
+
+Setting this to non-nil sets the `tab-always-indent' variable to the
+symbol `complete' in `gnuplot-mode' buffers."
+  :group 'gnuplot
+  :type 'boolean)
+
+(defun gnuplot-set-display-mode (variable value &rest _args)
+  "Customize :set function for `gnuplot-inline-image-mode'.
+Set VARIABLE to VALUE.  ARGS is optional args."
+  (if (and (eq variable 'gnuplot-inline-image-mode)
+           value
+           (not (display-images-p)))
+      (progn
+        (message "Displaying images is not supported.")
+        (set variable nil))
+    (set variable value))
+  (gnuplot-setup-comint-for-image-mode))
+
+(defcustom gnuplot-inline-image-mode nil
+  "Whether to display Gnuplot output in Emacs.
+
+Possible values are nil, `inline' and `dedicated'.
+
+When this is nil, Gnuplot output is handled outside of Emacs in
+the normal way.  Otherwise, Emacs attempts to capture Gnuplot's
+output and display it in a buffer.  Output is inserted inline in
+the Gnuplot interaction buffer it this is `inline', in a
+separate dedicated buffer if it is `dedicated'.
+
+Use Customize to set this variable, or the commands
+`gnuplot-external-display-mode', `gnuplot-inline-display-mode',
+and `gnuplot-dedicated-display-mode'."
+  :group 'gnuplot
+  :type '(radio
+          (const :tag "No" nil)
+          (const :tag "In Comint buffer" inline)
+          (const :tag "In dedicated buffer" dedicated))
+  :initialize #'custom-initialize-default
+  :set #'gnuplot-set-display-mode)
+
+(defcustom gnuplot-image-format "png"
+  "Image format to use for displaying images within Emacs.
+
+This will be sent directly to Gnuplot as a command of the form
+\"set terminal <FORMAT>\".  Common values are \"png\" and
+\"svg\".
+
+This only has an effect when `gnuplot-inline-image-mode' is
+non-nil."
+  :group 'gnuplot
+  :type 'string
+  :initialize #'custom-initialize-default
+  :set #'gnuplot-set-display-mode)
+
+(defgroup gnuplot-faces nil
+  "Text faces used by `gnuplot-mode'."
+  :prefix "gnuplot-"
+  :group 'gnuplot)
+
+(defface gnuplot-prompt-face '((((class color))
+                                (:foreground "firebrick"))
+                               (t
+                                (:bold t :underline t)))
+  "Face used for the prompt in the gnuplot process buffer."
+  :group 'gnuplot-faces)
+
+\f
+;;; --- key bindings and menus
+
+(defvar gnuplot-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-b"    #'gnuplot-send-buffer-to-gnuplot)
+    (define-key map "\C-c\C-c"    #'comment-region) ; <RF>
+    (define-key map "\C-c\C-o"    'gnuplot-gui-set-options-and-insert)
+    (define-key map "\C-c\C-e"    #'gnuplot-show-gnuplot-buffer)
+    (define-key map "\C-c\C-f"    #'gnuplot-send-file-to-gnuplot)
+    (define-key map "\C-c\C-d"    #'gnuplot-info-lookup-symbol)
+    (define-key map "\C-c\C-i"    #'gnuplot-insert-filename)
+    (define-key map "\C-c\C-j"    #'gnuplot-forward-script-line)
+    (define-key map "\C-c\C-k"    #'gnuplot-kill-gnuplot-buffer)
+    (define-key map "\C-c\C-l"    #'gnuplot-send-line-to-gnuplot)
+    (define-key map "\C-c\C-n"    #'gnuplot-negate-option)
+    (define-key map "\C-c\C-r"    #'gnuplot-send-region-to-gnuplot)
+    (define-key map (kbd "C-M-x") #'gnuplot-send-line-to-gnuplot)
+    (define-key map "\C-c\C-v"    #'gnuplot-send-line-and-forward)
+    (define-key map "\C-c\C-z"    #'gnuplot-customize)
+    (define-key map "\C-i"        #'indent-for-tab-command)
+    (define-key map "\C-m"        #'newline-and-indent)
+    (define-key map (kbd "}")     #'gnuplot-electric-insert)
+    (define-key map "\M-\r"       #'completion-at-point)
+    (define-key map "\M-\t"       #'completion-at-point)
+    (define-key map [S-mouse-2]   'gnuplot-gui-mouse-set)
+
+    map))
+
+(defvar gnuplot-mode-menu nil)
+
+(defvar gnuplot-display-options-menu
+  (cl-flet ((make-image-setter (type)
+                            `[,(concat (upcase type) " images")
+                              (lambda () (interactive) (gnuplot-set-image-format ,type))
+                              :style toggle
+                              :selected (eq gnuplot-image-format ,type)]))
+    `("Display plot output"
+      ["Externally" gnuplot-external-display-mode
+       :style toggle
+       :selected (null gnuplot-inline-image-mode)]
+      ["In Comint buffer" gnuplot-inline-display-mode
+       :active (display-images-p)
+       :style toggle
+       :selected (eq gnuplot-inline-image-mode 'comint)]
+      ["In dedicated buffer" gnuplot-dedicated-display-mode
+       :style toggle
+       :selected (eq gnuplot-inline-image-mode 'dedicated)]
+      "---"
+      ,@(mapcar #'make-image-setter (list "png" "jpeg" "svg"))
+      ["Other image type..." gnuplot-set-image-format])))
+
+(defvar gnuplot-menu
+  `("Gnuplot"
+    ["Send line to gnuplot"             gnuplot-send-line-to-gnuplot   t]
+    ["Send line & move forward"         gnuplot-send-line-and-forward (not (eobp))]
+    ["Send region to gnuplot"           gnuplot-send-region-to-gnuplot
+     (gnuplot-mark-active)]
+    ["Send buffer to gnuplot"           gnuplot-send-buffer-to-gnuplot t]
+    ["Send file to gnuplot"             gnuplot-send-file-to-gnuplot t]
+    "---"
+    ,gnuplot-display-options-menu
+    ["Contextual completion and help"   gnuplot-context-sensitive-mode
+     :style toggle
+     :selected gnuplot-context-sensitive-mode]
+    ["Echo area help (eldoc-mode)" eldoc-mode
+     :active gnuplot-context-sensitive-mode
+     :style toggle
+     :selected eldoc-mode]
+    "---"
+    ["Insert filename at point"         gnuplot-insert-filename t]
+    ["Negate set option"                gnuplot-negate-option t]
+    ["Keyword help"                     gnuplot-info-lookup-symbol
+     (or gnuplot-keywords gnuplot-keywords-pending)]
+    ["Quick help for thing at point"    gnuplot-help-function
+     gnuplot-context-sensitive-mode]
+    ["Info documentation on thing at point"
+     gnuplot-info-at-point
+     gnuplot-context-sensitive-mode]
+    ["Show gnuplot process buffer"      gnuplot-show-gnuplot-buffer t]
+    ["Set arguments at point"           gnuplot-gui-set-options-and-insert t]
+    ["Swap plot/splot/fit lists in GUI" gnuplot-gui-swap-simple-complete t]
+    "---"
+    ["Customize gnuplot"                gnuplot-customize t]
+    "---"
+    ["Kill gnuplot"                     gnuplot-kill-gnuplot-buffer t])
+  "Menu for `gnuplot-mode'.")
+
+
+\f
+;;; --- insertions variables and menus
+
+(defvar gnuplot-mode-insertions-menu nil)
+(defvar gnuplot-insertions-menu nil
+  "Menu for insertions in `gnuplot-mode'.
+
+The insertions menu is composed of several sub-menus.  The variables
+describing the sub-menus are:
+  `gnuplot-insertions-adornments'
+  `gnuplot-insertions-plot-options'
+  `gnuplot-insertions-terminal'
+  `gnuplot-insertions-x-axis'
+  `gnuplot-insertions-y-axis'
+  `gnuplot-insertions-z-axis'
+  `gnuplot-insertions-x2-axis'
+  `gnuplot-insertions-y2-axis'
+  `gnuplot-insertions-parametric-plots'
+  `gnuplot-insertions-polar-plots'
+  `gnuplot-insertions-surface-plots'
+These variables can be customized by the user.  For example, there are
+many terminal types which are not in the terminal submenu but which
+may be compiled into your copy of gnuplot.
+
+Each of these variables is a list whose first element is a string and
+all the rest are vectors as described in the document string for
+`easy-menu-define'.  The callback used throughout these menus is
+`gnuplot-insert' which inserts the appropriate set expression and,
+optionally, looks up that item in the gnuplot info file.
+
+The easiest way to customize the submenus is to use the custom
+package.  Just type \\[gnuplot-customize] and follow your nose.
+
+You can also add new items to any of these sub-menus by adding to the
+`with-eval-after-load' blocks in your .emacs file.  Here is an example of
+adding the \"regis\" terminal type to the terminal sub-menu:
+
+ (with-eval-after-load 'gnuplot
+      (setq gnuplot-insertions-terminal
+            (append gnuplot-insertions-terminal
+                    (list
+                     [\"regis\"
+                      (gnuplot-insert \"set terminal regis\")
+                       t]))))")
+
+(defvar gnuplot-insertions-top ()
+  "Top part of insertions menu.
+See the document string for `gnuplot-insertions-menu'")
+
+(defcustom gnuplot-insertions-menu-flag t
+  "Non-nil means to place the insertion menu in the menubar.
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type 'boolean)
+
+(defcustom gnuplot-insertions-adornments ; this is icky...
+  '("adornments"
+    ["arrow"       (gnuplot-insert "set arrow ")          t]
+    ["bar"         (gnuplot-insert "set bar")             t]
+    ["border"      (gnuplot-insert "set border")          t]
+    ["boxwidth"    (gnuplot-insert "set boxwidth ")       t]
+    ["format"      (gnuplot-insert "set format ")         t]
+    ["grid"        (gnuplot-insert "set grid")            t]
+    ["key"         (gnuplot-insert "set key ")            t]
+    ["label"       (gnuplot-insert "set label ")          t]
+    ["pointsize"   (gnuplot-insert "set pointsize ")      t]
+    ["samples"     (gnuplot-insert "set samples ")        t]
+    ["size"        (gnuplot-insert "set size ")           t]
+    ["style"       (gnuplot-insert "set style ")          t]
+    ["tics"        (gnuplot-insert "set tics ")           t]
+    ["timefmt"     (gnuplot-insert "set timefmt ")        t]
+    ["timestamp"   (gnuplot-insert "set timestamp ")      t]
+    ["title"       (gnuplot-insert "set title ")          t]
+    ["zeroaxis"    (gnuplot-insert "set zeroaxis")        t])
+
+  "Adornments submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+
+(defcustom gnuplot-insertions-plot-options
+  '("plot options"
+    ["autoscale"  (gnuplot-insert "set autoscale ")          t]
+    ["clip"       (gnuplot-insert "set clip ")               t]
+    ["encoding"   (gnuplot-insert "set encoding ")           t]
+    ["locale"     (gnuplot-insert "set locale ")             t]
+    ["logscale"   (gnuplot-insert "set logscale ")           t]
+    ["multiplot"  (gnuplot-insert "set multiplot")           t]
+    ["missing"    (gnuplot-insert "set missing \"\"")        t]
+    ["palette"    (gnuplot-insert "set palette ")            t]         ; <MT>
+    ["pm3d"       (gnuplot-insert "set pm3d ")               t]
+    ["offsets"    (gnuplot-insert "set offsets ")            t]
+    ["output"     (gnuplot-insert "set output ")             t]
+    ["zero"       (gnuplot-insert "set zero ")               t])
+  "Plot options submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-terminal
+  '("terminal"
+    ["eepic"      (gnuplot-insert "set terminal eepic")      t]
+    ["fig"        (gnuplot-insert "set terminal fig")        t]
+    ["gpic"       (gnuplot-insert "set terminal gpic")       t]
+    ["latex"      (gnuplot-insert "set terminal latex")      t]
+    ["linux"      (gnuplot-insert "set terminal linux")      t]
+    ["pbm"        (gnuplot-insert "set terminal pbm")        t]
+    ["png"        (gnuplot-insert "set terminal png")        t]
+    ["postscript" (gnuplot-insert "set terminal postscript") t]
+    ["pslatex"    (gnuplot-insert "set terminal pslatex")    t]
+    ["table"      (gnuplot-insert "set terminal table")      t]
+    ["tek40xx"    (gnuplot-insert "set terminal tek40xx")    t]
+    ["tkcanvas"   (gnuplot-insert "set terminal tkcanvas")   t]
+    ["tpic"       (gnuplot-insert "set terminal tpic")       t]
+    ["vgagl"      (gnuplot-insert "set terminal vgagl")      t]         ; for pm3d patch
+    ["vttek"      (gnuplot-insert "set terminal vttek")      t]
+    ["x11"        (gnuplot-insert "set terminal x11")        t])
+  "Terminal submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-x-axis
+  '("x-axis"
+    ["xdata"      (gnuplot-insert "set xdata ")              t]
+    ["xlabel"     (gnuplot-insert "set xlabel ")             t]
+    ["xrange"     (gnuplot-insert "set xrange [:]")          t]
+    ["xtics"      (gnuplot-insert "set xtics ")              t]
+    ["mxtics"     (gnuplot-insert "set mxtics ")             t]
+    ["xzeroaxis"  (gnuplot-insert "set xzeroaxis ")          t]
+    ["xdtics"     (gnuplot-insert "set xdtics ")             t]
+    ["xmtics"     (gnuplot-insert "set xmtics ")             t])
+  "X-axis submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-x2-axis
+  '("x2-axis"
+    ["x2data"     (gnuplot-insert "set xdata ")              t]
+    ["x2label"    (gnuplot-insert "set xlabel ")             t]
+    ["x2range"    (gnuplot-insert "set xrange [:]")          t]
+    ["x2tics"     (gnuplot-insert "set xtics ")              t]
+    ["mx2tics"    (gnuplot-insert "set mxtics ")             t]
+    ["x2zeroaxis" (gnuplot-insert "set xzeroaxis ")          t]
+    ["x2dtics"    (gnuplot-insert "set xdtics ")             t]
+    ["x2mtics"    (gnuplot-insert "set xmtics ")             t])
+  "X2-axis submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-y-axis
+  '("y-axis"
+    ["ydata"      (gnuplot-insert "set ydata ")              t]
+    ["ylabel"     (gnuplot-insert "set ylabel ")             t]
+    ["ymtics"     (gnuplot-insert "set ymtics ")             t]
+    ["yrange"     (gnuplot-insert "set yrange [:]")          t]
+    ["ytics"      (gnuplot-insert "set ytics ")              t]
+    ["yzeroaxis"  (gnuplot-insert "set yzeroaxis ")          t]
+    ["ydtics"     (gnuplot-insert "set ydtics ")             t]
+    ["mytics"     (gnuplot-insert "set mytics ")             t])
+  "Y-axis submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+(defcustom gnuplot-insertions-y2-axis
+  '("y2-axis"
+    ["y2data"     (gnuplot-insert "set ydata ")              t]
+    ["y2label"    (gnuplot-insert "set ylabel ")             t]
+    ["y2range"    (gnuplot-insert "set yrange [:]")          t]
+    ["y2tics"     (gnuplot-insert "set ytics ")              t]
+    ["my2tics"    (gnuplot-insert "set mytics ")             t]
+    ["y2zeroaxis"  (gnuplot-insert "set yzeroaxis ")         t]
+    ["y2mtics"    (gnuplot-insert "set ymtics ")             t]
+    ["y2dtics"    (gnuplot-insert "set ydtics ")             t])
+  "Y2-axis submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+
+(defcustom gnuplot-insertions-z-axis
+  '("z-axis"
+    ["zdata"      (gnuplot-insert "set zdata ")              t]
+    ["zlabel"     (gnuplot-insert "set zlabel ")             t]
+    ["zrange"     (gnuplot-insert "set zrange [:]")          t]
+    ["ztics"      (gnuplot-insert "set ztics ")              t]
+    ["mztics"     (gnuplot-insert "set mztics ")             t]
+    ["zdtics"     (gnuplot-insert "set zdtics ")             t]
+    ["zmtics"     (gnuplot-insert "set zmtics ")             t])
+  "Z-axis submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-parametric-plots
+  '("parametric plots"
+    ["parametric" (gnuplot-insert "set parametric")          t]
+    ["isosamples" (gnuplot-insert "set isosamples ")         t]
+    ["dummy"      (gnuplot-insert "set dummy ")              t]
+    ["trange"     (gnuplot-insert "set trange [:]")          t]
+    ["urange"     (gnuplot-insert "set urange [:]")          t]
+    ["vrange"     (gnuplot-insert "set vrange [:]")          t])
+  "Parametric plots submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-polar-plots
+  '("polar plots"
+    ["polar"      (gnuplot-insert "set polar")               t]
+    ["angles"     (gnuplot-insert "set angles ")             t]
+    ["rrange"     (gnuplot-insert "set rrange [:]")          t])
+  "Polar plots submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defcustom gnuplot-insertions-surface-plots
+  '("surface plots"
+    ["clabel"     (gnuplot-insert "set clabel ")             t]
+    ["cntrparam"  (gnuplot-insert "set cntrparam ")          t]
+    ["contour"    (gnuplot-insert "set contour")             t]
+    ["dgrid3d"    (gnuplot-insert "set dgrid3d ")            t]
+    ["hidden3d"   (gnuplot-insert "set hidden3d ")           t]
+    ["mapping"    (gnuplot-insert "set mapping ")            t]
+    ["surface"    (gnuplot-insert "set surface ")            t]
+    ["view"       (gnuplot-insert "set view ")               t])
+  "Surface plots submenu in the insertions menu.
+See the document string for `gnuplot-insertions-menu'
+Changing this will not effect a change in any currently existing
+`gnuplot-mode' buffer.  You will see the change the next time you
+create a `gnuplot-mode' buffer."
+  :group 'gnuplot-insertions
+  :type '(list (string :tag "Title")
+               (repeat :inline t
+                       (vector (string   :tag "Name")
+                               (function :tag "Callback")
+                               (boolean  :tag "Enabled" t)))))
+
+
+(defvar gnuplot-insertions-bottom
+  '("---"
+    ["Display of info with insertion" gnuplot-toggle-info-display
+     :style toggle :selected gnuplot-insertions-show-help-flag]
+    ["Display GUI popup with insertion" gnuplot-gui-toggle-popup
+     :active t
+     :style toggle :selected gnuplot-gui-popup-flag])
+  "Bottom part of the insertions menu.
+This part contains the toggle buttons for displaying info or
+opening an argument-setting popup.")
+
+(defun gnuplot-setup-menubar ()
+  "Initial setup of gnuplot and insertions menus."
+  (if gnuplot-insertions-menu-flag      ; set up insertions menu
+      (progn
+        (setq gnuplot-insertions-top
+              '("insert set expression" "---"))
+        (setq gnuplot-insertions-menu
+              (append (list "Insertions")
+                      gnuplot-insertions-top
+                      (list gnuplot-insertions-adornments)
+                      (list gnuplot-insertions-plot-options)
+                      (list gnuplot-insertions-terminal)
+                      (list gnuplot-insertions-x-axis)
+                      (list gnuplot-insertions-y-axis)
+                      (list gnuplot-insertions-z-axis)
+                      (list gnuplot-insertions-x2-axis)
+                      (list gnuplot-insertions-y2-axis)
+                      (list gnuplot-insertions-parametric-plots)
+                      (list gnuplot-insertions-polar-plots)
+                      (list gnuplot-insertions-surface-plots)
+                      gnuplot-insertions-bottom))
+        (easy-menu-define gnuplot-mode-insertions-menu gnuplot-mode-map
+          "Insertions menu used in Gnuplot-mode"
+          gnuplot-insertions-menu)))
+  (easy-menu-define                     ; set up gnuplot menu
+    gnuplot-mode-menu gnuplot-mode-map "Menu used in gnuplot-mode"
+    gnuplot-menu))
+
+(defun gnuplot-mark-active ()
+  "Return non-nil if the mark is active and it is not equal to point."
+  (condition-case nil
+      (and (mark) (/= (mark) (point)))
+    (error nil)))
+
+\f
+;;; --- syntax colorization, syntax table
+
+(defvar gnuplot-mode-syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?* "." table)
+    (modify-syntax-entry ?+ "." table)
+    (modify-syntax-entry ?- "." table)
+    (modify-syntax-entry ?/ "." table)
+    (modify-syntax-entry ?% "." table)
+    (modify-syntax-entry ?= "." table)
+    (modify-syntax-entry ?: "." table)
+    (modify-syntax-entry ?& "." table )
+    (modify-syntax-entry ?^ "." table )
+    (modify-syntax-entry ?| "." table )
+    (modify-syntax-entry ?& "." table )
+    (modify-syntax-entry ?? "." table )
+    (modify-syntax-entry ?~ "." table )
+    (modify-syntax-entry ?_ "w" table )
+    (modify-syntax-entry ?\" "." table)
+    (modify-syntax-entry ?\' "." table)
+    (modify-syntax-entry ?` "." table)
+    (modify-syntax-entry ?\\ "." table)
+
+    table)
+
+  "Syntax table in use in `gnuplot-mode' buffers.
+This is the same as the standard syntax table except that ` and _
+are word characters, and math operators are punctuation
+characters.")
+
+;; Macro to generate efficient regexps for keyword matching
+;;
+;; These regular expressions treat the gnuplot vocabulary as complete
+;; words.  Although gnuplot will recognise unique abbreviations, these
+;; regular expressions will not.
+(defmacro gnuplot-make-regexp (list)
+  "Macro to generate efficient regexps for keyword matching from LIST."
+  `(regexp-opt ,list 'words))
+
+;; Lists of gnuplot keywords for syntax coloring etc.
+(defvar gnuplot-keywords-builtin-functions
+  '("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" "EllipticPi" "EllipticE" "EllipticK" "words" "word" "value"
+    "timecolumn" "substr" "strstrt" "strptime" "strlen" "stringcolumn"
+    "strftime" "sprintf" "lambertw" "gprintf" "exists" "defined" "columnhead")
+
+  "List of GNUPLOT built-in functions, as strings.
+
+These are highlighted using `font-lock-function-name-face'.")
+
+(defvar gnuplot-keywords-plotting
+  '("axes" "every" "index" "lw" "lt" "ls" "linestyle" "linetype" "linewidth"
+    "notitle" "pt" "ps" "pointsize" "pointtype" "smooth" "thru" "title" "using"
+    "with" "noautoscale" "volatile" "matrix" "nonuniform" "binary" "fillstyle"
+    "linecolor" "pointinterval" "nosurface" "nocontours" "nohidden3d")
+  "List of GNUPLOT keywords associated with plotting, as strings.
+
+These are highlighted using `font-lock-type-face'.
+This list does not include plotting styles -- for that, see
+`gnuplot-keywords-plotting-styles'")
+
+(defvar gnuplot-keywords-plotting-styles
+  '("boxerrorbars" "boxes" "boxxyerrorbars" "candlesticks" "dots" "errorbars"
+    "financebars" "fsteps" "histeps" "impulses" "lines" "linespoints" "points"
+    "steps" "vector" "xerrorbars" "xyerrorbars" "yerrorbars" "vectors"
+    "filledcurves" "labels" "rgbalpha" "rgbimage" "image" "circles" "pm3d"
+    "histograms" "xyerrorlines" "xerrorlines" "errorlines" "yerrorlines")
+
+  "List of GNUPLOT plotting styles, as strings.
+
+These are highlighted using `font-lock-function-name-face'.")
+
+(defvar gnuplot-keywords-misc
+  '("bind" "cd" "clear" "exit" "fit" "help" "history" "load" "pause" "print"
+    "pwd" "quit" "replot" "save" "set" "show" "unset" "if" "else" "do" "update"
+    "undefine" "test" "system" "raise" "lower" "eval" "shell" "reset" "reread"
+    "refresh" "call")
+  "List of GNUPLOT miscellaneous commands, as strings.
+
+These are highlighted using `font-lock-constant-face'.")
+
+(defvar gnuplot-keywords-negatable-options
+  '("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")
+
+  "List of gnuplot options which can be negated using `gnuplot-negate-option'.")
+
+(defvar gnuplot-negatable-options-regexp
+  (gnuplot-make-regexp gnuplot-keywords-negatable-options))
+
+;; Set up colorization for gnuplot.
+(defvar gnuplot-font-lock-keywords
+  (list
+   ;; stuff in brackets, sugg. by <LB>
+   '("\\[\\([^]]+\\)\\]" 1 font-lock-constant-face)
+
+   ;; variable/function definitions
+   '("\\(\\(\\sw\\|\\s_\\)+\\s-*\\((\\s-*\\(\\sw\\|\\s_\\)*\\s-*\\(,\\s-*\\sw*\\)*\\s-*)\\)?\\s-*=\\)[^=]"
+     1 font-lock-variable-name-face)
+
+   ;; built-in function names
+   (cons (gnuplot-make-regexp gnuplot-keywords-builtin-functions)
+         font-lock-function-name-face)
+
+   ;; reserved words associated with plotting <AL>
+   (cons (gnuplot-make-regexp gnuplot-keywords-plotting)
+         font-lock-type-face)
+   (cons (gnuplot-make-regexp gnuplot-keywords-plotting-styles)
+         font-lock-function-name-face)
+
+   ;; (s)plot -- also thing (s)plotted
+   '("\\<s?plot\\>" . font-lock-keyword-face)
+   ;; '("\\<s?plot\\s-+\\([^'\" ]+\\)[) \n,\\\\]"
+   ;;   1 font-lock-variable-name-face)
+
+   ;; other common commands
+   (cons (gnuplot-make-regexp gnuplot-keywords-misc)
+         font-lock-constant-face)
+   (cons "!.*$" font-lock-constant-face))) ; what is this for? jjo
+
+(defvar gnuplot-font-lock-defaults
+  '(gnuplot-font-lock-keywords
+    nil                           ; Use syntactic fontification
+    t                             ; Use case folding
+    nil                           ; No extra syntax
+    ;; calls `gnuplot-beginning-of-continuation'
+    ;; to find a safe place to begin syntactic highlighting
+    beginning-of-defun))
+
+;; Some corner cases in Gnuplot's comment and string syntax are
+;; difficult to handle accurately using Emacs's built-in syntax tables
+;; and parser:
+;;
+;; - strings can continue over several lines, but only by using a
+;;   backslash to escape the newline
+;;
+;; - double-quoted strings can contain escaped quotes, \", and escaped
+;;   backslashes, \\; but in single-quoted strings the quote is
+;;   escaped by doubling it, '', and backslash is only special at
+;;   end-of-line
+;;
+;; - either type of string can end at newline without needing a
+;; - closing delimiter
+;;
+;; - comments continue over continuation lines
+;;
+;; The following syntax-propertize rules should accurately mark string
+;; and comment boundaries using the "generic string fence" and
+;; "generic comment fence" syntax properties.
+(defalias 'gnuplot-syntax-propertize
+  (syntax-propertize-rules
+   ;; Double quoted strings
+   ((rx
+     (group "\"")
+     (* (or (seq "\\" anything)
+            (not (any "\"" "\n"))))
+     (group (or "\"" "\n" buffer-end)))
+    (1 "|") (2 "|"))
+
+   ;; Single quoted strings
+   ((rx
+     (group "'")
+     (* (or (seq "\\" "\n")
+            "''"
+            (not (any "'" "\n"))))
+     (group (or "'" "\n" buffer-end)))
+    (1 "|") (2 "|"))
+
+   ;; Comments
+   ((rx
+     (group "#")
+     (* (or (seq "\\" "\n")
+            any))
+     (or (group "\n") buffer-end))
+    (1 "!") (2 "!"))))
+
+(defun gnuplot-syntax-propertize-extend-region (start end)
+  "Expand the region to `syntax-propertize' for strings and comments.
+
+Region range is START to END.
+Ensures that the region being searched begins and ends outside of
+any lines continued with a backslash.
+
+This function is added to `syntax-propertize-extend-region-functions'
+in `gnuplot-mode' buffers."
+  (let ((continuation-start
+         (min start
+              (gnuplot-point-at-beginning-of-continuation start)))
+        (continuation-end
+         (max end
+              (gnuplot-point-at-end-of-continuation end))))
+    (if (and (= continuation-start start)
+             (= continuation-end end))
+        nil
+      (cons continuation-start continuation-end))))
+
+;; Parsing utilities to tell if we are inside a string or comment
+(defun gnuplot-in-string (&optional where)
+  "Return non-nil if the text at WHERE is within a string.
+
+If WHERE is omitted, defaults to text at point.
+This is a simple wrapper for `syntax-ppss'."
+  (save-excursion
+    (let ((parse-state (syntax-ppss where)))
+      (nth 3 parse-state))))
+
+(defun gnuplot-in-comment (&optional where)
+  "Return non-nil if the text at WHERE is within a comment.
+
+If WHERE is omitted, defaults to text at point.
+This is a simple wrapper for `syntax-ppss'."
+  (save-excursion
+    (let ((parse-state (syntax-ppss where)))
+      (nth 4 parse-state))))
+
+(defun gnuplot-in-string-or-comment (&optional where)
+  "Return non-nil if the text at WHERE is within a string or comment.
+
+If WHERE is omitted, defaults to text at point.
+This is a simple wrapper for `syntax-ppss'."
+
+  (save-excursion
+    (let ((parse-state (syntax-ppss where)))
+      (or (nth 3 parse-state)
+          (nth 4 parse-state)))))
+
+\f
+;;; --- functions for sending commands to gnuplot
+
+(defun gnuplot-split-string (string)
+  "Break STRING at each carriage return, returning a list of lines."
+  (let ((list ()) (line "") (index 0))
+    (while (< index (length string))
+      (if (char-equal (elt string index) ?\n)
+          (setq list (append list (list line))
+                line "")
+        (setq line (concat line (char-to-string (elt string index)))))
+      (setq index (1+ index)))
+    list))
+
+;; -- the calls to `sleep-for' are to allow enough time for gnuplot
+;;    to write to the buffer before the next line is inserted
+;; -- note that the input string is split into lines and each line is
+;;    sent to gnuplot individually.  this is a bit slow, but it puts
+;;    each line on the comint history.
+(defun gnuplot-send-string-to-gnuplot (string text)
+  "Sends STRING to the gnuplot program.
+If no gnuplot process exists, a new one is created.  TEXT indicates
+the type of text being sent to gnuplot and is typically one of
+nil, `line', `region', `buffer', or `file'.  TEXT may be useful for
+functions in `gnuplot-after-plot-hook'.  `gnuplot-after-plot-hook' is
+called by this function after all of STRING is sent to gnuplot."
+  (gnuplot-make-gnuplot-buffer)         ; make sure a gnuplot buffer exists
+  (setq gnuplot-comint-recent-buffer (current-buffer))
+
+  ;; Create a gnuplot frame if needed
+  (if (equal gnuplot-display-process 'frame)
+      (or (and gnuplot-process-frame
+               (frame-live-p gnuplot-process-frame))
+          (let ((frame (selected-frame)))
+            (setq gnuplot-process-frame (make-frame))
+            (select-frame gnuplot-process-frame)
+            (switch-to-buffer gnuplot-buffer)
+            (delete-other-windows)
+            (select-frame frame))))
+
+  (let ((list (gnuplot-split-string string)))
+    (with-current-buffer (get-buffer gnuplot-buffer)
+      (goto-char (point-max))
+      ;; bruce asks: what is this next line for?
+      (set-marker (process-mark gnuplot-process) (point-marker))
+      (sleep-for (* 20 gnuplot-delay))
+      (while list
+        (insert (car list))
+        (comint-send-input)
+        (sleep-for gnuplot-delay)
+        (setq list (cdr list))
+        (goto-char (point-max))))
+
+    (cond ((equal gnuplot-display-process 'window)
+           (gnuplot-display-and-recenter-gnuplot-buffer))
+          ((equal gnuplot-display-process 'frame)
+           ;;(raise-frame gnuplot-process-frame)
+           (with-selected-frame gnuplot-process-frame
+             (gnuplot-display-and-recenter-gnuplot-buffer))))
+
+    (setq gnuplot-recently-sent text)
+    (run-hooks 'gnuplot-after-plot-hook)))
+
+(defun gnuplot-display-and-recenter-gnuplot-buffer ()
+  "Make sure the gnuplot comint buffer is displayed.
+Move point to the end if necessary."
+  (save-selected-window
+    (select-window (display-buffer (get-buffer gnuplot-buffer)))
+    (goto-char (point-max))
+    (unless (pos-visible-in-window-p (point) (selected-window)) (recenter 5))))
+
+(defun gnuplot-send-region-to-gnuplot (&optional begin end text)
+  "Sends a selected region to the gnuplot program.
+If BEGIN and END are not specified, point and mark are used.  TEXT
+indicates the type of text being sent to gnuplot.  This will be
+`region' unless explicitly set by a function calling this one.  Other
+typical values are of nil, `line', `buffer', or `file'.  TEXT may be
+useful for function in `gnuplot-after-plot-hook'."
+  (interactive "r")
+  (let (string (txt (or text 'region)))
+    (cond ((equal major-mode 'gnuplot-mode)
+           (setq string (buffer-substring-no-properties begin end))
+           (if (string= (substring string -1) "\n") ()
+             (setq string (concat string "\n")))
+           (gnuplot-send-string-to-gnuplot string txt))
+          (t
+           (message (concat "You can only send regions from "
+                            "gnuplot-mode buffers to gnuplot."))))))
+
+(defun gnuplot-send-line-to-gnuplot ()
+  "Sends the current line to the gnuplot program.
+Respects continuation lines.
+This sets `gnuplot-recently-sent' to `line'."
+  (interactive)
+  (cond ((equal major-mode 'gnuplot-mode)
+         (let (start end)
+           (save-excursion
+             ;; go to start of continued command, or beginning of line
+             ;; if this is not a continuation of a previous line <JJO>
+             (gnuplot-beginning-of-continuation)
+             (setq start (point))
+             (end-of-line)
+             (while (save-excursion
+                      (backward-char)
+                      (looking-at "\\\\"))      ; go to end of last continuation line
+               (end-of-line 2))
+             (beginning-of-line 2)
+             (setq end (point)))
+           (if (not (string-match "\\`\\s-*\\'"
+                                  (buffer-substring-no-properties start end)))
+               (gnuplot-send-region-to-gnuplot start end 'line))
+           end))
+        (t
+         (message "You can only send lines in gnuplot-mode buffers to gnuplot.")
+         nil)))
+
+;; I chose a very easy to type but slightly non-mnemonic key-binding
+;; for this (C-c C-v).  It seems like the kind of thing one would want
+;; to do repeatedly without incurring RSI. 8^)
+(defun gnuplot-send-line-and-forward (&optional num)
+  "Call `gnuplot-send-line-to-gnuplot' and move forward 1 line.
+You can use a numeric prefix to send more than one line.  Blank lines and
+lines with only comments are skipped when moving forward.
+NUM is optional arg."
+  (interactive "p")
+  (let (end)
+    (while (> num 0)
+      (setq end (gnuplot-send-line-to-gnuplot))
+      (goto-char end)
+      (backward-char 1)                         ; <AR>
+      (gnuplot-forward-script-line 1)
+      (setq num (1- num)))))
+
+(defun gnuplot-send-line-and-newline ()
+  "Call `gnuplot-send-line-to-gnuplot' and insert a new line."
+  (interactive)
+  (end-of-line)
+  (gnuplot-send-line-to-gnuplot)
+  (insert "\n"))
+
+(defun gnuplot-forward-script-line (&optional num) ; <SE>
+  "Move forward my NUM script lines.
+Blank lines and commented lines are not included in the NUM count."
+  (interactive "p")
+  (while (> num 0)
+    (and (not (eobp)) (forward-line 1))
+    (while (and (not (eobp))
+                (or (looking-at "^\\s-*$")
+                    (looking-at "^\\s-*#")))
+      (forward-line 1))
+    (setq num (1- num))))
+
+(defun gnuplot-send-buffer-to-gnuplot ()
+  "Sends the entire buffer to the gnuplot program.
+This sets `gnuplot-recently-sent' to `buffer'."
+  (interactive)
+  (if (equal major-mode 'gnuplot-mode)
+      (gnuplot-send-region-to-gnuplot (point-min) (point-max) 'buffer)
+    (message "You can only send gnuplot-mode buffers to gnuplot.")))
+
+(defun gnuplot-send-file-to-gnuplot ()
+  "Sends a selected file to the gnuplot program using the \"load\" command.
+This sets `gnuplot-recently-sent' to `file'."
+  (interactive)
+  (let ((string (read-file-name "Name of file to send to gnuplot > " nil nil t)))
+    (setq string (concat "load '" (expand-file-name string) "'\n"))
+    (message "%S" string)
+    (gnuplot-make-gnuplot-buffer)       ; make sure a gnuplot buffer exists
+    (gnuplot-send-string-to-gnuplot string 'file)))
+
+;; suggested by <JS>
+(defun gnuplot-plot-from-comint ()
+  "Send the contents of a script to gnuplot from the process buffer.
+This inserts the contents of the most recently used gnuplot script
+into the process buffer and sends those lines to gnuplot.  It does
+this by copying the script line by line."
+  (interactive)
+  (if (not (buffer-live-p gnuplot-comint-recent-buffer))
+      (message "Script buffer has been deleted.")
+    (let (string list (buffer (current-buffer)))
+      (set-buffer gnuplot-comint-recent-buffer)
+      (setq string (buffer-substring-no-properties (point-min) (point-max))
+            string (concat string "\n")
+            list   (gnuplot-split-string string))
+      (set-buffer buffer)
+      (while list
+        (insert (car list))
+        (comint-send-input)
+        (sleep-for gnuplot-delay)
+        (setq list (cdr list)))
+      (comint-send-input))))
+
+(defun gnuplot-save-and-plot-from-comint ()
+  "Send a current script to gnuplot from the process buffer.
+This sends the most recently used gnuplot script to gnuplot using the
+\"load\" command.  This function first saves the script buffer to a
+file, prompting for a filename if one is not associated with the script
+buffer.  Then it sends a load command to gnuplot using the name of the
+file visited by the script buffer."
+  (interactive)
+  (if (not (buffer-live-p gnuplot-comint-recent-buffer))
+      (message "Script buffer has been deleted.")
+    (let (fname)
+      (with-current-buffer gnuplot-comint-recent-buffer
+        (save-buffer)
+        (setq fname (buffer-file-name)))
+      (goto-char (point-max))
+      (insert (format "load '%s'" fname))
+      (comint-send-input))))
+
+(defun gnuplot-pop-to-recent-buffer ()
+  "Switch to the most recently-plotted gnuplot script buffer."
+  (interactive)
+  (when (buffer-live-p gnuplot-comint-recent-buffer)
+    (pop-to-buffer gnuplot-comint-recent-buffer)))
+
+(defun gnuplot-trim-gnuplot-buffer ()
+  "Trim lines from the beginning of the *gnuplot* buffer.
+This keeps that buffer from growing excessively in size.  Normally,
+this function is attached to `gnuplot-after-plot-hook'"
+  (if (> gnuplot-buffer-max-size 0)
+      (with-current-buffer gnuplot-buffer
+        (let ((gnuplot-lines (count-lines (point-min) (point-max))))
+          (dotimes (_n (- gnuplot-lines gnuplot-buffer-max-size))
+            (goto-char (point-min))
+            (delete-region (line-beginning-position) (1+ (line-end-position))))
+          (goto-char (point-max))))))
+
+\f
+;;; --- functions controlling the gnuplot process
+
+;; Menu for the comint-mode buffer
+(defvar gnuplot-comint-menu
+  `("Gnuplot"
+    ["Plot most recent gnuplot buffer"          gnuplot-plot-from-comint
+     (buffer-live-p gnuplot-comint-recent-buffer)]
+    ["Save and plot most recent gnuplot buffer"         gnuplot-save-and-plot-from-comint
+     (buffer-live-p gnuplot-comint-recent-buffer)]
+    "---"
+    ,gnuplot-display-options-menu
+    ["Contextual completion and help"           gnuplot-context-sensitive-mode
+     :style toggle
+     :selected gnuplot-context-sensitive-mode]
+    ["Echo area help (eldoc-mode)" eldoc-mode
+     :active gnuplot-context-sensitive-mode
+     :style toggle
+     :selected eldoc-mode]
+    "---"
+    ["Insert filename at point"                         gnuplot-insert-filename t]
+    ["Negate set option"                        gnuplot-negate-option t]
+    ["Keyword help"                             gnuplot-info-lookup-symbol
+     (or gnuplot-keywords gnuplot-keywords-pending)]
+    ["Quick help for thing at point"            gnuplot-help-function
+     gnuplot-context-sensitive-mode]
+    ["Info documentation on thing at point"
+     gnuplot-info-at-point
+     gnuplot-context-sensitive-mode]
+    ["Switch to recent gnuplot script buffer"   gnuplot-pop-to-recent-buffer
+     (buffer-live-p gnuplot-comint-recent-buffer)]
+    "---"
+    ["Customize gnuplot"                        gnuplot-customize t]
+    "---"
+    ["Kill gnuplot"                             gnuplot-kill-gnuplot-buffer t]))
+
+;; Major mode `gnuplot-comint-mode' for the interaction buffer
+(define-derived-mode gnuplot-comint-mode comint-mode "Gnuplot interaction"
+  "Major mode for interacting with a gnuplot process in a buffer.
+
+This sets font-lock and keyword completion in the comint/gnuplot
+buffer."
+
+  (set-syntax-table gnuplot-mode-syntax-table)
+
+  (setq font-lock-defaults gnuplot-font-lock-defaults)
+  (setq-local parse-sexp-lookup-properties t)
+  (setq-local syntax-propertize-function #'gnuplot-syntax-propertize)
+
+  (add-hook 'kill-buffer-hook #'gnuplot-close-down nil t)
+
+  (add-hook 'comint-output-filter-functions
+            #'comint-postoutput-scroll-to-bottom
+            nil t)
+  (add-hook 'comint-output-filter-functions
+            #'gnuplot-protect-prompt-fn
+            nil t)
+
+  ;; Set up completion, using completion-at-point
+  (add-hook 'completion-at-point-functions #'gnuplot-completion-at-point nil t)
+
+
+  ;; Set up menu (see below)
+  (easy-menu-define
+    gnuplot-comint-mode-menu gnuplot-comint-mode-map "Menu used in gnuplot-comint-mode"
+    gnuplot-comint-menu))
+
+;; Key bindings for gnuplot-comint-mode
+(define-key gnuplot-comint-mode-map "\M-\C-p"   #'gnuplot-plot-from-comint)
+(define-key gnuplot-comint-mode-map "\M-\C-f"   #'gnuplot-save-and-plot-from-comint)
+(define-key gnuplot-comint-mode-map "\C-d"      #'gnuplot-delchar-or-maybe-eof)
+(define-key gnuplot-comint-mode-map "\M-\r"     #'completion-at-point)
+(define-key gnuplot-comint-mode-map "\M-\t"     #'completion-at-point)
+(define-key gnuplot-comint-mode-map "\C-c\C-d"  #'gnuplot-info-lookup-symbol)
+(define-key gnuplot-comint-mode-map "\C-c\C-i"  #'gnuplot-insert-filename)
+(define-key gnuplot-comint-mode-map "\C-c\C-n"  #'gnuplot-negate-option)
+(define-key gnuplot-comint-mode-map "\C-c\C-z"  #'gnuplot-customize)
+(define-key gnuplot-comint-mode-map "\C-c\C-e"  #'gnuplot-pop-to-recent-buffer)
+
+;; Menu for gnuplot-comint-mode
+(defvar gnuplot-comint-mode-menu nil
+  "Menu for `gnuplot-comint-mode'.")
+
+;; Switch to the gnuplot program buffer
+(defun gnuplot-make-gnuplot-buffer ()
+  "Switch to the gnuplot program buffer or create one if none exists."
+  (unless (and gnuplot-process (eq (process-status gnuplot-process) 'run)
+               gnuplot-buffer (buffer-live-p gnuplot-buffer))
+    (message "Starting gnuplot plotting program...")
+    (let ((gnuplot-cmd (list #'make-comint gnuplot-process-name gnuplot-program)))
+      (when gnuplot-program-args
+        (setq gnuplot-cmd (append gnuplot-cmd '(nil) (split-string gnuplot-program-args))))
+      (setq gnuplot-buffer  (eval gnuplot-cmd)
+            gnuplot-process (get-buffer-process gnuplot-buffer)))
+    (set-process-query-on-exit-flag gnuplot-process nil)
+    (with-current-buffer gnuplot-buffer
+      (gnuplot-comint-mode)
+      (when gnuplot-inline-image-mode
+        (sleep-for gnuplot-delay)
+        (gnuplot-setup-comint-for-image-mode)))
+    (message "Starting gnuplot plotting program...Done")))
+
+(defvar gnuplot-prompt-regexp
+  (regexp-opt '("gnuplot> " "multiplot> "))
+  "Regexp for recognizing the GNUPLOT prompt.")
+
+(defun gnuplot-protect-prompt-fn (_string)
+  "Prevent the Gnuplot prompt from being deleted or overwritten.
+STRING is the text as originally inserted in the comint buffer."
+  (save-excursion
+    (let ((b (progn
+               (goto-char (point-max))
+               (beginning-of-line)
+               (point)))
+          e)
+      (if (re-search-forward gnuplot-prompt-regexp (point-max) t)
+          (progn
+            (setq e (point))
+            (put-text-property b e 'rear-nonsticky '(read-only intangible face))
+            (put-text-property b e 'intangible t)
+            (put-text-property b e 'face 'gnuplot-prompt-face)
+            ;;(put-text-property b e 'read-only t)
+            )))))
+
+(defun gnuplot-close-down ()
+  "Tidy up when deleting the gnuplot buffer."
+  (if (and gnuplot-process
+           (eq (process-status gnuplot-process) 'run)) ; <SE>
+      (kill-process gnuplot-process))
+  (setq gnuplot-process nil
+        gnuplot-buffer nil))
+
+(defun gnuplot-delchar-or-maybe-eof (arg)
+  "Delete ARG characters forward, or (if at eob) send an EOF to subprocess.
+This is very similar to `comint-delchar-or-maybe-eof'."
+  (interactive "p")
+  (if (eobp)
+      (gnuplot-kill-gnuplot-buffer)
+    (delete-char arg)))
+
+(defun gnuplot-kill-gnuplot-buffer ()
+  "Kill the gnuplot process and its display buffers."
+  (interactive)
+  (if (and gnuplot-process
+           (eq (process-status gnuplot-process) 'run))  ;; <SE>
+      (kill-process gnuplot-process))
+  (if (and gnuplot-buffer (get-buffer gnuplot-buffer))
+      (progn
+        (if (one-window-p) ()
+          (delete-window (get-buffer-window gnuplot-buffer)))
+        (kill-buffer gnuplot-buffer)))
+  (setq gnuplot-process nil
+        gnuplot-buffer nil))
+
+
+(defun gnuplot-show-gnuplot-buffer ()
+  "Switch to the buffer containing the gnuplot process.
+When `gnuplot-display-process' is nil this will switch to
+the gnuplot process buffer.  When that variable is non-nil, the
+gnuplot process buffer will be displayed in a window."
+  (interactive)
+  (unless (and gnuplot-buffer (get-buffer gnuplot-buffer))
+    (gnuplot-make-gnuplot-buffer))
+  (cond ((equal gnuplot-display-process 'window)
+         (switch-to-buffer-other-window gnuplot-buffer))
+        ((equal gnuplot-display-process 'frame)
+         (or (and gnuplot-process-frame
+                  (frame-live-p gnuplot-process-frame))
+             (setq gnuplot-process-frame (make-frame)))
+         (raise-frame gnuplot-process-frame)
+         (select-frame gnuplot-process-frame)
+         (switch-to-buffer gnuplot-buffer))
+        (t
+         (switch-to-buffer gnuplot-buffer))))
+
+\f
+;;; Support for displaying plotted images within Emacs
+
+(defvar gnuplot-inline-image-filename nil
+  "Name of the current Gnuplot output file.")
+
+(defvar gnuplot-image-buffer-name "*gnuplot output*")
+
+(defun gnuplot-external-display-mode ()
+  "Display image in external."
+  (interactive)
+  (gnuplot-set-display-mode 'gnuplot-inline-image-mode nil))
+
+(defun gnuplot-inline-display-mode ()
+  "Display image in inline."
+  (interactive)
+  (gnuplot-set-display-mode 'gnuplot-inline-image-mode 'inline))
+
+(defun gnuplot-dedicated-display-mode ()
+  "Display image in dedicated."
+  (interactive)
+  (gnuplot-set-display-mode 'gnuplot-inline-image-mode 'dedicated))
+
+(defun gnuplot-set-image-format (format)
+  "Display image in FORMAT."
+  (interactive "sGnuplot image format: ")
+  (gnuplot-set-display-mode 'gnuplot-image-format format)
+  (unless gnuplot-inline-image-mode
+    (message "Setting will take effect when plots are displayed in Emacs")))
+
+(defun gnuplot-setup-comint-for-image-mode ()
+  "Setup comint for image."
+  (when (and gnuplot-buffer (buffer-live-p gnuplot-buffer)
+             (get-buffer-process gnuplot-buffer))
+    (with-current-buffer gnuplot-buffer
+      (if gnuplot-inline-image-mode
+          (progn
+            (gnuplot-send-hiding-output
+             (format "set terminal %s\n" gnuplot-image-format))
+            (gnuplot-inline-image-set-output)
+            (add-hook 'comint-output-filter-functions
+                      #'gnuplot-insert-inline-image-output nil t))
+        (gnuplot-send-hiding-output "set terminal pop\n")
+        (remove-hook 'comint-output-filter-functions
+                     #'gnuplot-insert-inline-image-output t)))))
+
+(defun gnuplot-inline-image-set-output ()
+  "Set Gnuplot's output file to `gnuplot-inline-image-filename'."
+  (let ((tmp (make-temp-file "gnuplot")))
+    (setq gnuplot-inline-image-filename tmp)
+    (gnuplot-send-hiding-output (format "set output '%s'\n" tmp))))
+
+(defvar gnuplot--inhibit-filter nil)
+
+(defun gnuplot-insert-inline-image-output (_string)
+  "Insert Gnuplot graphical output STRING in the gnuplot-comint buffer.
+
+Called via `comint-preoutput-filter-functions' hook when
+`gnuplot-inline-image-mode' is enabled.  Checks the status of the
+file `gnuplot-inline-image-filename'; if it exists and has
+nonzero size, inserts it as an inline image, stores a new
+temporary filename in `gnuplot-inline-image-filename', and
+updates Gnuplot with the appropriate \"set output\" command."
+  (unless gnuplot--inhibit-filter        ; Prevent recursively entering this filter
+    (let ((gnuplot--inhibit-filter t))   ; (causing an infinite loop)
+      (save-excursion
+        (goto-char (point-max))
+        (beginning-of-line)
+        (when (looking-at gnuplot-prompt-regexp)
+          (let* ((filename gnuplot-inline-image-filename)
+                 (size (nth 7 (file-attributes filename))))
+            (when (and size (> size 0))
+              (gnuplot-send-hiding-output "set output\n") ; Flush output file
+              (sit-for 0.1)             ; Hack: wait for Gnuplot IO to finish
+              (cl-ecase gnuplot-inline-image-mode
+                (nil nil)
+                (inline
+                  (ignore-errors
+                    (let ((image (create-image filename)))
+                      (beginning-of-line)
+                      (insert-image image)
+                      (insert "\n")
+                      (gnuplot-inline-image-set-output))))
+                (dedicated
+                 (with-current-buffer
+                     (get-buffer-create gnuplot-image-buffer-name)
+                   (let ((inhibit-read-only t))
+                     (erase-buffer)
+                     (insert-file-contents filename)
+                     (ignore-errors (normal-mode))
+                     (display-buffer (current-buffer))
+                     (gnuplot-inline-image-set-output))))))))))))
+
+;;; Send commands to GNUPLOT silently & without generating an extra prompt
+(defvar gnuplot-hidden-output-buffer " *gnuplot output*")
+
+(defun gnuplot-send-hiding-output (string)
+  "Send STRING to the running Gnuplot process invisibly."
+  (with-current-buffer gnuplot-buffer
+    (add-hook 'comint-preoutput-filter-functions
+              #'gnuplot-discard-output nil t))
+  (with-current-buffer (get-buffer-create gnuplot-hidden-output-buffer)
+    (erase-buffer))
+  (comint-send-string (get-buffer-process gnuplot-buffer) string))
+
+(defun gnuplot-discard-output (string)
+  "Temporary preoutput filter for hiding Gnuplot output & prompt.
+Accumulates output STRING in a buffer until it finds the next prompt,
+then removes itself from `comint-preoutput-filter-functions'."
+  (with-current-buffer
+      (get-buffer-create gnuplot-hidden-output-buffer)
+    (insert string)
+    (when (looking-back gnuplot-prompt-regexp (point-min))
+      (with-current-buffer gnuplot-buffer
+        (remove-hook 'comint-preoutput-filter-functions
+                     'gnuplot-discard-output t))))
+  "")
+
+
+\f
+;;; --- miscellaneous functions: insert file name, indentation, negation
+
+(defun gnuplot-insert-filename ()
+  "Insert a filename at point, prompting for name in the minibuffer.
+This inserts a filename relative to the buffer's default directory.
+Uses completion and the value of `gnuplot-quote-character'.
+Bound to \\[gnuplot-insert-filename]"
+  (interactive)
+  (insert gnuplot-quote-character
+          (file-relative-name (read-file-name "Filename > " "")
+                              default-directory)
+          gnuplot-quote-character))
+
+
+;; Adjust indentation for the line containing point
+(defun gnuplot-indent-line ()
+  "Set indentation in gnuplot buffer.
+For most lines, set indentation to previous level of indentation.
+Add additional indentation for continuation lines."
+  (interactive)
+  (let (indent)
+    (if (gnuplot-in-string (line-beginning-position))
+        ;; Continued strings begin at left margin
+        (setq indent 0)
+      (save-excursion
+        (if (gnuplot-continuation-line-p)
+            ;; This is a continuation line. Indent to the same level as
+            ;; the second word on the line beginning this command (i.e.,
+            ;; the first non-whitespace character after whitespace)
+            (progn
+              (gnuplot-beginning-of-continuation)
+              (back-to-indentation)
+              (re-search-forward "\\S-+\\s-+" (line-end-position) 'end-at-limit)
+              (setq indent (current-column)))
+
+          ;; Not a continuation line; indent according to block
+          ;; nesting depth
+          (save-excursion
+            (condition-case nil
+                (progn
+                  (beginning-of-line)
+                  (skip-syntax-forward "-" (line-end-position))
+                  (if (looking-at "\\s)") (forward-char))
+                  (backward-up-list)
+                  (gnuplot-beginning-of-continuation)
+                  (setq indent (+ gnuplot-basic-offset (current-indentation))))
+              (error
+               (setq indent 0)))))))
+
+    ;; Set indentation
+    (save-excursion
+      (indent-line-to indent))
+
+    ;; Move point after indentation when at beginning of line
+    (when (< (current-column) indent)
+      (move-to-column indent))))
+
+(defun gnuplot-electric-insert (BRACE)
+  "Adjust indentation on inserting a close BRACE.
+The blink-paren fix is stolen from cc-mode"
+  (interactive "*p")
+  (let ((old-blink-paren blink-paren-function)
+        (blink-paren-function nil))
+    (self-insert-command BRACE)
+    (gnuplot-indent-line)
+    (when old-blink-paren (funcall old-blink-paren))))
+
+;;
+;; Functions for finding the start and end of continuation blocks
+;;
+
+;; Check if line containing point is a continuation
+(defun gnuplot-continuation-line-p ()
+  "Return t if the line containing point is a continuation of the previous line."
+  (save-excursion
+    (condition-case ()
+        (progn
+          (end-of-line 0)
+          (backward-char)
+          (looking-at "\\\\"))
+      (error nil))))
+
+;; Move point to start of continuation block
+(defun gnuplot-beginning-of-continuation ()
+  "Move point to the beginning of the continuation lines containing point.
+
+If not in a continuation line, move point to beginning of line."
+  (beginning-of-line)
+  (while (gnuplot-continuation-line-p)
+    (beginning-of-line 0)))
+
+;; Move point to end of continuation block
+(defun gnuplot-end-of-continuation ()
+  "Move point to the end of the continuation lines containing point.
+
+If there are no continuation lines, move point to `end-of-line'."
+  (end-of-line)
+  (unless (bobp)
+    (catch 'eob
+      (while (save-excursion (backward-char)
+                             (looking-at "\\\\"))
+        (end-of-line 2)
+        (if (eobp) (throw 'eob nil))))))
+
+;; Save-excursion wrappers for the above to return point at beginning
+;; or end of continuation
+(defun gnuplot-point-at-beginning-of-continuation (&optional pos)
+  "Return value of point at beginning of the continued block containing point.
+
+If there are no continuation lines, returns `line-beginning-position'.
+If specify POS, move POS befere execution."
+  (save-excursion
+    (when pos (goto-char pos))
+    (gnuplot-beginning-of-continuation)
+    (point)))
+
+(defun gnuplot-point-at-end-of-continuation (&optional pos)
+  "Return value of point at the end of the continued block containing point.
+
+If there are no continuation lines, returns `line-end-position'.
+If specify POS, move POS before execution."
+  (save-excursion
+    (when pos (goto-char pos))
+    (gnuplot-end-of-continuation)
+    (point)))
+
+(defun gnuplot-beginning-of-defun (&optional arg)
+  "We also treat a block of continuation lines as a `defun'.
+ARG is optional arg."
+  (if (not arg) (setq arg 1))
+  (if (> arg 0)
+      (catch 'bob               ; go to beginning of ARGth prev. defun
+        (dotimes (_n arg)
+          (when (= (point)
+                   (gnuplot-point-at-beginning-of-continuation))
+            (forward-line -1)
+            (if (bobp) (throw 'bob t))
+            (while (looking-at "^\\s-*$")
+              (forward-line -1)
+              (if (bobp) (throw 'bob t))))
+          (gnuplot-beginning-of-continuation))
+        t)
+
+    (catch 'eob                   ; find beginning of (-ARG)th following defun
+      (dotimes (_n (- arg))
+        (gnuplot-end-of-continuation)
+        (forward-line)
+        (if (eobp) (throw 'eob t))
+        (while (looking-at "^\\s-*$")
+          (forward-line)
+          (if (eobp) (throw 'eob t)))))))
+
+;; Movement to start or end of command, including multiple commands
+;; separated by semicolons
+(defun gnuplot-beginning-of-command ()
+  "Move point to beginning of command containing point."
+  (let ((limit (gnuplot-point-at-beginning-of-continuation)))
+    (while
+        (and
+         (search-backward ";" limit 'lim)
+         (gnuplot-in-string-or-comment)))
+    (skip-chars-forward ";")
+    (skip-syntax-forward "-")))
+
+(defun gnuplot-end-of-command ()
+  "Move point to end of command containing point."
+  (let ((limit (gnuplot-point-at-end-of-continuation)))
+    (while
+        (and
+         (search-forward ";" limit 'lim)
+         (gnuplot-in-string-or-comment)))
+    (skip-chars-backward ";")
+    (skip-syntax-backward "-")))
+
+(defun gnuplot-point-at-beginning-of-command ()
+  "Return position at the beginning of command containing point."
+  (save-excursion (gnuplot-beginning-of-command) (point)))
+
+(defun gnuplot-point-at-end-of-command ()
+  "Return position at the end of command containing point."
+  (save-excursion (gnuplot-end-of-command) (point)))
+
+(defun gnuplot-negate-option ()
+  "Append \"no\" to or remove \"no\" from the set option on the current line.
+This checks if the set option is one which has a negated form.
+
+Negatable options are defined in `gnuplot-keywords-negatable-options'."
+  (interactive)
+  (let ((begin (gnuplot-point-at-beginning-of-command))
+        (end   (gnuplot-point-at-end-of-command))
+        (regex gnuplot-negatable-options-regexp))
+    (save-excursion
+      (goto-char begin)
+      (skip-syntax-forward "-" end)
+      (if (looking-at "\\(un\\)?set\\s-+")
+          (cond ((looking-at "unset")
+                 (delete-char 2))
+                ((looking-at (concat "set\\s-+\\(" regex "\\)"))
+                 (insert "un"))
+                (t
+                 (message "There is not a negatable set option on this line")))
+        (message "There is not a set option on this line")))))
+
+
+(defun gnuplot-customize ()
+  "Customize `gnuplot-mode'."
+  (interactive)
+  (customize-group "gnuplot"))
+
+
+\f
+;;; --- help from the info file, keyword list + completion, insert function
+
+
+;; set up stuff for info-look (as suggested by <SE>)
+;; modified with suggestion from <MS>
+(defun gnuplot-setup-info-look ()
+  "Setup info-look in the gnuplot buffer.
+
+Also set the variable `gnuplot-keywords' and do something sensible if
+info-look was not available."
+  (interactive)
+  (setq gnuplot-keywords-pending nil)
+  ;; TODO Update info layout
+  (let ((doc-spec
+         '(("(gnuplot)Command_Index"   nil "[_a-zA-Z0-9]+")
+           ("(gnuplot)Options_Index"   nil "[_a-zA-Z0-9]+")
+           ("(gnuplot)Function_Index"  nil "[_a-zA-Z0-9]+")
+           ("(gnuplot)Terminal_Index"  nil "[_a-zA-Z0-9]+"))))
+    (info-lookup-add-help
+     :mode 'gnuplot-mode :topic 'symbol
+     :regexp "[a-zA-Z][_a-zA-Z0-9]*"
+     :doc-spec doc-spec)
+    (info-lookup-add-help
+     :mode 'gnuplot-comint-mode :topic 'symbol
+     :regexp "[a-zA-Z][_a-zA-Z0-9]*"
+     :doc-spec doc-spec))
+
+  (let ((there (bufferp (get-buffer "*info*"))))
+    (info-lookup-setup-mode 'symbol 'gnuplot-mode)
+    (or there (and (get-buffer "*info*") (kill-buffer "*info*")))
+    ;; why are these buffers here?  I think that the general
+    ;; user will not want them lying around
+    (and (get-buffer "info dir")    (kill-buffer "info dir"))
+    (and (get-buffer "info dir<2>") (kill-buffer "info dir<2>")))
+  (setq gnuplot-keywords (gnuplot-set-keywords-list)))
+
+(defun gnuplot-set-keywords-list ()
+  "Set `gnuplot-keywords' from `info-lookup-cache'.
+Return a list of keywords."
+  (let* ((list (cdr (assoc 'symbol info-lookup-cache)))
+         (list (cdr (cdr (assoc 'gnuplot-mode list))))
+         (list (car list))
+         (store ()) item)
+    (while list
+      (setq item (car (car list))
+            item (format "%s" item) ; keep this line for the sake of
+            store (append (list item) store) ; info-look.el w/o my patch
+            list  (cdr list)))
+    (delete "nil" store)
+    store ))
+
+\f
+;;;; Completion at point and Eldoc.
+
+;; There are two alternative completion-at-point mechanisms: the old
+;; one using info-look and the new one (enabled by default) which
+;; parses the command line to provide smarter completions.
+
+;; `gnuplot-completion-at-point-function' defines which one is
+;; used. `gnuplot-context-sensitive-mode' toggles between the two.
+
+(defvar gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look
+  "Function to call to perform completion in Gnuplot buffers.")
+
+(defun gnuplot-completion-at-point ()
+  "Perform completion in Gnuplot buffers."
+  (funcall gnuplot-completion-at-point-function))
+
+;; Older completion method using info-look
+(defun gnuplot-completion-at-point-info-look ()
+  "Return completions of keyword preceding point.
+
+Uses the cache of keywords generated by `info-lookup'.  See
+`gnuplot-setup-info-look'.  If non-nil, the return value is in the form
+\(BEGIN END COMPLETIONS) where BEGIN and END are buffer
+positions and COMPLETIONS is a list."
+
+  (if gnuplot-keywords-pending          ; <HW>
+      (gnuplot-setup-info-look))
+  (list (condition-case _err
+            (save-excursion (backward-sexp 1) (point))
+          (error (point)))
+        (point) gnuplot-keywords))
+
+\f
+(defun gnuplot-info-lookup-symbol (symbol &optional mode)
+  "Wrapper for `info-lookup-symbol'.
+Takes SYMBOL and MODE as arguments exactly as
+`info-lookup-symbol'.  After doing the info lookup, calls
+`gnuplot--adjust-info-display' to display the info buffer
+according to the value of `gnuplot-info-display'."
+  (interactive
+   (cond (gnuplot-keywords
+          (info-lookup-interactive-arguments 'symbol))
+         (gnuplot-keywords-pending      ; <HW>
+          (gnuplot-setup-info-look)
+          (info-lookup-interactive-arguments 'symbol))
+         (t
+          (list nil (message
+                     "Help is not available.  The gnuplot info file could not be found.")))))
+
+  (when gnuplot-keywords
+    (unless symbol (setq symbol "Commands"))
+    (save-window-excursion
+      (info-lookup-symbol symbol mode))
+    (gnuplot--adjust-info-display)))
+
+(defun gnuplot--adjust-info-display ()
+  "Displays the *info* buffer in a window or frame.
+Specified by the value of `gnuplot-info-display'.
+If `gnuplot-info-display' is `window', then the window will be
+shrunk to the size of the info entry if it is smaller than half
+the height of the frame.
+
+The *info* buffer should already exist when this function is
+called."
+  (cl-case gnuplot-info-display
+    (window
+     (switch-to-buffer-other-window "*info*")
+     ;; Adjust window height only if the frame is split
+     ;; horizontally, so as not to mess up the minibuffer <jjo>
+     ;; we can't use shrink-window-if-larger-than-buffer here
+     ;; because it doesn't work with Info mode's narrowing
+     (with-selected-window (get-buffer-window "*info*")
+       (unless (window-full-height-p)
+         (enlarge-window
+          (min (- (count-lines (point-min) (point-max)) (window-height) -1)
+               (- (/ (frame-height) 2) (window-height)))))))
+
+    (frame
+     (unless (and gnuplot-info-frame
+                  (frame-live-p gnuplot-info-frame))
+       (setq gnuplot-info-frame (make-frame)))
+     (select-frame gnuplot-info-frame)
+     (raise-frame gnuplot-info-frame)
+     (switch-to-buffer "*info*"))
+
+    (t
+     (switch-to-buffer "*info*"))))
+
+(defun gnuplot-insert (string)
+  "Insert STRING at point and display help for for STRING.
+Help is not shown if `gnuplot-insertions-show-help-flag' is nil.  The
+help shown is for STRING unless STRING begins with the word \"set\" or
+\"show\", in which case help is shown for the thing being set or
+shown."
+  (interactive)
+  (insert string)
+  (let ((topic string) term)
+    (if (string-match
+         "\\(set\\|show\\)[ \t]+\\([^ \t]+\\)\\(\\s-+\\([^ \t]+\\)\\)?"
+         string)
+        (progn
+          (setq topic (downcase (match-string 2 string))
+                term            (match-string 4 string))
+          (if (string= topic "terminal") (setq topic (downcase term)))))
+    (cond ((and (bound-and-true-p gnuplot-gui-popup-flag)
+                (fboundp 'gnuplot-gui-set-options-and-insert))
+           (gnuplot-gui-set-options-and-insert))
+          (gnuplot-insertions-show-help-flag
+           (if gnuplot-keywords-pending          ; <HW>
+               (gnuplot-setup-info-look))
+           (gnuplot-info-lookup-symbol topic)))))
+
+(defun gnuplot-toggle-info-display ()
+  "Toggle info display."
+  (interactive)
+  (setq gnuplot-insertions-show-help-flag (not gnuplot-insertions-show-help-flag))
+  (message (if gnuplot-insertions-show-help-flag
+               "Help will be displayed after insertions."
+             "Help no longer displayed after insertions.")))
+
+\f
+;;; --- autoloaded functions: gnuplot-mode and gnuplot-make-buffer
+
+;;;###autoload
+(defun gnuplot-mode ()
+  "Major mode for editing and executing GNUPLOT scripts.
+This was written with version 4.6 of gnuplot in mind, but should
+work with newer and older versions.
+
+Report bugs at https://github.com/emacs-gnuplot/gnuplot/issues
+
+                            ------O------
+
+Gnuplot-mode includes two different systems for keyword
+completion and documentation lookup: a newer one,
+`gnuplot-context-sensitive-mode' (enabled by default), and a
+older one which extracts keywords from gnuplot's Info file.  Both
+systems allow looking up documentation in the Info file.  The
+older system also depends having the info file properly installed
+to make a list of keywords.
+
+The info file should be installed by default with the Gnuplot
+distribution, or is available at the `gnuplot-mode' web page:
+https://github.com/emacs-gnuplot/gnuplot/
+
+With the new context-sensitive mode active, `gnuplot-mode' can also
+provide function/`eldoc-mode' syntax hints as you type.  This requires a
+separate file of strings, `gnuplot-eldoc.el', which is also
+provided by recent Gnuplot distributions.
+
+                            ------O------
+
+There are several known shortcomings of `gnuplot-mode', version 0.5g
+and up.  Many of the shortcomings involve the graphical interface
+\(refered to as the GUI) to setting arguments to plot options.  Here is
+a list:
+
+ 1.  Currently there is no way for `gnuplot-mode' to know if information
+     sent to gnuplot was correctly plotted.
+ 2.  \"plot\", \"splot\", and \"fit\" are handled in the GUI, but are
+     a bit flaky.  Their arguments may not be read correctly from
+     existing text, and continuation lines (common for plot and splot)
+     are not supported.
+ 3.  The GUI does not know how to read from continuation lines.
+ 4.  Comma separated position arguments to plot options are
+     unsupported in the GUI.  Colon separated datafile modifiers (used
+     for plot, splot, and fit) are not supported either.  Arguments
+     not yet supported by the GUI generate messages printed in grey
+     text.
+ 5.  The GUI handling of \"hidden3d\" is flaky and \"cntrparam\" is
+     unsupported.
+
+                            ------O------
+
+ Key bindings:
+ \\{gnuplot-mode-map}"
+  (interactive)
+  (kill-all-local-variables)
+  (use-local-map gnuplot-mode-map)
+  (setq major-mode 'gnuplot-mode
+        mode-name "Gnuplot")
+  (setq-local comment-start "# ")
+  (setq-local comment-end "")
+  (setq-local comment-column 32)
+  (setq-local comment-start-skip "#[ \t]*")
+  (setq-local indent-line-function #'gnuplot-indent-line)
+
+  (setq-local beginning-of-defun-function #'gnuplot-beginning-of-defun)
+  (setq-local end-of-defun-function #'gnuplot-end-of-continuation)
+
+  (add-hook 'completion-at-point-functions #'gnuplot-completion-at-point nil t)
+
+  (set-syntax-table gnuplot-mode-syntax-table)
+
+  (when (eq gnuplot-keywords-when 'immediately) ; <HW>
+    (gnuplot-setup-info-look)) ;; <SE>
+
+  ;; Add syntax-propertizing functions to search for strings and comments
+  (setq-local syntax-propertize-function #'gnuplot-syntax-propertize)
+  (add-hook 'syntax-propertize-extend-region-functions
+            #'gnuplot-syntax-propertize-extend-region nil t)
+
+  ;; Set up font-lock
+  (setq font-lock-defaults gnuplot-font-lock-defaults)
+  (setq-local font-lock-multiline t)
+  (setq-local parse-sexp-lookup-properties t)
+
+  (setq gnuplot-comint-recent-buffer (current-buffer))
+  (setq-local comint-process-echoes gnuplot-echo-command-line-flag)
+  (run-hooks 'gnuplot-mode-hook)
+  (gnuplot-setup-menubar))
+
+;;;###autoload
+(defun gnuplot-make-buffer ()
+  "Open a new buffer in `gnuplot-mode'.
+When invoked, it switches to a new, empty buffer visiting no file
+and then starts `gnuplot-mode'.
+
+It is convenient to bind this function to a global key sequence.  For
+example, to make the F10 key open a gnuplot script buffer, put the
+following in your .emacs file:
+     (autoload 'gnuplot-make-buffer \"gnuplot\"
+               \"open a buffer in gnuplot mode\" t)
+     (global-set-key [(f10)] 'gnuplot-make-buffer)"
+  (interactive)
+  (switch-to-buffer gnuplot-gnuplot-buffer)
+  (gnuplot-mode))
+
+;;;###autoload
+(defun run-gnuplot ()
+  "Run an inferior Gnuplot process."
+  (interactive)
+  (gnuplot-make-gnuplot-buffer)
+  (pop-to-buffer gnuplot-buffer))
+
+;;; That's it! ----------------------------------------------------------------
+
+(provide 'gnuplot)
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+
+;;; gnuplot.el ends here