comparison lisp/cedet/semantic/format.el @ 104442:b22b44e953cb

cedet/semantic/chart.el: Don't require semantic/find. cedet/semantic/complete.el: Don't require semantic/find. cedet/semantic/decorate.el: Require semantic/tag-file. (semantic-set-tag-folded-isearch): Require semantic/find. cedet/semantic/dep.el: Change semantic--dependency-find-file-on-path into a macro, to avoid compiler warning. Defvar ede-minor-mode and ede-object. Declare ede-system-include-path. cedet/semantic/doc.el: Require semantic/tag-file and semantic/find. cedet/semantic/edit.el: Require semantic/find and semantic/format. cedet/semantic/find.el: Defvar semantic-case-fold. Require semantic. (semantic-find-tags-external-children-of-type): Require semantic/sort. (semantic-find-tags-by-scope-protection-default): Require semantic/tag-ls. cedet/semantic/format.el: Require semantic/tag-ls. eval-when-compile semantic/find. (semantic-format-tag-name): Move up to avoid compiler error. (semantic-format-tag-prototype): Move up to avoid compiler error. (semantic--format-tag-parent-tree): Require semantic/tag-file. (semantic-format-tag-short-doc-default): Require semantic/doc.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 31 Aug 2009 02:16:34 +0000
parents 6810f0d84270
children 2bf481006ba4
comparison
equal deleted inserted replaced
104441:902d22a2d922 104442:b22b44e953cb
1 ;;; format.el --- Routines for formatting tags 1 ;;; semantic/format.el --- Routines for formatting tags
2 2
3 ;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 3 ;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
4 ;;; 2008, 2009 Free Software Foundation, Inc. 4 ;;; 2008, 2009 Free Software Foundation, Inc.
5 5
6 ;; Author: Eric M. Ludlam <zappo@gnu.org> 6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
31 ;; In addition, macros for setting up customizable variables that let 31 ;; In addition, macros for setting up customizable variables that let
32 ;; the user choose their default format type are also provided. 32 ;; the user choose their default format type are also provided.
33 ;; 33 ;;
34 34
35 ;;; Code: 35 ;;; Code:
36 (eval-when-compile (require 'font-lock)) 36 (require 'semantic)
37 (require 'semantic/tag) 37 (require 'semantic/tag)
38 (require 'semantic/tag-ls)
38 (require 'ezimage) 39 (require 'ezimage)
40
41 (eval-when-compile
42 (require 'font-lock)
43 (require 'semantic/find))
39 44
40 ;;; Tag to text overload functions 45 ;;; Tag to text overload functions
41 ;; 46 ;;
42 ;; abbreviations, prototypes, and coloring support. 47 ;; abbreviations, prototypes, and coloring support.
43 (defvar semantic-format-tag-functions 48 (defvar semantic-format-tag-functions
88 93
89 (defvar semantic-format-parent-separator "::" 94 (defvar semantic-format-parent-separator "::"
90 "Text used to separate names when between namespaces/classes and functions.") 95 "Text used to separate names when between namespaces/classes and functions.")
91 (make-variable-buffer-local 'semantic-format-parent-separator) 96 (make-variable-buffer-local 'semantic-format-parent-separator)
92 97
98 (define-overloadable-function semantic-format-tag-name (tag &optional parent color)
99 "Return the name string describing TAG.
100 The name is the shortest possible representation.
101 Optional argument PARENT is the parent type if TAG is a detail.
102 Optional argument COLOR means highlight the prototype with font-lock colors.")
103
104 (define-overloadable-function semantic-format-tag-prototype (tag &optional parent color)
105 "Return a prototype for TAG.
106 This function should be overloaded, though it need not be used.
107 This is because it can be used to create code by language independent
108 tools.
109 Optional argument PARENT is the parent type if TAG is a detail.
110 Optional argument COLOR means highlight the prototype with font-lock colors.")
111
112
93 (defun semantic-test-all-format-tag-functions (&optional arg) 113 (defun semantic-test-all-format-tag-functions (&optional arg)
94 "Test all outputs from `semantic-format-tag-functions'. 114 "Test all outputs from `semantic-format-tag-functions'.
95 Output is generated from the function under `point'. 115 Output is generated from the function under `point'.
96 Optional argument ARG specifies not to use color." 116 Optional argument ARG specifies not to use color."
97 (interactive "P") 117 (interactive "P")
118 (require 'semantic/find)
98 (semantic-fetch-tags) 119 (semantic-fetch-tags)
99 (let* ((tag (semantic-current-tag)) 120 (let* ((tag (semantic-current-tag))
100 (par (semantic-current-tag-parent)) 121 (par (semantic-current-tag-parent))
101 (fns semantic-format-tag-functions)) 122 (fns semantic-format-tag-functions))
102 (with-output-to-temp-buffer "*format-tag*" 123 (with-output-to-temp-buffer "*format-tag*"
272 ans)) 293 ans))
273 ((and (listp anything) 294 ((and (listp anything)
274 (stringp (car anything))) 295 (stringp (car anything)))
275 (semantic--format-colorize-text (car anything) colorhint)))) 296 (semantic--format-colorize-text (car anything) colorhint))))
276 297
277 (define-overloadable-function semantic-format-tag-name (tag &optional parent color)
278 "Return the name string describing TAG.
279 The name is the shortest possible representation.
280 Optional argument PARENT is the parent type if TAG is a detail.
281 Optional argument COLOR means highlight the prototype with font-lock colors.")
282
283 (defun semantic-format-tag-name-default (tag &optional parent color) 298 (defun semantic-format-tag-name-default (tag &optional parent color)
284 "Return an abbreviated string describing TAG. 299 "Return an abbreviated string describing TAG.
285 Optional argument PARENT is the parent type if TAG is a detail. 300 Optional argument PARENT is the parent type if TAG is a detail.
286 Optional argument COLOR means highlight the prototype with font-lock colors." 301 Optional argument COLOR means highlight the prototype with font-lock colors."
287 (let ((name (semantic-tag-name tag)) 302 (let ((name (semantic-tag-name tag))
291 (when destructor 306 (when destructor
292 (setq name (concat "~" name))) 307 (setq name (concat "~" name)))
293 (if color 308 (if color
294 (setq name (semantic--format-colorize-text name (semantic-tag-class tag)))) 309 (setq name (semantic--format-colorize-text name (semantic-tag-class tag))))
295 name)) 310 name))
311
312 (declare-function semantic-go-to-tag "semantic/tag-file")
296 313
297 (defun semantic--format-tag-parent-tree (tag parent) 314 (defun semantic--format-tag-parent-tree (tag parent)
298 "Under Consideration. 315 "Under Consideration.
299 316
300 Return a list of parents for TAG. 317 Return a list of parents for TAG.
309 (unless parent 326 (unless parent
310 ;; All mechanisms here must be fast as often parent 327 ;; All mechanisms here must be fast as often parent
311 ;; is nil because there isn't one. 328 ;; is nil because there isn't one.
312 (setq parent (or (semantic-tag-function-parent tag) 329 (setq parent (or (semantic-tag-function-parent tag)
313 (save-excursion 330 (save-excursion
331 (require 'semantic/tag-file)
314 (semantic-go-to-tag tag) 332 (semantic-go-to-tag tag)
315 (semantic-current-tag-parent))))) 333 (semantic-current-tag-parent)))))
316 (when (stringp parent) 334 (when (stringp parent)
317 (setq parent (semantic-find-first-tag-by-name 335 (setq parent (semantic-find-first-tag-by-name
318 parent (current-buffer)))) 336 parent (current-buffer))))
447 (define-overloadable-function semantic-format-tag-short-doc (tag &optional parent color) 465 (define-overloadable-function semantic-format-tag-short-doc (tag &optional parent color)
448 "Display a short form of TAG's documentation. (Comments, or docstring.) 466 "Display a short form of TAG's documentation. (Comments, or docstring.)
449 Optional argument PARENT is the parent type if TAG is a detail. 467 Optional argument PARENT is the parent type if TAG is a detail.
450 Optional argument COLOR means highlight the prototype with font-lock colors.") 468 Optional argument COLOR means highlight the prototype with font-lock colors.")
451 469
470 (declare-function semantic-documentation-for-tag "semantic/doc")
471
452 (defun semantic-format-tag-short-doc-default (tag &optional parent color) 472 (defun semantic-format-tag-short-doc-default (tag &optional parent color)
453 "Display a short form of TAG's documentation. (Comments, or docstring.) 473 "Display a short form of TAG's documentation. (Comments, or docstring.)
454 Optional argument PARENT is the parent type if TAG is a detail. 474 Optional argument PARENT is the parent type if TAG is a detail.
455 Optional argument COLOR means highlight the prototype with font-lock colors." 475 Optional argument COLOR means highlight the prototype with font-lock colors."
476
456 (let* ((fname (or (semantic-tag-file-name tag) 477 (let* ((fname (or (semantic-tag-file-name tag)
457 (when parent (semantic-tag-file-name parent)))) 478 (when parent (semantic-tag-file-name parent))))
458 (buf (or (semantic-tag-buffer tag) 479 (buf (or (semantic-tag-buffer tag)
459 (when parent (semantic-tag-buffer parent)))) 480 (when parent (semantic-tag-buffer parent))))
460 (doc (semantic-tag-docstring tag buf))) 481 (doc (semantic-tag-docstring tag buf)))
462 ;; If there is no doc, and no buffer, but we have a filename, 483 ;; If there is no doc, and no buffer, but we have a filename,
463 ;; lets try again. 484 ;; lets try again.
464 (setq buf (find-file-noselect fname)) 485 (setq buf (find-file-noselect fname))
465 (setq doc (semantic-tag-docstring tag buf))) 486 (setq doc (semantic-tag-docstring tag buf)))
466 (when (not doc) 487 (when (not doc)
488 (require 'semantic/doc)
467 (setq doc (semantic-documentation-for-tag tag)) 489 (setq doc (semantic-documentation-for-tag tag))
468 ) 490 )
469 (setq doc 491 (setq doc
470 (if (not doc) 492 (if (not doc)
471 ;; No doc, use summarize. 493 ;; No doc, use summarize.
480 doc 502 doc
481 )) 503 ))
482 504
483 ;;; Prototype generation 505 ;;; Prototype generation
484 ;; 506 ;;
485 (define-overloadable-function semantic-format-tag-prototype (tag &optional parent color)
486 "Return a prototype for TAG.
487 This function should be overloaded, though it need not be used.
488 This is because it can be used to create code by language independent
489 tools.
490 Optional argument PARENT is the parent type if TAG is a detail.
491 Optional argument COLOR means highlight the prototype with font-lock colors.")
492
493 (defun semantic-format-tag-prototype-default (tag &optional parent color) 507 (defun semantic-format-tag-prototype-default (tag &optional parent color)
494 "Default method for returning a prototype for TAG. 508 "Default method for returning a prototype for TAG.
495 This will work for C like languages. 509 This will work for C like languages.
496 Optional argument PARENT is the parent type if TAG is a detail. 510 Optional argument PARENT is the parent type if TAG is a detail.
497 Optional argument COLOR means highlight the prototype with font-lock colors." 511 Optional argument COLOR means highlight the prototype with font-lock colors."
769 'semantic-format-tag-uml-concise-prototype) 783 'semantic-format-tag-uml-concise-prototype)
770 784
771 785
772 (provide 'semantic/format) 786 (provide 'semantic/format)
773 787
774 ;;; semantic-format.el ends here 788 ;;; semantic/format.el ends here