+ :popup -> set-popup-rule! + :popups -> set-popup-rules! + :company-backend -> set-company-backend! + :evil-state -> set-evil-initial-state! I am slowly phasing out the setting system (def-setting! and set!), starting with these. What are autodefs? These are functions that are always defined, whether or not their respective modules are enabled. However, when their modules are disabled, they are replaced with macros that no-op and don't waste time evaluating their arguments. The old set! function will still work, for a while.
91 lines
3.1 KiB
EmacsLisp
91 lines
3.1 KiB
EmacsLisp
;;; completion/company/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
;;;###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
|
|
;;;###autoload
|
|
(def-setting! :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."
|
|
:obsolete set-company-backend!
|
|
`(set-company-backend! ,modes ,@backends))
|
|
|
|
;;;###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))
|
|
(message "Auto completion %s"
|
|
(if company-idle-delay "enabled" "disabled")))
|
|
|
|
;;;###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)))
|
|
|
|
;;;###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)))
|
|
|
|
;;;###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)
|
|
(pcase command
|
|
(`interactive (company-begin-backend '+company/whole-lines))
|
|
(`prefix (company-grab-line "^[\t\s]*\\(.+\\)" 1))
|
|
(`candidates
|
|
(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)))))
|
|
|
|
;;;###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))))
|
|
(call-interactively #'company-complete)))
|
|
|
|
;;;###autoload
|
|
(defun +company/dabbrev-code-previous ()
|
|
(interactive)
|
|
(require 'company-dabbrev)
|
|
(let ((company-selection-wrap-around t))
|
|
(call-interactively #'+company/dabbrev)
|
|
(company-select-previous-or-abort)))
|