Mercurial > emacs
annotate lisp/cedet/srecode/expandproto.el @ 106032:42cdafa98c50
(mode-line-buffer-identification): Do not purecopy.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sun, 15 Nov 2009 20:25:55 +0000 |
parents | 83dde921cc1b |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
104498 | 1 ;;; srecode/expandproto.el --- Expanding prototypes. |
2 | |
105284 | 3 ;; Copyright (C) 2007, 2009 Free Software Foundation, Inc. |
104498 | 4 |
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
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. | |
13 | |
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. | |
18 | |
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/>. | |
21 | |
22 ;;; Commentary: | |
23 ;; | |
24 ;; Methods for expanding a prototype into an implementation. | |
25 | |
26 (require 'ring) | |
27 (require 'semantic) | |
28 (require 'semantic/analyze) | |
105260
bbd7017a25d9
CEDET (development tools) package merged.
Chong Yidong <cyd@stupidchicken.com>
parents:
104498
diff
changeset
|
29 (require 'semantic/senator) |
104498 | 30 (require 'srecode/insert) |
31 (require 'srecode/dictionary) | |
32 | |
33 (declare-function semantic-brute-find-tag-by-attribute-value "semantic/find") | |
34 | |
35 ;;; Code: | |
36 (defcustom srecode-expandproto-template-file-alist | |
37 '( ( c++-mode . "srecode-expandproto-cpp.srt" ) | |
38 ) | |
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")) | |
44 )) | |
45 | |
46 ;;;###autoload | |
47 (defun srecode-insert-prototype-expansion () | |
48 "Insert get/set methods for the current class." | |
49 (interactive) | |
50 | |
51 (srecode-load-tables-for-mode major-mode) | |
52 (srecode-load-tables-for-mode major-mode | |
53 srecode-expandproto-template-file-alist) | |
54 | |
55 (if (not (srecode-table)) | |
56 (error "No template table found for mode %s" major-mode)) | |
57 | |
58 (let ((proto | |
59 ;; Step 1: Find the prototype, or prototype list to expand. | |
60 (srecode-find-prototype-for-expansion))) | |
61 | |
62 (if (not proto) | |
63 (error "Could not find prototype to expand")) | |
64 | |
65 ;; Step 2: Insert implementations of the prototypes. | |
66 | |
67 | |
68 )) | |
69 | |
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) | |
75 ) | |
76 | |
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))) | |
90 ) | |
91 | |
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)))) | |
100 | |
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)) | |
106 ) | |
107 (when | |
108 (and tag | |
109 (or | |
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)))) | |
119 ) | |
120 (setq proto tag)) | |
121 ))) | |
122 | |
123 proto)) | |
124 | |
105313
068b13ebb340
* cedet/srecode/expandproto.el: Fix provide statement.
Juanma Barranquero <lekktu@gmail.com>
parents:
105284
diff
changeset
|
125 (provide 'srecode/expandproto) |
104498 | 126 |
127 ;; Local variables: | |
128 ;; generated-autoload-file: "loaddefs.el" | |
129 ;; generated-autoload-load-name: "srecode/expandproto" | |
130 ;; End: | |
131 | |
105377 | 132 ;; arch-tag: f0371b5f-9bec-46a1-9b5d-8dff0e897426 |
104498 | 133 ;;; srecode/expandproto.el ends here |