2017-06-08 11:47:56 +02:00
|
|
|
;;; completion/company/autoload.el -*- lexical-binding: t; -*-
|
2017-02-19 18:41:26 -05:00
|
|
|
|
2018-02-02 15:57:38 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun +company/toggle-auto-completion ()
|
|
|
|
"Toggle as-you-type code completion."
|
|
|
|
(interactive)
|
|
|
|
(require 'company)
|
|
|
|
(setq company-idle-delay (unless company-idle-delay 0.2)))
|
|
|
|
|
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)))
|