]> code.delx.au - gnu-emacs/commitdiff
* cedet/semantic.el: Add autoloads for semantic/idle functions.
authorChong Yidong <cyd@stupidchicken.com>
Mon, 21 Sep 2009 15:59:48 +0000 (15:59 +0000)
committerChong Yidong <cyd@stupidchicken.com>
Mon, 21 Sep 2009 15:59:48 +0000 (15:59 +0000)
* cedet/semantic/util.el (semantic--completion-cache): New var.
(semantic-symbol-start, semantic-find-tag-for-completion)
(semantic-complete-symbol): New functions, adapted from Senator.

* bindings.el (complete-symbol): Try semantic-complete-symbol if
no tag table is active.

* cedet/semantic/idle.el (define-semantic-idle-service): Doc fix.

lisp/ChangeLog
lisp/bindings.el
lisp/cedet/semantic.el
lisp/cedet/semantic/idle.el
lisp/cedet/semantic/util.el

index 3f4b8f705aedd18cdeadda2bb5e54a0fdb37199a..e9805247938a1b608ec7a047f1cd1d2fd6043ae9 100644 (file)
@@ -1,3 +1,16 @@
+2009-09-21  Chong Yidong  <cyd@stupidchicken.com>
+
+       * cedet/semantic.el: Add autoloads for semantic/idle functions.
+
+       * cedet/semantic/util.el (semantic--completion-cache): New var.
+       (semantic-symbol-start, semantic-find-tag-for-completion)
+       (semantic-complete-symbol): New functions, adapted from Senator.
+
+       * bindings.el (complete-symbol): Try semantic-complete-symbol if
+       no tag table is active.
+
+       * cedet/semantic/idle.el (define-semantic-idle-service): Doc fix.
+
 2009-09-21  Chong Yidong  <cyd@stupidchicken.com>
 
        * menu-bar.el: Remove ediff-misc from Tools menu.
index c4c1c78674d1631dad8dbb72e74eb0c995677a25..6e23b972ad9fef9384be89a34712c30c8ad49064 100644 (file)
@@ -678,13 +678,20 @@ With a prefix argument, this command does completion within
 the collection of symbols listed in the index of the manual for the
 language you are using."
   (interactive "P")
-  (if arg
-      (info-complete-symbol)
-    (if (fboundp 'complete-tag)
-       (complete-tag)
-      ;; Don't autoload etags if we have no tags table.
-      (error "%s" (substitute-command-keys
-             "No tags table loaded; use \\[visit-tags-table] to load one")))))
+  (cond (arg
+        (info-complete-symbol))
+       ;; Don't autoload etags if we have no tags table.
+       ((or tags-table-list
+            tags-file-name)
+        (complete-tag))
+       ((and (fboundp 'semantic-active-p)
+             (semantic-active-p)
+             (fboundp 'semantic-complete-symbol))
+        (semantic-complete-symbol))
+       (t
+        (error "%s" (substitute-command-keys
+                     "No tags table loaded; \
+use \\[visit-tags-table] to load one")))))
 
 ;; Reduce total amount of space we must allocate during this function
 ;; that we will not need to keep permanently.
index 5596bda981bae9eef18fb9a76f3e8bed80fa8076..17c31a65c7fc08732ae88622f338bba916474066 100644 (file)
@@ -906,6 +906,37 @@ Semantic mode."
       (if (and (boundp mode) (eval mode))
          (funcall mode -1)))))
 
