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