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"
678 ; Assume, we are in the functions comment ...
680 (c-forward-out-of-comment)
681 (c-backward-syntactic-ws)
683 (let ((defun (c-get-defun-state))
684 (indent (make-string comment-column ? ))
686 (goto-char (or (aref defun 7) (car (aref defun 6))))
687 (c-backward-syntactic-ws)
688 (if (looking-at "[ \t\n\r]*///<")
690 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
691 (if (> (current-column) comment-column)
693 (indent-to-column comment-column)
694 (search-forward "*/")
696 (if (> (current-column) comment-column)
698 (indent-to-column comment-column)
706 (goto-char (car (aref defun 2)))
707 (setq defun (c-get-defun-state)))
709 (ccide-function-comment-adjust defun (concat indent " "))
710 (if place (goto-char place))))
712 (defun ccide-function-comment-grab-args ()
713 (let ((limit (save-excursion
714 (search-backward "/**" nil t)
717 begin start args argend)
719 (while (or (search-backward "\\param" limit t)
720 (search-backward "\\return" limit t)))
724 (while (search-forward "\\param" argend t)
725 (or (search-forward "\\param" argend t)
726 (search-forward "\\return" argend t)
729 (setq args (cons (ccide-function-comment-parse-arg start (point))
731 (setq start (point)))
733 (if (not (search-forward "\return" argend t))
736 (cons (buffer-substring (point) argend) args))
737 (delete-region begin end))))
739 (defun ccide-function-comment-parse-arg (start end)
742 (re-search-forward "\\param\\(\\[[^]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
743 (cons (match-string 2)
744 (cons (buffer-substring start (match-beginning 2))
745 (buffer-substring (match-end 2) end)))))
747 (defun ccide-function-comment-get-throws (defun)
750 (goto-char (car (aref defun 4)))
751 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
752 (cdr (aref defun 4)) t)
753 (let ((spec (match-string 2)))
754 (if (> (length spec) 0)
757 (defun ccide-function-comment-adjust (defun indent)
759 (let* ((defargs (mapcar (function (lambda (x)
760 (c-get-template-argument-name (car x) (cdr x))))
762 (defret (and (aref defun 1)
763 (not (string-match (concat "^\\("
765 "\\s-*\\)*\\s-*void$")
766 (buffer-substring (car (aref defun 1))
767 (cdr (aref defun 1)))))))
768 (throws (ccide-function-comment-get-throws defun))
769 (xargs (ccide-function-comment-grab-args))
770 (docargs (cdr xargs))
772 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
773 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
774 (size-eq (= (length defargs) (length docargs))))
775 ;; We differentiate four types changes
777 ;; - removed arguments
778 ;; - reordered arguments
779 ;; - renamed arguments
781 ;; If the change cannot be described by one of the above, it has
782 ;; to be resolved manually
784 (insert indent "\\throws " throws "\n"))
786 ;; reordered arguments or new arguments (or no change)
787 (loop for defarg in defargs
788 for docarg = (assoc defarg docargs)
790 (insert (cadr docarg) (car docarg) (cddr docarg))
791 (insert indent "\\param " defarg " \n"))))
792 (size-eq ; and (not doc-in-def)
794 (loop for defarg in defargs
795 for docarg in docargs
796 do (insert (cadr docarg) defarg (cddr docarg))))
799 (loop for defarg in defargs
800 for docarg = (assoc defarg docargs)
801 do (insert (cadr docarg) (car docarg) (cddr docarg))))
802 (t (error "Arg change too complex. Resolve manualy.")))
803 ;; return value is simple
807 (insert indent "\\return \n"))))
809 (delete-horizontal-space)
812 (defun ccide-grab-prototype (&optional prefix)
813 "Grab prototype of function defined or declared at point. Prefix
814 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
816 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
817 ccide-default-prefix))
818 (defn (c-build-defun prfx)))
819 (kill-new (concat (cadr defn) "\n{}\n"))
820 (message (concat (or prfx "")
824 (defun ccide-reformat-defun ()
825 "Reformat the defn of the current defun."
828 (c-beginning-of-defun-or-decl)
829 (let ((defn (c-build-defun nil t)))
830 (delete-region (or (caar (aref (caddr defn) 0))
831 (car (aref (caddr defn) 1))
832 (car (aref (caddr defn) 2)))
833 (or (car (aref (caddr defn) 6))
834 (aref (caddr defn) 7)))
835 (insert (cadr defn) "\n"))))
837 (defun ccide-replace-defun ()
838 "Replace the function header with the one on the top of the kill
839 ring (presumably placed there using c++-grab-prototype)."
842 (c-beginning-of-defun-or-decl)
843 (let ((parse (c-parse-defun)))
844 (delete-region (or (aref parse 0)
852 (defun ccide-prefix-defun-type-with-class (&optional strip)
853 "If a non-keyword type symbol is found prefixing the current defun,
854 it will be prefixed with the current class prefix."
857 (c-beginning-of-defun-or-decl)
858 (let* ((parse (c-parse-defun))
859 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
860 (goto-char (aref parse 1))
861 (while (and (or (looking-at c-any-key)
862 (looking-at c-user-prefix-re)
863 (not (c-at-symbol-p)))
864 (< (point) (aref parse 2))
867 (c-forward-syntactic-ws))
868 (if (and (c-at-symbol-p)
869 (< (point) (aref parse 2))
870 (not (looking-at (regexp-quote prefix))))
871 (let ((pos (string-match "<" prefix)))
873 (insert "typename "))
874 (if (and pos (looking-at (concat (substring prefix 0 pos)
877 (goto-char (match-end 0))
878 (c-backward-syntactic-ws)
879 (insert (substring prefix pos)))
880 (insert prefix "::"))
881 (ccide-reformat-defun))))))
883 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
885 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
887 (defun ccide-insert-defun-prefix (&optional strip)
888 "Insert the current defun prefix at point."
890 (let* ((parse (c-parse-defun))
891 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
892 (insert prefix "::")))
894 (defun ccide-kill-inline-decl (defn)
896 (if (aref (caddr defn) 6)
898 (goto-char (cdr (aref (caddr defn) 6)))
899 (let ((end-mark (point-marker)))
900 (goto-char (car (aref (caddr defn) 6)))
901 (indent-rigidly (point) end-mark
902 (- (current-column)))
906 (buffer-substring-no-properties (point) end-mark)
908 (when (aref (caddr defn) 5)
909 (goto-char (caar (aref (caddr defn) 5)))
910 (c-backward-syntactic-ws)
911 (skip-chars-backward ":"))
912 (c-backward-syntactic-ws)
913 (delete-region (point) end-mark)
915 (concat (cadr defn) "\n{}\n"))))
917 (defun ccide-grab-inline-decl ()
918 "Grab the inline decl at point at turn it into an out-of-line inline
919 declaration at the top of the kill ring."
921 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
922 (kill-new (ccide-kill-inline-decl defn))
923 (message (concat (or ccide-default-prefix "indline")
927 (defun ccide-grab-all-inlines ()
928 "Grab all inline decls in the current class"
930 (let ((class (c-parse-class (c-get-block-scope)))
933 (loop for method in (nreverse (aref class 4))
934 do (when (eq (car method) 'method)
935 (let ((defn (save-excursion
936 (goto-char (cdr method))
937 (c-build-defun (or ccide-default-prefix "inline")))))
938 (if (aref (caddr defn) 6)
939 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
940 (kill-new (loop for defn in (nreverse defns)
941 for next = nil then t
944 (message (format "%d inlines grabed to kill ring" (length defns))))))
947 (defun ccide-grab-create-constructor ()
949 (let ((defn (c-build-create-constructor)))
950 (kill-new (cadr defn))
951 (message (car defn))))
953 (defun ccide-grab-create-constructor-impl (&optional prefix)
955 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
956 ccide-default-prefix))
957 (defn (c-build-create-constructor-impl prfx)))
958 (kill-new (cadr defn))
959 (message (concat (or prfx "")
963 (defun ccide-find-implementation (&optional other-window)
964 "Find implementation of method declared at point."
966 (let* ((state (c-get-defun-state))
967 (name (c-defun-short-name state))
968 (scoped-name (c-defun-full-name state))
969 (args (ccide-implementation-args state))
970 (targs (ccide-implementation-template-args state))
973 (loop for ext in ccide-implementation-extensions
974 for filename = (ccide-file-name ext)
977 (let ((buf (or (find-buffer-visiting filename)
978 (and (file-readable-p filename)
979 (find-file-noselect filename)))))
981 (let ((found (save-excursion
983 (ccide-find-implementation-1 name scoped-name args targs
985 (car (aref state 2))))))
988 (setq rv (cons buf found))
989 (if (not fallback) (setq fallback (cons buf found))))))))))
990 (if (not rv) (setq rv fallback))
992 (let* ((buf (car rv))
994 (win (get-buffer-window buf)))
998 (switch-to-buffer-other-window buf)
999 (switch-to-buffer buf)))
1002 (c-beginning-of-defun-or-decl))
1003 (message (concat "Implementation of " scoped-name " not found.")))))
1005 (defun ccide-implementation-args (state)
1006 (string-replace "[ \t\n\r]+" ""
1007 (loop for (start . end) in (aref state 3)
1008 for sep = "" then ","
1010 concat (buffer-substring-no-properties
1011 start (save-excursion
1013 (if (search-forward "=" end 'move) (forward-char -1))
1018 (defun ccide-implementation-template-args (state)
1020 (string-replace "[ \t\n\r]+" ""
1021 (loop for (start . end) in (save-excursion
1022 (goto-char (caar (last (aref state 0))))
1023 (c-parse-template-declaration))
1024 for sep = "" then ","
1026 concat (buffer-substring-no-properties
1027 start (save-excursion
1029 (if (search-forward "=" end 'move) (forward-char -1))
1033 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1034 ;; Within the current buffer, search for all implementations of the
1035 ;; given function. The rv is a list of conses. The car holds the
1036 ;; buffer position of the implementation, the cdr is t if the name,
1037 ;; scoped-name and args are matched, otherwise the args did not match.
1039 (goto-char (point-min))
1040 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1042 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1043 fallback rv check-state)
1044 (while (and (not rv) (re-search-forward re nil t))
1045 (if (and (c-at-toplevel-p)
1046 (not (c-in-literal))
1047 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1048 (not (= (car (aref check-state 2)) skip-def)))
1049 (if (string= scoped-name (c-defun-full-name check-state))
1050 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1051 (string= args (ccide-implementation-args check-state))
1052 (string= targs (ccide-implementation-template-args check-state)))
1053 (setq rv (cons (point) t))
1055 (setq fallback (cons (point) nil)))))))
1058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1059 ;; variable/type level
1061 (defun ccide-variable-comment ()
1062 "Add a comment to current variable declaration."
1064 (c-forward-out-of-comment)
1065 (c-forward-syntactic-ws)
1066 (while (not (looking-at ";"))
1068 (c-forward-syntactic-ws))
1070 (if (> (current-column) comment-column)
1071 (insert "\n" (make-string comment-column ? ) "///< ")
1072 (indent-to-column comment-column)
1075 (defun ccide-grab-access-fn ()
1079 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1080 (let ((vardef (match-string 0))
1081 (in (make-string c-basic-offset ? ))
1082 type reftype varname fnname argname ws)
1084 (back-to-indentation)
1085 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1087 (setq varname (match-string 2 vardef)
1088 type (match-string 1 vardef)
1089 ws (substring vardef 0 (match-beginning 1)))
1090 (if (string-match "_$" varname)
1091 (setq fnname (string-replace "_$" "" varname)
1092 argname (concat "a_" fnname))
1093 (setq fnname (concat "q_" varname)
1094 argname (concat "a_" varname)))
1095 (if (string-match "^[ \t\n\r]*" type)
1096 (setq type (substring type (match-end 0))))
1097 (if (string-match "^[A-Z]" type)
1098 (setq reftype (concat type " const &"))
1099 (setq reftype type))
1100 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1102 ws in in type " old" varname " = " varname ";\n"
1103 ws in in varname " = " argname ";\n"
1104 ws in in "return old" varname ";\n"
1106 ws reftype " " fnname "() const\n"
1107 ws in "{ return " varname "; }\n"))
1110 (message "No variable found"))))
1112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1113 ;; doxy comment support functions
1115 (defun ccide-special-indent-function ()
1116 "Function to indent doxy comments correctly"
1117 (let ((indent (ccide-in-doxy-comment)))
1119 (let ((lim (save-excursion
1120 (back-to-indentation)
1121 (c-literal-limits)))
1122 (pos (- (point-max) (point))))
1124 (back-to-indentation)
1125 (if (looking-at "*/")
1127 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1129 (if (and (not (looking-at ccide-doxy-tag-re))
1130 (re-search-backward (concat "^\\s-*"
1134 (delete-region (progn (beginning-of-line) (point))
1135 (progn (back-to-indentation) (point)))
1137 (if (> (- (point-max) pos) (point))
1138 (goto-char (- (point-max) pos)))))))
1140 (defun ccide-fill-function ()
1141 "auto-fill function for doxy comments"
1143 (if (not fill-prefix)
1144 (indent-according-to-mode))))
1146 (defun ccide-hide-all-doxy-comments ()
1147 "Hide all doxy comments"
1150 (goto-char (point-min))
1151 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1154 (if (not (looking-at "\\s-*$"))
1157 (let ((start (point)))
1158 (if (re-search-forward "\\*/" nil t)
1160 (if (looking-at "\\s-*\n")
1163 (let ((overlay (make-overlay start (point))))
1164 (overlay-put overlay 'intangible 'hs)
1165 (overlay-put overlay 'invisible 'hs)))))))
1168 (defun ccide-show-all-comments ()
1172 (goto-char (point-min))
1174 (goto-char (next-overlay-change (point)))
1175 (loop for overlay in (overlays-at (point))
1176 if (eq (overlay-get overlay 'invisible) 'hs)
1177 do (delete-overlay overlay))))
1180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1181 ;; CORBA support (omniORB2)
1183 (defun ccide-get-corba-headers ()
1186 (goto-char (point-min))
1187 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1188 (setq files (cons (ccide-match-string 1) files)))
1191 (defun ccide-corba-maybe-build-hh (file)
1192 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1193 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1194 (if (and (file-readable-p idl)
1195 (or (not (file-readable-p skel))
1196 (file-newer-than-file-p idl skel)))
1197 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1199 (kill-buffer buffer))
1200 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1201 (if (ccide-shell-command (concat "cd "
1202 (real-path-name ccide-corba-skel-dir)
1204 ccide-corba-idl-command
1205 (if (> (length ccide-corba-idl-dir) 0)
1206 (concat " -I" ccide-corba-idl-dir))
1210 (display-buffer (get-buffer-create "*ccide shell command*"))
1211 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1212 (if (not (file-readable-p skel))
1213 (error "No file %s or %s"
1214 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1216 (defun ccide-corba-list-skeletons-1 (hh-file)
1217 (ccide-corba-maybe-build-hh hh-file)
1218 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1223 (goto-char (point-min))
1224 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1226 (setq skels (cons (ccide-match-string 1) skels)))))
1227 (mapcar (function (lambda (x) (cons x hh-file)))
1228 (sort skels 'string-lessp))))
1230 (defun ccide-corba-list-skeletons ()
1231 (let ((files (ccide-get-corba-headers)))
1232 (loop for file in files
1233 append (ccide-corba-list-skeletons-1 file))))
1235 (defun ccide-gen-corba-impl (class)
1236 (interactive (list (completing-read "Class name of skeleton: "
1237 (ccide-corba-list-skeletons)
1239 (let* ((skels (ccide-corba-list-skeletons))
1240 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1241 ccide-corba-skel-dir))
1242 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1243 ccide-corba-skel-dir))))
1244 (ccide-gen-class (concat class "_i"))
1245 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1247 (search-forward "protected:" nil t)
1249 (ccide-gen-corba-impl-methods)
1252 (defun ccide-get-corba-defns (hh-file class)
1253 (let ((hh-buf (find-file-noselect hh-file))
1258 (goto-char (point-min))
1259 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1261 (error "CORBA skeleton class not found.")
1262 (search-forward "{")
1264 (let ((end (save-excursion (forward-sexp) (point))))
1265 (while (and (< (point) end)
1266 (< (forward-line 1) 1))
1267 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1268 (setq defns (cons (match-string 1) defns))))))))
1271 (defun ccide-gen-corba-impl-methods ()
1273 (let* ((class (c-get-class-at-point))
1276 (error "No class at point."))
1278 (goto-char (aref (car class) 1))
1279 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1281 (error "No CORBA impl at point."))
1282 (let* ((name (ccide-match-string 1))
1283 (skels (ccide-corba-list-skeletons))
1284 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1285 ccide-corba-skel-dir))
1286 (defns (ccide-get-corba-defns hh-file name))
1288 (goto-char (aref (car class) 2))
1292 (if (re-search-forward "^\\s-*// CORBA$" end t)
1293 (let ((start (match-beginning 0)))
1294 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1295 (let ((eend (match-end 0)))
1298 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1299 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1300 (delete-region start (1+ eend))
1303 (delete-region (point) (progn
1308 (delete-region (point) (progn
1312 (delete-region start (1+ eend))))))
1314 (indent-according-to-mode)
1315 (insert "// CORBA\n")
1316 (loop for defn in defns
1318 (save-excursion (insert defn ";"))
1319 (indent-according-to-mode)
1320 (let ((start (point)) end)
1324 (while (re-search-forward "\\s-+" end t)
1326 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1328 (loop with done = nil
1329 while (> (current-column) c-max-def-column)
1330 do (while (and (> (current-column) c-max-def-column)
1331 (search-backward "," start t)))
1332 do (if (looking-at ",")
1337 (indent-according-to-mode)
1339 (setq start (point))
1344 (indent-according-to-mode)
1345 (insert "// END-CORBA\n")))))
1347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1350 (defun ccide-scan-mantemps ()
1351 "Scan *compilation* buffer for errors and generate manual template
1352 instatiations at point."
1355 (set-buffer "*compilation*")
1356 (goto-char (point-min)))
1358 (set-buffer (get-buffer-create "*mantemps*"))
1360 (loop for temp = (ccide-get-mantemp)
1362 do (insert temp "\n"))
1363 (mantemp-make-mantemps-buffer)
1364 (goto-char (point-min))
1367 (< (forward-line 1) 1))))
1368 (insert-buffer-substring "*mantemps*"))
1370 (defun ccide-get-mantemp ()
1372 (set-buffer "*compilation*")
1373 (if (search-forward "undefined reference to `" nil t)
1374 (let ((start (point)))
1376 (search-backward "'" nil t)
1377 (buffer-substring start (point))))))
1379 (defun ccide-fix-mantemp ()
1380 (let ((end (save-excursion
1381 (end-of-line) (point))))
1382 (if (and (save-excursion (search-forward "(" end t))
1383 (search-forward " class" end t))
1390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1393 (defun ccide-open-compilation-frame ()
1395 (let ((c-frame (selected-frame))
1396 (compilation-frame (make-frame '((minibuffer . nil)
1398 (menu-bar-lines . 0)
1403 (select-frame compilation-frame)
1404 (switch-to-buffer "*compilation*")
1405 (set-window-dedicated-p (selected-window) t)))
1407 (defun ccide-compile (command)
1408 (delete-other-windows)
1409 (split-window-horizontally)
1412 (set-buffer "*compilation*")
1413 (let ((point (point-max)))
1415 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1416 do (set-window-point window point)))))
1418 (defun ccide-compile-compile ()
1420 (ccide-compile (concat "make -k " ccide-compile-opts)))
1422 (defun ccide-compile-clean ()
1424 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1426 (defun ccide-compile-cleandepends ()
1428 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1430 (defun ccide-compile-kill ()
1432 (set-buffer "*compilation*")
1435 (defun ccide-hide-compilation ()
1437 (let ((active (selected-window)))
1439 (loop for window in (get-buffer-window-list "*compilation*")
1440 do (progn (select-window window)
1441 (switch-to-buffer (other-buffer "*compilation*"))))
1442 (select-window active))))
1444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1445 ;; keymap and installation
1447 (defun ccide-bind-keys (prefix map)
1448 (loop for binding in ccide-bindings
1449 do (apply 'vcmd-define-key
1451 (concat prefix (car binding))
1456 (defun ccide-install-it ()
1460 (local-unset-key "\C-c;")
1461 (local-unset-key [menu-bar IDE])
1462 (ccide-bind-keys "\C-c;" (current-local-map))
1463 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1464 (local-set-key "\C-cS" 'ccide-show-all-comments)
1465 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1466 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1467 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1469 (ccide-project-load-config)
1470 (ccide-directory-load-config)
1471 (ccide-auto-decorate-new-files))
1473 (defun ccide-project-load-config ()
1474 (let ((conf (ccide-project-search-upwards "project.el" (file-name-directory (buffer-file-name)))))
1476 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1479 (defun ccide-project-search-upwards (file &optional dir)
1480 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1481 DIR defaults to ccide-project-root"
1482 (let (conf last-dir)
1483 (setq dir (expand-file-name "x" (or dir ccide-project-root)))
1484 (while (and (not (string= (setq last-dir dir
1485 dir (directory-file-name (file-name-directory dir))) last-dir))
1486 (setq conf (expand-file-name file dir))
1487 (not (file-readable-p conf))))
1488 (and (file-readable-p conf) conf)))
1490 (defun ccide-directory-load-config ()
1491 (if (file-readable-p ".dir.el")
1492 (load-file ".dir.el")))
1494 (add-hook 'c-mode-hook 'ccide-install-it)
1495 (add-hook 'c++-mode-hook 'ccide-install-it)
1496 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1498 (loop for extension in ccide-special-extensions
1499 for re = (concat (regexp-quote extension) "$")
1500 if (not (assoc re auto-mode-alist))
1501 do (setq auto-mode-alist (append auto-mode-alist
1502 (list (cons re 'c++-mode)))))
1504 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1505 ;; new indent function for c-mode: do standard indentation first. If line
1506 ;; is to long using standard indentation, just indent by c-basic-indentation.
1507 (let ((cc (save-excursion (end-of-line) (current-column)))
1510 (let ((pos (- (point-max) (point))))
1512 (let ((point (point))
1513 (line (1+ (count-lines 1 (point))))
1515 (c-beginning-of-statement-2)
1516 (if (and (not (c-crosses-statement-barrier-p (point) point))
1517 (not (eq (+ (count-lines 1 (point))
1521 (setq indent (+ (current-indentation) c-basic-offset))
1523 (if (< indent (current-indentation))
1525 (setq ad-return-value
1527 (- (current-indentation) indent)))
1528 (delete-region (c-point 'bol) (c-point 'boi))
1529 (indent-to indent))))))
1530 (if (< (point) (c-point 'boi))
1531 (back-to-indentation)
1532 (if (> (- (point-max) pos) (point))
1533 (goto-char (- (point-max) pos))))))))
1537 ;;; Local Variables:
1538 ;;; elisp-project-autoload-file-name: "cc-autoload.el"