1 ;;; semantic/tag-write.el --- Write tags to a text stream
3 ;; Copyright (C) 2008-2013 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; Routine for writing out a list of tags to a text stream.
26 ;; These routines will be used by semanticdb to output a tag list into
27 ;; a text stream to be saved to a file. Ideally, you could use tag streams
28 ;; to share tags between processes as well.
30 ;; As a bonus, these routines will also validate the tag structure, and make sure
31 ;; that they conform to good semantic tag hygiene.
37 (defun semantic-tag-write-one-tag (tag &optional indent)
38 "Write a single tag TAG to standard out.
39 INDENT is the amount of indentation to use for this tag."
40 (when (not (semantic-tag-p tag))
41 (signal 'wrong-type-argument (list tag 'semantic-tag-p)))
42 (when (not indent) (setq indent 0))
43 ;(princ (make-string indent ? ))
46 (let ((name (semantic-tag-name tag))
47 (class (semantic-tag-class tag)))
50 (princ (symbol-name class))
52 (let ((attr (semantic-tag-attributes tag))
58 ((= (length attr) 2) ;; One item
60 (semantic-tag-write-one-attribute attr indent)
66 (princ (make-string (+ indent 3) ? ))
69 (semantic-tag-write-one-attribute attr (+ indent 4))
70 (setq attr (cdr (cdr attr)))
73 (princ (make-string (+ indent 4) ? )))
76 (princ (make-string (+ indent 3) ? ))
78 ;; Properties - for now, always nil.
79 (let ((rs (semantic--tag-get-property tag 'reparse-symbol)))
82 ;; Else, put in the property list.
83 (princ " (reparse-symbol ")
84 (princ (symbol-name rs))
88 (if (semantic-tag-with-position-p tag)
89 (let ((bounds (semantic-tag-bounds tag)))
91 (prin1 (apply 'vector bounds))
98 (defun semantic-tag-write-tag-list (tlist &optional indent dontaddnewline)
99 "Write the tag list TLIST to the current stream.
100 INDENT indicates the current indentation level.
101 If optional DONTADDNEWLINE is non-nil, then don't add a newline."
104 (unless dontaddnewline
105 ;; Assume cursor at end of current line. Add a CR, and make the list.
107 (princ (make-string indent ? ))))
110 (if (semantic-tag-p (car tlist))
111 (semantic-tag-write-one-tag (car tlist) (+ indent 2))
112 ;; If we don't have a tag in the tag list, use the below hack, and hope
113 ;; it doesn't contain anything bad. If we find something bad, go back here
114 ;; and start extending what's expected here.
115 (princ (format "%S" (car tlist))))
116 (setq tlist (cdr tlist))
119 (princ (make-string (+ indent 2) ? )))
122 (princ (make-string indent ? ))
126 ;; Writing out random stuff.
127 (defun semantic-tag-write-one-attribute (attrs indent)
128 "Write out one attribute from the head of the list of attributes ATTRS.
129 INDENT is the current amount of indentation."
130 (when (not attrs) (signal 'wrong-type-argument (list 'listp attrs)))
131 (when (not (symbolp (car attrs))) (error "Bad Attribute List in tag"))
133 (princ (symbol-name (car attrs)))
135 (semantic-tag-write-one-value (car (cdr attrs)) indent)
138 (defun semantic-tag-write-one-value (value indent)
139 "Write out a VALUE for something in a tag.
140 INDENT is the current tag indentation.
141 Items that are long lists of tags may need their own line."
144 ((semantic-tag-p value)
145 (semantic-tag-write-one-tag value (+ indent 2)))
146 ;; A list of more tags
147 ((and (listp value) (semantic-tag-p (car value)))
148 (semantic-tag-write-tag-list value (+ indent 2))
150 ;; Some arbitrary data.
152 (let ((str (format "%S" value)))
153 ;; Protect against odd data types in tags.
154 (if (= (aref str 0) ?#)
157 (message "Warning: Value %s not writable in tag." str))
162 (defun semantic-tag-write-list-slot-value (value)
163 "Write out the VALUE of a slot for EIEIO.
164 The VALUE is a list of tags."
168 (semantic-tag-write-tag-list value 10 t)
171 (provide 'semantic/tag-write)
174 ;; generated-autoload-file: "loaddefs.el"
175 ;; generated-autoload-load-name: "semantic/tag-write"
178 ;;; semantic/tag-write.el ends here