Mercurial > emacs
annotate lisp/cedet/cedet-global.el @ 111599:d6320bd900cd
* doc/lispref/text.texi (Kill Functions, Low-Level Kill Ring): Small fixes.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 10 Nov 2010 00:42:42 -0800 |
parents | b150a06c6999 |
children | b799d38f522a 376148b31b5e |
rev | line source |
---|---|
105241 | 1 ;;; cedet-global.el --- GNU Global support for CEDET. |
2 | |
106815 | 3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
105241 | 4 |
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation, either version 3 of the License, or | |
12 ;; (at your option) any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 ;;; Commentary: | |
23 ;; | |
24 ;; Basic support for calling GNU Global, and testing version numbers. | |
25 | |
26 (declare-function inversion-check-version "inversion") | |
27 | |
28 (defvar cedet-global-min-version "5.0" | |
29 "Minimum version of GNU global required.") | |
30 | |
31 (defcustom cedet-global-command "global" | |
32 "Command name for the GNU Global executable." | |
33 :type 'string | |
34 :group 'cedet) | |
35 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
36 (defcustom cedet-global-gtags-command "gtags" |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
37 "Command name for the GNU Global gtags executable. |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
38 GTAGS is used to create the tags table queried by the 'global' command." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
39 :type 'string |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
40 :group 'cedet) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
41 |
105241 | 42 ;;; Code: |
43 (defun cedet-gnu-global-search (searchtext texttype type scope) | |
44 "Perform a search with GNU Global, return the created buffer. | |
45 SEARCHTEXT is text to find. | |
46 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
47 'tagregexp, or 'tagcompletions. | |
48 TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
49 filename, tagname (tags table), references (uses of a tag) , or | |
50 symbol (uses of something not in the tag table.) | |
51 SCOPE is the scope of the search, such as 'project or 'subdirs." | |
52 (let ((flgs (cond ((eq type 'file) | |
53 "-a") | |
54 (t "-xa"))) | |
55 (scopeflgs (cond | |
56 ((eq scope 'project) | |
57 "" | |
58 ) | |
59 ((eq scope 'target) | |
60 "l"))) | |
61 (stflag (cond ((or (eq texttype 'tagname) | |
62 (eq texttype 'tagregexp)) | |
63 "") | |
64 ((eq texttype 'tagcompletions) | |
65 "c") | |
66 ((eq texttype 'regexp) | |
67 "g") | |
68 (t "r")))) | |
69 (cedet-gnu-global-call (list (concat flgs scopeflgs stflag) | |
70 searchtext)))) | |
71 | |
72 (defun cedet-gnu-global-call (flags) | |
73 "Call GNU Global with the list of FLAGS." | |
74 (let ((b (get-buffer-create "*CEDET Global*")) | |
75 (cd default-directory)) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
76 (with-current-buffer b |
105241 | 77 (setq default-directory cd) |
78 (erase-buffer)) | |
79 (apply 'call-process cedet-global-command | |
80 nil b nil | |
81 flags) | |
82 b)) | |
83 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
84 (defun cedet-gnu-global-gtags-call (flags) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
85 "Create GNU Global TAGS using gtags with FLAGS." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
86 (let ((b (get-buffer-create "*CEDET Global gtags*")) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
87 (cd default-directory) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
88 ) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
89 (with-current-buffer b |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
90 (setq default-directory cd) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
91 (erase-buffer)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
92 (apply 'call-process cedet-global-gtags-command |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
93 nil b nil |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
94 flags) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
95 b)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
96 |
105241 | 97 (defun cedet-gnu-global-expand-filename (filename) |
98 "Expand the FILENAME with GNU Global. | |
99 Return a fully qualified filename." | |
100 (interactive "sFile: ") | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
101 (let ((ans (with-current-buffer (cedet-gnu-global-call (list "-Pa" filename)) |
105241 | 102 (goto-char (point-min)) |
103 (if (looking-at "global: ") | |
104 (error "GNU Global not available") | |
105 (split-string (buffer-string) "\n" t))))) | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
106 (when (called-interactively-p 'interactive) |
105241 | 107 (if ans |
108 (if (= (length ans) 1) | |
109 (message "%s" (car ans)) | |
110 (message "%s + %d others" (car ans) | |
111 (length (cdr ans)))) | |
112 (error "No file found"))) | |
113 ans)) | |
114 | |
115 (defun cedet-gnu-global-show-root () | |
116 "Show the root of a GNU Global area under the current buffer." | |
117 (interactive) | |
118 (message "%s" (cedet-gnu-global-root))) | |
119 | |
120 (defun cedet-gnu-global-root (&optional dir) | |
121 "Return the root of any GNU Global scanned project. | |
122 If a default starting DIR is not specified, the current buffer's | |
123 `default-directory' is used." | |
124 (let ((default-directory (or dir default-directory))) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
125 (with-current-buffer (cedet-gnu-global-call (list "-pq")) |
105241 | 126 (goto-char (point-min)) |
127 (when (not (eobp)) | |
128 (file-name-as-directory | |
129 (buffer-substring (point) (point-at-eol))))))) | |
130 | |
131 (defun cedet-gnu-global-version-check (&optional noerror) | |
132 "Check the version of the installed GNU Global command. | |
133 If optional programatic argument NOERROR is non-nil, then | |
134 instead of throwing an error if Global isn't available, then | |
135 return nil." | |
136 (interactive) | |
137 (require 'inversion) | |
138 (let ((b (condition-case nil | |
139 (cedet-gnu-global-call (list "--version")) | |
140 (error nil))) | |
141 (rev nil)) | |
142 (if (not b) | |
143 (progn | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
144 (when (called-interactively-p 'interactive) |
105241 | 145 (message "GNU Global not found.")) |
146 nil) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
147 (with-current-buffer b |
105241 | 148 (goto-char (point-min)) |
149 (re-search-forward "GNU GLOBAL \\([0-9.]+\\)" nil t) | |
150 (setq rev (match-string 1)) | |
151 (if (inversion-check-version rev nil cedet-global-min-version) | |
152 (if noerror | |
153 nil | |
154 (error "Version of GNU Global is %s. Need at least %s" | |
155 rev cedet-global-min-version)) | |
156 ;; 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
|
157 (when (called-interactively-p 'interactive) |
105241 | 158 (message "GNU Global %s - Good enough for CEDET." rev)) |
159 t))))) | |
160 | |
161 (defun cedet-gnu-global-scan-hits (buffer) | |
162 "Scan all the hits from the GNU Global output BUFFER." | |
163 (let ((hits nil) | |
164 (r1 "^\\([^ ]+\\) +\\([0-9]+\\) \\([^ ]+\\) ")) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
165 (with-current-buffer buffer |
105241 | 166 (goto-char (point-min)) |
167 (while (re-search-forward r1 nil t) | |
168 (setq hits (cons (cons (string-to-number (match-string 2)) | |
169 (match-string 3)) | |
170 hits))) | |
171 ;; Return the results | |
172 (nreverse hits)))) | |
173 | |
110526
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
174 (defun cedet-gnu-global-create/update-database (&optional dir) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
175 "Create a GNU Global database in DIR. |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
176 If a database already exists, then just update it." |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
177 (interactive "DDirectory: ") |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
178 (let ((root (cedet-gnu-global-root dir))) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
179 (if root (setq dir root)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
180 (let ((default-directory dir)) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
181 (cedet-gnu-global-gtags-call |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
182 (when root |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
183 '("-i");; Incremental update flag. |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
184 ))))) |
b150a06c6999
Synch EDE to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
185 |
105241 | 186 (provide 'cedet-global) |
187 | |
105377 | 188 ;; arch-tag: 0d0d3ac2-91ef-4820-bb2b-1d59ccf38392 |
105241 | 189 ;;; cedet-global.el ends here |