Guest User

Untitled

a guest
Mar 8th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. #+title: Auto Completion
  2.  
  3. * Hippie-expand
  4. #+begin_src emacs-lisp :section init
  5. (dolist (f '(try-expand-line try-expand-list))
  6. (setq hippie-expand-try-functions-list
  7. (remq f hippie-expand-try-functions-list)))
  8. #+end_src
  9.  
  10. #+begin_src emacs-lisp :section bindings
  11. (define-key evil-insert-state-map (kbd "M-/") 'dabbrev-completion)
  12. (define-key evil-insert-state-map (kbd "C-M-/") 'hippie-expand)
  13. #+end_src
  14.  
  15. * Bindings
  16. #+begin_src emacs-lisp :section bindings
  17. (define-key evil-insert-state-map (kbd "S-SPC") #'cycle-spacing)
  18. #+end_src
  19.  
  20. * Cape
  21. https://github.com/minad/cape
  22.  
  23. #+begin_src emacs-lisp :section features
  24. (use-package cape
  25. ;; Bind dedicated completion commands
  26. :bind (("C-c p p" . completion-at-point) ;; capf
  27. ("C-c p t" . complete-tag) ;; etags
  28. ("C-c p d" . cape-dabbrev) ;; or dabbrev-completion
  29. ("C-c p f" . cape-file)
  30. ("C-c p k" . cape-keyword)
  31. ("C-c p s" . cape-symbol)
  32. ("C-c p a" . cape-abbrev)
  33. ("C-c p i" . cape-ispell)
  34. ("C-c p l" . cape-line)
  35. ("C-c p w" . cape-dict)
  36. ("C-c p \\" . cape-tex)
  37. ("C-c p _" . cape-tex)
  38. ("C-c p ^" . cape-tex)
  39. ("C-c p &" . cape-sgml)
  40. ("C-c p r" . cape-rfc1345))
  41. :init
  42. ;; Add `completion-at-point-functions', used by `completion-at-point'.
  43. (add-to-list 'completion-at-point-functions #'cape-file)
  44. ;; (add-to-list 'completion-at-point-functions #'cape-tex)
  45. (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  46. (add-to-list 'completion-at-point-functions #'cape-keyword)
  47. ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
  48. ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
  49. ;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
  50. ;;(add-to-list 'completion-at-point-functions #'cape-ispell)
  51. ;;(add-to-list 'completion-at-point-functions #'cape-dict)
  52. ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
  53. ;;(add-to-list 'completion-at-point-functions #'cape-line)
  54. )
  55. #+end_src
  56.  
  57. * Corfu
  58. #+begin_src emacs-lisp :section features
  59. (use-package corfu)
  60. #+end_src
  61.  
  62. * English dictionary
  63. Taken from: [[http://justinhj.github.io/2018/10/24/radix-trees-dash-and-company-mode.html][radix-trees-dash-and-company-mode]]
  64. #+begin_src emacs-lisp :section defvars
  65. (defvar hfj/rt-dict-base (expand-file-name ".cache/english-dictionary" user-emacs-directory))
  66. (defvar hfj/company-english-dictionary--words-tree)
  67. #+end_src
  68.  
  69. TODO: Replace with cape
  70. #+begin_src emacs-lisp :section features
  71. (with-eval-after-load 'company
  72. (defun hfj/not-prog-or-in-comment ()
  73. (cond ((derived-mode-p 'prog-mode)
  74. (nth 4 (syntax-ppss))) ;; in comment
  75. ((derived-mode-p 'comint-mode)
  76. nil)
  77. (t
  78. t)))
  79.  
  80. (defun hfj/company-english-dictionary (command &optional arg &rest ignored)
  81. "Company mode backend for a english dictionary stored as a radix tree."
  82. (interactive (list 'interactive))
  83. (cl-flet ((get-candidates (word)
  84. (hfj/radix-tree-keys hfj/company-english-dictionary--words-tree
  85. (downcase word))))
  86. (cl-case command
  87. (init (unless (boundp 'hfj/company-english-dictionary--words-tree)
  88. (unless (or (file-exists-p (concat hfj/rt-dict-base ".elc"))
  89. ;; elc files might be removed due to native compile problems
  90. (and hfj/native-compile (file-exists-p (concat hfj/rt-dict-base ".el"))))
  91. (let ((rt-dict (hfj/radix-tree-from-file-downcased (expand-file-name "english.txt" user-emacs-directory)))
  92. (el-path (concat hfj/rt-dict-base ".el")))
  93. (hfj/write-text-to-file (format "(defvar hfj/company-english-dictionary--words-tree '%S)" rt-dict)
  94. el-path)
  95. (byte-compile-file el-path)))
  96. (load hfj/rt-dict-base)))
  97. (prefix (and (hfj/not-prog-or-in-comment)
  98. (let ((word (company-grab-word)))
  99. (when (and word (get-candidates word))
  100. word))))
  101. (candidates (get-candidates arg))
  102. (ignore-case 'keep-prefix))))
  103.  
  104. ;; If you want to change the dictionary, rewrite dictionary.el and unintern the symbol
  105. ;; (unintern 'hfj/company-english-dictionary--words-tree)
  106.  
  107. ;; Place after company-files to avoid conflicting with code
  108. (run-at-time 10 nil
  109. (lambda ()
  110. (setq company-backends
  111. (let ((parts (-partition-after-item 'company-files company-backends)))
  112. (append (car parts) '(hfj/company-english-dictionary) (cadr parts)))))))
  113. #+end_src
  114.  
Advertisement
Add Comment
Please, Sign In to add comment