emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gnuplot b7f43bff2a 05/11: Move gnuplot-context-sensitive-m


From: ELPA Syncer
Subject: [nongnu] elpa/gnuplot b7f43bff2a 05/11: Move gnuplot-context-sensitive-mode to gnuplot-context.el with proper autoloading
Date: Sun, 2 Jan 2022 11:58:18 -0500 (EST)

branch: elpa/gnuplot
commit b7f43bff2aedb7829b42c5609b3b976e97791f29
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Move gnuplot-context-sensitive-mode to gnuplot-context.el with proper 
autoloading
---
 gnuplot-context.el |  80 ++++++++++++++++++++++++++++++++++++++++++
 gnuplot.el         | 100 +++++++----------------------------------------------
 2 files changed, 92 insertions(+), 88 deletions(-)

diff --git a/gnuplot-context.el b/gnuplot-context.el
index e89f947f90..67f15b0ab0 100644
--- a/gnuplot-context.el
+++ b/gnuplot-context.el
@@ -1755,6 +1755,12 @@ name specified in the (capture NAME PATTERN) form in the
 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'.")
+
 
 ;;;; The pattern matching machine
 (defun gnuplot-match-pattern (instructions tokens completing-p
@@ -2180,6 +2186,80 @@ command."
       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)))
+
 
 ;;; All done!
 (provide 'gnuplot-context)
diff --git a/gnuplot.el b/gnuplot.el
index 561d7fc455..69c03c5708 100644
--- a/gnuplot.el
+++ b/gnuplot.el
@@ -335,13 +335,20 @@ command line to provide smarter completion and 
documentation
 suggestions."
   :group 'gnuplot
   :type 'boolean
-  :initialize 'custom-set-default
-  :set (lambda (_sym value)
+  :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 (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
-               (gnuplot-context-sensitive-mode
-                (if value 1 0))))))
+             (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
@@ -512,7 +519,6 @@ non-nil."
 
 ;;; --- 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'.
@@ -1953,88 +1959,6 @@ Return a list of keywords."
   "Perform completion in Gnuplot buffers."
   (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
-        (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)))
-
 ;; Older completion method using info-look
 (defun gnuplot-completion-at-point-info-look ()
   "Return completions of keyword preceding point.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]