1 ;;;; Add to your ~/.emacs the following lines:
3 ;;;; (load-path "/full/path/to/this/file")
4 ;;;; (require 'cvc-devel)
6 ;;;; If you want to modify the key binding for inserting the comment,
7 ;;;; add also something like this:
9 ;;;; (setq cvc-devel-comment-key "\M-/")
12 (defvar cvc-devel-comment-key "\C-c\C-h"
13 "The hot key binding to insert an appropriate comment in C++ header
17 (add-to-list 'c++-mode-hook
19 (local-set-key cvc-devel-comment-key
20 'insert-comment-template)))
22 (defun insert-comment-template ()
23 "Insert a comment template into C++ file in the CVC style. The
24 comment is different depending on where it is inserted. For example,
25 inserting it in the empty file will produce a file comment, a class
26 comment will be inserted before a class definition, and so on."
33 (cond ((not (search-forward "#define" nil t))
34 (throw 'not-macro t)))
36 (cond ((not (= (mark) (point)))
39 (throw 'not-macro t))))
40 ; It's a macro: insert the comment template
42 (re-search-forward "[^ ]")
45 (re-search-forward " \\|(\\|^")
47 (copy-region-as-kill (mark) (point))
50 "/*****************************************************************************/
57 (insert-string (user-full-name))
61 (insert-string (current-time-string))
66 /*****************************************************************************/
77 (cond ((not (search-forward "(" nil t))
78 (throw 'not-function t)))
80 (cond ((not (= (mark) (point)))
83 (throw 'not-function t))))
84 ; It's a function: insert the comment template
86 (re-search-backward "[^ ] *(")
89 (re-search-backward " \\|^.")
90 (re-search-forward "[^ ]")
92 (copy-region-as-kill (mark) (point))
95 "/*****************************************************************************/
102 (insert-string (user-full-name))
106 (insert-string (current-time-string))
111 /*****************************************************************************/
114 (search-forward "* ")
122 (cond ((not (search-forward "class" nil t))
123 (throw 'not-class t)))
125 (cond ((not (= (mark) (point)))
128 (throw 'not-class t))))
129 ; It's a class definition: insert the comment template
131 (re-search-forward "[^ ]")
134 (re-search-forward "^\\| \\|{")
136 (copy-region-as-kill (mark) (point))
139 "/*****************************************************************************/
149 (insert-string (user-full-name))
153 (insert-string (current-time-string))
158 /*****************************************************************************/
161 (search-forward "* ")
169 (beginning-of-buffer)
170 (cond ((not (= (mark) (point)))
173 (throw 'not-bof t))))
174 ; At beginning of file: insert beginning of file comment
176 "/*****************************************************************************/
179 (insert-string (file-name-nondirectory (buffer-file-name)))
184 (insert-string (user-full-name))
188 (insert-string (current-time-string))
191 /*****************************************************************************/
194 (search-forward "brief ")
198 ; Insert default comment template
200 "/*****************************************************************************/
204 /*****************************************************************************/
207 (search-forward "* ")