 ;; to offer completion inside comments too.
 (setq company-dabbrev-code-everywhere t)
 
-;; Don't bother with company-dabbrev when we have company-dabbrev-code
-;; already. It's a little too aggressive at suggesting words,
-;; especially when writing comments.
-(setq company-backends
-      (remove 'company-dabbrev company-backends))
+(global-set-key (kbd "s-/") #'company-dabbrev)
+
+;; Precise completion.
 
 (global-set-key (kbd "C-z") #'company-try-hard)
 (define-key company-active-map (kbd "C-z") #'company-try-hard)

;;; Commentary
;; Completion is hard to get right. I'm gradually moving to company,
;; but this is everything I expect from completion:
;;
;; DUMB COMPLETION: This is often sufficient. Just complete the
;; current substring based on other strings in the buffer. If no
;; matches are present, try other buffers with the same mode. It must
;; be case sensitive.
;;
;; FULL LINE COMPLETION: It's often handy for imports if we can expand
;; the whole current line to match lines from other buffers (of the
;; same mode).
;;
;; FILENAME COMPLETION: If the current substring matches a filename of
;; a file at point, expand it to the full path. Occasionally useful.
;;
;; SYMBOL COMPLETION: In elisp or other languages with an inferior
;; process attached, complete symbols based on what is currently
;; defined. This should not affect buffers in other modes (a current
;; bug).
;;
;; LANGUAGE COMPLETION: Complete substrings that are known to exist in
;; a language. In the current configuration, I'm only doing this with
;; CSS.
;;
;; STATIC ANALYSIS COMPLETION: Complete methods and attributes on
;; classes. The current configuration only does this for Java with
;; eclim.

(defun wh/company-code ()
  "Generic completion in programming language buffers.
We just use symbols and lines from any open buffers in the current mode."
  (interactive)
  (let ((company-backends '((company-whole-line company-dabbrev-code))))
    (company-complete)))

;; yasnippet, clever abbreviation expansion
(require 'yasnippet)

;; candidate. Otherwise, we end with a function foo shown as "foof".
(setq company-tooltip-align-annotations t)

;; Use C-n and C-p when company is active (for consistency with helm).
(define-key company-active-map (kbd "C-n") #'company-select-next)
(define-key company-active-map (kbd "C-p") #'company-select-previous)
