diff options
| author | tslil <tslil@posteo.de> | 2026-03-25 14:27:05 +0000 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-03-25 14:58:36 +0000 |
| commit | ca6bd0258cc2a332ebd76bff7c05a4f62a9f8876 (patch) | |
| tree | 2cfbc819db188e0a604df5c8a20519eab36203aa /emacs/inits/11-completion.el | |
| parent | 52b2374019f4f46fe53e7e9e0a96c07b0ca134fb (diff) | |
[emacs] try a completing-read-in-region which more closely follows consult--in-region
Diffstat (limited to 'emacs/inits/11-completion.el')
| -rw-r--r-- | emacs/inits/11-completion.el | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/emacs/inits/11-completion.el b/emacs/inits/11-completion.el index 74b6e44..0fc2356 100644 --- a/emacs/inits/11-completion.el +++ b/emacs/inits/11-completion.el @@ -1,4 +1,4 @@ -;; Time-stamp: <2026-03-22 19h03 GMT (11978fd4)> +;; Time-stamp: <2026-03-25 14h58 GMT (242d7eec)> (use-package savehist :ensure t @@ -33,31 +33,32 @@ :init (defun my-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'." + "Prompt for completion of region in the minibuffer if non-unique." + (barf-if-buffer-read-only) (let* ((initial (buffer-substring-no-properties start end)) - (all (completion-all-completions initial collection predicate - (length initial))) (metadata (completion-metadata initial collection predicate)) - (exit-fn (completion-metadata-get metadata 'exit-function)) - (completion (cond - ((atom all) nil) - ((and (consp all) (atom (cdr all))) (car all)) - (t (completing-read - "Completion: " collection predicate t initial))))) - (cond - (completion - (let* ((bounds (completion-boundaries completion collection nil "")) - (prefix-len (car bounds)) - ;; If completion includes a prefix portion, adjust start - (new-start (if (> prefix-len 0) - (max start (- end prefix-len)) - start))) - (completion--replace new-start end completion) - (when exit-fn - (funcall exit-fn completion 'finished))) - t) - (t (message "No completion") nil)))) + (all (completion-all-completions initial collection predicate + (if (<= start (point) end) + (- (point) start) + (length initial))))) + (when-let ((last (last all))) + (setcdr last nil)) + (let ((completion (cond + ((null all) nil) + ((and (consp all) (null (cdr all))) (car all)) + (t (completing-read "Completion: " collection + predicate t initial))))) + (cond + (completion + (completion--replace start end completion) + (let ((exit-fn (completion-metadata-get metadata 'exit-function))) + (when exit-fn + (funcall exit-fn completion + (if (eq (try-completion completion collection predicate) t) + 'finished 'exact)))) + t) + (t (message "No completion") nil))))) + (defun my-icomplete-backspace () "Delete back to previous / in paths, or normal backspace otherwise." @@ -119,9 +120,6 @@ Use as a value for `completion-in-region-function'." (setq completion-styles '(flex basic partial-completion) completion-ignore-case t) - (advice-add 'completion-at-point - :after #'minibuffer-hide-completions) - (setq completion-in-region-function #'my-completing-read-in-region)) ;; ----------------------------------------------------------------------------- |
