cscope.el 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; semantic/symref/cscope.el --- Semantic-symref support via cscope.
  2. ;;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Semantic symref support via cscope.
  18. (require 'cedet-cscope)
  19. (require 'semantic/symref)
  20. (defvar ede-minor-mode)
  21. (declare-function ede-toplevel "ede/base")
  22. (declare-function ede-project-root-directory "ede/files")
  23. ;;; Code:
  24. ;;;###autoload
  25. (defclass semantic-symref-tool-cscope (semantic-symref-tool-baseclass)
  26. (
  27. )
  28. "A symref tool implementation using CScope.
  29. The CScope command can be used to generate lists of tags in a way
  30. similar to that of `grep'. This tool will parse the output to generate
  31. the hit list.
  32. See the function `cedet-cscope-search' for more details.")
  33. (defmethod semantic-symref-perform-search ((tool semantic-symref-tool-cscope))
  34. "Perform a search with GNU Global."
  35. (let* ((rootproj (when (and (featurep 'ede) ede-minor-mode)
  36. (ede-toplevel)))
  37. (default-directory (if rootproj
  38. (ede-project-root-directory rootproj)
  39. default-directory))
  40. ;; CScope has to be run from the project root where
  41. ;; cscope.out is.
  42. (b (cedet-cscope-search (oref tool :searchfor)
  43. (oref tool :searchtype)
  44. (oref tool :resulttype)
  45. (oref tool :searchscope)
  46. ))
  47. )
  48. (semantic-symref-parse-tool-output tool b)
  49. ))
  50. (defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-cscope))
  51. "Parse one line of grep output, and return it as a match list.
  52. Moves cursor to end of the match."
  53. (cond ((eq (oref tool :resulttype) 'file)
  54. ;; Search for files
  55. (when (re-search-forward "^\\([^\n]+\\)$" nil t)
  56. (match-string 1)))
  57. ((eq (oref tool :searchtype) 'tagcompletions)
  58. ;; Search for files
  59. (when (re-search-forward "^[^ ]+ [^ ]+ [^ ]+ \\(.*\\)$" nil t)
  60. (let ((subtxt (match-string 1))
  61. (searchtxt (oref tool :searchfor)))
  62. (if (string-match (concat "\\<" searchtxt "\\(\\w\\|\\s_\\)*\\>")
  63. subtxt)
  64. (match-string 0 subtxt)
  65. ;; We have to return something at this point.
  66. subtxt)))
  67. )
  68. (t
  69. (when (re-search-forward "^\\([^ ]+\\) [^ ]+ \\([0-9]+\\) " nil t)
  70. (cons (string-to-number (match-string 2))
  71. (expand-file-name (match-string 1)))
  72. ))))
  73. (provide 'semantic/symref/cscope)
  74. ;; Local variables:
  75. ;; generated-autoload-file: "../loaddefs.el"
  76. ;; generated-autoload-load-name: "semantic/symref/cscope"
  77. ;; End:
  78. ;;; semantic/symref/cscope.el ends here