Commit | Line | Data |
---|---|---|
a4bdf715 CY |
1 | ;;; semantic/symref/cscope.el --- Semantic-symref support via cscope. |
2 | ||
3 | ;;; Copyright (C) 2009 Free Software Foundation, Inc. | |
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 | ;; Semantic symref support via cscope. | |
25 | ||
26 | (require 'cedet-cscope) | |
27 | (require 'semantic/symref) | |
28 | ||
29 | ;;; Code: | |
30 | (defclass semantic-symref-tool-cscope (semantic-symref-tool-baseclass) | |
31 | ( | |
32 | ) | |
33 | "A symref tool implementation using CScope. | |
34 | The CScope command can be used to generate lists of tags in a way | |
35 | similar to that of `grep'. This tool will parse the output to generate | |
36 | the hit list. | |
37 | ||
38 | See the function `cedet-cscope-search' for more details.") | |
39 | ||
40 | (defmethod semantic-symref-perform-search ((tool semantic-symref-tool-cscope)) | |
41 | "Perform a search with GNU Global." | |
42 | (let* ((rootproj (when (and (featurep 'ede) ede-minor-mode) | |
43 | (ede-toplevel))) | |
44 | (default-directory (if rootproj | |
45 | (ede-project-root-directory rootproj) | |
46 | default-directory)) | |
47 | ;; CScope has to be run from the project root where | |
48 | ;; cscope.out is. | |
49 | (b (cedet-cscope-search (oref tool :searchfor) | |
50 | (oref tool :searchtype) | |
51 | (oref tool :resulttype) | |
52 | (oref tool :searchscope) | |
53 | )) | |
54 | ) | |
55 | (semantic-symref-parse-tool-output tool b) | |
56 | )) | |
57 | ||
58 | (defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-cscope)) | |
59 | "Parse one line of grep output, and return it as a match list. | |
60 | Moves cursor to end of the match." | |
61 | (cond ((eq (oref tool :resulttype) 'file) | |
62 | ;; Search for files | |
63 | (when (re-search-forward "^\\([^\n]+\\)$" nil t) | |
64 | (match-string 1))) | |
65 | ((eq (oref tool :searchtype) 'tagcompletions) | |
66 | ;; Search for files | |
67 | (when (re-search-forward "^[^ ]+ [^ ]+ [^ ]+ \\(.*\\)$" nil t) | |
68 | (let ((subtxt (match-string 1)) | |
69 | (searchtxt (oref tool :searchfor))) | |
70 | (if (string-match (concat "\\<" searchtxt "\\(\\w\\|\\s_\\)*\\>") | |
71 | subtxt) | |
72 | (match-string 0 subtxt) | |
73 | ;; We have to return something at this point. | |
74 | subtxt))) | |
75 | ) | |
76 | (t | |
77 | (when (re-search-forward "^\\([^ ]+\\) [^ ]+ \\([0-9]+\\) " nil t) | |
78 | (cons (string-to-number (match-string 2)) | |
79 | (expand-file-name (match-string 1))) | |
80 | )))) | |
81 | ||
82 | (provide 'semantic/symref/cscope) | |
83 | ||
84 | ;;; semantic/symref/cscope.el ends here |