1 ;;; srecode/expandproto.el --- Expanding prototypes.
3 ;; Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; Methods for expanding a prototype into an implementation.
28 (require 'semantic
/analyze
)
29 (require 'semantic
/senator
)
30 (require 'srecode
/insert
)
31 (require 'srecode
/dictionary
)
33 (declare-function semantic-brute-find-tag-by-attribute-value
"semantic/find")
36 (defcustom srecode-expandproto-template-file-alist
37 '( ( c
++-mode .
"srecode-expandproto-cpp.srt" )
39 ;; @todo - Make this variable auto-generated from the Makefile.
40 "Associate template files for expanding prototypes to a major mode."
42 :type
'(repeat (cons (sexp :tag
"Mode")
43 (sexp :tag
"Filename"))
47 (defun srecode-insert-prototype-expansion ()
48 "Insert get/set methods for the current class."
51 (srecode-load-tables-for-mode major-mode
)
52 (srecode-load-tables-for-mode major-mode
53 srecode-expandproto-template-file-alist
)
55 (if (not (srecode-table))
56 (error "No template table found for mode %s" major-mode
))
59 ;; Step 1: Find the prototype, or prototype list to expand.
60 (srecode-find-prototype-for-expansion)))
63 (error "Could not find prototype to expand"))
65 ;; Step 2: Insert implementations of the prototypes.
70 (defun srecode-find-prototype-for-expansion ()
71 "Find a prototype to use for expanding into an implementation."
72 ;; We may find a prototype tag in one of several places.
73 ;; Search in order of logical priority.
77 ;; 1) A class full of prototypes under point.
78 (let ((tag (semantic-current-tag)))
80 (when (not (semantic-tag-of-class-p tag
'type
))
81 (setq tag
(semantic-current-tag-parent))))
82 (when (and tag
(semantic-tag-of-class-p tag
'type
))
83 ;; If the current class has prototype members, then
84 ;; we will do the whole class!
85 (require 'semantic
/find
)
86 (if (semantic-brute-find-tag-by-attribute-value
88 (semantic-tag-type-members tag
))
92 ;; 2) A prototype under point.
94 (let ((tag (semantic-current-tag)))
97 (semantic-tag-of-class-p tag
'function
)
98 (semantic-tag-get-attribute tag
:prototype
)))
101 ;; 3) A tag in the kill ring that is a prototype
103 (if (ring-empty-p senator-tag-ring
)
105 (let ((tag (ring-ref senator-tag-ring
0))
111 (semantic-tag-of-class-p tag
'function
)
112 (semantic-tag-get-attribute tag
:prototype
))
114 (semantic-tag-of-class-p tag
'type
)
115 (require 'semantic
/find
)
116 (semantic-brute-find-tag-by-attribute-value
118 (semantic-tag-type-members tag
))))
125 (provide 'srecode
/expandproto
)
128 ;; generated-autoload-file: "loaddefs.el"
129 ;; generated-autoload-load-name: "srecode/expandproto"
132 ;;; srecode/expandproto.el ends here