Mercurial > emacs
annotate lisp/cedet/cedet-idutils.el @ 109351:c8a969d13eda
merge trunk
author | Kenichi Handa <handa@etlken> |
---|---|
date | Fri, 09 Jul 2010 15:55:27 +0900 |
parents | 1d1d5d9bd884 |
children | 280c8ae2476d b150a06c6999 |
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 | |
46 (defun cedet-idutils-search (searchtext texttype type scope) | |
105325 | 47 "Perform a search with ID Utils, return the created buffer. |
105241 | 48 SEARCHTEXT is text to find. |
49 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
50 'tagregexp, or 'tagcompletions. | |
51 TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
52 filename, tagname (tags table), references (uses of a tag) , or | |
53 symbol (uses of something not in the tag table.) | |
54 SCOPE is the scope of the search, such as 'project or 'subdirs. | |
55 Note: Scope is not yet supported." | |
56 (if (eq type 'file) | |
57 ;; Calls for file stuff is very simple. | |
58 (cedet-idutils-fnid-call (list searchtext)) | |
59 ;; Calls for text searches is more complex. | |
60 (let* ((resultflg (if (eq texttype 'tagcompletions) | |
61 (list "--key=token") | |
62 (list "--result=grep"))) | |
63 (scopeflgs nil) ; (cond ((eq scope 'project) "" ) ((eq scope 'target) "l"))) | |
64 (stflag (cond ((or (eq texttype 'tagname) | |
65 (eq texttype 'tagregexp)) | |
66 (list "-r" "-w")) | |
67 ((eq texttype 'tagcompletions) | |
68 ;; Add regex to search text for beginning of char. | |
69 (setq searchtext (concat "^" searchtext)) | |
70 (list "-r" "-s" )) | |
71 ((eq texttype 'regexp) | |
72 (list "-r")) | |
73 ;; t means 'symbol | |
74 (t (list "-l" "-w")))) | |
75 ) | |
76 (cedet-idutils-lid-call (append resultflg scopeflgs stflag | |
77 (list searchtext)))))) | |
78 | |
79 (defun cedet-idutils-fnid-call (flags) | |
80 "Call ID Utils fnid with the list of FLAGS. | |
81 Return the created buffer with with program output." | |
82 (let ((b (get-buffer-create "*CEDET fnid*")) | |
83 (cd default-directory) | |
84 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
85 (with-current-buffer b |
105241 | 86 (setq default-directory cd) |
87 (erase-buffer)) | |
88 (apply 'call-process cedet-idutils-file-command | |
89 nil b nil | |
90 flags) | |
91 b)) | |
92 | |
93 (defun cedet-idutils-lid-call (flags) | |
94 "Call ID Utils lid with the list of FLAGS. | |
95 Return the created buffer with with program output." | |
96 (let ((b (get-buffer-create "*CEDET lid*")) | |
97 (cd default-directory) | |
98 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
99 (with-current-buffer b |
105241 | 100 (setq default-directory cd) |
101 (erase-buffer)) | |
102 (apply 'call-process cedet-idutils-token-command | |
103 nil b nil | |
104 flags) | |
105 b)) | |
106 | |
107 ;;; UTIL CALLS | |
108 ;; | |
109 (defun cedet-idutils-expand-filename (filename) | |
105325 | 110 "Expand the FILENAME with ID Utils. |
105241 | 111 Return a filename relative to the default directory." |
112 (interactive "sFile: ") | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
113 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename)) |
105241 | 114 (goto-char (point-min)) |
115 (if (looking-at "[^ \n]*fnid: ") | |
116 (error "ID Utils not available") | |
117 (split-string (buffer-string) "\n" t))))) | |
118 (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
|
119 (when (called-interactively-p 'interactive) |
105241 | 120 (if ans |
121 (if (= (length ans) 1) | |
122 (message "%s" (car ans)) | |
123 (message "%s + %d others" (car ans) | |
124 (length (cdr ans)))) | |
125 (error "No file found"))) | |
126 ans)) | |
127 | |
128 (defun cedet-idutils-support-for-directory (&optional dir) | |
105325 | 129 "Return non-nil if ID Utils has a support file for DIR. |
105241 | 130 If DIR is not supplied, use the current default directory. |
131 This works by running lid on a bogus symbol, and looking for | |
132 the error code." | |
133 (save-excursion | |
134 (let ((default-directory (or dir default-directory))) | |
135 (condition-case nil | |
136 (progn | |
137 (set-buffer (cedet-idutils-fnid-call '("moose"))) | |
138 (goto-char (point-min)) | |
139 (if (looking-at "[^ \n]*fnid: ") | |
140 nil | |
141 t)) | |
142 (error nil))))) | |
143 | |
144 (defun cedet-idutils-version-check (&optional noerror) | |
145 "Check the version of the installed ID Utils command. | |
146 If optional programatic argument NOERROR is non-nil, then | |
147 instead of throwing an error if Global isn't available, then | |
148 return nil." | |
149 (interactive) | |
150 (require 'inversion) | |
151 (let ((b (condition-case nil | |
152 (cedet-idutils-fnid-call (list "--version")) | |
153 (error nil))) | |
154 (rev nil)) | |
155 (if (not b) | |
156 (progn | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
157 (when (called-interactively-p 'interactive) |
105241 | 158 (message "ID Utils not found.")) |
159 nil) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
160 (with-current-buffer b |
105241 | 161 (goto-char (point-min)) |
162 (re-search-forward "fnid - \\([0-9.]+\\)" nil t) | |
163 (setq rev (match-string 1)) | |
164 (if (inversion-check-version rev nil cedet-idutils-min-version) | |
165 (if noerror | |
166 nil | |
105325 | 167 (error "Version of ID Utils is %s. Need at least %s" |
105241 | 168 rev cedet-idutils-min-version)) |
169 ;; 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
|
170 (when (called-interactively-p 'interactive) |
105241 | 171 (message "ID Utils %s - Good enough for CEDET." rev)) |
172 t))))) | |
173 | |
174 | |
175 (provide 'cedet-idutils) | |
176 | |
105377 | 177 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501 |
105241 | 178 ;;; cedet-idutils.el ends here |