1 ;;; cedet-idutils.el --- ID Utils support for CEDET.
3 ;; Copyright (C) 2009 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 (defun cedet-idutils-search (searchtext texttype type scope
)
47 "Perform a search with ID Utils, return the created buffer.
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."
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
)
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
))
67 ((eq texttype
'tagcompletions
)
68 ;; Add regex to search text for beginning of char.
69 (setq searchtext
(concat "^" searchtext
))
71 ((eq texttype
'regexp
)
74 (t (list "-l" "-w"))))
76 (cedet-idutils-lid-call (append resultflg scopeflgs stflag
77 (list searchtext
))))))
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
)
85 (with-current-buffer b
86 (setq default-directory cd
)
88 (apply 'call-process cedet-idutils-file-command
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
)
99 (with-current-buffer b
100 (setq default-directory cd
)
102 (apply 'call-process cedet-idutils-token-command
109 (defun cedet-idutils-expand-filename (filename)
110 "Expand the FILENAME with ID Utils.
111 Return a filename relative to the default directory."
112 (interactive "sFile: ")
113 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename
))
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
))
119 (when (interactive-p)
121 (if (= (length ans
) 1)
122 (message "%s" (car ans
))
123 (message "%s + %d others" (car ans
)
125 (error "No file found")))
128 (defun cedet-idutils-support-for-directory (&optional dir
)
129 "Return non-nil if ID Utils has a support file for DIR.
130 If DIR is not supplied, use the current default directory.
131 This works by running lid on a bogus symbol, and looking for
134 (let ((default-directory (or dir default-directory
)))
137 (set-buffer (cedet-idutils-fnid-call '("moose")))
138 (goto-char (point-min))
139 (if (looking-at "[^ \n]*fnid: ")
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
151 (let ((b (condition-case nil
152 (cedet-idutils-fnid-call (list "--version"))
157 (when (interactive-p)
158 (message "ID Utils not found."))
160 (with-current-buffer b
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
)
167 (error "Version of ID Utils is %s. Need at least %s"
168 rev cedet-idutils-min-version
))
169 ;; Else, return TRUE, as in good enough.
170 (when (interactive-p)
171 (message "ID Utils %s - Good enough for CEDET." rev
))
175 (provide 'cedet-idutils
)
177 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501
178 ;;; cedet-idutils.el ends here