1 ;;; cedet-idutils.el --- ID Utils support for CEDET.
3 ;; Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
26 ;; Basic support calling ID Utils functions, and checking version
31 (declare-function inversion-check-version
"inversion")
33 (defvar cedet-idutils-min-version
"4.0"
34 "Minimum version of ID Utils required.")
36 (defcustom cedet-idutils-file-command
"fnid"
37 "Command name for the ID Utils executable for searching file names."
41 (defcustom cedet-idutils-token-command
"lid"
42 "Command name for the ID Utils executable for searching for tokens."
46 (defcustom cedet-idutils-make-command
"mkid"
47 "Command name for the ID Utils executable for creating token databases."
51 (defun cedet-idutils-search (searchtext texttype type scope
)
52 "Perform a search with ID Utils, return the created buffer.
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."
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
)
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
))
72 ((eq texttype
'tagcompletions
)
73 ;; Add regex to search text for beginning of char.
74 (setq searchtext
(concat "^" searchtext
))
76 ((eq texttype
'regexp
)
79 (t (list "-l" "-w"))))
81 (cedet-idutils-lid-call (append resultflg scopeflgs stflag
82 (list searchtext
))))))
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
)
90 (with-current-buffer b
91 (setq default-directory cd
)
93 (apply 'call-process cedet-idutils-file-command
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
)
104 (with-current-buffer b
105 (setq default-directory cd
)
107 (apply 'call-process cedet-idutils-token-command
112 (defun cedet-idutils-mkid-call (flags)
113 "Call ID Utils mkid with the list of FLAGS.
114 Return the created buffer with with program output."
115 (let ((b (get-buffer-create "*CEDET mkid*"))
116 (cd default-directory
)
118 (with-current-buffer b
119 (setq default-directory cd
)
121 (apply 'call-process cedet-idutils-make-command
128 (defun cedet-idutils-expand-filename (filename)
129 "Expand the FILENAME with ID Utils.
130 Return a filename relative to the default directory."
131 (interactive "sFile: ")
132 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename
))
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
))
138 (when (called-interactively-p 'interactive
)
140 (if (= (length ans
) 1)
141 (message "%s" (car ans
))
142 (message "%s + %d others" (car ans
)
144 (error "No file found")))
147 (defun cedet-idutils-support-for-directory (&optional dir
)
148 "Return non-nil if ID Utils has a support file for DIR.
149 If DIR is not supplied, use the current default directory.
150 This works by running lid on a bogus symbol, and looking for
153 (let ((default-directory (or dir default-directory
)))
156 (set-buffer (cedet-idutils-fnid-call '("moose")))
157 (goto-char (point-min))
158 (if (looking-at "[^ \n]*fnid: ")
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
170 (let ((b (condition-case nil
171 (cedet-idutils-fnid-call (list "--version"))
176 (when (called-interactively-p 'interactive
)
177 (message "ID Utils not found."))
179 (with-current-buffer b
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
)
186 (error "Version of ID Utils is %s. Need at least %s"
187 rev cedet-idutils-min-version
))
188 ;; Else, return TRUE, as in good enough.
189 (when (called-interactively-p 'interactive
)
190 (message "ID Utils %s - Good enough for CEDET." rev
))
193 (defun cedet-idutils-create/update-database
(&optional dir
)
194 "Create an IDUtils database in DIR.
195 IDUtils must start from scratch when updating a database."
196 (interactive "DDirectory: ")
197 (let ((default-directory dir
))
198 (cedet-idutils-mkid-call nil
)))
200 (provide 'cedet-idutils
)
202 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501
203 ;;; cedet-idutils.el ends here