2017-06-08 11:47:56 +02:00
|
|
|
;;; completion/company/autoload.el -*- lexical-binding: t; -*-
|
2017-02-19 18:41:26 -05:00
|
|
|
|
2018-06-15 02:58:12 +02:00
|
|
|
;;;###autodef
|
|
|
|
(defun set-company-backend! (modes &rest backends)
|
|
|
|
"Prepends BACKENDS to `company-backends' in major MODES.
|
|
|
|
|
|
|
|
MODES should be one major-mode symbol or a list of them."
|
|
|
|
(cl-loop for mode in modes
|
|
|
|
for def-name = (intern (format "doom--init-company-%s" mode))
|
|
|
|
do
|
|
|
|
(fset def-name
|
|
|
|
(lambda () (when (or (eq major-mode mode)
|
|
|
|
(and (boundp mode) (symbol-value mode)))
|
|
|
|
(require 'company)
|
|
|
|
(make-variable-buffer-local 'company-backends)
|
|
|
|
(dolist (backend backends)
|
|
|
|
(cl-pushnew backend company-backends :test #'equal)))))
|
|
|
|
and do (add-hook (intern (format "%s-hook" mode)) def-name)))
|
|
|
|
|
|
|
|
;; FIXME obsolete :company-backend
|
2018-02-02 15:57:38 -05:00
|
|
|
;;;###autoload
|
2018-06-01 14:53:49 +02:00
|
|
|
(def-setting! :company-backend (modes &rest backends)
|
2018-06-15 02:58:12 +02:00
|
|
|
:obsolete set-company-backend!
|
|
|
|
`(set-company-backend! ,modes ,@backends))
|
2018-06-01 14:53:49 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2018-02-02 15:57:38 -05:00
|
|
|
(defun +company/toggle-auto-completion ()
|
|
|
|
"Toggle as-you-type code completion."
|
|
|
|
(interactive)
|
|
|
|
(require 'company)
|
2018-05-31 15:59:52 +02:00
|
|
|
(setq company-idle-delay (unless company-idle-delay 0.2))
|
|
|
|
(message "Auto completion %s"
|
|
|
|
(if company-idle-delay "enabled" "disabled")))
|
2018-02-02 15:57:38 -05:00
|
|
|
|
2017-02-19 18:41:26 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun +company/complete ()
|
|
|
|
"Bring up the completion popup. If only one result, complete it."
|
|
|
|
(interactive)
|
|
|
|
(require 'company)
|
|
|
|
(when (and (company-manual-begin)
|
|
|
|
(= company-candidates-length 1))
|
|
|
|
(company-complete-common)))
|
|
|
|
|
2018-05-28 00:08:14 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +company/dabbrev ()
|
|
|
|
"Invokes `company-dabbrev-code' in prog-mode buffers and `company-dabbrev'
|
|
|
|
everywhere else."
|
|
|
|
(interactive)
|
|
|
|
(call-interactively
|
|
|
|
(if (derived-mode-p 'prog-mode)
|
|
|
|
#'company-dabbrev-code
|
|
|
|
#'company-dabbrev)))
|
|
|
|
|
2017-02-19 18:41:26 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun +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)
|
2017-06-08 11:47:56 +02:00
|
|
|
(pcase command
|
2018-05-08 17:57:26 +02:00
|
|
|
(`interactive (company-begin-backend '+company/whole-lines))
|
|
|
|
(`prefix (company-grab-line "^[\t\s]*\\(.+\\)" 1))
|
|
|
|
(`candidates
|
2017-06-08 11:47:56 +02:00
|
|
|
(all-completions
|
|
|
|
arg
|
|
|
|
(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)))))
|
2017-02-19 18:41:26 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +company/dict-or-keywords ()
|
|
|
|
"`company-mode' completion combining `company-dict' and `company-keywords'."
|
|
|
|
(interactive)
|
|
|
|
(require 'company-dict)
|
|
|
|
(require 'company-keywords)
|
|
|
|
(let ((company-backends '((company-keywords company-dict))))
|
2018-05-08 17:57:26 +02:00
|
|
|
(call-interactively #'company-complete)))
|
2017-02-19 18:41:26 -05:00
|
|
|
|
2017-06-09 00:36:38 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +company/dabbrev-code-previous ()
|
|
|
|
(interactive)
|
|
|
|
(require 'company-dabbrev)
|
|
|
|
(let ((company-selection-wrap-around t))
|
2018-05-28 00:08:14 +02:00
|
|
|
(call-interactively #'+company/dabbrev)
|
2017-06-09 00:36:38 +02:00
|
|
|
(company-select-previous-or-abort)))
|