Skip to content

Commit d1a6a60

Browse files
authored
Merge pull request #76 from minad/lazy-loading
Lazy loading and lexical scoping
2 parents e74ca19 + 0654205 commit d1a6a60

File tree

8 files changed

+195
-212
lines changed

8 files changed

+195
-212
lines changed

README.org

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ When =gnuplot-mode= is on, the following keybindings are available:
103103
| M-tab or M-ret | complete keyword before point |
104104
| ret | newline and indent |
105105
| tab | indent current line |
106-
| C-c M-i | toggle inline plot display in comint buffer |
107106

108107

109108
With the exception of the commands for sending commands to Gnuplot,
@@ -140,16 +139,16 @@ terminal= commands.
140139
If you install the file =gnuplot-eldoc.el= from a recent Gnuplot
141140
distribution, gnuplot-mode can show syntax hints in the modeline when
142141
~eldoc-mode~ is turned on and context sensitivity is enabled.
143-
142+
144143
** Inline Images
145144

146145
You can optionally have plots displayed inline in the Gnuplot comint
147146
process buffer. This is handy for trying things out without having to
148147
switch between Emacs and the Gnuplot display. Call
149-
=gnuplot-inline-imge-mode= or type ~C-c M-i~ in a gnuplot-mode buffer
150-
to try it out. This feature is implemented using temporary =png=
151-
files, and is also somewhat experimental. It requires Gnuplot to have
152-
=png= support and a GNU Emacs with image support. Please report bugs.
148+
=gnuplot-inline-display-mode= in a gnuplot-mode buffer to try it out. This
149+
feature is implemented using temporary =png= files, and is also somewhat
150+
experimental. It requires Gnuplot to have =png= support and a GNU Emacs
151+
with image support. Please report bugs.
153152

154153

155154

gnuplot-context.el

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; gnuplot-context.el -- context-sensitive help and completion for gnuplot
1+
;;; gnuplot-context.el -- context-sensitive help and completion for gnuplot -*- lexical-binding: t -*-
22

33
;; Copyright (C) 2012-2013 Jon Oddie <[email protected]>
44

