Skip to content

Commit b7f43bf

Browse files
committed
Move gnuplot-context-sensitive-mode to gnuplot-context.el with proper autoloading
1 parent 68508cd commit b7f43bf

File tree

2 files changed

+92
-88
lines changed

2 files changed

+92
-88
lines changed

gnuplot-context.el

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -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.el

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,20 @@ command line to provide smarter completion and documentation
335335
suggestions."
336336
:group 'gnuplot
337337
:type 'boolean
338-
:initialize 'custom-set-default
339-
:set (lambda (_sym value)
338+
:set (lambda (sym value)
339+
(set sym value)
340+
(cond
341+
(value
342+
(add-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode nil nil)
343+
(add-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode nil nil))
344+
(t
345+
(remove-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode)
346+
(remove-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode)))
340347
(dolist (buffer (buffer-list))
341348
(with-current-buffer buffer
342-
(when (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
343-
(gnuplot-context-sensitive-mode
344-
(if value 1 0))))))
349+
(when (and (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
350+
(fboundp 'gnuplot-context-sensitive-mode))
351+
(gnuplot-context-sensitive-mode (if value 1 0))))))
345352
:link '(emacs-commentary-link "gnuplot-context"))
346353

347354
(defcustom gnuplot-eldoc-mode nil
@@ -512,7 +519,6 @@ non-nil."
512519

513520
;;; --- insertions variables and menus
514521

515-
;;(load-library "gnuplot-insertions")
516522
(defvar gnuplot-mode-insertions-menu nil)
517523
(defvar gnuplot-insertions-menu nil
518524
"Menu for insertions in `gnuplot-mode'.
@@ -1953,88 +1959,6 @@ Return a list of keywords."
19531959
"Perform completion in Gnuplot buffers."
19541960
(funcall gnuplot-completion-at-point-function))
19551961

1956-
(defvar gnuplot-eldoc-hash nil
1957-
"ElDoc strings for gnuplot-mode.
1958-
1959-
These have to be compiled from the Gnuplot source tree using
1960-
`doc2texi.el'.")
1961-
1962-
;; Enable and disable context-sensitive completion
1963-
(define-minor-mode gnuplot-context-sensitive-mode
1964-
"Use context-sensitive completion and help in gnuplot-mode.
1965-
1966-
When context-sensitive mode is enabled, gnuplot-mode tries to
1967-
provide more useful completions and help suggestions for built-in
1968-
keywords and functions by parsing each command as you type. It
1969-
attempts to take into account Gnuplot's many abbreviated
1970-
keywords. For example, with point at the end of a line reading
1971-
\"plot 'datafile' w \", typing \\[completion-at-point] will pop
1972-
up a list of plotting styles.
1973-
1974-
Key bindings:
1975-
1976-
\\[completion-at-point] will complete the keyword at point based
1977-
on its context in the command. To make keyword completion work on
1978-
pressing TAB, set `tab-always-indent' to `complete', or customize
1979-
`gnuplot-tab-completion' to make this automatic in gnuplot-mode
1980-
buffers.
1981-
1982-
\\[gnuplot-info-at-point] will try to find the most relevant
1983-
Gnuplot info node for the construction at point, prompting for a
1984-
node name if nothing is found.
1985-
1986-
\\[gnuplot-help-function] will pop up a brief summary of the
1987-
syntax at point in the minibuffer. To have one-line syntax
1988-
summaries appear in the echo area as you type, toggle
1989-
`eldoc-mode' or customize `gnuplot-eldoc-mode'.
1990-
1991-
To choose whether to use this mode by default in Gnuplot buffers,
1992-
customize the variable
1993-
`gnuplot-use-context-sensitive-completion'.
1994-
1995-
Note: help strings for eldoc-mode and \\[gnuplot-help-function]
1996-
need to be provided in an Emacs-readable form by the Gnuplot
1997-
distribution. See gnuplot-context.el for details."
1998-
:keymap
1999-
`((,(kbd "C-c C-/") . gnuplot-help-function)
2000-
(,(kbd "C-c C-d") . gnuplot-info-at-point))
2001-
(unless (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
2002-
(message "Gnuplot context-sensitive mode works only in Gnuplot-mode buffers")
2003-
(setq gnuplot-context-sensitive-mode nil))
2004-
(if gnuplot-context-sensitive-mode
2005-
;; Turn on
2006-
(progn
2007-
(load-library "gnuplot-context")
2008-
(load-library "eldoc")
2009-
(setq gnuplot-completion-at-point-function #'gnuplot-context-completion-at-point)
2010-
2011-
;; Setup Eldoc
2012-
(setq-local eldoc-documentation-function #'gnuplot-eldoc-function)
2013-
(eldoc-add-command 'completion-at-point) ; Check for eldoc after completion
2014-
2015-
;; Try to load Eldoc strings
2016-
(when gnuplot-eldoc-mode
2017-
(unless gnuplot-eldoc-hash
2018-
(condition-case nil
2019-
(load-library "gnuplot-eldoc")
2020-
(error
2021-
(message "gnuplot-eldoc.el not found. Install it from the Gnuplot distribution.")
2022-
(setq gnuplot-eldoc-hash nil
2023-
gnuplot-eldoc-mode nil))))
2024-
2025-
(if gnuplot-eldoc-hash
2026-
(eldoc-mode 1)
2027-
(eldoc-mode 0)))
2028-
2029-
;; Set up tab-to-complete
2030-
(when gnuplot-tab-completion
2031-
(setq-local tab-always-indent 'complete)))
2032-
2033-
;; Turn off
2034-
(setq gnuplot-completion-at-point-function #'gnuplot-completion-at-point-info-look)
2035-
(setq eldoc-documentation-function nil)
2036-
(eldoc-mode 0)))
2037-
20381962
;; Older completion method using info-look
20391963
(defun gnuplot-completion-at-point-info-look ()
20401964
"Return completions of keyword preceding point.

0 commit comments

Comments
 (0)