Mercurial > emacs
comparison lisp/cedet/cedet-idutils.el @ 104407:4af663a1c4ab
cedet-cscope.el, cedet-edebug.el, cedet-global.el, cedet-idutils.el,
cedet.el, inversion.el, pulse.el: Initial version, from CEDET's
common/ directory.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 22 Aug 2009 19:04:43 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
104406:399d233ddb97 | 104407:4af663a1c4ab |
---|---|
1 ;;; cedet-idutils.el --- ID Utils support for CEDET. | |
2 | |
3 ;;; Copyright (C) 2009 Free Software Foundation, Inc. | |
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 (defvar cedet-idutils-min-version "4.0" | |
32 "Minimum version of ID Utils required.") | |
33 | |
34 (defcustom cedet-idutils-file-command "fnid" | |
35 "Command name for the ID Utils executable for searching file names." | |
36 :type 'string | |
37 :group 'cedet) | |
38 | |
39 (defcustom cedet-idutils-token-command "lid" | |
40 "Command name for the ID Utils executable for searching for tokens." | |
41 :type 'string | |
42 :group 'cedet) | |
43 | |
44 (defun cedet-idutils-search (searchtext texttype type scope) | |
45 "Perform a search with IDUtils, return the created buffer. | |
46 SEARCHTEXT is text to find. | |
47 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
48 'tagregexp, or 'tagcompletions. | |
49 TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
50 filename, tagname (tags table), references (uses of a tag) , or | |
51 symbol (uses of something not in the tag table.) | |
52 SCOPE is the scope of the search, such as 'project or 'subdirs. | |
53 Note: Scope is not yet supported." | |
54 (if (eq type 'file) | |
55 ;; Calls for file stuff is very simple. | |
56 (cedet-idutils-fnid-call (list searchtext)) | |
57 ;; Calls for text searches is more complex. | |
58 (let* ((resultflg (if (eq texttype 'tagcompletions) | |
59 (list "--key=token") | |
60 (list "--result=grep"))) | |
61 (scopeflgs nil) ; (cond ((eq scope 'project) "" ) ((eq scope 'target) "l"))) | |
62 (stflag (cond ((or (eq texttype 'tagname) | |
63 (eq texttype 'tagregexp)) | |
64 (list "-r" "-w")) | |
65 ((eq texttype 'tagcompletions) | |
66 ;; Add regex to search text for beginning of char. | |
67 (setq searchtext (concat "^" searchtext)) | |
68 (list "-r" "-s" )) | |
69 ((eq texttype 'regexp) | |
70 (list "-r")) | |
71 ;; t means 'symbol | |
72 (t (list "-l" "-w")))) | |
73 ) | |
74 (cedet-idutils-lid-call (append resultflg scopeflgs stflag (list searchtext)))) | |
75 )) | |
76 | |
77 (defun cedet-idutils-fnid-call (flags) | |
78 "Call ID Utils fnid with the list of FLAGS. | |
79 Return the created buffer with with program output." | |
80 (let ((b (get-buffer-create "*CEDET fnid*")) | |
81 (cd default-directory) | |
82 ) | |
83 (save-excursion | |
84 (set-buffer b) | |
85 (setq default-directory cd) | |
86 (erase-buffer)) | |
87 (apply 'call-process cedet-idutils-file-command | |
88 nil b nil | |
89 flags) | |
90 b)) | |
91 | |
92 (defun cedet-idutils-lid-call (flags) | |
93 "Call ID Utils lid with the list of FLAGS. | |
94 Return the created buffer with with program output." | |
95 (let ((b (get-buffer-create "*CEDET lid*")) | |
96 (cd default-directory) | |
97 ) | |
98 (save-excursion | |
99 (set-buffer b) | |
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) | |
110 "Expand the FILENAME with IDUtils. | |
111 Return a filename relative to the default directory." | |
112 (interactive "sFile: ") | |
113 (let ((ans (save-excursion | |
114 (set-buffer (cedet-idutils-fnid-call (list filename))) | |
115 (goto-char (point-min)) | |
116 (if (looking-at "[^ \n]*fnid: ") | |
117 (error "ID Utils not available") | |
118 (split-string (buffer-string) "\n" t))))) | |
119 (setq ans (mapcar 'expand-file-name ans)) | |
120 (when (interactive-p) | |
121 (if ans | |
122 (if (= (length ans) 1) | |
123 (message "%s" (car ans)) | |
124 (message "%s + %d others" (car ans) | |
125 (length (cdr ans)))) | |
126 (error "No file found"))) | |
127 ans)) | |
128 | |
129 (defun cedet-idutils-support-for-directory (&optional dir) | |
130 "Return non-nil if IDUtils has a support file for DIR. | |
131 If DIR is not supplied, use the current default directory. | |
132 This works by running lid on a bogus symbol, and looking for | |
133 the error code." | |
134 (save-excursion | |
135 (let ((default-directory (or dir default-directory))) | |
136 (condition-case nil | |
137 (progn | |
138 (set-buffer (cedet-idutils-fnid-call '("moose"))) | |
139 (goto-char (point-min)) | |
140 (if (looking-at "[^ \n]*fnid: ") | |
141 nil | |
142 t)) | |
143 (error nil))))) | |
144 | |
145 (declare-function inversion-check-version "inversion") | |
146 | |
147 (defun cedet-idutils-version-check (&optional noerror) | |
148 "Check the version of the installed ID Utils command. | |
149 If optional programatic argument NOERROR is non-nil, then | |
150 instead of throwing an error if Global isn't available, then | |
151 return nil." | |
152 (interactive) | |
153 (require 'inversion) | |
154 (let ((b (condition-case nil | |
155 (cedet-idutils-fnid-call (list "--version")) | |
156 (error nil))) | |
157 (rev nil)) | |
158 (if (not b) | |
159 (progn | |
160 (when (interactive-p) | |
161 (message "ID Utils not found.")) | |
162 nil) | |
163 (save-excursion | |
164 (set-buffer b) | |
165 (goto-char (point-min)) | |
166 (re-search-forward "fnid - \\([0-9.]+\\)" nil t) | |
167 (setq rev (match-string 1)) | |
168 (if (inversion-check-version rev nil cedet-idutils-min-version) | |
169 (if noerror | |
170 nil | |
171 (error "Version of ID Utis is %s. Need at least %s" | |
172 rev cedet-idutils-min-version)) | |
173 ;; Else, return TRUE, as in good enough. | |
174 (when (interactive-p) | |
175 (message "ID Utils %s - Good enough for CEDET." rev)) | |
176 t))))) | |
177 | |
178 | |
179 (provide 'cedet-idutils) | |
180 | |
181 ;;; cedet-idutils.el ends here |