3 ;; C Cross Referencing & Documentation tool. Version 1.3.
5 ;; Some useful Emacs lisp functions for use with cxref.
6 ;; Adds in comments of the appropriate format for cxref.
8 ;; Written by Andrew M. Bishop
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.
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
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)
38 (insert "\n")(c-indent-command)
39 (set-marker cp
(point))
40 (insert "\n***************************************/") (c-indent-command)
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"))
52 (goto-char (point-max))
53 (while (looking-at-backward "\n") (delete-char -
1))
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))
68 (while (looking-at-backward "\n\n") (delete-backward-char 1))
71 (insert "/*++++++++++++++++++++++++++++++++++++++") (c-indent-command)
73 (set-marker bp
(point))
75 (set-marker cp
(point))
76 (insert "++++++++++++++++++++++++++++++++++++++*/") (c-indent-command)
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_]"))
85 (search-forward "(") (backward-char)
87 (setq a
(buffer-substring as ae
))
90 (insert a
) (c-indent-line)
92 (set-marker cp
(point))
97 (search-forward "(") (set-marker fp
(point))
103 (if (looking-at-backward ")")
104 (throw 'finished-args t
))
106 (re-search-forward "[\n\t ]*")
107 (set-marker fp
(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
)))
117 (set-marker fp
(1+ (point)))
119 (re-search-backward "[\n\t ]*")
122 (setq a
(buffer-substring as ae
))
124 (if (not (or (string= a
"void") (string= a
"")))
128 (insert a
) (c-indent-line)
130 (set-marker cp
(point))
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)))
144 (while (looking-at-backward "\n\n") (delete-backward-char 1))
148 (set-marker fp
(point))
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)))
160 (indent-to-column (c-comment-indent))
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)))
175 (while (looking-at-backward "\n\n") (delete-backward-char 1))
179 (set-marker fp
(point))
183 (goto-char fp
) (c-indent-command)
186 ;; A Very Useful Function
188 (defun looking-at-backward (arg)
190 (let ((cp (point)) (return))
191 (if (re-search-backward arg
(point-min) t
)
192 (if (re-search-forward arg cp t
)