Mercurial > emacs
annotate lisp/cedet/cedet-global.el @ 110372:8e1e2c124dec
(c-forward-<>-arglist-recur): Correct the indentation.
author | Alan Mackenzie <acm@muc.de> |
---|---|
date | Wed, 15 Sep 2010 17:51:15 +0000 |
parents | 280c8ae2476d |
children | b799d38f522a |
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> | |
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 | |
37 ;;; Code: | |
38 (defun cedet-gnu-global-search (searchtext texttype type scope) | |
39 "Perform a search with GNU Global, return the created buffer. | |
40 SEARCHTEXT is text to find. | |
41 TEXTTYPE is the type of text, such as 'regexp, 'string, 'tagname, | |
42 'tagregexp, or 'tagcompletions. | |
43 TYPE is the type of search, meaning that SEARCHTEXT is compared to | |
44 filename, tagname (tags table), references (uses of a tag) , or | |
45 symbol (uses of something not in the tag table.) | |
46 SCOPE is the scope of the search, such as 'project or 'subdirs." | |
47 (let ((flgs (cond ((eq type 'file) | |
48 "-a") | |
49 (t "-xa"))) | |
50 (scopeflgs (cond | |
51 ((eq scope 'project) | |
52 "" | |
53 ) | |
54 ((eq scope 'target) | |
55 "l"))) | |
56 (stflag (cond ((or (eq texttype 'tagname) | |
57 (eq texttype 'tagregexp)) | |
58 "") | |
59 ((eq texttype 'tagcompletions) | |
60 "c") | |
61 ((eq texttype 'regexp) | |
62 "g") | |
63 (t "r")))) | |
64 (cedet-gnu-global-call (list (concat flgs scopeflgs stflag) | |
65 searchtext)))) | |
66 | |
67 (defun cedet-gnu-global-call (flags) | |
68 "Call GNU Global with the list of FLAGS." | |
69 (let ((b (get-buffer-create "*CEDET Global*")) | |
70 (cd default-directory)) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
71 (with-current-buffer b |
105241 | 72 (setq default-directory cd) |
73 (erase-buffer)) | |
74 (apply 'call-process cedet-global-command | |
75 nil b nil | |
76 flags) | |
77 b)) | |
78 | |
79 (defun cedet-gnu-global-expand-filename (filename) | |
80 "Expand the FILENAME with GNU Global. | |
81 Return a fully qualified filename." | |
82 (interactive "sFile: ") | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
83 (let ((ans (with-current-buffer (cedet-gnu-global-call (list "-Pa" filename)) |
105241 | 84 (goto-char (point-min)) |
85 (if (looking-at "global: ") | |
86 (error "GNU Global not available") | |
87 (split-string (buffer-string) "\n" t))))) | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
88 (when (called-interactively-p 'interactive) |
105241 | 89 (if ans |
90 (if (= (length ans) 1) | |
91 (message "%s" (car ans)) | |
92 (message "%s + %d others" (car ans) | |
93 (length (cdr ans)))) | |
94 (error "No file found"))) | |
95 ans)) | |
96 | |
97 (defun cedet-gnu-global-show-root () | |
98 "Show the root of a GNU Global area under the current buffer." | |
99 (interactive) | |
100 (message "%s" (cedet-gnu-global-root))) | |
101 | |
102 (defun cedet-gnu-global-root (&optional dir) | |
103 "Return the root of any GNU Global scanned project. | |
104 If a default starting DIR is not specified, the current buffer's | |
105 `default-directory' is used." | |
106 (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
|
107 (with-current-buffer (cedet-gnu-global-call (list "-pq")) |
105241 | 108 (goto-char (point-min)) |
109 (when (not (eobp)) | |
110 (file-name-as-directory | |
111 (buffer-substring (point) (point-at-eol))))))) | |
112 | |
113 (defun cedet-gnu-global-version-check (&optional noerror) | |
114 "Check the version of the installed GNU Global command. | |
115 If optional programatic argument NOERROR is non-nil, then | |
116 instead of throwing an error if Global isn't available, then | |
117 return nil." | |
118 (interactive) | |
119 (require 'inversion) | |
120 (let ((b (condition-case nil | |
121 (cedet-gnu-global-call (list "--version")) | |
122 (error nil))) | |
123 (rev nil)) | |
124 (if (not b) | |
125 (progn | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105799
diff
changeset
|
126 (when (called-interactively-p 'interactive) |
105241 | 127 (message "GNU Global not found.")) |
128 nil) | |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
129 (with-current-buffer b |
105241 | 130 (goto-char (point-min)) |
131 (re-search-forward "GNU GLOBAL \\([0-9.]+\\)" nil t) | |
132 (setq rev (match-string 1)) | |
133 (if (inversion-check-version rev nil cedet-global-min-version) | |
134 (if noerror | |
135 nil | |
136 (error "Version of GNU Global is %s. Need at least %s" | |
137 rev cedet-global-min-version)) | |
138 ;; 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
|
139 (when (called-interactively-p 'interactive) |
105241 | 140 (message "GNU Global %s - Good enough for CEDET." rev)) |
141 t))))) | |
142 | |
143 (defun cedet-gnu-global-scan-hits (buffer) | |
144 "Scan all the hits from the GNU Global output BUFFER." | |
145 (let ((hits nil) | |
146 (r1 "^\\([^ ]+\\) +\\([0-9]+\\) \\([^ ]+\\) ")) | |
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 buffer |
105241 | 148 (goto-char (point-min)) |
149 (while (re-search-forward r1 nil t) | |
150 (setq hits (cons (cons (string-to-number (match-string 2)) | |
151 (match-string 3)) | |
152 hits))) | |
153 ;; Return the results | |
154 (nreverse hits)))) | |
155 | |
156 (provide 'cedet-global) | |
157 | |
105377 | 158 ;; arch-tag: 0d0d3ac2-91ef-4820-bb2b-1d59ccf38392 |
105241 | 159 ;;; cedet-global.el ends here |