2015-04-03 04:28:13 +00:00
|
|
|
;;; packages.el --- Auto-completion Layer packages File for Spacemacs
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
2015-04-03 04:28:13 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq auto-completion-packages
|
2015-05-06 07:28:50 +00:00
|
|
|
'(
|
|
|
|
auto-complete
|
|
|
|
ac-ispell
|
|
|
|
company
|
|
|
|
company-statistics
|
2015-10-09 16:14:23 +00:00
|
|
|
helm-company
|
2015-05-06 07:28:50 +00:00
|
|
|
helm-c-yasnippet
|
|
|
|
hippie-exp
|
|
|
|
yasnippet
|
2015-05-13 07:33:55 +00:00
|
|
|
auto-yasnippet
|
2015-12-03 15:33:03 +00:00
|
|
|
smartparens
|
2015-05-06 07:28:50 +00:00
|
|
|
))
|
2015-04-03 04:28:13 +00:00
|
|
|
|
|
|
|
;; company-quickhelp from MELPA is not compatible with 24.3 anymore
|
|
|
|
(unless (version< emacs-version "24.4")
|
|
|
|
(push 'company-quickhelp auto-completion-packages))
|
|
|
|
|
2015-08-14 03:02:16 +00:00
|
|
|
;; TODO replace by company-ispell which comes with company
|
|
|
|
;; to be moved to spell-checking layer as well
|
2015-04-03 04:28:13 +00:00
|
|
|
(defun auto-completion/init-ac-ispell ()
|
|
|
|
(use-package ac-ispell
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq ac-ispell-requires 4)
|
2015-09-29 05:07:57 +00:00
|
|
|
(with-eval-after-load 'auto-complete
|
|
|
|
(ac-ispell-setup))
|
2015-04-03 04:28:13 +00:00
|
|
|
;; (add-hook 'markdown-mode-hook 'ac-ispell-ac-setup)
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun auto-completion/init-auto-complete ()
|
|
|
|
(use-package auto-complete
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(setq ac-auto-start 0
|
|
|
|
ac-delay 0.2
|
|
|
|
ac-quick-help-delay 1.
|
|
|
|
ac-use-fuzzy t
|
|
|
|
ac-fuzzy-enable t
|
|
|
|
ac-comphist-file (concat spacemacs-cache-directory "ac-comphist.dat")
|
2015-04-03 17:30:26 +00:00
|
|
|
;; use 'complete when auto-complete is disabled
|
|
|
|
tab-always-indent 'complete
|
2015-04-03 04:28:13 +00:00
|
|
|
ac-dwim t)
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(require 'auto-complete-config)
|
2015-04-03 17:30:26 +00:00
|
|
|
(setq-default ac-sources '(ac-source-abbrev
|
|
|
|
ac-source-dictionary
|
|
|
|
ac-source-words-in-same-mode-buffers))
|
2015-04-03 23:13:52 +00:00
|
|
|
(when (configuration-layer/package-usedp 'yasnippet)
|
2015-04-03 04:28:13 +00:00
|
|
|
(push 'ac-source-yasnippet ac-sources))
|
|
|
|
(add-to-list 'completion-styles 'initials t)
|
|
|
|
(define-key ac-completing-map (kbd "C-j") 'ac-next)
|
|
|
|
(define-key ac-completing-map (kbd "C-k") 'ac-previous)
|
|
|
|
(define-key ac-completing-map (kbd "<S-tab>") 'ac-previous)
|
2015-04-06 20:02:14 +00:00
|
|
|
(spacemacs|diminish auto-complete-mode " ⓐ" " a"))))
|
2015-04-03 04:28:13 +00:00
|
|
|
|
|
|
|
(defun auto-completion/init-company ()
|
|
|
|
(use-package company
|
2015-04-09 12:09:00 +00:00
|
|
|
:defer t
|
2015-04-03 04:28:13 +00:00
|
|
|
:init
|
2015-04-06 20:49:53 +00:00
|
|
|
(progn
|
|
|
|
(setq company-idle-delay 0.2
|
|
|
|
company-minimum-prefix-length 2
|
|
|
|
company-require-match nil
|
|
|
|
company-dabbrev-ignore-case nil
|
|
|
|
company-dabbrev-downcase nil
|
2015-09-13 21:10:10 +00:00
|
|
|
company-frontends '(company-pseudo-tooltip-frontend)))
|
2015-04-22 10:45:27 +00:00
|
|
|
(defvar-local company-fci-mode-on-p nil)
|
|
|
|
|
|
|
|
(defun company-turn-off-fci (&rest ignore)
|
|
|
|
(when (boundp 'fci-mode)
|
|
|
|
(setq company-fci-mode-on-p fci-mode)
|
|
|
|
(when fci-mode (fci-mode -1))))
|
|
|
|
|
|
|
|
(defun company-maybe-turn-on-fci (&rest ignore)
|
|
|
|
(when company-fci-mode-on-p (fci-mode 1)))
|
|
|
|
|
|
|
|
(add-hook 'company-completion-started-hook 'company-turn-off-fci)
|
|
|
|
(add-hook 'company-completion-finished-hook 'company-maybe-turn-on-fci)
|
|
|
|
(add-hook 'company-completion-cancelled-hook 'company-maybe-turn-on-fci)
|
2015-04-03 04:28:13 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2015-04-06 20:02:14 +00:00
|
|
|
(spacemacs|diminish company-mode " ⓐ" " a")
|
2015-04-30 03:49:59 +00:00
|
|
|
|
|
|
|
;; key bindings
|
2015-05-04 04:13:58 +00:00
|
|
|
(defun spacemacs//company-complete-common-or-cycle-backward ()
|
|
|
|
"Complete common prefix or cycle backward."
|
|
|
|
(interactive)
|
|
|
|
(company-complete-common-or-cycle -1))
|
2015-05-06 02:32:28 +00:00
|
|
|
(spacemacs//auto-completion-set-RET-key-behavior 'company)
|
|
|
|
(spacemacs//auto-completion-set-TAB-key-behavior 'company)
|
|
|
|
(spacemacs//auto-completion-setup-key-sequence 'company)
|
2015-04-27 02:53:26 +00:00
|
|
|
(let ((map company-active-map))
|
|
|
|
(define-key map (kbd "C-/") 'company-search-candidates)
|
|
|
|
(define-key map (kbd "C-M-/") 'company-filter-candidates)
|
2015-04-30 03:49:59 +00:00
|
|
|
(define-key map (kbd "C-d") 'company-show-doc-buffer)
|
|
|
|
(define-key map (kbd "C-j") 'company-select-next)
|
|
|
|
(define-key map (kbd "C-k") 'company-select-previous)
|
|
|
|
(define-key map (kbd "C-l") 'company-complete-selection))
|
2015-04-03 04:28:13 +00:00
|
|
|
;; Nicer looking faces
|
|
|
|
(custom-set-faces
|
|
|
|
'(company-tooltip-common
|
|
|
|
((t (:inherit company-tooltip :weight bold :underline nil))))
|
|
|
|
'(company-tooltip-common-selection
|
|
|
|
((t (:inherit company-tooltip-selection :weight bold :underline nil)))))
|
|
|
|
;; Transformers
|
|
|
|
(defun spacemacs//company-transformer-cancel (candidates)
|
|
|
|
"Cancel completion if prefix is in the list
|
|
|
|
`company-mode-completion-cancel-keywords'"
|
2015-04-27 02:47:08 +00:00
|
|
|
(unless (member company-prefix company-mode-completion-cancel-keywords)
|
2015-04-03 04:28:13 +00:00
|
|
|
candidates))
|
|
|
|
(setq company-transformers '(spacemacs//company-transformer-cancel
|
2015-04-09 03:57:22 +00:00
|
|
|
company-sort-by-occurrence)))))
|
2015-04-03 04:28:13 +00:00
|
|
|
|
2015-05-06 07:28:50 +00:00
|
|
|
(defun auto-completion/init-company-statistics ()
|
|
|
|
(use-package company-statistics
|
2015-05-07 02:22:01 +00:00
|
|
|
:if auto-completion-enable-sort-by-usage
|
2015-05-06 07:28:50 +00:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
2015-05-07 02:22:01 +00:00
|
|
|
(setq company-statistics-file (concat spacemacs-cache-directory
|
|
|
|
"company-statistics-cache.el"))
|
2015-05-06 07:28:50 +00:00
|
|
|
(add-hook 'company-mode-hook 'company-statistics-mode))))
|
|
|
|
|
2015-04-03 04:28:13 +00:00
|
|
|
(defun auto-completion/init-company-quickhelp ()
|
|
|
|
(use-package company-quickhelp
|
2015-05-04 04:15:58 +00:00
|
|
|
:if (and auto-completion-enable-help-tooltip (display-graphic-p))
|
2015-04-03 04:28:13 +00:00
|
|
|
:defer t
|
|
|
|
:init (add-hook 'company-mode-hook 'company-quickhelp-mode)))
|
2015-04-23 02:03:04 +00:00
|
|
|
|
2016-01-04 19:35:19 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'spacemacs-helm)
|
|
|
|
(defun auto-completion/init-helm-c-yasnippet ()
|
|
|
|
(use-package helm-c-yasnippet
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(defun spacemacs/helm-yas ()
|
|
|
|
"Properly lazy load helm-c-yasnipper."
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/load-yasnippet)
|
|
|
|
(require 'helm-c-yasnippet)
|
|
|
|
(call-interactively 'helm-yas-complete))
|
|
|
|
(spacemacs/set-leader-keys "is" 'spacemacs/helm-yas)
|
|
|
|
(setq helm-c-yas-space-match-any-greedy t)))))
|
2015-04-23 02:03:04 +00:00
|
|
|
|
2016-01-04 19:35:19 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'spacemacs-helm)
|
|
|
|
(defun auto-completion/init-helm-company ()
|
|
|
|
(use-package helm-company
|
|
|
|
:if (configuration-layer/package-usedp 'company)
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(with-eval-after-load 'company
|
|
|
|
(define-key company-active-map (kbd "C-/") 'helm-company)))))
|
2015-10-09 16:14:23 +00:00
|
|
|
|
2015-04-23 02:03:04 +00:00
|
|
|
(defun auto-completion/init-hippie-exp ()
|
2015-05-06 07:28:50 +00:00
|
|
|
;; replace dabbrev-expand
|
2015-04-23 02:03:04 +00:00
|
|
|
(global-set-key (kbd "M-/") 'hippie-expand)
|
2016-02-01 14:23:55 +00:00
|
|
|
(define-key evil-insert-state-map [remap evil-complete-previous] 'hippie-expand)
|
2015-04-23 02:03:04 +00:00
|
|
|
(setq hippie-expand-try-functions-list
|
|
|
|
'(
|
|
|
|
;; Try to expand word "dynamically", searching the current buffer.
|
|
|
|
try-expand-dabbrev
|
|
|
|
;; Try to expand word "dynamically", searching all other buffers.
|
|
|
|
try-expand-dabbrev-all-buffers
|
|
|
|
;; Try to expand word "dynamically", searching the kill ring.
|
|
|
|
try-expand-dabbrev-from-kill
|
|
|
|
;; Try to complete text as a file name, as many characters as unique.
|
|
|
|
try-complete-file-name-partially
|
|
|
|
;; Try to complete text as a file name.
|
|
|
|
try-complete-file-name
|
|
|
|
;; Try to expand word before point according to all abbrev tables.
|
|
|
|
try-expand-all-abbrevs
|
|
|
|
;; Try to complete the current line to an entire line in the buffer.
|
|
|
|
try-expand-list
|
|
|
|
;; Try to complete the current line to an entire line in the buffer.
|
|
|
|
try-expand-line
|
|
|
|
;; Try to complete as an Emacs Lisp symbol, as many characters as
|
|
|
|
;; unique.
|
|
|
|
try-complete-lisp-symbol-partially
|
|
|
|
;; Try to complete word as an Emacs Lisp symbol.
|
|
|
|
try-complete-lisp-symbol))
|
|
|
|
(when (configuration-layer/package-usedp 'yasnippet)
|
|
|
|
;; Try to expand yasnippet snippets based on prefix
|
|
|
|
(push 'yas-hippie-try-expand hippie-expand-try-functions-list)))
|
|
|
|
|
|
|
|
(defun auto-completion/init-yasnippet ()
|
|
|
|
(use-package yasnippet
|
2015-08-31 12:01:26 +00:00
|
|
|
:commands (yas-global-mode yas-minor-mode)
|
2015-04-23 02:03:04 +00:00
|
|
|
:init
|
|
|
|
(progn
|
2015-08-31 12:01:26 +00:00
|
|
|
;; We don't want undefined variable errors
|
|
|
|
(defvar yas-global-mode nil)
|
2016-01-07 05:14:32 +00:00
|
|
|
(setq yas-triggers-in-field t
|
|
|
|
yas-wrap-around-region t
|
|
|
|
helm-yas-display-key-on-candidate t)
|
|
|
|
;; on multiple keys, fall back to completing read
|
|
|
|
;; typically this means helm
|
|
|
|
(setq yas-prompt-functions '(yas-completing-prompt))
|
2015-04-30 03:49:59 +00:00
|
|
|
;; disable yas minor mode map
|
|
|
|
;; use hippie-expand instead
|
|
|
|
(setq yas-minor-mode-map (make-sparse-keymap))
|
2015-05-21 23:00:27 +00:00
|
|
|
;; this makes it easy to get out of a nested expansion
|
2016-01-07 05:14:32 +00:00
|
|
|
(define-key yas-minor-mode-map (kbd "M-s-/") 'yas-next-field)
|
|
|
|
;; configure snippet directories
|
|
|
|
(let* ((spacemacs--auto-completion-dir
|
|
|
|
(configuration-layer/get-layer-property 'auto-completion :dir))
|
|
|
|
(private-yas-dir (if auto-completion-private-snippets-directory
|
|
|
|
auto-completion-private-snippets-directory
|
|
|
|
(concat
|
|
|
|
configuration-layer-private-directory
|
|
|
|
"snippets/")))
|
2016-01-09 02:56:49 +00:00
|
|
|
(spacemacs-layer-snippets-dir (expand-file-name
|
2016-01-07 05:14:32 +00:00
|
|
|
"snippets"
|
|
|
|
spacemacs--auto-completion-dir))
|
2016-01-09 02:56:49 +00:00
|
|
|
(dotspacemacs-directory-snippets-dir (when dotspacemacs-directory
|
|
|
|
(expand-file-name
|
|
|
|
"snippets"
|
|
|
|
dotspacemacs-directory))))
|
|
|
|
(setq yas-snippet-dirs nil)
|
|
|
|
;; ~/.emacs.d/layers/auto-completion/snippets
|
|
|
|
(push spacemacs-layer-snippets-dir yas-snippet-dirs)
|
|
|
|
;; ~/.emacs.d/elpa/yasnippet-xxxxx/snippets
|
|
|
|
(push 'yas-installed-snippets-dir yas-snippet-dirs)
|
|
|
|
;; ~/.spacemacs.d/snippets
|
|
|
|
(when dotspacemacs-directory-snippets-dir
|
|
|
|
(push dotspacemacs-directory-snippets-dir yas-snippet-dirs))
|
|
|
|
;; arbitrary directories in `auto-completion-private-snippets-directory'
|
|
|
|
(when private-yas-dir
|
|
|
|
(if (listp private-yas-dir)
|
|
|
|
(setq yas-snippet-dirs (append yas-snippet-dirs private-yas-dir))
|
|
|
|
(push private-yas-dir yas-snippet-dirs))))
|
2015-06-01 22:26:58 +00:00
|
|
|
|
2015-04-23 02:03:04 +00:00
|
|
|
(defun spacemacs/load-yasnippet ()
|
2016-01-07 05:14:32 +00:00
|
|
|
(unless yas-global-mode (yas-global-mode 1))
|
2015-05-26 01:32:27 +00:00
|
|
|
(yas-minor-mode 1))
|
2015-08-23 01:47:30 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(prog-mode-hook
|
|
|
|
markdown-mode-hook
|
|
|
|
org-mode-hook))
|
2015-04-23 02:03:04 +00:00
|
|
|
(spacemacs|add-toggle yasnippet
|
2015-07-25 13:14:53 +00:00
|
|
|
:status yas-minor-mode
|
|
|
|
:on (yas-minor-mode)
|
|
|
|
:off (yas-minor-mode -1)
|
2015-08-27 06:58:05 +00:00
|
|
|
:documentation "Enable snippets."
|
2015-07-25 13:14:53 +00:00
|
|
|
:evil-leader "ty")
|
2015-04-23 02:03:04 +00:00
|
|
|
|
|
|
|
(defun spacemacs/force-yasnippet-off ()
|
|
|
|
(yas-minor-mode -1)
|
|
|
|
(setq yas-dont-activate t))
|
2016-01-07 05:14:32 +00:00
|
|
|
(spacemacs/add-to-hooks
|
|
|
|
'spacemacs/force-yasnippet-off '(term-mode-hook
|
|
|
|
shell-mode-hook
|
|
|
|
eshell-mode-hook)))
|
2015-12-03 15:33:03 +00:00
|
|
|
:config (spacemacs|diminish yas-minor-mode " ⓨ" " y")))
|
2015-05-13 07:33:55 +00:00
|
|
|
|
2015-05-17 02:07:28 +00:00
|
|
|
(defun auto-completion/init-auto-yasnippet ()
|
2015-05-13 07:33:55 +00:00
|
|
|
(use-package auto-yasnippet
|
|
|
|
:defer t
|
|
|
|
:init
|
2015-05-17 02:07:28 +00:00
|
|
|
(progn
|
2015-11-06 14:18:00 +00:00
|
|
|
(setq aya-persist-snippets-dir
|
|
|
|
(or auto-completion-private-snippets-directory
|
|
|
|
(concat configuration-layer-private-directory "snippets/")))
|
2015-05-17 02:07:28 +00:00
|
|
|
(defun spacemacs/auto-yasnippet-expand ()
|
|
|
|
"Call `yas-expand' and switch to `insert state'"
|
|
|
|
(interactive)
|
|
|
|
(call-interactively 'aya-expand)
|
2016-01-07 14:52:21 +00:00
|
|
|
(unless holy-mode (evil-insert-state)))
|
2015-08-07 01:40:28 +00:00
|
|
|
(spacemacs/declare-prefix "iS" "auto-yasnippet")
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys
|
2015-05-17 02:07:28 +00:00
|
|
|
"iSc" 'aya-create
|
|
|
|
"iSe" 'spacemacs/auto-yasnippet-expand
|
|
|
|
"iSw" 'aya-persist-snippet))))
|
2015-12-03 15:33:03 +00:00
|
|
|
|
|
|
|
(defun auto-completion/post-init-smartparens ()
|
|
|
|
(with-eval-after-load 'smartparens
|
|
|
|
;; We need to know whether the smartparens was enabled, see
|
|
|
|
;; `yas-before-expand-snippet-hook' below.
|
|
|
|
(defvar smartparens-enabled-initially t
|
|
|
|
"Stored whether smartparens is originally enabled or not.")
|
|
|
|
(add-hook 'yas-before-expand-snippet-hook
|
|
|
|
(lambda ()
|
|
|
|
;; If enabled, smartparens will mess snippets expanded by `hippie-expand`
|
|
|
|
(setq smartparens-enabled-initially smartparens-mode)
|
|
|
|
(smartparens-mode -1)))
|
|
|
|
(add-hook 'yas-after-exit-snippet-hook
|
|
|
|
(lambda ()
|
|
|
|
(when smartparens-enabled-initially
|
|
|
|
(smartparens-mode 1))))))
|