reddit / emacs

Setting :exclusive 'no by default for all completion-at-point-functions

skyler544 · 2022-12-27 14:04
I've started setting up `corfu` and `cape` and there's something that I don't understand; apparently when you use something like this: `(add-to-list 'completion-at-point-functions 'cape-file)`, it is applied to a "global" version of that variable. So far so good. Most major modes seem to have their own version of that variable however, which means that you would need to add the variable to each major mode you want to use the capf for. Ok, but not really ideal. There's another thing at play here; out of the box, the value of `completion-at-point-functions` in `emacs-lisp-mode` is `(elisp-completion-at-point t)`; the `t` here apparently indicates that if `elisp-completion-at-point` fails, it should fall back to the next function in the global `completion-at-point-functions`. That would be good enough, but `elisp-completion-at-point` is an "exclusive" function, meaning that if it cannot complete (which happens in strings for instance), completion does nothing. This seems like a case where the default behavior is just wrong; is there a way to set `:exclusive 'no` for *all* capfs? Alternatively, I'm misunderstanding all of this entirely. Where can I look for more information on how this works? EDIT: relevant config: ```lisp (use-package emacs :config (setq tab-always-indent 'complete)) (use-package corfu :custom (corfu-auto t) (corfu-cycle t) (corfu-auto-prefix 2) (corfu-auto-delay 0.0) (corfu-echo-documentation 0.25) (corfu-preselect 'prompt) (corfu-preselect-first nil) :general (:keymaps 'corfu-map "RET" nil "C-j" 'corfu-next [tab] 'corfu-next "C-k" 'corfu-previous ;; [tab] 'corfu-insert) [backtab] 'corfu-previous) :hook (eshell . (lambda () (setq-local corfu-auto nil) (corfu-mode))) :init (global-corfu-mode) (corfu-echo-mode)) (use-package cape :init (defun rex/add-capfs () (let ((result)) (dolist (element '(cape-dabbrev cape-file) result) (add-to-list 'completion-at-point-functions element)))) :general (rex-leader "cd" 'cape-dabbrev "cf" 'cape-file) :config (rex/add-capfs)) ```
eleven_cupfuls · 2022-12-27 18:00
I don't believe that `elisp-completion-at-point` is in fact exclusive. That said, if you encounter any capfs that don't do what you want, Cape has helper transformers: https://github.com/minad/cape#capf-transformers to wrap and change their behavior. For example, `cape-capf-nonexclusive`.
skyler544 · 2022-12-27 19:13
You're totally right. I knew that I must have been doing something wrong. I wonder what part of my config was conflicting with it, or if I had just failed to test it correctly. At any rate, it does work now as expected (and I learned a little more about elisp while fighting with this)!