2020-04-26 07:37:30 +02:00
|
|
|
;;; evil-collection-company.el --- Bindings for `company-mode' -*- lexical-binding: t -*-
|
2017-11-11 22:58:26 +01:00
|
|
|
|
|
|
|
;; Copyright (C) 2017 James Nguyen
|
|
|
|
|
|
|
|
;; Author: James Nguyen <james@jojojames.com>
|
|
|
|
;; Maintainer: James Nguyen <james@jojojames.com>
|
2018-08-27 10:41:51 +02:00
|
|
|
;; Pierre Neidhardt <mail@ambrevar.xyz>
|
2018-03-02 02:22:38 +01:00
|
|
|
;; URL: https://github.com/emacs-evil/evil-collection
|
2017-11-11 22:58:26 +01:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "25.1"))
|
2017-11-16 09:47:09 +01:00
|
|
|
;; Keywords: evil, company, abbrev, convenience, matching
|
2017-11-11 22:58:26 +01:00
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Bindings for `company-mode'.
|
|
|
|
|
|
|
|
;;; Code:
|
2017-11-15 10:12:24 +01:00
|
|
|
(require 'company nil t)
|
2018-06-20 03:14:50 +02:00
|
|
|
(require 'evil-collection)
|
2017-11-11 22:58:26 +01:00
|
|
|
|
2020-09-08 04:20:07 +02:00
|
|
|
(declare-function company-tng-mode "company-tng")
|
2021-12-18 10:52:31 +01:00
|
|
|
(declare-function company-grab-line "company")
|
|
|
|
(declare-function company-begin-backend "company")
|
2017-12-07 22:02:46 +01:00
|
|
|
|
2017-12-07 02:41:09 +01:00
|
|
|
(defgroup evil-collection-company nil
|
2017-12-06 18:49:35 +01:00
|
|
|
"Evil bindings for `company-mode'."
|
|
|
|
:group 'evil-collection)
|
|
|
|
|
2020-09-08 04:20:07 +02:00
|
|
|
(defcustom evil-collection-company-supported-states '(insert replace emacs)
|
|
|
|
"The `evil-state's which `company' function can be requested."
|
|
|
|
:type '(repeat symbol))
|
2021-12-18 10:52:31 +01:00
|
|
|
(defcustom evil-collection-want-company-extended-keybindings nil
|
2022-01-10 19:18:40 +01:00
|
|
|
"The 'evil-company-extended' keybindings should be requested"
|
2021-12-18 10:52:31 +01:00
|
|
|
:type 'boolean)
|
2020-09-08 04:20:07 +02:00
|
|
|
|
2017-11-15 10:13:25 +01:00
|
|
|
(defvar company-active-map)
|
|
|
|
(defvar company-search-map)
|
|
|
|
|
2017-12-18 04:26:31 +01:00
|
|
|
(defconst evil-collection-company-maps '(company-active-map company-search-map))
|
|
|
|
|
2020-09-08 04:20:07 +02:00
|
|
|
(defun evil-collection-company-supported-p (command &rest _)
|
|
|
|
"Return non-nil if `evil-state' is in supported states."
|
|
|
|
(cond
|
2021-01-29 04:56:26 +01:00
|
|
|
((not (bound-and-true-p evil-mode)) t)
|
2021-01-29 08:47:45 +01:00
|
|
|
((eq command 'prefix)
|
|
|
|
(memq evil-state evil-collection-company-supported-states))
|
2021-01-27 23:53:50 +01:00
|
|
|
(t t)))
|
|
|
|
|
2021-12-18 10:52:31 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun evil-collection-company-whole-lines (command &optional arg &rest ignored)
|
|
|
|
"`company-mode' completion backend that completes whole-lines, akin to vim's
|
|
|
|
C-x C-l."
|
|
|
|
(interactive (list 'interactive))
|
|
|
|
(require 'company)
|
|
|
|
(pcase command
|
|
|
|
(`interactive (company-begin-backend 'evil-collection-company-whole-lines))
|
|
|
|
(`prefix (company-grab-line "^[\t\s]*\\(.+\\)" 1))
|
|
|
|
(`candidates
|
|
|
|
(all-completions
|
|
|
|
arg
|
|
|
|
(delete-dups
|
|
|
|
(split-string
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"^[\t\s]+" ""
|
|
|
|
(concat (buffer-substring-no-properties (point-min) (line-beginning-position))
|
|
|
|
(buffer-substring-no-properties (line-end-position) (point-max))))
|
|
|
|
"\\(\r\n\\|[\n\r]\\)" t))))))
|
|
|
|
|
2018-10-15 12:30:19 +02:00
|
|
|
;;;###autoload
|
2017-12-07 02:41:09 +01:00
|
|
|
(defun evil-collection-company-setup ()
|
2017-11-17 03:53:35 +01:00
|
|
|
"Set up `evil' bindings for `company'."
|
2018-06-06 14:22:30 +02:00
|
|
|
(evil-collection-define-key nil 'company-active-map
|
|
|
|
(kbd "C-n") 'company-select-next-or-abort
|
|
|
|
(kbd "C-p") 'company-select-previous-or-abort
|
|
|
|
(kbd "C-j") 'company-select-next-or-abort
|
|
|
|
(kbd "C-k") 'company-select-previous-or-abort
|
|
|
|
(kbd "M-j") 'company-select-next
|
|
|
|
(kbd "M-k") 'company-select-previous)
|
2017-11-11 23:21:46 +01:00
|
|
|
|
2021-12-18 10:52:31 +01:00
|
|
|
(when evil-collection-want-company-extended-keybindings
|
|
|
|
(evil-collection-define-key nil 'company-active-map
|
|
|
|
(kbd "C-l") 'evil-collection-company-whole-lines
|
|
|
|
(kbd "C-]") 'company-etags
|
|
|
|
(kbd "C-f") 'company-files
|
|
|
|
(kbd "C-o") 'company-capf
|
|
|
|
(kbd "C-s") 'company-ispell))
|
|
|
|
|
2017-11-11 23:21:46 +01:00
|
|
|
(when evil-want-C-u-scroll
|
2021-01-29 08:47:45 +01:00
|
|
|
(evil-collection-define-key nil 'company-active-map
|
|
|
|
(kbd "C-u") 'company-previous-page))
|
2017-11-11 23:21:46 +01:00
|
|
|
|
|
|
|
(when evil-want-C-d-scroll
|
2021-01-29 08:47:45 +01:00
|
|
|
(evil-collection-define-key nil 'company-active-map
|
|
|
|
(kbd "C-d") 'company-next-page))
|
2018-06-06 14:22:30 +02:00
|
|
|
|
|
|
|
(evil-collection-define-key nil 'company-search-map
|
|
|
|
(kbd "C-j") 'company-select-next-or-abort
|
|
|
|
(kbd "C-k") 'company-select-previous-or-abort
|
|
|
|
(kbd "M-j") 'company-select-next
|
|
|
|
(kbd "M-k") 'company-select-previous
|
|
|
|
(kbd "<escape>") 'company-search-abort)
|
2017-11-11 23:21:46 +01:00
|
|
|
|
2020-09-08 04:20:07 +02:00
|
|
|
;; Make `company-mode' not show popup when not in supported state
|
2021-01-29 08:47:45 +01:00
|
|
|
(advice-add 'company-call-backend
|
|
|
|
:before-while 'evil-collection-company-supported-p))
|
2021-01-27 23:53:50 +01:00
|
|
|
|
2017-11-11 22:58:26 +01:00
|
|
|
|
2017-12-07 02:41:09 +01:00
|
|
|
(provide 'evil-collection-company)
|
|
|
|
;;; evil-collection-company.el ends here
|