reddit / emacs

completion-at-point using completing-read (icomplete)

O10120240501 · 2022-12-13 20:40
``` (defun completing-read-in-region (start end collection &optional predicate) "Prompt for completion of region in the minibuffer if non-unique. Use as a value for `completion-in-region-function'." (let* ((initial (buffer-substring-no-properties start end)) (all (completion-all-completions initial collection predicate (length initial))) (completion (cond ((atom all) nil) ((and (consp all) (atom (cdr all))) (car all)) (t (completing-read "Completion: " collection predicate t initial))))) (cond (completion (completion--replace start end completion) t) (t (message "No completion") nil)))) (setq completion-in-region-function #'completing-read-in-region) ``` I have based this function at `consult-completion-in-region` but for some reason my version fails for some cases, like when you enter exact match into the minibuffer (it doesn't happen always which is especially annoying) or sometimes it removes wrong characters (eg it cuts the newline). I tried different variants with `delete-region` and `insert` but result was the same. Any idea how to fix this? EDIT: Also for some reason it's completely broken in common lisp mode and doesn't allow to choose anything (enter doesn't do anything, it just completes like tab but doesn't quit, C-j works the same) For reference I use eglot to provide completion sources (and sly for cl)
sebhoagie · 2022-12-15 04:12
Interesting! I was trying icomplete in the same way a few days ago, but using what seems to be built in functionality, see https://reddit.com/r/emacs/comments/z9sm91/_/iyxyrgb/?context=1 Hope that comment helps you in some way. Will test your function when I get a chance.
sebhoagie · 2022-12-22 17:25
UPDATE: I just tested this (very lightly) and it seems to work OK with elisp completion, but not with LSP & Golang, there's some error when the minibuffer pops.