123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- (require 'semantic/analyze)
- (require 'speedbar)
- (defvar semantic-ia-sb-key-map nil
- "Keymap used when in semantic analysis display mode.")
- (if semantic-ia-sb-key-map
- nil
- (setq semantic-ia-sb-key-map (speedbar-make-specialized-keymap))
-
- (define-key semantic-ia-sb-key-map "\C-m" 'speedbar-edit-line)
- (define-key semantic-ia-sb-key-map "I" 'semantic-ia-sb-show-tag-info)
- )
- (defvar semantic-ia-sb-easymenu-definition
- '( "---"
- [ "Tag Information" semantic-ia-sb-show-tag-info t ]
- [ "Jump to Tag" speedbar-edit-line t ]
- [ "Complete" speedbar-edit-line t ]
- )
- "Extra menu items Analysis mode.")
- (speedbar-add-expansion-list '("Analyze"
- semantic-ia-sb-easymenu-definition
- semantic-ia-sb-key-map
- semantic-ia-speedbar))
- (speedbar-add-mode-functions-list
- (list "Analyze"
-
- '(speedbar-line-directory . semantic-ia-sb-line-path)))
- (defun semantic-speedbar-analysis ()
- "Start Speedbar in semantic analysis mode.
- The analyzer displays information about the current context, plus a smart
- list of possible completions."
- (interactive)
-
- (speedbar-frame-mode 1)
-
- (speedbar-change-initial-expansion-list "Analyze")
- )
- (defun semantic-ia-speedbar (directory zero)
- "Create buttons in speedbar which define the current analysis at POINT.
- DIRECTORY is the current directory, which is ignored, and ZERO is 0."
- (let ((analysis nil)
- (scope nil)
- (buffer nil)
- (completions nil)
- (cf (selected-frame))
- (cnt nil)
- (mode-local-active-mode nil)
- )
-
- (condition-case nil
- (progn
- (speedbar-select-attached-frame)
- (setq buffer (current-buffer))
- (setq mode-local-active-mode major-mode)
- (save-excursion
-
- (setq scope (semantic-calculate-scope (point)))
-
- (setq analysis (semantic-analyze-current-context (point)))
- (setq cnt (semantic-find-tag-by-overlay))
- (when analysis
- (setq completions (semantic-analyze-possible-completions analysis))
- )
- ))
- (error nil))
- (select-frame cf)
- (with-current-buffer speedbar-buffer
-
- (erase-buffer)
- (speedbar-insert-separator "Buffer/Function")
-
- (speedbar-make-tag-line 'bracket ? nil nil
- (buffer-name buffer)
- nil nil 'speedbar-file-face 0)
- (when cnt
- (semantic-ia-sb-string-list cnt
- 'speedbar-tag-face
- 'semantic-sb-token-jump))
- (when analysis
-
-
- (semantic-ia-sb-show-doc analysis))
- (when analysis
-
- (semantic-ia-sb-more-buttons analysis)
- (when completions
- (speedbar-insert-separator "Completions")
- (semantic-ia-sb-completion-list completions
- 'speedbar-tag-face
- 'semantic-ia-sb-complete))
- )
-
- (when scope
- (semantic-ia-sb-show-scope scope))
- )))
- (defmethod semantic-ia-sb-show-doc ((context semantic-analyze-context))
- "Show documentation about CONTEXT iff CONTEXT points at a complete symbol."
- (let ((sym (car (reverse (oref context prefix))))
- (doc nil))
- (when (semantic-tag-p sym)
- (setq doc (semantic-documentation-for-tag sym))
- (when doc
- (speedbar-insert-separator "Documentation")
- (insert doc)
- (insert "\n")
- ))
- ))
- (defun semantic-ia-sb-show-scope (scope)
- "Show SCOPE information."
- (let ((localvars (when scope
- (oref scope localvar)))
- )
- (when localvars
- (speedbar-insert-separator "Local Variables")
- (semantic-ia-sb-string-list localvars
- 'speedbar-tag-face
-
- 'semantic-sb-token-jump))))
- (defmethod semantic-ia-sb-more-buttons ((context semantic-analyze-context))
- "Show a set of speedbar buttons specific to CONTEXT."
- (let ((prefix (oref context prefix)))
- (when prefix
- (speedbar-insert-separator "Prefix")
- (semantic-ia-sb-string-list prefix
- 'speedbar-tag-face
- 'semantic-sb-token-jump))
- ))
- (defmethod semantic-ia-sb-more-buttons ((context semantic-analyze-context-assignment))
- "Show a set of speedbar buttons specific to CONTEXT."
- (call-next-method)
- (let ((assignee (oref context assignee)))
- (when assignee
- (speedbar-insert-separator "Assignee")
- (semantic-ia-sb-string-list assignee
- 'speedbar-tag-face
- 'semantic-sb-token-jump))))
- (defmethod semantic-ia-sb-more-buttons ((context semantic-analyze-context-functionarg))
- "Show a set of speedbar buttons specific to CONTEXT."
- (call-next-method)
- (let ((func (oref context function)))
- (when func
- (speedbar-insert-separator "Function")
- (semantic-ia-sb-string-list func
- 'speedbar-tag-face
- 'semantic-sb-token-jump)
-
- (let ((arg (oref context argument))
- (args (semantic-tag-function-arguments (car func)))
- (idx 0)
- )
- (speedbar-insert-separator
- (format "Argument #%d" (oref context index)))
- (if args
- (semantic-ia-sb-string-list args
- 'speedbar-tag-face
- 'semantic-sb-token-jump
- (oref context index)
- 'speedbar-selected-face)
-
- (semantic-ia-sb-string-list arg
- 'speedbar-tag-face
- 'semantic-sb-token-jump))
- ))))
- (defun semantic-ia-sb-string-list (list face function &optional idx idxface)
- "Create some speedbar buttons from LIST.
- Each button will use FACE, and be activated with FUNCTION.
- Optional IDX is an index into LIST to apply IDXFACE instead."
- (let ((count 1))
- (while list
- (let* ((usefn nil)
- (string (cond ((stringp (car list))
- (car list))
- ((semantic-tag-p (car list))
- (setq usefn (semantic-tag-with-position-p (car list)))
- (semantic-format-tag-uml-concise-prototype (car list)))
- (t "<No Tag>")))
- (localface (if (or (not idx) (/= idx count))
- face
- idxface))
- )
- (if (semantic-tag-p (car list))
- (speedbar-make-tag-line 'angle ?i
- 'semantic-ia-sb-tag-info (car list)
- string (if usefn function) (car list) localface
- 0)
- (speedbar-make-tag-line 'statictag ??
- nil nil
- string (if usefn function) (car list) localface
- 0))
- (setq list (cdr list)
- count (1+ count)))
- )))
- (defun semantic-ia-sb-completion-list (list face function)
- "Create some speedbar buttons from LIST.
- Each button will use FACE, and be activated with FUNCTION."
- (while list
- (let* ((documentable nil)
- (string (cond ((stringp (car list))
- (car list))
- ((semantic-tag-p (car list))
- (setq documentable t)
- (semantic-format-tag-uml-concise-prototype (car list)))
- (t "foo"))))
- (if documentable
- (speedbar-make-tag-line 'angle ?i
- 'semantic-ia-sb-tag-info
- (car list)
- string function (car list) face
- 0)
- (speedbar-make-tag-line 'statictag ? nil nil
- string function (car list) face
- 0))
- (setq list (cdr list)))))
- (defun semantic-ia-sb-show-tag-info ()
- "Display information about the tag on the current line.
- Same as clicking on the <i> button.
- See `semantic-ia-sb-tag-info' for more."
- (interactive)
- (let ((tok nil))
- (save-excursion
- (end-of-line)
- (forward-char -1)
- (setq tok (get-text-property (point) 'speedbar-token)))
- (semantic-ia-sb-tag-info nil tok 0)))
- (defun semantic-ia-sb-tag-info (text tag indent)
- "Display as much information as we can about tag.
- Show the information in a shrunk split-buffer and expand
- out as many details as possible.
- TEXT, TAG, and INDENT are speedbar function arguments."
- (when (semantic-tag-p tag)
- (unwind-protect
- (let ((ob nil))
- (speedbar-select-attached-frame)
- (setq ob (current-buffer))
- (with-output-to-temp-buffer "*Tag Information*"
-
- (with-current-buffer "*Tag Information*"
- (goto-char (point-max))
- (insert
- (semantic-format-tag-prototype tag nil t)
- "\n")
- (let ((typetok
- (condition-case nil
- (with-current-buffer ob
-
- (semantic-analyze-tag-type tag nil))
- (error nil))))
- (if typetok
- (insert (semantic-format-tag-prototype
- typetok nil t))
-
-
-
-
- (let ((type (semantic-tag-type tag)))
- (cond ((semantic-tag-p type)
- (setq type (semantic-tag-name type)))
- ((listp type)
- (setq type (car type))))
- (if (semantic-lex-keyword-p type)
- (setq typetok
- (semantic-lex-keyword-get type 'summary))))
- (if typetok
- (insert typetok))
- ))
- ))
-
- (shrink-window-if-larger-than-buffer
- (get-buffer-window "*Tag Information*")))
- (select-frame speedbar-frame))))
- (defun semantic-ia-sb-line-path (&optional depth)
- "Return the file name associated with DEPTH."
- (save-match-data
- (let* ((tok (speedbar-line-token))
- (buff (if (semantic-tag-buffer tok)
- (semantic-tag-buffer tok)
- (current-buffer))))
- (buffer-file-name buff))))
- (defun semantic-ia-sb-complete (text tag indent)
- "At point in the attached buffer, complete the symbol clicked on.
- TEXT TAG and INDENT are the details."
-
- (speedbar-select-attached-frame)
- (unwind-protect
- (let* ((a (semantic-analyze-current-context (point)))
- (bounds (oref a bounds))
- (movepoint nil)
- )
- (save-excursion
- (if (and (<= (point) (cdr bounds)) (>= (point) (car bounds)))
- (setq movepoint t))
- (goto-char (car bounds))
- (delete-region (car bounds) (cdr bounds))
- (insert (semantic-tag-name tag))
- (if movepoint (setq movepoint (point)))
-
-
-
-
- )
- (if movepoint
- (let ((cf (selected-frame)))
- (speedbar-select-attached-frame)
- (goto-char movepoint)
- (select-frame cf))))
- (select-frame speedbar-frame)))
- (provide 'semantic/ia-sb)
|