- :config (progn
- (setq company-shell-modes '(sh-mode shell-mode))
- (add-to-list 'company-backends 'company-shell)))
-#+END_SRC
-
-*** YaSnippet
-
-Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
-
-*Note:* Do this at the end of =company-mode= config.
-
-#+BEGIN_SRC emacs-lisp
-(defvar malb/company-mode/enable-yas t
- "Enable yasnippet for all backends.")
-
-(defun malb/company-mode/backend-with-yas (backend)
- (if (or (not malb/company-mode/enable-yas)
- (and (listp backend)
- (member 'company-yasnippet backend)))
- backend
- (append (if (consp backend) backend (list backend))
- '(:with company-yasnippet))))
-
-(setq company-backends
- (mapcar #'malb/company-mode/backend-with-yas company-backends))
-#+END_SRC
-
-*** All the words
-
-Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
-
-#+BEGIN_SRC emacs-lisp
-(defun malb/toggle-company-ispell ()
- (interactive)
- (cond
- ((member '(company-ispell :with company-yasnippet) company-backends)
- (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
- (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
- (message "company-ispell disabled"))
- (t
- (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
- (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
- (message "company-ispell enabled!"))))
-
-(defun malb/company-ispell-setup ()
- ;; @see https://github.com/company-mode/company-mode/issues/50
- (when (boundp 'company-backends)
- (make-local-variable 'company-backends)
- (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
- (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
- ;; https://github.com/redguardtoo/emacs.d/issues/473
- (if (and (boundp 'ispell-alternate-dictionary)
- ispell-alternate-dictionary)
- (setq company-ispell-dictionary ispell-alternate-dictionary))))
-#+END_SRC
-
-*** Tab DWIM
-
- 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
-
- 2. This function then hopefully does what I want:
-
- a. if a region is active, just indent
- b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
- c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
- d. otherwise call whatever would have been called otherwise.
-
- ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
-
-#+BEGIN_SRC emacs-lisp
-(defun malb/indent-fold-or-complete (&optional arg)
- (interactive "P")
- (cond
- ;; if a region is active, indent
- ((use-region-p)
- (indent-region (region-beginning)
- (region-end)))
- ;; if the next char is space or eol, but prev char not whitespace
- ((and (not (active-minibuffer-window))
- (or (looking-at " ")
- (looking-at "$"))
- (looking-back "[^[:space:]]")
- (not (looking-back "^")))
-
- (cond (company-mode (company-complete-common))
- (auto-complete-mode (auto-complete))))
-
- ;; no whitespace anywhere
- ((and (not (active-minibuffer-window))
- (looking-at "[^[:space:]]")
- (looking-back "[^[:space:]]")
- (not (looking-back "^")))
- (cond
- ((bound-and-true-p hs-minor-mode)
- (save-excursion (end-of-line) (hs-toggle-hiding)))
- ((bound-and-true-p outline-minor-mode)
- (save-excursion (outline-cycle)))))
-
- ;; by default just call whatever was bound
- (t
- (let ((fn (or (if (current-local-map) (lookup-key (current-local-map) (kbd "TAB")))
- 'indent-for-tab-command)))
- (if (not (called-interactively-p 'any))
- (fn arg)
- (setq this-command fn)
- (call-interactively fn))))))
-
-(defun malb/toggle-fold ()
- (interactive)
- (cond ((eq major-mode 'org-mode)
- (org-force-cycle-archived))
- ((bound-and-true-p hs-minor-mode)
- (save-excursion
- (end-of-line)
- (hs-toggle-hiding)))
-
- ((bound-and-true-p outline-minor-mode)
- (save-excursion
- (outline-cycle)))))
-
-(bind-key "<tab>" 'malb/indent-fold-or-complete)
-(bind-key "C-<tab>" 'malb/toggle-fold)