Mercurial > emacs
annotate lisp/cedet/cedet-idutils.el @ 111390:d30a1f654ca5
* lisp/progmodes/tcl.el (tcl-hairy-scan-for-comment): Doc fix.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 08 Nov 2010 23:41:57 -0800 |
parents | b150a06c6999 |
children | b799d38f522a 376148b31b5e |
rev | line source |
---|---|
105241 | 1 ;;; cedet-idutils.el --- ID Utils support for CEDET. |
2 | |
106815 | 3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
105241 | 4 |
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 ;; Version: 0.2 | |
7 ;; Keywords: OO, lisp | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation, either version 3 of the License, or | |
14 ;; (at your option) any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | |
24 ;;; Commentary: | |
25 ;; | |
26 ;; Basic support calling ID Utils functions, and checking version | |
27 ;; numbers. | |
28 | |
29 ;;; Code: | |
30 | |
31 (declare-function inversion-check-version "inversion") | |
32 | |
33 (defvar cedet-idutils-min-version "4.0" | |
34 "Minimum version of ID Utils required.") | |
35 | |
36 (defcustom cedet-idutils-file-command "fnid" | |
37 "Command name for the ID Utils executable for searching file names." | |
38 :type 'string | |
39 :group 'cedet) | |
40 | |
41 (defcustom cedet-idutils-token-command "lid" | |
42 "Command name for the ID Utils executable for searching for tokens." | |
43 :type 'string | |
44 :group 'cedet) | |
45 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
46 (defcustom cedet-idutils-make-command "mkid" |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
47 "Command name for the ID Utils executable for creating token databases." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
48 :type 'string |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
49 :group 'cedet) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
50 |
105241 | 51 (defun cedet-idutils-search (searchtext texttype type scope) |
105325 | 52 "Perform a search with ID Utils, return the created buffer. |
105241 | 53 SEARCHTEXT is text to find. |
54 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
55 'tagregexp, or 'tagcompletions. | |
56 TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
57 filename, tagname (tags table), references (uses of a tag) , or | |
58 symbol (uses of something not in the tag table.) | |
59 SCOPE is the scope of the search, such as 'project or 'subdirs. | |
60 Note: Scope is not yet supported." | |
61 (if (eq type 'file) | |
62 ;; Calls for file stuff is very simple. | |
63 (cedet-idutils-fnid-call (list searchtext)) | |
64 ;; Calls for text searches is more complex. | |
65 (let* ((resultflg (if (eq texttype 'tagcompletions) | |
66 (list "--key=token") | |
67 (list "--result=grep"))) | |
68 (scopeflgs nil) ; (cond ((eq scope 'project) "" ) ((eq scope 'target) "l"))) | |
69 (stflag (cond ((or (eq texttype 'tagname) | |
70 (eq texttype 'tagregexp)) | |
71 (list "-r" "-w")) | |
72 ((eq texttype 'tagcompletions) | |
73 ;; Add regex to search text for beginning of char. | |
74 (setq searchtext (concat "^" searchtext)) | |
75 (list "-r" "-s" )) | |
76 ((eq texttype 'regexp) | |
77 (list "-r")) | |
78 ;; t means 'symbol | |
79 (t (list "-l" "-w")))) | |
80 ) | |
81 (cedet-idutils-lid-call (append resultflg scopeflgs stflag | |
82 (list searchtext)))))) | |
83 | |
84 (defun cedet-idutils-fnid-call (flags) | |
85 "Call ID Utils fnid with the list of FLAGS. | |
86 Return the created buffer with with program output." | |
87 (let ((b (get-buffer-create "*CEDET fnid*")) | |
88 (cd default-directory) | |
89 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
90 (with-current-buffer b |
105241 | 91 (setq default-directory cd) |
92 (erase-buffer)) | |
93 (apply 'call-process cedet-idutils-file-command | |
94 nil b nil | |
95 flags) | |
96 b)) | |
97 | |
98 (defun cedet-idutils-lid-call (flags) | |
99 "Call ID Utils lid with the list of FLAGS. | |
100 Return the created buffer with with program output." | |
101 (let ((b (get-buffer-create "*CEDET lid*")) | |
102 (cd default-directory) | |
103 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
104 (with-current-buffer b |
105241 | 105 (setq default-directory cd) |
106 (erase-buffer)) | |
107 (apply 'call-process cedet-idutils-token-command | |
108 nil b nil | |
109 flags) | |
110 b)) | |
111 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
112 (defun cedet-idutils-mkid-call (flags) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
113 "Call ID Utils mkid with the list of FLAGS. |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
114 Return the created buffer with with program output." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
115 (let ((b (get-buffer-create "*CEDET mkid*")) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
116 (cd default-directory) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
117 ) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
118 (with-current-buffer b |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
119 (setq default-directory cd) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
120 (erase-buffer)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
121 (apply 'call-process cedet-idutils-make-command |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
122 nil b nil |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
123 flags) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
124 b)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
125 |
105241 | 126 ;;; UTIL CALLS |
127 ;; | |
128 (defun cedet-idutils-expand-filename (filename) | |
105325 | 129 "Expand the FILENAME with ID Utils. |
105241 | 130 Return a filename relative to the default directory." |
131 (interactive "sFile: ") | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
132 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename)) |
105241 | 133 (goto-char (point-min)) |
134 (if (looking-at "[^ \n]*fnid: ") | |
135 (error "ID Utils not available") | |
136 (split-string (buffer-string) "\n" t))))) | |
137 (setq ans (mapcar 'expand-file-name ans)) | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
138 (when (called-interactively-p 'interactive) |
105241 | 139 (if ans |
140 (if (= (length ans) 1) | |
141 (message "%s" (car ans)) | |
142 (message "%s + %d others" (car ans) | |
143 (length (cdr ans)))) | |
144 (error "No file found"))) | |
145 ans)) | |
146 | |
147 (defun cedet-idutils-support-for-directory (&optional dir) | |
105325 | 148 "Return non-nil if ID Utils has a support file for DIR. |
105241 | 149 If DIR is not supplied, use the current default directory. |
150 This works by running lid on a bogus symbol, and looking for | |
151 the error code." | |
152 (save-excursion | |
153 (let ((default-directory (or dir default-directory))) | |
154 (condition-case nil | |
155 (progn | |
156 (set-buffer (cedet-idutils-fnid-call '("moose"))) | |
157 (goto-char (point-min)) | |
158 (if (looking-at "[^ \n]*fnid: ") | |
159 nil | |
160 t)) | |
161 (error nil))))) | |
162 | |
163 (defun cedet-idutils-version-check (&optional noerror) | |
164 "Check the version of the installed ID Utils command. | |
165 If optional programatic argument NOERROR is non-nil, then | |
166 instead of throwing an error if Global isn't available, then | |
167 return nil." | |
168 (interactive) | |
169 (require 'inversion) | |
170 (let ((b (condition-case nil | |
171 (cedet-idutils-fnid-call (list "--version")) | |
172 (error nil))) | |
173 (rev nil)) | |
174 (if (not b) | |
175 (progn | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
176 (when (called-interactively-p 'interactive) |
105241 | 177 (message "ID Utils not found.")) |
178 nil) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
179 (with-current-buffer b |
105241 | 180 (goto-char (point-min)) |
181 (re-search-forward "fnid - \\([0-9.]+\\)" nil t) | |
182 (setq rev (match-string 1)) | |
183 (if (inversion-check-version rev nil cedet-idutils-min-version) | |
184 (if noerror | |
185 nil | |
105325 | 186 (error "Version of ID Utils is %s. Need at least %s" |
105241 | 187 rev cedet-idutils-min-version)) |
188 ;; Else, return TRUE, as in good enough. | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
189 (when (called-interactively-p 'interactive) |
105241 | 190 (message "ID Utils %s - Good enough for CEDET." rev)) |
191 t))))) | |
192 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
193 (defun cedet-idutils-create/update-database (&optional dir) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
194 "Create an IDUtils database in DIR. |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
195 IDUtils must start from scratch when updating a database." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
196 (interactive "DDirectory: ") |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
197 (let ((default-directory dir)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
198 (cedet-idutils-mkid-call nil))) |
105241 | 199 |
200 (provide 'cedet-idutils) | |
201 | |
105377 | 202 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501 |
105241 | 203 ;;; cedet-idutils.el ends here |