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-project-name nil)
36 (defvar ccide-all-includes nil
37 "*If non-nil, this is the name of a file to include to fetch all
38 includes of a project. This is used if single include files cannot be
41 (defvar ccide-corba-skel-dir "")
42 (defvar ccide-corba-idl-dir "")
43 (defvar ccide-corba-idl-command "omniidl2 -w")
45 (defvar c-user-prefixes '("inline" "static" "prefix_")
46 "*List of possible prefixes for function definitions.")
48 (defvar ccide-default-prefix "prefix_"
49 "*Prefix added to every implementation header. Probably eiter empty or 'prefix_'")
51 (defvar ccide-gen-throw nil
52 "*If non-nil, generate throw_ specs")
54 (defvar ccide-project-root)
56 (defvar ccide-new-file-hook)
58 (defconst c-user-prefix-re (regexp-opt c-user-prefixes t))
60 (defconst ccide-doxy-tag-re
61 (concat "\\\\\\(group\\|defgroup\\|see\\|author\\|version\\|id\\|since"
62 "\\|returns?\\|throws?\\|exception\\|raises\\|param\\|li\\|brief"
63 "\\|internal\\|bug\\|fixme\\|todo\\|idea\\|implementation"
64 "\\|note\\|attention\\|warning\\|par\\|code\\|endcode"
65 "\\|post\\|pre\\|deprecated\\)\\b"))
67 (defconst ccide-special-extensions
68 '(".h" ".hh" ".mpp" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci" ".dox"))
70 (defconst ccide-implementation-extensions
71 '(".h" ".hh" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci"))
73 (defconst ccide-class-defaults-word
74 "// \\(default\\|no\\|protected\\|private\\|disabled\\|my\\)")
76 (defconst ccide-bindings
79 ("fc" ccide-file-comment "File comment")
80 ("fs" ccide-syncronize-includes "Sync includes")
84 ("cc" ccide-class-comment "Class comment")
85 ("cg" ccide-gen-class "Generate class")
86 ("cd" ccide-gen-class-defaults "Generate class defaults")
87 ("cD" ccide-gen-class-defaults-impl "Generate class defaults impl")
89 ("csd" ccide-set-class-defaults-default "Set class defaults comment" "Default")
90 ("csn" ccide-set-class-defaults-no "Set class defaults comment" "No")
91 ("csp" ccide-set-class-defaults-protected "Set class defaults comment" "Protected")
92 ("csr" ccide-set-class-defaults-private "Set class defaults comment" "Private")
93 ("csx" ccide-set-class-defaults-disabled "Set class defaults comment" "Disabled")
94 ("csm" ccide-set-class-defaults-my "Set class defaults comment" "My")
96 ("cS" ccide-gen-struct-constructors "Generate structure constructors")
98 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
100 ("ce" ccide-gen-exception "Generate an exception class")
105 ("mc" ccide-function-comment "Method comment")
106 ("mp" ccide-grab-prototype "Grab prototype")
107 ("mr" ccide-reformat-defun "Reformat defun")
108 ("mx" ccide-replace-defun "Replace defun")
109 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
110 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
111 ("mi" ccide-grab-inline-decl "Grab inline decl")
112 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
113 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
114 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
115 ("mf" ccide-find-implementation "Find method implementation")
116 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
120 ("vc" ccide-variable-comment "Variable comment")
121 ("vf" ccide-grab-access-fn "Grab access methods")
125 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
126 ("s" ccide-show-all-comments "Show all Doxygen comments")
129 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
130 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
131 ; (nil nil separator)
134 ; ("ts" ccide-scan-mantemps "Scan mantemps")
135 ; (nil nil separator)
138 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
139 ; ("oc" ccide-compile-compile "Make -> Compile")
140 ; ("ox" ccide-compile-clean "Make -> Clean")
141 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
142 ; ("ok" ccide-compile-kill "Kill compilation")
143 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
149 (require 'cc-engine-2)
158 (require 'misc-local)
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
163 (defsubst ccide-match-string (n)
164 (buffer-substring-no-properties (match-beginning n) (match-end n)))
166 (defun ccide-file-macro-name (&optional file-name)
167 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
169 (if ccide-project-name (concat ccide-project-name "_") "")
170 (if ccide-project-root
171 (string-replace "/" "_"
172 (substring (file-name-directory
173 (expand-file-name (or file-name buffer-file-name)))
174 (length ccide-project-root))
177 (string-replace "\\." "_" (file-name-sans-extension
178 (file-name-nondirectory
179 (or file-name (buffer-file-name))))
183 (defun ccide-file-name (&optional extension file-name directory)
184 (concat (if directory (file-name-as-directory directory) "")
185 (file-name-sans-extension
186 (file-name-nondirectory
187 (or file-name (buffer-file-name))))
190 (defun ccide-in-doxy-comment ()
192 (back-to-indentation)
193 (let ((lit (c-in-literal)))
194 (if (cond ((eq lit 'c)
195 (goto-char (car (c-literal-limits)))
196 (looking-at "/\\*\\*<?[ \t\n\r@]"))
198 (goto-char (car (c-literal-limits)))
199 (looking-at "///<?[ \t\n\r@]"))
202 (goto-char (match-end 0))
203 (current-column))))))
205 (defun ccide-shell-command (command)
206 (let ((obuf (get-buffer-create "*ccide shell command*"))
211 (insert command "\n"))
212 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
213 shell-command-switch command))
214 (and exit-status (equal exit-status 0))))
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219 (defun ccide-file-comment ()
220 "Add a comment to this source file."
225 (goto-char (point-min))
228 "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
229 " " ccide-default-author "\n"
230 ccide-default-copyright
233 (cond ((string-match "\\.hh?$" (buffer-file-name))
234 (insert "/** \\file\n"
235 " \\brief " (ccide-file-name) " public header */\n\n"
236 "#ifndef " (ccide-file-macro-name) "\n"
237 "#define " (ccide-file-macro-name) " 1\n\n")
238 (if ccide-all-includes
239 (insert "#ifndef " (ccide-file-macro-name ccide-all-includes) "\n"
240 "#error \"Don't include '" (file-name-nondirectory (buffer-file-name)) "'"
241 " directly, include '" ccide-all-includes "'\"\n"
243 (insert "// Custom includes\n\n"
244 "//#include \"" (ccide-file-name ".mpp") "\"\n"
245 "///////////////////////////////hh.p////////////////////////////////////////\n\n")
247 (goto-char (point-max))
248 (insert "\n\n///////////////////////////////hh.e////////////////////////////////////////\n")
249 (if ccide-all-includes
251 "#if !defined(" (ccide-file-macro-name ccide-all-includes) "_decls_) "
252 "&& !defined(" (ccide-file-macro-name) "i_)\n"
253 "#define " (ccide-file-macro-name) "i_\n"))
254 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
255 "//#include \"" (ccide-file-name ".ct") "\"\n"
256 "//#include \"" (ccide-file-name ".cti") "\"\n"
259 ((string-match "\\.mpp$" (buffer-file-name))
260 (insert "/** \\file\n"
261 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
264 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
265 "#define " (ccide-file-macro-name) " 1\n\n"
266 "// Custom includes\n\n\n"
267 "// ///////////////////////////mpp.p////////////////////////////////////////\n"
268 "#elif BOOST_PP_IS_ITERATING // ////////////////////////////////////////////\n"
269 "// ////////////////////////////////////////////////////////////////////////\n"
270 "// Local Macros\n\n\n"
271 "// ////////////////////////////////////////////////////////////////////////\n"
272 "#if BOOST_PP_ITERATION_FLAGS()==1 // //////////////////////////////////////\n"
273 "// ////////////////////////////////////////////////////////////////////////\n\n")
275 (goto-char (point-max))
276 (insert "\n\n// ////////////////////////////////////////////////////////////////////////\n"
277 "#endif // /////////////////////////////////////////////////////////////////\n"
278 "// ////////////////////////////////////////////////////////////////////////\n"
279 "// Undefine local Macros\n\n\n"
280 "// ////////////////////////////////////////////////////////////////////////\n"
281 "#endif // /////////////////////////////////////////////////////////////////\n"
282 "// ///////////////////////////mpp.e////////////////////////////////////////"))
284 ((string-match "\\.ih$" (buffer-file-name))
285 (insert "/** \\file\n"
286 " \\brief " (ccide-file-name) " internal header */\n\n"
287 "#ifndef " (ccide-file-macro-name) "\n"
288 "#define " (ccide-file-macro-name) " 1\n\n"
289 "// Custom includes\n\n"
290 "///////////////////////////////ih.p////////////////////////////////////////\n\n")
292 (goto-char (point-max))
293 (insert "\n\n///////////////////////////////ih.e////////////////////////////////////////\n"
296 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
297 (string-match "\\.test\\.cpp$" (buffer-file-name)))
298 (insert "/** \\file\n"
299 " \\brief " (ccide-file-name) " unit tests */\n\n"
300 "//#include \"" (ccide-file-name ".hh") "\"\n"
301 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
302 "// Custom includes\n"
303 "#include \"" (or ccide-all-includes
304 (ccide-file-name ".hh" (ccide-file-name))) "\"\n\n"
305 "#include <boost/test/auto_unit_test.hpp>\n"
306 "#include <boost/test/test_tools.hpp>\n\n"
308 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
310 (goto-char (point-max))
311 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
314 ((or (string-match "\\.cc$" (buffer-file-name))
315 (string-match "\\.cpp$" (buffer-file-name)))
316 (insert "/** \\file\n"
317 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
318 (if ccide-all-includes "" "//")
319 "#include \"" (or ccide-all-includes (ccide-file-name ".hh")) "\"\n"
320 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
321 "// Custom includes\n\n"
322 "//#include \"" (ccide-file-name ".mpp") "\"\n"
324 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
326 (goto-char (point-max))
327 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
329 "//#include \"" (ccide-file-name ".mpp") "\""))
331 ((string-match "\\.cci$" (buffer-file-name))
332 (insert "/** \\file\n"
333 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
334 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
335 "// Custom includes\n\n"
336 "#define prefix_ inline\n"
337 "///////////////////////////////cci.p///////////////////////////////////////\n\n")
339 (goto-char (point-max))
340 (insert "\n\n///////////////////////////////cci.e///////////////////////////////////////\n"
343 ((string-match "\\.ct$" (buffer-file-name))
344 (insert "/** \\file\n"
345 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
346 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
347 "// Custom includes\n\n"
349 "///////////////////////////////ct.p////////////////////////////////////////\n\n")
351 (goto-char (point-max))
352 (insert "\n\n///////////////////////////////ct.e////////////////////////////////////////\n"
355 ((string-match "\\.cti$" (buffer-file-name))
356 (insert "/** \\file\n"
357 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
358 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
359 "// Custom includes\n\n"
360 "#define prefix_ inline\n"
361 "///////////////////////////////cti.p///////////////////////////////////////\n\n")
363 (goto-char (point-max))
364 (insert "\n\n///////////////////////////////cti.e///////////////////////////////////////\n"
367 ((string-match "\\.dox$" (buffer-file-name))
368 (insert "/** \\mainpage\n\n ")
371 (setq add-file-vars '(( mode . flyspell)
372 ( mode . auto-fill))))
374 ((string-match "\\.java$" (buffer-file-name))
377 (goto-char (point-max)))
381 (goto-char (point-max))))
384 "// Local Variables:\n"
385 "// mode: " mode "\n")
386 (loop for (var . value) in ccide-file-vars
387 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
388 (loop for (var . value) in add-file-vars
389 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
393 (if (equal mode "jde")
394 (let ((package (file-name-directory (buffer-file-name))))
395 (jdeap-initialize-setup)
396 (if (not (equal jdeap-current-source-directory "."))
398 (concat "^" (regexp-quote jdeap-current-source-directory))
401 (setq package (substring package
403 (1- (length package))))
405 (string-replace "/" "." package t)
407 (insert "class " (file-name-sans-extension
408 (file-name-nondirectory
409 (buffer-file-name))) "\n{}")
410 (beginning-of-line))))
411 (run-hooks 'ccide-new-file-hooks))
413 (defun ccide-sync-file-variables ()
414 "Syncronize file variables to the current value of ccide-file-vars"
417 (goto-char (point-max))
418 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
419 (let ((case-fold-search t))
420 (if (search-forward "Local Variables:" nil t)
421 (let (prefix suffix vars)
422 (skip-chars-forward " \t")
424 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
425 (goto-char (match-beginning 0))
427 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
430 (if (and prefix (looking-at prefix))
431 (goto-char (match-end 0)))
432 (skip-chars-forward " \t"))
433 while (not (looking-at "end:"))
435 (setq vars (cons (intern (buffer-substring
437 (progn (skip-chars-forward "^:\n") (point))))
440 (loop for (var . value) in ccide-file-vars
441 do (if (not (memq var vars))
442 (insert (or prefix "")
443 (symbol-name var) ": " (prin1-to-string value)
444 (or suffix "") "\n"))))))))
446 (defun ccide-syncronize-includes ()
447 "Syncronize include's in all other files"
450 (loop for extension in ccide-special-extensions
451 for file-name = (ccide-file-name extension)
453 (cons (cons file-name
454 (or (find-buffer-visiting file-name)
455 (and (file-readable-p file-name)
456 (find-file-noselect file-name))))
459 (loop for buffer in buffer-map
462 (set-buffer (cdr buffer))
464 (loop for include in buffer-map
466 (goto-char (point-min))
467 (while (re-search-forward
468 (concat "^\\(//\\)?#\\s-*include \""
469 (regexp-quote (car include))
472 (goto-char (match-beginning 0))
473 (if (looking-at "//")
476 (if (not (cdr include))
478 (forward-line 1))))))))))
480 (defun ccide-auto-decorate-new-files ()
481 (if (= (point-min) (point-max))
482 (let ((status (buffer-modified-p)))
484 (set-buffer-modified-p status))))
486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
489 (defun ccide-class-comment ()
490 "Add comment to start of current class definition"
492 (let ((class (c-get-class-at-point)))
494 (error "No class found")
495 (goto-char (or (aref (car class) 3)
496 (aref (car class) 1)))
499 (ccide-in-doxy-comment))
501 (search-backward "/**" nil t)
503 (let ((indent (make-string (current-indentation) ? )))
504 (insert "/** \\brief ")
510 (defun ccide-gen-class (name &optional defns)
511 "Generate class declaration template"
512 (interactive (list (read-string (concat "Class name (default "
515 nil nil (ccide-file-name))))
516 (insert "class " name)
517 (indent-according-to-mode)
518 (let ((in (make-string c-basic-offset ? ))
519 (ofs (make-string (current-indentation) ? )))
523 (insert ofs "/** \\brief\n"
529 ofs in "///////////////////////////////////////////////////////////////////////////\n"
530 ofs in "// Types\n\n"
531 ofs in "///////////////////////////////////////////////////////////////////////////\n"
532 ofs in "///\\name Structors and default members\n"
534 ofs in "// default default constructor\n"
535 ofs in "// default copy constructor\n"
536 ofs in "// default copy assignment\n"
537 ofs in "// default destructor\n\n"
538 ofs in "// no conversion constructors\n\n"
540 ofs in "///////////////////////////////////////////////////////////////////////////\n"
541 ofs in "///\\name Accessors\n"
544 ofs in "///////////////////////////////////////////////////////////////////////////\n"
545 ofs in "///\\name Mutators\n"
548 (loop for defn in defns
549 do (insert ofs in defn ";\n"))
552 (insert ofs "protected:\n\n"
556 (defun ccide-gen-class-defaults ()
557 "Generate signatures of the default functions: default constructor,
558 copy constructor, assignment operator and destructor."
559 (indent-according-to-mode)
560 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
561 (in (make-string c-basic-offset ? ))
562 (ofs (make-string (current-indentation) ? ))
563 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
565 (while (string-match "::" name colon)
566 (setq colon (match-end 0)))
567 (setq name (substring name colon))
569 (delete-horizontal-space)
570 (loop with exit = nil
571 do (message (concat "1-dflt constr, 2-destr, "
572 "3-copy constr, 4-copy assmnt, "
573 "c-all copy, d-all dflt, RET-all/done: "))
574 for ch = (read-event)
575 for first = t then nil
576 do (cond ((eq ch 'return)
578 (insert ofs name "()"
580 ofs name "(const " name "& other)"
583 ofs name "& operator=(const " name "& other)"
587 (insert ofs name "()"
590 (insert ofs "~" name "();\n"))
592 (insert ofs name "(const " name "& other)"
595 (insert ofs name "& operator=(const " name "& other)"
598 (insert ofs name "(const " name "& other)"
600 ofs name "& operator=(const " name "& other)"
603 (insert ofs name "()"
605 ofs "~" name "();\n"))
606 (t (setq unread-command-events (cons ch unread-command-events))
610 (defun ccide-gen-class-defaults-impl ()
611 "Generate default implementations for class default functions"
613 (let ((defn (c-build-default-funcions-impl)))
614 (kill-new (cadr defn))
615 (message (concat (car defn) " default members"))))
617 (defun ccide-set-class-defaults-comment (word)
619 (back-to-indentation)
620 (if (not (looking-at ccide-class-defaults-word))
621 (message "Not at class defaults commnet")
622 (replace-match word t t nil 1))))
624 (defmacro ccide-build-class-defaults-f (sym)
625 (let ((fn (intern (concat "ccide-set-class-defaults-"
626 (symbol-name sym)))))
629 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
631 (ccide-build-class-defaults-f no)
632 (ccide-build-class-defaults-f default)
633 (ccide-build-class-defaults-f my)
634 (ccide-build-class-defaults-f protected)
635 (ccide-build-class-defaults-f private)
636 (ccide-build-class-defaults-f disabled)
638 (defun ccide-gen-struct-constructors ()
642 (indent-according-to-mode)
643 (let* ((scope (c-get-block-scope))
644 (class (c-parse-class scope))
645 (variables (c-get-variable-members-with-type class))
646 (name (c-scope-name (aref (car (last scope)) 1)))
647 (in (make-string (current-indentation) ? ))
648 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
649 (insert name "()\n" inin ": ")
650 (indent-according-to-mode)
651 (loop for var in variables
652 for first = t then nil
653 if (not first) do (insert ", ")
654 do (insert (car var) "()"))
655 (insert "\n" in "{}\n"
657 (loop for var in variables
658 for first = t then nil
659 if (not first) do (insert ", ")
660 do (insert (cdr var) " " (car var) "_"))
661 (insert ")\n" inin ": ")
662 (loop for var in variables
663 for first = t then nil
664 if (not first) do (insert ", ")
665 do (insert (car var) "(" (car var) "_)"))
666 (insert "\n" in "{}"))))
668 (defun ccide-class-impl-comment ()
669 "Get implementation comment for current class"
671 (let* ((scope (c-get-block-scope))
672 (name (c-get-full-prefix scope)))
673 (kill-new (concat (make-string 75 ?/) "\n"
679 (defun ccide-gen-exception (class &optional description)
680 (interactive "sException name: \nsDescription (defaults to full class name): ")
683 (indent-according-to-mode)
685 (let ((in (make-string c-basic-offset ? ))
686 (ofs (make-string (current-indentation) ? ))
687 (prefix (c-get-full-prefix (c-get-block-scope)))
689 (insert "struct " class " : public std::exception\n"
690 ofs "{ virtual char const * what() const throw() ")
692 (insert "{ return \""
693 (if (and description (> (length description) 0))
695 (concat prefix "::" class))
697 (if (> (current-column) fill-column)
700 (insert "\n" ofs in in))))))
702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
703 ;; function/method level
705 (defun ccide-function-comment ()
706 "Add comment for current function"
708 (if (memq (c-in-literal) '(c c++))
709 ; Assume, we are in the functions comment ...
711 (c-forward-out-of-comment)
712 (c-backward-syntactic-ws)
715 (c-beginning-of-defun-or-decl)
716 (let ((defun (c-get-defun-state))
717 (indent (make-string comment-column ? ))
719 (goto-char (or (aref defun 7) (car (aref defun 6))))
720 (c-backward-syntactic-ws)
721 (if (looking-at "[ \t\n\r]*///<")
723 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
724 (if (> (current-column) comment-column)
726 (indent-to-column comment-column)
727 (search-forward "*/")
729 (if (> (current-column) comment-column)
731 (indent-to-column comment-column)
739 (goto-char (car (aref defun 2)))
740 (setq defun (c-get-defun-state)))
742 (ccide-function-comment-adjust defun (concat indent " "))
743 (if place (goto-char place))))
745 (defun ccide-function-comment-grab-args ()
746 (let ((limit (save-excursion
747 (search-backward "/**" nil t)
750 begin start args argend)
752 (while (or (search-backward "\\param" limit t)
753 (search-backward "\\return" limit t)))
757 (while (search-forward "\\param" argend t)
758 (or (search-forward "\\param" argend t)
759 (search-forward "\\return" argend t)
762 (setq args (cons (ccide-function-comment-parse-arg start (point))
764 (setq start (point)))
766 (if (not (search-forward "\return" argend t))
769 (cons (buffer-substring (point) argend) args))
770 (delete-region begin end))))
772 (defun ccide-function-comment-parse-arg (start end)
775 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
776 (cons (match-string 2)
777 (cons (buffer-substring start (match-beginning 2))
778 (buffer-substring (match-end 2) end)))))
780 (defun ccide-function-comment-get-throws (defun)
783 (goto-char (car (aref defun 4)))
784 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
785 (cdr (aref defun 4)) t)
786 (let ((spec (match-string 2)))
787 (if (> (length spec) 0)
790 (defun ccide-function-comment-adjust (defun indent)
792 (let* ((defargs (mapcar (function (lambda (x)
793 (c-get-template-argument-name (car x) (cdr x))))
795 (defret (and (aref defun 1)
796 (not (string-match (concat "^\\("
798 "\\s-*\\)*\\s-*void$")
799 (buffer-substring (car (aref defun 1))
800 (cdr (aref defun 1)))))))
801 (throws (ccide-function-comment-get-throws defun))
802 (xargs (ccide-function-comment-grab-args))
803 (docargs (cdr xargs))
805 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
806 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
807 (size-eq (= (length defargs) (length docargs))))
808 ;; We differentiate four types changes
810 ;; - removed arguments
811 ;; - reordered arguments
812 ;; - renamed arguments
814 ;; If the change cannot be described by one of the above, it has
815 ;; to be resolved manually
817 (insert indent "\\throws " throws "\n"))
819 ;; reordered arguments or new arguments (or no change)
820 (loop for defarg in defargs
821 for docarg = (assoc defarg docargs)
823 (insert (cadr docarg) (car docarg) (cddr docarg))
824 (insert indent "\\param " defarg " \n"))))
825 (size-eq ; and (not doc-in-def)
827 (loop for defarg in defargs
828 for docarg in docargs
829 do (insert (cadr docarg) defarg (cddr docarg))))
832 (loop for defarg in defargs
833 for docarg = (assoc defarg docargs)
834 do (insert (cadr docarg) (car docarg) (cddr docarg))))
835 (t (error "Arg change too complex. Resolve manualy.")))
836 ;; return value is simple
840 (insert indent "\\return \n"))))
842 (delete-horizontal-space)
845 (defun ccide-grab-prototype (&optional prefix)
846 "Grab prototype of function defined or declared at point. Prefix
847 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
850 (c-beginning-of-defun-or-decl)
851 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
852 ccide-default-prefix))
853 (defn (c-build-defun prfx)))
854 (kill-new (concat (cadr defn) "\n{}\n"))
855 (message (concat (or prfx "")
859 (defun ccide-reformat-defun ()
860 "Reformat the defn of the current defun."
863 (c-beginning-of-defun-or-decl)
864 (let ((defn (c-build-defun nil t)))
865 (delete-region (or (caar (aref (caddr defn) 0))
866 (car (aref (caddr defn) 1))
867 (car (aref (caddr defn) 2)))
868 (or (car (aref (caddr defn) 6))
869 (aref (caddr defn) 7)))
870 (insert (cadr defn) "\n"))))
872 (defun ccide-replace-defun ()
873 "Replace the function header with the one on the top of the kill
874 ring (presumably placed there using c++-grab-prototype)."
877 (c-beginning-of-defun-or-decl)
878 (let ((parse (c-parse-defun)))
879 (delete-region (or (aref parse 0)
888 (defun ccide-prefix-defun-type-with-class (&optional strip)
889 "If a non-keyword type symbol is found prefixing the current defun,
890 it will be prefixed with the current class prefix."
893 (c-beginning-of-defun-or-decl)
894 (let* ((parse (c-parse-defun))
895 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
896 (goto-char (aref parse 1))
897 (while (and (or (looking-at c-any-key)
898 (looking-at c-user-prefix-re)
899 (not (c-at-symbol-p)))
900 (< (point) (aref parse 2))
903 (c-forward-syntactic-ws))
904 (if (and (c-at-symbol-p)
905 (< (point) (aref parse 2))
906 (not (looking-at (regexp-quote prefix))))
907 (let ((pos (string-match "<" prefix)))
909 (insert "typename "))
910 (if (and pos (looking-at (concat (substring prefix 0 pos)
913 (goto-char (match-end 0))
914 (c-backward-syntactic-ws)
915 (insert (substring prefix pos)))
916 (insert prefix "::"))
917 (ccide-reformat-defun))))))
919 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
921 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
923 (defun ccide-insert-defun-prefix (&optional strip)
924 "Insert the current defun prefix at point."
926 (let* ((parse (c-parse-defun))
927 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
928 (insert prefix "::")))
930 (defun ccide-kill-inline-decl (defn)
932 (if (aref (caddr defn) 6)
934 (goto-char (cdr (aref (caddr defn) 6)))
935 (let ((end-mark (point-marker)))
936 (goto-char (car (aref (caddr defn) 6)))
937 (indent-rigidly (point) end-mark
938 (- (current-column)))
942 (buffer-substring-no-properties (point) end-mark)
944 (when (aref (caddr defn) 5)
945 (goto-char (caar (aref (caddr defn) 5)))
946 (c-backward-syntactic-ws)
947 (skip-chars-backward ":"))
948 (c-backward-syntactic-ws)
949 (delete-region (point) end-mark)
951 (concat (cadr defn) "\n{}\n"))))
953 (defun ccide-grab-inline-decl ()
954 "Grab the inline decl at point at turn it into an out-of-line inline
955 declaration at the top of the kill ring."
957 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
958 (kill-new (ccide-kill-inline-decl defn))
959 (message (concat (or ccide-default-prefix "indline")
963 (defun ccide-grab-all-inlines ()
964 "Grab all inline decls in the current class"
966 (let ((class (c-parse-class (c-get-block-scope)))
969 (loop for method in (nreverse (aref class 4))
970 do (when (eq (car method) 'method)
971 (let ((defn (save-excursion
972 (goto-char (cdr method))
973 (c-build-defun (or ccide-default-prefix "inline")))))
974 (if (aref (caddr defn) 6)
975 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
976 (kill-new (loop for defn in (nreverse defns)
977 for next = nil then t
980 (message (format "%d inlines grabed to kill ring" (length defns))))))
983 (defun ccide-grab-create-constructor ()
985 (let ((defn (c-build-create-constructor)))
986 (kill-new (cadr defn))
987 (message (car defn))))
989 (defun ccide-grab-create-constructor-impl (&optional prefix)
991 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
992 ccide-default-prefix))
993 (defn (c-build-create-constructor-impl prfx)))
994 (kill-new (cadr defn))
995 (message (concat (or prfx "")
999 (defun ccide-find-implementation (&optional other-window)
1000 "Find implementation of method declared at point."
1002 (let* ((state (c-get-defun-state))
1003 (name (c-defun-short-name state))
1004 (scoped-name (c-defun-full-name state))
1005 (args (ccide-implementation-args state))
1006 (targs (ccide-implementation-template-args state))
1009 (loop for ext in ccide-implementation-extensions
1010 for filename = (ccide-file-name ext)
1013 (let ((buf (or (find-buffer-visiting filename)
1014 (and (file-readable-p filename)
1015 (find-file-noselect filename)))))
1017 (let ((found (save-excursion
1019 (ccide-find-implementation-1 name scoped-name args targs
1020 (not (aref state 6))
1021 (car (aref state 2))))))
1024 (setq rv (cons buf found))
1025 (if (not fallback) (setq fallback (cons buf found))))))))))
1026 (if (not rv) (setq rv fallback))
1028 (let* ((buf (car rv))
1030 (win (get-buffer-window buf)))
1034 (switch-to-buffer-other-window buf)
1035 (switch-to-buffer buf)))
1038 (c-beginning-of-defun-or-decl))
1039 (message (concat "Implementation of " scoped-name " not found.")))))
1041 (defun ccide-implementation-args (state)
1042 (string-replace "[ \t\n\r]+" ""
1043 (loop for (start . end) in (aref state 3)
1044 for sep = "" then ","
1046 concat (buffer-substring-no-properties
1047 start (save-excursion
1049 (if (search-forward "=" end 'move) (forward-char -1))
1054 (defun ccide-implementation-template-args (state)
1056 (string-replace "[ \t\n\r]+" ""
1057 (loop for (start . end) in (save-excursion
1058 (goto-char (caar (last (aref state 0))))
1059 (c-parse-template-declaration))
1060 for sep = "" then ","
1062 concat (buffer-substring-no-properties
1063 start (save-excursion
1065 (if (search-forward "=" end 'move) (forward-char -1))
1069 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1070 ;; Within the current buffer, search for all implementations of the
1071 ;; given function. The rv is a list of conses. The car holds the
1072 ;; buffer position of the implementation, the cdr is t if the name,
1073 ;; scoped-name and args are matched, otherwise the args did not match.
1075 (goto-char (point-min))
1076 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1078 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1079 fallback rv check-state)
1080 (while (and (not rv) (re-search-forward re nil t))
1081 (if (and (c-at-toplevel-p)
1082 (not (c-in-literal))
1083 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1084 (not (= (car (aref check-state 2)) skip-def)))
1085 (if (string= scoped-name (c-defun-full-name check-state))
1086 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1087 (string= args (ccide-implementation-args check-state))
1088 (string= targs (ccide-implementation-template-args check-state)))
1089 (setq rv (cons (point) t))
1091 (setq fallback (cons (point) nil)))))))
1094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1095 ;; variable/type level
1097 (defun ccide-variable-comment ()
1098 "Add a comment to current variable declaration."
1100 (c-forward-out-of-comment)
1101 (c-forward-syntactic-ws)
1102 (while (not (looking-at ";"))
1104 (c-forward-syntactic-ws))
1106 (if (> (current-column) comment-column)
1107 (insert "\n" (make-string comment-column ? ) "///< ")
1108 (indent-to-column comment-column)
1111 (defun ccide-grab-access-fn ()
1115 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1116 (let ((vardef (match-string 0))
1117 (in (make-string c-basic-offset ? ))
1118 type reftype varname fnname argname ws)
1120 (back-to-indentation)
1121 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1123 (setq varname (match-string 2 vardef)
1124 type (match-string 1 vardef)
1125 ws (substring vardef 0 (match-beginning 1)))
1126 (if (string-match "_$" varname)
1127 (setq fnname (string-replace "_$" "" varname)
1128 argname (concat "a_" fnname))
1129 (setq fnname (concat "q_" varname)
1130 argname (concat "a_" varname)))
1131 (if (string-match "^[ \t\n\r]*" type)
1132 (setq type (substring type (match-end 0))))
1133 (if (string-match "^[A-Z]" type)
1134 (setq reftype (concat type " const &"))
1135 (setq reftype type))
1136 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1138 ws in in type " old" varname " = " varname ";\n"
1139 ws in in varname " = " argname ";\n"
1140 ws in in "return old" varname ";\n"
1142 ws reftype " " fnname "() const\n"
1143 ws in "{ return " varname "; }\n"))
1146 (message "No variable found"))))
1148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1149 ;; doxy comment support functions
1151 (defun ccide-special-indent-function ()
1152 "Function to indent doxy comments correctly"
1153 (let ((indent (ccide-in-doxy-comment)))
1155 (let ((lim (save-excursion
1156 (back-to-indentation)
1157 (c-literal-limits)))
1158 (pos (- (point-max) (point))))
1160 (back-to-indentation)
1161 (if (looking-at "*/")
1163 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1165 (if (and (not (looking-at ccide-doxy-tag-re))
1166 (re-search-backward (concat "^\\s-*"
1170 (delete-region (progn (beginning-of-line) (point))
1171 (progn (back-to-indentation) (point)))
1173 (if (> (- (point-max) pos) (point))
1174 (goto-char (- (point-max) pos)))))))
1176 (defun ccide-fill-function ()
1177 "auto-fill function for doxy comments"
1179 (if (not fill-prefix)
1180 (indent-according-to-mode))))
1182 (defun ccide-hide-all-doxy-comments ()
1183 "Hide all doxy comments"
1186 (goto-char (point-min))
1187 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1190 (if (not (looking-at "\\s-*$"))
1193 (let ((start (point)))
1194 (if (re-search-forward "\\*/" nil t)
1196 (if (looking-at "\\s-*\n")
1199 (let ((overlay (make-overlay start (point))))
1200 (overlay-put overlay 'intangible 'hs)
1201 (overlay-put overlay 'invisible 'hs)))))))
1204 (defun ccide-show-all-comments ()
1208 (goto-char (point-min))
1210 (goto-char (next-overlay-change (point)))
1211 (loop for overlay in (overlays-at (point))
1212 if (eq (overlay-get overlay 'invisible) 'hs)
1213 do (delete-overlay overlay))))
1216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1217 ;; CORBA support (omniORB2)
1219 (defun ccide-get-corba-headers ()
1222 (goto-char (point-min))
1223 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1224 (setq files (cons (ccide-match-string 1) files)))
1227 (defun ccide-corba-maybe-build-hh (file)
1228 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1229 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1230 (if (and (file-readable-p idl)
1231 (or (not (file-readable-p skel))
1232 (file-newer-than-file-p idl skel)))
1233 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1235 (kill-buffer buffer))
1236 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1237 (if (ccide-shell-command (concat "cd "
1238 (real-path-name ccide-corba-skel-dir)
1240 ccide-corba-idl-command
1241 (if (> (length ccide-corba-idl-dir) 0)
1242 (concat " -I" ccide-corba-idl-dir))
1246 (display-buffer (get-buffer-create "*ccide shell command*"))
1247 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1248 (if (not (file-readable-p skel))
1249 (error "No file %s or %s"
1250 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1252 (defun ccide-corba-list-skeletons-1 (hh-file)
1253 (ccide-corba-maybe-build-hh hh-file)
1254 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1259 (goto-char (point-min))
1260 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1262 (setq skels (cons (ccide-match-string 1) skels)))))
1263 (mapcar (function (lambda (x) (cons x hh-file)))
1264 (sort skels 'string-lessp))))
1266 (defun ccide-corba-list-skeletons ()
1267 (let ((files (ccide-get-corba-headers)))
1268 (loop for file in files
1269 append (ccide-corba-list-skeletons-1 file))))
1271 (defun ccide-gen-corba-impl (class)
1272 (interactive (list (completing-read "Class name of skeleton: "
1273 (ccide-corba-list-skeletons)
1275 (let* ((skels (ccide-corba-list-skeletons))
1276 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1277 ccide-corba-skel-dir))
1278 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1279 ccide-corba-skel-dir))))
1280 (ccide-gen-class (concat class "_i"))
1281 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1283 (search-forward "protected:" nil t)
1285 (ccide-gen-corba-impl-methods)
1288 (defun ccide-get-corba-defns (hh-file class)
1289 (let ((hh-buf (find-file-noselect hh-file))
1294 (goto-char (point-min))
1295 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1297 (error "CORBA skeleton class not found.")
1298 (search-forward "{")
1300 (let ((end (save-excursion (forward-sexp) (point))))
1301 (while (and (< (point) end)
1302 (< (forward-line 1) 1))
1303 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1304 (setq defns (cons (match-string 1) defns))))))))
1307 (defun ccide-gen-corba-impl-methods ()
1309 (let* ((class (c-get-class-at-point))
1312 (error "No class at point."))
1314 (goto-char (aref (car class) 1))
1315 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1317 (error "No CORBA impl at point."))
1318 (let* ((name (ccide-match-string 1))
1319 (skels (ccide-corba-list-skeletons))
1320 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1321 ccide-corba-skel-dir))
1322 (defns (ccide-get-corba-defns hh-file name))
1324 (goto-char (aref (car class) 2))
1328 (if (re-search-forward "^\\s-*// CORBA$" end t)
1329 (let ((start (match-beginning 0)))
1330 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1331 (let ((eend (match-end 0)))
1334 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1335 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1336 (delete-region start (1+ eend))
1339 (delete-region (point) (progn
1344 (delete-region (point) (progn
1348 (delete-region start (1+ eend))))))
1350 (indent-according-to-mode)
1351 (insert "// CORBA\n")
1352 (loop for defn in defns
1354 (save-excursion (insert defn ";"))
1355 (indent-according-to-mode)
1356 (let ((start (point)) end)
1360 (while (re-search-forward "\\s-+" end t)
1362 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1364 (loop with done = nil
1365 while (> (current-column) c-max-def-column)
1366 do (while (and (> (current-column) c-max-def-column)
1367 (search-backward "," start t)))
1368 do (if (looking-at ",")
1373 (indent-according-to-mode)
1375 (setq start (point))
1380 (indent-according-to-mode)
1381 (insert "// END-CORBA\n")))))
1383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1386 (defun ccide-scan-mantemps ()
1387 "Scan *compilation* buffer for errors and generate manual template
1388 instatiations at point."
1391 (set-buffer "*compilation*")
1392 (goto-char (point-min)))
1394 (set-buffer (get-buffer-create "*mantemps*"))
1396 (loop for temp = (ccide-get-mantemp)
1398 do (insert temp "\n"))
1399 (mantemp-make-mantemps-buffer)
1400 (goto-char (point-min))
1403 (< (forward-line 1) 1))))
1404 (insert-buffer-substring "*mantemps*"))
1406 (defun ccide-get-mantemp ()
1408 (set-buffer "*compilation*")
1409 (if (search-forward "undefined reference to `" nil t)
1410 (let ((start (point)))
1412 (search-backward "'" nil t)
1413 (buffer-substring start (point))))))
1415 (defun ccide-fix-mantemp ()
1416 (let ((end (save-excursion
1417 (end-of-line) (point))))
1418 (if (and (save-excursion (search-forward "(" end t))
1419 (search-forward " class" end t))
1426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1429 (defun ccide-open-compilation-frame ()
1431 (let ((c-frame (selected-frame))
1432 (compilation-frame (make-frame '((minibuffer . nil)
1434 (menu-bar-lines . 0)
1439 (select-frame compilation-frame)
1440 (switch-to-buffer "*compilation*")
1441 (set-window-dedicated-p (selected-window) t)))
1443 (defun ccide-compile (command)
1444 (delete-other-windows)
1445 (split-window-horizontally)
1448 (set-buffer "*compilation*")
1449 (let ((point (point-max)))
1451 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1452 do (set-window-point window point)))))
1454 (defun ccide-compile-compile ()
1456 (ccide-compile (concat "make -k " ccide-compile-opts)))
1458 (defun ccide-compile-clean ()
1460 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1462 (defun ccide-compile-cleandepends ()
1464 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1466 (defun ccide-compile-kill ()
1468 (set-buffer "*compilation*")
1471 (defun ccide-hide-compilation ()
1473 (let ((active (selected-window)))
1475 (loop for window in (get-buffer-window-list "*compilation*")
1476 do (progn (select-window window)
1477 (switch-to-buffer (other-buffer "*compilation*"))))
1478 (select-window active))))
1480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1481 ;; keymap and installation
1483 (defun ccide-bind-keys (prefix map)
1484 (loop for binding in ccide-bindings
1485 do (apply 'vcmd-define-key
1487 (concat prefix (car binding))
1492 (defun ccide-install-it ()
1496 (local-unset-key "\C-c;")
1497 (local-unset-key [menu-bar IDE])
1498 (ccide-bind-keys "\C-c;" (current-local-map))
1499 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1500 (local-set-key "\C-cS" 'ccide-show-all-comments)
1501 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1502 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1503 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1505 (ccide-project-load-config)
1506 (ccide-directory-load-config)
1507 (ccide-auto-decorate-new-files))
1509 (defun ccide-project-load-config ()
1510 (let ((conf (ccide-project-search-upwards "project.el" (file-name-directory (buffer-file-name)))))
1512 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1515 (defun ccide-project-search-upwards (file &optional dir)
1516 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1517 DIR defaults to ccide-project-root"
1518 (let (conf last-dir)
1519 (setq dir (expand-file-name "x" (or dir ccide-project-root)))
1520 (while (and (not (string= (setq last-dir dir
1521 dir (directory-file-name (file-name-directory dir))) last-dir))
1522 (setq conf (expand-file-name file dir))
1523 (not (file-readable-p conf))))
1524 (and (file-readable-p conf) conf)))
1526 (defun ccide-directory-load-config ()
1527 (if (file-readable-p ".dir.el")
1528 (load-file ".dir.el")))
1530 (add-hook 'c-mode-hook 'ccide-install-it)
1531 (add-hook 'c++-mode-hook 'ccide-install-it)
1532 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1534 (loop for extension in ccide-special-extensions
1535 for re = (concat (regexp-quote extension) "$")
1536 if (not (assoc re auto-mode-alist))
1537 do (setq auto-mode-alist (append auto-mode-alist
1538 (list (cons re 'c++-mode)))))
1540 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1541 ;; new indent function for c-mode: do standard indentation first. If line
1542 ;; is to long using standard indentation, just indent by c-basic-indentation.
1543 (let ((cc (save-excursion (end-of-line) (current-column)))
1546 (let ((pos (- (point-max) (point))))
1548 (let ((point (point))
1549 (line (1+ (count-lines 1 (point))))
1551 (c-beginning-of-statement-2)
1552 (if (and (not (c-crosses-statement-barrier-p (point) point))
1553 (not (eq (+ (count-lines 1 (point))
1557 (setq indent (+ (current-indentation) c-basic-offset))
1559 (if (< indent (current-indentation))
1561 (setq ad-return-value
1563 (- (current-indentation) indent)))
1564 (delete-region (c-point 'bol) (c-point 'boi))
1565 (indent-to indent))))))
1566 (if (< (point) (c-point 'boi))
1567 (back-to-indentation)
1568 (if (> (- (point-max) pos) (point))
1569 (goto-char (- (point-max) pos))))))))
1573 ;;; Local Variables:
1574 ;;; elisp-project-autoload-file-name: "cc-autoload.el"