Mercurial > emacs
comparison lisp/minibuffer.el @ 108251:275d802c8570
Extract common suffix for * in partial-completion.
* minibuffer.el (completion--sreverse, completion--common-suffix):
New functions.
(completion-pcm--merge-completions): Extract common suffix when safe.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 05 May 2010 22:59:07 -0400 |
parents | 8bcf1c901e9a |
children | 77714da1307b |
comparison
equal
deleted
inserted
replaced
108250:2fb37c89f2f7 | 108251:275d802c8570 |
---|---|
1981 (completion-pcm--find-all-completions string table pred point) | 1981 (completion-pcm--find-all-completions string table pred point) |
1982 (when all | 1982 (when all |
1983 (nconc (completion-pcm--hilit-commonality pattern all) | 1983 (nconc (completion-pcm--hilit-commonality pattern all) |
1984 (length prefix))))) | 1984 (length prefix))))) |
1985 | 1985 |
1986 (defun completion--sreverse (str) | |
1987 "Like `reverse' but for a string STR rather than a list." | |
1988 (apply 'string (nreverse (mapcar 'identity str)))) | |
1989 | |
1990 (defun completion--common-suffix (strs) | |
1991 "Return the common suffix of the strings STRS." | |
1992 (completion--sreverse | |
1993 (try-completion | |
1994 "" | |
1995 (mapcar 'completion--sreverse comps)))) | |
1996 | |
1986 (defun completion-pcm--merge-completions (strs pattern) | 1997 (defun completion-pcm--merge-completions (strs pattern) |
1987 "Extract the commonality in STRS, with the help of PATTERN." | 1998 "Extract the commonality in STRS, with the help of PATTERN." |
1988 ;; When completing while ignoring case, we want to try and avoid | 1999 ;; When completing while ignoring case, we want to try and avoid |
1989 ;; completing "fo" to "foO" when completing against "FOO" (bug#4219). | 2000 ;; completing "fo" to "foO" when completing against "FOO" (bug#4219). |
1990 ;; So we try and make sure that the string we return is all made up | 2001 ;; So we try and make sure that the string we return is all made up |
2042 ;; any more: it can only match the empty string. | 2053 ;; any more: it can only match the empty string. |
2043 ;; FIXME: in some cases, it may be necessary to turn an | 2054 ;; FIXME: in some cases, it may be necessary to turn an |
2044 ;; `any' into a `star' because the surrounding context has | 2055 ;; `any' into a `star' because the surrounding context has |
2045 ;; changed such that string->pattern wouldn't add an `any' | 2056 ;; changed such that string->pattern wouldn't add an `any' |
2046 ;; here any more. | 2057 ;; here any more. |
2047 (unless unique (push elem res)) | 2058 (unless unique |
2059 (push elem res) | |
2060 (when (memq elem '(star point)) | |
2061 ;; Extract common suffix additionally to common prefix. | |
2062 ;; Only do it for `point' and `star' since for | |
2063 ;; `any' it could lead to a merged completion that | |
2064 ;; doesn't itself match the candidates. | |
2065 (let ((suffix (completion--common-suffix comps))) | |
2066 (assert (stringp suffix)) | |
2067 (unless (equal suffix "") | |
2068 (push suffix res))))) | |
2048 (setq fixed ""))))) | 2069 (setq fixed ""))))) |
2049 ;; We return it in reverse order. | 2070 ;; We return it in reverse order. |
2050 res))))) | 2071 res))))) |
2051 | 2072 |
2052 (defun completion-pcm--pattern->string (pattern) | 2073 (defun completion-pcm--pattern->string (pattern) |