<commit_before>;;; completion/company/config.el

(def-setting! :company-backend (modes backends)
  "Register company BACKENDS to MODES."
  (let* ((modes (if (listp modes) modes (list modes)))
         (backends (if (listp backends) backends (list backends)))
         (def-name (intern (format "doom--init-company-%s"
                                   (mapconcat #'identity (mapcar #'symbol-name modes) "-"))))
         (quoted (eq (car-safe backends) 'quote)))
    ;; TODO more type checks
    `(progn
       (defun ,def-name ()
         (require 'company)
         (setq-local company-backends (append '((,@backends)) company-backends)))
       (add-hook! ,modes ',def-name))))


;;
;; Packages
;;

(def-package! company
  :commands (company-mode global-company-mode company-complete
             company-complete-common company-manual-begin company-grab-line)
  :config
  (setq company-idle-delay nil
        company-minimum-prefix-length 2
        company-tooltip-limit 10
        company-dabbrev-downcase nil
        company-dabbrev-ignore-case nil
        company-dabbrev-code-other-buffers t
        company-tooltip-align-annotations t
        company-require-match 'never
        company-global-modes '(not eshell-mode comint-mode erc-mode message-mode help-mode)
        company-frontends '(company-pseudo-tooltip-frontend company-echo-metadata-frontend)
        company-backends '(company-capf))

  (push #'company-sort-by-occurrence company-transformers)

  (after! yasnippet
    (nconc company-backends '(company-yasnippet)))

  (map! (:map company-active-map
          ;; Don't interfere with `evil-delete-backward-word' in insert mode
          "C-w"        nil

          "C-o"        #'company-search-kill-others
          "C-n"        #'company-select-next
          "C-p"        #'company-select-previous
          "C-h"        #'company-quickhelp-manual-begin
          "C-S-h"      #'company-show-doc-buffer
          "C-S-s"      #'company-search-candidates
          "C-s"        #'company-filter-candidates
          "C-SPC"      #'company-complete-common
          "C-h"        #'company-quickhelp-manual-begin
          [tab]        #'company-complete-common-or-cycle
          [backtab]    #'company-select-previous
          [escape]     (λ! (company-abort) (evil-normal-state 1)))

        ;; Automatically applies to `company-filter-map'
        (:map company-search-map
          "C-n"        #'company-search-repeat-forward
          "C-p"        #'company-search-repeat-backward
          "C-s"        (λ! (company-search-abort) (company-filter-candidates))
          [escape]     #'company-search-abort))

  (global-company-mode +1))


(def-package! company-statistics
  :after company
  :config
  (setq company-statistics-file (concat doom-cache-dir "company-stats-cache.el"))
  (company-statistics-mode +1))


;; Looks ugly on OSX without emacs-mac build
(def-package! company-quickhelp
  :after company
  :config
  (setq company-quickhelp-delay nil)
  (company-quickhelp-mode +1))


(def-package! company-dict
  :commands company-dict
  :config
  ;; Project-specific dictionaries
  (defun +company|enable-project-dicts (mode &rest _)
    (if (symbol-value mode)
        (push mode company-dict-minor-mode-list)
      (setq company-dict-minor-mode-list (delq mode company-dict-minor-mode-list))))
  (add-hook 'doom-project-hook #'+company|enable-project-dicts))


;;
;; Autoloads
;;

(autoload 'company-capf "company-capf")
(autoload 'company-yasnippet "company-yasnippet")
(autoload 'company-dabbrev "company-dabbrev")<commit_msg>completion/company: silence company-statistic-mode load-file call<commit_after>;;; completion/company/config.el

(def-setting! :company-backend (modes backends)
  "Register company BACKENDS to MODES."
  (let* ((modes (if (listp modes) modes (list modes)))
         (backends (if (listp backends) backends (list backends)))
         (def-name (intern (format "doom--init-company-%s"
                                   (mapconcat #'identity (mapcar #'symbol-name modes) "-"))))
         (quoted (eq (car-safe backends) 'quote)))
    ;; TODO more type checks
    `(progn
       (defun ,def-name ()
         (require 'company)
         (setq-local company-backends (append '((,@backends)) company-backends)))
       (add-hook! ,modes ',def-name))))


;;
;; Packages
;;

(def-package! company
  :commands (company-mode global-company-mode company-complete
             company-complete-common company-manual-begin company-grab-line)
  :config
  (setq company-idle-delay nil
        company-minimum-prefix-length 2
        company-tooltip-limit 10
        company-dabbrev-downcase nil
        company-dabbrev-ignore-case nil
        company-dabbrev-code-other-buffers t
        company-tooltip-align-annotations t
        company-require-match 'never
        company-global-modes '(not eshell-mode comint-mode erc-mode message-mode help-mode)
        company-frontends '(company-pseudo-tooltip-frontend company-echo-metadata-frontend)
        company-backends '(company-capf))

  (push #'company-sort-by-occurrence company-transformers)

  (after! yasnippet
    (nconc company-backends '(company-yasnippet)))

  (map! (:map company-active-map
          ;; Don't interfere with `evil-delete-backward-word' in insert mode
          "C-w"        nil

          "C-o"        #'company-search-kill-others
          "C-n"        #'company-select-next
          "C-p"        #'company-select-previous
          "C-h"        #'company-quickhelp-manual-begin
          "C-S-h"      #'company-show-doc-buffer
          "C-S-s"      #'company-search-candidates
          "C-s"        #'company-filter-candidates
          "C-SPC"      #'company-complete-common
          "C-h"        #'company-quickhelp-manual-begin
          [tab]        #'company-complete-common-or-cycle
          [backtab]    #'company-select-previous
          [escape]     (λ! (company-abort) (evil-normal-state 1)))

        ;; Automatically applies to `company-filter-map'
        (:map company-search-map
          "C-n"        #'company-search-repeat-forward
          "C-p"        #'company-search-repeat-backward
          "C-s"        (λ! (company-search-abort) (company-filter-candidates))
          [escape]     #'company-search-abort))

  (global-company-mode +1))


(def-package! company-statistics
  :after company
  :config
  (setq company-statistics-file (concat doom-cache-dir "company-stats-cache.el"))
  (quiet! (company-statistics-mode +1)))


;; Looks ugly on OSX without emacs-mac build
(def-package! company-quickhelp
  :after company
  :config
  (setq company-quickhelp-delay nil)
  (company-quickhelp-mode +1))


(def-package! company-dict
  :commands company-dict
  :config
  ;; Project-specific dictionaries
  (defun +company|enable-project-dicts (mode &rest _)
    (if (symbol-value mode)
        (push mode company-dict-minor-mode-list)
      (setq company-dict-minor-mode-list (delq mode company-dict-minor-mode-list))))
  (add-hook 'doom-project-hook #'+company|enable-project-dicts))


;;
;; Autoloads
;;

(autoload 'company-capf "company-capf")
(autoload 'company-yasnippet "company-yasnippet")
(autoload 'company-dabbrev "company-dabbrev")
{'fraction_non_alphanumeric': 0.13842946490618485, 'fraction_numerical': 0.0019457956914523975, 'mean_word_length': 2.5483234714003946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851858', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2261, 'n_words': 456}