* net/browse-url.el (browse-url):
[emacs.git] / lisp / cedet / cedet-idutils.el
blobea0ad88aa9da8ffe32ac29871a68274864d7fc91
1 ;;; cedet-idutils.el --- ID Utils support for CEDET.
3 ;; Copyright (C) 2009-2014 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
6 ;; Old-Version: 0.2
7 ;; Keywords: OO, lisp
8 ;; Package: cedet
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/>.
25 ;;; Commentary:
27 ;; Basic support calling ID Utils functions, and checking version
28 ;; numbers.
30 ;;; Code:
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."
39 :type 'string
40 :group 'cedet)
42 (defcustom cedet-idutils-token-command "lid"
43 "Command name for the ID Utils executable for searching for tokens."
44 :type 'string
45 :group 'cedet)
47 (defcustom cedet-idutils-make-command "mkid"
48 "Command name for the ID Utils executable for creating token databases."
49 :type 'string
50 :group 'cedet)
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."
62 (if (eq type 'file)
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)
67 (list "--key=token")
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))
72 (list "-r" "-w"))
73 ((eq texttype 'tagcompletions)
74 ;; Add regex to search text for beginning of char.
75 (setq searchtext (concat "^" searchtext))
76 (list "-r" "-s" ))
77 ((eq texttype 'regexp)
78 (list "-r"))
79 ;; t means 'symbol
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)
93 (erase-buffer))
94 (apply 'call-process cedet-idutils-file-command
95 nil b nil
96 flags)
97 b))
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)
107 (erase-buffer))
108 (apply 'call-process cedet-idutils-token-command
109 nil b nil
110 flags)
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)
121 (erase-buffer))
122 (apply 'call-process cedet-idutils-make-command
123 nil b nil
124 flags)
127 ;;; UTIL CALLS
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)
140 (if ans
141 (if (= (length ans) 1)
142 (message "%s" (car ans))
143 (message "%s + %d others" (car ans)
144 (length (cdr ans))))
145 (error "No file found")))
146 ans))
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
152 the error code."
153 (save-excursion
154 (let ((default-directory (or dir default-directory)))
155 (condition-case nil
156 (progn
157 (set-buffer (cedet-idutils-fnid-call '("moose")))
158 (goto-char (point-min))
159 (if (looking-at "[^ \n]*fnid: ")
162 (error nil)))))
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,
168 return nil."
169 (interactive)
170 (require 'inversion)
171 (let ((b (condition-case nil
172 (cedet-idutils-fnid-call (list "--version"))
173 (error nil)))
174 (rev nil))
175 (if (not b)
176 (progn
177 (when (called-interactively-p 'interactive)
178 (message "ID Utils not found."))
179 nil)
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))
184 (setq rev "0"))
185 (if (inversion-check-version rev nil cedet-idutils-min-version)
186 (if noerror
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))
193 t)))))
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