Mercurial > emacs
annotate lisp/cedet/cedet-idutils.el @ 110417:8a3552ec7934
* lisp/indent.el (indent-according-to-mode): Apply syntax-propertize.
(indent-region): Use indent-according-to-mode.
* test/indent/octave.m: Remove one more `fixindent'. Use `end'.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 18 Sep 2010 18:21:16 +0200 |
parents | 280c8ae2476d |
children | b799d38f522a |
rev | line source |
---|---|
105241 | 1 ;;; cedet-idutils.el --- ID Utils support for CEDET. |
2 | |
106815 | 3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
105241 | 4 |
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 ;; Version: 0.2 | |
7 ;; Keywords: OO, lisp | |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
8 ;; Package: cedet |
105241 | 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) | |
105325 | 48 "Perform a search with ID Utils, return the created buffer. |
105241 | 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 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
86 (with-current-buffer b |
105241 | 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 ) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
100 (with-current-buffer b |
105241 | 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) | |
105325 | 111 "Expand the FILENAME with ID Utils. |
105241 | 112 Return a filename relative to the default directory." |
113 (interactive "sFile: ") | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
114 (let ((ans (with-current-buffer (cedet-idutils-fnid-call (list filename)) |
105241 | 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)) | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
120 (when (called-interactively-p 'interactive) |
105241 | 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) | |
105325 | 130 "Return non-nil if ID Utils has a support file for DIR. |
105241 | 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 | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
158 (when (called-interactively-p 'interactive) |
105241 | 159 (message "ID Utils not found.")) |
160 nil) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
161 (with-current-buffer b |
105241 | 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 | |
105325 | 168 (error "Version of ID Utils is %s. Need at least %s" |
105241 | 169 rev cedet-idutils-min-version)) |
170 ;; Else, return TRUE, as in good enough. | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
171 (when (called-interactively-p 'interactive) |
105241 | 172 (message "ID Utils %s - Good enough for CEDET." rev)) |
173 t))))) | |
174 | |
175 | |
176 (provide 'cedet-idutils) | |
177 | |
105377 | 178 ;; arch-tag: 663ca082-5b3d-4384-8710-cc74f990b501 |
105241 | 179 ;;; cedet-idutils.el ends here |