diff options
author | Chong Yidong <cyd@stupidchicken.com> | 2009-09-21 15:59:48 +0000 |
---|---|---|
committer | Chong Yidong <cyd@stupidchicken.com> | 2009-09-21 15:59:48 +0000 |
commit | af7b5a91b2c7e4f3ee18f72192d7baa572d03735 (patch) | |
tree | 2e891245bc618f1a24e8c084cc5f021d571522d4 | |
parent | 602a8d7e4fa3616878f9161c4431bdd4b3b0fb04 (diff) | |
download | emacs-af7b5a91b2c7e4f3ee18f72192d7baa572d03735.tar.gz |
* 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.
-rw-r--r-- | lisp/ChangeLog | 13 | ||||
-rw-r--r-- | lisp/bindings.el | 21 | ||||
-rw-r--r-- | lisp/cedet/semantic.el | 31 | ||||
-rw-r--r-- | lisp/cedet/semantic/idle.el | 2 | ||||
-rw-r--r-- | lisp/cedet/semantic/util.el | 76 |
5 files changed, 135 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3f4b8f705ae..e9805247938 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,18 @@ 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. * cedet/semantic.el (semantic-init-hook) diff --git a/lisp/bindings.el b/lisp/bindings.el index c4c1c78674d..6e23b972ad9 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -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. diff --git a/lisp/cedet/semantic.el b/lisp/cedet/semantic.el index 5596bda981b..17c31a65c7f 100644 --- a/lisp/cedet/semantic.el +++ b/lisp/cedet/semantic.el @@ -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) diff --git a/lisp/cedet/semantic/idle.el b/lisp/cedet/semantic/idle.el index e3ae984ae98..87da3cbd2cc 100644 --- a/lisp/cedet/semantic/idle.el +++ b/lisp/cedet/semantic/idle.el @@ -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") diff --git a/lisp/cedet/semantic/util.el b/lisp/cedet/semantic/util.el index 7981f75c30c..5d22cd068bd 100644 --- a/lisp/cedet/semantic/util.el +++ b/lisp/cedet/semantic/util.el @@ -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 |