Commit 40efb8e8 authored by joddie's avatar joddie

Make loading of gnuplot work with and without gnuplot-context.

This is a bit tricky and there may well be a better solution.  Here's
how it works:

- gnuplot-context.el is not loaded automatically by gnuplot.el

- function `gnuplot-context-sensitive-mode', the main on/off switch
  for contextual parsing, is defined in `gnuplot-context.el' and
  marked as autoloaded in `gnuplot.el'. This makes the menu item and
  M-x gnuplot-context-sensitive-mode work, by loading the
  gnuplot-context library as soon as it's needed

- defcustoms relating to context-sensitive mode are in gnuplot.el, so
  that context mode can be discovered and enabled without an explicit
  (require 'gnuplot-context). A special :set function for the
  defcustom `gnuplot-context-sensitive-mode' loads gnuplot-context.el
  only if enabling the mode. defcustom has a :require option which
  seems like it would be made for this, but in fact it loads the
  library independent of whether it's enabled or not, AFAICT.
parent e02534cb
......@@ -272,7 +272,7 @@ These have to be compiled from the Gnuplot source tree using
(setq gnuplot-eldoc-hash (make-hash-table))))
;;;; Customization interface, etc.
;;;; Interface to turning the mode on and off
(defun gnuplot-context-sensitive-mode (&optional enable)
"Turn gnuplot-mode context-sensitive completion and help on and off.
......@@ -309,39 +309,57 @@ off. With no argument, toggle context-sensitive mode."
(interactive "P")
(setq gnuplot-context-sensitive-mode
(if (null enable) (not gnuplot-context-sensitive-mode)
(> (prefix-numeric-value enable) 0)))
(> (prefix-numeric-value enable) 0)))
(if gnuplot-context-sensitive-mode
;; Turn on
(progn
(when (called-interactively-p 'any)
(message "Gnuplot context-sensitive help & completion enabled."))
(ad-enable-advice 'gnuplot-completion-at-point
'around 'gnuplot-context)
(ad-activate 'gnuplot-completion-at-point)
(dolist (keymap (list gnuplot-mode-map gnuplot-comint-mode-map))
(define-key keymap (kbd "C-c M-h") 'gnuplot-help-function)
(define-key keymap (kbd "C-c C-/") 'gnuplot-help-function)
(define-key keymap (kbd "C-c C-d") 'gnuplot-info-at-point))
(define-key gnuplot-comint-mode-map (kbd "TAB") 'comint-dynamic-complete)
(add-hook 'gnuplot-mode-hook 'gnuplot-setup-eldoc)
(add-hook 'gnuplot-comint-mode-hook 'gnuplot-setup-eldoc))
(eval-after-load 'gnuplot '(gnuplot--turn-on-context-sensitive-mode)))
;; Turn off
(when (called-interactively-p 'any)
(message "Gnuplot context-sensitive help & completion disabled."))
(dolist (keymap (list gnuplot-mode-map gnuplot-comint-mode-map))
(define-key keymap (kbd "C-c M-h") 'undefined)
(define-key keymap (kbd "C-c C-/") 'undefined)
(define-key keymap (kbd "C-c C-d") 'gnuplot-info-lookup-symbol))
(ad-disable-advice 'gnuplot-completion-at-point
'around 'gnuplot-context)
(ad-activate 'gnuplot-completion-at-point)
(remove-hook 'gnuplot-mode-hook 'gnuplot-setup-eldoc)
(remove-hook 'gnuplot-comint-mode-hook 'gnuplot-setup-eldoc)
(eval-after-load 'gnuplot '(gnuplot--turn-off-context-sensitive-mode))))
(eval-when-compile
(defmacro gnuplot-foreach-buffer (&rest forms)
(declare (indent 0))
`(dolist (buf (buffer-list))
(when (memq (buffer-local-value 'major-mode buf)
'(gnuplot-mode gnuplot-comint-mode))
(with-current-buffer buf
,@forms)))))
(defun gnuplot--turn-on-context-sensitive-mode ()
(ad-enable-advice 'gnuplot-completion-at-point
'around 'gnuplot-context)
(ad-activate 'gnuplot-completion-at-point)
(dolist (keymap (list gnuplot-mode-map gnuplot-comint-mode-map))
(define-key keymap (kbd "C-c M-h") 'gnuplot-help-function)
(define-key keymap (kbd "C-c C-/") 'gnuplot-help-function)
(define-key keymap (kbd "C-c C-d") 'gnuplot-info-at-point))
(define-key gnuplot-comint-mode-map (kbd "TAB") 'comint-dynamic-complete)
(add-hook 'gnuplot-mode-hook 'gnuplot-setup-eldoc)
(add-hook 'gnuplot-comint-mode-hook 'gnuplot-setup-eldoc)
(gnuplot-foreach-buffer (gnuplot-setup-eldoc)))
(defun gnuplot--turn-off-context-sensitive-mode ()
(dolist (keymap (list gnuplot-mode-map gnuplot-comint-mode-map))
(define-key keymap (kbd "C-c M-h") 'undefined)
(define-key keymap (kbd "C-c C-/") 'undefined)
(define-key keymap (kbd "C-c C-d") 'gnuplot-info-lookup-symbol))
(ad-disable-advice 'gnuplot-completion-at-point
'around 'gnuplot-context)
(ad-activate 'gnuplot-completion-at-point)
(remove-hook 'gnuplot-mode-hook 'gnuplot-setup-eldoc)
(remove-hook 'gnuplot-comint-mode-hook 'gnuplot-setup-eldoc)
(gnuplot-foreach-buffer
(setq eldoc-documentation-function nil)
(eldoc-mode 0)))
;; Has to be defined here. Grumble.
......@@ -350,36 +368,6 @@ off. With no argument, toggle context-sensitive mode."
;; context-sensitivity on and off
(setq ad-return-value (gnuplot-context-completion-at-point)))
(defcustom gnuplot-context-sensitive-mode nil
"Whether context-sensitive completion and help for gnuplot are enabled.
With context-sensitive mode on, gnuplot-mode's tab completion and
info file lookup try to parse the current command line to find
the most useful completions or info pages.
Don't set this variable from Lisp code; instead, use Customize or
call the `gnuplot-context-sensitive-mode' function, which behaves
like a minor mode."
:group 'gnuplot
:type 'boolean
:set 'custom-set-minor-mode
:link '(emacs-commentary-link "gnuplot-context"))
(defcustom gnuplot-eldoc-mode nil
"Whether to enable ElDoc mode by default in Gnuplot buffers.
ElDoc support requires `gnuplot-context-sensitive-mode' to be
on."
:group 'gnuplot
:type 'boolean)
(defcustom gnuplot-tab-completion nil
"Whether the TAB key 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-setup-eldoc ()
(set (make-local-variable 'eldoc-documentation-function)
'gnuplot-eldoc-function)
......@@ -2322,4 +2310,4 @@ command."
;;; All done!
(provide 'gnuplot-context)
;;; gnuplot-context.el ends here
\ No newline at end of file
;;; gnuplot-context.el ends here
......@@ -5,8 +5,8 @@
;; Author: Bruce Ravel <bruceravel1@gmail.com> and Phil Type
;; Maintainer: Bruce Ravel <bruceravel1@gmail.com>
;; Created: June 28 1998
;; Updated: April 20 2012
;; Version: 0.6.1
;; Updated: October 05 2012
;; Version: 0.7
;; Keywords: gnuplot, plotting
;; This file is not part of GNU Emacs.
......@@ -96,6 +96,15 @@
;; 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.oddie@gmail.com)
;; Provides context-sensitive completion, help lookup and eldoc
;; strings for gnuplot buffers. This is somewhat experimental, which
;; is why it is a separate library for now. It should be
;; byte-compiled before using. Run `gnuplot-context-sensitive-mode'
;; (which autoloads the file) to try it out, and see the commentary
;; of gnuplot-context.el for more.
;;
;; ---------------------------------------------------------------------
;;
;; This mode was inspired by the original gnu-plot-mode by Gershon
......@@ -283,6 +292,9 @@
;; 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 Oct 20 2012 <jjo> Contextual completion & help, inline plots,
;; some other stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Acknowledgements:
;; David Batty <DB> (numerous corrections)
......@@ -303,6 +315,8 @@
;; 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
......@@ -357,7 +371,7 @@
(defconst gnuplot-maintainer-email "ravel@phys.washington.edu")
(defconst gnuplot-maintainer-url
"http://github.com/bruceravel/gnuplot-mode/")
(defconst gnuplot-version "0.6.1")
(defconst gnuplot-version "0.7")
(defgroup gnuplot nil
"Gnuplot-mode for Emacs."
......@@ -591,6 +605,51 @@ you're not using that musty old thing, are you..."
'(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-mode (variable value)
"Turn context-sensitive mode on or off through Customize.
Unlike the built-in custom-set-minor-mode, this avoids loading
gnuplot-context if it is not being enabled."
(if (featurep 'gnuplot-context)
;; Already loaded, OK to enable or disable
(gnuplot-context-sensitive-mode (if value 1 0))
;; Not loaded; load gnuplot-context only if enabling
(if value
(progn
(load "gnuplot-context")
(gnuplot-context-sensitive-mode 1))
(setq gnuplot-context-sensitive-mode nil))))
(defcustom gnuplot-context-sensitive-mode nil
"Non-nil if contextual completion and help for gnuplot are enabled.
With context-sensitive mode on, gnuplot-mode's tab completion and
info file lookup try to parse the current command line to find
the most useful completions or info pages.
Don't set this variable from Lisp code; instead, use Customize or
call the `gnuplot-context-sensitive-mode' function, which behaves
like a minor mode."
:group 'gnuplot
:type 'boolean
:set 'gnuplot-set-context-mode
: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)
(defgroup gnuplot-faces nil
"Text faces used by gnuplot-mode."
:prefix "gnuplot-"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment