From 99cded03775f74a4fd1ea34479278b8180002a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Thu, 12 Feb 2026 22:33:35 +0000 Subject: [PATCH] ; Cargo-cult old flex try-completion behavior * lisp/minibuffer.el (completion-flex-try-completion): Tweak. --- lisp/minibuffer.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6b4552136e0..87a69910ded 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4979,15 +4979,25 @@ usual. Returns (ALL PAT PREFIX SUFFIX)." "Try to flex-complete STRING in TABLE given PRED and POINT." (when (and completion-flex-nospace (string-search " " string)) (cl-return-from completion-flex-try-completion)) - (pcase-let ((`(,all ,_pattern-str ,_prefix ,_suffix) - (completion--flex-all-completions-1 string table pred point)) - (probe)) - (cond ((null all) nil) - ((and (equal string (car all)) (null (cdr all))) t) - ((and (setq probe (try-completion "" all pred)) - (cl-plusp (length probe))) - (cons probe (length probe))) - ((cons string point))))) + (pcase-let* ((`(,all ,pattern-str ,prefix ,suffix) + (completion--flex-all-completions-1 string table pred point)) + (pcm-pattern + (cons + 'prefix + (cl-loop with point-idx = (1- (- point (length prefix))) + for x across pattern-str for i from 0 + collect (char-to-string x) + collect (if (eq i point-idx) + 'point 'any))))) + (if minibuffer-completing-file-name + (setq all (completion-pcm--filename-try-filter all))) + ;; Try some "merging", meaning add as much as possible to the + ;; user's pattern without losing any possible matches in `all'. + ;; i.e this will augment "cfi" to "config" if all candidates + ;; contain the substring "config". FIXME: this still won't + ;; augment "foo" to "froo" when matching "frodo" and + ;; "farfromsober". + (completion-pcm--merge-try pcm-pattern all prefix suffix))) (cl-defun completion-flex-all-completions (string table pred point) "Get flex-completions of STRING in TABLE, given PRED and POINT."