@@ -1721,9 +1721,9 @@ name; otherwise continues tokenizing up to the token at point. FIXME."
17211721
;; them. For normal use, they compile to no-ops.
17221722
(eval-when-compile
17231723
(when (not (featurep 'gnuplot-debug-context))
1724-
(defmacro with-gnuplot-trace-buffer (&rest args) "No-op." '(progn nil))
1725-
(defmacro gnuplot-trace (&rest args) "No-op." '(progn nil))
1726-
(defmacro gnuplot-debug (&rest args) "No-op." '(progn nil))))
1724+
(defmacro with-gnuplot-trace-buffer (&rest _) "No-op." '(progn nil))
1725+
(defmacro gnuplot-trace (&rest _) "No-op." '(progn nil))
1726+
(defmacro gnuplot-debug (&rest _) "No-op." '(progn nil))))
17271727

17281728

17291729

@@ -1755,6 +1755,12 @@ name specified in the (capture NAME PATTERN) form in the
17551755
list beginning the capture group, and END is the tail of the
17561756
token list just after the end of the capture group.")
17571757

1758+
(defvar gnuplot-eldoc-hash nil
1759+
"ElDoc strings for gnuplot-mode.
1760+
1761+
These have to be compiled from the Gnuplot source tree using
1762+
`doc2texi.el'.")
1763+
17581764

17591765
;;;; The pattern matching machine
17601766
(defun gnuplot-match-pattern (instructions tokens completing-p
@@ -1984,7 +1990,7 @@ there."
19841990
(defun gnuplot-scan-stack (stack tokens)
19851991
"Scan STACK for the most recently pushed eldoc and info strings."
19861992
(gnuplot-trace "\t* scanning stack *\n")
1987-
(gnuplot-debug (gnuplot-backtrace))
1993+
(gnuplot-debug (gnuplot-backtrace stack))
19881994
(gnuplot-debug (gnuplot-dump-captures))
19891995

19901996
(catch 'no-scan
@@ -2180,6 +2186,80 @@ command."
21802186
nil)))
21812187

21822188

2189+
;;;###autoload
2190+
(define-minor-mode gnuplot-context-sensitive-mode
2191+
"Use context-sensitive completion and help in gnuplot-mode.
2192+
2193+
When context-sensitive mode is enabled, gnuplot-mode tries to
2194+
provide more useful completions and help suggestions for built-in
2195+
keywords and functions by parsing each command as you type. It
2196+
attempts to take into account Gnuplot's many abbreviated
2197+
keywords. For example, with point at the end of a line reading
2198+
\"plot 'datafile' w \", typing \\[completion-at-point] will pop
2199+
up a list of plotting styles.
2200+
2201+
Key bindings:
2202+
2203+
\\[completion-at-point] will complete the keyword at point based
2204+
on its context in the command. To make keyword completion work on
2205+
pressing TAB, set `tab-always-indent' to `complete', or customize
2206+
`gnuplot-tab-completion' to make this automatic in gnuplot-mode
2207+
buffers.
2208+
2209+
\\[gnuplot-info-at-point] will try to find the most relevant
2210+
Gnuplot info node for the construction at point, prompting for a
2211+
node name if nothing is found.
2212+
2213+
\\[gnuplot-help-function] will pop up a brief summary of the
2214+
syntax at point in the minibuffer. To have one-line syntax
2215+
summaries appear in the echo area as you type, toggle
2216+
`eldoc-mode' or customize `gnuplot-eldoc-mode'.
2217+
2218+
To choose whether to use this mode by default in Gnuplot buffers,
2219+
customize the variable
2220+
`gnuplot-use-context-sensitive-completion'.
2221+
2222+
Note: help strings for eldoc-mode and \\[gnuplot-help-function]
2223+
need to be provided in an Emacs-readable form by the Gnuplot
2224+
distribution. See gnuplot-context.el for details."
2225+
:keymap
2226+
`((,(kbd "C-c C-/") . gnuplot-help-function)
2227+
(,(kbd "C-c C-d") . gnuplot-info-at-point))
2228+
(unless (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
2229+
(message "Gnuplot context-sensitive mode works only in Gnuplot-mode buffers")
2230+
(setq gnuplot-context-sensitive-mode nil))
2231+
(if gnuplot-context-sensitive-mode
2232+
;; Turn on
2233+
(progn
2234+
(setq gnuplot-completion-at-point-function #'gnuplot-context-completion-at-point)
2235+
2236+
;; Setup Eldoc
2237+
(setq-local eldoc-documentation-function #'gnuplot-eldoc-function)
2238+
(eldoc-add-command 'completion-at-point) ; Check for eldoc after completion
2239+
2240+
;; Try to load Eldoc strings
2241+
(when gnuplot-eldoc-mode
2242+
(unless gnuplot-eldoc-hash
2243+
(condition-case nil
2244+
(load-library "gnuplot-eldoc")
2245+
(error
2246+
(message "gnuplot-eldoc.el not found. Install it from the Gnuplot distribution.")
2247+
(setq gnuplot-eldoc-hash nil
2248+
gnuplot-eldoc-mode nil))))
2249+
2250+
(if gnuplot-eldoc-hash
2251+
(eldoc-mode 1)
2252+
(eldoc-mode 0)))
2253+
2254+
;; Set up tab-to-complete
2255+
(when gnuplot-tab-completion
2256+
(setq-local tab-always-indent 'complete)))
2257+
2258+
;; Turn off
2259+
(setq gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look)
2260+
(setq eldoc-documentation-function nil)
2261+
(eldoc-mode 0)))
2262+
21832263

21842264
;;; All done!
21852265
(provide 'gnuplot-context)

gnuplot-debug-context.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
;;
2-
;; debugging utilities for the gnuplot-mode context matcher
3-
;;
1+
;; debugging utilities for the gnuplot-mode context matcher -*- lexical-binding: t -*-
42

53
(require 'gnuplot-test-context) ; for gnuplot-simplify-tokens
64

@@ -56,7 +54,7 @@
5654
(defmacro gnuplot-trace (&rest args)
5755
`(with-gnuplot-trace-buffer (insert (format ,@args))))
5856

59-
(defun gnuplot-backtrace ()
57+
(defun gnuplot-backtrace (stack)
6058
(if stack
6159
(with-gnuplot-trace-buffer
6260
(insert "\n-- * backtrace: * --\n")

gnuplot-gui.el

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;;; gnuplot-gui.el -- GUI interface to setting options in gnuplot-mode
1+
;;;; gnuplot-gui.el -- GUI interface to setting options in gnuplot-mode -*- lexical-binding: t -*-
22

33
;; Copyright (C) 1998-2000 Bruce Ravel
44

@@ -805,6 +805,7 @@ This alist is formed at load time by appending together
805805
gnuplot-gui-test-type))
806806

807807

808+
;;;###autoload
808809
(defun gnuplot-gui-swap-simple-complete ()
809810
(interactive)
810811
(setq gnuplot-gui-plot-splot-fit-style
@@ -826,6 +827,7 @@ This alist is formed at load time by appending together
826827

827828
;;; user interface to the widget-y stuff
828829

830+
;;;###autoload
829831
(defun gnuplot-gui-mouse-set (event)
830832
"Use the mouse to begin setting options using a GUI interface.
831833
EVENT is a mouse event. Bound to \\[gnuplot-gui-mouse-set]
@@ -842,6 +844,7 @@ currently supported."
842844
(defun gnuplot-gui-set-frame-param (param value)
843845
(setcdr (assoc param gnuplot-gui-frame-parameters) value))
844846

847+
;;;###autoload
845848
(defun gnuplot-gui-set-options-and-insert ()
846849
"Insert arguments using a GUI interface.
847850
Determine contents of current line and set up the appropriate GUI
@@ -923,6 +926,7 @@ Note that \"cntrparam\" is not currently supported."
923926
(message
924927
"%S is not a gnuplot command which takes options" w)))) )))
925928

929+
;;;###autoload
926930
(defun gnuplot-gui-toggle-popup ()
927931
(interactive)
928932
(setq gnuplot-gui-popup-flag (not gnuplot-gui-popup-flag))
@@ -931,7 +935,6 @@ Note that \"cntrparam\" is not currently supported."
931935
"Argument popup will no longer appear after insertions.")))
932936

933937

934-
(defun gnuplot-gui-y-n (foo))
935938
(defalias 'gnuplot-gui-y-n 'y-or-n-p)
936939

937940
(defun gnuplot-gui-correct-command (word set term begin)
@@ -1312,7 +1315,7 @@ SAVE-FRAME is non-nil when the widgets are being reset."
13121315
:button-face 'gnuplot-gui-button-face
13131316
:help-echo "Push this button to set options"
13141317
:notify
1315-
(lambda (widget &rest ignore)
1318+
(lambda (widget &rest _ignore)
13161319
(kill-buffer (get-buffer-create "*Gnuplot GUI*"))
13171320
(delete-frame)
13181321
(select-frame gnuplot-current-frame)
@@ -1352,7 +1355,7 @@ SAVE-FRAME is non-nil when the widgets are being reset."
13521355
:button-face 'gnuplot-gui-button-face
13531356
:doc item
13541357
:notify
1355-
(lambda (widget &rest ignore)
1358+
(lambda (widget &rest _ignore)
13561359
(let ((word (widget-get widget :doc)))
13571360
(gnuplot-gui-set-alist word gnuplot-gui-current-string)
13581361
(gnuplot-gui-prompt-for-frame word t))))
@@ -1362,7 +1365,7 @@ SAVE-FRAME is non-nil when the widgets are being reset."
13621365
:button-face 'gnuplot-gui-button-face
13631366
:doc item
13641367
:notify
1365-
(lambda (widget &rest ignore)
1368+
(lambda (widget &rest _ignore)
13661369
(let* ((word (widget-get widget :doc))
13671370
(alist (cdr (assoc word gnuplot-gui-all-types))))
13681371
(while alist
@@ -1375,7 +1378,7 @@ SAVE-FRAME is non-nil when the widgets are being reset."
13751378
(widget-create 'push-button :value "Cancel"
13761379
:help-echo "Quit setting options and dismiss frame"
13771380
:button-face 'gnuplot-gui-button-face
1378-
:notify (lambda (widget &rest ignore)
1381+
:notify (lambda (_widget &rest _ignore)
13791382
(kill-buffer (get-buffer-create "*Gnuplot GUI*"))
13801383
(setq gnuplot-gui-alist nil
13811384
gnuplot-gui-current-string nil)
@@ -1425,7 +1428,7 @@ menu. STARRED is true if this a 'list* widget."
14251428
:button-prefix "[" :button-suffix "]"
14261429
:help-echo (format "Mouse-2 to view the %S menu" (downcase item))
14271430
:notify
1428-
(lambda (widget &rest ignore)
1431+
(lambda (widget &rest _ignore)
14291432
(let ((lab (if (widget-get widget :doc)
14301433
(concat (downcase (widget-get widget :tag)) " ")
14311434
"" )))
@@ -1450,7 +1453,7 @@ the numerical argument."
14501453
(widget-create 'editable-field
14511454
:size 2 :tag item :value default :doc prefix
14521455
:help-echo (format "Insert new value of %S here" help-label)
1453-
:notify (lambda (widget &rest ignore)
1456+
:notify (lambda (widget &rest _ignore)
14541457
(let ((val (widget-value widget))
14551458
(pre (concat (widget-get widget :doc) " ")))
14561459
(setcdr (assoc (widget-get widget :tag)
@@ -1486,7 +1489,7 @@ prefix for the string. STARRED is t if quotes are not to be used."
14861489
'editable-field
14871490
:size width :tag item :doc prefix :value default
14881491
:help-echo (format "Insert new value of %S here" help-label)
1489-
:notify (lambda (widget &rest ignore)
1492+
:notify (lambda (widget &rest _ignore)
14901493
(let ((val (widget-value widget))
14911494
(q gnuplot-quote-character)
14921495
(p (widget-get widget :doc)) )
@@ -1520,7 +1523,7 @@ prefix for the string."
15201523
(widget-create 'editable-field
15211524
:size (/ (frame-width) 3) :tag item :value default
15221525
:help-echo (format "Insert new format string here")
1523-
:notify (lambda (widget &rest ignore)
1526+
:notify (lambda (widget &rest _ignore)
15241527
(let ((val (widget-value widget)))
15251528
(setcdr (assoc (widget-get widget :tag)
15261529
gnuplot-gui-alist)
@@ -1574,7 +1577,7 @@ the default value for the argument. TAG is non-nil if ITEM rather than
15741577
:doc item :help-echo "Insert a filename here"
15751578
:complete 'gnuplot-gui-file-completion
15761579
:notify
1577-
(lambda (widget &rest ignore)
1580+
(lambda (widget &rest _ignore)
15781581
(setcdr (assoc (widget-get widget :doc) gnuplot-gui-alist)
15791582
(format "%s%s%s" gnuplot-quote-character
15801583
(widget-value widget)
@@ -1584,7 +1587,7 @@ the default value for the argument. TAG is non-nil if ITEM rather than
15841587
'push-button :value "Browse"
15851588
:doc item :help-echo "Browse directories for a filename."
15861589
:parent widg
1587-
:notify (lambda (widget &rest ignore)
1590+
:notify (lambda (widget &rest _ignore)
15881591
(let ((fname (file-relative-name (read-file-name "File: ")
15891592
default-directory))
15901593
(q gnuplot-quote-character))
@@ -1610,7 +1613,7 @@ the default value for the argument."
16101613
:format "%{%t%}:\n%v\t %i\n"
16111614
:entry-format "\t %i %d %v\n"
16121615
:button-face 'gnuplot-gui-labels-face
1613-
:notify (lambda (widget &rest ignore)
1616+
:notify (lambda (widget &rest _ignore)
16141617
(setcdr (assoc (upcase (widget-get widget :tag))
16151618
gnuplot-gui-alist)
16161619
(widget-value widget)))))
@@ -1627,7 +1630,7 @@ is non-nil if this is a 'range widget."
16271630
:size 4 :tag item :value (car default)
16281631
:help-echo (format "Insert the first value of the %S here"
16291632
(downcase item))
1630-
:notify (lambda (widget &rest ignore)
1633+
:notify (lambda (widget &rest _ignore)
16311634
(setcar (cdr (assoc (widget-get widget :tag)
16321635
gnuplot-gui-alist))
16331636
(format "%s" (widget-value widget)))))
@@ -1636,7 +1639,7 @@ is non-nil if this is a 'range widget."
16361639
:size 4 :tag item :value (cdr default)
16371640
:help-echo (format "Insert the second value of the %S here"
16381641
(downcase item))
1639-
:notify (lambda (widget &rest ignore)
1642+
:notify (lambda (widget &rest _ignore)
16401643
(setcdr (cdr (assoc (widget-get widget :tag)
16411644
gnuplot-gui-alist))
16421645
(format "%s" (widget-value widget)))))

gnuplot-test-context.el

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
;;
2-
;; automated tests for gnuplot-mode context matching
3-
;;
1+
;; automated tests for gnuplot-mode context matching -*- lexical-binding: t -*-
42

53
(require 'gnuplot-context)
64

gnuplot-tests.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; Tests for gnuplot-mode.
1+
;;; Tests for gnuplot-mode. -*- lexical-binding: t -*-
22

33
;;; Currently these attempt to cover the correct identification of
44
;;; string and comment syntax.

0 commit comments

Comments
 (0)