3(semanticdb-toggle-global-mode)
5;; Return a Semantic tag table for file
6(defun get-file-tags (file-name)
8 (find-file-noselect file-name)
9 (semantic-fetch-tags)))
11;; Return full tag source code (suitable for princ-ing)
12(defun get-tag-body (tag)
13 (let ((from (semantic-tag-start tag))
14 (to (semantic-tag-end tag))
15 (buffer (semantic-tag-buffer tag)))
16 (with-current-buffer buffer
17 (buffer-substring from to))))
19;; Return a list of tags from tag-table which are also mentioned in
21(defun get-tag-deps (tag tag-table)
22 (let ((from (semantic-tag-start tag))
23 (to (semantic-tag-end tag))
24 (buffer (semantic-tag-buffer tag))
25 ;; Build associative list with tag names as keys
28 (cons (semantic-tag-name tag)
31 (with-current-buffer buffer
33 ;; cddddr is a Lisp-oriented hack to prevent tag itself from
34 ;; inclusion to dependency list
35 (dolist (lexem (cddddr (semantic-lex from to 1.0e+INF)) result)
36 (if (or (eq 'symbol (car lexem))
37 (eq 'NAME (car lexem)))
38 (let* ((lexem-string (buffer-substring
41 (found-tag (assoc lexem-string
44 (add-to-list 'result (cdr found-tag) t)))))))))
46;; Print body of tag with specified name from specified file
47(defun print-tag-from-file (tag-name file-name)
48 (interactive "sTag name: \nfFile name: ")
49 (let ((tag-table (get-file-tags file-name)))
52 (semantic-find-first-tag-by-name
56;; Get a list of all 'function tags declared in specified file
57(defun get-file-functions (file-name)
58 (semantic-find-tags-by-class
60 (get-file-tags file-name)))
62;; Get a list of all 'function tags declared in specified file and its
64(defun get-file-functions-deep (file-name)
66 (find-file-noselect file-name)
67 (semanticdb-strip-find-results
68 (semanticdb-find-tags-by-class
71;; Return a list of pairs (TAG . DEPS) where DEPS is a list of
72;; functions TAG «depends» on
73(defun get-file-depgraph (file-name)
74 (let ((deep-tag-table (get-file-functions-deep file-name))
75 (file-tag-table (get-file-functions file-name))
77 (dolist (tag file-tag-table depgraph)
78 (let ((deps (get-tag-deps tag deep-tag-table)))
79 (add-to-list 'depgraph (cons tag deps) t)))))
81;; Print depgraph for functions in specified files in DOT format
82;; (suitable for processing with Graphviz programs)
83(defun print-files-depgraph (&rest file-names)
84 (princ "digraph D {\n")
85 (princ "overlap=scale;\n")
86 (dolist (file file-names)
87 (let ((depgraph (get-file-depgraph file)))
88 (dolist (dep-list-for-tag depgraph)
89 (let ((function-name (semantic-tag-name
90 (car dep-list-for-tag))))
91 (princ (format "\"%s\";\n" function-name))
92 (dolist (dependency (cdr dep-list-for-tag))
93 (princ (format "\"%s\" -> \"%s\";\n"
94 (semantic-tag-name dependency)