changelog shortlog tags changeset files revisions annotate raw

doc/grok-lisp.el

changeset 113: bc94df402ff0
parent:25e7fcde0f79
author: Dmitry Dzhus <mail@sphinx.net.ru>
date: Fri Nov 16 19:08:52 2007 +0300 (13 months ago)
permissions: -rw-r--r--
description: Updated report to comply with source code changes introduced in rev 110.
1(require 'semantic)
2(require 'semanticdb)
3(semanticdb-toggle-global-mode)
4
5;; Return a Semantic tag table for file
6(defun get-file-tags (file-name)
7 (with-current-buffer
8 (find-file-noselect file-name)
9 (semantic-fetch-tags)))
10
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))))
18
19;; Return a list of tags from tag-table which are also mentioned in
20;; tag
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
26 (deps (mapcar
27 (lambda (tag)
28 (cons (semantic-tag-name tag)
29 tag))
30 tag-table)))
31 (with-current-buffer buffer
32 (let (result)
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
39 (cadr lexem)
40 (cddr lexem)))
41 (found-tag (assoc lexem-string
42 deps)))
43 (if found-tag
44 (add-to-list 'result (cdr found-tag) t)))))))))
45
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)))
50 (princ (format "%s"
51 (get-tag-body
52 (semantic-find-first-tag-by-name
53 tag-name
54 tag-table))))))
55
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
59 'function
60 (get-file-tags file-name)))
61
62;; Get a list of all 'function tags declared in specified file and its
63;; included files
64(defun get-file-functions-deep (file-name)
65 (with-current-buffer
66 (find-file-noselect file-name)
67 (semanticdb-strip-find-results
68 (semanticdb-find-tags-by-class
69 'function))))
70
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))
76 (depgraph))
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)))))
80
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)
95 function-name)))))))
96 (princ "}\n"))