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.

104 lines
4.1 KiB

4 years ago
  1. ;;; company-dabbrev-code.el --- dabbrev-like company-mode backend for code -*- lexical-binding: t -*-
  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 'company-dabbrev)
  20. (require 'cl-lib)
  21. (defgroup company-dabbrev-code nil
  22. "dabbrev-like completion backend for code."
  23. :group 'company)
  24. (defcustom company-dabbrev-code-modes
  25. '(prog-mode
  26. batch-file-mode csharp-mode css-mode erlang-mode haskell-mode jde-mode
  27. lua-mode python-mode)
  28. "Modes that use `company-dabbrev-code'.
  29. In all these modes (and their derivatives) `company-dabbrev-code' will
  30. complete only symbols, not text in comments or strings. In other modes
  31. `company-dabbrev-code' will pass control to other backends
  32. \(e.g. `company-dabbrev'\). Value t means complete in all modes."
  33. :type '(choice (repeat :tag "Some modes" (symbol :tag "Major mode"))
  34. (const :tag "All modes" t)))
  35. (defcustom company-dabbrev-code-other-buffers t
  36. "Determines whether `company-dabbrev-code' should search other buffers.
  37. If `all', search all other buffers, except the ignored ones. If t, search
  38. buffers with the same major mode. If `code', search all buffers with major
  39. modes in `company-dabbrev-code-modes', or derived from one of them. See
  40. also `company-dabbrev-code-time-limit'."
  41. :type '(choice (const :tag "Off" nil)
  42. (const :tag "Same major mode" t)
  43. (const :tag "Code major modes" code)
  44. (const :tag "All" all)))
  45. (defcustom company-dabbrev-code-time-limit .1
  46. "Determines how long `company-dabbrev-code' should look for matches."
  47. :type '(choice (const :tag "Off" nil)
  48. (number :tag "Seconds")))
  49. (defcustom company-dabbrev-code-everywhere nil
  50. "Non-nil to offer completions in comments and strings."
  51. :type 'boolean)
  52. (defcustom company-dabbrev-code-ignore-case nil
  53. "Non-nil to ignore case when collecting completion candidates."
  54. :type 'boolean)
  55. (defun company-dabbrev-code--make-regexp (prefix)
  56. (concat "\\_<" (if (equal prefix "")
  57. "\\([a-zA-Z]\\|\\s_\\)"
  58. (regexp-quote prefix))
  59. "\\(\\sw\\|\\s_\\)*\\_>"))
  60. ;;;###autoload
  61. (defun company-dabbrev-code (command &optional arg &rest ignored)
  62. "dabbrev-like `company-mode' backend for code.
  63. The backend looks for all symbols in the current buffer that aren't in
  64. comments or strings."
  65. (interactive (list 'interactive))
  66. (cl-case command
  67. (interactive (company-begin-backend 'company-dabbrev-code))
  68. (prefix (and (or (eq t company-dabbrev-code-modes)
  69. (apply #'derived-mode-p company-dabbrev-code-modes))
  70. (or company-dabbrev-code-everywhere
  71. (not (company-in-string-or-comment)))
  72. (or (company-grab-symbol) 'stop)))
  73. (candidates (let ((case-fold-search company-dabbrev-code-ignore-case))
  74. (company-dabbrev--search
  75. (company-dabbrev-code--make-regexp arg)
  76. company-dabbrev-code-time-limit
  77. (pcase company-dabbrev-code-other-buffers
  78. (`t (list major-mode))
  79. (`code company-dabbrev-code-modes)
  80. (`all `all))
  81. (not company-dabbrev-code-everywhere))))
  82. (ignore-case company-dabbrev-code-ignore-case)
  83. (duplicates t)))
  84. (provide 'company-dabbrev-code)
  85. ;;; company-dabbrev-code.el ends here