33; ; Copyright (C) 2012-2013 Jon Oddie <jonxfield@gmail.com>
44
55; ; Author: Jon Oddie <jonxfield@gmail.com>
6- ; ; Maintainer: Jon Oddie <jonxfield@gmail.com>
7- ; ; Created: Wednesday, 08 February 2012
8- ; ; Updated: Friday, 07 February 2013
9- ; ; Version: 0.7.0
10- ; ; Keywords: gnuplot, plotting
6+ ; ; URL: https://github.com/emacsorphanage/gnuplot
117
128; ; This file is not part of GNU Emacs.
139
4541; ;
4642; ; Gnuplot's context sensitive mode is best controlled using Customize
4743; ; (M-x customize-group gnuplot): simply enable the
48- ; ; `gnuplot-context-sensitive-mode' setting. On recent Emacs (>= 23),
44+ ; ; `gnuplot-context-sensitive-mode' setting. On recent Emacs (>= 23),
4945; ; you may also want to turn on `gnuplot-tab-completion' so that the
5046; ; TAB key does auto-completion on lines which are already
51- ; ; indented. (This just sets the Emacs variable `tab-always-indent' to
47+ ; ; indented. (This just sets the Emacs variable `tab-always-indent' to
5248; ; `complete' in Gnuplot buffers).
5349; ;
5450; ; If you need to turn context sensitivity on or off from Lisp code
6056; ; or not, you can always pop up a longer description of syntax using
6157; ; `gnuplot-help-function' (C-c C-/ or C-c M-h). ElDoc support also
6258; ; requires an additional file of help strings, `gnuplot-eldoc.el' ,
63- ; ; which should be included in recent Gnuplot releases. If it didn't
59+ ; ; which should be included in recent Gnuplot releases. If it didn't
6460; ; come with your Gnuplot installation, you'll need to grab a recent
6561; ; source distribution of Gnuplot from http://gnuplot.info, and use
6662; ; the `doc2texi.el' program in the docs/ directory to create it. So
7672; ;
7773; ; Gnuplot's command language has a fair amount of syntactic
7874; ; complexity, and the only way I could think of to support these
79- ; ; features was to do a complete parse of the command line. So that's
80- ; ; what this package does. Instead of building a parse tree, it
75+ ; ; features was to do a complete parse of the command line. So that's
76+ ; ; what this package does. Instead of building a parse tree, it
8177; ; matches up until the token at point, and then either makes a list
8278; ; of possible completions, or sets the variables `gnuplot-eldoc' and
8379; ; `gnuplot-info-at-point' based on where it is in the grammar at that
9591; ; work well enough, and it saves on the Emacs call stack.
9692; ;
9793; ; Compiling the grammar does require increasing `max-lisp-eval-depth'
98- ; ; modestly. This shouldn't cause any problems on modern machines, and
94+ ; ; modestly. This shouldn't cause any problems on modern machines, and
9995; ; it only needs to be done once, at byte-compilation time.
10096; ;
10197; ; The parsing machine and compiler are partially based on the
113109; ; Match any token
114110; ;
115111; ; name, number, string, separator
116- ; ; Match a token of the given type. "Separator" is semicolon, the
112+ ; ; Match a token of the given type. "Separator" is semicolon, the
117113; ; statement separator.
118114; ;
119115; ; Any other symbol
120- ; ; Match another named rule in the grammar. May be recursive.
116+ ; ; Match another named rule in the grammar. May be recursive.
121117; ;
122118; ; "STRING"
123119; ; Match literally: a token with exactly the text "STRING".
124120; ;
125121; ; (kw KEYWORD ALIASES ...)
126- ; ; Match abbreviated Gnuplot keywords. KEYWORD can be a string or
127- ; ; a cons (PREFIX . SUFFIX). In the latter case, this pattern
122+ ; ; Match abbreviated Gnuplot keywords. KEYWORD can be a string or
123+ ; ; a cons (PREFIX . SUFFIX). In the latter case, this pattern
128124; ; will match PREFIX plus any number of characters from the
129125; ; beginning of SUFFIX. Any literal string from ALIASES will
130- ; ; also match. The token-id of the matching token is mutated to
126+ ; ; also match. The token-id of the matching token is mutated to
131127; ; the canonical value of KEYWORD.
132128; ; Example:
133129; ; (kw ("linew" ."idth") "lw") matches "linew", "linewi",
134- ; ; ... "linewidth" as well as "lw". Any of these tokens will
135- ; ; appear as "linewidth" in subsequent processing. (This is
130+ ; ; ... "linewidth" as well as "lw". Any of these tokens will
131+ ; ; appear as "linewidth" in subsequent processing. (This is
136132; ; important for the "info-keyword" form, see below).
137133; ;
138134; ; The other pattern forms combine simpler patterns, much like regular
142138; ; { (:info "info page") }
143139; ; { (:no-info) }
144140; ; PATTERN PATTERN... )
145- ; ; Match all the PATTERNs in sequence or fail. Sequences can also
141+ ; ; Match all the PATTERNs in sequence or fail. Sequences can also
146142; ; have optional ElDoc strings and info pages associated with
147143; ; them; the innermost ElDoc or info page around point is the one
148- ; ; shown to the user. Alternatively, either property may be a
144+ ; ; shown to the user. Alternatively, either property may be a
149145; ; symbol, which should be a function to be called to get the
150146; ; real value. Finally, if no ElDoc string is specified but the
151147; ; variable `gnuplot-eldoc-hash' contains a value for the name of
157153; ;
158154; ; (either PATTERN PATTERN...)
159155; ; Match the first PATTERN to succeed, or fail if none
160- ; ; matches. Like regexp `|' .
156+ ; ; matches. Like regexp `|' .
161157; ;
162158; ; (many PATTERN)
163159; ; Match PATTERN zero or more times, greedily; like regexp
164- ; ; `*' . Unlike a regular expression matcher, the parsing machine
160+ ; ; `*' . Unlike a regular expression matcher, the parsing machine
165161; ; will not backtrack and try to match fewer times if a later
166- ; ; part of the pattern fails. This applies equally to the other
162+ ; ; part of the pattern fails. This applies equally to the other
167163; ; non-deterministic forms "either" and "maybe".
168164; ;
169165; ; (maybe PATTERN)
170166; ; Match PATTERN zero or one times, like regexp `?' .
171167; ;
172168; ; (capture NAME PATTERN)
173169; ; Match PATTERN, capturing the tokens in a capture group named
174- ; ; NAME. Capture groups are stored in `gnuplot-captures'
175- ; ; and can be retrieved using `gnuplot-capture-group' . This is
170+ ; ; NAME. Capture groups are stored in `gnuplot-captures'
171+ ; ; and can be retrieved using `gnuplot-capture-group' . This is
176172; ; used to store the plotting style, which we need in order to
177173; ; give the correct ElDoc string for "using" clauses, and for
178174; ; info keywords (see below)
179175; ;
180176; ; (info-keyword PATTERN)
181177; ; Match PATTERN, and use whatever the value of the first token
182- ; ; it matches is to look up info pages for this pattern. Most
178+ ; ; it matches is to look up info pages for this pattern. Most
183179; ; Gnuplot info pages have the same name as the keyword they
184180; ; document, so by using this we only have to put :info
185181; ; properties on the few that don't, such as "set".
190186; ; (maybe (sequence "," expression))
191187; ;
192188; ; (delimited-list PATTERN SEPARATOR)
193- ; ; Match a list of PATTERNs separated by SEPARATOR. Sugar for:
189+ ; ; Match a list of PATTERNs separated by SEPARATOR. Sugar for:
194190; ; (sequence PATTERN (many (sequence SEPARATOR PATTERN)))
195191; ;
196192; ; (assert LISP-FORM)
197- ; ; Evaluate LISP-FORM and fail if it returns NIL. We need this in
193+ ; ; Evaluate LISP-FORM and fail if it returns NIL. We need this in
198194; ; the patterns for "plot" and "splot" to check whether the
199195; ; command at point should be parsed in parametric mode or
200- ; ; not. See `gnuplot-guess-parametric-p' .
196+ ; ; not. See `gnuplot-guess-parametric-p' .
201197; ;
202198; ;
203199; ; Bugs, TODOs, etc.
214210; ; many lines.
215211; ;
216212; ; In ElDoc mode, we parse the whole line every time the user stops
217- ; ; typing. This is wasteful; should cache things in text properties
213+ ; ; typing. This is wasteful; should cache things in text properties
218214; ; instead.
219215; ;
220216; ; The pattern matching engine uses backtracking, which can take
221- ; ; exponential time. So far it seems "fast enough" in actual use.
217+ ; ; exponential time. So far it seems "fast enough" in actual use.
222218; ;
223219; ; The patterns don't really distinguish between "plot" and "splot"
224220; ; for things like plot styles, binary arguments, etc.
225221; ;
226222; ; Some other the patterns are probably not quite right, especially for
227223; ; things like abbreviated keywords, and features that I don't use
228- ; ; myself like "fit". Hopefully anyone bothered by this will submit
224+ ; ; myself like "fit". Hopefully anyone bothered by this will submit
229225; ; patches ;-)
230226; ;
231227; ; It would be possible to provide more helpful ElDoc strings for
232- ; ; sub-parts of complicated options like "cntrparam". This is a time
228+ ; ; sub-parts of complicated options like "cntrparam". This is a time
233229; ; and maintenance issue rather than a technical one.
234230
235231; ;; Code:
284280 rules))))
285281
286282(defun gnuplot-tokenize (&optional completing-p )
287- " Tokenize the Gnuplot command at point. Returns a list of `gnuplot-token' objects.
283+ " Tokenize the Gnuplot command at point.
284+ Return a list of `gnuplot-token' objects.
288285
289286If COMPLETING-P is non-nil, omits the token at point if it is a
290- name; otherwise continues tokenizing up to the token at point. FIXME"
287+ name; otherwise continues tokenizing up to the token at point. FIXME. "
291288 (let ((tokens '())
292289 (stop-point (min (point )
293290 (gnuplot-point-at-end-of-command))))
@@ -326,7 +323,7 @@ name; otherwise continues tokenizing up to the token at point. FIXME"
326323 :start from :end to)))
327324
328325 (t (error
329- " gnuplot -tokenize: bad token beginning %s"
326+ " Gnuplot -tokenize: bad token beginning %s"
330327 (buffer-substring-no-properties (point ) stop-point))))))
331328
332329 (push token tokens))))
@@ -572,7 +569,7 @@ name; otherwise continues tokenizing up to the token at point. FIXME"
572569 `((assert , form ))))
573570
574571 (t
575- (error " gnuplot -compile-pattern: bad pattern form %s " pat)))))))
572+ (error " Gnuplot -compile-pattern: bad pattern form %s " pat)))))))
576573
577574 ; ; Helper function for destructuring (sequence ...) forms in patterns
578575 ; ; Takes the cdr of the sequence form, returns a list (PATTERNS ELDOC
@@ -679,7 +676,7 @@ name; otherwise continues tokenizing up to the token at point. FIXME"
679676 (setcdr inst `(, location ))))
680677
681678 (t
682- (error " gnuplot -compile-grammar: bad instruction %s " inst))))))))
679+ (error " Gnuplot -compile-grammar: bad instruction %s " inst))))))))
683680 object-code))))
684681
685682; ;; The grammar.
@@ -1751,14 +1748,14 @@ token before point.")
17511748 " Relevant page of the Gnuplot info manual for the construction at point.
17521749
17531750Set by `gnuplot-match-pattern' using information from
1754- `gnuplot-compiled-grammar' . `gnuplot-match-pattern' pushes ElDoc
1751+ `gnuplot-compiled-grammar' . `gnuplot-match-pattern' pushes ElDoc
17551752and info strings onto the stack as it runs, and scans the stack
17561753for the topmost entry when it reaches the token at point." )
17571754
17581755(defvar gnuplot-eldoc nil
17591756 " ElDoc documentation string for the Gnuplot construction at point.
17601757
1761- Set by `gnuplot-match-pattern' . See also `gnuplot-info-at-point' ." )
1758+ Set by `gnuplot-match-pattern' . See also `gnuplot-info-at-point' ." )
17621759
17631760(defvar gnuplot-captures nil
17641761 " Alist of named capture groups for gnuplot-mode completion code.
@@ -1776,9 +1773,9 @@ token list just after the end of the capture group.")
17761773 " Parse TOKENS, setting completions, info and ElDoc information.
17771774
17781775This function parses TOKENS by simulating a stack machine with
1779- unlimited backtracking. If COMPLETING-P is non-nil, it stops
1776+ unlimited backtracking. If COMPLETING-P is non-nil, it stops
17801777before the token at point and collects a list of the next tokens
1781- that it would accept in `gnuplot-completions' . If COMPLETING-P is
1778+ that it would accept in `gnuplot-completions' . If COMPLETING-P is
17821779nil, it parses up to the token at point and sets `gnuplot-eldoc'
17831780and `gnuplot-info-at-point' based on the contents of the stack
17841781there."
@@ -1914,7 +1911,7 @@ there."
19141911 ((commit)
19151912 (let ((location (cadr inst)))
19161913 (if (not backtrack)
1917- (error " no more backtrack points in commit" ))
1914+ (error " No more backtrack points in commit" ))
19181915 (pop backtrack)
19191916 (setq jump location)))
19201917
@@ -1955,7 +1952,7 @@ there."
19551952 (let* ((name (cadr inst))
19561953 (record (assoc name gnuplot-captures)))
19571954 (if (not record)
1958- (error " gnuplot -match-tokens: no open capture group named %s " name)
1955+ (error " Gnuplot -match-tokens: no open capture group named %s " name)
19591956 (setf (caddr record) tokens)
19601957 (gnuplot-debug (gnuplot-dump-captures)))))
19611958
@@ -1967,7 +1964,7 @@ there."
19671964 (push (cons pc tokens) progress))))
19681965
19691966 (t
1970- (error " bad instruction: %s " inst)))
1967+ (error " Bad instruction: %s " inst)))
19711968
19721969 ; ; Increment PC or jump
19731970 (setq pc (or jump (1+ pc))
@@ -1996,7 +1993,7 @@ there."
19961993 (gnuplot-debug (gnuplot-dump-progress progress)))))))))))
19971994
19981995(defun gnuplot-scan-stack (stack tokens )
1999- " Scan STACK for the most recently pushed eldoc and info strings"
1996+ " Scan STACK for the most recently pushed eldoc and info strings. "
20001997 (gnuplot-trace " \t * scanning stack *\n " )
20011998 (gnuplot-debug (gnuplot-backtrace))
20021999 (gnuplot-debug (gnuplot-dump-captures))
0 commit comments