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 (defvar ccide-new-file-command nil)
60 (defvar ccide-format-command nil)
62 (defconst c-user-prefix-re (regexp-opt c-user-prefixes t))
64 (defconst ccide-doxy-tag-re
65 (concat "\\\\\\(group\\|defgroup\\|see\\|author\\|version\\|id\\|since"
66 "\\|returns?\\|throws?\\|exception\\|raises\\|param\\|li\\|brief"
67 "\\|internal\\|bug\\|fixme\\|todo\\|idea\\|implementation"
68 "\\|note\\|attention\\|warning\\|par\\|code\\|endcode"
69 "\\|post\\|pre\\|deprecated\\)\\b"))
71 (defconst ccide-special-extensions
72 '(".h" ".hh" ".mpp" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci" ".dox"))
74 (defconst ccide-implementation-extensions
75 '(".h" ".hh" ".ih" ".cc" ".cpp" ".ct" ".cti" ".cci"))
77 (defconst ccide-class-defaults-word
78 "// \\(default\\|no\\|protected\\|private\\|disabled\\|my\\)")
80 (defconst ccide-bindings
83 ("fc" ccide-file-comment "File comment")
84 ("fs" ccide-syncronize-includes "Sync includes")
88 ("cc" ccide-class-comment "Class comment")
89 ("cg" ccide-gen-class "Generate class")
90 ("cd" ccide-gen-class-defaults "Generate class defaults")
91 ("cD" ccide-gen-class-defaults-impl "Generate class defaults impl")
93 ("csd" ccide-set-class-defaults-default "Set class defaults comment" "Default")
94 ("csn" ccide-set-class-defaults-no "Set class defaults comment" "No")
95 ("csp" ccide-set-class-defaults-protected "Set class defaults comment" "Protected")
96 ("csr" ccide-set-class-defaults-private "Set class defaults comment" "Private")
97 ("csx" ccide-set-class-defaults-disabled "Set class defaults comment" "Disabled")
98 ("csm" ccide-set-class-defaults-my "Set class defaults comment" "My")
100 ("cS" ccide-gen-struct-constructors "Generate structure constructors")
101 ("c<" ccide-gen-struct-compare "Generate structure compare operators")
103 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
105 ("ce" ccide-gen-exception "Generate an exception class")
110 ("mc" ccide-function-comment "Method comment")
111 ("mp" ccide-grab-prototype "Grab prototype")
112 ("mr" ccide-reformat-defun "Reformat defun")
113 ("mx" ccide-replace-defun "Replace defun")
114 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
115 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
116 ("mi" ccide-grab-inline-decl "Grab inline decl")
117 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
118 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
119 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
120 ("mf" ccide-find-implementation "Find method implementation")
121 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
125 ("vc" ccide-variable-comment "Variable comment")
126 ("vf" ccide-grab-access-fn "Grab access methods")
130 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
131 ("s" ccide-show-all-comments "Show all Doxygen comments")
134 ("yp" ccide-grab-pxd-fn "Generate pxd function/method decl")
137 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
138 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
139 ; (nil nil separator)
142 ; ("ts" ccide-scan-mantemps "Scan mantemps")
143 ; (nil nil separator)
146 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
147 ; ("oc" ccide-compile-compile "Make -> Compile")
148 ; ("ox" ccide-compile-clean "Make -> Clean")
149 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
150 ; ("ok" ccide-compile-kill "Kill compilation")
151 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
157 (require 'cc-engine-2)
166 (require 'misc-local)
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
171 (defsubst ccide-match-string (n)
172 (buffer-substring-no-properties (match-beginning n) (match-end n)))
174 (defun ccide-file-macro-name (&optional file-name)
175 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
177 (if ccide-project-name (concat ccide-project-name "_") "")
178 (if ccide-project-root
179 (string-replace "/" "_"
180 (substring (file-name-directory
181 (expand-file-name (or file-name buffer-file-name)))
182 (length ccide-project-root))
185 (string-replace "\\." "_" (file-name-sans-extension
186 (file-name-nondirectory
187 (or file-name (buffer-file-name))))
191 (defun ccide-file-name (&optional extension file-name directory)
192 (concat (if directory (file-name-as-directory directory) "")
193 (file-name-sans-extension
194 (file-name-nondirectory
195 (or file-name (buffer-file-name))))
198 (defun ccide-in-doxy-comment ()
200 (back-to-indentation)
201 (let ((lit (c-in-literal)))
202 (when (and (memq lit '(c c++))
203 (progn (goto-char (car (c-literal-limits)))
204 (looking-at "/\\(\\*\\*\\|///\\)<?[ \t\n\r@]")))
205 (goto-char (match-end 0))
208 (defun ccide-shell-command (command)
209 (let ((obuf (get-buffer-create "*ccide shell command*"))
214 (insert command "\n"))
215 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
216 shell-command-switch command))
217 (and exit-status (equal exit-status 0))))
219 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 (defun ccide-file-comment ()
223 "Add a comment to this source file."
228 (goto-char (point-min))
231 "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
232 " " ccide-default-author "\n"
233 ccide-default-copyright
236 (cond ((string-match "\\.hh?$" (buffer-file-name))
237 (insert "/** \\file\n"
238 " \\brief " (ccide-file-name) " public header */\n\n"
239 "#ifndef " (ccide-file-macro-name) "\n"
240 "#define " (ccide-file-macro-name) " 1\n\n")
241 (if ccide-all-includes
242 (insert "#ifndef " (ccide-file-macro-name ccide-all-includes) "\n"
243 "#error \"Don't include '" (file-name-nondirectory (buffer-file-name)) "'"
244 " directly, include '" ccide-all-includes "'\"\n"
246 (insert "// Custom includes\n\n"
247 "//#include \"" (ccide-file-name ".mpp") "\"\n"
248 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
250 (goto-char (point-max))
251 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n")
252 (if ccide-all-includes
254 "#if !defined(" (ccide-file-macro-name ccide-all-includes) "_decls_) "
255 "&& !defined(" (ccide-file-macro-name) "i_)\n"
256 "#define " (ccide-file-macro-name) "i_\n"))
257 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
258 "//#include \"" (ccide-file-name ".ct") "\"\n"
259 "//#include \"" (ccide-file-name ".cti") "\"\n"
262 ((string-match "\\.mpp$" (buffer-file-name))
263 (insert "/** \\file\n"
264 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
267 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
268 "#define " (ccide-file-macro-name) " 1\n\n"
269 "// Custom includes\n\n\n"
270 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
271 "#elif BOOST_PP_IS_ITERATING //-/////////////////////////////////////////////////////////////////////\n"
272 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
273 "// Local Macros\n\n\n"
274 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
275 "#if BOOST_PP_ITERATION_FLAGS()==1 //-///////////////////////////////////////////////////////////////\n"
276 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
278 (goto-char (point-max))
279 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
280 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
281 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
282 "// Undefine local Macros\n\n\n"
283 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
284 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
285 "//-/////////////////////////////////////////////////////////////////////////////////////////////////"))
287 ((string-match "\\.ih$" (buffer-file-name))
288 (insert "/** \\file\n"
289 " \\brief " (ccide-file-name) " internal header */\n\n"
290 "#ifndef " (ccide-file-macro-name) "\n"
291 "#define " (ccide-file-macro-name) " 1\n\n"
292 "// Custom includes\n\n"
293 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
295 (goto-char (point-max))
296 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
299 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
300 (string-match "\\.test\\.cpp$" (buffer-file-name)))
301 (insert "/** \\file\n"
302 " \\brief " (ccide-file-name) " unit tests */\n\n"
303 "//#include \"" (ccide-file-name ".hh") "\"\n"
304 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
305 "// Custom includes\n"
306 "#include \"" (or ccide-all-includes
307 (ccide-file-name ".hh" (ccide-file-name))) "\"\n\n"
308 "#include <boost/test/auto_unit_test.hpp>\n"
309 "#include <boost/test/test_tools.hpp>\n\n"
311 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
313 (goto-char (point-max))
314 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
317 ((or (string-match "\\.cc$" (buffer-file-name))
318 (string-match "\\.cpp$" (buffer-file-name)))
319 (insert "/** \\file\n"
320 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
321 (if ccide-all-includes "" "//")
322 "#include \"" (or ccide-all-includes (ccide-file-name ".hh")) "\"\n"
323 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
324 "// Custom includes\n\n"
325 "//#include \"" (ccide-file-name ".mpp") "\"\n"
327 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
329 (goto-char (point-max))
330 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
332 "//#include \"" (ccide-file-name ".mpp") "\""))
334 ((string-match "\\.cci$" (buffer-file-name))
335 (insert "/** \\file\n"
336 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
337 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
338 "// Custom includes\n\n"
339 "#define prefix_ inline\n"
340 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
342 (goto-char (point-max))
343 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
346 ((string-match "\\.ct$" (buffer-file-name))
347 (insert "/** \\file\n"
348 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
349 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
350 "// Custom includes\n\n"
352 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
354 (goto-char (point-max))
355 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
358 ((string-match "\\.cti$" (buffer-file-name))
359 (insert "/** \\file\n"
360 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
361 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
362 "// Custom includes\n\n"
363 "#define prefix_ inline\n"
364 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
366 (goto-char (point-max))
367 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
370 ((string-match "\\.dox$" (buffer-file-name))
371 (insert "/** \\mainpage\n\n ")
374 (setq add-file-vars '(( mode . flyspell)
375 ( mode . auto-fill))))
377 ((string-match "\\.java$" (buffer-file-name))
380 (goto-char (point-max)))
384 (goto-char (point-max))))
387 "// Local Variables:\n"
388 "// mode: " mode "\n")
389 (loop for (var . value) in ccide-file-vars
390 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
391 (loop for (var . value) in add-file-vars
392 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
396 (if (equal mode "jde")
397 (let ((package (file-name-directory (buffer-file-name))))
398 (jdeap-initialize-setup)
399 (if (not (equal jdeap-current-source-directory "."))
401 (concat "^" (regexp-quote jdeap-current-source-directory))
404 (setq package (substring package
406 (1- (length package))))
408 (string-replace "/" "." package t)
410 (insert "class " (file-name-sans-extension
411 (file-name-nondirectory
412 (buffer-file-name))) "\n{}")
413 (beginning-of-line))))
414 (run-hooks 'ccide-new-file-hooks))
416 (defun ccide-sync-file-variables ()
417 "Syncronize file variables to the current value of ccide-file-vars"
420 (goto-char (point-max))
421 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
422 (let ((case-fold-search t))
423 (if (search-forward "Local Variables:" nil t)
424 (let (prefix suffix vars)
425 (skip-chars-forward " \t")
427 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
428 (goto-char (match-beginning 0))
430 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
433 (if (and prefix (looking-at prefix))
434 (goto-char (match-end 0)))
435 (skip-chars-forward " \t"))
436 while (not (looking-at "end:"))
438 (setq vars (cons (intern (buffer-substring
440 (progn (skip-chars-forward "^:\n") (point))))
443 (loop for (var . value) in ccide-file-vars
444 do (if (not (memq var vars))
445 (insert (or prefix "")
446 (symbol-name var) ": " (prin1-to-string value)
447 (or suffix "") "\n"))))))))
449 (defun ccide-syncronize-includes ()
450 "Syncronize include's in all other files"
453 (loop for extension in ccide-special-extensions
454 for file-name = (ccide-file-name extension)
456 (cons (cons file-name
457 (or (find-buffer-visiting file-name)
458 (and (file-readable-p file-name)
459 (find-file-noselect file-name))))
462 (loop for buffer in buffer-map
465 (set-buffer (cdr buffer))
467 (loop for include in buffer-map
469 (goto-char (point-min))
470 (while (re-search-forward
471 (concat "^\\(//\\)?#\\s-*include \""
472 (regexp-quote (car include))
475 (goto-char (match-beginning 0))
476 (if (looking-at "//")
479 (if (not (cdr include))
481 (forward-line 1))))))))))
483 (defun ccide-auto-decorate-new-files ()
484 (if (and (buffer-file-name) (= (point-min) (point-max)))
485 (if (or (not ccide-new-file-command)
490 (shell-command (format "%s %s" ccide-new-file-command (buffer-file-name)))
491 (revert-buffer t t t)
494 (let ((status (buffer-modified-p)))
496 (set-buffer-modified-p status)))))
498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
501 (defun ccide-class-comment ()
502 "Add comment to start of current class definition"
504 (let ((class (c-get-class-at-point)))
506 (error "No class found")
507 (goto-char (or (aref (car class) 3)
508 (aref (car class) 1)))
511 (ccide-in-doxy-comment))
513 (search-backward "/**" nil t)
515 (let ((indent (make-string (current-indentation) ? )))
516 (insert "/** \\brief ")
522 (defun ccide-gen-class (name &optional defns)
523 "Generate class declaration template"
524 (interactive (list (read-string (concat "Class name (default "
527 nil nil (ccide-file-name))))
528 (insert "class " name)
529 (indent-according-to-mode)
530 (let ((in (make-string c-basic-offset ? ))
531 (ofs (make-string (current-indentation) ? ))
532 (sl (make-string (- 100 3 c-basic-offset (current-indentation)) ?/)))
536 (insert ofs "/** \\brief\n"
543 ofs in "// Types\n\n"
545 ofs in "///\\name Structors and default members\n"
547 ofs in "// default default constructor\n"
548 ofs in "// default copy constructor\n"
549 ofs in "// default copy assignment\n"
550 ofs in "// default destructor\n\n"
551 ofs in "// no conversion constructors\n\n"
554 ofs in "///\\name Accessors\n"
558 ofs in "///\\name Mutators\n"
561 (loop for defn in defns
562 do (insert ofs in defn ";\n"))
565 (insert ofs "protected:\n\n"
569 (defun ccide-gen-class-defaults ()
570 "Generate signatures of the default functions: default constructor,
571 copy constructor, assignment operator and destructor."
572 (indent-according-to-mode)
573 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
574 (in (make-string c-basic-offset ? ))
575 (ofs (make-string (current-indentation) ? ))
576 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
578 (while (string-match "::" name colon)
579 (setq colon (match-end 0)))
580 (setq name (substring name colon))
582 (delete-horizontal-space)
583 (loop with exit = nil
584 do (message (concat "1-dflt constr, 2-destr, "
585 "3-copy constr, 4-copy assmnt, "
586 "c-all copy, d-all dflt, RET-all/done: "))
587 for ch = (read-event)
588 for first = t then nil
589 do (cond ((eq ch 'return)
591 (insert ofs name "()"
593 ofs name "(const " name "& other)"
596 ofs name "& operator=(const " name "& other)"
600 (insert ofs name "()"
603 (insert ofs "~" name "();\n"))
605 (insert ofs name "(const " name "& other)"
608 (insert ofs name "& operator=(const " name "& other)"
611 (insert ofs name "(const " name "& other)"
613 ofs name "& operator=(const " name "& other)"
616 (insert ofs name "()"
618 ofs "~" name "();\n"))
619 (t (setq unread-command-events (cons ch unread-command-events))
623 (defun ccide-gen-class-defaults-impl ()
624 "Generate default implementations for class default functions"
626 (let ((defn (c-build-default-funcions-impl)))
627 (kill-new (cadr defn))
628 (message (concat (car defn) " default members"))))
630 (defun ccide-set-class-defaults-comment (word)
632 (back-to-indentation)
633 (if (not (looking-at ccide-class-defaults-word))
634 (message "Not at class defaults commnet")
635 (replace-match word t t nil 1))))
637 (defmacro ccide-build-class-defaults-f (sym)
638 (let ((fn (intern (concat "ccide-set-class-defaults-"
639 (symbol-name sym)))))
642 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
644 (ccide-build-class-defaults-f no)
645 (ccide-build-class-defaults-f default)
646 (ccide-build-class-defaults-f my)
647 (ccide-build-class-defaults-f protected)
648 (ccide-build-class-defaults-f private)
649 (ccide-build-class-defaults-f disabled)
651 (defun ccide-gen-struct-constructors ()
656 (indent-according-to-mode)
657 (let* ((scope (c-get-block-scope))
658 (class (c-parse-class scope))
659 (variables (c-get-variable-members-with-type class))
660 (name (c-scope-name (aref (car (last scope)) 1)))
661 (in (make-string (current-indentation) ? ))
662 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
663 (insert name "()\n" inin ": ")
664 (loop for var in variables
665 for first = t then nil
666 if (not first) do (insert ", ")
667 do (insert (car var) " ()"))
670 (loop for var in variables
671 for first = t then nil
672 if (not first) do (insert ", ")
673 do (insert (cdr var) " " (car var) "_"))
674 (insert ")\n" inin ": ")
675 (loop for var in variables
676 for first = t then nil
677 if (not first) do (insert ", ")
678 do (insert (car var) " (" (car var) "_)"))
682 (defun ccide-gen-struct-compare ()
687 (indent-according-to-mode)
688 (let* ((scope (c-get-block-scope))
689 (class (c-parse-class scope))
690 (variables (c-get-variable-members-with-type class))
691 (name (c-scope-name (aref (car (last scope)) 1)))
692 (in (make-string (current-indentation) ? ))
693 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
695 (insert "bool operator<(" name " const & other) const\n"
697 (loop for ((varName . varType) . tail) on variables
698 do (insert inin varName " < other." varName " ? true :")
700 (insert "\n" inin "other." varName " < " varName " ? false :\n")
701 (insert " false; }\n\n")))
702 (insert in "bool operator==(" name " const & other) const\n"
704 (loop for ((varName . varType) . tail) on variables
705 do (insert inin varName " == other." varName)
706 do (if tail (insert " &&\n") (insert "; }\n\n")))
707 (insert in "std::size_type hash_value() const\n"
708 in "{ std::size_t current (0);\n")
709 (loop for ((varName . varType) . tail) on variables
710 do (insert inin "boost::hash_combine(current, " varName ");\n"))
711 (insert inin "return current; }\n\n")
712 (insert in "void write(std::ostream & os) const\n"
714 (loop for ((varName . varType) . tail) on variables
715 do (insert "\n" inin "<< " varName)
716 do (if tail (insert " << ' '")))
717 (insert " << \" }\"; }\n"))))
719 (defun ccide-class-impl-comment ()
720 "Get implementation comment for current class"
722 (let* ((scope (c-get-block-scope))
723 (name (c-get-full-prefix scope)))
724 (kill-new (concat (make-string 75 ?/) "\n"
730 (defun ccide-gen-exception (class &optional description)
731 (interactive "sException name: \nsDescription (defaults to full class name): ")
734 (indent-according-to-mode)
736 (let ((in (make-string c-basic-offset ? ))
737 (ofs (make-string (current-indentation) ? ))
738 (prefix (c-get-full-prefix (c-get-block-scope)))
740 (insert "struct " class " : public std::exception\n"
741 ofs "{ virtual char const * what() const throw() ")
743 (insert "{ return \""
744 (if (and description (> (length description) 0))
746 (concat prefix "::" class))
748 (if (> (current-column) fill-column)
751 (insert "\n" ofs in in))))))
753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
754 ;; function/method level
756 (defun ccide-function-comment ()
757 "Add comment for current function"
759 (if (memq (c-in-literal) '(c c++))
760 ; Assume, we are in the functions comment ...
762 (c-forward-out-of-comment)
763 (c-backward-syntactic-ws)
766 (c-beginning-of-defun-or-decl)
767 (let ((defun (c-get-defun-state))
768 (indent (make-string comment-column ? ))
770 (goto-char (or (aref defun 7) (car (aref defun 6))))
771 (c-backward-syntactic-ws)
772 (if (looking-at "[ \t\n\r]*///<")
774 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
775 (if (> (current-column) comment-column)
777 (indent-to-column comment-column)
778 (search-forward "*/")
780 (if (> (current-column) comment-column)
782 (indent-to-column comment-column)
790 (goto-char (car (aref defun 2)))
791 (setq defun (c-get-defun-state)))
793 (ccide-function-comment-adjust defun (concat indent " "))
794 (if place (goto-char place))))
796 (defun ccide-function-comment-grab-args ()
797 (let ((limit (save-excursion
798 (search-backward "/**" nil t)
801 begin start args argend)
803 (while (or (search-backward "\\param" limit t)
804 (search-backward "\\return" limit t)))
808 (while (search-forward "\\param" argend t)
809 (or (search-forward "\\param" argend t)
810 (search-forward "\\return" argend t)
813 (setq args (cons (ccide-function-comment-parse-arg start (point))
815 (setq start (point)))
817 (if (not (search-forward "\return" argend t))
820 (cons (buffer-substring (point) argend) args))
821 (delete-region begin end))))
823 (defun ccide-function-comment-parse-arg (start end)
826 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
827 (cons (match-string 2)
828 (cons (buffer-substring start (match-beginning 2))
829 (buffer-substring (match-end 2) end)))))
831 (defun ccide-function-comment-get-throws (defun)
834 (goto-char (car (aref defun 4)))
835 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
836 (cdr (aref defun 4)) t)
837 (let ((spec (match-string 2)))
838 (if (> (length spec) 0)
841 (defun ccide-function-comment-adjust (defun indent)
843 (let* ((defargs (mapcar (function (lambda (x)
844 (c-get-template-argument-name (car x) (cdr x))))
846 (defret (and (aref defun 1)
847 (not (string-match (concat "^\\("
849 "\\s-*\\)*\\s-*void$")
850 (buffer-substring (car (aref defun 1))
851 (cdr (aref defun 1)))))))
852 (throws (ccide-function-comment-get-throws defun))
853 (xargs (ccide-function-comment-grab-args))
854 (docargs (cdr xargs))
856 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
857 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
858 (size-eq (= (length defargs) (length docargs))))
859 ;; We differentiate four types changes
861 ;; - removed arguments
862 ;; - reordered arguments
863 ;; - renamed arguments
865 ;; If the change cannot be described by one of the above, it has
866 ;; to be resolved manually
868 (insert indent "\\throws " throws "\n"))
870 ;; reordered arguments or new arguments (or no change)
871 (loop for defarg in defargs
872 for docarg = (assoc defarg docargs)
874 (insert (cadr docarg) (car docarg) (cddr docarg))
875 (insert indent "\\param " defarg " \n"))))
876 (size-eq ; and (not doc-in-def)
878 (loop for defarg in defargs
879 for docarg in docargs
880 do (insert (cadr docarg) defarg (cddr docarg))))
883 (loop for defarg in defargs
884 for docarg = (assoc defarg docargs)
885 do (insert (cadr docarg) (car docarg) (cddr docarg))))
886 (t (error "Arg change too complex. Resolve manualy.")))
887 ;; return value is simple
891 (insert indent "\\return \n"))))
893 (delete-horizontal-space)
896 (defun ccide-grab-prototype (&optional prefix)
897 "Grab prototype of function defined or declared at point. Prefix
898 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
901 (c-beginning-of-defun-or-decl)
902 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
903 ccide-default-prefix))
904 (defn (c-build-defun prfx)))
905 (kill-new (concat (cadr defn) "\n{}\n"))
906 (message (concat (or prfx "")
910 (defun ccide-reformat-defun ()
911 "Reformat the defn of the current defun."
914 (c-beginning-of-defun-or-decl)
915 (let ((defn (c-build-defun nil t)))
916 (delete-region (or (caar (aref (caddr defn) 0))
917 (car (aref (caddr defn) 1))
918 (car (aref (caddr defn) 2)))
919 (or (car (aref (caddr defn) 6))
920 (aref (caddr defn) 7)))
921 (insert (cadr defn) "\n"))))
923 (defun ccide-replace-defun ()
924 "Replace the function header with the one on the top of the kill
925 ring (presumably placed there using c++-grab-prototype)."
928 (c-beginning-of-defun-or-decl)
929 (let ((parse (c-parse-defun)))
930 (delete-region (or (aref parse 0)
939 (defun ccide-prefix-defun-type-with-class (&optional strip)
940 "If a non-keyword type symbol is found prefixing the current defun,
941 it will be prefixed with the current class prefix."
944 (c-beginning-of-defun-or-decl)
945 (let* ((parse (c-parse-defun))
946 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
947 (goto-char (aref parse 1))
948 (while (and (or (looking-at c-any-key)
949 (looking-at c-user-prefix-re)
950 (not (c-at-symbol-p)))
951 (< (point) (aref parse 2))
954 (c-forward-syntactic-ws))
955 (if (and (c-at-symbol-p)
956 (< (point) (aref parse 2))
957 (not (looking-at (regexp-quote prefix))))
958 (let ((pos (string-match "<" prefix)))
960 (insert "typename "))
961 (if (and pos (looking-at (concat (substring prefix 0 pos)
964 (goto-char (match-end 0))
965 (c-backward-syntactic-ws)
966 (insert (substring prefix pos)))
967 (insert prefix "::"))
968 (ccide-reformat-defun))))))
970 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
972 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
974 (defun ccide-insert-defun-prefix (&optional strip)
975 "Insert the current defun prefix at point."
977 (let* ((parse (c-parse-defun))
978 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
979 (insert prefix "::")))
981 (defun ccide-kill-inline-decl (defn)
983 (if (aref (caddr defn) 6)
985 (goto-char (cdr (aref (caddr defn) 6)))
986 (let ((end-mark (point-marker)))
987 (goto-char (car (aref (caddr defn) 6)))
988 (indent-rigidly (point) end-mark
989 (- (current-column)))
993 (buffer-substring-no-properties (point) end-mark)
995 (when (aref (caddr defn) 5)
996 (goto-char (caar (aref (caddr defn) 5)))
997 (c-backward-syntactic-ws)
998 (skip-chars-backward ":"))
999 (c-backward-syntactic-ws)
1000 (delete-region (point) end-mark)
1002 (concat (cadr defn) "\n{}\n"))))
1004 (defun ccide-grab-inline-decl ()
1005 "Grab the inline decl at point at turn it into an out-of-line inline
1006 declaration at the top of the kill ring."
1008 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
1009 (kill-new (ccide-kill-inline-decl defn))
1010 (message (concat (or ccide-default-prefix "indline")
1014 (defun ccide-grab-all-inlines ()
1015 "Grab all inline decls in the current class"
1017 (let ((class (c-parse-class (c-get-block-scope)))
1020 (loop for method in (nreverse (aref class 4))
1021 do (when (eq (car method) 'method)
1022 (let ((defn (save-excursion
1023 (goto-char (cdr method))
1024 (c-build-defun (or ccide-default-prefix "inline")))))
1025 (if (aref (caddr defn) 6)
1026 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
1027 (setq defns (nreverse defns))
1028 (kill-new (loop for defn in defns
1029 for next = nil then t
1030 if next concat "\n";
1032 (message (format "%d inlines grabed to kill ring" (length defns))))))
1034 (defun ccide-grab-create-constructor ()
1036 (let ((defn (c-build-create-constructor)))
1037 (kill-new (cadr defn))
1038 (message (car defn))))
1040 (defun ccide-grab-create-constructor-impl (&optional prefix)
1042 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
1043 ccide-default-prefix))
1044 (defn (c-build-create-constructor-impl prfx)))
1045 (kill-new (cadr defn))
1046 (message (concat (or prfx "")
1050 (defun ccide-find-implementation (&optional other-window)
1051 "Find implementation of method declared at point."
1053 (let* ((state (c-get-defun-state))
1054 (name (c-defun-short-name state))
1055 (scoped-name (c-defun-full-name state))
1056 (args (ccide-implementation-args state))
1057 (targs (ccide-implementation-template-args state))
1060 (loop for ext in ccide-implementation-extensions
1061 for filename = (ccide-file-name ext)
1064 (let ((buf (or (find-buffer-visiting filename)
1065 (and (file-readable-p filename)
1066 (find-file-noselect filename)))))
1068 (let ((found (save-excursion
1070 (ccide-find-implementation-1 name scoped-name args targs
1071 (not (aref state 6))
1072 (car (aref state 2))))))
1075 (setq rv (cons buf found))
1076 (if (not fallback) (setq fallback (cons buf found))))))))))
1077 (if (not rv) (setq rv fallback))
1079 (let* ((buf (car rv))
1081 (win (get-buffer-window buf)))
1085 (switch-to-buffer-other-window buf)
1086 (switch-to-buffer buf)))
1089 (c-beginning-of-defun-or-decl))
1090 (message (concat "Implementation of " scoped-name " not found.")))))
1092 (defun ccide-implementation-args (state)
1093 (string-replace "[ \t\n\r]+" ""
1094 (loop for (start . end) in (aref state 3)
1095 for sep = "" then ","
1097 concat (buffer-substring-no-properties
1098 start (save-excursion
1100 (if (search-forward "=" end 'move) (forward-char -1))
1105 (defun ccide-implementation-template-args (state)
1107 (string-replace "[ \t\n\r]+" ""
1108 (loop for (start . end) in (save-excursion
1109 (goto-char (caar (last (aref state 0))))
1110 (c-parse-template-declaration))
1111 for sep = "" then ","
1113 concat (buffer-substring-no-properties
1114 start (save-excursion
1116 (if (search-forward "=" end 'move) (forward-char -1))
1120 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1121 ;; Within the current buffer, search for all implementations of the
1122 ;; given function. The rv is a list of conses. The car holds the
1123 ;; buffer position of the implementation, the cdr is t if the name,
1124 ;; scoped-name and args are matched, otherwise the args did not match.
1126 (goto-char (point-min))
1127 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1129 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1130 fallback rv check-state)
1131 (while (and (not rv) (re-search-forward re nil t))
1132 (if (c-save-buffer-state ()
1133 (and (c-at-toplevel-p)
1134 (not (c-in-literal))
1135 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1136 (not (= (car (aref check-state 2)) skip-def))))
1137 (if (string= scoped-name (c-defun-full-name check-state))
1138 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1139 (string= args (ccide-implementation-args check-state))
1140 (string= targs (ccide-implementation-template-args check-state)))
1141 (setq rv (cons (point) t))
1143 (setq fallback (cons (point) nil)))))))
1146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1147 ;; variable/type level
1149 (defun ccide-variable-comment ()
1150 "Add a comment to current variable declaration."
1152 (c-forward-out-of-comment)
1153 (c-forward-syntactic-ws)
1154 (while (not (looking-at ";"))
1156 (c-forward-syntactic-ws))
1158 (if (> (current-column) comment-column)
1159 (insert "\n" (make-string comment-column ? ) "///< ")
1160 (indent-to-column comment-column)
1163 (defun ccide-grab-access-fn ()
1167 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1168 (let ((vardef (match-string 0))
1169 (in (make-string c-basic-offset ? ))
1170 type reftype varname fnname argname ws)
1172 (back-to-indentation)
1173 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1175 (setq varname (match-string 2 vardef)
1176 type (match-string 1 vardef)
1177 ws (substring vardef 0 (match-beginning 1)))
1178 (if (string-match "_$" varname)
1179 (setq fnname (string-replace "_$" "" varname)
1180 argname (concat "a_" fnname))
1181 (setq fnname (concat "q_" varname)
1182 argname (concat "a_" varname)))
1183 (if (string-match "^[ \t\n\r]*" type)
1184 (setq type (substring type (match-end 0))))
1185 (if (string-match "^[A-Z]" type)
1186 (setq reftype (concat type " const &"))
1187 (setq reftype type))
1188 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1190 ws in in type " old" varname " = " varname ";\n"
1191 ws in in varname " = " argname ";\n"
1192 ws in in "return old" varname ";\n"
1194 ws reftype " " fnname "() const\n"
1195 ws in "{ return " varname "; }\n"))
1198 (message "No variable found"))))
1200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1201 ;; doxy comment support functions
1203 (defun ccide-special-indent-function ()
1204 "Function to indent doxy comments correctly"
1205 (let ((indent (ccide-in-doxy-comment)))
1207 (let ((lim (save-excursion
1208 (back-to-indentation)
1209 (c-literal-limits)))
1210 (pos (- (point-max) (point))))
1212 (back-to-indentation)
1213 (if (looking-at "*/")
1215 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1217 (if (and (not (looking-at ccide-doxy-tag-re))
1218 (re-search-backward (concat "^\\s-*"
1222 (delete-region (progn (beginning-of-line) (point))
1223 (progn (back-to-indentation) (point)))
1225 (if (> (- (point-max) pos) (point))
1226 (goto-char (- (point-max) pos)))))))
1228 (defun ccide-fill-function ()
1229 "auto-fill function for doxy comments"
1231 (if (not fill-prefix)
1232 (indent-according-to-mode))))
1234 (defun ccide-hide-all-doxy-comments ()
1235 "Hide all doxy comments"
1238 (goto-char (point-min))
1239 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1242 (if (not (looking-at "\\s-*$"))
1245 (let ((start (point)))
1246 (if (re-search-forward "\\*/" nil t)
1248 (if (looking-at "\\s-*\n")
1251 (let ((overlay (make-overlay start (point))))
1252 (overlay-put overlay 'intangible 'hs)
1253 (overlay-put overlay 'invisible 'hs)))))))
1256 (defun ccide-show-all-comments ()
1260 (goto-char (point-min))
1262 (goto-char (next-overlay-change (point)))
1263 (loop for overlay in (overlays-at (point))
1264 if (eq (overlay-get overlay 'invisible) 'hs)
1265 do (delete-overlay overlay))))
1268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1269 ;; CORBA support (omniORB2)
1271 (defun ccide-get-corba-headers ()
1274 (goto-char (point-min))
1275 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1276 (setq files (cons (ccide-match-string 1) files)))
1279 (defun ccide-corba-maybe-build-hh (file)
1280 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1281 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1282 (if (and (file-readable-p idl)
1283 (or (not (file-readable-p skel))
1284 (file-newer-than-file-p idl skel)))
1285 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1287 (kill-buffer buffer))
1288 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1289 (if (ccide-shell-command (concat "cd "
1290 (real-path-name ccide-corba-skel-dir)
1292 ccide-corba-idl-command
1293 (if (> (length ccide-corba-idl-dir) 0)
1294 (concat " -I" ccide-corba-idl-dir))
1298 (display-buffer (get-buffer-create "*ccide shell command*"))
1299 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1300 (if (not (file-readable-p skel))
1301 (error "No file %s or %s"
1302 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1304 (defun ccide-corba-list-skeletons-1 (hh-file)
1305 (ccide-corba-maybe-build-hh hh-file)
1306 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1311 (goto-char (point-min))
1312 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1314 (setq skels (cons (ccide-match-string 1) skels)))))
1315 (mapcar (function (lambda (x) (cons x hh-file)))
1316 (sort skels 'string-lessp))))
1318 (defun ccide-corba-list-skeletons ()
1319 (let ((files (ccide-get-corba-headers)))
1320 (loop for file in files
1321 append (ccide-corba-list-skeletons-1 file))))
1323 (defun ccide-gen-corba-impl (class)
1324 (interactive (list (completing-read "Class name of skeleton: "
1325 (ccide-corba-list-skeletons)
1327 (let* ((skels (ccide-corba-list-skeletons))
1328 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1329 ccide-corba-skel-dir))
1330 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1331 ccide-corba-skel-dir))))
1332 (ccide-gen-class (concat class "_i"))
1333 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1335 (search-forward "protected:" nil t)
1337 (ccide-gen-corba-impl-methods)
1340 (defun ccide-get-corba-defns (hh-file class)
1341 (let ((hh-buf (find-file-noselect hh-file))
1346 (goto-char (point-min))
1347 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1349 (error "CORBA skeleton class not found.")
1350 (search-forward "{")
1352 (let ((end (save-excursion (forward-sexp) (point))))
1353 (while (and (< (point) end)
1354 (< (forward-line 1) 1))
1355 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1356 (setq defns (cons (match-string 1) defns))))))))
1359 (defun ccide-gen-corba-impl-methods ()
1361 (let* ((class (c-get-class-at-point))
1364 (error "No class at point."))
1366 (goto-char (aref (car class) 1))
1367 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1369 (error "No CORBA impl at point."))
1370 (let* ((name (ccide-match-string 1))
1371 (skels (ccide-corba-list-skeletons))
1372 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1373 ccide-corba-skel-dir))
1374 (defns (ccide-get-corba-defns hh-file name))
1376 (goto-char (aref (car class) 2))
1380 (if (re-search-forward "^\\s-*// CORBA$" end t)
1381 (let ((start (match-beginning 0)))
1382 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1383 (let ((eend (match-end 0)))
1386 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1387 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1388 (delete-region start (1+ eend))
1391 (delete-region (point) (progn
1396 (delete-region (point) (progn
1400 (delete-region start (1+ eend))))))
1402 (indent-according-to-mode)
1403 (insert "// CORBA\n")
1404 (loop for defn in defns
1406 (save-excursion (insert defn ";"))
1407 (indent-according-to-mode)
1408 (let ((start (point)) end)
1412 (while (re-search-forward "\\s-+" end t)
1414 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1416 (loop with done = nil
1417 while (> (current-column) c-max-def-column)
1418 do (while (and (> (current-column) c-max-def-column)
1419 (search-backward "," start t)))
1420 do (if (looking-at ",")
1425 (indent-according-to-mode)
1427 (setq start (point))
1432 (indent-according-to-mode)
1433 (insert "// END-CORBA\n")))))
1435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1438 (defun ccide-scan-mantemps ()
1439 "Scan *compilation* buffer for errors and generate manual template
1440 instatiations at point."
1443 (set-buffer "*compilation*")
1444 (goto-char (point-min)))
1446 (set-buffer (get-buffer-create "*mantemps*"))
1448 (loop for temp = (ccide-get-mantemp)
1450 do (insert temp "\n"))
1451 (mantemp-make-mantemps-buffer)
1452 (goto-char (point-min))
1455 (< (forward-line 1) 1))))
1456 (insert-buffer-substring "*mantemps*"))
1458 (defun ccide-get-mantemp ()
1460 (set-buffer "*compilation*")
1461 (if (search-forward "undefined reference to `" nil t)
1462 (let ((start (point)))
1464 (search-backward "'" nil t)
1465 (buffer-substring start (point))))))
1467 (defun ccide-fix-mantemp ()
1468 (let ((end (save-excursion
1469 (end-of-line) (point))))
1470 (if (and (save-excursion (search-forward "(" end t))
1471 (search-forward " class" end t))
1478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1481 (defun ccide-grab-pxd-fn ()
1484 (c-beginning-of-defun-or-decl)
1485 (let ((defn (c-build-pxd)))
1486 (kill-new (cadr defn))
1487 (message (concat (car defn))))))
1489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1492 (defun ccide-open-compilation-frame ()
1494 (let ((c-frame (selected-frame))
1495 (compilation-frame (make-frame '((minibuffer . nil)
1497 (menu-bar-lines . 0)
1502 (select-frame compilation-frame)
1503 (switch-to-buffer "*compilation*")
1504 (set-window-dedicated-p (selected-window) t)))
1506 (defun ccide-compile (command)
1507 (delete-other-windows)
1508 (split-window-horizontally)
1511 (set-buffer "*compilation*")
1512 (let ((point (point-max)))
1514 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1515 do (set-window-point window point)))))
1517 (defun ccide-compile-compile ()
1519 (ccide-compile (concat "make -k " ccide-compile-opts)))
1521 (defun ccide-compile-clean ()
1523 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1525 (defun ccide-compile-cleandepends ()
1527 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1529 (defun ccide-compile-kill ()
1531 (set-buffer "*compilation*")
1534 (defun ccide-hide-compilation ()
1536 (let ((active (selected-window)))
1538 (loop for window in (get-buffer-window-list "*compilation*")
1539 do (progn (select-window window)
1540 (switch-to-buffer (other-buffer "*compilation*"))))
1541 (select-window active))))
1543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1544 ;; keymap and installation
1546 (defun ccide-bind-keys (prefix map)
1547 (loop for binding in ccide-bindings
1548 do (apply 'vcmd-define-key
1550 (concat prefix (car binding))
1555 (defun ccide-install-it ()
1559 (local-unset-key "\C-c;")
1560 (local-unset-key [menu-bar IDE])
1561 (ccide-bind-keys "\C-c;" (current-local-map))
1562 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1563 (local-set-key "\C-cS" 'ccide-show-all-comments)
1564 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1565 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1566 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1568 (ccide-project-load-config)
1569 (ccide-directory-load-config)
1570 (ccide-auto-decorate-new-files)
1571 (if ccide-format-command
1572 (add-hook 'write-contents-functions 'ccide-format-buffer nil t)))
1574 (defun ccide-format-buffer ()
1576 (if ccide-format-command
1577 (let ((bkmp (bookmark-make-record)))
1579 (shell-command-on-region (point-min) (point-max) ccide-format-command nil t)
1580 (goto-char (cdr (bookmark-jump-noselect bkmp))))))
1583 (defun ccide-project-load-config ()
1584 (if (buffer-file-name)
1585 (let ((conf (ccide-project-search-upwards '(".project.el" "project.el")
1586 (file-name-directory (buffer-file-name)))))
1588 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1589 (load-file conf)))))
1591 (defun ccide-project-search-upwards (names &optional base)
1592 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1593 DIR defaults to ccide-project-root. If FILE is a list, search for any file in list."
1594 (if (not (consp names))
1595 (setq names (list names)))
1596 (loop for dir = (or base ccide-project-root) then (directory-file-name (file-name-directory dir))
1597 while (not (string= dir "/"))
1598 thereis (loop for name in names
1599 for path = (expand-file-name name dir)
1600 thereis (and (file-readable-p path) path))))
1602 (defun ccide-directory-load-config ()
1603 (if (file-readable-p ".dir.el")
1604 (load-file ".dir.el")))
1606 (add-hook 'c-mode-hook 'ccide-install-it)
1607 (add-hook 'c++-mode-hook 'ccide-install-it)
1608 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1610 (loop for extension in ccide-special-extensions
1611 for re = (concat (regexp-quote extension) "$")
1612 if (not (assoc re auto-mode-alist))
1613 do (setq auto-mode-alist (append auto-mode-alist
1614 (list (cons re 'c++-mode)))))
1616 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1617 ;; new indent function for c-mode: do standard indentation first. If line
1618 ;; is to long using standard indentation, just indent by c-basic-indentation.
1619 (let ((cc (save-excursion (end-of-line) (current-column)))
1622 (let ((pos (- (point-max) (point))))
1624 (let ((point (point))
1625 (line (1+ (count-lines 1 (point))))
1627 (c-beginning-of-statement-2)
1628 (if (and (not (c-crosses-statement-barrier-p (point) point))
1629 (not (eq (+ (count-lines 1 (point))
1633 (setq indent (+ (current-indentation) c-basic-offset))
1635 (if (< indent (current-indentation))
1637 (setq ad-return-value
1639 (- (current-indentation) indent)))
1640 (delete-region (c-point 'bol) (c-point 'boi))
1641 (indent-to indent))))))
1642 (if (< (point) (c-point 'boi))
1643 (back-to-indentation)
1644 (if (> (- (point-max) pos) (point))
1645 (goto-char (- (point-max) pos))))))))
1648 ;;; Local Variables:
1649 ;;; elisp-project-autoload-file-name: "cc-autoload.el"