Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #+title: Auto Completion
- * Hippie-expand
- #+begin_src emacs-lisp :section init
- (dolist (f '(try-expand-line try-expand-list))
- (setq hippie-expand-try-functions-list
- (remq f hippie-expand-try-functions-list)))
- #+end_src
- #+begin_src emacs-lisp :section bindings
- (define-key evil-insert-state-map (kbd "M-/") 'dabbrev-completion)
- (define-key evil-insert-state-map (kbd "C-M-/") 'hippie-expand)
- #+end_src
- * Bindings
- #+begin_src emacs-lisp :section bindings
- (define-key evil-insert-state-map (kbd "S-SPC") #'cycle-spacing)
- #+end_src
- * Cape
- https://github.com/minad/cape
- #+begin_src emacs-lisp :section features
- (use-package cape
- ;; Bind dedicated completion commands
- :bind (("C-c p p" . completion-at-point) ;; capf
- ("C-c p t" . complete-tag) ;; etags
- ("C-c p d" . cape-dabbrev) ;; or dabbrev-completion
- ("C-c p f" . cape-file)
- ("C-c p k" . cape-keyword)
- ("C-c p s" . cape-symbol)
- ("C-c p a" . cape-abbrev)
- ("C-c p i" . cape-ispell)
- ("C-c p l" . cape-line)
- ("C-c p w" . cape-dict)
- ("C-c p \\" . cape-tex)
- ("C-c p _" . cape-tex)
- ("C-c p ^" . cape-tex)
- ("C-c p &" . cape-sgml)
- ("C-c p r" . cape-rfc1345))
- :init
- ;; Add `completion-at-point-functions', used by `completion-at-point'.
- (add-to-list 'completion-at-point-functions #'cape-file)
- ;; (add-to-list 'completion-at-point-functions #'cape-tex)
- (add-to-list 'completion-at-point-functions #'cape-dabbrev)
- (add-to-list 'completion-at-point-functions #'cape-keyword)
- ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
- ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
- ;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
- ;;(add-to-list 'completion-at-point-functions #'cape-ispell)
- ;;(add-to-list 'completion-at-point-functions #'cape-dict)
- ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
- ;;(add-to-list 'completion-at-point-functions #'cape-line)
- )
- #+end_src
- * Corfu
- #+begin_src emacs-lisp :section features
- (use-package corfu)
- #+end_src
- * English dictionary
- Taken from: [[http://justinhj.github.io/2018/10/24/radix-trees-dash-and-company-mode.html][radix-trees-dash-and-company-mode]]
- #+begin_src emacs-lisp :section defvars
- (defvar hfj/rt-dict-base (expand-file-name ".cache/english-dictionary" user-emacs-directory))
- (defvar hfj/company-english-dictionary--words-tree)
- #+end_src
- TODO: Replace with cape
- #+begin_src emacs-lisp :section features
- (with-eval-after-load 'company
- (defun hfj/not-prog-or-in-comment ()
- (cond ((derived-mode-p 'prog-mode)
- (nth 4 (syntax-ppss))) ;; in comment
- ((derived-mode-p 'comint-mode)
- nil)
- (t
- t)))
- (defun hfj/company-english-dictionary (command &optional arg &rest ignored)
- "Company mode backend for a english dictionary stored as a radix tree."
- (interactive (list 'interactive))
- (cl-flet ((get-candidates (word)
- (hfj/radix-tree-keys hfj/company-english-dictionary--words-tree
- (downcase word))))
- (cl-case command
- (init (unless (boundp 'hfj/company-english-dictionary--words-tree)
- (unless (or (file-exists-p (concat hfj/rt-dict-base ".elc"))
- ;; elc files might be removed due to native compile problems
- (and hfj/native-compile (file-exists-p (concat hfj/rt-dict-base ".el"))))
- (let ((rt-dict (hfj/radix-tree-from-file-downcased (expand-file-name "english.txt" user-emacs-directory)))
- (el-path (concat hfj/rt-dict-base ".el")))
- (hfj/write-text-to-file (format "(defvar hfj/company-english-dictionary--words-tree '%S)" rt-dict)
- el-path)
- (byte-compile-file el-path)))
- (load hfj/rt-dict-base)))
- (prefix (and (hfj/not-prog-or-in-comment)
- (let ((word (company-grab-word)))
- (when (and word (get-candidates word))
- word))))
- (candidates (get-candidates arg))
- (ignore-case 'keep-prefix))))
- ;; If you want to change the dictionary, rewrite dictionary.el and unintern the symbol
- ;; (unintern 'hfj/company-english-dictionary--words-tree)
- ;; Place after company-files to avoid conflicting with code
- (run-at-time 10 nil
- (lambda ()
- (setq company-backends
- (let ((parts (-partition-after-item 'company-files company-backends)))
- (append (car parts) '(hfj/company-english-dictionary) (cadr parts)))))))
- #+end_src
Advertisement
Add Comment
Please, Sign In to add comment