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-guard nil)
36 (defvar ccide-corba-skel-dir "")
37 (defvar ccide-corba-idl-dir "")
38 (defvar ccide-corba-idl-command "omniidl2 -w")
40 (defvar c-user-prefixes '("inline" "static" "prefix_")
41 "*List of possible prefixes for function definitions.")
43 (defvar ccide-default-prefix "prefix_"
44 "*Prefix added to every implementation header. Probably eiter empty or 'prefix_'")
46 (defvar ccide-gen-throw nil
47 "*If non-nil, generate throw_ specs")
49 (defvar ccide-project-root)
51 (defconst c-user-prefix-re (regexp-opt c-user-prefixes t))
53 (defconst ccide-doxy-tag-re
54 (concat "\\\\\\(group\\|defgroup\\|see\\|author\\|version\\|id\\|since"
55 "\\|returns?\\|throws?\\|exception\\|raises\\|param\\|li\\|brief"
56 "\\|internal\\|bug\\|fixme\\|todo\\|idea\\|implementation"
57 "\\|note\\|attention\\|warning\\|par\\|code\\|endcode"
58 "\\|post\\|pre\\)\\b"))
60 (defconst ccide-special-extensions
61 '(".h" ".hh" ".mpp" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci" ".dox"))
63 (defconst ccide-implementation-extensions
64 '(".h" ".hh" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci"))
66 (defconst ccide-class-defaults-word
67 "// \\(default\\|no\\|protected\\|private\\|disabled\\|my\\)")
69 (defconst ccide-bindings
72 ("fc" ccide-file-comment "File comment")
73 ("fs" ccide-syncronize-includes "Sync includes")
77 ("cc" ccide-class-comment "Class comment")
78 ("cg" ccide-gen-class "Generate class")
79 ("cd" ccide-gen-class-defaults "Generate class defaults")
80 ("cD" ccide-gen-class-defaults-impl "Generate class defaults impl")
82 ("csd" ccide-set-class-defaults-default "Set class defaults comment" "Default")
83 ("csn" ccide-set-class-defaults-no "Set class defaults comment" "No")
84 ("csp" ccide-set-class-defaults-protected "Set class defaults comment" "Protected")
85 ("csr" ccide-set-class-defaults-private "Set class defaults comment" "Private")
86 ("csx" ccide-set-class-defaults-disabled "Set class defaults comment" "Disabled")
87 ("csm" ccide-set-class-defaults-my "Set class defaults comment" "My")
89 ("cS" ccide-gen-struct-constructors "Generate structure constructors")
91 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
93 ("ce" ccide-gen-exception "Generate an exception class")
98 ("mc" ccide-function-comment "Method comment")
99 ("mp" ccide-grab-prototype "Grab prototype")
100 ("mr" ccide-reformat-defun "Reformat defun")
101 ("mx" ccide-replace-defun "Replace defun")
102 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
103 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
104 ("mi" ccide-grab-inline-decl "Grab inline decl")
105 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
106 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
107 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
108 ("mf" ccide-find-implementation "Find method implementation")
109 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
113 ("vc" ccide-variable-comment "Variable comment")
114 ("vf" ccide-grab-access-fn "Grab access methods")
118 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
119 ("s" ccide-show-all-comments "Show all Doxygen comments")
122 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
123 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
124 ; (nil nil separator)
127 ; ("ts" ccide-scan-mantemps "Scan mantemps")
128 ; (nil nil separator)
131 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
132 ; ("oc" ccide-compile-compile "Make -> Compile")
133 ; ("ox" ccide-compile-clean "Make -> Clean")
134 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
135 ; ("ok" ccide-compile-kill "Kill compilation")
136 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
142 (require 'cc-engine-2)
151 (require 'misc-local)
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 (defsubst ccide-match-string (n)
157 (buffer-substring-no-properties (match-beginning n) (match-end n)))
159 (defun ccide-file-macro-name (&optional file-name)
160 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
162 (string-replace "\\." "_" (file-name-sans-extension
163 (file-name-nondirectory
164 (or file-name (buffer-file-name))))
168 (defun ccide-file-name (&optional extension file-name directory)
169 (concat (if directory (file-name-as-directory directory) "")
170 (file-name-sans-extension
171 (file-name-nondirectory
172 (or file-name (buffer-file-name))))
175 (defun ccide-in-doxy-comment ()
177 (back-to-indentation)
178 (let ((lit (c-in-literal)))
179 (if (cond ((eq lit 'c)
180 (goto-char (car (c-literal-limits)))
181 (looking-at "/\\*\\*<?[ \t\n\r@]"))
183 (goto-char (car (c-literal-limits)))
184 (looking-at "///<?[ \t\n\r@]"))
187 (goto-char (match-end 0))
188 (current-column))))))
190 (defun ccide-shell-command (command)
191 (let ((obuf (get-buffer-create "*ccide shell command*"))
196 (insert command "\n"))
197 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
198 shell-command-switch command))
199 (and exit-status (equal exit-status 0))))
201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 (defun ccide-file-comment ()
205 "Add a comment to this source file."
210 (goto-char (point-min))
211 (insert "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
212 " " ccide-default-author "\n"
213 ccide-default-copyright
216 (cond ((string-match "\\.hh?$" (buffer-file-name))
217 (insert "/** \\file\n"
218 " \\brief " (ccide-file-name) " public header */\n\n"
219 "#ifndef " (ccide-file-macro-name) "\n"
220 "#define " (ccide-file-macro-name) " 1\n\n"
221 "// Custom includes\n\n"
222 "//#include \"" (ccide-file-name ".mpp") "\"\n"
223 "///////////////////////////////hh.p////////////////////////////////////////\n\n")
225 (goto-char (point-max))
226 (insert "\n\n///////////////////////////////hh.e////////////////////////////////////////\n")
227 (if ccide-all-includes-guard
229 "#if !defined(" ccide-all-includes-guard ") && !defined(" (ccide-file-macro-name) "i_)\n"
230 "#define " (ccide-file-macro-name) "i_\n"))
231 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
232 "//#include \"" (ccide-file-name ".ct") "\"\n"
233 "//#include \"" (ccide-file-name ".cti") "\"\n"
236 ((string-match "\\.mpp$" (buffer-file-name))
237 (insert "/** \\file\n"
238 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
241 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
242 "#define " (ccide-file-macro-name) " 1\n\n"
243 "// Custom includes\n\n\n"
244 "// ///////////////////////////mpp.p////////////////////////////////////////\n"
245 "#elif BOOST_PP_IS_ITERATING // ////////////////////////////////////////////\n"
246 "// ////////////////////////////////////////////////////////////////////////\n"
247 "// Local Macros\n\n\n"
248 "// ////////////////////////////////////////////////////////////////////////\n"
249 "#if BOOST_PP_ITERATION_FLAGS()==1 // //////////////////////////////////////\n"
250 "// ////////////////////////////////////////////////////////////////////////\n\n")
252 (goto-char (point-max))
253 (insert "\n\n// ////////////////////////////////////////////////////////////////////////\n"
254 "#endif // /////////////////////////////////////////////////////////////////\n"
255 "// ////////////////////////////////////////////////////////////////////////\n"
256 "// Undefine local Macros\n\n\n"
257 "// ////////////////////////////////////////////////////////////////////////\n"
258 "#endif // /////////////////////////////////////////////////////////////////\n"
259 "// ///////////////////////////mpp.e////////////////////////////////////////"))
261 ((string-match "\\.ih$" (buffer-file-name))
262 (insert "/** \\file\n"
263 " \\brief " (ccide-file-name) " internal header */\n\n"
264 "#ifndef " (ccide-file-macro-name) "\n"
265 "#define " (ccide-file-macro-name) " 1\n\n"
266 "// Custom includes\n\n"
267 "///////////////////////////////ih.p////////////////////////////////////////\n\n")
269 (goto-char (point-max))
270 (insert "\n\n///////////////////////////////ih.e////////////////////////////////////////\n"
273 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
274 (string-match "\\.test\\.cpp$" (buffer-file-name)))
275 (insert "/** \\file\n"
276 " \\brief " (ccide-file-name) " unit tests */\n\n"
277 "//#include \"" (ccide-file-name ".hh") "\"\n"
278 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
279 "// Custom includes\n"
280 "#include \"" (ccide-file-name ".hh" (ccide-file-name)) "\"\n\n"
281 "#include <boost/test/auto_unit_test.hpp>\n"
282 "#include <boost/test/test_tools.hpp>\n\n"
284 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
286 (goto-char (point-max))
287 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
290 ((or (string-match "\\.cc$" (buffer-file-name))
291 (string-match "\\.cpp$" (buffer-file-name)))
292 (insert "/** \\file\n"
293 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
294 "//#include \"" (ccide-file-name ".hh") "\"\n"
295 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
296 "// Custom includes\n\n"
297 "//#include \"" (ccide-file-name ".mpp") "\"\n"
299 "///////////////////////////////cc.p////////////////////////////////////////\n\n")
301 (goto-char (point-max))
302 (insert "\n\n///////////////////////////////cc.e////////////////////////////////////////\n"
304 "//#include \"" (ccide-file-name ".mpp") "\""))
306 ((string-match "\\.cci$" (buffer-file-name))
307 (insert "/** \\file\n"
308 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
309 "// Custom includes\n\n"
310 "#define prefix_ inline\n"
311 "///////////////////////////////cci.p///////////////////////////////////////\n\n")
313 (goto-char (point-max))
314 (insert "\n\n///////////////////////////////cci.e///////////////////////////////////////\n"
317 ((string-match "\\.ct$" (buffer-file-name))
318 (insert "/** \\file\n"
319 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
320 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
321 "// Custom includes\n\n"
323 "///////////////////////////////ct.p////////////////////////////////////////\n\n")
325 (goto-char (point-max))
326 (insert "\n\n///////////////////////////////ct.e////////////////////////////////////////\n"
329 ((string-match "\\.cti$" (buffer-file-name))
330 (insert "/** \\file\n"
331 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
332 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
333 "// Custom includes\n\n"
334 "#define prefix_ inline\n"
335 "///////////////////////////////cti.p///////////////////////////////////////\n\n")
337 (goto-char (point-max))
338 (insert "\n\n///////////////////////////////cti.e///////////////////////////////////////\n"
341 ((string-match "\\.dox$" (buffer-file-name))
342 (insert "/** \\mainpage\n\n ")
345 (setq add-file-vars '(( mode . flyspell)
346 ( mode . auto-fill))))
348 ((string-match "\\.java$" (buffer-file-name))
351 (goto-char (point-max)))
355 (goto-char (point-max))))
358 "// Local Variables:\n"
359 "// mode: " mode "\n")
360 (loop for (var . value) in ccide-file-vars
361 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
362 (loop for (var . value) in add-file-vars
363 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
367 (if (equal mode "jde")
368 (let ((package (file-name-directory (buffer-file-name))))
369 (jdeap-initialize-setup)
370 (if (not (equal jdeap-current-source-directory "."))
372 (concat "^" (regexp-quote jdeap-current-source-directory))
375 (setq package (substring package
377 (1- (length package))))
379 (string-replace "/" "." package t)
381 (insert "class " (file-name-sans-extension
382 (file-name-nondirectory
383 (buffer-file-name))) "\n{}")
384 (beginning-of-line)))))
386 (defun ccide-sync-file-variables ()
387 "Syncronize file variables to the current value of ccide-file-vars"
390 (goto-char (point-max))
391 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
392 (let ((case-fold-search t))
393 (if (search-forward "Local Variables:" nil t)
394 (let (prefix suffix vars)
395 (skip-chars-forward " \t")
397 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
398 (goto-char (match-beginning 0))
400 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
403 (if (and prefix (looking-at prefix))
404 (goto-char (match-end 0)))
405 (skip-chars-forward " \t"))
406 while (not (looking-at "end:"))
408 (setq vars (cons (intern (buffer-substring
410 (progn (skip-chars-forward "^:\n") (point))))
413 (loop for (var . value) in ccide-file-vars
414 do (if (not (memq var vars))
415 (insert (or prefix "")
416 (symbol-name var) ": " (prin1-to-string value)
417 (or suffix "") "\n"))))))))
419 (defun ccide-syncronize-includes ()
420 "Syncronize include's in all other files"
423 (loop for extension in ccide-special-extensions
424 for file-name = (ccide-file-name extension)
426 (cons (cons file-name
427 (or (find-buffer-visiting file-name)
428 (and (file-readable-p file-name)
429 (find-file-noselect file-name))))
432 (loop for buffer in buffer-map
435 (set-buffer (cdr buffer))
437 (loop for include in buffer-map
439 (goto-char (point-min))
440 (while (re-search-forward
441 (concat "^\\(//\\)?#\\s-*include \""
442 (regexp-quote (car include))
445 (goto-char (match-beginning 0))
446 (if (looking-at "//")
449 (if (not (cdr include))
451 (forward-line 1))))))))))
453 (defun ccide-auto-decorate-new-files ()
454 (if (= (point-min) (point-max))
455 (let ((status (buffer-modified-p)))
457 (set-buffer-modified-p status))))
459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
462 (defun ccide-class-comment ()
463 "Add comment to start of current class definition"
465 (let ((class (c-get-class-at-point)))
467 (error "No class found")
468 (goto-char (or (aref (car class) 3)
469 (aref (car class) 1)))
472 (ccide-in-doxy-comment))
474 (search-backward "/**" nil t)
476 (let ((indent (make-string (current-indentation) ? )))
477 (insert "/** \\brief ")
483 (defun ccide-gen-class (name &optional defns)
484 "Generate class declaration template"
485 (interactive (list (read-string (concat "Class name (default "
488 nil nil (ccide-file-name))))
489 (insert "class " name)
490 (indent-according-to-mode)
491 (let ((in (make-string c-basic-offset ? ))
492 (ofs (make-string (current-indentation) ? )))
496 (insert ofs "/** \\brief\n"
502 ofs in "///////////////////////////////////////////////////////////////////////////\n"
503 ofs in "// Types\n\n"
504 ofs in "///////////////////////////////////////////////////////////////////////////\n"
505 ofs in "///\\name Structors and default members\n"
507 ofs in "// default default constructor\n"
508 ofs in "// default copy constructor\n"
509 ofs in "// default copy assignment\n"
510 ofs in "// default destructor\n\n"
511 ofs in "// no conversion constructors\n\n"
513 ofs in "///////////////////////////////////////////////////////////////////////////\n"
514 ofs in "///\\name Accessors\n"
517 ofs in "///////////////////////////////////////////////////////////////////////////\n"
518 ofs in "///\\name Mutators\n"
521 (loop for defn in defns
522 do (insert ofs in defn ";\n"))
525 (insert ofs "protected:\n\n"
529 (defun ccide-gen-class-defaults ()
530 "Generate signatures of the default functions: default constructor,
531 copy constructor, assignment operator and destructor."
532 (indent-according-to-mode)
533 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
534 (in (make-string c-basic-offset ? ))
535 (ofs (make-string (current-indentation) ? ))
536 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
538 (while (string-match "::" name colon)
539 (setq colon (match-end 0)))
540 (setq name (substring name colon))
542 (delete-horizontal-space)
543 (loop with exit = nil
544 do (message (concat "1-dflt constr, 2-destr, "
545 "3-copy constr, 4-copy assmnt, "
546 "c-all copy, d-all dflt, RET-all/done: "))
547 for ch = (read-event)
548 for first = t then nil
549 do (cond ((eq ch 'return)
551 (insert ofs name "()"
553 ofs name "(const " name "& other)"
556 ofs name "& operator=(const " name "& other)"
560 (insert ofs name "()"
563 (insert ofs "~" name "();\n"))
565 (insert ofs name "(const " name "& other)"
568 (insert ofs name "& operator=(const " name "& other)"
571 (insert ofs name "(const " name "& other)"
573 ofs name "& operator=(const " name "& other)"
576 (insert ofs name "()"
578 ofs "~" name "();\n"))
579 (t (setq unread-command-events (cons ch unread-command-events))
583 (defun ccide-gen-class-defaults-impl ()
584 "Generate default implementations for class default functions"
586 (let ((defn (c-build-default-funcions-impl)))
587 (kill-new (cadr defn))
588 (message (concat (car defn) " default members"))))
590 (defun ccide-set-class-defaults-comment (word)
592 (back-to-indentation)
593 (if (not (looking-at ccide-class-defaults-word))
594 (message "Not at class defaults commnet")
595 (replace-match word t t nil 1))))
597 (defmacro ccide-build-class-defaults-f (sym)
598 (let ((fn (intern (concat "ccide-set-class-defaults-"
599 (symbol-name sym)))))
602 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
604 (ccide-build-class-defaults-f no)
605 (ccide-build-class-defaults-f default)
606 (ccide-build-class-defaults-f my)
607 (ccide-build-class-defaults-f protected)
608 (ccide-build-class-defaults-f private)
609 (ccide-build-class-defaults-f disabled)
611 (defun ccide-gen-struct-constructors ()
615 (indent-according-to-mode)
616 (let* ((scope (c-get-block-scope))
617 (class (c-parse-class scope))
618 (variables (c-get-variable-members-with-type class))
619 (name (c-scope-name (aref (car (last scope)) 1)))
620 (in (make-string (current-indentation) ? ))
621 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
622 (insert name "()\n" inin ": ")
623 (indent-according-to-mode)
624 (loop for var in variables
625 for first = t then nil
626 if (not first) do (insert ", ")
627 do (insert (car var) "()"))
628 (insert "\n" in "{}\n"
630 (loop for var in variables
631 for first = t then nil
632 if (not first) do (insert ", ")
633 do (insert (cdr var) " " (car var) "_"))
634 (insert ")\n" inin ": ")
635 (loop for var in variables
636 for first = t then nil
637 if (not first) do (insert ", ")
638 do (insert (car var) "(" (car var) "_)"))
639 (insert "\n" in "{}"))))
641 (defun ccide-class-impl-comment ()
642 "Get implementation comment for current class"
644 (let* ((scope (c-get-block-scope))
645 (name (c-get-full-prefix scope)))
646 (kill-new (concat (make-string 75 ?/) "\n"
652 (defun ccide-gen-exception (class &optional description)
653 (interactive "sException name: ")
656 (indent-according-to-mode)
658 (let ((in (make-string c-basic-offset ? ))
659 (ofs (make-string (current-indentation) ? ))
660 (prefix (c-get-full-prefix (c-get-block-scope)))
662 (insert "struct " class " : public std::exception\n"
663 ofs "{ virtual char const * what() const throw() ")
665 (insert "{ return \"" prefix "::" class "\"; } };")
666 (if (> (current-column) fill-column)
669 (insert "\n" ofs in in))))))
671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
672 ;; function/method level
674 (defun ccide-function-comment ()
675 "Add comment for current function"
677 (if (memq (c-in-literal) '(c c++))
678 ; Assume, we are in the functions comment ...
680 (c-forward-out-of-comment)
681 (c-backward-syntactic-ws)
683 (c-beginning-of-defun-or-decl)
684 (let ((defun (c-get-defun-state))
685 (indent (make-string comment-column ? ))
687 (goto-char (or (aref defun 7) (car (aref defun 6))))
688 (c-backward-syntactic-ws)
689 (if (looking-at "[ \t\n\r]*///<")
691 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
692 (if (> (current-column) comment-column)
694 (indent-to-column comment-column)
695 (search-forward "*/")
697 (if (> (current-column) comment-column)
699 (indent-to-column comment-column)
707 (goto-char (car (aref defun 2)))
708 (setq defun (c-get-defun-state)))
710 (ccide-function-comment-adjust defun (concat indent " "))
711 (if place (goto-char place))))
713 (defun ccide-function-comment-grab-args ()
714 (let ((limit (save-excursion
715 (search-backward "/**" nil t)
718 begin start args argend)
720 (while (or (search-backward "\\param" limit t)
721 (search-backward "\\return" limit t)))
725 (while (search-forward "\\param" argend t)
726 (or (search-forward "\\param" argend t)
727 (search-forward "\\return" argend t)
730 (setq args (cons (ccide-function-comment-parse-arg start (point))
732 (setq start (point)))
734 (if (not (search-forward "\return" argend t))
737 (cons (buffer-substring (point) argend) args))
738 (delete-region begin end))))
740 (defun ccide-function-comment-parse-arg (start end)
743 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
744 (cons (match-string 2)
745 (cons (buffer-substring start (match-beginning 2))
746 (buffer-substring (match-end 2) end)))))
748 (defun ccide-function-comment-get-throws (defun)
751 (goto-char (car (aref defun 4)))
752 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
753 (cdr (aref defun 4)) t)
754 (let ((spec (match-string 2)))
755 (if (> (length spec) 0)
758 (defun ccide-function-comment-adjust (defun indent)
760 (let* ((defargs (mapcar (function (lambda (x)
761 (c-get-template-argument-name (car x) (cdr x))))
763 (defret (and (aref defun 1)
764 (not (string-match (concat "^\\("
766 "\\s-*\\)*\\s-*void$")
767 (buffer-substring (car (aref defun 1))
768 (cdr (aref defun 1)))))))
769 (throws (ccide-function-comment-get-throws defun))
770 (xargs (ccide-function-comment-grab-args))
771 (docargs (cdr xargs))
773 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
774 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
775 (size-eq (= (length defargs) (length docargs))))
776 ;; We differentiate four types changes
778 ;; - removed arguments
779 ;; - reordered arguments
780 ;; - renamed arguments
782 ;; If the change cannot be described by one of the above, it has
783 ;; to be resolved manually
785 (insert indent "\\throws " throws "\n"))
787 ;; reordered arguments or new arguments (or no change)
788 (loop for defarg in defargs
789 for docarg = (assoc defarg docargs)
791 (insert (cadr docarg) (car docarg) (cddr docarg))
792 (insert indent "\\param " defarg " \n"))))
793 (size-eq ; and (not doc-in-def)
795 (loop for defarg in defargs
796 for docarg in docargs
797 do (insert (cadr docarg) defarg (cddr docarg))))
800 (loop for defarg in defargs
801 for docarg = (assoc defarg docargs)
802 do (insert (cadr docarg) (car docarg) (cddr docarg))))
803 (t (error "Arg change too complex. Resolve manualy.")))
804 ;; return value is simple
808 (insert indent "\\return \n"))))
810 (delete-horizontal-space)
813 (defun ccide-grab-prototype (&optional prefix)
814 "Grab prototype of function defined or declared at point. Prefix
815 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
818 (c-beginning-of-defun-or-decl)
819 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
820 ccide-default-prefix))
821 (defn (c-build-defun prfx)))
822 (kill-new (concat (cadr defn) "\n{}\n"))
823 (message (concat (or prfx "")
827 (defun ccide-reformat-defun ()
828 "Reformat the defn of the current defun."
831 (c-beginning-of-defun-or-decl)
832 (let ((defn (c-build-defun nil t)))
833 (delete-region (or (caar (aref (caddr defn) 0))
834 (car (aref (caddr defn) 1))
835 (car (aref (caddr defn) 2)))
836 (or (car (aref (caddr defn) 6))
837 (aref (caddr defn) 7)))
838 (insert (cadr defn) "\n"))))
840 (defun ccide-replace-defun ()
841 "Replace the function header with the one on the top of the kill
842 ring (presumably placed there using c++-grab-prototype)."
845 (c-beginning-of-defun-or-decl)
846 (let ((parse (c-parse-defun)))
847 (delete-region (or (aref parse 0)
856 (defun ccide-prefix-defun-type-with-class (&optional strip)
857 "If a non-keyword type symbol is found prefixing the current defun,
858 it will be prefixed with the current class prefix."
861 (c-beginning-of-defun-or-decl)
862 (let* ((parse (c-parse-defun))
863 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
864 (goto-char (aref parse 1))
865 (while (and (or (looking-at c-any-key)
866 (looking-at c-user-prefix-re)
867 (not (c-at-symbol-p)))
868 (< (point) (aref parse 2))
871 (c-forward-syntactic-ws))
872 (if (and (c-at-symbol-p)
873 (< (point) (aref parse 2))
874 (not (looking-at (regexp-quote prefix))))
875 (let ((pos (string-match "<" prefix)))
877 (insert "typename "))
878 (if (and pos (looking-at (concat (substring prefix 0 pos)
881 (goto-char (match-end 0))
882 (c-backward-syntactic-ws)
883 (insert (substring prefix pos)))
884 (insert prefix "::"))
885 (ccide-reformat-defun))))))
887 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
889 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
891 (defun ccide-insert-defun-prefix (&optional strip)
892 "Insert the current defun prefix at point."
894 (let* ((parse (c-parse-defun))
895 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
896 (insert prefix "::")))
898 (defun ccide-kill-inline-decl (defn)
900 (if (aref (caddr defn) 6)
902 (goto-char (cdr (aref (caddr defn) 6)))
903 (let ((end-mark (point-marker)))
904 (goto-char (car (aref (caddr defn) 6)))
905 (indent-rigidly (point) end-mark
906 (- (current-column)))
910 (buffer-substring-no-properties (point) end-mark)
912 (when (aref (caddr defn) 5)
913 (goto-char (caar (aref (caddr defn) 5)))
914 (c-backward-syntactic-ws)
915 (skip-chars-backward ":"))
916 (c-backward-syntactic-ws)
917 (delete-region (point) end-mark)
919 (concat (cadr defn) "\n{}\n"))))
921 (defun ccide-grab-inline-decl ()
922 "Grab the inline decl at point at turn it into an out-of-line inline
923 declaration at the top of the kill ring."
925 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
926 (kill-new (ccide-kill-inline-decl defn))
927 (message (concat (or ccide-default-prefix "indline")
931 (defun ccide-grab-all-inlines ()
932 "Grab all inline decls in the current class"
934 (let ((class (c-parse-class (c-get-block-scope)))
937 (loop for method in (nreverse (aref class 4))
938 do (when (eq (car method) 'method)
939 (let ((defn (save-excursion
940 (goto-char (cdr method))
941 (c-build-defun (or ccide-default-prefix "inline")))))
942 (if (aref (caddr defn) 6)
943 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
944 (kill-new (loop for defn in (nreverse defns)
945 for next = nil then t
948 (message (format "%d inlines grabed to kill ring" (length defns))))))
951 (defun ccide-grab-create-constructor ()
953 (let ((defn (c-build-create-constructor)))
954 (kill-new (cadr defn))
955 (message (car defn))))
957 (defun ccide-grab-create-constructor-impl (&optional prefix)
959 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
960 ccide-default-prefix))
961 (defn (c-build-create-constructor-impl prfx)))
962 (kill-new (cadr defn))
963 (message (concat (or prfx "")
967 (defun ccide-find-implementation (&optional other-window)
968 "Find implementation of method declared at point."
970 (let* ((state (c-get-defun-state))
971 (name (c-defun-short-name state))
972 (scoped-name (c-defun-full-name state))
973 (args (ccide-implementation-args state))
974 (targs (ccide-implementation-template-args state))
977 (loop for ext in ccide-implementation-extensions
978 for filename = (ccide-file-name ext)
981 (let ((buf (or (find-buffer-visiting filename)
982 (and (file-readable-p filename)
983 (find-file-noselect filename)))))
985 (let ((found (save-excursion
987 (ccide-find-implementation-1 name scoped-name args targs
989 (car (aref state 2))))))
992 (setq rv (cons buf found))
993 (if (not fallback) (setq fallback (cons buf found))))))))))
994 (if (not rv) (setq rv fallback))
996 (let* ((buf (car rv))
998 (win (get-buffer-window buf)))
1002 (switch-to-buffer-other-window buf)
1003 (switch-to-buffer buf)))
1006 (c-beginning-of-defun-or-decl))
1007 (message (concat "Implementation of " scoped-name " not found.")))))
1009 (defun ccide-implementation-args (state)
1010 (string-replace "[ \t\n\r]+" ""
1011 (loop for (start . end) in (aref state 3)
1012 for sep = "" then ","
1014 concat (buffer-substring-no-properties
1015 start (save-excursion
1017 (if (search-forward "=" end 'move) (forward-char -1))
1022 (defun ccide-implementation-template-args (state)
1024 (string-replace "[ \t\n\r]+" ""
1025 (loop for (start . end) in (save-excursion
1026 (goto-char (caar (last (aref state 0))))
1027 (c-parse-template-declaration))
1028 for sep = "" then ","
1030 concat (buffer-substring-no-properties
1031 start (save-excursion
1033 (if (search-forward "=" end 'move) (forward-char -1))
1037 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1038 ;; Within the current buffer, search for all implementations of the
1039 ;; given function. The rv is a list of conses. The car holds the
1040 ;; buffer position of the implementation, the cdr is t if the name,
1041 ;; scoped-name and args are matched, otherwise the args did not match.
1043 (goto-char (point-min))
1044 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1046 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1047 fallback rv check-state)
1048 (while (and (not rv) (re-search-forward re nil t))
1049 (if (and (c-at-toplevel-p)
1050 (not (c-in-literal))
1051 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1052 (not (= (car (aref check-state 2)) skip-def)))
1053 (if (string= scoped-name (c-defun-full-name check-state))
1054 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1055 (string= args (ccide-implementation-args check-state))
1056 (string= targs (ccide-implementation-template-args check-state)))
1057 (setq rv (cons (point) t))
1059 (setq fallback (cons (point) nil)))))))
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1063 ;; variable/type level
1065 (defun ccide-variable-comment ()
1066 "Add a comment to current variable declaration."
1068 (c-forward-out-of-comment)
1069 (c-forward-syntactic-ws)
1070 (while (not (looking-at ";"))
1072 (c-forward-syntactic-ws))
1074 (if (> (current-column) comment-column)
1075 (insert "\n" (make-string comment-column ? ) "///< ")
1076 (indent-to-column comment-column)
1079 (defun ccide-grab-access-fn ()
1083 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1084 (let ((vardef (match-string 0))
1085 (in (make-string c-basic-offset ? ))
1086 type reftype varname fnname argname ws)
1088 (back-to-indentation)
1089 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1091 (setq varname (match-string 2 vardef)
1092 type (match-string 1 vardef)
1093 ws (substring vardef 0 (match-beginning 1)))
1094 (if (string-match "_$" varname)
1095 (setq fnname (string-replace "_$" "" varname)
1096 argname (concat "a_" fnname))
1097 (setq fnname (concat "q_" varname)
1098 argname (concat "a_" varname)))
1099 (if (string-match "^[ \t\n\r]*" type)
1100 (setq type (substring type (match-end 0))))
1101 (if (string-match "^[A-Z]" type)
1102 (setq reftype (concat type " const &"))
1103 (setq reftype type))
1104 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1106 ws in in type " old" varname " = " varname ";\n"
1107 ws in in varname " = " argname ";\n"
1108 ws in in "return old" varname ";\n"
1110 ws reftype " " fnname "() const\n"
1111 ws in "{ return " varname "; }\n"))
1114 (message "No variable found"))))
1116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1117 ;; doxy comment support functions
1119 (defun ccide-special-indent-function ()
1120 "Function to indent doxy comments correctly"
1121 (let ((indent (ccide-in-doxy-comment)))
1123 (let ((lim (save-excursion
1124 (back-to-indentation)
1125 (c-literal-limits)))
1126 (pos (- (point-max) (point))))
1128 (back-to-indentation)
1129 (if (looking-at "*/")
1131 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1133 (if (and (not (looking-at ccide-doxy-tag-re))
1134 (re-search-backward (concat "^\\s-*"
1138 (delete-region (progn (beginning-of-line) (point))
1139 (progn (back-to-indentation) (point)))
1141 (if (> (- (point-max) pos) (point))
1142 (goto-char (- (point-max) pos)))))))
1144 (defun ccide-fill-function ()
1145 "auto-fill function for doxy comments"
1147 (if (not fill-prefix)
1148 (indent-according-to-mode))))
1150 (defun ccide-hide-all-doxy-comments ()
1151 "Hide all doxy comments"
1154 (goto-char (point-min))
1155 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1158 (if (not (looking-at "\\s-*$"))
1161 (let ((start (point)))
1162 (if (re-search-forward "\\*/" nil t)
1164 (if (looking-at "\\s-*\n")
1167 (let ((overlay (make-overlay start (point))))
1168 (overlay-put overlay 'intangible 'hs)
1169 (overlay-put overlay 'invisible 'hs)))))))
1172 (defun ccide-show-all-comments ()
1176 (goto-char (point-min))
1178 (goto-char (next-overlay-change (point)))
1179 (loop for overlay in (overlays-at (point))
1180 if (eq (overlay-get overlay 'invisible) 'hs)
1181 do (delete-overlay overlay))))
1184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1185 ;; CORBA support (omniORB2)
1187 (defun ccide-get-corba-headers ()
1190 (goto-char (point-min))
1191 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1192 (setq files (cons (ccide-match-string 1) files)))
1195 (defun ccide-corba-maybe-build-hh (file)
1196 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1197 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1198 (if (and (file-readable-p idl)
1199 (or (not (file-readable-p skel))
1200 (file-newer-than-file-p idl skel)))
1201 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1203 (kill-buffer buffer))
1204 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1205 (if (ccide-shell-command (concat "cd "
1206 (real-path-name ccide-corba-skel-dir)
1208 ccide-corba-idl-command
1209 (if (> (length ccide-corba-idl-dir) 0)
1210 (concat " -I" ccide-corba-idl-dir))
1214 (display-buffer (get-buffer-create "*ccide shell command*"))
1215 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1216 (if (not (file-readable-p skel))
1217 (error "No file %s or %s"
1218 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1220 (defun ccide-corba-list-skeletons-1 (hh-file)
1221 (ccide-corba-maybe-build-hh hh-file)
1222 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1227 (goto-char (point-min))
1228 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1230 (setq skels (cons (ccide-match-string 1) skels)))))
1231 (mapcar (function (lambda (x) (cons x hh-file)))
1232 (sort skels 'string-lessp))))
1234 (defun ccide-corba-list-skeletons ()
1235 (let ((files (ccide-get-corba-headers)))
1236 (loop for file in files
1237 append (ccide-corba-list-skeletons-1 file))))
1239 (defun ccide-gen-corba-impl (class)
1240 (interactive (list (completing-read "Class name of skeleton: "
1241 (ccide-corba-list-skeletons)
1243 (let* ((skels (ccide-corba-list-skeletons))
1244 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1245 ccide-corba-skel-dir))
1246 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1247 ccide-corba-skel-dir))))
1248 (ccide-gen-class (concat class "_i"))
1249 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1251 (search-forward "protected:" nil t)
1253 (ccide-gen-corba-impl-methods)
1256 (defun ccide-get-corba-defns (hh-file class)
1257 (let ((hh-buf (find-file-noselect hh-file))
1262 (goto-char (point-min))
1263 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1265 (error "CORBA skeleton class not found.")
1266 (search-forward "{")
1268 (let ((end (save-excursion (forward-sexp) (point))))
1269 (while (and (< (point) end)
1270 (< (forward-line 1) 1))
1271 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1272 (setq defns (cons (match-string 1) defns))))))))
1275 (defun ccide-gen-corba-impl-methods ()
1277 (let* ((class (c-get-class-at-point))
1280 (error "No class at point."))
1282 (goto-char (aref (car class) 1))
1283 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1285 (error "No CORBA impl at point."))
1286 (let* ((name (ccide-match-string 1))
1287 (skels (ccide-corba-list-skeletons))
1288 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1289 ccide-corba-skel-dir))
1290 (defns (ccide-get-corba-defns hh-file name))
1292 (goto-char (aref (car class) 2))
1296 (if (re-search-forward "^\\s-*// CORBA$" end t)
1297 (let ((start (match-beginning 0)))
1298 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1299 (let ((eend (match-end 0)))
1302 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1303 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1304 (delete-region start (1+ eend))
1307 (delete-region (point) (progn
1312 (delete-region (point) (progn
1316 (delete-region start (1+ eend))))))
1318 (indent-according-to-mode)
1319 (insert "// CORBA\n")
1320 (loop for defn in defns
1322 (save-excursion (insert defn ";"))
1323 (indent-according-to-mode)
1324 (let ((start (point)) end)
1328 (while (re-search-forward "\\s-+" end t)
1330 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1332 (loop with done = nil
1333 while (> (current-column) c-max-def-column)
1334 do (while (and (> (current-column) c-max-def-column)
1335 (search-backward "," start t)))
1336 do (if (looking-at ",")
1341 (indent-according-to-mode)
1343 (setq start (point))
1348 (indent-according-to-mode)
1349 (insert "// END-CORBA\n")))))
1351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1354 (defun ccide-scan-mantemps ()
1355 "Scan *compilation* buffer for errors and generate manual template
1356 instatiations at point."
1359 (set-buffer "*compilation*")
1360 (goto-char (point-min)))
1362 (set-buffer (get-buffer-create "*mantemps*"))
1364 (loop for temp = (ccide-get-mantemp)
1366 do (insert temp "\n"))
1367 (mantemp-make-mantemps-buffer)
1368 (goto-char (point-min))
1371 (< (forward-line 1) 1))))
1372 (insert-buffer-substring "*mantemps*"))
1374 (defun ccide-get-mantemp ()
1376 (set-buffer "*compilation*")
1377 (if (search-forward "undefined reference to `" nil t)
1378 (let ((start (point)))
1380 (search-backward "'" nil t)
1381 (buffer-substring start (point))))))
1383 (defun ccide-fix-mantemp ()
1384 (let ((end (save-excursion
1385 (end-of-line) (point))))
1386 (if (and (save-excursion (search-forward "(" end t))
1387 (search-forward " class" end t))
1394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1397 (defun ccide-open-compilation-frame ()
1399 (let ((c-frame (selected-frame))
1400 (compilation-frame (make-frame '((minibuffer . nil)
1402 (menu-bar-lines . 0)
1407 (select-frame compilation-frame)
1408 (switch-to-buffer "*compilation*")
1409 (set-window-dedicated-p (selected-window) t)))
1411 (defun ccide-compile (command)
1412 (delete-other-windows)
1413 (split-window-horizontally)
1416 (set-buffer "*compilation*")
1417 (let ((point (point-max)))
1419 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1420 do (set-window-point window point)))))
1422 (defun ccide-compile-compile ()
1424 (ccide-compile (concat "make -k " ccide-compile-opts)))
1426 (defun ccide-compile-clean ()
1428 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1430 (defun ccide-compile-cleandepends ()
1432 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1434 (defun ccide-compile-kill ()
1436 (set-buffer "*compilation*")
1439 (defun ccide-hide-compilation ()
1441 (let ((active (selected-window)))
1443 (loop for window in (get-buffer-window-list "*compilation*")
1444 do (progn (select-window window)
1445 (switch-to-buffer (other-buffer "*compilation*"))))
1446 (select-window active))))
1448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1449 ;; keymap and installation
1451 (defun ccide-bind-keys (prefix map)
1452 (loop for binding in ccide-bindings
1453 do (apply 'vcmd-define-key
1455 (concat prefix (car binding))
1460 (defun ccide-install-it ()
1464 (local-unset-key "\C-c;")
1465 (local-unset-key [menu-bar IDE])
1466 (ccide-bind-keys "\C-c;" (current-local-map))
1467 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1468 (local-set-key "\C-cS" 'ccide-show-all-comments)
1469 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1470 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1471 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1473 (ccide-project-load-config)
1474 (ccide-directory-load-config)
1475 (ccide-auto-decorate-new-files))
1477 (defun ccide-project-load-config ()
1478 (let ((conf (ccide-project-search-upwards "project.el" (file-name-directory (buffer-file-name)))))
1480 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1483 (defun ccide-project-search-upwards (file &optional dir)
1484 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1485 DIR defaults to ccide-project-root"
1486 (let (conf last-dir)
1487 (setq dir (expand-file-name "x" (or dir ccide-project-root)))
1488 (while (and (not (string= (setq last-dir dir
1489 dir (directory-file-name (file-name-directory dir))) last-dir))
1490 (setq conf (expand-file-name file dir))
1491 (not (file-readable-p conf))))
1492 (and (file-readable-p conf) conf)))
1494 (defun ccide-directory-load-config ()
1495 (if (file-readable-p ".dir.el")
1496 (load-file ".dir.el")))
1498 (add-hook 'c-mode-hook 'ccide-install-it)
1499 (add-hook 'c++-mode-hook 'ccide-install-it)
1500 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1502 (loop for extension in ccide-special-extensions
1503 for re = (concat (regexp-quote extension) "$")
1504 if (not (assoc re auto-mode-alist))
1505 do (setq auto-mode-alist (append auto-mode-alist
1506 (list (cons re 'c++-mode)))))
1508 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1509 ;; new indent function for c-mode: do standard indentation first. If line
1510 ;; is to long using standard indentation, just indent by c-basic-indentation.
1511 (let ((cc (save-excursion (end-of-line) (current-column)))
1514 (let ((pos (- (point-max) (point))))
1516 (let ((point (point))
1517 (line (1+ (count-lines 1 (point))))
1519 (c-beginning-of-statement-2)
1520 (if (and (not (c-crosses-statement-barrier-p (point) point))
1521 (not (eq (+ (count-lines 1 (point))
1525 (setq indent (+ (current-indentation) c-basic-offset))
1527 (if (< indent (current-indentation))
1529 (setq ad-return-value
1531 (- (current-indentation) indent)))
1532 (delete-region (c-point 'bol) (c-point 'boi))
1533 (indent-to indent))))))
1534 (if (< (point) (c-point 'boi))
1535 (back-to-indentation)
1536 (if (> (- (point-max) pos) (point))
1537 (goto-char (- (point-max) pos))))))))
1541 ;;; Local Variables:
1542 ;;; elisp-project-autoload-file-name: "cc-autoload.el"