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-clang-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")
85 ("ff" ccide-clang-format-buffer "Reformat buffer")
89 ("cc" ccide-class-comment "Class comment")
90 ("cg" ccide-gen-class "Generate class")
91 ("cd" ccide-gen-class-defaults "Generate class defaults")
92 ("cD" ccide-gen-class-defaults-impl "Generate class defaults impl")
94 ("csd" ccide-set-class-defaults-default "Set class defaults comment" "Default")
95 ("csn" ccide-set-class-defaults-no "Set class defaults comment" "No")
96 ("csp" ccide-set-class-defaults-protected "Set class defaults comment" "Protected")
97 ("csr" ccide-set-class-defaults-private "Set class defaults comment" "Private")
98 ("csx" ccide-set-class-defaults-disabled "Set class defaults comment" "Disabled")
99 ("csm" ccide-set-class-defaults-my "Set class defaults comment" "My")
101 ("cS" ccide-gen-struct-constructors "Generate structure constructors")
102 ("c<" ccide-gen-struct-compare "Generate structure compare operators")
104 ("ci" ccide-class-impl-comment "Generate class implemenation comment")
106 ("ce" ccide-gen-exception "Generate an exception class")
111 ("mc" ccide-function-comment "Method comment")
112 ("mp" ccide-grab-prototype "Grab prototype")
113 ("mr" ccide-reformat-defun "Reformat defun")
114 ("mx" ccide-replace-defun "Replace defun")
115 ("mt" ccide-prefix-defun-type-with-class "Prefix defun type with class")
116 ("mn" ccide-prefix-defun-type-with-namespace "Prefix defun type with namespace")
117 ("mi" ccide-grab-inline-decl "Grab inline decl")
118 ("mA" ccide-grab-all-inlines "Grab ALL inline decls")
119 ("mC" ccide-grab-create-constructor "Grab CREATE constructor")
120 ("mI" ccide-grab-create-constructor-impl "Build CREATE cosntructor")
121 ("mf" ccide-find-implementation "Find method implementation")
122 ("mT" ccide-insert-defun-prefix "Insert current defun prefix at point")
126 ("vc" ccide-variable-comment "Variable comment")
127 ("vf" ccide-grab-access-fn "Grab access methods")
131 ("h" ccide-hide-all-doxy-comments "Hide all Doxygen comments")
132 ("s" ccide-show-all-comments "Show all Doxygen comments")
135 ("yp" ccide-grab-pxd-fn "Generate pxd function/method decl")
138 ; ("Cg" ccide-gen-corba-impl "Generate CORBA impl")
139 ; ("Cm" ccide-gen-corba-impl-methods "Generate CORBA impl methods")
140 ; (nil nil separator)
143 ; ("ts" ccide-scan-mantemps "Scan mantemps")
144 ; (nil nil separator)
147 ; ("of" ccide-open-compilation-frame "Open *compilation* frame")
148 ; ("oc" ccide-compile-compile "Make -> Compile")
149 ; ("ox" ccide-compile-clean "Make -> Clean")
150 ; ("od" ccide-compile-cleandepends "Make -> Clean depends")
151 ; ("ok" ccide-compile-kill "Kill compilation")
152 ; ("oh" ccide-hide-compilation "Hide *compilation* buffer")
158 (require 'cc-engine-2)
167 (require 'misc-local)
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 (defsubst ccide-match-string (n)
173 (buffer-substring-no-properties (match-beginning n) (match-end n)))
175 (defun ccide-file-macro-name (&optional file-name)
176 (concat (upcase (file-name-extension (or file-name (buffer-file-name))))
178 (if ccide-project-name (concat ccide-project-name "_") "")
179 (if ccide-project-root
180 (string-replace "/" "_"
181 (substring (file-name-directory
182 (expand-file-name (or file-name buffer-file-name)))
183 (length ccide-project-root))
186 (string-replace "\\." "_" (file-name-sans-extension
187 (file-name-nondirectory
188 (or file-name (buffer-file-name))))
192 (defun ccide-file-name (&optional extension file-name directory)
193 (concat (if directory (file-name-as-directory directory) "")
194 (file-name-sans-extension
195 (file-name-nondirectory
196 (or file-name (buffer-file-name))))
199 (defun ccide-in-doxy-comment ()
201 (back-to-indentation)
202 (let ((lit (c-in-literal)))
203 (when (and (memq lit '(c c++))
204 (progn (goto-char (car (c-literal-limits)))
205 (looking-at "/\\(\\*\\*\\|///\\)<?[ \t\n\r@]")))
206 (goto-char (match-end 0))
209 (defun ccide-shell-command (command)
210 (let ((obuf (get-buffer-create "*ccide shell command*"))
215 (insert command "\n"))
216 (setq exit-status (call-process shell-file-name nil "*ccide shell command*" nil
217 shell-command-switch command))
218 (and exit-status (equal exit-status 0))))
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
223 (defun ccide-file-comment ()
224 "Add a comment to this source file."
229 (goto-char (point-min))
232 "// Copyright (C) " (number-to-string (nth 5 (decode-time)))
233 " " ccide-default-author "\n"
234 ccide-default-copyright
237 (cond ((string-match "\\.hh?$" (buffer-file-name))
238 (insert "/** \\file\n"
239 " \\brief " (ccide-file-name) " public header */\n\n"
240 "#ifndef " (ccide-file-macro-name) "\n"
241 "#define " (ccide-file-macro-name) " 1\n\n")
242 (if ccide-all-includes
243 (insert "#ifndef " (ccide-file-macro-name ccide-all-includes) "\n"
244 "#error \"Don't include '" (file-name-nondirectory (buffer-file-name)) "'"
245 " directly, include '" ccide-all-includes "'\"\n"
247 (insert "// Custom includes\n\n"
248 "//#include \"" (ccide-file-name ".mpp") "\"\n"
249 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
251 (goto-char (point-max))
252 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n")
253 (if ccide-all-includes
255 "#if !defined(" (ccide-file-macro-name ccide-all-includes) "_decls_) "
256 "&& !defined(" (ccide-file-macro-name) "i_)\n"
257 "#define " (ccide-file-macro-name) "i_\n"))
258 (insert "//#include \"" (ccide-file-name ".cci") "\"\n"
259 "//#include \"" (ccide-file-name ".ct") "\"\n"
260 "//#include \"" (ccide-file-name ".cti") "\"\n"
263 ((string-match "\\.mpp$" (buffer-file-name))
264 (insert "/** \\file\n"
265 " \\brief " (ccide-file-name) " Boost.Preprocesser external iteration include */\n\n"
268 "#if !BOOST_PP_IS_ITERATING && !defined(" (ccide-file-macro-name) ")\n"
269 "#define " (ccide-file-macro-name) " 1\n\n"
270 "// Custom includes\n\n\n"
271 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
272 "#elif BOOST_PP_IS_ITERATING //-/////////////////////////////////////////////////////////////////////\n"
273 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
274 "// Local Macros\n\n\n"
275 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
276 "#if BOOST_PP_ITERATION_FLAGS()==1 //-///////////////////////////////////////////////////////////////\n"
277 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
279 (goto-char (point-max))
280 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
281 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
282 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
283 "// Undefine local Macros\n\n\n"
284 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
285 "#endif //-//////////////////////////////////////////////////////////////////////////////////////////\n"
286 "//-/////////////////////////////////////////////////////////////////////////////////////////////////"))
288 ((string-match "\\.ih$" (buffer-file-name))
289 (insert "/** \\file\n"
290 " \\brief " (ccide-file-name) " internal header */\n\n"
291 "#ifndef " (ccide-file-macro-name) "\n"
292 "#define " (ccide-file-macro-name) " 1\n\n"
293 "// Custom includes\n\n"
294 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
296 (goto-char (point-max))
297 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
300 ((or (string-match "\\.test\\.cc$" (buffer-file-name))
301 (string-match "\\.test\\.cpp$" (buffer-file-name)))
302 (insert "/** \\file\n"
303 " \\brief " (ccide-file-name) " unit tests */\n\n"
304 "//#include \"" (ccide-file-name ".hh") "\"\n"
305 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
306 "// Custom includes\n"
307 "#include \"" (or ccide-all-includes
308 (ccide-file-name ".hh" (ccide-file-name))) "\"\n\n"
309 "#include <boost/test/auto_unit_test.hpp>\n"
310 "#include <boost/test/test_tools.hpp>\n\n"
312 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
314 (goto-char (point-max))
315 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
318 ((or (string-match "\\.cc$" (buffer-file-name))
319 (string-match "\\.cpp$" (buffer-file-name)))
320 (insert "/** \\file\n"
321 " \\brief " (ccide-file-name) " non-inline non-template implementation */\n\n"
322 (if ccide-all-includes "" "//")
323 "#include \"" (or ccide-all-includes (ccide-file-name ".hh")) "\"\n"
324 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
325 "// Custom includes\n\n"
326 "//#include \"" (ccide-file-name ".mpp") "\"\n"
328 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
330 (goto-char (point-max))
331 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
333 "//#include \"" (ccide-file-name ".mpp") "\""))
335 ((string-match "\\.cci$" (buffer-file-name))
336 (insert "/** \\file\n"
337 " \\brief " (ccide-file-name) " inline non-template implementation */\n\n"
338 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
339 "// Custom includes\n\n"
340 "#define prefix_ inline\n"
341 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
343 (goto-char (point-max))
344 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
347 ((string-match "\\.ct$" (buffer-file-name))
348 (insert "/** \\file\n"
349 " \\brief " (ccide-file-name) " non-inline template implementation */\n\n"
350 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
351 "// Custom includes\n\n"
353 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
355 (goto-char (point-max))
356 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
359 ((string-match "\\.cti$" (buffer-file-name))
360 (insert "/** \\file\n"
361 " \\brief " (ccide-file-name) " inline template implementation */\n\n"
362 "//#include \"" (ccide-file-name ".ih") "\"\n\n"
363 "// Custom includes\n\n"
364 "#define prefix_ inline\n"
365 "//-/////////////////////////////////////////////////////////////////////////////////////////////////\n\n")
367 (goto-char (point-max))
368 (insert "\n\n//-/////////////////////////////////////////////////////////////////////////////////////////////////\n"
371 ((string-match "\\.dox$" (buffer-file-name))
372 (insert "/** \\mainpage\n\n ")
375 (setq add-file-vars '(( mode . flyspell)
376 ( mode . auto-fill))))
378 ((string-match "\\.java$" (buffer-file-name))
381 (goto-char (point-max)))
385 (goto-char (point-max))))
388 "// Local Variables:\n"
389 "// mode: " mode "\n")
390 (loop for (var . value) in ccide-file-vars
391 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
392 (loop for (var . value) in add-file-vars
393 do (insert "// " (symbol-name var) ": " (prin1-to-string value) "\n"))
397 (if (equal mode "jde")
398 (let ((package (file-name-directory (buffer-file-name))))
399 (jdeap-initialize-setup)
400 (if (not (equal jdeap-current-source-directory "."))
402 (concat "^" (regexp-quote jdeap-current-source-directory))
405 (setq package (substring package
407 (1- (length package))))
409 (string-replace "/" "." package t)
411 (insert "class " (file-name-sans-extension
412 (file-name-nondirectory
413 (buffer-file-name))) "\n{}")
414 (beginning-of-line))))
415 (run-hooks 'ccide-new-file-hooks))
417 (defun ccide-sync-file-variables ()
418 "Syncronize file variables to the current value of ccide-file-vars"
421 (goto-char (point-max))
422 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
423 (let ((case-fold-search t))
424 (if (search-forward "Local Variables:" nil t)
425 (let (prefix suffix vars)
426 (skip-chars-forward " \t")
428 (setq suffix (buffer-substring (point) (progn (end-of-line) (point)))))
429 (goto-char (match-beginning 0))
431 (setq prefix (buffer-substring (point) (progn (beginning-of-line) (point)))))
434 (if (and prefix (looking-at prefix))
435 (goto-char (match-end 0)))
436 (skip-chars-forward " \t"))
437 while (not (looking-at "end:"))
439 (setq vars (cons (intern (buffer-substring
441 (progn (skip-chars-forward "^:\n") (point))))
444 (loop for (var . value) in ccide-file-vars
445 do (if (not (memq var vars))
446 (insert (or prefix "")
447 (symbol-name var) ": " (prin1-to-string value)
448 (or suffix "") "\n"))))))))
450 (defun ccide-syncronize-includes ()
451 "Syncronize include's in all other files"
454 (loop for extension in ccide-special-extensions
455 for file-name = (ccide-file-name extension)
457 (cons (cons file-name
458 (or (find-buffer-visiting file-name)
459 (and (file-readable-p file-name)
460 (find-file-noselect file-name))))
463 (loop for buffer in buffer-map
466 (set-buffer (cdr buffer))
468 (loop for include in buffer-map
470 (goto-char (point-min))
471 (while (re-search-forward
472 (concat "^\\(//\\)?#\\s-*include \""
473 (regexp-quote (car include))
476 (goto-char (match-beginning 0))
477 (if (looking-at "//")
480 (if (not (cdr include))
482 (forward-line 1))))))))))
484 (defun ccide-auto-decorate-new-files ()
485 (if (and (buffer-file-name) (= (point-min) (point-max)))
486 (if (or (not ccide-new-file-command)
491 (shell-command (format "%s %s" ccide-new-file-command (buffer-file-name)))
492 (revert-buffer t t t)
495 (let ((status (buffer-modified-p)))
497 (set-buffer-modified-p status)))))
499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
502 (defun ccide-class-comment ()
503 "Add comment to start of current class definition"
505 (let ((class (c-get-class-at-point)))
507 (error "No class found")
508 (goto-char (or (aref (car class) 3)
509 (aref (car class) 1)))
512 (ccide-in-doxy-comment))
514 (search-backward "/**" nil t)
516 (let ((indent (make-string (current-indentation) ? )))
517 (insert "/** \\brief ")
523 (defun ccide-gen-class (name &optional defns)
524 "Generate class declaration template"
525 (interactive (list (read-string (concat "Class name (default "
528 nil nil (ccide-file-name))))
529 (insert "class " name)
530 (indent-according-to-mode)
531 (let ((in (make-string c-basic-offset ? ))
532 (ofs (make-string (current-indentation) ? ))
533 (sl (make-string (- 100 3 c-basic-offset (current-indentation)) ?/)))
537 (insert ofs "/** \\brief\n"
544 ofs in "// Types\n\n"
546 ofs in "///\\name Structors and default members\n"
548 ofs in "// default default constructor\n"
549 ofs in "// default copy constructor\n"
550 ofs in "// default copy assignment\n"
551 ofs in "// default destructor\n\n"
552 ofs in "// no conversion constructors\n\n"
555 ofs in "///\\name Accessors\n"
559 ofs in "///\\name Mutators\n"
562 (loop for defn in defns
563 do (insert ofs in defn ";\n"))
566 (insert ofs "protected:\n\n"
570 (defun ccide-gen-class-defaults ()
571 "Generate signatures of the default functions: default constructor,
572 copy constructor, assignment operator and destructor."
573 (indent-according-to-mode)
574 (let* ((name (c-scope-name (aref (car (c-get-class-at-point)) 1)))
575 (in (make-string c-basic-offset ? ))
576 (ofs (make-string (current-indentation) ? ))
577 (tspec (if ccide-gen-throw (concat "\n" ofs in "throw_(());\n") ";\n"))
579 (while (string-match "::" name colon)
580 (setq colon (match-end 0)))
581 (setq name (substring name colon))
583 (delete-horizontal-space)
584 (loop with exit = nil
585 do (message (concat "1-dflt constr, 2-destr, "
586 "3-copy constr, 4-copy assmnt, "
587 "c-all copy, d-all dflt, RET-all/done: "))
588 for ch = (read-event)
589 for first = t then nil
590 do (cond ((eq ch 'return)
592 (insert ofs name "()"
594 ofs name "(const " name "& other)"
597 ofs name "& operator=(const " name "& other)"
601 (insert ofs name "()"
604 (insert ofs "~" name "();\n"))
606 (insert ofs name "(const " name "& other)"
609 (insert ofs name "& operator=(const " name "& other)"
612 (insert ofs name "(const " name "& other)"
614 ofs name "& operator=(const " name "& other)"
617 (insert ofs name "()"
619 ofs "~" name "();\n"))
620 (t (setq unread-command-events (cons ch unread-command-events))
624 (defun ccide-gen-class-defaults-impl ()
625 "Generate default implementations for class default functions"
627 (let ((defn (c-build-default-funcions-impl)))
628 (kill-new (cadr defn))
629 (message (concat (car defn) " default members"))))
631 (defun ccide-set-class-defaults-comment (word)
633 (back-to-indentation)
634 (if (not (looking-at ccide-class-defaults-word))
635 (message "Not at class defaults commnet")
636 (replace-match word t t nil 1))))
638 (defmacro ccide-build-class-defaults-f (sym)
639 (let ((fn (intern (concat "ccide-set-class-defaults-"
640 (symbol-name sym)))))
643 (ccide-set-class-defaults-comment ,(symbol-name sym)))))
645 (ccide-build-class-defaults-f no)
646 (ccide-build-class-defaults-f default)
647 (ccide-build-class-defaults-f my)
648 (ccide-build-class-defaults-f protected)
649 (ccide-build-class-defaults-f private)
650 (ccide-build-class-defaults-f disabled)
652 (defun ccide-gen-struct-constructors ()
657 (indent-according-to-mode)
658 (let* ((scope (c-get-block-scope))
659 (class (c-parse-class scope))
660 (variables (c-get-variable-members-with-type class))
661 (name (c-scope-name (aref (car (last scope)) 1)))
662 (in (make-string (current-indentation) ? ))
663 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
664 (insert name "()\n" inin ": ")
665 (loop for var in variables
666 for first = t then nil
667 if (not first) do (insert ", ")
668 do (insert (car var) " ()"))
671 (loop for var in variables
672 for first = t then nil
673 if (not first) do (insert ", ")
674 do (insert (cdr var) " " (car var) "_"))
675 (insert ")\n" inin ": ")
676 (loop for var in variables
677 for first = t then nil
678 if (not first) do (insert ", ")
679 do (insert (car var) " (" (car var) "_)"))
683 (defun ccide-gen-struct-compare ()
688 (indent-according-to-mode)
689 (let* ((scope (c-get-block-scope))
690 (class (c-parse-class scope))
691 (variables (c-get-variable-members-with-type class))
692 (name (c-scope-name (aref (car (last scope)) 1)))
693 (in (make-string (current-indentation) ? ))
694 (inin (make-string (+ (current-indentation) c-basic-offset) ? )))
696 (insert "bool operator<(" name " const & other) const\n"
698 (loop for ((varName . varType) . tail) on variables
699 do (insert inin varName " < other." varName " ? true :")
701 (insert "\n" inin "other." varName " < " varName " ? false :\n")
702 (insert " false; }\n\n")))
703 (insert in "bool operator==(" name " const & other) const\n"
705 (loop for ((varName . varType) . tail) on variables
706 do (insert inin varName " == other." varName)
707 do (if tail (insert " &&\n") (insert "; }\n\n")))
708 (insert in "std::size_type hash_value() const\n"
709 in "{ std::size_t current (0);\n")
710 (loop for ((varName . varType) . tail) on variables
711 do (insert inin "boost::hash_combine(current, " varName ");\n"))
712 (insert inin "return current; }\n\n")
713 (insert in "void write(std::ostream & os) const\n"
715 (loop for ((varName . varType) . tail) on variables
716 do (insert "\n" inin "<< " varName)
717 do (if tail (insert " << ' '")))
718 (insert " << \" }\"; }\n"))))
720 (defun ccide-class-impl-comment ()
721 "Get implementation comment for current class"
723 (let* ((scope (c-get-block-scope))
724 (name (c-get-full-prefix scope)))
725 (kill-new (concat (make-string 75 ?/) "\n"
731 (defun ccide-gen-exception (class &optional description)
732 (interactive "sException name: \nsDescription (defaults to full class name): ")
735 (indent-according-to-mode)
737 (let ((in (make-string c-basic-offset ? ))
738 (ofs (make-string (current-indentation) ? ))
739 (prefix (c-get-full-prefix (c-get-block-scope)))
741 (insert "struct " class " : public std::exception\n"
742 ofs "{ virtual char const * what() const throw() ")
744 (insert "{ return \""
745 (if (and description (> (length description) 0))
747 (concat prefix "::" class))
749 (if (> (current-column) fill-column)
752 (insert "\n" ofs in in))))))
754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
755 ;; function/method level
757 (defun ccide-function-comment ()
758 "Add comment for current function"
760 (if (memq (c-in-literal) '(c c++))
761 ; Assume, we are in the functions comment ...
763 (c-forward-out-of-comment)
764 (c-backward-syntactic-ws)
767 (c-beginning-of-defun-or-decl)
768 (let ((defun (c-get-defun-state))
769 (indent (make-string comment-column ? ))
771 (goto-char (or (aref defun 7) (car (aref defun 6))))
772 (c-backward-syntactic-ws)
773 (if (looking-at "[ \t\n\r]*///<")
775 (delete-region (point) (progn (skip-chars-forward " \t\n\r") (point)))
776 (if (> (current-column) comment-column)
778 (indent-to-column comment-column)
779 (search-forward "*/")
781 (if (> (current-column) comment-column)
783 (indent-to-column comment-column)
791 (goto-char (car (aref defun 2)))
792 (setq defun (c-get-defun-state)))
794 (ccide-function-comment-adjust defun (concat indent " "))
795 (if place (goto-char place))))
797 (defun ccide-function-comment-grab-args ()
798 (let ((limit (save-excursion
799 (search-backward "/**" nil t)
802 begin start args argend)
804 (while (or (search-backward "\\param" limit t)
805 (search-backward "\\return" limit t)))
809 (while (search-forward "\\param" argend t)
810 (or (search-forward "\\param" argend t)
811 (search-forward "\\return" argend t)
814 (setq args (cons (ccide-function-comment-parse-arg start (point))
816 (setq start (point)))
818 (if (not (search-forward "\return" argend t))
821 (cons (buffer-substring (point) argend) args))
822 (delete-region begin end))))
824 (defun ccide-function-comment-parse-arg (start end)
827 (re-search-forward "\\\\param\\(\\[[^]]*\\]\\)?\\s-*\\(\\S-*\\)" end t)
828 (cons (match-string 2)
829 (cons (buffer-substring start (match-beginning 2))
830 (buffer-substring (match-end 2) end)))))
832 (defun ccide-function-comment-get-throws (defun)
835 (goto-char (car (aref defun 4)))
836 (if (re-search-forward "\\(throw_\\|throw\\)((?\\s-*\\([^()]*\\))?)"
837 (cdr (aref defun 4)) t)
838 (let ((spec (match-string 2)))
839 (if (> (length spec) 0)
842 (defun ccide-function-comment-adjust (defun indent)
844 (let* ((defargs (mapcar (function (lambda (x)
845 (c-get-template-argument-name (car x) (cdr x))))
847 (defret (and (aref defun 1)
848 (not (string-match (concat "^\\("
850 "\\s-*\\)*\\s-*void$")
851 (buffer-substring (car (aref defun 1))
852 (cdr (aref defun 1)))))))
853 (throws (ccide-function-comment-get-throws defun))
854 (xargs (ccide-function-comment-grab-args))
855 (docargs (cdr xargs))
857 (def-in-doc (loop for defarg in defargs always (assoc defarg docargs)))
858 (doc-in-def (loop for docarg in docargs always (member (car docarg) defargs)))
859 (size-eq (= (length defargs) (length docargs))))
860 ;; We differentiate four types changes
862 ;; - removed arguments
863 ;; - reordered arguments
864 ;; - renamed arguments
866 ;; If the change cannot be described by one of the above, it has
867 ;; to be resolved manually
869 (insert indent "\\throws " throws "\n"))
871 ;; reordered arguments or new arguments (or no change)
872 (loop for defarg in defargs
873 for docarg = (assoc defarg docargs)
875 (insert (cadr docarg) (car docarg) (cddr docarg))
876 (insert indent "\\param " defarg " \n"))))
877 (size-eq ; and (not doc-in-def)
879 (loop for defarg in defargs
880 for docarg in docargs
881 do (insert (cadr docarg) defarg (cddr docarg))))
884 (loop for defarg in defargs
885 for docarg = (assoc defarg docargs)
886 do (insert (cadr docarg) (car docarg) (cddr docarg))))
887 (t (error "Arg change too complex. Resolve manualy.")))
888 ;; return value is simple
892 (insert indent "\\return \n"))))
894 (delete-horizontal-space)
897 (defun ccide-grab-prototype (&optional prefix)
898 "Grab prototype of function defined or declared at point. Prefix
899 arg, if given, specifies the kind of prefix (inline, static, ...) to use."
902 (c-beginning-of-defun-or-decl)
903 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
904 ccide-default-prefix))
905 (defn (c-build-defun prfx)))
906 (kill-new (concat (cadr defn) "\n{}\n"))
907 (message (concat (or prfx "")
911 (defun ccide-reformat-defun ()
912 "Reformat the defn of the current defun."
915 (c-beginning-of-defun-or-decl)
916 (let ((defn (c-build-defun nil t)))
917 (delete-region (or (caar (aref (caddr defn) 0))
918 (car (aref (caddr defn) 1))
919 (car (aref (caddr defn) 2)))
920 (or (car (aref (caddr defn) 6))
921 (aref (caddr defn) 7)))
922 (insert (cadr defn) "\n"))))
924 (defun ccide-replace-defun ()
925 "Replace the function header with the one on the top of the kill
926 ring (presumably placed there using c++-grab-prototype)."
929 (c-beginning-of-defun-or-decl)
930 (let ((parse (c-parse-defun)))
931 (delete-region (or (aref parse 0)
940 (defun ccide-prefix-defun-type-with-class (&optional strip)
941 "If a non-keyword type symbol is found prefixing the current defun,
942 it will be prefixed with the current class prefix."
945 (c-beginning-of-defun-or-decl)
946 (let* ((parse (c-parse-defun))
947 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
948 (goto-char (aref parse 1))
949 (while (and (or (looking-at c-any-key)
950 (looking-at c-user-prefix-re)
951 (not (c-at-symbol-p)))
952 (< (point) (aref parse 2))
955 (c-forward-syntactic-ws))
956 (if (and (c-at-symbol-p)
957 (< (point) (aref parse 2))
958 (not (looking-at (regexp-quote prefix))))
959 (let ((pos (string-match "<" prefix)))
961 (insert "typename "))
962 (if (and pos (looking-at (concat (substring prefix 0 pos)
965 (goto-char (match-end 0))
966 (c-backward-syntactic-ws)
967 (insert (substring prefix pos)))
968 (insert prefix "::"))
969 (ccide-reformat-defun))))))
971 (defun ccide-prefix-defun-type-with-namespace (&optional strip)
973 (ccide-prefix-defun-type-with-class (+ (or strip 0) 1)))
975 (defun ccide-insert-defun-prefix (&optional strip)
976 "Insert the current defun prefix at point."
978 (let* ((parse (c-parse-defun))
979 (prefix (c-scope-name (aref parse 2) (+ (or strip 0) 0))))
980 (insert prefix "::")))
982 (defun ccide-kill-inline-decl (defn)
984 (if (aref (caddr defn) 6)
986 (goto-char (cdr (aref (caddr defn) 6)))
987 (let ((end-mark (point-marker)))
988 (goto-char (car (aref (caddr defn) 6)))
989 (indent-rigidly (point) end-mark
990 (- (current-column)))
994 (buffer-substring-no-properties (point) end-mark)
996 (when (aref (caddr defn) 5)
997 (goto-char (caar (aref (caddr defn) 5)))
998 (c-backward-syntactic-ws)
999 (skip-chars-backward ":"))
1000 (c-backward-syntactic-ws)
1001 (delete-region (point) end-mark)
1003 (concat (cadr defn) "\n{}\n"))))
1005 (defun ccide-grab-inline-decl ()
1006 "Grab the inline decl at point at turn it into an out-of-line inline
1007 declaration at the top of the kill ring."
1009 (let ((defn (c-build-defun (or ccide-default-prefix "inline"))))
1010 (kill-new (ccide-kill-inline-decl defn))
1011 (message (concat (or ccide-default-prefix "indline")
1015 (defun ccide-grab-all-inlines ()
1016 "Grab all inline decls in the current class"
1018 (let ((class (c-parse-class (c-get-block-scope)))
1021 (loop for method in (nreverse (aref class 4))
1022 do (when (eq (car method) 'method)
1023 (let ((defn (save-excursion
1024 (goto-char (cdr method))
1025 (c-build-defun (or ccide-default-prefix "inline")))))
1026 (if (aref (caddr defn) 6)
1027 (setq defns (nconc defns (list (ccide-kill-inline-decl defn))))))))
1028 (setq defns (nreverse defns))
1029 (kill-new (loop for defn in defns
1030 for next = nil then t
1031 if next concat "\n";
1033 (message (format "%d inlines grabed to kill ring" (length defns))))))
1035 (defun ccide-grab-create-constructor ()
1037 (let ((defn (c-build-create-constructor)))
1038 (kill-new (cadr defn))
1039 (message (car defn))))
1041 (defun ccide-grab-create-constructor-impl (&optional prefix)
1043 (let* ((prfx (or (and prefix (nth (prefix-numeric-value prefix) c-user-prefixes))
1044 ccide-default-prefix))
1045 (defn (c-build-create-constructor-impl prfx)))
1046 (kill-new (cadr defn))
1047 (message (concat (or prfx "")
1051 (defun ccide-find-implementation (&optional other-window)
1052 "Find implementation of method declared at point."
1054 (let* ((state (c-get-defun-state))
1055 (name (c-defun-short-name state))
1056 (scoped-name (c-defun-full-name state))
1057 (args (ccide-implementation-args state))
1058 (targs (ccide-implementation-template-args state))
1061 (loop for ext in ccide-implementation-extensions
1062 for filename = (ccide-file-name ext)
1065 (let ((buf (or (find-buffer-visiting filename)
1066 (and (file-readable-p filename)
1067 (find-file-noselect filename)))))
1069 (let ((found (save-excursion
1071 (ccide-find-implementation-1 name scoped-name args targs
1072 (not (aref state 6))
1073 (car (aref state 2))))))
1076 (setq rv (cons buf found))
1077 (if (not fallback) (setq fallback (cons buf found))))))))))
1078 (if (not rv) (setq rv fallback))
1080 (let* ((buf (car rv))
1082 (win (get-buffer-window buf)))
1086 (switch-to-buffer-other-window buf)
1087 (switch-to-buffer buf)))
1090 (c-beginning-of-defun-or-decl))
1091 (message (concat "Implementation of " scoped-name " not found.")))))
1093 (defun ccide-implementation-args (state)
1094 (string-replace "[ \t\n\r]+" ""
1095 (loop for (start . end) in (aref state 3)
1096 for sep = "" then ","
1098 concat (buffer-substring-no-properties
1099 start (save-excursion
1101 (if (search-forward "=" end 'move) (forward-char -1))
1106 (defun ccide-implementation-template-args (state)
1108 (string-replace "[ \t\n\r]+" ""
1109 (loop for (start . end) in (save-excursion
1110 (goto-char (caar (last (aref state 0))))
1111 (c-parse-template-declaration))
1112 for sep = "" then ","
1114 concat (buffer-substring-no-properties
1115 start (save-excursion
1117 (if (search-forward "=" end 'move) (forward-char -1))
1121 (defun ccide-find-implementation-1 (name scoped-name args targs with-body skip-def)
1122 ;; Within the current buffer, search for all implementations of the
1123 ;; given function. The rv is a list of conses. The car holds the
1124 ;; buffer position of the implementation, the cdr is t if the name,
1125 ;; scoped-name and args are matched, otherwise the args did not match.
1127 (goto-char (point-min))
1128 (let ((re (concat (if (eq (char-syntax (aref name 0)) ?w) "\\<" "")
1130 (if (eq (char-syntax (aref name (1- (length name)))) ?w) "\\>" "")))
1131 fallback rv check-state)
1132 (while (and (not rv) (re-search-forward re nil t))
1133 (if (c-save-buffer-state ()
1134 (and (c-at-toplevel-p)
1135 (not (c-in-literal))
1136 (setq check-state (condition-case nil (c-get-defun-state) (error nil)))
1137 (not (= (car (aref check-state 2)) skip-def))))
1138 (if (string= scoped-name (c-defun-full-name check-state))
1139 (if (and (if with-body (aref check-state 6) (not (aref check-state 6)))
1140 (string= args (ccide-implementation-args check-state))
1141 (string= targs (ccide-implementation-template-args check-state)))
1142 (setq rv (cons (point) t))
1144 (setq fallback (cons (point) nil)))))))
1147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1148 ;; variable/type level
1150 (defun ccide-variable-comment ()
1151 "Add a comment to current variable declaration."
1153 (c-forward-out-of-comment)
1154 (c-forward-syntactic-ws)
1155 (while (not (looking-at ";"))
1157 (c-forward-syntactic-ws))
1159 (if (> (current-column) comment-column)
1160 (insert "\n" (make-string comment-column ? ) "///< ")
1161 (indent-to-column comment-column)
1164 (defun ccide-grab-access-fn ()
1168 (if (looking-at (concat c++-simple-type-regexp "[ \t\n\r][a-zA-Z0-9_]+[ \t\n\r]*;"))
1169 (let ((vardef (match-string 0))
1170 (in (make-string c-basic-offset ? ))
1171 type reftype varname fnname argname ws)
1173 (back-to-indentation)
1174 (string-match "^[ \t\n\r]*\\(.*\\)[ \t\n\r]\\([a-zA-Z0-9_]+\\)[ \t\n\r]*;$"
1176 (setq varname (match-string 2 vardef)
1177 type (match-string 1 vardef)
1178 ws (substring vardef 0 (match-beginning 1)))
1179 (if (string-match "_$" varname)
1180 (setq fnname (string-replace "_$" "" varname)
1181 argname (concat "a_" fnname))
1182 (setq fnname (concat "q_" varname)
1183 argname (concat "a_" varname)))
1184 (if (string-match "^[ \t\n\r]*" type)
1185 (setq type (substring type (match-end 0))))
1186 (if (string-match "^[A-Z]" type)
1187 (setq reftype (concat type " const &"))
1188 (setq reftype type))
1189 (kill-new (concat ws type " " fnname "(" reftype " " argname ")\n"
1191 ws in in type " old" varname " = " varname ";\n"
1192 ws in in varname " = " argname ";\n"
1193 ws in in "return old" varname ";\n"
1195 ws reftype " " fnname "() const\n"
1196 ws in "{ return " varname "; }\n"))
1199 (message "No variable found"))))
1201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1202 ;; doxy comment support functions
1204 (defun ccide-special-indent-function ()
1205 "Function to indent doxy comments correctly"
1206 (let ((indent (ccide-in-doxy-comment)))
1208 (let ((lim (save-excursion
1209 (back-to-indentation)
1210 (c-literal-limits)))
1211 (pos (- (point-max) (point))))
1213 (back-to-indentation)
1214 (if (looking-at "*/")
1216 (let ((para (or (save-excursion (re-search-backward "^\\s-*$" (car lim) t))
1218 (if (and (not (looking-at ccide-doxy-tag-re))
1219 (re-search-backward (concat "^\\s-*"
1223 (delete-region (progn (beginning-of-line) (point))
1224 (progn (back-to-indentation) (point)))
1226 (if (> (- (point-max) pos) (point))
1227 (goto-char (- (point-max) pos)))))))
1229 (defun ccide-fill-function ()
1230 "auto-fill function for doxy comments"
1232 (if (not fill-prefix)
1233 (indent-according-to-mode))))
1235 (defun ccide-hide-all-doxy-comments ()
1236 "Hide all doxy comments"
1239 (goto-char (point-min))
1240 (while (re-search-forward "^\\s-*/\\*\\*" nil t)
1243 (if (not (looking-at "\\s-*$"))
1246 (let ((start (point)))
1247 (if (re-search-forward "\\*/" nil t)
1249 (if (looking-at "\\s-*\n")
1252 (let ((overlay (make-overlay start (point))))
1253 (overlay-put overlay 'intangible 'hs)
1254 (overlay-put overlay 'invisible 'hs)))))))
1257 (defun ccide-show-all-comments ()
1261 (goto-char (point-min))
1263 (goto-char (next-overlay-change (point)))
1264 (loop for overlay in (overlays-at (point))
1265 if (eq (overlay-get overlay 'invisible) 'hs)
1266 do (delete-overlay overlay))))
1269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1270 ;; CORBA support (omniORB2)
1272 (defun ccide-get-corba-headers ()
1275 (goto-char (point-min))
1276 (while (re-search-forward "#include\\s-*[\"<]\\([^\">]*\\)\\.hh[\">]" nil t)
1277 (setq files (cons (ccide-match-string 1) files)))
1280 (defun ccide-corba-maybe-build-hh (file)
1281 (let ((skel (ccide-file-name ".hh" file ccide-corba-skel-dir))
1282 (idl (ccide-file-name ".idl" file ccide-corba-idl-dir)))
1283 (if (and (file-readable-p idl)
1284 (or (not (file-readable-p skel))
1285 (file-newer-than-file-p idl skel)))
1286 (let ((buffer (find-buffer-visiting (ccide-file-name ".hh" file))))
1288 (kill-buffer buffer))
1289 (message "Please wait ... building %s" (ccide-file-name ".hh" file))
1290 (if (ccide-shell-command (concat "cd "
1291 (real-path-name ccide-corba-skel-dir)
1293 ccide-corba-idl-command
1294 (if (> (length ccide-corba-idl-dir) 0)
1295 (concat " -I" ccide-corba-idl-dir))
1299 (display-buffer (get-buffer-create "*ccide shell command*"))
1300 (error "Generation of %s failed" (ccide-file-name ".hh")))))
1301 (if (not (file-readable-p skel))
1302 (error "No file %s or %s"
1303 (ccide-file-name ".hh" file) (ccide-file-name ".idl" file)))))
1305 (defun ccide-corba-list-skeletons-1 (hh-file)
1306 (ccide-corba-maybe-build-hh hh-file)
1307 (let ((hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file)))
1312 (goto-char (point-min))
1313 (while (re-search-forward "^\\s-*class\\s-+_sk_\\([a-zA-Z0-9_]+\\)\\s-+:"
1315 (setq skels (cons (ccide-match-string 1) skels)))))
1316 (mapcar (function (lambda (x) (cons x hh-file)))
1317 (sort skels 'string-lessp))))
1319 (defun ccide-corba-list-skeletons ()
1320 (let ((files (ccide-get-corba-headers)))
1321 (loop for file in files
1322 append (ccide-corba-list-skeletons-1 file))))
1324 (defun ccide-gen-corba-impl (class)
1325 (interactive (list (completing-read "Class name of skeleton: "
1326 (ccide-corba-list-skeletons)
1328 (let* ((skels (ccide-corba-list-skeletons))
1329 (hh-file (ccide-file-name ".hh" (cdr (assoc class skels))
1330 ccide-corba-skel-dir))
1331 (hh-buf (find-file-noselect (ccide-file-name ".hh" hh-file
1332 ccide-corba-skel-dir))))
1333 (ccide-gen-class (concat class "_i"))
1334 (insert (make-string c-basic-offset ? ) ": public virtual _sk_" class "\n")
1336 (search-forward "protected:" nil t)
1338 (ccide-gen-corba-impl-methods)
1341 (defun ccide-get-corba-defns (hh-file class)
1342 (let ((hh-buf (find-file-noselect hh-file))
1347 (goto-char (point-min))
1348 (if (not (re-search-forward (concat "^\\s-*class\\s-+_sk_" class "\\s-+:")
1350 (error "CORBA skeleton class not found.")
1351 (search-forward "{")
1353 (let ((end (save-excursion (forward-sexp) (point))))
1354 (while (and (< (point) end)
1355 (< (forward-line 1) 1))
1356 (if (looking-at "\\s-+virtual\\s-+\\(.*)\\)\\s-*=\\s-*0;\\s-*$")
1357 (setq defns (cons (match-string 1) defns))))))))
1360 (defun ccide-gen-corba-impl-methods ()
1362 (let* ((class (c-get-class-at-point))
1365 (error "No class at point."))
1367 (goto-char (aref (car class) 1))
1368 (if (not (re-search-forward ":\\s-*public\\s-*virtual\\s-*_sk_\\([^ \t\n\r{},:]*\\)"
1370 (error "No CORBA impl at point."))
1371 (let* ((name (ccide-match-string 1))
1372 (skels (ccide-corba-list-skeletons))
1373 (hh-file (ccide-file-name ".hh" (cdr (assoc name skels))
1374 ccide-corba-skel-dir))
1375 (defns (ccide-get-corba-defns hh-file name))
1377 (goto-char (aref (car class) 2))
1381 (if (re-search-forward "^\\s-*// CORBA$" end t)
1382 (let ((start (match-beginning 0)))
1383 (if (re-search-forward "^\\s-*// END-CORBA$" end t)
1384 (let ((eend (match-end 0)))
1387 (if (re-search-forward "/\\*\\|//" (match-beginning 0) t)
1388 (if (y-or-n-p "Remove CORBA Funktion comments? (y/n)")
1389 (delete-region start (1+ eend))
1392 (delete-region (point) (progn
1397 (delete-region (point) (progn
1401 (delete-region start (1+ eend))))))
1403 (indent-according-to-mode)
1404 (insert "// CORBA\n")
1405 (loop for defn in defns
1407 (save-excursion (insert defn ";"))
1408 (indent-according-to-mode)
1409 (let ((start (point)) end)
1413 (while (re-search-forward "\\s-+" end t)
1415 (setq end (- end (- (match-end 0) (match-beginning 0) 1))))
1417 (loop with done = nil
1418 while (> (current-column) c-max-def-column)
1419 do (while (and (> (current-column) c-max-def-column)
1420 (search-backward "," start t)))
1421 do (if (looking-at ",")
1426 (indent-according-to-mode)
1428 (setq start (point))
1433 (indent-according-to-mode)
1434 (insert "// END-CORBA\n")))))
1436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 (defun ccide-scan-mantemps ()
1440 "Scan *compilation* buffer for errors and generate manual template
1441 instatiations at point."
1444 (set-buffer "*compilation*")
1445 (goto-char (point-min)))
1447 (set-buffer (get-buffer-create "*mantemps*"))
1449 (loop for temp = (ccide-get-mantemp)
1451 do (insert temp "\n"))
1452 (mantemp-make-mantemps-buffer)
1453 (goto-char (point-min))
1456 (< (forward-line 1) 1))))
1457 (insert-buffer-substring "*mantemps*"))
1459 (defun ccide-get-mantemp ()
1461 (set-buffer "*compilation*")
1462 (if (search-forward "undefined reference to `" nil t)
1463 (let ((start (point)))
1465 (search-backward "'" nil t)
1466 (buffer-substring start (point))))))
1468 (defun ccide-fix-mantemp ()
1469 (let ((end (save-excursion
1470 (end-of-line) (point))))
1471 (if (and (save-excursion (search-forward "(" end t))
1472 (search-forward " class" end t))
1479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1482 (defun ccide-grab-pxd-fn ()
1485 (c-beginning-of-defun-or-decl)
1486 (let ((defn (c-build-pxd)))
1487 (kill-new (cadr defn))
1488 (message (concat (car defn))))))
1490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 (defun ccide-open-compilation-frame ()
1495 (let ((c-frame (selected-frame))
1496 (compilation-frame (make-frame '((minibuffer . nil)
1498 (menu-bar-lines . 0)
1503 (select-frame compilation-frame)
1504 (switch-to-buffer "*compilation*")
1505 (set-window-dedicated-p (selected-window) t)))
1507 (defun ccide-compile (command)
1508 (delete-other-windows)
1509 (split-window-horizontally)
1512 (set-buffer "*compilation*")
1513 (let ((point (point-max)))
1515 (loop for window in (get-buffer-window-list "*compilation*" nil t)
1516 do (set-window-point window point)))))
1518 (defun ccide-compile-compile ()
1520 (ccide-compile (concat "make -k " ccide-compile-opts)))
1522 (defun ccide-compile-clean ()
1524 (ccide-compile (concat "make -k " ccide-compile-opts " clean")))
1526 (defun ccide-compile-cleandepends ()
1528 (ccide-compile (concat "make -k " ccide-compile-opts " cleandepends")))
1530 (defun ccide-compile-kill ()
1532 (set-buffer "*compilation*")
1535 (defun ccide-hide-compilation ()
1537 (let ((active (selected-window)))
1539 (loop for window in (get-buffer-window-list "*compilation*")
1540 do (progn (select-window window)
1541 (switch-to-buffer (other-buffer "*compilation*"))))
1542 (select-window active))))
1544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1545 ;; keymap and installation
1547 (defun ccide-bind-keys (prefix map)
1548 (loop for binding in ccide-bindings
1549 do (apply 'vcmd-define-key
1551 (concat prefix (car binding))
1556 (defun ccide-install-it ()
1560 (local-unset-key "\C-c;")
1561 (local-unset-key [menu-bar IDE])
1562 (ccide-bind-keys "\C-c;" (current-local-map))
1563 (local-set-key "\C-cC" 'ccide-hide-all-doxy-comments)
1564 (local-set-key "\C-cS" 'ccide-show-all-comments)
1565 (set (make-local-variable 'auto-fill-function) 'ccide-fill-function)
1566 (set (make-local-variable 'paragraph-start) (concat "[ \t\f]*$\\|[ \t\f]*" ccide-doxy-tag-re))
1567 (set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
1569 (ccide-project-load-config)
1570 (ccide-directory-load-config)
1571 (ccide-auto-decorate-new-files)
1572 (if ccide-clang-format-command
1573 (add-hook 'write-contents-functions 'ccide-clang-format-buffer nil t)))
1577 (defun clang-format-xmltok-attribute (name)
1578 (loop for attribute in xmltok-attributes
1579 if (string= (buffer-substring-no-properties (xmltok-attribute-name-start attribute)
1580 (xmltok-attribute-name-end attribute))
1582 return (buffer-substring-no-properties (xmltok-attribute-value-start attribute)
1583 (xmltok-attribute-value-end attribute))))
1585 (defun clang-format-parse-replacement-text ()
1586 (cond ((eq tok 'char-ref)
1587 (let ((number-start (+ xmltok-start 2))
1588 (number-end (1- (point))))
1589 (if (not (string= (buffer-substring-no-properties xmltok-start number-start)
1591 (error "invalid character reference"))
1592 (char-to-string (string-to-number (buffer-substring-no-properties number-start
1596 (buffer-substring-no-properties xmltok-start (point)))))
1598 (defun clang-format-parse-replacement ()
1599 (let ((offset (string-to-number (clang-format-xmltok-attribute "offset")))
1600 (length (string-to-number (clang-format-xmltok-attribute "length"))))
1603 (loop for tok = (xmltok-forward)
1604 while (not (eq tok 'end-tag))
1605 concat (clang-format-parse-replacement-text)))))
1607 (defun clang-format-parse-replacements (buffer)
1610 (goto-char (point-min))
1611 (xmltok-forward-prolog)
1612 (loop for tok = (xmltok-forward)
1614 if (and (eq tok 'start-tag)
1615 (string= (buffer-substring-no-properties (1+ xmltok-start) xmltok-name-end)
1617 collect (clang-format-parse-replacement))))
1619 (defun clang-format-apply-replacements (replacements)
1620 (loop for (offset length replacement) in (nreverse replacements)
1622 (goto-char (1+ offset))
1623 (delete-char length)
1624 (insert replacement))))
1626 (defun ccide-clang-format-buffer ()
1628 (if ccide-clang-format-command
1629 (let ((replacementsBuffer (get-buffer-create " *clang-format-replacements*")))
1630 (save-excursion (set-buffer replacementsBuffer) (erase-buffer))
1631 (shell-command-on-region (point-min) (point-max) ccide-clang-format-command
1632 replacementsBuffer nil)
1633 (let ((replacements (clang-format-parse-replacements replacementsBuffer)))
1635 (clang-format-apply-replacements replacements)))))
1638 (defun ccide-project-load-config ()
1639 (if (buffer-file-name)
1640 (let ((conf (ccide-project-search-upwards '(".project.el" "project.el")
1641 (file-name-directory (buffer-file-name)))))
1643 (set (make-local-variable 'ccide-project-root) (file-name-directory conf))
1644 (load-file conf)))))
1646 (defun ccide-project-search-upwards (names &optional base)
1647 "Search for FILE in all directories starting at DIR and going up the directory hierarchy.
1648 DIR defaults to ccide-project-root. If FILE is a list, search for any file in list."
1649 (if (not (consp names))
1650 (setq names (list names)))
1651 (loop for dir = (or base ccide-project-root) then (directory-file-name (file-name-directory dir))
1652 while (not (string= dir "/"))
1653 thereis (loop for name in names
1654 for path = (expand-file-name name dir)
1655 thereis (and (file-readable-p path) path))))
1657 (defun ccide-directory-load-config ()
1658 (if (file-readable-p ".dir.el")
1659 (load-file ".dir.el")))
1661 (add-hook 'c-mode-hook 'ccide-install-it)
1662 (add-hook 'c++-mode-hook 'ccide-install-it)
1663 (add-hook 'c-special-indent-hook 'ccide-special-indent-function)
1665 (loop for extension in ccide-special-extensions
1666 for re = (concat (regexp-quote extension) "$")
1667 if (not (assoc re auto-mode-alist))
1668 do (setq auto-mode-alist (append auto-mode-alist
1669 (list (cons re 'c++-mode)))))
1671 (defadvice c-indent-line (after c-indent-less compile disable) ;activate
1672 ;; new indent function for c-mode: do standard indentation first. If line
1673 ;; is to long using standard indentation, just indent by c-basic-indentation.
1674 (let ((cc (save-excursion (end-of-line) (current-column)))
1677 (let ((pos (- (point-max) (point))))
1679 (let ((point (point))
1680 (line (1+ (count-lines 1 (point))))
1682 (c-beginning-of-statement-2)
1683 (if (and (not (c-crosses-statement-barrier-p (point) point))
1684 (not (eq (+ (count-lines 1 (point))
1688 (setq indent (+ (current-indentation) c-basic-offset))
1690 (if (< indent (current-indentation))
1692 (setq ad-return-value
1694 (- (current-indentation) indent)))
1695 (delete-region (c-point 'bol) (c-point 'boi))
1696 (indent-to indent))))))
1697 (if (< (point) (c-point 'boi))
1698 (back-to-indentation)
1699 (if (> (- (point-max) pos) (point))
1700 (goto-char (- (point-max) pos))))))))
1703 ;;; Local Variables:
1704 ;;; elisp-project-autoload-file-name: "cc-autoload.el"