define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / tools / cxref / contrib / cxref.el
blob0a56e65a7f90850c7a71588577a6fe84cc50c307
1 ;; $Header$
2 ;;
3 ;; C Cross Referencing & Documentation tool. Version 1.3.
4 ;;
5 ;; Some useful Emacs lisp functions for use with cxref.
6 ;; Adds in comments of the appropriate format for cxref.
7 ;;
8 ;; Written by Andrew M. Bishop
9 ;;
10 ;; This file Copyright 1995,96 Andrew M. Bishop
11 ;; It may be distributed under the GNU Public License, version 2, or
12 ;; any higher version. See section COPYING of the GNU Public license
13 ;; for conditions under which this file may be redistributed.
16 ;;;###autoload
17 (defun cxref-c-mode-common-hook () "Set up the key bindings for cxref in cc-mode"
18 (define-key c-mode-map "\C-c\C-f" 'cxref-file-comment) ;; Control-C Control-F
19 (define-key c-mode-map "\C-cf" 'cxref-function-comment) ;; Control-C f
20 (define-key c-mode-map "\C-cv" 'cxref-variable-comment) ;; Control-C v
21 (define-key c-mode-map "\C-ce" 'cxref-endline-comment) ;; Control-C e
22 (define-key c-mode-map "\C-ci" 'cxref-inline-comment) ;; Control-C i
25 ;;;###autoload
26 (add-hook 'c-mode-common-hook 'cxref-c-mode-common-hook)
28 ;; Insert a file comment suitable for parsing with cxref
30 (defun cxref-file-comment () "Inserts a file comment suitable for parsing with cxref" (interactive)
31 (let ((cp (make-marker)))
33 (goto-char (point-min))
35 (insert "/***************************************") (c-indent-command)
36 (insert (concat "\n$" "Header" "$")) (c-indent-command)
37 (insert "\n")
38 (insert "\n")(c-indent-command)
39 (set-marker cp (point))
40 (insert "\n***************************************/") (c-indent-command)
41 (insert "\n\n\n")
42 (while (looking-at "\n") (delete-char 1))
44 (if (string-match "\\.h$" (buffer-file-name))
45 (let ((st) (defname (file-name-nondirectory (buffer-file-name))))
46 (while (setq st (string-match "\\." defname))
47 (setq defname (concat (substring defname 0 st) "_" (substring defname (+ 1 st) nil))))
48 (setq defname (upcase defname))
49 (insert (concat "#ifndef " defname "\n"))
50 (insert (concat "#define " defname " /*+ To stop multiple inclusions. +*/\n"))
51 (insert "\n")
52 (goto-char (point-max))
53 (while (looking-at-backward "\n") (delete-char -1))
54 (insert "\n\n")
55 (insert (concat "#endif /* " defname " */\n"))
58 (goto-char cp) (c-indent-command)
61 ;; Insert a function comment suitable for parsing with cxref
63 (defun cxref-function-comment () "Inserts a function comment suitable for parsing with cxref" (interactive)
64 (let ((bp (make-marker)) (cp (make-marker)) (fp (make-marker)) (as) (ae) (a) (depth 0))
66 (beginning-of-line)
68 (while (looking-at-backward "\n\n") (delete-backward-char 1))
70 (insert "\n\n")
71 (insert "/*++++++++++++++++++++++++++++++++++++++") (c-indent-command)
72 (insert "\n")
73 (set-marker bp (point))
74 (insert "\n")
75 (set-marker cp (point))
76 (insert "++++++++++++++++++++++++++++++++++++++*/") (c-indent-command)
77 (insert "\n\n")
79 (if (looking-at "static") (re-search-forward "[ \t\n]+"))
80 (set-marker fp (point))
82 (if (not (looking-at "void[\t ]+[a-zA-Z0-9_]"))
83 (progn
84 (setq as (point))
85 (search-forward "(") (backward-char)
86 (setq ae (point))
87 (setq a (buffer-substring as ae))
88 (goto-char cp)
89 (insert "\n")
90 (insert a) (c-indent-line)
91 (insert "\n")
92 (set-marker cp (point))
93 (goto-char fp)
97 (search-forward "(") (set-marker fp (point))
99 (catch 'finished-args
101 (while t
103 (if (looking-at-backward ")")
104 (throw 'finished-args t))
106 (re-search-forward "[\n\t ]*")
107 (set-marker fp (point))
108 (setq as (point))
110 (while (not (and (= depth 0) (looking-at "[,)]")))
111 (if (looking-at "[({]")
112 (setq depth (1+ depth)))
113 (if (looking-at "[)}]")
114 (setq depth (1- depth)))
115 (forward-char))
117 (set-marker fp (1+ (point)))
119 (re-search-backward "[\n\t ]*")
120 (setq ae (point))
122 (setq a (buffer-substring as ae))
124 (if (not (or (string= a "void") (string= a "")))
125 (progn
126 (goto-char cp)
127 (insert "\n")
128 (insert a) (c-indent-line)
129 (insert "\n")
130 (set-marker cp (point))
132 (goto-char fp)
135 (goto-char bp) (c-indent-command)
138 ;; Insert a variable comment suitable for parsing with cxref
140 (defun cxref-variable-comment () "Inserts a variable comment suitable for parsing with cxref" (interactive)
141 (let ((fp (make-marker)))
142 (beginning-of-line)
144 (while (looking-at-backward "\n\n") (delete-backward-char 1))
146 (insert "\n")
147 (insert "/*+ ")
148 (set-marker fp (point))
149 (insert " +*/")
150 (insert "\n")
152 (goto-char fp) (c-indent-command)
155 ;; Inserts an end of line comment that is parsed by cxref
157 (defun cxref-endline-comment () "Inserts an end of line comment that is parsed by cxref" (interactive)
158 (let ((fp (make-marker)))
159 (end-of-line)
160 (indent-to-column (c-comment-indent))
162 (insert "/*+ ")
163 (setq fp (point))
164 (insert " +*/")
166 (goto-char fp)
169 ;; Insert an inline comment that is not parsed with cxref
171 (defun cxref-inline-comment () "Inserts an inline comment that is not parsed with cxref" (interactive)
172 (let ((fp (make-marker)))
173 (beginning-of-line)
175 (while (looking-at-backward "\n\n") (delete-backward-char 1))
177 (insert "\n")
178 (insert "/* ")
179 (set-marker fp (point))
180 (insert " */")
181 (insert "\n\n")
183 (goto-char fp) (c-indent-command)
186 ;; A Very Useful Function
188 (defun looking-at-backward (arg)
189 (save-excursion
190 (let ((cp (point)) (return))
191 (if (re-search-backward arg (point-min) t)
192 (if (re-search-forward arg cp t)
193 (if (= (point) cp)
194 (setq return t)
196 return