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