Mercurial > emacs
changeset 104508:90ca5d588aa9
* 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.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 21 Sep 2009 15:59:48 +0000 |
parents | 51e316109fba |
children | 32af6b5a433d |
files | lisp/ChangeLog lisp/bindings.el lisp/cedet/semantic.el lisp/cedet/semantic/idle.el lisp/cedet/semantic/util.el |
diffstat | 5 files changed, 135 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Mon Sep 21 02:26:07 2009 +0000 +++ b/lisp/ChangeLog Mon Sep 21 15:59:48 2009 +0000 @@ -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.
--- a/lisp/bindings.el Mon Sep 21 02:26:07 2009 +0000 +++ b/lisp/bindings.el Mon Sep 21 15:59:48 2009 +0000 @@ -678,13 +678,20 @@ 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.
--- a/lisp/cedet/semantic.el Mon Sep 21 02:26:07 2009 +0000 +++ b/lisp/cedet/semantic.el Mon Sep 21 15:59:48 2009 +0000 @@ -906,6 +906,37 @@ (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)
--- a/lisp/cedet/semantic/idle.el Mon Sep 21 02:26:07 2009 +0000 +++ b/lisp/cedet/semantic/idle.el Mon Sep 21 15:59:48 2009 +0000 @@ -612,7 +612,7 @@ `(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")
--- a/lisp/cedet/semantic/util.el Mon Sep 21 02:26:07 2009 +0000 +++ b/lisp/cedet/semantic/util.el Mon Sep 21 15:59:48 2009 +0000 @@ -437,6 +437,82 @@ (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