Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.9 KiB

4 years ago
  1. ;;; company-etags.el --- company-mode completion backend for etags
  2. ;; Copyright (C) 2009-2011, 2014 Free Software Foundation, Inc.
  3. ;; Author: Nikolaj Schumacher
  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. ;;; Code:
  18. (require 'company)
  19. (require 'cl-lib)
  20. (require 'etags)
  21. (defgroup company-etags nil
  22. "Completion backend for etags."
  23. :group 'company)
  24. (defcustom company-etags-use-main-table-list t
  25. "Always search `tags-table-list' if set.
  26. If this is disabled, `company-etags' will try to find the one table for each
  27. buffer automatically."
  28. :type '(choice (const :tag "off" nil)
  29. (const :tag "on" t)))
  30. (defcustom company-etags-ignore-case nil
  31. "Non-nil to ignore case in completion candidates."
  32. :type 'boolean
  33. :package-version '(company . "0.7.3"))
  34. (defcustom company-etags-everywhere nil
  35. "Non-nil to offer completions in comments and strings.
  36. Set it to t or to a list of major modes."
  37. :type '(choice (const :tag "Off" nil)
  38. (const :tag "Any supported mode" t)
  39. (repeat :tag "Some major modes"
  40. (symbol :tag "Major mode")))
  41. :package-version '(company . "0.9.0"))
  42. (defvar company-etags-modes '(prog-mode c-mode objc-mode c++-mode java-mode
  43. jde-mode pascal-mode perl-mode python-mode))
  44. (defvar-local company-etags-buffer-table 'unknown)
  45. (defun company-etags-find-table ()
  46. (let ((file (expand-file-name
  47. "TAGS"
  48. (locate-dominating-file (or buffer-file-name
  49. default-directory)
  50. "TAGS"))))
  51. (when (and file (file-regular-p file))
  52. (list file))))
  53. (defun company-etags-buffer-table ()
  54. (or (and company-etags-use-main-table-list tags-table-list)
  55. (if (eq company-etags-buffer-table 'unknown)
  56. (setq company-etags-buffer-table (company-etags-find-table))
  57. company-etags-buffer-table)))
  58. (defun company-etags--candidates (prefix)
  59. (let ((tags-table-list (company-etags-buffer-table))
  60. (tags-file-name tags-file-name)
  61. (completion-ignore-case company-etags-ignore-case))
  62. (and (or tags-file-name tags-table-list)
  63. (fboundp 'tags-completion-table)
  64. (save-excursion
  65. (visit-tags-table-buffer)
  66. (all-completions prefix (tags-completion-table))))))
  67. ;;;###autoload
  68. (defun company-etags (command &optional arg &rest ignored)
  69. "`company-mode' completion backend for etags."
  70. (interactive (list 'interactive))
  71. (cl-case command
  72. (interactive (company-begin-backend 'company-etags))
  73. (prefix (and (apply #'derived-mode-p company-etags-modes)
  74. (or (eq t company-etags-everywhere)
  75. (apply #'derived-mode-p company-etags-everywhere)
  76. (not (company-in-string-or-comment)))
  77. (company-etags-buffer-table)
  78. (or (company-grab-symbol) 'stop)))
  79. (candidates (company-etags--candidates arg))
  80. (location (let ((tags-table-list (company-etags-buffer-table)))
  81. (when (fboundp 'find-tag-noselect)
  82. (save-excursion
  83. (let ((buffer (find-tag-noselect arg)))
  84. (cons buffer (with-current-buffer buffer (point))))))))
  85. (ignore-case company-etags-ignore-case)))
  86. (provide 'company-etags)
  87. ;;; company-etags.el ends here