1 ;;; cc-ide.el --- C++ IDE
5 ;; Copyright (C) 2000 Stefan Bund
7 ;; cc-ide.el is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; cc-ide.el is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
26 (defvar ccide-compile-opts "DEBUG=1"
27 "*Additional options to make command")
29 (defvar ccide-file-vars nil)
31 (defvar ccide-default-author "")
32 (defvar ccide-default-copyright "")
34 (defvar ccide-all-includes nil
35 "*If non-nil, this is the name of a file to include to fetch all
36 includes of a project. This is used if single include files cannot be
39 (defvar ccide-corba-skel-dir "")
40 (defvar ccide-corba-idl-dir "")
41 (defvar ccide-corba-idl-command "omniidl2 -w")
43 (defvar c-user-prefixes '("inline" "static" "prefix_")
44 "*List of possible prefixes for function definitions.")
46 (defvar ccide-default-prefix "prefix_"
47 "*Prefix added to every implementation header. Probably eiter empty or 'prefix_'")
49 (defvar ccide-gen-throw nil
50 "*If non-nil, generate throw_ specs")
52 (defvar ccide-project-root)
54 (defconst c-user-prefix-re (regexp-opt c-user-prefixes t))
56 (defconst ccide-doxy-tag-re
57 (concat "\\\\\\(group\\|defgroup\\|see\\|author\\|version\\|id\\|since"
58 "\\|returns?\\|throws?\\|exception\\|raises\\|param\\|li\\|brief"
59 "\\|internal\\|bug\\|fixme\\|todo\\|idea\\|implementation"
60 "\\|note\\|attention\\|warning\\|par\\|code\\|endcode"
61 "\\|post\\|pre\\|deprecated\\)\\b"))
63 (defconst ccide-special-extensions
64 '(".h" ".hh" ".mpp" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci" ".dox"))
66 (defconst ccide-implementation-extensions
67 '(".h" ".hh" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci"))
69 (defconst ccide-class-defaults-word
70 "// \\(default\\|no\\|protected\\|private\\|disabled\\|my\\)")
72 (defconst ccide-bindings
75 ("fc" ccide-file-comment "File comment")
76 ("fs" ccide-syncronize-includes "Sync includes")
80 ("cc" ccide-class-comment "Class comment")
81 ("cg" ccide-gen-class "Generate class")
82 ("cd" ccide-gen-class-defaults "Generate class defaults")
83 ("cD" ccide-gen-class-defaults-impl "Generate class defaults impl")
85 ("csd" ccide-set-class-defaults-default "Set class defaults comment" "Default")
86 ("csn" ccide-set-class-defaults-no "Set class defaults comment" "No")
87 ("csp" ccide-set-class-defaults-protected "Set class defaults comment" "Protected")
88 ("csr" ccide-set-class-defaults-private "Set class defaults comment" "Private")
89 ("csx" ccide-set-class-defaults-disabled "Set class defaults comment" "Disabled")
90 ("csm" ccide-set-class-defaults-my "Set class defaults comment" "My")
92 ("cS" ccide-gen-struct-constructors "Generate structure constructors")
94 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
96 ("ce" ccide-gen-exception "Generate an exception class")
101 ("mc" ccide-function-comment "Method comment")
102 ("mp" ccide-grab-prototype "Grab prototype")
103 ("mr" ccide-reformat-defun "Reformat defun")
104 ("mx" ccide-replace-defun "Replace defun")
105 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
106 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
107 ("mi" ccide-grab-inline-decl "Grab inline decl")
108 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
109 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
110 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
111 ("mf" ccide-find-implementation "Find method implementation")
112 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
116 ("vc" ccide-variable-comment "Variable comment")
117 ("vf" ccide-grab-access-fn "Grab access methods")
121 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
122 ("s" ccide-show-all-comments "Show all Doxygen comments")
125 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
126 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
127 ; (nil nil separator)
130 ; ("ts" ccide-scan-mantemps "Scan mantemps")
131 ; (nil nil separator)
134 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
135 ; ("oc" ccide-compile-compile "Make -> Compile")
136 ; ("ox" ccide-compile-clean "Make -> Clean")
137 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
138 ; ("ok" ccide-compile-kill "Kill compilation")
139 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
145 (require 'cc-engine-2)
154 (require 'misc-local)
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 (defsubst ccide-match-string (n)
160 (buffer-substring-no-properties (match-beginning n) (match-end n)))
162 (defun ccide-file-macro-name (&optional file-name)
163 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
165 (string-replace "\\." "_" (file-name-sans-extension
166 (file-name-nondirectory
167 (or file-name (buffer-file-name))))
171 (defun ccide-file-name (&optional extension file-name directory)
172 (concat (if directory (file-name-as-directory directory) "")
173 (file-name-sans-extension
174 (file-name-nondirectory
175 (or file-name (buffer-file-name))))
178 (defun ccide-in-doxy-comment ()
180 (back-to-indentation)
181 (let ((lit (c-in-literal)))
182 (if (cond ((eq lit 'c)
183 (goto-char (car (c-literal-limits)))
184 (looking-at "/\\*\\*<?[ \t\n\r@]"))
186 (goto-char (car (c-literal-limits)))
187 (looking-at "///<?[ \t\n\r@]"))
190 (goto-char (match-end 0))
191 (current-column))))))
193 (defun ccide-shell-command (command)
194 (let ((obuf (get-buffer-create "*ccide shell command*"))
199 (insert command "\n"))
200 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
201 shell-command-switch command))
202 (and exit-status (equal exit-status 0))))
204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
207 (defun ccide-file-comment ()
208 "Add a comment to this source file."
213 (goto-char (point-min))
216 "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
217 " " ccide-default-author "\n"
218 ccide-default-copyright
221 (cond ((string-match "\\.hh?$" (buffer-file-name))
222 (insert "/** \\file\n"
223 " \\brief " (ccide-file-name) " public header */\n\n"
224 "#ifndef " (ccide-file-macro-name) "\n"
225 "#define " (ccide-file-macro-name) " 1\n\n")
226 (if ccide-all-includes
227 (insert "#ifndef " (ccide-file-macro-name ccide-all-includes) "\n"
228 "#error \"Don't include '" (file-name-nondirectory (buffer-file-name)) "'"
229 " directly, include '" ccide-all-includes "'\"\n"
231 (insert "// Custom includes\n\n"
232 "//#include \"" (ccide-file-name ".mpp") "\"\n"
233 "///////////////////////////////hh.p////////////////////////////////////////\n\n")
235 (goto-char (point-max))
236 (insert "\n\n///////////////////////////////hh.e////////////////////////////////////////\n")
237 (if ccide-all-includes
239 "#if !defined(" (ccide-file-macro-name ccide-all-includes) "_decls_) "
240 "&& !defined(" (ccide-file-macro-name) "i_)\n"
241 "#define " (ccide-file-macro-name) "i_\n"))
242 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
243 "//#include \"" (ccide-file-name ".ct") "\"\n"
244 "//#include \"" (ccide-file-name ".cti") "\"\n"
247 ((string-match "\\.mpp$" (buffer-file-name))
248 (insert "/** \\file\n"
249 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
252 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
253 "#define " (ccide-file-macro-name) " 1\n\n"
254 "// Custom includes\n\n\n"
255 "// ///////////////////////////mpp.p////////////////////////////////////////\n"
256 "#elif BOOST_PP_IS_ITERATING // ////////////////////////////////////////////\n"
257 "// ////////////////////////////////////////////////////////////////////////\n"
258 "// Local Macros\n\n\n"
259 "// ////////////////////////////////////////////////////////////////////////\n"
260 "#if BOOST_PP_ITERATION_FLAGS()==1 // //////////////////////////////////////\n"
261 "// ////////////////////////////////////////////////////////////////////////\n\n")
263 (goto-char (point-max))
264 (insert "\n\n// ////////////////////////////////////////////////////////////////////////\n"
265 "#endif // /////////////////////////////////////////////////////////////////\n"
266 "// ////////////////////////////////////////////////////////////////////////\n"
267 "// Undefine local Macros\n\n\n"
268 "// ////////////////////////////////////////////////////////////////////////\n"
269 "#endif // /////////////////////////////////////////////////////////////////\n"
270 "// ///////////////////////////mpp.e////////////////////////////////////////"))
272 ((string-match "\\.ih$" (buffer-file-name))
273 (insert "/** \\file\n"
274 " \\brief " (ccide-file-name) " internal header */\n\n"
275 "#ifndef " (ccide-file-macro-name) "\n"
276 "#define " (ccide-file-macro-name) " 1\n\n"
277 "// Custom includes\n\n"
278 "///////////////////////////////ih.p////////////////////////////////////////\n\n")
280 (goto-char (point-max))
281 (insert "\n\n///////////////////////////////ih.e////////////////////////////////////////\n"
284 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
285 (string-match "\\.test\\.cpp$" (buffer-file-name)))
286 (insert "/** \\file\n"
287 " \\brief " (ccide-file-name) " unit tests */\n\n"
288 "//#include \"" (ccide-file-name ".hh") "\"\n"
289 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
290 "// Custom includes\n"
291 "#include \"" (or ccide-all-includes
292 (ccide-file-name ".hh" (ccide-file-name))) "\"\n\n"
293 "#include <boost/test/auto_unit_test.hpp>\n"
294 "#include <boost/test/test_tools.hpp>\n\n"
296 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
298 (goto-char (point-max))
299 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
302 ((or (string-match "\\.cc$" (buffer-file-name))
303 (string-match "\\.cpp$" (buffer-file-name)))
304 (insert "/** \\file\n"
305 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
306 (if ccide-all-includes "" "//")
307 "#include \"" (or ccide-all-includes (ccide-file-name ".hh")) "\"\n"
308 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
309 "// Custom includes\n\n"
310 "//#include \"" (ccide-file-name ".mpp") "\"\n"
312 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
314 (goto-char (point-max))
315 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
317 "//#include \"" (ccide-file-name ".mpp") "\""))
319 ((string-match "\\.cci$" (buffer-file-name))
320 (insert "/** \\file\n"
321 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
322 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
323 "// Custom includes\n\n"
324 "#define prefix_ inline\n"
325 "///////////////////////////////cci.p///////////////////////////////////////\n\n")
327 (goto-char (point-max))
328 (insert "\n\n///////////////////////////////cci.e///////////////////////////////////////\n"
331 ((string-match "\\.ct$" (buffer-file-name))
332 (insert "/** \\file\n"
333 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
334 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
335 "// Custom includes\n\n"
337 "///////////////////////////////ct.p////////////////////////////////////////\n\n")
339 (goto-char (point-max))
340 (insert "\n\n///////////////////////////////ct.e////////////////////////////////////////\n"
343 ((string-match "\\.cti$" (buffer-file-name))
344 (insert "/** \\file\n"
345 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
346 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
347 "// Custom includes\n\n"
348 "#define prefix_ inline\n"
349 "///////////////////////////////cti.p///////////////////////////////////////\n\n")
351 (goto-char (point-max))
352 (insert "\n\n///////////////////////////////cti.e///////////////////////////////////////\n"
355 ((string-match "\\.dox$" (buffer-file-name))
356 (insert "/** \\mainpage\n\n ")
359 (setq add-file-vars '(( mode . flyspell)
360 ( mode . auto-fill))))
362 ((string-match "\\.java$" (buffer-file-name))
365 (goto-char (point-max)))
369 (goto-char (point-max))))
372 "// Local Variables:\n"
373 "// mode: " mode "\n")
374 (loop for (var . value) in ccide-file-vars
375 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
376 (loop for (var . value) in add-file-vars
377 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
381 (if (equal mode "jde")
382 (let ((package (file-name-directory (buffer-file-name))))
383 (jdeap-initialize-setup)
384 (if (not (equal jdeap-current-source-directory "."))
386 (concat "^" (regexp-quote jdeap-current-source-directory))
389 (setq package (substring package
391 (1- (length package))))
393 (string-replace "/" "." package t)
395 (insert "class " (file-name-sans-extension
396 (file-name-nondirectory
397 (buffer-file-name))) "\n{}")
398 (beginning-of-line)))))
400 (defun ccide-sync-file-variables ()
401 "Syncronize file variables to the current value of ccide-file-vars"
404 (goto-char (point-max))
405 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
406 (let ((case-fold-search t))
407 (if (search-forward "Local Variables:" nil t)
408 (let (prefix suffix vars)
409 (skip-chars-forward " \t")
411 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
412 (goto-char (match-beginning 0))
414 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
417 (if (and prefix (looking-at prefix))
418 (goto-char (match-end 0)))
419 (skip-chars-forward " \t"))
420 while (not (looking-at "end:"))
422 (setq vars (cons (intern (buffer-substring
424 (progn (skip-chars-forward "^:\n") (point))))
427 (loop for (var . value) in ccide-file-vars
428 do (if (not (memq var vars))
429 (insert (or prefix "")
430 (symbol-name var) ": " (prin1-to-string value)
431 (or suffix "") "\n"))))))))
433 (defun ccide-syncronize-includes ()
434 "Syncronize include's in all other files"
437 (loop for extension in ccide-special-extensions
438 for file-name = (ccide-file-name extension)
440 (cons (cons file-name
441 (or (find-buffer-visiting file-name)
442 (and (file-readable-p file-name)
443 (find-file-noselect file-name))))
446 (loop for buffer in buffer-map
449 (set-buffer (cdr buffer))
451 (loop for include in buffer-map
453 (goto-char (point-min))
454 (while (re-search-forward
455 (concat "^\\(//\\)?#\\s-*include \""
456 (regexp-quote (car include))
459 (goto-char (match-beginning 0))
460 (if (looking-at "//")
463 (if (not (cdr include))
465 (forward-line 1))))))))))
467 (defun ccide-auto-decorate-new-files ()
468 (if (= (point-min) (point-max))
469 (let ((status (buffer-modified-p)))
471 (set-buffer-modified-p status))))
473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
476 (defun ccide-class-comment ()
477 "Add comment to start of current class definition"
479 (let ((class (c-get-class-at-point)))
481 (error "No class found")
482 (goto-char (or (aref (car class) 3)
483 (aref (car class) 1)))
486 (ccide-in-doxy-comment))
488 (search-backward "/**" nil t)
490 (let ((indent (make-string (current-indentation) ? )))
491 (insert "/** \\brief ")
497 (defun ccide-gen-class (name &optional defns)
498 "Generate class declaration template"
499 (interactive (list (read-string (concat "Class name (default "
502 nil nil (ccide-file-name))))
503 (insert "class " name)
504 (indent-according-to-mode)
505 (let ((in (make-string c-basic-offset ? ))
506 (ofs (make-string (current-indentation) ? )))
510 (insert ofs "/** \\brief\n"
516 ofs in "///////////////////////////////////////////////////////////////////////////\n"
517 ofs in "// Types\n\n"
518 ofs in "///////////////////////////////////////////////////////////////////////////\n"
519 ofs in "///\\name Structors and default members\n"
521 ofs in "// default default constructor\n"
522 ofs in "// default copy constructor\n"
523 ofs in "// default copy assignment\n"
524 ofs in "// default destructor\n\n"
525 ofs in "// no conversion constructors\n\n"
527 ofs in "///////////////////////////////////////////////////////////////////////////\n"
528 ofs in "///\\name Accessors\n"
531 ofs in "///////////////////////////////////////////////////////////////////////////\n"
532 ofs in "///\\name Mutators\n"
535 (loop for defn in defns
536 do (insert ofs in defn ";\n"))
539 (insert ofs "protected:\n\n"
543 (defun ccide-gen-class-defaults ()
544 "Generate signatures of the default functions: default constructor,
545 copy constructor, assignment operator and destructor."
546 (indent-according-to-mode)
547 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
548 (in (make-string c-basic-offset ? ))
549 (ofs (make-string (current-indentation) ? ))
550 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
552 (while (string-match "::" name colon)
553 (setq colon (match-end 0)))
554 (setq name (substring name colon))
556 (delete-horizontal-space)
557 (loop with exit = nil
558 do (message (concat "1-dflt constr, 2-destr, "
559 "3-copy constr, 4-copy assmnt, "
560 "c-all copy, d-all dflt, RET-all/done: "))
561 for ch = (read-event)
562 for first = t then nil
563 do (cond ((eq ch 'return)
565 (insert ofs name "()"
567 ofs name "(const " name "& other)"
570 ofs name "& operator=(const " name "& other)"
574 (insert ofs name "()"
577 (insert ofs "~" name "();\n"))
579 (insert ofs name "(const " name "& other)"
582 (insert ofs name "& operator=(const " name "& other)"
585 (insert ofs name "(const " name "& other)"
587 ofs name "& operator=(const " name "& other)"
590 (insert ofs name "()"
592 ofs "~" name "();\n"))
593 (t (setq unread-command-events (cons ch unread-command-events))
597 (defun ccide-gen-class-defaults-impl ()
598 "Generate default implementations for class default functions"
600 (let ((defn (c-build-default-funcions-impl)))
601 (kill-new (cadr defn))
602 (message (concat (car defn) " default members"))))
604 (defun ccide-set-class-defaults-comment (word)
606 (back-to-indentation)
607 (if (not (looking-at ccide-class-defaults-word))
608 (message "Not at class defaults commnet")
609 (replace-match word t t nil 1))))
611 (defmacro ccide-build-class-defaults-f (sym)
612 (let ((fn (intern (concat "ccide-set-class-defaults-"
613 (symbol-name sym)))))
616 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
618 (ccide-build-class-defaults-f no)
619 (ccide-build-class-defaults-f default)
620 (ccide-build-class-defaults-f my)
621 (ccide-build-class-defaults-f protected)
622 (ccide-build-class-defaults-f private)
623 (ccide-build-class-defaults-f disabled)
625 (defun ccide-gen-struct-constructors ()
629 (indent-according-to-mode)
630 (let* ((scope (c-get-block-scope))
631 (class (c-parse-class scope))
632 (variables (c-get-variable-members-with-type class))
633 (name (c-scope-name (aref (car (last scope)) 1)))
634 (in (make-string (current-indentation) ? ))
635 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
636 (insert name "()\n" inin ": ")
637 (indent-according-to-mode)
638 (loop for var in variables
639 for first = t then nil
640 if (not first) do (insert ", ")
641 do (insert (car var) "()"))
642 (insert "\n" in "{}\n"
644 (loop for var in variables
645 for first = t then nil
646 if (not first) do (insert ", ")
647 do (insert (cdr var) " " (car var) "_"))
648 (insert ")\n" inin ": ")
649 (loop for var in variables
650 for first = t then nil
651 if (not first) do (insert ", ")
652 do (insert (car var) "(" (car var) "_)"))
653 (insert "\n" in "{}"))))
655 (defun ccide-class-impl-comment ()
656 "Get implementation comment for current class"
658 (let* ((scope (c-get-block-scope))
659 (name (c-get-full-prefix scope)))
660 (kill-new (concat (make-string 75 ?/) "\n"
666 (defun ccide-gen-exception (class &optional description)
667 (interactive "sException name: \nsDescription (defaults to full class name): ")
670 (indent-according-to-mode)
672 (let ((in (make-string c-basic-offset ? ))
673 (ofs (make-string (current-indentation) ? ))
674 (prefix (c-get-full-prefix (c-get-block-scope)))
676 (insert "struct " class " : public std::exception\n"
677 ofs "{ virtual char const * what() const throw() ")
679 (insert "{ return \""
680 (if (and description (> (length description) 0))
682 (concat prefix "::" class))
684 (if (> (current-column) fill-column)
687 (insert "\n" ofs in in))))))
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
690 ;; function/method level
692 (defun ccide-function-comment ()
693 "Add comment for current function"
695 (if (memq (c-in-literal) '(c c++))
696 ; Assume, we are in the functions comment ...
698 (c-forward-out-of-comment)
699 (c-backward-syntactic-ws)
702 (c-beginning-of-defun-or-decl)
703 (let ((defun (c-get-defun-state))
704 (indent (make-string comment-column ? ))
706 (goto-char (or (aref defun 7) (car (aref defun 6))))
707 (c-backward-syntactic-ws)
708 (if (looking-at "[ \t\n\r]*///<")
710 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
711 (if (> (current-column) comment-column)
713 (indent-to-column comment-column)
714 (search-forward "*/")
716 (if (> (current-column) comment-column)
718 (indent-to-column comment-column)
726 (goto-char (car (aref defun 2)))
727 (setq defun (c-get-defun-state)))
729 (ccide-function-comment-adjust defun (concat indent " "))
730 (if place (goto-char place))))
732 (defun ccide-function-comment-grab-args ()
733 (let ((limit (save-excursion
734 (search-backward "/**" nil t)
737 begin start args argend)
739 (while (or (search-backward "\\param" limit t)
740 (search-backward "\\return" limit t)))
744 (while (search-forward "\\param" argend t)
745 (or (search-forward "\\param" argend t)
746 (search-forward "\\return" argend t)
749 (setq args (cons (ccide-function-comment-parse-arg start (point))
751 (setq start (point)))
753 (if (not (search-forward "\return" argend t))
756 (cons (buffer-substring (point) argend) args))
757 (delete-region begin end))))
759 (defun ccide-function-comment-parse-arg (start end)
762 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
763 (cons (match-string 2)
764 (cons (buffer-substring start (match-beginning 2))
765 (buffer-substring (match-end 2) end)))))
767 (defun ccide-function-comment-get-throws (defun)
770 (goto-char (car (aref defun 4)))
771 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
772 (cdr (aref defun 4)) t)
773 (let ((spec (match-string 2)))
774 (if (> (length spec) 0)
777 (defun ccide-function-comment-adjust (defun indent)
779 (let* ((defargs (mapcar (function (lambda (x)
780 (c-get-template-argument-name (car x) (cdr x))))
782 (defret (and (aref defun 1)
783 (not (string-match (concat "^\\("
785 "\\s-*\\)*\\s-*void$")
786 (buffer-substring (car (aref defun 1))
787 (cdr (aref defun 1)))))))
788 (throws (ccide-function-comment-get-throws defun))
789 (xargs (ccide-function-comment-grab-args))
790 (docargs (cdr xargs))
792 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
793 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
794 (size-eq (= (length defargs) (length docargs))))
795 ;; We differentiate four types changes
797 ;; - removed arguments
798 ;; - reordered arguments
799 ;; - renamed arguments
801 ;; If the change cannot be described by one of the above, it has
802 ;; to be resolved manually
804 (insert indent "\\throws " throws "\n"))
806 ;; reordered arguments or new arguments (or no change)
807 (loop for defarg in defargs
808 for docarg = (assoc defarg docargs)
810 (insert (cadr docarg) (car docarg) (cddr docarg))
811 (insert indent "\\param " defarg " \n"))))
812 (size-eq ; and (not doc-in-def)
814 (loop for defarg in defargs
815 for docarg in docargs
816 do (insert (cadr docarg) defarg (cddr docarg))))
819 (loop for defarg in defargs
820 for docarg = (assoc defarg docargs)
821 do (insert (cadr docarg) (car docarg) (cddr docarg))))
822 (t (error "Arg change too complex. Resolve manualy.")))
823 ;; return value is simple
827 (insert indent "\\return \n"))))
829 (delete-horizontal-space)
832 (defun ccide-grab-prototype (&optional prefix)
833 "Grab prototype of function defined or declared at point. Prefix
834 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
837 (c-beginning-of-defun-or-decl)
838 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
839 ccide-default-prefix))
840 (defn (c-build-defun prfx)))
841 (kill-new (concat (cadr defn) "\n{}\n"))
842 (message (concat (or prfx "")
846 (defun ccide-reformat-defun ()
847 "Reformat the defn of the current defun."
850 (c-beginning-of-defun-or-decl)
851 (let ((defn (c-build-defun nil t)))
852 (delete-region (or (caar (aref (caddr defn) 0))
853 (car (aref (caddr defn) 1))
854 (car (aref (caddr defn) 2)))
855 (or (car (aref (caddr defn) 6))
856 (aref (caddr defn) 7)))
857 (insert (cadr defn) "\n"))))
859 (defun ccide-replace-defun ()
860 "Replace the function header with the one on the top of the kill
861 ring (presumably placed there using c++-grab-prototype)."
864 (c-beginning-of-defun-or-decl)
865 (let ((parse (c-parse-defun)))
866 (delete-region (or (aref parse 0)
875 (defun ccide-prefix-defun-type-with-class (&optional strip)
876 "If a non-keyword type symbol is found prefixing the current defun,
877 it will be prefixed with the current class prefix."
880 (c-beginning-of-defun-or-decl)
881 (let* ((parse (c-parse-defun))
882 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
883 (goto-char (aref parse 1))
884 (while (and (or (looking-at c-any-key)
885 (looking-at c-user-prefix-re)
886 (not (c-at-symbol-p)))
887 (< (point) (aref parse 2))
890 (c-forward-syntactic-ws))
891 (if (and (c-at-symbol-p)
892 (< (point) (aref parse 2))
893 (not (looking-at (regexp-quote prefix))))
894 (let ((pos (string-match "<" prefix)))
896 (insert "typename "))
897 (if (and pos (looking-at (concat (substring prefix 0 pos)
900 (goto-char (match-end 0))
901 (c-backward-syntactic-ws)
902 (insert (substring prefix pos)))
903 (insert prefix "::"))
904 (ccide-reformat-defun))))))
906 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
908 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
910 (defun ccide-insert-defun-prefix (&optional strip)
911 "Insert the current defun prefix at point."
913 (let* ((parse (c-parse-defun))
914 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
915 (insert prefix "::")))
917 (defun ccide-kill-inline-decl (defn)
919 (if (aref (caddr defn) 6)
921 (goto-char (cdr (aref (caddr defn) 6)))
922 (let ((end-mark (point-marker)))
923 (goto-char (car (aref (caddr defn) 6)))
924 (indent-rigidly (point) end-mark
925 (- (current-column)))
929 (buffer-substring-no-properties (point) end-mark)
931 (when (aref (caddr defn) 5)
932 (goto-char (caar (aref (caddr defn) 5)))
933 (c-backward-syntactic-ws)
934 (skip-chars-backward ":"))
935 (c-backward-syntactic-ws)
936 (delete-region (point) end-mark)
938 (concat (cadr defn) "\n{}\n"))))
940 (defun ccide-grab-inline-decl ()
941 "Grab the inline decl at point at turn it into an out-of-line inline
942 declaration at the top of the kill ring."
944 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
945 (kill-new (ccide-kill-inline-decl defn))
946 (message (concat (or ccide-default-prefix "indline")
950 (defun ccide-grab-all-inlines ()
951 "Grab all inline decls in the current class"
953 (let ((class (c-parse-class (c-get-block-scope)))
956 (loop for method in (nreverse (aref class 4))
957 do (when (eq (car method) 'method)
958 (let ((defn (save-excursion
959 (goto-char (cdr method))
960 (c-build-defun (or ccide-default-prefix "inline")))))
961 (if (aref (caddr defn) 6)
962 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
963 (kill-new (loop for defn in (nreverse defns)
964 for next = nil then t
967 (message (format "%d inlines grabed to kill ring" (length defns))))))
970 (defun ccide-grab-create-constructor ()
972 (let ((defn (c-build-create-constructor)))
973 (kill-new (cadr defn))
974 (message (car defn))))
976 (defun ccide-grab-create-constructor-impl (&optional prefix)
978 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
979 ccide-default-prefix))
980 (defn (c-build-create-constructor-impl prfx)))
981 (kill-new (cadr defn))
982 (message (concat (or prfx "")
986 (defun ccide-find-implementation (&optional other-window)
987 "Find implementation of method declared at point."
989 (let* ((state (c-get-defun-state))
990 (name (c-defun-short-name state))
991 (scoped-name (c-defun-full-name state))
992 (args (ccide-implementation-args state))
993 (targs (ccide-implementation-template-args state))
996 (loop for ext in ccide-implementation-extensions
997 for filename = (ccide-file-name ext)
1000 (let ((buf (or (find-buffer-visiting filename)
1001 (and (file-readable-p filename)
1002 (find-file-noselect filename)))))
1004 (let ((found (save-excursion
1006 (ccide-find-implementation-1 name scoped-name args targs
1007 (not (aref state 6))
1008 (car (aref state 2))))))
1011 (setq rv (cons buf found))
1012 (if (not fallback) (setq fallback (cons buf found))))))))))
1013 (if (not rv) (setq rv fallback))
1015 (let* ((buf (car rv))
1017 (win (get-buffer-window buf)))
1021 (switch-to-buffer-other-window buf)
1022 (switch-to-buffer buf)))
1025 (c-beginning-of-defun-or-decl))
1026 (message (concat "Implementation of " scoped-name " not found.")))))
1028 (defun ccide-implementation-args (state)
1029 (string-replace "[ \t\n\r]+" ""
1030 (loop for (start . end) in (aref state 3)
1031 for sep = "" then ","
1033 concat (buffer-substring-no-properties
1034 start (save-excursion
1036 (if (search-forward "=" end 'move) (forward-char -1))
1041 (defun ccide-implementation-template-args (state)
1043 (string-replace "[ \t\n\r]+" ""
1044 (loop for (start . end) in (save-excursion
1045 (goto-char (caar (last (aref state 0))))
1046 (c-parse-template-declaration))
1047 for sep = "" then ","
1049 concat (buffer-substring-no-properties
1050 start (save-excursion
1052 (if (search-forward "=" end 'move) (forward-char -1))
1056 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1057 ;; Within the current buffer, search for all implementations of the
1058 ;; given function. The rv is a list of conses. The car holds the
1059 ;; buffer position of the implementation, the cdr is t if the name,
1060 ;; scoped-name and args are matched, otherwise the args did not match.
1062 (goto-char (point-min))
1063 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1065 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1066 fallback rv check-state)
1067 (while (and (not rv) (re-search-forward re nil t))
1068 (if (and (c-at-toplevel-p)
1069 (not (c-in-literal))
1070 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1071 (not (= (car (aref check-state 2)) skip-def)))
1072 (if (string= scoped-name (c-defun-full-name check-state))
1073 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1074 (string= args (ccide-implementation-args check-state))
1075 (string= targs (ccide-implementation-template-args check-state)))
1076 (setq rv (cons (point) t))
1078 (setq fallback (cons (point) nil)))))))
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1082 ;; variable/type level
1084 (defun ccide-variable-comment ()
1085 "Add a comment to current variable declaration."
1087 (c-forward-out-of-comment)
1088 (c-forward-syntactic-ws)
1089 (while (not (looking-at ";"))
1091 (c-forward-syntactic-ws))
1093 (if (> (current-column) comment-column)
1094 (insert "\n" (make-string comment-column ? ) "///< ")
1095 (indent-to-column comment-column)
1098 (defun ccide-grab-access-fn ()
1102 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1103 (let ((vardef (match-string 0))
1104 (in (make-string c-basic-offset ? ))
1105 type reftype varname fnname argname ws)
1107 (back-to-indentation)
1108 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1110 (setq varname (match-string 2 vardef)
1111 type (match-string 1 vardef)
1112 ws (substring vardef 0 (match-beginning 1)))
1113 (if (string-match "_$" varname)
1114 (setq fnname (string-replace "_$" "" varname)
1115 argname (concat "a_" fnname))
1116 (setq fnname (concat "q_" varname)
1117 argname (concat "a_" varname)))
1118 (if (string-match "^[ \t\n\r]*" type)
1119 (setq type (substring type (match-end 0))))
1120 (if (string-match "^[A-Z]" type)
1121 (setq reftype (concat type " const &"))
1122 (setq reftype type))
1123 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1125 ws in in type " old" varname " = " varname ";\n"
1126 ws in in varname " = " argname ";\n"
1127 ws in in "return old" varname ";\n"
1129 ws reftype " " fnname "() const\n"
1130 ws in "{ return " varname "; }\n"))
1133 (message "No variable found"))))
1135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1136 ;; doxy comment support functions
1138 (defun ccide-special-indent-function ()
1139 "Function to indent doxy comments correctly"
1140 (let ((indent (ccide-in-doxy-comment)))
1142 (let ((lim (save-excursion
1143 (back-to-indentation)
1144 (c-literal-limits)))
1145 (pos (- (point-max) (point))))
1147 (back-to-indentation)
1148 (if (looking-at "*/")
1150 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1152 (if (and (not (looking-at ccide-doxy-tag-re))
1153 (re-search-backward (concat "^\\s-*"
1157 (delete-region (progn (beginning-of-line) (point))
1158 (progn (back-to-indentation) (point)))
1160 (if (> (- (point-max) pos) (point))
1161 (goto-char (- (point-max) pos)))))))
1163 (defun ccide-fill-function ()
1164 "auto-fill function for doxy comments"
1166 (if (not fill-prefix)
1167 (indent-according-to-mode))))
1169 (defun ccide-hide-all-doxy-comments ()
1170 "Hide all doxy comments"
1173 (goto-char (point-min))
1174 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1177 (if (not (looking-at "\\s-*$"))
1180 (let ((start (point)))
1181 (if (re-search-forward "\\*/" nil t)
1183 (if (looking-at "\\s-*\n")
1186 (let ((overlay (make-overlay start (point))))
1187 (overlay-put overlay 'intangible 'hs)
1188 (overlay-put overlay 'invisible 'hs)))))))
1191 (defun ccide-show-all-comments ()
1195 (goto-char (point-min))
1197 (goto-char (next-overlay-change (point)))
1198 (loop for overlay in (overlays-at (point))
1199 if (eq (overlay-get overlay 'invisible) 'hs)
1200 do (delete-overlay overlay))))
1203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1204 ;; CORBA support (omniORB2)
1206 (defun ccide-get-corba-headers ()
1209 (goto-char (point-min))
1210 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1211 (setq files (cons (ccide-match-string 1) files)))
1214 (defun ccide-corba-maybe-build-hh (file)
1215 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1216 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1217 (if (and (file-readable-p idl)
1218 (or (not (file-readable-p skel))
1219 (file-newer-than-file-p idl skel)))
1220 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1222 (kill-buffer buffer))
1223 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1224 (if (ccide-shell-command (concat "cd "
1225 (real-path-name ccide-corba-skel-dir)
1227 ccide-corba-idl-command
1228 (if (> (length ccide-corba-idl-dir) 0)
1229 (concat " -I" ccide-corba-idl-dir))
1233 (display-buffer (get-buffer-create "*ccide shell command*"))
1234 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1235 (if (not (file-readable-p skel))
1236 (error "No file %s or %s"
1237 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1239 (defun ccide-corba-list-skeletons-1 (hh-file)
1240 (ccide-corba-maybe-build-hh hh-file)
1241 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1246 (goto-char (point-min))
1247 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1249 (setq skels (cons (ccide-match-string 1) skels)))))
1250 (mapcar (function (lambda (x) (cons x hh-file)))
1251 (sort skels 'string-lessp))))
1253 (defun ccide-corba-list-skeletons ()
1254 (let ((files (ccide-get-corba-headers)))
1255 (loop for file in files
1256 append (ccide-corba-list-skeletons-1 file))))
1258 (defun ccide-gen-corba-impl (class)
1259 (interactive (list (completing-read "Class name of skeleton: "
1260 (ccide-corba-list-skeletons)
1262 (let* ((skels (ccide-corba-list-skeletons))
1263 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1264 ccide-corba-skel-dir))
1265 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1266 ccide-corba-skel-dir))))
1267 (ccide-gen-class (concat class "_i"))
1268 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1270 (search-forward "protected:" nil t)
1272 (ccide-gen-corba-impl-methods)
1275 (defun ccide-get-corba-defns (hh-file class)
1276 (let ((hh-buf (find-file-noselect hh-file))
1281 (goto-char (point-min))
1282 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1284 (error "CORBA skeleton class not found.")
1285 (search-forward "{")
1287 (let ((end (save-excursion (forward-sexp) (point))))
1288 (while (and (< (point) end)
1289 (< (forward-line 1) 1))
1290 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1291 (setq defns (cons (match-string 1) defns))))))))
1294 (defun ccide-gen-corba-impl-methods ()
1296 (let* ((class (c-get-class-at-point))
1299 (error "No class at point."))
1301 (goto-char (aref (car class) 1))
1302 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1304 (error "No CORBA impl at point."))
1305 (let* ((name (ccide-match-string 1))
1306 (skels (ccide-corba-list-skeletons))
1307 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1308 ccide-corba-skel-dir))
1309 (defns (ccide-get-corba-defns hh-file name))
1311 (goto-char (aref (car class) 2))
1315 (if (re-search-forward "^\\s-*// CORBA$" end t)
1316 (let ((start (match-beginning 0)))
1317 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1318 (let ((eend (match-end 0)))
1321 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1322 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1323 (delete-region start (1+ eend))
1326 (delete-region (point) (progn
1331 (delete-region (point) (progn
1335 (delete-region start (1+ eend))))))
1337 (indent-according-to-mode)
1338 (insert "// CORBA\n")
1339 (loop for defn in defns
1341 (save-excursion (insert defn ";"))
1342 (indent-according-to-mode)
1343 (let ((start (point)) end)
1347 (while (re-search-forward "\\s-+" end t)
1349 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1351 (loop with done = nil
1352 while (> (current-column) c-max-def-column)
1353 do (while (and (> (current-column) c-max-def-column)
1354 (search-backward "," start t)))
1355 do (if (looking-at ",")
1360 (indent-according-to-mode)
1362 (setq start (point))
1367 (indent-according-to-mode)
1368 (insert "// END-CORBA\n")))))
1370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1373 (defun ccide-scan-mantemps ()
1374 "Scan *compilation* buffer for errors and generate manual template
1375 instatiations at point."
1378 (set-buffer "*compilation*")
1379 (goto-char (point-min)))
1381 (set-buffer (get-buffer-create "*mantemps*"))
1383 (loop for temp = (ccide-get-mantemp)
1385 do (insert temp "\n"))
1386 (mantemp-make-mantemps-buffer)
1387 (goto-char (point-min))
1390 (< (forward-line 1) 1))))
1391 (insert-buffer-substring "*mantemps*"))
1393 (defun ccide-get-mantemp ()
1395 (set-buffer "*compilation*")
1396 (if (search-forward "undefined reference to `" nil t)
1397 (let ((start (point)))
1399 (search-backward "'" nil t)
1400 (buffer-substring start (point))))))
1402 (defun ccide-fix-mantemp ()
1403 (let ((end (save-excursion
1404 (end-of-line) (point))))
1405 (if (and (save-excursion (search-forward "(" end t))
1406 (search-forward " class" end t))
1413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1416 (defun ccide-open-compilation-frame ()
1418 (let ((c-frame (selected-frame))
1419 (compilation-frame (make-frame '((minibuffer . nil)
1421 (menu-bar-lines . 0)
1426 (select-frame compilation-frame)
1427 (switch-to-buffer "*compilation*")
1428 (set-window-dedicated-p (selected-window) t)))
1430 (defun ccide-compile (command)
1431 (delete-other-windows)
1432 (split-window-horizontally)
1435 (set-buffer "*compilation*")
1436 (let ((point (point-max)))
1438 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1439 do (set-window-point window point)))))
1441 (defun ccide-compile-compile ()
1443 (ccide-compile (concat "make -k " ccide-compile-opts)))
1445 (defun ccide-compile-clean ()
1447 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1449 (defun ccide-compile-cleandepends ()
1451 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1453 (defun ccide-compile-kill ()
1455 (set-buffer "*compilation*")
1458 (defun ccide-hide-compilation ()
1460 (let ((active (selected-window)))
1462 (loop for window in (get-buffer-window-list "*compilation*")
1463 do (progn (select-window window)
1464 (switch-to-buffer (other-buffer "*compilation*"))))
1465 (select-window active))))
1467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1468 ;; keymap and installation
1470 (defun ccide-bind-keys (prefix map)
1471 (loop for binding in ccide-bindings
1472 do (apply 'vcmd-define-key
1474 (concat prefix (car binding))
1479 (defun ccide-install-it ()
1483 (local-unset-key "\C-c;")
1484 (local-unset-key [menu-bar IDE])
1485 (ccide-bind-keys "\C-c;" (current-local-map))
1486 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1487 (local-set-key "\C-cS" 'ccide-show-all-comments)
1488 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1489 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1490 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1492 (ccide-project-load-config)
1493 (ccide-directory-load-config)
1494 (ccide-auto-decorate-new-files))
1496 (defun ccide-project-load-config ()
1497 (let ((conf (ccide-project-search-upwards "project.el" (file-name-directory (buffer-file-name)))))
1499 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1502 (defun ccide-project-search-upwards (file &optional dir)
1503 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1504 DIR defaults to ccide-project-root"
1505 (let (conf last-dir)
1506 (setq dir (expand-file-name "x" (or dir ccide-project-root)))
1507 (while (and (not (string= (setq last-dir dir
1508 dir (directory-file-name (file-name-directory dir))) last-dir))
1509 (setq conf (expand-file-name file dir))
1510 (not (file-readable-p conf))))
1511 (and (file-readable-p conf) conf)))
1513 (defun ccide-directory-load-config ()
1514 (if (file-readable-p ".dir.el")
1515 (load-file ".dir.el")))
1517 (add-hook 'c-mode-hook 'ccide-install-it)
1518 (add-hook 'c++-mode-hook 'ccide-install-it)
1519 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1521 (loop for extension in ccide-special-extensions
1522 for re = (concat (regexp-quote extension) "$")
1523 if (not (assoc re auto-mode-alist))
1524 do (setq auto-mode-alist (append auto-mode-alist
1525 (list (cons re 'c++-mode)))))
1527 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1528 ;; new indent function for c-mode: do standard indentation first. If line
1529 ;; is to long using standard indentation, just indent by c-basic-indentation.
1530 (let ((cc (save-excursion (end-of-line) (current-column)))
1533 (let ((pos (- (point-max) (point))))
1535 (let ((point (point))
1536 (line (1+ (count-lines 1 (point))))
1538 (c-beginning-of-statement-2)
1539 (if (and (not (c-crosses-statement-barrier-p (point) point))
1540 (not (eq (+ (count-lines 1 (point))
1544 (setq indent (+ (current-indentation) c-basic-offset))
1546 (if (< indent (current-indentation))
1548 (setq ad-return-value
1550 (- (current-indentation) indent)))
1551 (delete-region (c-point 'bol) (c-point 'boi))
1552 (indent-to indent))))))
1553 (if (< (point) (c-point 'boi))
1554 (back-to-indentation)
1555 (if (> (- (point-max) pos) (point))
1556 (goto-char (- (point-max) pos))))))))
1560 ;;; Local Variables:
1561 ;;; elisp-project-autoload-file-name: "cc-autoload.el"