From 32043bfebe5c9ded91a1040c185e3cfc84e5ba33 Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:06:11 -0400 Subject: [PATCH] Add corfu and cape to README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index d3f1dcc..48d2eca 100644 --- a/README.md +++ b/README.md @@ -435,6 +435,7 @@ You can also add the following code to enable commenting and uncommenting by pre To set up Language Server Protocol (LSP) servers using Eglot, you can configure it in your Emacs setup as follows. This configuration ensures minimal disruption from Eglot’s progress reporting and optimizes performance by disabling unnecessary logging. +To configure `eglot`, add the following to `~/.emacs.d/post-init.el`: ``` emacs-lisp (use-package eglot :ensure nil @@ -478,6 +479,47 @@ Here is an example of how to configure Eglot to enable or disable certain option (add-hook 'python-ts-mode-hook #'eglot) ``` +### Code completion with corfu + +Corfu enhances in-buffer completion by displaying a compact popup with current candidates, positioned either below or above the point. Candidates can be selected by navigating up or down. + +Cape, or Completion At Point Extensions, extends the capabilities of in-buffer completion. It integrates with Corfu or the default completion UI, by providing additional backends through completion-at-point-functions. + +To configure `corfu` and `cape`, add the following to `~/.emacs.d/post-init.el`: +``` emacs-lisp +(use-package corfu + :ensure t + :defer t + :commands (corfu-mode global-corfu-mode) + + :hook ((prog-mode . corfu-mode) + (shell-mode . corfu-mode) + (eshell-mode . corfu-mode)) + + :custom + ;; Hide commands in M-x which do not apply to the current mode. + (read-extended-command-predicate #'command-completion-default-include-p) + ;; Disable Ispell completion function. As an alternative try `cape-dict'. + (text-mode-ispell-word-completion nil) + (tab-always-indent 'complete) + + ;; Enable Corfu + :config + (global-corfu-mode)) + +(use-package cape + :ensure t + :defer t + :commands (cape-dabbrev cape-file cape-elisp-block) + :bind ("C-c p" . cape-prefix-map) + :init + ;; Add to the global default value of `completion-at-point-functions' which is + ;; used by `completion-at-point'. + (add-hook 'completion-at-point-functions #'cape-dabbrev) + (add-hook 'completion-at-point-functions #'cape-file) + (add-hook 'completion-at-point-functions #'cape-elisp-block)) +``` + ### How to configure straight.el? [Add the straight.el bootstrap code](https://github.com/radian-software/straight.el?tab=readme-ov-file#getting-started) to `~/.emacs.d/pre-init.el`: