1 ;;; cedet-idutils.el --- ID Utils support for CEDET.
3 ;; Copyright (C) 2009-2013 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Basic support calling ID Utils functions, and checking version
32 (declare-function inversion-check-version
"inversion")
34 (defvar cedet-idutils-min-version
"4.0"
35 "Minimum version of ID Utils required.")
37 (defcustom cedet-idutils-file-command
"fnid"
38 "Command name for the ID Utils executable for searching file names."
42 (defcustom cedet-idutils-token-command
"lid"
43 "Command name for the ID Utils executable for searching for tokens."
47 (defcustom cedet-idutils-make-command
"mkid"
48 "Command name for the ID Utils executable for creating token databases."
52 (defun cedet-idutils-search (searchtext texttype type scope
)
53 "Perform a search with ID Utils, return the created buffer.
54 SEARCHTEXT is text to find.
55 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname,
56 'tagregexp, or 'tagcompletions.
57 TYPE is the type of search, meaning that SEARCHTEXT is compared to
58 filename, tagname (tags table), references (uses of a tag) , or
59 symbol (uses of something not in the tag table.)
60 SCOPE is the scope of the search, such as 'project or 'subdirs.
61 Note: Scope is not yet supported."
63 ;; Calls for file stuff is very simple.
64 (cedet-idutils-fnid-call (list searchtext
))
65 ;; Calls for text searches is more complex.
66 (let* ((resultflg (if (eq texttype
'tagcompletions
)
68 (list "--result=grep")))
69 (scopeflgs nil
) ; (cond ((eq scope 'project) "" ) ((eq scope 'target) "l")))
70 (stflag (cond ((or (eq texttype
'tagname
)
71 (eq texttype
'tagregexp
))
73 ((eq texttype
'tagcompletions
)
74 ;; Add regex to search text for beginning of char.
75 (setq searchtext
(concat "^" searchtext
))
77 ((eq texttype
'regexp
)
80 (t (list "-l" "-w"))))
82 (cedet-idutils-lid-call (append resultflg scopeflgs stflag
83 (list searchtext
))))))
85 (defun cedet-idutils-fnid-call (flags)
86 "Call ID Utils fnid with the list of FLAGS.
87 Return the created buffer with program output."
88 (let ((b (get-buffer-create "*CEDET fnid*"))
89 (cd default-directory
)
91 (with-current-buffer b
92 (setq default-directory cd
)
94 (apply 'call-process cedet-idutils-file-command
99 (defun cedet-idutils-lid-call (flags)
100 "Call ID Utils lid with the list of FLAGS.
101 Return the created buffer with with program output."
102 (let ((b (get-buffer-create "*CEDET lid*"))
103 (cd default-directory
)
105 (with-current-buffer b
106 (setq default-directory cd
)
108 (apply 'call-process cedet-idutils-token-command
113 (defun cedet-idutils-mkid-call (flags)
114 "Call ID Utils mkid with the list of FLAGS.
115 Return the created buffer with program output."
116 (let ((b (get-buffer-create "*CEDET mkid*"))
117 (cd default-directory
)
119 (with-current-buffer b
120 (setq default-directory cd
)
122 (apply 'call-process cedet-idutils-make-command
129 (defun cedet-idutils-expand-filename (filename)
130 "Expand the FILENAME with ID Utils.
131 Return a filename relative to the default directory."
132 (interactive "sFile: ")
133 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename
))
134 (goto-char (point-min))
135 (if (looking-at "[^ \n]*fnid: ")
136 (error "ID Utils not available")
137 (split-string (buffer-string) "\n" t
)))))
138 (setq ans
(mapcar 'expand-file-name ans
))
139 (when (called-interactively-p 'interactive
)
141 (if (= (length ans
) 1)
142 (message "%s" (car ans
))
143 (message "%s + %d others" (car ans
)
145 (error "No file found")))
148 (defun cedet-idutils-support-for-directory (&optional dir
)
149 "Return non-nil if ID Utils has a support file for DIR.
150 If DIR is not supplied, use the current default directory.
151 This works by running lid on a bogus symbol, and looking for
154 (let ((default-directory (or dir default-directory
)))
157 (set-buffer (cedet-idutils-fnid-call '("moose")))
158 (goto-char (point-min))
159 (if (looking-at "[^ \n]*fnid: ")
164 (defun cedet-idutils-version-check (&optional noerror
)
165 "Check the version of the installed ID Utils command.
166 If optional programmatic argument NOERROR is non-nil,
167 then instead of throwing an error if Global isn't available,
171 (let ((b (condition-case nil
172 (cedet-idutils-fnid-call (list "--version"))
177 (when (called-interactively-p 'interactive
)
178 (message "ID Utils not found."))
180 (with-current-buffer b
181 (goto-char (point-min))
182 (if (re-search-forward "fnid - \\([0-9.]+\\)" nil t
)
183 (setq rev
(match-string 1))
185 (if (inversion-check-version rev nil cedet-idutils-min-version
)
188 (error "Version of ID Utils is %s. Need at least %s"
189 rev cedet-idutils-min-version
))
190 ;; Else, return TRUE, as in good enough.
191 (when (called-interactively-p 'interactive
)
192 (message "ID Utils %s - Good enough for CEDET." rev
))
195 (defun cedet-idutils-create/update-database
(&optional dir
)
196 "Create an IDUtils database in DIR.
197 IDUtils must start from scratch when updating a database."
198 (interactive "DDirectory: ")
199 (let ((default-directory dir
))
200 (cedet-idutils-mkid-call nil
)))
202 (provide 'cedet-idutils
)
204 ;;; cedet-idutils.el ends here