Commit | Line | Data |
---|---|---|
666fd2cc CY |
1 | ;;; cedet-idutils.el --- ID Utils support for CEDET. |
2 | ||
114f9c96 | 3 | ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
666fd2cc CY |
4 | |
5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | ;; Version: 0.2 | |
7 | ;; Keywords: OO, lisp | |
bd78fa1d | 8 | ;; Package: cedet |
666fd2cc CY |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
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. | |
16 | ||
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. | |
21 | ||
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/>. | |
24 | ||
25 | ;;; Commentary: | |
26 | ;; | |
27 | ;; Basic support calling ID Utils functions, and checking version | |
28 | ;; numbers. | |
29 | ||
30 | ;;; Code: | |
31 | ||
32 | (declare-function inversion-check-version "inversion") | |
33 | ||
34 | (defvar cedet-idutils-min-version "4.0" | |
35 | "Minimum version of ID Utils required.") | |
36 | ||
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) | |
41 | ||
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) | |
46 | ||
47 | (defun cedet-idutils-search (searchtext texttype type scope) | |
bd2afec2 | 48 | "Perform a search with ID Utils, return the created buffer. |
666fd2cc CY |
49 | SEARCHTEXT is text to find. |
50 | TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
51 | 'tagregexp, or 'tagcompletions. | |
52 | TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
53 | filename, tagname (tags table), references (uses of a tag) , or | |
54 | symbol (uses of something not in the tag table.) | |
55 | SCOPE is the scope of the search, such as 'project or 'subdirs. | |
56 | Note: Scope is not yet supported." | |
57 | (if (eq type 'file) | |
58 | ;; Calls for file stuff is very simple. | |
59 | (cedet-idutils-fnid-call (list searchtext)) | |
60 | ;; Calls for text searches is more complex. | |
61 | (let* ((resultflg (if (eq texttype 'tagcompletions) | |
62 | (list "--key=token") | |
63 | (list "--result=grep"))) | |
64 | (scopeflgs nil) ; (cond ((eq scope 'project) "" ) ((eq scope 'target) "l"))) | |
65 | (stflag (cond ((or (eq texttype 'tagname) | |
66 | (eq texttype 'tagregexp)) | |
67 | (list "-r" "-w")) | |
68 | ((eq texttype 'tagcompletions) | |
69 | ;; Add regex to search text for beginning of char. | |
70 | (setq searchtext (concat "^" searchtext)) | |
71 | (list "-r" "-s" )) | |
72 | ((eq texttype 'regexp) | |
73 | (list "-r")) | |
74 | ;; t means 'symbol | |
75 | (t (list "-l" "-w")))) | |
76 | ) | |
77 | (cedet-idutils-lid-call (append resultflg scopeflgs stflag | |
78 | (list searchtext)))))) | |
79 | ||
80 | (defun cedet-idutils-fnid-call (flags) | |
81 | "Call ID Utils fnid with the list of FLAGS. | |
82 | Return the created buffer with with program output." | |
83 | (let ((b (get-buffer-create "*CEDET fnid*")) | |
84 | (cd default-directory) | |
85 | ) | |
0816d744 | 86 | (with-current-buffer b |
666fd2cc CY |
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 | ) | |
0816d744 | 100 | (with-current-buffer b |
666fd2cc CY |
101 | (setq default-directory cd) |
102 | (erase-buffer)) | |
103 | (apply 'call-process cedet-idutils-token-command | |
104 | nil b nil | |
105 | flags) | |
106 | b)) | |
107 | ||
108 | ;;; UTIL CALLS | |
109 | ;; | |
110 | (defun cedet-idutils-expand-filename (filename) | |
bd2afec2 | 111 | "Expand the FILENAME with ID Utils. |
666fd2cc CY |
112 | Return a filename relative to the default directory." |
113 | (interactive "sFile: ") | |
0816d744 | 114 | (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename)) |
666fd2cc CY |
115 | (goto-char (point-min)) |
116 | (if (looking-at "[^ \n]*fnid: ") | |
117 | (error "ID Utils not available") | |
118 | (split-string (buffer-string) "\n" t))))) | |
119 | (setq ans (mapcar 'expand-file-name ans)) | |
2054a44c | 120 | (when (called-interactively-p 'interactive) |
666fd2cc CY |
121 | (if ans |
122 | (if (= (length ans) 1) | |
123 | (message "%s" (car ans)) | |
124 | (message "%s + %d others" (car ans) | |
125 | (length (cdr ans)))) | |
126 | (error "No file found"))) | |
127 | ans)) | |
128 | ||
129 | (defun cedet-idutils-support-for-directory (&optional dir) | |
bd2afec2 | 130 | "Return non-nil if ID Utils has a support file for DIR. |
666fd2cc CY |
131 | If DIR is not supplied, use the current default directory. |
132 | This works by running lid on a bogus symbol, and looking for | |
133 | the error code." | |
134 | (save-excursion | |
135 | (let ((default-directory (or dir default-directory))) | |
136 | (condition-case nil | |
137 | (progn | |
138 | (set-buffer (cedet-idutils-fnid-call '("moose"))) | |
139 | (goto-char (point-min)) | |
140 | (if (looking-at "[^ \n]*fnid: ") | |
141 | nil | |
142 | t)) | |
143 | (error nil))))) | |
144 | ||
145 | (defun cedet-idutils-version-check (&optional noerror) | |
146 | "Check the version of the installed ID Utils command. | |
147 | If optional programatic argument NOERROR is non-nil, then | |
148 | instead of throwing an error if Global isn't available, then | |
149 | return nil." | |
150 | (interactive) | |
151 | (require 'inversion) | |
152 | (let ((b (condition-case nil | |
153 | (cedet-idutils-fnid-call (list "--version")) | |
154 | (error nil))) | |
155 | (rev nil)) | |
156 | (if (not b) | |
157 | (progn | |
2054a44c | 158 | (when (called-interactively-p 'interactive) |
666fd2cc CY |
159 | (message "ID Utils not found.")) |
160 | nil) | |
0816d744 | 161 | (with-current-buffer b |
666fd2cc CY |
162 | (goto-char (point-min)) |
163 | (re-search-forward "fnid - \\([0-9.]+\\)" nil t) | |
164 | (setq rev (match-string 1)) | |
165 | (if (inversion-check-version rev nil cedet-idutils-min-version) | |
166 | (if noerror | |
167 | nil | |
bd2afec2 | 168 | (error "Version of ID Utils is %s. Need at least %s" |
666fd2cc CY |
169 | rev cedet-idutils-min-version)) |
170 | ;; Else, return TRUE, as in good enough. | |
2054a44c | 171 | (when (called-interactively-p 'interactive) |
666fd2cc CY |
172 | (message "ID Utils %s - Good enough for CEDET." rev)) |
173 | t))))) | |
174 | ||
175 | ||
176 | (provide 'cedet-idutils) | |
177 | ||
3999968a | 178 | ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501 |
666fd2cc | 179 | ;;; cedet-idutils.el ends here |