global.el 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; semantic/symref/global.el --- Use GNU Global for symbol references
  2. ;; Copyright (C) 2008-2017 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. ;; GNU Global use with the semantic-symref system.
  18. (require 'cedet-global)
  19. (require 'semantic/symref)
  20. ;;; Code:
  21. ;;;###autoload
  22. (defclass semantic-symref-tool-global (semantic-symref-tool-baseclass)
  23. (
  24. )
  25. "A symref tool implementation using GNU Global.
  26. The GNU Global command can be used to generate lists of tags in a way
  27. similar to that of `grep'. This tool will parse the output to generate
  28. the hit list.
  29. See the function `cedet-gnu-global-search' for more details.")
  30. (cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-global))
  31. "Perform a search with GNU Global."
  32. (let ((b (cedet-gnu-global-search (oref tool :searchfor)
  33. (oref tool :searchtype)
  34. (oref tool :resulttype)
  35. (oref tool :searchscope)
  36. ))
  37. )
  38. (semantic-symref-parse-tool-output tool b)
  39. ))
  40. (defconst semantic-symref-global--line-re
  41. "^\\([^ ]+\\) +\\([0-9]+\\) \\([^ ]+\\) ")
  42. (cl-defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-global))
  43. "Parse one line of grep output, and return it as a match list.
  44. Moves cursor to end of the match."
  45. (cond ((or (eq (oref tool :resulttype) 'file)
  46. (eq (oref tool :searchtype) 'tagcompletions))
  47. ;; Search for files
  48. (when (re-search-forward "^\\([^\n]+\\)$" nil t)
  49. (match-string 1)))
  50. ((eq (oref tool :resulttype) 'line-and-text)
  51. (when (re-search-forward semantic-symref-global--line-re nil t)
  52. (list (string-to-number (match-string 2))
  53. (match-string 3)
  54. (buffer-substring-no-properties (point) (line-end-position)))))
  55. (t
  56. (when (re-search-forward semantic-symref-global--line-re nil t)
  57. (cons (string-to-number (match-string 2))
  58. (match-string 3))
  59. ))))
  60. (provide 'semantic/symref/global)
  61. ;; Local variables:
  62. ;; generated-autoload-file: "../loaddefs.el"
  63. ;; generated-autoload-load-name: "semantic/symref/global"
  64. ;; End:
  65. ;;; semantic/symref/global.el ends here