1 ;;; semantic/symref/cscope.el --- Semantic-symref support via cscope.
3 ;;; Copyright (C) 2009-2017 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;; Semantic symref support via cscope.
26 (require 'cedet-cscope
)
27 (require 'semantic
/symref
)
29 (defvar ede-minor-mode
)
30 (declare-function ede-toplevel
"ede/base")
31 (declare-function ede-project-root-directory
"ede/files")
35 (defclass semantic-symref-tool-cscope
(semantic-symref-tool-baseclass)
38 "A symref tool implementation using CScope.
39 The CScope command can be used to generate lists of tags in a way
40 similar to that of `grep'. This tool will parse the output to generate
43 See the function `cedet-cscope-search' for more details.")
45 (cl-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
)
49 (default-directory (if rootproj
50 (ede-project-root-directory rootproj
)
52 ;; CScope has to be run from the project root where
54 (b (cedet-cscope-search (oref tool
:searchfor
)
55 (oref tool
:searchtype
)
56 (oref tool
:resulttype
)
57 (oref tool
:searchscope
)
60 (semantic-symref-parse-tool-output tool b
)
63 (defconst semantic-symref-cscope--line-re
64 "^\\([^ ]+\\) [^ ]+ \\([0-9]+\\) ")
66 (cl-defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-cscope
))
67 "Parse one line of grep output, and return it as a match list.
68 Moves cursor to end of the match."
69 (cond ((eq (oref tool
:resulttype
) 'file
)
71 (when (re-search-forward "^\\([^\n]+\\)$" nil t
)
73 ((eq (oref tool
:searchtype
) 'tagcompletions
)
75 (when (re-search-forward "^[^ ]+ [^ ]+ [^ ]+ \\(.*\\)$" nil t
)
76 (let ((subtxt (match-string 1))
77 (searchtxt (oref tool
:searchfor
)))
78 (if (string-match (concat "\\<" searchtxt
"\\(\\w\\|\\s_\\)*\\>")
80 (match-string 0 subtxt
)
81 ;; We have to return something at this point.
84 ((eq (oref tool
:resulttype
) 'line-and-text
)
85 (when (re-search-forward semantic-symref-cscope--line-re nil t
)
86 (list (string-to-number (match-string 2))
87 (expand-file-name (match-string 1))
88 (buffer-substring-no-properties (point) (line-end-position)))))
89 (t ; :resulttype is 'line
90 (when (re-search-forward semantic-symref-cscope--line-re nil t
)
91 (cons (string-to-number (match-string 2))
92 (expand-file-name (match-string 1)))
95 (provide 'semantic
/symref
/cscope
)
98 ;; generated-autoload-file: "../loaddefs.el"
99 ;; generated-autoload-load-name: "semantic/symref/cscope"
102 ;;; semantic/symref/cscope.el ends here