+;;; Autoload some functions that are not in semantic/loaddefs
+
+(autoload 'global-semantic-idle-completions-mode "semantic/idle"
+  "Toggle global use of `semantic-idle-completions-mode'.
+If ARG is positive, enable, if it is negative, disable.
+If ARG is nil, then toggle." t nil)
+
+(autoload 'semantic-idle-completions-mode "semantic/idle"
+  "Display a list of possible completions in a tooltip.
+
+This is a minor mode which performs actions during idle time.
+With prefix argument ARG, turn on if positive, otherwise off.  The
+minor mode can be turned on only if semantic feature is available and
+the current buffer was set up for parsing.  Return non-nil if the
+minor mode is enabled." t nil)
+
+(autoload 'global-semantic-idle-summary-mode "semantic/idle"
+  "Toggle global use of `semantic-idle-summary-mode'.
+If ARG is positive, enable, if it is negative, disable.
+If ARG is nil, then toggle." t nil)
+
+(autoload 'semantic-idle-summary-mode "semantic/idle"
+  "Display a tag summary of the lexical token under the cursor.
+Call `semantic-idle-summary-current-symbol-info' for getting the
+current tag to display information.
+
+This is a minor mode which performs actions during idle time.
+With prefix argument ARG, turn on if positive, otherwise off.  The
+minor mode can be turned on only if semantic feature is available and
+the current buffer was set up for parsing.  Return non-nil if the
+minor mode is enabled." t nil)
 
 (provide 'semantic)
 
index e3ae984ae98e6a484481beb7c1730e6bc771cbc4..87da3cbd2cccfebf047f230c213043156196dbd0 100644 (file)
@@ -612,7 +612,7 @@ This routines creates the following functions and variables:"
 
     `(eval-and-compile
        (defun ,global (&optional arg)
-        ,(concat "Toggle global use of option `" (symbol-name mode) "'.
+        ,(concat "Toggle global use of `" (symbol-name mode) "'.
 If ARG is positive, enable, if it is negative, disable.
 If ARG is nil, then toggle.")
         (interactive "P")
index 7981f75c30c083e4affce4e96253a592a3adb935..5d22cd068bd9fa83800d5985be8ed4b10470597e 100644 (file)
@@ -437,6 +437,82 @@ NOTFIRST indicates that this was not the first call in the recursive use."
        (message "Remaining overlays: %S" o)))
   over)
 
+;;; Interactive commands (from Senator).
+
+;; The Senator library from upstream CEDET is not included in the
+;; built-in version of Emacs.  The plan is to fold it into the
+;; different parts of CEDET and Emacs, so that it works
+;; "transparently".  Here are some interactive commands based on
+;; Senator.
+
+(defvar semantic--completion-cache nil
+  "Internal variable used by `senator-complete-symbol'.")
+
+(defsubst semantic-symbol-start (pos)
+  "Return the start of the symbol at buffer position POS."
+  (car (nth 2 (semantic-ctxt-current-symbol-and-bounds pos))))
+
+(defun semantic-find-tag-for-completion (prefix)
+  "Find all tags with name starting with PREFIX.
+This uses `semanticdb' when available."
+  (let (result ctxt)
+    (condition-case nil
+       (and (featurep 'semantic/analyze)
+            (setq ctxt (semantic-analyze-current-context))
+            (setq result (semantic-analyze-possible-completions ctxt)))
+      (error nil))
+    (or result
+       ;; If the analyzer fails, then go into boring completion.
+       (if (and (featurep 'semantic/db) (semanticdb-minor-mode-p))
+           (semanticdb-fast-strip-find-results
+            (semanticdb-deep-find-tags-for-completion prefix))
+         (semantic-deep-find-tags-for-completion prefix (current-buffer))))))
+
+(defun semantic-complete-symbol (&optional predicate)
+  "Complete the symbol under point, using Semantic facilities.
+When called from a program, optional arg PREDICATE is a predicate
+determining which symbols are considered."
+  (interactive)
+  (let* ((start (car (nth 2 (semantic-ctxt-current-symbol-and-bounds
+                            (point)))))
+        (pattern (regexp-quote (buffer-substring start (point))))
+        collection completion)
+    (when start
+      (if (and semantic--completion-cache
+              (eq (nth 0 semantic--completion-cache) (current-buffer))
+              (=  (nth 1 semantic--completion-cache) start)
+              (save-excursion
+                (goto-char start)
+                (looking-at (nth 3 semantic--completion-cache))))
+         ;; Use cached value.
+         (setq collection (nthcdr 4 semantic--completion-cache))
+       ;; Perform new query.
+       (setq collection (semantic-find-tag-for-completion pattern))
+       (setq semantic--completion-cache
+             (append (list (current-buffer) start 0 pattern)
+                     collection))))
+    (if (null collection)
+       (let ((str (if pattern (format " for \"%s\"" pattern) "")))
+         (if (window-minibuffer-p (selected-window))
+             (minibuffer-message (format " [No completions%s]" str))
+           (message "Can't find completion%s" str)))
+      (setq completion (try-completion pattern collection predicate))
+      (if (string= pattern completion)
+         (let ((list (all-completions pattern collection predicate)))
+           (setq list (sort list 'string<))
+           (if (> (length list) 1)
+               (with-output-to-temp-buffer "*Completions*"
+                 (display-completion-list list pattern))
+             ;; Bury any out-of-date completions buffer.
+             (let ((win (get-buffer-window "*Completions*" 0)))
+               (if win (with-selected-window win (bury-buffer))))))
+       ;; Exact match
+       (delete-region start (point))
+       (insert completion)
+       ;; Bury any out-of-date completions buffer.
+       (let ((win (get-buffer-window "*Completions*" 0)))
+         (if win (with-selected-window win (bury-buffer))))))))
+
 (provide 'semantic/util)
 
 ;;; Minor modes