From 3299dc9f9c87cb85b573c1a69f806c32bdf3f741 Mon Sep 17 00:00:00 2001 From: Matt Nish-Lapidus Date: Wed, 29 Mar 2023 17:03:22 -0400 Subject: [PATCH] switched to pr version of corfu and added more keybinds --- bindings.el | 24 +- config.el | 10 +- init.el | 14 +- modules/completion/corfu/README.org | 153 ++++++++ modules/completion/corfu/autoload/extra.el | 39 -- .../completion/corfu/autoload/minad-capf.el | 75 ---- .../completion/corfu/autoload/minibuffer.el | 13 - modules/completion/corfu/config.el | 363 ++++++++---------- modules/completion/corfu/packages.el | 25 +- packages.el | 3 +- 10 files changed, 363 insertions(+), 356 deletions(-) create mode 100644 modules/completion/corfu/README.org delete mode 100644 modules/completion/corfu/autoload/extra.el delete mode 100644 modules/completion/corfu/autoload/minad-capf.el delete mode 100644 modules/completion/corfu/autoload/minibuffer.el diff --git a/bindings.el b/bindings.el index 0c16f95..9571af6 100644 --- a/bindings.el +++ b/bindings.el @@ -2,6 +2,27 @@ (setq doom-localleader-alt-key "C-SPC") +(map! (:when (modulep! :ui popup) + "C-`" #'+popup/toggle + "C-~" #'+popup/raise + "C-x p" #'+popup/other) + + (:when (modulep! :ui workspaces) + (:when IS-MAC + "s-t" #'+workspace/new + "s-T" #'+workspace/display + "s-1" #'+workspace/switch-to-0 + "s-2" #'+workspace/switch-to-1 + "s-3" #'+workspace/switch-to-2 + "s-4" #'+workspace/switch-to-3 + "s-5" #'+workspace/switch-to-4 + "s-6" #'+workspace/switch-to-5 + "s-7" #'+workspace/switch-to-6 + "s-8" #'+workspace/switch-to-7 + "s-9" #'+workspace/switch-to-8 + "s-0" #'+workspace/switch-to-final))) + + (map! :leader "`" nil (:prefix ("m" . "")) ; bound locally @@ -168,7 +189,6 @@ :desc "Dictionary" "t" #'+lookup/dictionary-definition :desc "Thesaurus" "T" #'+lookup/synonyms) - ;;; t --- toggle (:prefix-map ("t" . "toggle") :desc "Big mode" "b" #'doom-big-font-mode @@ -345,7 +365,7 @@ :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines :desc "List errors" "x" #'+default/diagnostics) - ;;; q --- quit/restart +;;; q --- quit/restart (:prefix-map ("q" . "quit/session") :desc "Restart emacs server" "d" #'+default/restart-server :desc "Delete frame" "f" #'delete-frame diff --git a/config.el b/config.el index a250618..a03d6eb 100644 --- a/config.el +++ b/config.el @@ -37,7 +37,7 @@ doom-modeline-major-mode-icon t)) ;; fixing compat issue for corfu in emacs28 -(defalias 'compat-string-width 'string-width) +;; (defalias 'compat-string-width 'string-width) ;; some global settings (setq tab-always-indent t) ; don't autocomplete with tab @@ -78,9 +78,8 @@ "M-" nil "M-" nil) -;; treemacs -- NOTE i'm not using this right now, switched back to neotree for now -;; (setq treemacs-follow-mode t) -;; (setq treemacs-project-follow-mode t) +(setq treemacs-follow-mode t) +(setq treemacs-project-follow-mode t) ;; smart tabs set modes (after! smart-tabs-mode @@ -97,9 +96,6 @@ '(orderless))) (add-hook! lsp-completion-mode 'my/lsp-mode-setup-completion)) -(after! lisp-mode - (setq lsp-completion-provider :none)) - ;; bibliography file location (after! citar (setq! citar-bibliography '("/Users/emenel/Zotero/lib.bib")) diff --git a/init.el b/init.el index 36796f1..cd95579 100644 --- a/init.el +++ b/init.el @@ -26,7 +26,7 @@ ;;ido ; the other *other* search engine... ;;ivy ; a search engine for love and life (vertico +icons +orderless) ; the search engine of the future - (corfu +icons +orderless) + (corfu +icons) :ui ;;deft ; notational velocity for Emacs @@ -41,11 +41,11 @@ ;; minimap ; show a map of the code on the side modeline ; snazzy, Atom-inspired modeline, plus API nav-flash ; blink cursor line after big motions - neotree ; a project drawer, like NERDTree for vim + ;; neotree ; a project drawer, like NERDTree for vim ophints ; highlight the region an operation acts on (popup +all +defaults) ; tame sudden yet inevitable temporary windows tabs ; a tab bar for Emacs - ;; treemacs ; a project drawer, like neotree but cooler + treemacs ; a project drawer, like neotree but cooler ;;unicode ; extended unicode support for various languages (vc-gutter +pretty) ; vcs diff in the fringe vi-tilde-fringe ; fringe tildes to mark beyond EOB @@ -97,7 +97,7 @@ (eval +overlay) ; run code, run (also, repls) ;;gist ; interacting with github gists lookup ; navigate your code and its documentation - lsp ; M-x vscode + (lsp) ; M-x vscode magit ; a git porcelain for Emacs ;;make ; run make tasks from Emacs ;;pass ; password manager for nerds @@ -139,7 +139,7 @@ ;;gdscript ; the language you waited for ;;(go +lsp) ; the hipster dialect ;;(graphql +lsp) ; Give queries a REST - (haskell +lsp +tree-sitter) ; a language that's lazier than I am + (haskell +tree-sitter) ; a language that's lazier than I am ;;hy ; readability of scheme w/ speed of python ;;idris ; a language you can depend on (json +lsp +tree-sitter) ; At least it ain't XML @@ -153,7 +153,7 @@ lua ; one-based indices? one-based indices (markdown +tree-sitter) ; writing docs for people to ignore ;;nim ; python + lisp at the speed of c - ;;nix ; I hereby declare "nix geht mehr!" + ;;nix ; I hereby Declare "nix geht mehr!" ;;ocaml ; an objective camel (org +pretty) ; organize your plain life in plain text php ; perl's insecure younger brother @@ -175,7 +175,7 @@ ;;swift ; who asked for emoji variables? ;;terra ; Earth and Moon in alignment for performance. (web +lsp +tree-sitter) - (yaml +tree-sitter) ; JSON, but readable + (yaml +tree-sitter) ; JSON, but readable ;;zig ; C, but simpler :email diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org new file mode 100644 index 0000000..60cb7ec --- /dev/null +++ b/modules/completion/corfu/README.org @@ -0,0 +1,153 @@ +#+title: :completion corfu +#+subtitle: Complete with cap(f), cape and a flying feather +#+created: September 9, 2022 +#+since: 3.0.0 (#7002) + +* Description :unfold: +This module provides code completion, powered by [[https://github.com/minad/corfu][corfu]]. + +It is recommended to enable either this or [[doom-module:][:completion company]], in case you +desire pre-configured auto-completion. Corfu is much lighter weight and focused, +plus it's built on native Emacs functionality, whereas company is heavy and +highly non-native, but has some extra features and more maturity. + +** Maintainers +- [[doom-user:][@LuigiPiucco]] + +[[doom-contrib-maintainer:][Become a maintainer?]] + +** Module flags +- +icons :: + Display icons beside completion suggestions. +- +tng :: + Invoke completion on [[kbd:][TAB]]. When corfu is active, [[kbd:][TAB]] and [[kbd:][S-TAB]] will navigate + the completion candidates. Arrow keys and evil-style movement are still + supported. + +** Packages +- [[doom-package:][corfu]] +- [[doom-package:][cape]] +- [[doom-package:][kind-icon]] if [[doom-module:][:completion corfu +icons]] +- [[doom-package:][corfu-terminal]] if [[doom-module:][:os tty]] + +** Hacks +/No hacks documented for this module./ + +** TODO Changelog +# This section will be machine generated. Don't edit it by hand. +/This module does not have a changelog yet./ + +* Installation +Enable this module in your ~doom!~ block. + +This module has no direct requirements, but some languages may have their own +requirements to fulfill before you get code completion in them (and some +languages may lack code completion support altogether). Run ~$ doom doctor~ to +find out if you're missing any dependencies. Note that corfu may have support +for completions in languages that have no development intelligence, since it +supports generic, context insensitive candidates such as file names or recurring +words. + +* TODO Usage +#+begin_quote + 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] +#+end_quote + +** Code completion +By default, completion gets triggered after typing 2 non-space consecutive +characters, or by means of the [[kbd:][C-SPC]] keybinding at any moment. While the popup +is visible, the following relevant keys are available: + +| Keybind | Description | +|----------+------------------------------------------------------| +| [[kbd:][]] | Go to next candidate | +| [[kbd:][]] | Go to previous candidate | +| [[kbd:][C-n]] | Go to next candidate | +| [[kbd:][C-p]] | Go to previous candidate | +| [[kbd:][C-j]] | (evil) Go to next candidate | +| [[kbd:][C-k]] | (evil) Go to previous candidate | +| [[kbd:][C-]] | Go to next doc line | +| [[kbd:][C-]] | Go to previous doc line | +| [[kbd:][C-S-n]] | Go to next doc line | +| [[kbd:][C-S-p]] | Go to previous doc line | +| [[kbd:][C-S-j]] | (evil) Go to next doc line | +| [[kbd:][C-S-k]] | (evil) Go to previous doc line | +| [[kbd:][C-h]] | Toggle documentation (if available) | +| [[kbd:][s-]] | Export to minibuffer (if [[doom-module:][:completion vertico]]) | +| [[kbd:][s-j]] | (evil) Export to minibuffer (if [[doom-module:][:completion vertico]]) | +| [[kbd:][RET]] | Insert candidate | +| [[kbd:][C-SPC]] | (when completing) Insert separator (see below) | +| [[kbd:][C-SPC]] | Complete (unless [[doom-module:][:completion corfu +tng]]) | + +If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module:][:completion corfu +tng]] +flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the following +additional binds: + +| Keybind | Description | +|---------+--------------------------------------------| +| [[kbd:][TAB]] | Complete | +| [[kbd:][TAB]] | (when completing) Go to next candidate | +| [[kbd:][S-TAB]] | (when completing) Go to previous candidate | + +** Searching with multiple keywords +If the [[doom-module:][:completion vertico]] module is enabled, users can perform code completion +with multiple search keywords by use of space as separator. More information can +be found [[https://github.com/oantolin/orderless#company][here]]. Pressing [[kdb:][C-SPC]] again while completing inserts a space as +separator. This allows searching with space-separated terms; each piece will +match individually and in any order, with smart casing. Pressing just [[kbd:][SPC]] acts +as normal and restarts completion, so that when typing sentences it doesn't try +to complete the whole sentence instead of just the word. + +Without [[doom-module:][:completion vertico]], it still works, just not as intelligently, due to +the lack of orderless. + +** Exporting to the minibuffer (requires [[doom-module:][:completion vertico]]) +When using the [[doom-module:][:completion vertico]] module, which pulls in the [[doom-package:][consult]] package, +the entries shown in the completion popup can be exported to a consult +minibuffer, giving access to all the manipulations the vertico suite allows. For +instance, one could use this to export with [[doom-package:][embark]] via [[kbd:][C-c C-l]] and get a buffer +with all candidates. + +** Ispell completion +Ispell completion is supported, so long as you point to the right ~.dic~ file in +~ispell-alternate-dictionary~. For selected text modes (see the configuration +section) it completes everywhere, for programming modes it can complete in +comments and strings. + +* Configuration +A few variables may be set to change behavior of this module: + +- +corfu-auto-delay :: + Number of seconds till completion occurs automatically. Defaults to 0.1. +- +corfu-auto-prefix :: + Number of characters till auto-completion starts to happen. Defaults to 2. +- +corfu-want-multi-component :: + Sets whether orderless-style matching should be supported with space as a + separator. +- +corfu-ispell-completion-modes :: + Lists modes in which to add ~cape-ispell~ as a capf. These show be majorly + text modes, else you will get lots of bad suggestions, since when this matches + it interrupts the flow of candidate selection. +- +corfu-ispell-in-comments-and-strings :: + Whether we should complete when point is inside a string or comment. If + non-nil, works as in a text mode, else gives programming completions just like + in the rest of the buffer. + +Additionally, if you prefer to never stop completion on [[kbd:][SPC]], add the following +to your ~config.el~: + +#+begin_src emacs-lisp +(map! :map corfu-map + :desc "insert separator" "C-SPC" #'corfu-insert-separator) +#+end_src + +* Troubleshooting +[[doom-report:][Report an issue?]] + +* Frequently asked questions +/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] + +* TODO Appendix +#+begin_quote + 🔨 This module has no appendix yet. [[doom-contrib-module:][Write one?]] +#+end_quote diff --git a/modules/completion/corfu/autoload/extra.el b/modules/completion/corfu/autoload/extra.el deleted file mode 100644 index 3f9739c..0000000 --- a/modules/completion/corfu/autoload/extra.el +++ /dev/null @@ -1,39 +0,0 @@ -;;; completion/corfu/autoload.el -*- lexical-binding: t; -*- - -;;;###autoload -(defun +corfu-complete-file-at-point () - "Complete a file path from scratch at point" - (interactive) - (completion-in-region (point) (point) #'read-file-name-internal)) - -;;;###autoload -(defun +corfu-files () - "Complete using files source" - (interactive) - (let ((completion-at-point-functions (list #'+file-completion-at-point-function))) - (completion-at-point))) - -;;;###autoload -(defun +corfu-dabbrev () - "Complete using dabbrev source" - (interactive) - (let ((completion-at-point-functions (list #'+dabbrev-completion-at-point-function))) - (completion-at-point))) - -;;;###autoload -(defun +corfu-ispell () - "Complete using ispell source. - -See `ispell-lookup-words' for more info" - (interactive) - (let ((completion-at-point-functions (list #'+ispell-completion-at-point-function))) - (completion-at-point))) - -;;;###autoload -(defun +corfu-dict () - "Complete using dict source. - -See `+dict--words' for extra words, and `+dict-file' for a wordslist source " - (interactive) - (let ((completion-at-point-functions (list #'+dict-completion-at-point-function))) - (completion-at-point))) diff --git a/modules/completion/corfu/autoload/minad-capf.el b/modules/completion/corfu/autoload/minad-capf.el deleted file mode 100644 index 6bea695..0000000 --- a/modules/completion/corfu/autoload/minad-capf.el +++ /dev/null @@ -1,75 +0,0 @@ -;; Daniel "minad" Mendler extra capfs -*- lexical-binding: t -*- -;; Source : https://github.com/minad/corfu/issues/9#issuecomment-945090516 - -(require 'dabbrev) - -;;;###autoload -(defun +file-completion-at-point-function () - "File name completion-at-point-function." - (when-let (bounds (bounds-of-thing-at-point 'filename)) - (list (car bounds) (cdr bounds) - 'read-file-name-internal - :exclusive 'no - :annotation-function (lambda (_) " (File)")))) - -;;;###autoload -(defun +dabbrev-completion-at-point-function () - (let ((dabbrev-check-all-buffers nil) - (dabbrev-check-other-buffers nil)) - (dabbrev--reset-global-variables)) - (let ((abbrev (ignore-errors (dabbrev--abbrev-at-point)))) - (when (and abbrev (not (string-match-p "[ \t]" abbrev))) - (pcase ;; Interruptible scanning - (while-no-input - (let ((inhibit-message t) - (message-log-max nil)) - (or (dabbrev--find-all-expansions - abbrev (dabbrev--ignore-case-p abbrev)) - t))) - ('nil (keyboard-quit)) - ('t nil) - (words - ;; Ignore completions which are too short - (let ((min-len (+ 4 (length abbrev)))) - (setq words (seq-remove (lambda (x) (< (length x) min-len)) words))) - (when words - (let ((beg (progn (search-backward abbrev) (point))) - (end (progn (search-forward abbrev) (point)))) - (unless (string-match-p "\n" (buffer-substring beg end)) - (list beg end words - :exclusive 'no - :annotation-function (lambda (_) " (Dabbrev)")))))))))) - -(autoload 'ispell-lookup-words "ispell") - -;;;###autoload -(defun +ispell-completion-at-point-function () - (when-let* ((bounds (bounds-of-thing-at-point 'word)) - (table (with-demoted-errors - (let ((message-log-max nil) - (inhibit-message t)) - (ispell-lookup-words - (format "*%s*" - (buffer-substring-no-properties (car bounds) (cdr bounds)))))))) - (list (car bounds) (cdr bounds) table - :exclusive 'no - :annotation-function (lambda (_) " (Ispell)")))) - -(defun +word-completion-at-point-function (words) - (when-let (bounds (bounds-of-thing-at-point 'word)) - (list (car bounds) (cdr bounds) words - :exclusive 'no - :annotation-function (lambda (_) " (Words)")))) - -(defvar +dict--words nil) -(defvar +dict-file "/etc/dictionaries-common/words") - -;;;###autoload -(defun +dict-completion-at-point-function () - (+word-completion-at-point-function - (or +dict--words - (setq +dict--words - (split-string (with-temp-buffer - (insert-file-contents-literally +dict-file) - (buffer-string)) - "\n"))))) diff --git a/modules/completion/corfu/autoload/minibuffer.el b/modules/completion/corfu/autoload/minibuffer.el deleted file mode 100644 index 7f5d455..0000000 --- a/modules/completion/corfu/autoload/minibuffer.el +++ /dev/null @@ -1,13 +0,0 @@ -;;; completion/corfu/autoload/corfu.el -*- lexical-binding: t; -*- -;;;###if (modulep! :completion corfu +minibuffer) - -;;;###autoload -(defun +corfu--enable-in-minibuffer () - (unless (or (bound-and-true-p mct--active) - (bound-and-true-p vertico--input) - (memq this-command '(evil-ex - evil-ex-search-forward - evil-ex-search-backward)) - (and (modulep! :completion helm) - (helm--alive-p)) - (corfu-mode +1)))) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 4ce7a8d..e39a1bd 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -1,215 +1,188 @@ ;;; completion/corfu/config.el -*- lexical-binding: t; -*- -;; Corfu completion module +(defvar +corfu-auto-delay 0.1 + "How long after point stands still will completion be called automatically, +in seconds. -(defvar +corfu-global-capes - '(cape-yasnippet - :completion - cape-dict) - "A list of global capes to be available at all times. - The key :completion is used to specify where completion candidates should be - placed, otherwise they come first.") +Setting `corfu-auto-delay' directly may not work, as it needs to be set *before* +enabling `corfu-mode'.") +(defvar +corfu-auto-prefix 2 + "How many characters should be typed before auto-complete starts to kick in. -(defvar +corfu-capf-hosts - '(lsp-completion-at-point - eglot-completion-at-point - elisp-completion-at-point - tags-completion-at-point-function) - "A prioritised list of host capfs to create a super cape onto from - `+corfu-global-capes'.") +Setting `corfu-auto-prefix' directly may not work, as it needs to be set +*before* enabling `corfu-mode'.") +(defvar +corfu-want-multi-component t + "Enables multiple component search, with pieces separated by spaces. -(defun +corfu--load-capes () - "Load all capes specified in `+corfu-global-capes'." - (interactive) - (when-let ((host (cl-intersection +corfu-capf-hosts completion-at-point-functions))) - (setq-local - completion-at-point-functions - (cl-substitute - (apply #'cape-super-capf (cl-substitute (car host) :completion (cl-pushnew :completion +corfu-global-capes))) - (car host) - completion-at-point-functions)))) +This allows search of non-contiguous unordered bits, for instance by typing +\"tear rip\" to match \"rip-and-tear\". Notice the space, it does not break +completion in this case.") +(defvar +corfu-icon-height 0.9 + "The height applied to the icons (it is passed to both svg-lib and kind-icon). -(add-hook 'lsp-mode-hook #'+corfu--load-capes) -(add-hook 'eglot-mode-hook #'+corfu--load-capes) -(add-hook 'change-major-mode-hook #'+corfu--load-capes) +It may need tweaking for the completions to not become cropped at the end. +Note that changes are applied only after a cache reset, via +`kind-icon-reset-cache'.") +(defvar +corfu-ispell-completion-modes '(org-mode markdown-mode text-mode) + "Modes to enable ispell completion in. + +For completion in comments, see `+corfu-ispell-in-comments-and-strings'.") +(defvar +corfu-ispell-in-comments-and-strings t + "Enable completion with ispell inside comments when in a `prog-mode' +derivative.") + +;; +;;; Packages (use-package! corfu - :custom - (corfu-separator ?\s) - (corfu-auto t) - (corfu-auto-delay 0.2) - (corfu-preview-current nil) ;; Disable current candidate preview - (corfu-on-exact-match nil) - (corfu-quit-no-match 'separator) - (corfu-cycle t) - (corfu-auto-prefix 2) - (completion-cycle-threshold 1) - (tab-always-indent 'complete) - (corfu-max-width 80) - (corfu-preselect-first nil) - :hook - (doom-first-buffer . global-corfu-mode) - :config - (when (modulep! +minibuffer) - (add-hook 'minibuffer-setup-hook #'+corfu--enable-in-minibuffer)) - - ;; Dirty hack to get c completion running - ;; Discussion in https://github.com/minad/corfu/issues/34 - (when (and (modulep! :lang cc) - (equal tab-always-indent 'complete)) - (map! :map c-mode-base-map - :i [remap c-indent-line-or-region] #'completion-at-point)) - - ;; Reset lsp-completion provider - (add-hook 'doom-init-modules-hook - (lambda () - (after! lsp-mode - (setq lsp-completion-provider :none)))) - - ;; Set orderless filtering for LSP-mode completions - ;; TODO: expose a Doom variable to control this part - (add-hook 'lsp-completion-mode-hook - (lambda () - (setf (alist-get 'lsp-capf completion-category-defaults) '((styles . (orderless flex)))))) - - (defun corfu-move-to-minibuffer () - "Move current completions to the minibuffer" - (interactive) - (let ((completion-extra-properties corfu--extra) - completion-cycle-threshold completion-cycling) - (apply #'consult-completion-in-region completion-in-region--data))) - - (map! :map corfu-map - "C-SPC" #'corfu-insert-separator - "C-n" #'corfu-next - "C-p" #'corfu-previous - "M-m" #'corfu-move-to-minibuffer - (:prefix "C-x" - "C-k" #'cape-dict - "s" #'cape-ispell - "C-n" #'cape-keyword - "C-f" #'cape-file)) - (after! evil - (advice-add 'corfu--setup :after 'evil-normalize-keymaps) - (advice-add 'corfu--teardown :after 'evil-normalize-keymaps) - (evil-make-overriding-map corfu-map)) - - (defadvice! +corfu--org-return (orig) :around '+org/return - (if (and (modulep! :completion corfu) - corfu-mode - (>= corfu--index 0)) - (corfu-insert) - (funcall orig))) - - ;; TODO: check how to deal with Daemon/Client workflow with that - (unless (display-graphic-p) - (corfu-doc-terminal-mode) - (corfu-terminal-mode))) - -(use-package! orderless - :when (modulep! +orderless) + :hook (doom-first-buffer . global-corfu-mode) :init - (setq completion-styles '(orderless partial-completion) - completion-category-defaults nil - completion-category-overrides '((file (styles . (partial-completion)))))) + ;; Auto-completion settings, must be set before calling `global-corfu-mode'. + (setq corfu-auto t + corfu-auto-delay +corfu-auto-delay + corfu-auto-prefix +corfu-auto-prefix + corfu-excluded-modes '(erc-mode + circe-mode + help-mode + gud-mode + vterm-mode)) -(use-package! kind-icon - :after corfu - :when (modulep! +icons) - :custom - (kind-icon-default-face 'corfu-default) :config - (setq kind-icon-use-icons t - svg-lib-icons-dir (expand-file-name "svg-lib" doom-cache-dir) - kind-icon-mapping - '((array "a" :icon "code-brackets" :face font-lock-variable-name-face) - (boolean "b" :icon "circle-half-full" :face font-lock-builtin-face) - (class "c" :icon "view-grid-plus-outline" :face font-lock-type-face) - (color "#" :icon "palette" :face success) - (constant "co" :icon "pause-circle" :face font-lock-constant-face) - (constructor "cn" :icon "table-column-plus-after" :face font-lock-function-name-face) - (enum "e" :icon "format-list-bulleted-square" :face font-lock-builtin-face) - (enum-member "em" :icon "format-list-checks" :face font-lock-builtin-face) - (event "ev" :icon "lightning-bolt-outline" :face font-lock-warning-face) - (field "fd" :icon "application-braces-outline" :face font-lock-variable-name-face) - (file "f" :icon "file" :face font-lock-string-face) - (folder "d" :icon "folder" :face font-lock-doc-face) - (function "f" :icon "lambda" :face font-lock-function-name-face) - (interface "if" :icon "video-input-component" :face font-lock-type-face) - (keyword "kw" :icon "image-filter-center-focus" :face font-lock-keyword-face) - (macro "mc" :icon "sigma" :face font-lock-keyword-face) - (method "m" :icon "lambda" :face font-lock-function-name-face) - (module "{" :icon "view-module" :face font-lock-preprocessor-face}) - (numeric "nu" :icon "numeric" :face font-lock-builtin-face) - (operator "op" :icon "plus-circle-outline" :face font-lock-comment-delimiter-face) - (param "pa" :icon "cog" :face default) - (property "pr" :icon "tune-vertical" :face font-lock-variable-name-face) - (reference "rf" :icon "bookmark-box-multiple" :face font-lock-variable-name-face) - (snippet "S" :icon "text-short" :face font-lock-string-face) - (string "s" :icon "sticker-text-outline" :face font-lock-string-face) - (struct "%" :icon "code-braces" :face font-lock-variable-name-face) - (t "." :icon "crosshairs-question" :face shadow) - (text "tx" :icon "script-text-outline" :face shadow) - (type-parameter "tp" :icon "format-list-bulleted-type" :face font-lock-type-face) - (unit "u" :icon "ruler-square" :face shadow) - (value "v" :icon "numeric-1-box-multiple-outline" :face font-lock-builtin-face) - (variable "va" :icon "adjust" :face font-lock-variable-name-face))) - (add-hook 'doom-load-theme-hook #'kind-icon-reset-cache) - (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter)) + (when (and (modulep! :tools lsp) (not (modulep! :tools lsp +eglot))) + (add-hook 'lsp-mode-hook (defun doom--add-lsp-capf () + (add-to-list 'completion-at-point-functions (cape-capf-buster #'lsp-completion-at-point))) + ;; Below is so that context specific completions in cape come first. + :depth 1)) + (add-to-list 'completion-styles 'partial-completion t) + (add-to-list 'completion-styles 'initials t) + (setq corfu-cycle t + corfu-separator (when +corfu-want-multi-component ?\s) + corfu-preselect t + corfu-count 16 + corfu-max-width 120 + corfu-preview-current 'insert + corfu-quit-at-boundary (if +corfu-want-multi-component 'separator t) + corfu-quit-no-match (if +corfu-want-multi-component 'separator t) + ;; In the case of +tng, TAB should be smart regarding completion; + ;; However, it should otherwise behave like normal, whatever normal was. + tab-always-indent (if (modulep! +tng) 'complete tab-always-indent)) + ;; Only done with :tools vertico active due to orderless. Alternatively, we + ;; could set it up here if it's not there. + (when (and +corfu-want-multi-component (modulep! :completion vertico)) + (cond ((modulep! :tools lsp +eglot) (add-to-list 'completion-category-overrides '(eglot (styles orderless)))) + ((modulep! :tools lsp) (add-hook 'lsp-completion-mode-hook + (defun doom--use-orderless-lsp-capf () + (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults)) + '(orderless))))))) + (map! (:unless (modulep! +tng) + :desc "complete" "C-SPC" #'completion-at-point) + (:map 'corfu-map + (:when +corfu-want-multi-component + :desc "insert separator" "C-SPC" #'corfu-insert-separator) + (:when (modulep! :completion vertico) + :desc "move to minibuffer" "s-" #'corfu-move-to-minibuffer + (:when (modulep! :editor evil) + :desc "move to minibuffer" "s-j" #'corfu-move-to-minibuffer)) + (:when (modulep! +tng) + :desc "next" [tab] #'corfu-next + :desc "previous" [backtab] #'corfu-previous + :desc "next" "TAB" #'corfu-next + :desc "previous" "S-TAB" #'corfu-previous)))) +;; Taken from corfu's README. +;; TODO: extend this to other completion front-ends, mainly helm and ido, since +;; ivy is being considered for removal. +(when (modulep! :completion vertico) + (defun corfu-move-to-minibuffer () + (interactive) + (let ((completion-extra-properties corfu--extra) + completion-cycle-threshold completion-cycling) + (apply #'consult-completion-in-region completion-in-region--data)))) (use-package! cape - :defer t + :after corfu + :commands (cape-dabbrev + cape-file + cape-history + cape-keyword + cape-tex + cape-sgml + cape-rfc1345 + cape-abbrev + cape-ispell + cape-dict + cape-symbol + cape-line) :init - (map! - [remap dabbrev-expand] 'cape-dabbrev) - (add-hook! 'latex-mode-hook (defun +corfu--latex-set-capfs () - (add-to-list 'completion-at-point-functions #'cape-tex))) - (when (modulep! :checkers spell) - (add-to-list 'completion-at-point-functions #'cape-dict) - (add-to-list 'completion-at-point-functions #'cape-ispell)) (add-to-list 'completion-at-point-functions #'cape-file) - (add-to-list 'completion-at-point-functions #'cape-keyword t) - (add-to-list 'completion-at-point-functions #'cape-dabbrev t)) + (when +corfu-ispell-in-comments-and-strings + (defalias 'corfu--ispell-in-comments-and-strings + (cape-super-capf (cape-capf-inside-comment #'cape-ispell) + (cape-capf-inside-string #'cape-ispell))) + (add-hook 'prog-mode-hook + (lambda () + (add-to-list 'completion-at-point-functions #'corfu--ispell-in-comments-and-strings)))) + (dolist (sym +corfu-ispell-completion-modes) + (add-hook (intern (concat (symbol-name sym) "-hook")) + (lambda () + (add-to-list 'completion-at-point-functions #'cape-ispell)))) + (add-hook! '(TeX-mode-hook LaTeX-mode-hook org-mode-hook) + (lambda () + (add-to-list 'completion-at-point-functions #'cape-tex t)) + :depth 2) + (add-hook! '(html-mode-hook +web-react-mode-hook typescript-tsx-mode-hook org-mode-hook markdown-mode-hook) + (lambda () + (add-to-list 'completion-at-point-functions #'cape-sgml t)) + :depth 2) + (add-to-list 'completion-at-point-functions #'cape-dabbrev) + (add-to-list 'completion-at-point-functions #'cape-keyword) + :config + ;; Enhances speed on large projects, for which many buffers may be open. + (setq cape-dabbrev-check-other-buffers nil)) +(use-package! kind-icon + :when (modulep! +icons) + :commands kind-icon-margin-formatter + :init + (add-hook 'corfu-margin-formatters #'kind-icon-margin-formatter) + :config + (setq kind-icon-default-face 'corfu-default + kind-icon-blend-background t + kind-icon-blend-frac 0.2) + (plist-put kind-icon-default-style :height +corfu-icon-height) + (plist-put svg-lib-style-default :height +corfu-icon-height)) +(use-package! corfu-terminal + :when (and (modulep! :os tty) (not (display-graphic-p))) + :hook (corfu-mode . corfu-terminal-mode)) + +(use-package! dabbrev + :config + (setq dabbrev-ignored-buffer-regexps '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'"))) + +(setq read-extended-command-predicate + #'command-completion-default-include-p) + +;; +;;; Extensions (use-package! corfu-history - :after corfu - :hook (corfu-mode . (lambda () - (corfu-history-mode 1) - (savehist-mode 1) - (add-to-list 'savehist-additional-variables 'corfu-history)))) - -(use-package! corfu-quick - :after corfu - :bind (:map corfu-map - ("M-q" . corfu-quick-complete) - ("C-q" . corfu-quick-insert))) - -(use-package! corfu-echo - :after corfu - :hook (corfu-mode . corfu-echo-mode)) - - -(use-package! corfu-info - :after corfu) - - + :after savehist + :hook (corfu-mode . corfu-history-mode) + :config + (add-to-list 'savehist-additional-variables 'corfu-history)) (use-package! corfu-popupinfo - :after corfu - :hook (corfu-mode . corfu-popupinfo-mode)) - -(when (modulep! :editor evil +everywhere) - (setq evil-collection-corfu-key-themes '(default magic-return))) - -(use-package! cape-yasnippet - :after cape) - -;; Override :config default mapping by waiting for after corfu is loaded -(add-hook! 'doom-after-modules-config-hook - (defun +corfu-unbind-yasnippet-h () - "Remove problematic tab bindings in cmds! on :i TAB" - (map! :i [tab] nil - :i "TAB" nil - :i "C-SPC" #'completion-at-point - :i "C-@" #'completion-at-point))) + :hook (corfu-mode . corfu-popupinfo-mode) + :config + (setq corfu-popupinfo-delay '(0.5 . 1.0)) + (map! (:map 'corfu-map + :desc "scroll info up" "C-" #'corfu-popupinfo-scroll-down + :desc "scroll info down" "C-" #'corfu-popupinfo-scroll-up + :desc "scroll info up" "C-S-p" #'corfu-popupinfo-scroll-down + :desc "scroll info down" "C-S-n" #'corfu-popupinfo-scroll-up + :desc "toggle info" "C-h" #'corfu-popupinfo-toggle) + (:map 'corfu-popupinfo-map + :when (modulep! :editor evil) + ;; Reversed because popupinfo assumes opposite of what feels intuitive + ;; with evil. + :desc "scroll info up" "C-S-k" #'corfu-popupinfo-scroll-down + :desc "scroll info down" "C-S-j" #'corfu-popupinfo-scroll-up))) diff --git a/modules/completion/corfu/packages.el b/modules/completion/corfu/packages.el index 878ffb6..746b764 100644 --- a/modules/completion/corfu/packages.el +++ b/modules/completion/corfu/packages.el @@ -1,20 +1,13 @@ -(package! corfu - :recipe (:files (:defaults "extensions/*.el"))) +;; -*- no-byte-compile: t; -*- +;;; completion/corfu/packages.el +(package! corfu :recipe (:files ("*.el" "extensions/*.el"))) +(package! cape) +(package! dabbrev) (when (modulep! +icons) (package! kind-icon)) +(when (modulep! :os tty) + (package! corfu-terminal) + (package! corfu-doc-terminal)) -(when (modulep! +orderless) - (package! orderless)) - -(package! cape) - -(package! popon - :recipe (:type git :repo "https://codeberg.org/akib/emacs-popon")) -(package! corfu-terminal - :recipe (:type git :repo "https://codeberg.org/akib/emacs-corfu-terminal.git")) -(package! corfu-doc-terminal - :recipe (:type git :repo "https://codeberg.org/akib/emacs-corfu-doc-terminal.git")) - -(package! cape-yasnippet - :recipe (:host github :repo "elken/cape-yasnippet")) +;; (package! cape-yasnippet) diff --git a/packages.el b/packages.el index 4c9523b..8e57d34 100644 --- a/packages.el +++ b/packages.el @@ -10,8 +10,7 @@ (unpin! doom-themes) (unpin! lsp-mode) (unpin! sly) -;; (unpin! corfu) -;; (unpin! cape) +(unpin! eglot) ;; (unpin! markdown-mode) ;; (unpin! consult) ;; (unpin! vertico)