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.

61 lines
2.2 KiB

4 years ago
  1. ;;; company-bbdb.el --- company-mode completion backend for BBDB in message-mode
  2. ;; Copyright (C) 2013-2014, 2016 Free Software Foundation, Inc.
  3. ;; Author: Jan Tatarik <jan.tatarik@gmail.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. (require 'company)
  16. (require 'cl-lib)
  17. (declare-function bbdb-record-get-field "bbdb")
  18. (declare-function bbdb-records "bbdb")
  19. (declare-function bbdb-dwim-mail "bbdb-com")
  20. (declare-function bbdb-search "bbdb-com")
  21. (defgroup company-bbdb nil
  22. "Completion backend for BBDB."
  23. :group 'company)
  24. (defcustom company-bbdb-modes '(message-mode)
  25. "Major modes in which `company-bbdb' may complete."
  26. :type '(repeat (symbol :tag "Major mode"))
  27. :package-version '(company . "0.8.8"))
  28. (defun company-bbdb--candidates (arg)
  29. (cl-mapcan (lambda (record)
  30. (mapcar (lambda (mail) (bbdb-dwim-mail record mail))
  31. (bbdb-record-get-field record 'mail)))
  32. (eval '(bbdb-search (bbdb-records) arg nil arg))))
  33. ;;;###autoload
  34. (defun company-bbdb (command &optional arg &rest ignore)
  35. "`company-mode' completion backend for BBDB."
  36. (interactive (list 'interactive))
  37. (cl-case command
  38. (interactive (company-begin-backend 'company-bbdb))
  39. (prefix (and (memq major-mode company-bbdb-modes)
  40. (featurep 'bbdb-com)
  41. (looking-back "^\\(To\\|Cc\\|Bcc\\): *.*? *\\([^,;]*\\)"
  42. (line-beginning-position))
  43. (match-string-no-properties 2)))
  44. (candidates (company-bbdb--candidates arg))
  45. (sorted t)
  46. (no-cache t)))
  47. (provide 'company-bbdb)
  48. ;;; company-bbdb.el ends here