minor documentation updates
[emacs.git] / lisp / cedet / srecode / expandproto.el
blob1ddaa1acdeae8c72a47cb2f19335699a72849070
1 ;;; srecode/expandproto.el --- Expanding prototypes.
3 ;; Copyright (C) 2007, 2009-2012 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/>.
22 ;;; Commentary:
24 ;; Methods for expanding a prototype into an implementation.
26 (require 'ring)
27 (require 'semantic)
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")
35 ;;; Code:
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."
41 :group 'srecode
42 :type '(repeat (cons (sexp :tag "Mode")
43 (sexp :tag "Filename"))
46 ;;;###autoload
47 (defun srecode-insert-prototype-expansion ()
48 "Insert get/set methods for the current class."
49 (interactive)
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))
58 (let ((proto
59 ;; Step 1: Find the prototype, or prototype list to expand.
60 (srecode-find-prototype-for-expansion)))
62 (if (not proto)
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.
74 (let ((proto nil)
77 ;; 1) A class full of prototypes under point.
78 (let ((tag (semantic-current-tag)))
79 (when 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
87 :prototype t
88 (semantic-tag-type-members tag))
89 (setq proto tag)))
92 ;; 2) A prototype under point.
93 (when (not proto)
94 (let ((tag (semantic-current-tag)))
95 (when (and tag
96 (and
97 (semantic-tag-of-class-p tag 'function)
98 (semantic-tag-get-attribute tag :prototype)))
99 (setq proto tag))))
101 ;; 3) A tag in the kill ring that is a prototype
102 (when (not proto)
103 (if (ring-empty-p senator-tag-ring)
104 nil ;; Not for us.
105 (let ((tag (ring-ref senator-tag-ring 0))
107 (when
108 (and tag
110 (and
111 (semantic-tag-of-class-p tag 'function)
112 (semantic-tag-get-attribute tag :prototype))
113 (and
114 (semantic-tag-of-class-p tag 'type)
115 (require 'semantic/find)
116 (semantic-brute-find-tag-by-attribute-value
117 :prototype t
118 (semantic-tag-type-members tag))))
120 (setq proto tag))
123 proto))
125 (provide 'srecode/expandproto)
127 ;; Local variables:
128 ;; generated-autoload-file: "loaddefs.el"
129 ;; generated-autoload-load-name: "srecode/expandproto"
130 ;; End:
132 ;;; srecode/expandproto.el ends here