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 nil)
56 (defvar ccide-new-file-hook nil)
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")
97 ("c<" ccide-gen-struct-compare "Generate structure compare operators")
99 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
101 ("ce" ccide-gen-exception "Generate an exception class")
106 ("mc" ccide-function-comment "Method comment")
107 ("mp" ccide-grab-prototype "Grab prototype")
108 ("mr" ccide-reformat-defun "Reformat defun")
109 ("mx" ccide-replace-defun "Replace defun")
110 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
111 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
112 ("mi" ccide-grab-inline-decl "Grab inline decl")
113 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
114 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
115 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
116 ("mf" ccide-find-implementation "Find method implementation")
117 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
121 ("vc" ccide-variable-comment "Variable comment")
122 ("vf" ccide-grab-access-fn "Grab access methods")
126 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
127 ("s" ccide-show-all-comments "Show all Doxygen comments")
130 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
131 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
132 ; (nil nil separator)
135 ; ("ts" ccide-scan-mantemps "Scan mantemps")
136 ; (nil nil separator)
139 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
140 ; ("oc" ccide-compile-compile "Make -> Compile")
141 ; ("ox" ccide-compile-clean "Make -> Clean")
142 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
143 ; ("ok" ccide-compile-kill "Kill compilation")
144 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
150 (require 'cc-engine-2)
159 (require 'misc-local)
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 (defsubst ccide-match-string (n)
165 (buffer-substring-no-properties (match-beginning n) (match-end n)))
167 (defun ccide-file-macro-name (&optional file-name)
168 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
170 (if ccide-project-name (concat ccide-project-name "_") "")
171 (if ccide-project-root
172 (string-replace "/" "_"
173 (substring (file-name-directory
174 (expand-file-name (or file-name buffer-file-name)))
175 (length ccide-project-root))
178 (string-replace "\\." "_" (file-name-sans-extension
179 (file-name-nondirectory
180 (or file-name (buffer-file-name))))
184 (defun ccide-file-name (&optional extension file-name directory)
185 (concat (if directory (file-name-as-directory directory) "")
186 (file-name-sans-extension
187 (file-name-nondirectory
188 (or file-name (buffer-file-name))))
191 (defun ccide-in-doxy-comment ()
193 (back-to-indentation)
194 (let ((lit (c-in-literal)))
195 (when (and (memq lit '(c c++))
196 (progn (goto-char (car (c-literal-limits)))
197 (looking-at "/\\(\\*\\*\\|///\\)<?[ \t\n\r@]")))
198 (goto-char (match-end 0))
201 (defun ccide-shell-command (command)
202 (let ((obuf (get-buffer-create "*ccide shell command*"))
207 (insert command "\n"))
208 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
209 shell-command-switch command))
210 (and exit-status (equal exit-status 0))))
212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
215 (defun ccide-file-comment ()
216 "Add a comment to this source file."
221 (goto-char (point-min))
224 "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
225 " " ccide-default-author "\n"
226 ccide-default-copyright
229 (cond ((string-match "\\.hh?$" (buffer-file-name))
230 (insert "/** \\file\n"
231 " \\brief " (ccide-file-name) " public header */\n\n"
232 "#ifndef " (ccide-file-macro-name) "\n"
233 "#define " (ccide-file-macro-name) " 1\n\n")
234 (if ccide-all-includes
235 (insert "#ifndef " (ccide-file-macro-name ccide-all-includes) "\n"
236 "#error \"Don't include '" (file-name-nondirectory (buffer-file-name)) "'"
237 " directly, include '" ccide-all-includes "'\"\n"
239 (insert "// Custom includes\n\n"
240 "//#include \"" (ccide-file-name ".mpp") "\"\n"
241 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
243 (goto-char (point-max))
244 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n")
245 (if ccide-all-includes
247 "#if !defined(" (ccide-file-macro-name ccide-all-includes) "_decls_) "
248 "&& !defined(" (ccide-file-macro-name) "i_)\n"
249 "#define " (ccide-file-macro-name) "i_\n"))
250 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
251 "//#include \"" (ccide-file-name ".ct") "\"\n"
252 "//#include \"" (ccide-file-name ".cti") "\"\n"
255 ((string-match "\\.mpp$" (buffer-file-name))
256 (insert "/** \\file\n"
257 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
260 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
261 "#define " (ccide-file-macro-name) " 1\n\n"
262 "// Custom includes\n\n\n"
263 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
264 "#elif BOOST_PP_IS_ITERATING //-/////////////////////////////////////////////////////////////////////\n"
265 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
266 "// Local Macros\n\n\n"
267 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
268 "#if BOOST_PP_ITERATION_FLAGS()==1 //-///////////////////////////////////////////////////////////////\n"
269 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
271 (goto-char (point-max))
272 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
273 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
274 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
275 "// Undefine local Macros\n\n\n"
276 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
277 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
278 "//-/////////////////////////////////////////////////////////////////////////////////////////////////"))
280 ((string-match "\\.ih$" (buffer-file-name))
281 (insert "/** \\file\n"
282 " \\brief " (ccide-file-name) " internal header */\n\n"
283 "#ifndef " (ccide-file-macro-name) "\n"
284 "#define " (ccide-file-macro-name) " 1\n\n"
285 "// Custom includes\n\n"
286 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
288 (goto-char (point-max))
289 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
292 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
293 (string-match "\\.test\\.cpp$" (buffer-file-name)))
294 (insert "/** \\file\n"
295 " \\brief " (ccide-file-name) " unit tests */\n\n"
296 "//#include \"" (ccide-file-name ".hh") "\"\n"
297 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
298 "// Custom includes\n"
299 "#include \"" (or ccide-all-includes
300 (ccide-file-name ".hh" (ccide-file-name))) "\"\n\n"
301 "#include <boost/test/auto_unit_test.hpp>\n"
302 "#include <boost/test/test_tools.hpp>\n\n"
304 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
306 (goto-char (point-max))
307 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
310 ((or (string-match "\\.cc$" (buffer-file-name))
311 (string-match "\\.cpp$" (buffer-file-name)))
312 (insert "/** \\file\n"
313 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
314 (if ccide-all-includes "" "//")
315 "#include \"" (or ccide-all-includes (ccide-file-name ".hh")) "\"\n"
316 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
317 "// Custom includes\n\n"
318 "//#include \"" (ccide-file-name ".mpp") "\"\n"
320 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
322 (goto-char (point-max))
323 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
325 "//#include \"" (ccide-file-name ".mpp") "\""))
327 ((string-match "\\.cci$" (buffer-file-name))
328 (insert "/** \\file\n"
329 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
330 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
331 "// Custom includes\n\n"
332 "#define prefix_ inline\n"
333 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
335 (goto-char (point-max))
336 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
339 ((string-match "\\.ct$" (buffer-file-name))
340 (insert "/** \\file\n"
341 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
342 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
343 "// Custom includes\n\n"
345 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
347 (goto-char (point-max))
348 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
351 ((string-match "\\.cti$" (buffer-file-name))
352 (insert "/** \\file\n"
353 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
354 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
355 "// Custom includes\n\n"
356 "#define prefix_ inline\n"
357 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
359 (goto-char (point-max))
360 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
363 ((string-match "\\.dox$" (buffer-file-name))
364 (insert "/** \\mainpage\n\n ")
367 (setq add-file-vars '(( mode . flyspell)
368 ( mode . auto-fill))))
370 ((string-match "\\.java$" (buffer-file-name))
373 (goto-char (point-max)))
377 (goto-char (point-max))))
380 "// Local Variables:\n"
381 "// mode: " mode "\n")
382 (loop for (var . value) in ccide-file-vars
383 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
384 (loop for (var . value) in add-file-vars
385 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
389 (if (equal mode "jde")
390 (let ((package (file-name-directory (buffer-file-name))))
391 (jdeap-initialize-setup)
392 (if (not (equal jdeap-current-source-directory "."))
394 (concat "^" (regexp-quote jdeap-current-source-directory))
397 (setq package (substring package
399 (1- (length package))))
401 (string-replace "/" "." package t)
403 (insert "class " (file-name-sans-extension
404 (file-name-nondirectory
405 (buffer-file-name))) "\n{}")
406 (beginning-of-line))))
407 (run-hooks 'ccide-new-file-hooks))
409 (defun ccide-sync-file-variables ()
410 "Syncronize file variables to the current value of ccide-file-vars"
413 (goto-char (point-max))
414 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
415 (let ((case-fold-search t))
416 (if (search-forward "Local Variables:" nil t)
417 (let (prefix suffix vars)
418 (skip-chars-forward " \t")
420 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
421 (goto-char (match-beginning 0))
423 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
426 (if (and prefix (looking-at prefix))
427 (goto-char (match-end 0)))
428 (skip-chars-forward " \t"))
429 while (not (looking-at "end:"))
431 (setq vars (cons (intern (buffer-substring
433 (progn (skip-chars-forward "^:\n") (point))))
436 (loop for (var . value) in ccide-file-vars
437 do (if (not (memq var vars))
438 (insert (or prefix "")
439 (symbol-name var) ": " (prin1-to-string value)
440 (or suffix "") "\n"))))))))
442 (defun ccide-syncronize-includes ()
443 "Syncronize include's in all other files"
446 (loop for extension in ccide-special-extensions
447 for file-name = (ccide-file-name extension)
449 (cons (cons file-name
450 (or (find-buffer-visiting file-name)
451 (and (file-readable-p file-name)
452 (find-file-noselect file-name))))
455 (loop for buffer in buffer-map
458 (set-buffer (cdr buffer))
460 (loop for include in buffer-map
462 (goto-char (point-min))
463 (while (re-search-forward
464 (concat "^\\(//\\)?#\\s-*include \""
465 (regexp-quote (car include))
468 (goto-char (match-beginning 0))
469 (if (looking-at "//")
472 (if (not (cdr include))
474 (forward-line 1))))))))))
476 (defun ccide-auto-decorate-new-files ()
477 (if (and (buffer-file-name) (= (point-min) (point-max)))
478 (let ((status (buffer-modified-p)))
480 (set-buffer-modified-p status))))
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
485 (defun ccide-class-comment ()
486 "Add comment to start of current class definition"
488 (let ((class (c-get-class-at-point)))
490 (error "No class found")
491 (goto-char (or (aref (car class) 3)
492 (aref (car class) 1)))
495 (ccide-in-doxy-comment))
497 (search-backward "/**" nil t)
499 (let ((indent (make-string (current-indentation) ? )))
500 (insert "/** \\brief ")
506 (defun ccide-gen-class (name &optional defns)
507 "Generate class declaration template"
508 (interactive (list (read-string (concat "Class name (default "
511 nil nil (ccide-file-name))))
512 (insert "class " name)
513 (indent-according-to-mode)
514 (let ((in (make-string c-basic-offset ? ))
515 (ofs (make-string (current-indentation) ? ))
516 (sl (make-string (- 100 3 c-basic-offset (current-indentation)) ?/)))
520 (insert ofs "/** \\brief\n"
527 ofs in "// Types\n\n"
529 ofs in "///\\name Structors and default members\n"
531 ofs in "// default default constructor\n"
532 ofs in "// default copy constructor\n"
533 ofs in "// default copy assignment\n"
534 ofs in "// default destructor\n\n"
535 ofs in "// no conversion constructors\n\n"
538 ofs in "///\\name Accessors\n"
542 ofs in "///\\name Mutators\n"
545 (loop for defn in defns
546 do (insert ofs in defn ";\n"))
549 (insert ofs "protected:\n\n"
553 (defun ccide-gen-class-defaults ()
554 "Generate signatures of the default functions: default constructor,
555 copy constructor, assignment operator and destructor."
556 (indent-according-to-mode)
557 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
558 (in (make-string c-basic-offset ? ))
559 (ofs (make-string (current-indentation) ? ))
560 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
562 (while (string-match "::" name colon)
563 (setq colon (match-end 0)))
564 (setq name (substring name colon))
566 (delete-horizontal-space)
567 (loop with exit = nil
568 do (message (concat "1-dflt constr, 2-destr, "
569 "3-copy constr, 4-copy assmnt, "
570 "c-all copy, d-all dflt, RET-all/done: "))
571 for ch = (read-event)
572 for first = t then nil
573 do (cond ((eq ch 'return)
575 (insert ofs name "()"
577 ofs name "(const " name "& other)"
580 ofs name "& operator=(const " name "& other)"
584 (insert ofs name "()"
587 (insert ofs "~" name "();\n"))
589 (insert ofs name "(const " name "& other)"
592 (insert ofs name "& operator=(const " name "& other)"
595 (insert ofs name "(const " name "& other)"
597 ofs name "& operator=(const " name "& other)"
600 (insert ofs name "()"
602 ofs "~" name "();\n"))
603 (t (setq unread-command-events (cons ch unread-command-events))
607 (defun ccide-gen-class-defaults-impl ()
608 "Generate default implementations for class default functions"
610 (let ((defn (c-build-default-funcions-impl)))
611 (kill-new (cadr defn))
612 (message (concat (car defn) " default members"))))
614 (defun ccide-set-class-defaults-comment (word)
616 (back-to-indentation)
617 (if (not (looking-at ccide-class-defaults-word))
618 (message "Not at class defaults commnet")
619 (replace-match word t t nil 1))))
621 (defmacro ccide-build-class-defaults-f (sym)
622 (let ((fn (intern (concat "ccide-set-class-defaults-"
623 (symbol-name sym)))))
626 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
628 (ccide-build-class-defaults-f no)
629 (ccide-build-class-defaults-f default)
630 (ccide-build-class-defaults-f my)
631 (ccide-build-class-defaults-f protected)
632 (ccide-build-class-defaults-f private)
633 (ccide-build-class-defaults-f disabled)
635 (defun ccide-gen-struct-constructors ()
640 (indent-according-to-mode)
641 (let* ((scope (c-get-block-scope))
642 (class (c-parse-class scope))
643 (variables (c-get-variable-members-with-type class))
644 (name (c-scope-name (aref (car (last scope)) 1)))
645 (in (make-string (current-indentation) ? ))
646 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
647 (insert name "()\n" inin ": ")
648 (loop for var in variables
649 for first = t then nil
650 if (not first) do (insert ", ")
651 do (insert (car var) " ()"))
654 (loop for var in variables
655 for first = t then nil
656 if (not first) do (insert ", ")
657 do (insert (cdr var) " " (car var) "_"))
658 (insert ")\n" inin ": ")
659 (loop for var in variables
660 for first = t then nil
661 if (not first) do (insert ", ")
662 do (insert (car var) " (" (car var) "_)"))
666 (defun ccide-gen-struct-compare ()
671 (indent-according-to-mode)
672 (let* ((scope (c-get-block-scope))
673 (class (c-parse-class scope))
674 (variables (c-get-variable-members-with-type class))
675 (name (c-scope-name (aref (car (last scope)) 1)))
676 (in (make-string (current-indentation) ? ))
677 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
679 (insert "bool operator<(" name " const & other) const\n"
681 (loop for ((varName . varType) . tail) on variables
682 do (insert inin varName " < other." varName " ? true :")
684 (insert "\n" inin "other." varName " < " varName " ? false :\n")
685 (insert " false; }\n\n")))
686 (insert in "bool operator==(" name " const & other) const\n"
688 (loop for ((varName . varType) . tail) on variables
689 do (insert inin varName " == other." varName)
690 do (if tail (insert " &&\n") (insert "; }\n\n")))
691 (insert in "std::size_type hash_value() const\n"
692 in "{ std::size_t current (0);\n")
693 (loop for ((varName . varType) . tail) on variables
694 do (insert inin "boost::hash_combine(current, " varName ");\n"))
695 (insert inin "return current; }\n\n")
696 (insert in "void write(std::ostream & os) const\n"
698 (loop for ((varName . varType) . tail) on variables
699 do (insert "\n" inin "<< " varName)
700 do (if tail (insert " << ' '")))
701 (insert " << \" }\"; }\n"))))
703 (defun ccide-class-impl-comment ()
704 "Get implementation comment for current class"
706 (let* ((scope (c-get-block-scope))
707 (name (c-get-full-prefix scope)))
708 (kill-new (concat (make-string 75 ?/) "\n"
714 (defun ccide-gen-exception (class &optional description)
715 (interactive "sException name: \nsDescription (defaults to full class name): ")
718 (indent-according-to-mode)
720 (let ((in (make-string c-basic-offset ? ))
721 (ofs (make-string (current-indentation) ? ))
722 (prefix (c-get-full-prefix (c-get-block-scope)))
724 (insert "struct " class " : public std::exception\n"
725 ofs "{ virtual char const * what() const throw() ")
727 (insert "{ return \""
728 (if (and description (> (length description) 0))
730 (concat prefix "::" class))
732 (if (> (current-column) fill-column)
735 (insert "\n" ofs in in))))))
737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
738 ;; function/method level
740 (defun ccide-function-comment ()
741 "Add comment for current function"
743 (if (memq (c-in-literal) '(c c++))
744 ; Assume, we are in the functions comment ...
746 (c-forward-out-of-comment)
747 (c-backward-syntactic-ws)
750 (c-beginning-of-defun-or-decl)
751 (let ((defun (c-get-defun-state))
752 (indent (make-string comment-column ? ))
754 (goto-char (or (aref defun 7) (car (aref defun 6))))
755 (c-backward-syntactic-ws)
756 (if (looking-at "[ \t\n\r]*///<")
758 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
759 (if (> (current-column) comment-column)
761 (indent-to-column comment-column)
762 (search-forward "*/")
764 (if (> (current-column) comment-column)
766 (indent-to-column comment-column)
774 (goto-char (car (aref defun 2)))
775 (setq defun (c-get-defun-state)))
777 (ccide-function-comment-adjust defun (concat indent " "))
778 (if place (goto-char place))))
780 (defun ccide-function-comment-grab-args ()
781 (let ((limit (save-excursion
782 (search-backward "/**" nil t)
785 begin start args argend)
787 (while (or (search-backward "\\param" limit t)
788 (search-backward "\\return" limit t)))
792 (while (search-forward "\\param" argend t)
793 (or (search-forward "\\param" argend t)
794 (search-forward "\\return" argend t)
797 (setq args (cons (ccide-function-comment-parse-arg start (point))
799 (setq start (point)))
801 (if (not (search-forward "\return" argend t))
804 (cons (buffer-substring (point) argend) args))
805 (delete-region begin end))))
807 (defun ccide-function-comment-parse-arg (start end)
810 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
811 (cons (match-string 2)
812 (cons (buffer-substring start (match-beginning 2))
813 (buffer-substring (match-end 2) end)))))
815 (defun ccide-function-comment-get-throws (defun)
818 (goto-char (car (aref defun 4)))
819 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
820 (cdr (aref defun 4)) t)
821 (let ((spec (match-string 2)))
822 (if (> (length spec) 0)
825 (defun ccide-function-comment-adjust (defun indent)
827 (let* ((defargs (mapcar (function (lambda (x)
828 (c-get-template-argument-name (car x) (cdr x))))
830 (defret (and (aref defun 1)
831 (not (string-match (concat "^\\("
833 "\\s-*\\)*\\s-*void$")
834 (buffer-substring (car (aref defun 1))
835 (cdr (aref defun 1)))))))
836 (throws (ccide-function-comment-get-throws defun))
837 (xargs (ccide-function-comment-grab-args))
838 (docargs (cdr xargs))
840 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
841 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
842 (size-eq (= (length defargs) (length docargs))))
843 ;; We differentiate four types changes
845 ;; - removed arguments
846 ;; - reordered arguments
847 ;; - renamed arguments
849 ;; If the change cannot be described by one of the above, it has
850 ;; to be resolved manually
852 (insert indent "\\throws " throws "\n"))
854 ;; reordered arguments or new arguments (or no change)
855 (loop for defarg in defargs
856 for docarg = (assoc defarg docargs)
858 (insert (cadr docarg) (car docarg) (cddr docarg))
859 (insert indent "\\param " defarg " \n"))))
860 (size-eq ; and (not doc-in-def)
862 (loop for defarg in defargs
863 for docarg in docargs
864 do (insert (cadr docarg) defarg (cddr docarg))))
867 (loop for defarg in defargs
868 for docarg = (assoc defarg docargs)
869 do (insert (cadr docarg) (car docarg) (cddr docarg))))
870 (t (error "Arg change too complex. Resolve manualy.")))
871 ;; return value is simple
875 (insert indent "\\return \n"))))
877 (delete-horizontal-space)
880 (defun ccide-grab-prototype (&optional prefix)
881 "Grab prototype of function defined or declared at point. Prefix
882 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
885 (c-beginning-of-defun-or-decl)
886 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
887 ccide-default-prefix))
888 (defn (c-build-defun prfx)))
889 (kill-new (concat (cadr defn) "\n{}\n"))
890 (message (concat (or prfx "")
894 (defun ccide-reformat-defun ()
895 "Reformat the defn of the current defun."
898 (c-beginning-of-defun-or-decl)
899 (let ((defn (c-build-defun nil t)))
900 (delete-region (or (caar (aref (caddr defn) 0))
901 (car (aref (caddr defn) 1))
902 (car (aref (caddr defn) 2)))
903 (or (car (aref (caddr defn) 6))
904 (aref (caddr defn) 7)))
905 (insert (cadr defn) "\n"))))
907 (defun ccide-replace-defun ()
908 "Replace the function header with the one on the top of the kill
909 ring (presumably placed there using c++-grab-prototype)."
912 (c-beginning-of-defun-or-decl)
913 (let ((parse (c-parse-defun)))
914 (delete-region (or (aref parse 0)
923 (defun ccide-prefix-defun-type-with-class (&optional strip)
924 "If a non-keyword type symbol is found prefixing the current defun,
925 it will be prefixed with the current class prefix."
928 (c-beginning-of-defun-or-decl)
929 (let* ((parse (c-parse-defun))
930 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
931 (goto-char (aref parse 1))
932 (while (and (or (looking-at c-any-key)
933 (looking-at c-user-prefix-re)
934 (not (c-at-symbol-p)))
935 (< (point) (aref parse 2))
938 (c-forward-syntactic-ws))
939 (if (and (c-at-symbol-p)
940 (< (point) (aref parse 2))
941 (not (looking-at (regexp-quote prefix))))
942 (let ((pos (string-match "<" prefix)))
944 (insert "typename "))
945 (if (and pos (looking-at (concat (substring prefix 0 pos)
948 (goto-char (match-end 0))
949 (c-backward-syntactic-ws)
950 (insert (substring prefix pos)))
951 (insert prefix "::"))
952 (ccide-reformat-defun))))))
954 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
956 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
958 (defun ccide-insert-defun-prefix (&optional strip)
959 "Insert the current defun prefix at point."
961 (let* ((parse (c-parse-defun))
962 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
963 (insert prefix "::")))
965 (defun ccide-kill-inline-decl (defn)
967 (if (aref (caddr defn) 6)
969 (goto-char (cdr (aref (caddr defn) 6)))
970 (let ((end-mark (point-marker)))
971 (goto-char (car (aref (caddr defn) 6)))
972 (indent-rigidly (point) end-mark
973 (- (current-column)))
977 (buffer-substring-no-properties (point) end-mark)
979 (when (aref (caddr defn) 5)
980 (goto-char (caar (aref (caddr defn) 5)))
981 (c-backward-syntactic-ws)
982 (skip-chars-backward ":"))
983 (c-backward-syntactic-ws)
984 (delete-region (point) end-mark)
986 (concat (cadr defn) "\n{}\n"))))
988 (defun ccide-grab-inline-decl ()
989 "Grab the inline decl at point at turn it into an out-of-line inline
990 declaration at the top of the kill ring."
992 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
993 (kill-new (ccide-kill-inline-decl defn))
994 (message (concat (or ccide-default-prefix "indline")
998 (defun ccide-grab-all-inlines ()
999 "Grab all inline decls in the current class"
1001 (let ((class (c-parse-class (c-get-block-scope)))
1004 (loop for method in (nreverse (aref class 4))
1005 do (when (eq (car method) 'method)
1006 (let ((defn (save-excursion
1007 (goto-char (cdr method))
1008 (c-build-defun (or ccide-default-prefix "inline")))))
1009 (if (aref (caddr defn) 6)
1010 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
1011 (setq defns (nreverse defns))
1012 (kill-new (loop for defn in defns
1013 for next = nil then t
1014 if next concat "\n";
1016 (message (format "%d inlines grabed to kill ring" (length defns))))))
1018 (defun ccide-grab-create-constructor ()
1020 (let ((defn (c-build-create-constructor)))
1021 (kill-new (cadr defn))
1022 (message (car defn))))
1024 (defun ccide-grab-create-constructor-impl (&optional prefix)
1026 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
1027 ccide-default-prefix))
1028 (defn (c-build-create-constructor-impl prfx)))
1029 (kill-new (cadr defn))
1030 (message (concat (or prfx "")
1034 (defun ccide-find-implementation (&optional other-window)
1035 "Find implementation of method declared at point."
1037 (let* ((state (c-get-defun-state))
1038 (name (c-defun-short-name state))
1039 (scoped-name (c-defun-full-name state))
1040 (args (ccide-implementation-args state))
1041 (targs (ccide-implementation-template-args state))
1044 (loop for ext in ccide-implementation-extensions
1045 for filename = (ccide-file-name ext)
1048 (let ((buf (or (find-buffer-visiting filename)
1049 (and (file-readable-p filename)
1050 (find-file-noselect filename)))))
1052 (let ((found (save-excursion
1054 (ccide-find-implementation-1 name scoped-name args targs
1055 (not (aref state 6))
1056 (car (aref state 2))))))
1059 (setq rv (cons buf found))
1060 (if (not fallback) (setq fallback (cons buf found))))))))))
1061 (if (not rv) (setq rv fallback))
1063 (let* ((buf (car rv))
1065 (win (get-buffer-window buf)))
1069 (switch-to-buffer-other-window buf)
1070 (switch-to-buffer buf)))
1073 (c-beginning-of-defun-or-decl))
1074 (message (concat "Implementation of " scoped-name " not found.")))))
1076 (defun ccide-implementation-args (state)
1077 (string-replace "[ \t\n\r]+" ""
1078 (loop for (start . end) in (aref state 3)
1079 for sep = "" then ","
1081 concat (buffer-substring-no-properties
1082 start (save-excursion
1084 (if (search-forward "=" end 'move) (forward-char -1))
1089 (defun ccide-implementation-template-args (state)
1091 (string-replace "[ \t\n\r]+" ""
1092 (loop for (start . end) in (save-excursion
1093 (goto-char (caar (last (aref state 0))))
1094 (c-parse-template-declaration))
1095 for sep = "" then ","
1097 concat (buffer-substring-no-properties
1098 start (save-excursion
1100 (if (search-forward "=" end 'move) (forward-char -1))
1104 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1105 ;; Within the current buffer, search for all implementations of the
1106 ;; given function. The rv is a list of conses. The car holds the
1107 ;; buffer position of the implementation, the cdr is t if the name,
1108 ;; scoped-name and args are matched, otherwise the args did not match.
1110 (goto-char (point-min))
1111 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1113 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1114 fallback rv check-state)
1115 (while (and (not rv) (re-search-forward re nil t))
1116 (if (c-save-buffer-state ()
1117 (and (c-at-toplevel-p)
1118 (not (c-in-literal))
1119 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1120 (not (= (car (aref check-state 2)) skip-def))))
1121 (if (string= scoped-name (c-defun-full-name check-state))
1122 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1123 (string= args (ccide-implementation-args check-state))
1124 (string= targs (ccide-implementation-template-args check-state)))
1125 (setq rv (cons (point) t))
1127 (setq fallback (cons (point) nil)))))))
1130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1131 ;; variable/type level
1133 (defun ccide-variable-comment ()
1134 "Add a comment to current variable declaration."
1136 (c-forward-out-of-comment)
1137 (c-forward-syntactic-ws)
1138 (while (not (looking-at ";"))
1140 (c-forward-syntactic-ws))
1142 (if (> (current-column) comment-column)
1143 (insert "\n" (make-string comment-column ? ) "///< ")
1144 (indent-to-column comment-column)
1147 (defun ccide-grab-access-fn ()
1151 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1152 (let ((vardef (match-string 0))
1153 (in (make-string c-basic-offset ? ))
1154 type reftype varname fnname argname ws)
1156 (back-to-indentation)
1157 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1159 (setq varname (match-string 2 vardef)
1160 type (match-string 1 vardef)
1161 ws (substring vardef 0 (match-beginning 1)))
1162 (if (string-match "_$" varname)
1163 (setq fnname (string-replace "_$" "" varname)
1164 argname (concat "a_" fnname))
1165 (setq fnname (concat "q_" varname)
1166 argname (concat "a_" varname)))
1167 (if (string-match "^[ \t\n\r]*" type)
1168 (setq type (substring type (match-end 0))))
1169 (if (string-match "^[A-Z]" type)
1170 (setq reftype (concat type " const &"))
1171 (setq reftype type))
1172 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1174 ws in in type " old" varname " = " varname ";\n"
1175 ws in in varname " = " argname ";\n"
1176 ws in in "return old" varname ";\n"
1178 ws reftype " " fnname "() const\n"
1179 ws in "{ return " varname "; }\n"))
1182 (message "No variable found"))))
1184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1185 ;; doxy comment support functions
1187 (defun ccide-special-indent-function ()
1188 "Function to indent doxy comments correctly"
1189 (let ((indent (ccide-in-doxy-comment)))
1191 (let ((lim (save-excursion
1192 (back-to-indentation)
1193 (c-literal-limits)))
1194 (pos (- (point-max) (point))))
1196 (back-to-indentation)
1197 (if (looking-at "*/")
1199 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1201 (if (and (not (looking-at ccide-doxy-tag-re))
1202 (re-search-backward (concat "^\\s-*"
1206 (delete-region (progn (beginning-of-line) (point))
1207 (progn (back-to-indentation) (point)))
1209 (if (> (- (point-max) pos) (point))
1210 (goto-char (- (point-max) pos)))))))
1212 (defun ccide-fill-function ()
1213 "auto-fill function for doxy comments"
1215 (if (not fill-prefix)
1216 (indent-according-to-mode))))
1218 (defun ccide-hide-all-doxy-comments ()
1219 "Hide all doxy comments"
1222 (goto-char (point-min))
1223 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1226 (if (not (looking-at "\\s-*$"))
1229 (let ((start (point)))
1230 (if (re-search-forward "\\*/" nil t)
1232 (if (looking-at "\\s-*\n")
1235 (let ((overlay (make-overlay start (point))))
1236 (overlay-put overlay 'intangible 'hs)
1237 (overlay-put overlay 'invisible 'hs)))))))
1240 (defun ccide-show-all-comments ()
1244 (goto-char (point-min))
1246 (goto-char (next-overlay-change (point)))
1247 (loop for overlay in (overlays-at (point))
1248 if (eq (overlay-get overlay 'invisible) 'hs)
1249 do (delete-overlay overlay))))
1252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1253 ;; CORBA support (omniORB2)
1255 (defun ccide-get-corba-headers ()
1258 (goto-char (point-min))
1259 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1260 (setq files (cons (ccide-match-string 1) files)))
1263 (defun ccide-corba-maybe-build-hh (file)
1264 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1265 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1266 (if (and (file-readable-p idl)
1267 (or (not (file-readable-p skel))
1268 (file-newer-than-file-p idl skel)))
1269 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1271 (kill-buffer buffer))
1272 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1273 (if (ccide-shell-command (concat "cd "
1274 (real-path-name ccide-corba-skel-dir)
1276 ccide-corba-idl-command
1277 (if (> (length ccide-corba-idl-dir) 0)
1278 (concat " -I" ccide-corba-idl-dir))
1282 (display-buffer (get-buffer-create "*ccide shell command*"))
1283 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1284 (if (not (file-readable-p skel))
1285 (error "No file %s or %s"
1286 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1288 (defun ccide-corba-list-skeletons-1 (hh-file)
1289 (ccide-corba-maybe-build-hh hh-file)
1290 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1295 (goto-char (point-min))
1296 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1298 (setq skels (cons (ccide-match-string 1) skels)))))
1299 (mapcar (function (lambda (x) (cons x hh-file)))
1300 (sort skels 'string-lessp))))
1302 (defun ccide-corba-list-skeletons ()
1303 (let ((files (ccide-get-corba-headers)))
1304 (loop for file in files
1305 append (ccide-corba-list-skeletons-1 file))))
1307 (defun ccide-gen-corba-impl (class)
1308 (interactive (list (completing-read "Class name of skeleton: "
1309 (ccide-corba-list-skeletons)
1311 (let* ((skels (ccide-corba-list-skeletons))
1312 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1313 ccide-corba-skel-dir))
1314 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1315 ccide-corba-skel-dir))))
1316 (ccide-gen-class (concat class "_i"))
1317 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1319 (search-forward "protected:" nil t)
1321 (ccide-gen-corba-impl-methods)
1324 (defun ccide-get-corba-defns (hh-file class)
1325 (let ((hh-buf (find-file-noselect hh-file))
1330 (goto-char (point-min))
1331 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1333 (error "CORBA skeleton class not found.")
1334 (search-forward "{")
1336 (let ((end (save-excursion (forward-sexp) (point))))
1337 (while (and (< (point) end)
1338 (< (forward-line 1) 1))
1339 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1340 (setq defns (cons (match-string 1) defns))))))))
1343 (defun ccide-gen-corba-impl-methods ()
1345 (let* ((class (c-get-class-at-point))
1348 (error "No class at point."))
1350 (goto-char (aref (car class) 1))
1351 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1353 (error "No CORBA impl at point."))
1354 (let* ((name (ccide-match-string 1))
1355 (skels (ccide-corba-list-skeletons))
1356 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1357 ccide-corba-skel-dir))
1358 (defns (ccide-get-corba-defns hh-file name))
1360 (goto-char (aref (car class) 2))
1364 (if (re-search-forward "^\\s-*// CORBA$" end t)
1365 (let ((start (match-beginning 0)))
1366 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1367 (let ((eend (match-end 0)))
1370 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1371 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1372 (delete-region start (1+ eend))
1375 (delete-region (point) (progn
1380 (delete-region (point) (progn
1384 (delete-region start (1+ eend))))))
1386 (indent-according-to-mode)
1387 (insert "// CORBA\n")
1388 (loop for defn in defns
1390 (save-excursion (insert defn ";"))
1391 (indent-according-to-mode)
1392 (let ((start (point)) end)
1396 (while (re-search-forward "\\s-+" end t)
1398 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1400 (loop with done = nil
1401 while (> (current-column) c-max-def-column)
1402 do (while (and (> (current-column) c-max-def-column)
1403 (search-backward "," start t)))
1404 do (if (looking-at ",")
1409 (indent-according-to-mode)
1411 (setq start (point))
1416 (indent-according-to-mode)
1417 (insert "// END-CORBA\n")))))
1419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1422 (defun ccide-scan-mantemps ()
1423 "Scan *compilation* buffer for errors and generate manual template
1424 instatiations at point."
1427 (set-buffer "*compilation*")
1428 (goto-char (point-min)))
1430 (set-buffer (get-buffer-create "*mantemps*"))
1432 (loop for temp = (ccide-get-mantemp)
1434 do (insert temp "\n"))
1435 (mantemp-make-mantemps-buffer)
1436 (goto-char (point-min))
1439 (< (forward-line 1) 1))))
1440 (insert-buffer-substring "*mantemps*"))
1442 (defun ccide-get-mantemp ()
1444 (set-buffer "*compilation*")
1445 (if (search-forward "undefined reference to `" nil t)
1446 (let ((start (point)))
1448 (search-backward "'" nil t)
1449 (buffer-substring start (point))))))
1451 (defun ccide-fix-mantemp ()
1452 (let ((end (save-excursion
1453 (end-of-line) (point))))
1454 (if (and (save-excursion (search-forward "(" end t))
1455 (search-forward " class" end t))
1462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1465 (defun ccide-open-compilation-frame ()
1467 (let ((c-frame (selected-frame))
1468 (compilation-frame (make-frame '((minibuffer . nil)
1470 (menu-bar-lines . 0)
1475 (select-frame compilation-frame)
1476 (switch-to-buffer "*compilation*")
1477 (set-window-dedicated-p (selected-window) t)))
1479 (defun ccide-compile (command)
1480 (delete-other-windows)
1481 (split-window-horizontally)
1484 (set-buffer "*compilation*")
1485 (let ((point (point-max)))
1487 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1488 do (set-window-point window point)))))
1490 (defun ccide-compile-compile ()
1492 (ccide-compile (concat "make -k " ccide-compile-opts)))
1494 (defun ccide-compile-clean ()
1496 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1498 (defun ccide-compile-cleandepends ()
1500 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1502 (defun ccide-compile-kill ()
1504 (set-buffer "*compilation*")
1507 (defun ccide-hide-compilation ()
1509 (let ((active (selected-window)))
1511 (loop for window in (get-buffer-window-list "*compilation*")
1512 do (progn (select-window window)
1513 (switch-to-buffer (other-buffer "*compilation*"))))
1514 (select-window active))))
1516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1517 ;; keymap and installation
1519 (defun ccide-bind-keys (prefix map)
1520 (loop for binding in ccide-bindings
1521 do (apply 'vcmd-define-key
1523 (concat prefix (car binding))
1528 (defun ccide-install-it ()
1532 (local-unset-key "\C-c;")
1533 (local-unset-key [menu-bar IDE])
1534 (ccide-bind-keys "\C-c;" (current-local-map))
1535 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1536 (local-set-key "\C-cS" 'ccide-show-all-comments)
1537 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1538 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1539 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1541 (ccide-project-load-config)
1542 (ccide-directory-load-config)
1543 (ccide-auto-decorate-new-files))
1545 (defun ccide-project-load-config ()
1546 (if (buffer-file-name)
1547 (let ((conf (ccide-project-search-upwards '(".project.el" "project.el")
1548 (file-name-directory (buffer-file-name)))))
1550 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1551 (load-file conf)))))
1553 (defun ccide-project-search-upwards (names &optional base)
1554 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1555 DIR defaults to ccide-project-root. If FILE is a list, search for any file in list."
1556 (if (not (consp names))
1557 (setq names (list names)))
1558 (loop for dir = (or base ccide-project-root) then (directory-file-name (file-name-directory dir))
1559 while (not (string= dir "/"))
1560 thereis (loop for name in names
1561 for path = (expand-file-name name dir)
1562 thereis (and (file-readable-p path) path))))
1564 (defun ccide-directory-load-config ()
1565 (if (file-readable-p ".dir.el")
1566 (load-file ".dir.el")))
1568 (add-hook 'c-mode-hook 'ccide-install-it)
1569 (add-hook 'c++-mode-hook 'ccide-install-it)
1570 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1572 (loop for extension in ccide-special-extensions
1573 for re = (concat (regexp-quote extension) "$")
1574 if (not (assoc re auto-mode-alist))
1575 do (setq auto-mode-alist (append auto-mode-alist
1576 (list (cons re 'c++-mode)))))
1578 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1579 ;; new indent function for c-mode: do standard indentation first. If line
1580 ;; is to long using standard indentation, just indent by c-basic-indentation.
1581 (let ((cc (save-excursion (end-of-line) (current-column)))
1584 (let ((pos (- (point-max) (point))))
1586 (let ((point (point))
1587 (line (1+ (count-lines 1 (point))))
1589 (c-beginning-of-statement-2)
1590 (if (and (not (c-crosses-statement-barrier-p (point) point))
1591 (not (eq (+ (count-lines 1 (point))
1595 (setq indent (+ (current-indentation) c-basic-offset))
1597 (if (< indent (current-indentation))
1599 (setq ad-return-value
1601 (- (current-indentation) indent)))
1602 (delete-region (c-point 'bol) (c-point 'boi))
1603 (indent-to indent))))))
1604 (if (< (point) (c-point 'boi))
1605 (back-to-indentation)
1606 (if (> (- (point-max) pos) (point))
1607 (goto-char (- (point-max) pos))))))))
1611 ;;; Local Variables:
1612 ;;; elisp-project-autoload-file-name: "cc-autoload.el"