Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / cedet / semantic / format.el
blob549933da57cf57fec610a9291e4ce37197dff00e
1 ;;; semantic/format.el --- Routines for formatting tags
3 ;; Copyright (C) 1999-2005, 2007-2014 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: syntax
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Once a language file has been parsed into a TAG, it is often useful
26 ;; then display that tag information in browsers, completion engines, or
27 ;; help routines. The functions and setup in this file provide ways
28 ;; to reformat a tag into different standard output types.
30 ;; In addition, macros for setting up customizable variables that let
31 ;; the user choose their default format type are also provided.
34 ;;; Code:
35 (eval-when-compile (require 'font-lock))
36 (require 'semantic)
37 (require 'semantic/tag-ls)
38 (require 'ezimage)
40 (eval-when-compile (require 'semantic/find))
42 ;;; Tag to text overload functions
44 ;; abbreviations, prototypes, and coloring support.
45 (defvar semantic-format-tag-functions
46 '(semantic-format-tag-name
47 semantic-format-tag-canonical-name
48 semantic-format-tag-abbreviate
49 semantic-format-tag-summarize
50 semantic-format-tag-summarize-with-file
51 semantic-format-tag-short-doc
52 semantic-format-tag-prototype
53 semantic-format-tag-concise-prototype
54 semantic-format-tag-uml-abbreviate
55 semantic-format-tag-uml-prototype
56 semantic-format-tag-uml-concise-prototype
57 semantic-format-tag-prin1
59 "List of functions which convert a tag to text.
60 Each function must take the parameters TAG &optional PARENT COLOR.
61 TAG is the tag to convert.
62 PARENT is a parent tag or name which refers to the structure
63 or class which contains TAG. PARENT is NOT a class which a TAG
64 would claim as a parent.
65 COLOR indicates that the generated text should be colored using
66 `font-lock'.")
68 (defvar semantic-format-tag-custom-list
69 (append '(radio)
70 (mapcar (lambda (f) (list 'const f))
71 semantic-format-tag-functions)
72 '(function))
73 "A List used by customizable variables to choose a tag to text function.
74 Use this variable in the :type field of a customizable variable.")
76 (defcustom semantic-format-use-images-flag ezimage-use-images
77 "Non-nil means semantic format functions use images.
78 Images can be used as icons instead of some types of text strings."
79 :group 'semantic
80 :type 'boolean)
82 (defvar semantic-function-argument-separator ","
83 "Text used to separate arguments when creating text from tags.")
84 (make-variable-buffer-local 'semantic-function-argument-separator)
86 (defvar semantic-format-parent-separator "::"
87 "Text used to separate names when between namespaces/classes and functions.")
88 (make-variable-buffer-local 'semantic-format-parent-separator)
90 (defvar semantic-format-face-alist
91 `( (function . font-lock-function-name-face)
92 (variable . font-lock-variable-name-face)
93 (type . font-lock-type-face)
94 ;; These are different between Emacsen.
95 (include . ,(if (featurep 'xemacs)
96 'font-lock-preprocessor-face
97 'font-lock-constant-face))
98 (package . ,(if (featurep 'xemacs)
99 'font-lock-preprocessor-face
100 'font-lock-constant-face))
101 ;; Not a tag, but instead a feature of output
102 (label . font-lock-string-face)
103 (comment . font-lock-comment-face)
104 (keyword . font-lock-keyword-face)
105 (abstract . italic)
106 (static . underline)
107 (documentation . font-lock-doc-face)
109 "Face used to colorize tags of different types.
110 Override the value locally if a language supports other tag types.
111 When adding new elements, try to use symbols also returned by the parser.
112 The form of an entry in this list is of the form:
113 ( SYMBOL . FACE )
114 where SYMBOL is a tag type symbol used with semantic. FACE
115 is a symbol representing a face.
116 Faces used are generated in `font-lock' for consistency, and will not
117 be used unless font lock is a feature.")
120 ;;; Coloring Functions
122 (defun semantic--format-colorize-text (text face-class)
123 "Apply onto TEXT a color associated with FACE-CLASS.
124 FACE-CLASS is a tag type found in `semantic-format-face-alist'.
125 See that variable for details on adding new types."
126 (if (featurep 'font-lock)
127 (let ((face (cdr-safe (assoc face-class semantic-format-face-alist)))
128 (newtext (concat text)))
129 (put-text-property 0 (length text) 'face face newtext)
130 newtext)
131 text))
133 (defun semantic--format-colorize-merge-text (precoloredtext face-class)
134 "Apply onto PRECOLOREDTEXT a color associated with FACE-CLASS.
135 FACE-CLASS is a tag type found in `semantic-formatface-alist'.
136 See that variable for details on adding new types."
137 (let ((face (cdr-safe (assoc face-class semantic-format-face-alist)))
138 (newtext (concat precoloredtext))
140 (if (featurep 'xemacs)
141 (add-text-properties 0 (length newtext) (list 'face face) newtext)
142 (alter-text-property 0 (length newtext) 'face
143 (lambda (current-face)
144 (let ((cf
145 (cond ((facep current-face)
146 (list current-face))
147 ((listp current-face)
148 current-face)
149 (t nil)))
151 (cond ((facep face)
152 (list face))
153 ((listp face)
154 face)
155 (t nil))))
156 (append cf nf)))
157 newtext))
158 newtext))
160 ;;; Function Arguments
162 (defun semantic--format-tag-arguments (args formatter color)
163 "Format the argument list ARGS with FORMATTER.
164 FORMATTER is a function used to format a tag.
165 COLOR specifies if color should be used."
166 (let ((out nil))
167 (while args
168 (push (if (and formatter
169 (semantic-tag-p (car args))
170 (not (string= (semantic-tag-name (car args)) ""))
172 (funcall formatter (car args) nil color)
173 (semantic-format-tag-name-from-anything
174 (car args) nil color 'variable))
175 out)
176 (setq args (cdr args)))
177 (mapconcat 'identity (nreverse out) semantic-function-argument-separator)
180 ;;; Data Type
181 (define-overloadable-function semantic-format-tag-type (tag color)
182 "Convert the data type of TAG to a string usable in tag formatting.
183 It is presumed that TYPE is a string or semantic tag.")
185 (defun semantic-format-tag-type-default (tag color)
186 "Convert the data type of TAG to a string usable in tag formatting.
187 Argument COLOR specifies to colorize the text."
188 (let* ((type (semantic-tag-type tag))
189 (out (cond ((semantic-tag-p type)
190 (let* ((typetype (semantic-tag-type type))
191 (name (semantic-tag-name type))
192 (str (if typetype
193 (concat typetype " " name)
194 name)))
195 (if color
196 (semantic--format-colorize-text
198 'type)
199 str)))
200 ((and (listp type)
201 (stringp (car type)))
202 (car type))
203 ((stringp type)
204 type)
205 (t nil))))
206 (if (and color out)
207 (setq out (semantic--format-colorize-text out 'type))
208 out)
212 ;;; Abstract formatting functions
215 (defun semantic-format-tag-prin1 (tag &optional parent color)
216 "Convert TAG to a string that is the print name for TAG.
217 PARENT and COLOR are ignored."
218 (format "%S" tag))
220 (defun semantic-format-tag-name-from-anything (anything &optional
221 parent color
222 colorhint)
223 "Convert just about anything into a name like string.
224 Argument ANYTHING is the thing to be converted.
225 Optional argument PARENT is the parent type if TAG is a detail.
226 Optional argument COLOR means highlight the prototype with font-lock colors.
227 Optional COLORHINT is the type of color to use if ANYTHING is not a tag
228 with a tag class. See `semantic--format-colorize-text' for a definition
229 of FACE-CLASS for which this is used."
230 (cond ((stringp anything)
231 (semantic--format-colorize-text anything colorhint))
232 ((semantic-tag-p anything)
233 (let ((ans (semantic-format-tag-name anything parent color)))
234 ;; If ANS is empty string or nil, then the name wasn't
235 ;; supplied. The implication is as in C where there is a data
236 ;; type but no name for a prototype from an include file, or
237 ;; an argument just wasn't used in the body of the fcn.
238 (if (or (null ans) (string= ans ""))
239 (setq ans (semantic-format-tag-type anything color)))
240 ans))
241 ((and (listp anything)
242 (stringp (car anything)))
243 (semantic--format-colorize-text (car anything) colorhint))))
245 ;;;###autoload
246 (define-overloadable-function semantic-format-tag-name (tag &optional parent color)
247 "Return the name string describing TAG.
248 The name is the shortest possible representation.
249 Optional argument PARENT is the parent type if TAG is a detail.
250 Optional argument COLOR means highlight the prototype with font-lock colors.")
252 (defun semantic-format-tag-name-default (tag &optional parent color)
253 "Return an abbreviated string describing TAG.
254 Optional argument PARENT is the parent type if TAG is a detail.
255 Optional argument COLOR means highlight the prototype with font-lock colors."
256 (let ((name (semantic-tag-name tag))
257 (destructor
258 (if (eq (semantic-tag-class tag) 'function)
259 (semantic-tag-function-destructor-p tag))))
260 (when destructor
261 (setq name (concat "~" name)))
262 (if color
263 (setq name (semantic--format-colorize-text name (semantic-tag-class tag))))
264 name))
266 (declare-function semantic-go-to-tag "semantic/tag-file")
268 (defun semantic--format-tag-parent-tree (tag parent)
269 "Under Consideration.
271 Return a list of parents for TAG.
272 PARENT is the first parent, or nil. If nil, then an attempt to
273 determine PARENT is made.
274 Once PARENT is identified, additional parents are looked for.
275 The return list first element is the nearest parent, and the last
276 item is the first parent which may be a string. The root parent may
277 not be the actual first parent as there may just be a failure to find
278 local definitions."
279 ;; First, validate the PARENT argument.
280 (unless parent
281 ;; All mechanisms here must be fast as often parent
282 ;; is nil because there isn't one.
283 (setq parent (or (semantic-tag-function-parent tag)
284 (save-excursion
285 (require 'semantic/tag-file)
286 (semantic-go-to-tag tag)
287 (semantic-current-tag-parent)))))
288 (when (stringp parent)
289 (setq parent (semantic-find-first-tag-by-name
290 parent (current-buffer))))
291 ;; Try and find a trail of parents from PARENT
292 (let ((rlist (list parent))
294 ;; IMPLEMENT ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
295 (reverse rlist)))
297 (define-overloadable-function semantic-format-tag-canonical-name (tag &optional parent color)
298 "Return a canonical name for TAG.
299 A canonical name includes the names of any parents or namespaces preceding
300 the tag.
301 Optional argument PARENT is the parent type if TAG is a detail.
302 Optional argument COLOR means highlight the prototype with font-lock colors.")
304 (defun semantic-format-tag-canonical-name-default (tag &optional parent color)
305 "Return a canonical name for TAG.
306 A canonical name includes the names of any parents or namespaces preceding
307 the tag with colons separating them.
308 Optional argument PARENT is the parent type if TAG is a detail.
309 Optional argument COLOR means highlight the prototype with font-lock colors."
310 (let ((parent-input-str
311 (if (and parent
312 (semantic-tag-p parent)
313 (semantic-tag-of-class-p parent 'type))
314 (concat
315 ;; Choose a class of 'type as the default parent for something.
316 ;; Just a guess though.
317 (semantic-format-tag-name-from-anything parent nil color 'type)
318 ;; Default separator between class/namespace and others.
319 semantic-format-parent-separator)
320 ""))
321 (tag-parent-str
322 (or (when (and (semantic-tag-of-class-p tag 'function)
323 (semantic-tag-function-parent tag))
324 (concat (semantic-tag-function-parent tag)
325 semantic-format-parent-separator))
326 ""))
328 (concat parent-input-str
329 tag-parent-str
330 (semantic-format-tag-name tag parent color))
333 (define-overloadable-function semantic-format-tag-abbreviate (tag &optional parent color)
334 "Return an abbreviated string describing TAG.
335 The abbreviation is to be short, with possible symbols indicating
336 the type of tag, or other information.
337 Optional argument PARENT is the parent type if TAG is a detail.
338 Optional argument COLOR means highlight the prototype with font-lock colors.")
340 (defun semantic-format-tag-abbreviate-default (tag &optional parent color)
341 "Return an abbreviated string describing TAG.
342 Optional argument PARENT is a parent tag in the tag hierarchy.
343 In this case PARENT refers to containment, not inheritance.
344 Optional argument COLOR means highlight the prototype with font-lock colors.
345 This is a simple C like default."
346 ;; Do lots of complex stuff here.
347 (let ((class (semantic-tag-class tag))
348 (name (semantic-format-tag-canonical-name tag parent color))
349 (suffix "")
350 (prefix "")
351 str)
352 (cond ((eq class 'function)
353 (setq suffix "()"))
354 ((eq class 'include)
355 (setq suffix "<>"))
356 ((eq class 'variable)
357 (setq suffix (if (semantic-tag-variable-default tag)
358 "=" "")))
359 ((eq class 'label)
360 (setq suffix ":"))
361 ((eq class 'code)
362 (setq prefix "{"
363 suffix "}"))
364 ((eq class 'type)
365 (setq suffix "{}"))
367 (setq str (concat prefix name suffix))
368 str))
370 ;;;###autoload
371 (define-overloadable-function semantic-format-tag-summarize (tag &optional parent color)
372 "Summarize TAG in a reasonable way.
373 Optional argument PARENT is the parent type if TAG is a detail.
374 Optional argument COLOR means highlight the prototype with font-lock colors.")
376 (defun semantic-format-tag-summarize-default (tag &optional parent color)
377 "Summarize TAG in a reasonable way.
378 Optional argument PARENT is the parent type if TAG is a detail.
379 Optional argument COLOR means highlight the prototype with font-lock colors."
380 (let* ((proto (semantic-format-tag-prototype tag nil color))
381 (names (if parent
382 semantic-symbol->name-assoc-list-for-type-parts
383 semantic-symbol->name-assoc-list))
384 (tsymb (semantic-tag-class tag))
385 (label (capitalize (or (cdr-safe (assoc tsymb names))
386 (symbol-name tsymb)))))
387 (if color
388 (setq label (semantic--format-colorize-text label 'label)))
389 (concat label ": " proto)))
391 (define-overloadable-function semantic-format-tag-summarize-with-file (tag &optional parent color)
392 "Like `semantic-format-tag-summarize', but with the file name.
393 Optional argument PARENT is the parent type if TAG is a detail.
394 Optional argument COLOR means highlight the prototype with font-lock colors.")
396 (defun semantic-format-tag-summarize-with-file-default (tag &optional parent color)
397 "Summarize TAG in a reasonable way.
398 Optional argument PARENT is the parent type if TAG is a detail.
399 Optional argument COLOR means highlight the prototype with font-lock colors."
400 (let* ((proto (semantic-format-tag-prototype tag nil color))
401 (file (semantic-tag-file-name tag))
403 ;; Nothing for tag? Try parent.
404 (when (and (not file) (and parent))
405 (setq file (semantic-tag-file-name parent)))
406 ;; Don't include the file name if we can't find one, or it is the
407 ;; same as the current buffer.
408 (if (or (not file)
409 (string= file (buffer-file-name (current-buffer))))
410 proto
411 (setq file (file-name-nondirectory file))
412 (when color
413 (setq file (semantic--format-colorize-text file 'label)))
414 (concat file ": " proto))))
416 (define-overloadable-function semantic-format-tag-short-doc (tag &optional parent color)
417 "Display a short form of TAG's documentation. (Comments, or docstring.)
418 Optional argument PARENT is the parent type if TAG is a detail.
419 Optional argument COLOR means highlight the prototype with font-lock colors.")
421 (declare-function semantic-documentation-for-tag "semantic/doc")
423 (defun semantic-format-tag-short-doc-default (tag &optional parent color)
424 "Display a short form of TAG's documentation. (Comments, or docstring.)
425 Optional argument PARENT is the parent type if TAG is a detail.
426 Optional argument COLOR means highlight the prototype with font-lock colors."
427 (let* ((fname (or (semantic-tag-file-name tag)
428 (when parent (semantic-tag-file-name parent))))
429 (buf (or (semantic-tag-buffer tag)
430 (when parent (semantic-tag-buffer parent))))
431 (doc (semantic-tag-docstring tag buf)))
432 (when (and (not doc) (not buf) fname)
433 ;; If there is no doc, and no buffer, but we have a filename,
434 ;; let's try again.
435 (save-match-data
436 (setq buf (find-file-noselect fname)))
437 (setq doc (semantic-tag-docstring tag buf)))
438 (when (not doc)
439 (require 'semantic/doc)
440 (setq doc (semantic-documentation-for-tag tag))
442 (setq doc
443 (if (not doc)
444 ;; No doc, use summarize.
445 (semantic-format-tag-summarize tag parent color)
446 ;; We have doc. Can we devise a single line?
447 (if (string-match "$" doc)
448 (substring doc 0 (match-beginning 0))
449 doc)
451 (when color
452 (setq doc (semantic--format-colorize-text doc 'documentation)))
456 ;;; Prototype generation
458 ;;;###autoload
459 (define-overloadable-function semantic-format-tag-prototype (tag &optional parent color)
460 "Return a prototype for TAG.
461 This function should be overloaded, though it need not be used.
462 This is because it can be used to create code by language independent
463 tools.
464 Optional argument PARENT is the parent type if TAG is a detail.
465 Optional argument COLOR means highlight the prototype with font-lock colors.")
467 (defun semantic-format-tag-prototype-default (tag &optional parent color)
468 "Default method for returning a prototype for TAG.
469 This will work for C like languages.
470 Optional argument PARENT is the parent type if TAG is a detail.
471 Optional argument COLOR means highlight the prototype with font-lock colors."
472 (let* ((class (semantic-tag-class tag))
473 (name (semantic-format-tag-name tag parent color))
474 (type (if (member class '(function variable type))
475 (semantic-format-tag-type tag color)))
476 (args (if (member class '(function type))
477 (semantic--format-tag-arguments
478 (if (eq class 'function)
479 (semantic-tag-function-arguments tag)
480 (list "")
481 ;;(semantic-tag-type-members tag)
483 #'semantic-format-tag-prototype
484 color)))
485 (const (semantic-tag-get-attribute tag :constant-flag))
486 (tm (semantic-tag-get-attribute tag :typemodifiers))
487 (mods (append
488 (if const '("const") nil)
489 (cond ((stringp tm) (list tm))
490 ((consp tm) tm)
491 (t nil))
493 (array (if (eq class 'variable)
494 (let ((deref
495 (semantic-tag-get-attribute
496 tag :dereference))
497 (r ""))
498 (while (and deref (/= deref 0))
499 (setq r (concat r "[]")
500 deref (1- deref)))
501 r)))
502 (default (when (eq class 'variable)
503 (let ((defval
504 (semantic-tag-get-attribute tag :default-value)))
505 (when (and defval (stringp defval))
506 (concat "[=" defval "]")))))
508 (if args
509 (setq args
510 (concat " "
511 (if (eq class 'type) "{" "(")
512 args
513 (if (eq class 'type) "}" ")"))))
514 (when mods
515 (setq mods (concat (mapconcat 'identity mods " ") " ")))
516 (concat (or mods "")
517 (if type (concat type " "))
518 name
519 (or args "")
520 (or array "")
521 (or default ""))))
523 ;;;###autoload
524 (define-overloadable-function semantic-format-tag-concise-prototype (tag &optional parent color)
525 "Return a concise prototype for TAG.
526 Optional argument PARENT is the parent type if TAG is a detail.
527 Optional argument COLOR means highlight the prototype with font-lock colors.")
529 (defun semantic-format-tag-concise-prototype-default (tag &optional parent color)
530 "Return a concise prototype for TAG.
531 This default function will make a cheap concise prototype using C like syntax.
532 Optional argument PARENT is the parent type if TAG is a detail.
533 Optional argument COLOR means highlight the prototype with font-lock colors."
534 (let ((class (semantic-tag-class tag)))
535 (cond
536 ((eq class 'type)
537 (concat (semantic-format-tag-name tag parent color) "{}"))
538 ((eq class 'function)
539 (concat (semantic-format-tag-name tag parent color)
540 " ("
541 (semantic--format-tag-arguments
542 (semantic-tag-function-arguments tag)
543 'semantic-format-tag-concise-prototype
544 color)
545 ")"))
546 ((eq class 'variable)
547 (let* ((deref (semantic-tag-get-attribute
548 tag :dereference))
549 (array "")
551 (while (and deref (/= deref 0))
552 (setq array (concat array "[]")
553 deref (1- deref)))
554 (concat (semantic-format-tag-name tag parent color)
555 array)))
557 (semantic-format-tag-abbreviate tag parent color)))))
559 ;;; UML display styles
561 (defcustom semantic-uml-colon-string " : "
562 "*String used as a color separator between parts of a UML string.
563 In UML, a variable may appear as `varname : type'.
564 Change this variable to change the output separator."
565 :group 'semantic
566 :type 'string)
568 (defcustom semantic-uml-no-protection-string ""
569 "*String used to describe when no protection is specified.
570 Used by `semantic-format-tag-uml-protection-to-string'."
571 :group 'semantic
572 :type 'string)
574 (defun semantic--format-uml-post-colorize (text tag parent)
575 "Add color to TEXT created from TAG and PARENT.
576 Adds augmentation for `abstract' and `static' entries."
577 (if (semantic-tag-abstract-p tag parent)
578 (setq text (semantic--format-colorize-merge-text text 'abstract)))
579 (if (semantic-tag-static-p tag parent)
580 (setq text (semantic--format-colorize-merge-text text 'static)))
581 text
584 (defun semantic-uml-attribute-string (tag &optional parent)
585 "Return a string for TAG, a child of PARENT representing a UML attribute.
586 UML attribute strings are things like {abstract} or {leaf}."
587 (cond ((semantic-tag-abstract-p tag parent)
588 "{abstract}")
589 ((semantic-tag-leaf-p tag parent)
590 "{leaf}")
593 (defvar semantic-format-tag-protection-image-alist
594 '(("+" . ezimage-unlock)
595 ("#" . ezimage-key)
596 ("-" . ezimage-lock)
598 "Association of protection strings, and images to use.")
600 (defvar semantic-format-tag-protection-symbol-to-string-assoc-list
601 '((public . "+")
602 (protected . "#")
603 (private . "-")
605 "Association list of the form (SYMBOL . \"STRING\") for protection symbols.
606 This associates a symbol, such as 'public with the st ring \"+\".")
608 (define-overloadable-function semantic-format-tag-uml-protection-to-string (protection-symbol color)
609 "Convert PROTECTION-SYMBOL to a string for UML.
610 By default, uses `semantic-format-tag-protection-symbol-to-string-assoc-list'
611 to convert.
612 By default character returns are:
613 public -- +
614 private -- -
615 protected -- #.
616 If PROTECTION-SYMBOL is unknown, then the return value is
617 `semantic-uml-no-protection-string'.
618 COLOR indicates if we should use an image on the text.")
620 (defun semantic-format-tag-uml-protection-to-string-default (protection-symbol color)
621 "Convert PROTECTION-SYMBOL to a string for UML.
622 Uses `semantic-format-tag-protection-symbol-to-string-assoc-list' to convert.
623 If PROTECTION-SYMBOL is unknown, then the return value is
624 `semantic-uml-no-protection-string'.
625 COLOR indicates if we should use an image on the text."
626 (let* ((ezimage-use-images (and semantic-format-use-images-flag color))
627 (key (assoc protection-symbol
628 semantic-format-tag-protection-symbol-to-string-assoc-list))
629 (str (or (cdr-safe key) semantic-uml-no-protection-string)))
630 (ezimage-image-over-string
631 (copy-sequence str) ; make a copy to keep the original pristine.
632 semantic-format-tag-protection-image-alist)))
634 (defsubst semantic-format-tag-uml-protection (tag parent color)
635 "Retrieve the protection string for TAG with PARENT.
636 Argument COLOR specifies that color should be added to the string as
637 needed."
638 (semantic-format-tag-uml-protection-to-string
639 (semantic-tag-protection tag parent)
640 color))
642 (defun semantic--format-tag-uml-type (tag color)
643 "Format the data type of TAG to a string usable for formatting.
644 COLOR indicates if it should be colorized."
645 (let ((str (semantic-format-tag-type tag color)))
646 (if str
647 (concat semantic-uml-colon-string str))))
649 (define-overloadable-function semantic-format-tag-uml-abbreviate (tag &optional parent color)
650 "Return a UML style abbreviation for TAG.
651 Optional argument PARENT is the parent type if TAG is a detail.
652 Optional argument COLOR means highlight the prototype with font-lock colors.")
654 (defun semantic-format-tag-uml-abbreviate-default (tag &optional parent color)
655 "Return a UML style abbreviation for TAG.
656 Optional argument PARENT is the parent type if TAG is a detail.
657 Optional argument COLOR means highlight the prototype with font-lock colors."
658 (let* ((name (semantic-format-tag-name tag parent color))
659 (type (semantic--format-tag-uml-type tag color))
660 (protstr (semantic-format-tag-uml-protection tag parent color))
661 (text nil))
662 (setq text
663 (concat
664 protstr
665 (if type (concat name type)
666 name)))
667 (if color
668 (setq text (semantic--format-uml-post-colorize text tag parent)))
669 text))
671 (define-overloadable-function semantic-format-tag-uml-prototype (tag &optional parent color)
672 "Return a UML style prototype for TAG.
673 Optional argument PARENT is the parent type if TAG is a detail.
674 Optional argument COLOR means highlight the prototype with font-lock colors.")
676 (defun semantic-format-tag-uml-prototype-default (tag &optional parent color)
677 "Return a UML style prototype for TAG.
678 Optional argument PARENT is the parent type if TAG is a detail.
679 Optional argument COLOR means highlight the prototype with font-lock colors."
680 (let* ((class (semantic-tag-class tag))
681 (cp (semantic-format-tag-name tag parent color))
682 (type (semantic--format-tag-uml-type tag color))
683 (prot (semantic-format-tag-uml-protection tag parent color))
684 (argtext
685 (cond ((eq class 'function)
686 (concat
687 " ("
688 (semantic--format-tag-arguments
689 (semantic-tag-function-arguments tag)
690 #'semantic-format-tag-uml-prototype
691 color)
692 ")"))
693 ((eq class 'type)
694 "{}")))
695 (text nil))
696 (setq text (concat prot cp argtext type))
697 (if color
698 (setq text (semantic--format-uml-post-colorize text tag parent)))
699 text
702 (define-overloadable-function semantic-format-tag-uml-concise-prototype (tag &optional parent color)
703 "Return a UML style concise prototype for TAG.
704 Optional argument PARENT is the parent type if TAG is a detail.
705 Optional argument COLOR means highlight the prototype with font-lock colors.")
707 (defun semantic-format-tag-uml-concise-prototype-default (tag &optional parent color)
708 "Return a UML style concise prototype for TAG.
709 Optional argument PARENT is the parent type if TAG is a detail.
710 Optional argument COLOR means highlight the prototype with font-lock colors."
711 (let* ((cp (semantic-format-tag-concise-prototype tag parent color))
712 (type (semantic--format-tag-uml-type tag color))
713 (prot (semantic-format-tag-uml-protection tag parent color))
714 (text nil)
716 (setq text (concat prot cp type))
717 (if color
718 (setq text (semantic--format-uml-post-colorize text tag parent)))
719 text))
721 (provide 'semantic/format)
723 ;; Local variables:
724 ;; generated-autoload-file: "loaddefs.el"
725 ;; generated-autoload-load-name: "semantic/format"
726 ;; End:
728 ;;; semantic/format.el ends here