105241
|
1 ;;; cedet-idutils.el --- ID Utils support for CEDET.
|
|
2
|
105325
|
3 ;; Copyright (C) 2009 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 )
|
|
85 (save-excursion
|
|
86 (set-buffer b)
|
|
87 (setq default-directory cd)
|
|
88 (erase-buffer))
|
|
89 (apply 'call-process cedet-idutils-file-command
|
|
90 nil b nil
|
|
91 flags)
|
|
92 b))
|
|
93
|
|
94 (defun cedet-idutils-lid-call (flags)
|
|
95 "Call ID Utils lid with the list of FLAGS.
|
|
96 Return the created buffer with with program output."
|
|
97 (let ((b (get-buffer-create "*CEDET lid*"))
|
|
98 (cd default-directory)
|
|
99 )
|
|
100 (save-excursion
|
|
101 (set-buffer b)
|
|
102 (setq default-directory cd)
|
|
103 (erase-buffer))
|
|
104 (apply 'call-process cedet-idutils-token-command
|
|
105 nil b nil
|
|
106 flags)
|
|
107 b))
|
|
108
|
|
109 ;;; UTIL CALLS
|
|
110 ;;
|
|
111 (defun cedet-idutils-expand-filename (filename)
|
105325
|
112 "Expand the FILENAME with ID Utils.
|
105241
|
113 Return a filename relative to the default directory."
|
|
114 (interactive "sFile: ")
|
|
115 (let ((ans (save-excursion
|
|
116 (set-buffer (cedet-idutils-fnid-call (list filename)))
|
|
117 (goto-char (point-min))
|
|
118 (if (looking-at "[^ \n]*fnid: ")
|
|
119 (error "ID Utils not available")
|
|
120 (split-string (buffer-string) "\n" t)))))
|
|
121 (setq ans (mapcar 'expand-file-name ans))
|
|
122 (when (interactive-p)
|
|
123 (if ans
|
|
124 (if (= (length ans) 1)
|
|
125 (message "%s" (car ans))
|
|
126 (message "%s + %d others" (car ans)
|
|
127 (length (cdr ans))))
|
|
128 (error "No file found")))
|
|
129 ans))
|
|
130
|
|
131 (defun cedet-idutils-support-for-directory (&optional dir)
|
105325
|
132 "Return non-nil if ID Utils has a support file for DIR.
|
105241
|
133 If DIR is not supplied, use the current default directory.
|
|
134 This works by running lid on a bogus symbol, and looking for
|
|
135 the error code."
|
|
136 (save-excursion
|
|
137 (let ((default-directory (or dir default-directory)))
|
|
138 (condition-case nil
|
|
139 (progn
|
|
140 (set-buffer (cedet-idutils-fnid-call '("moose")))
|
|
141 (goto-char (point-min))
|
|
142 (if (looking-at "[^ \n]*fnid: ")
|
|
143 nil
|
|
144 t))
|
|
145 (error nil)))))
|
|
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
|
105325
|
171 (error "Version of ID Utils is %s. Need at least %s"
|
105241
|
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
|
105377
|
181 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501
|
105241
|
182 ;;; cedet-idutils.el ends here
|