Commit 79ccd68f authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):

New custom variable.
(completion-pcm--string->pattern): Use it.
(completion-pcm--pattern->regex, completion-pcm--pattern->string):
Make it handle any symbol as `any'.
(completion-pcm--merge-completions): Extract common suffix for the new
`prefix' symbol as well.
(completion-substring--all-completions): Use the new `prefix' symbol.
parent 0d5852cf
...@@ -123,8 +123,9 @@ regardless of the value of `delete-by-moving-to-trash'. ...@@ -123,8 +123,9 @@ regardless of the value of `delete-by-moving-to-trash'.
The reason is that this interferes with cua-mode. The reason is that this interferes with cua-mode.
** partial-completion-mode is now obsolete. ** partial-completion-mode is now obsolete.
You can get the same behavior with You can get a comparable behavior with:
(setq completion-styles '(partial-completion initials)). (setq completion-styles '(partial-completion initials))
(setq completion-pcm-complete-word-inserts-delimiters t)
** mpc.el: Can use pseudo tags of the form tag1|tag2 as a union of two tags. ** mpc.el: Can use pseudo tags of the form tag1|tag2 as a union of two tags.
** Customize ** Customize
......
2010-05-09 Stefan Monnier <monnier@iro.umontreal.ca>
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
New custom variable.
(completion-pcm--string->pattern): Use it.
(completion-pcm--pattern->regex, completion-pcm--pattern->string):
Make it handle any symbol as `any'.
(completion-pcm--merge-completions): Extract common suffix for the new
`prefix' symbol as well.
(completion-substring--all-completions): Use the new `prefix' symbol.
2010-05-09 Michael Albinus <michael.albinus@gmx.de> 2010-05-09 Michael Albinus <michael.albinus@gmx.de>
* net/tramp-compat.el (byte-compile-not-obsolete-vars): Define if * net/tramp-compat.el (byte-compile-not-obsolete-vars): Define if
......
...@@ -1769,6 +1769,14 @@ expression (not containing character ranges like `a-z')." ...@@ -1769,6 +1769,14 @@ expression (not containing character ranges like `a-z')."
:group 'minibuffer :group 'minibuffer
:type 'string) :type 'string)
(defcustom completion-pcm-complete-word-inserts-delimiters nil
"Treat the SPC or - inserted by `minibuffer-complete-word' as delimiters.
Those chars are treated as delimiters iff this variable is non-nil.
I.e. if non-nil, M-x SPC will just insert a \"-\" in the minibuffer, whereas
if nil, it will list all possible commands in *Completions* because none of
the commands start with a \"-\" or a SPC."
:type 'boolean)
(defun completion-pcm--pattern-trivial-p (pattern) (defun completion-pcm--pattern-trivial-p (pattern)
(and (stringp (car pattern)) (and (stringp (car pattern))
;; It can be followed by `point' and "" and still be trivial. ;; It can be followed by `point' and "" and still be trivial.
...@@ -1781,7 +1789,7 @@ expression (not containing character ranges like `a-z')." ...@@ -1781,7 +1789,7 @@ expression (not containing character ranges like `a-z')."
(defun completion-pcm--string->pattern (string &optional point) (defun completion-pcm--string->pattern (string &optional point)
"Split STRING into a pattern. "Split STRING into a pattern.
A pattern is a list where each element is either a string A pattern is a list where each element is either a string
or a symbol chosen among `any', `star', `point'." or a symbol chosen among `any', `star', `point', `prefix'."
(if (and point (< point (length string))) (if (and point (< point (length string)))
(let ((prefix (substring string 0 point)) (let ((prefix (substring string 0 point))
(suffix (substring string point))) (suffix (substring string point)))
...@@ -1794,11 +1802,12 @@ or a symbol chosen among `any', `star', `point'." ...@@ -1794,11 +1802,12 @@ or a symbol chosen among `any', `star', `point'."
(while (and (setq p (string-match completion-pcm--delim-wild-regex (while (and (setq p (string-match completion-pcm--delim-wild-regex
string p)) string p))
;; If the char was added by minibuffer-complete-word, then (or completion-pcm-complete-word-inserts-delimiters
;; don't treat it as a delimiter, otherwise "M-x SPC" ;; If the char was added by minibuffer-complete-word,
;; ends up inserting a "-" rather than listing ;; then don't treat it as a delimiter, otherwise
;; all completions. ;; "M-x SPC" ends up inserting a "-" rather than listing
(not (get-text-property p 'completion-try-word string))) ;; all completions.
(not (get-text-property p 'completion-try-word string))))
;; Usually, completion-pcm--delim-wild-regex matches a delimiter, ;; Usually, completion-pcm--delim-wild-regex matches a delimiter,
;; meaning that something can be added *before* it, but it can also ;; meaning that something can be added *before* it, but it can also
;; match a prefix and postfix, in which case something can be added ;; match a prefix and postfix, in which case something can be added
...@@ -1824,11 +1833,10 @@ or a symbol chosen among `any', `star', `point'." ...@@ -1824,11 +1833,10 @@ or a symbol chosen among `any', `star', `point'."
(concat "\\`" (concat "\\`"
(mapconcat (mapconcat
(lambda (x) (lambda (x)
(case x (cond
((star any point) ((stringp x) (regexp-quote x))
(if (if (consp group) (memq x group) group) ((if (consp group) (memq x group) group)
"\\(.*?\\)" ".*?")) "\\(.*?\\)" ".*?")))
(t (regexp-quote x))))
pattern pattern
"")))) ""))))
;; Avoid pathological backtracking. ;; Avoid pathological backtracking.
...@@ -2057,9 +2065,9 @@ filter out additional entries (because TABLE migth not obey PRED)." ...@@ -2057,9 +2065,9 @@ filter out additional entries (because TABLE migth not obey PRED)."
;; here any more. ;; here any more.
(unless unique (unless unique
(push elem res) (push elem res)
(when (memq elem '(star point)) (when (memq elem '(star point prefix))
;; Extract common suffix additionally to common prefix. ;; Extract common suffix additionally to common prefix.
;; Only do it for `point' and `star' since for ;; Only do it for `point', `star', and `prefix' since for
;; `any' it could lead to a merged completion that ;; `any' it could lead to a merged completion that
;; doesn't itself match the candidates. ;; doesn't itself match the candidates.
(let ((suffix (completion--common-suffix comps))) (let ((suffix (completion--common-suffix comps)))
...@@ -2074,8 +2082,7 @@ filter out additional entries (because TABLE migth not obey PRED)." ...@@ -2074,8 +2082,7 @@ filter out additional entries (because TABLE migth not obey PRED)."
(mapconcat (lambda (x) (cond (mapconcat (lambda (x) (cond
((stringp x) x) ((stringp x) x)
((eq x 'star) "*") ((eq x 'star) "*")
((eq x 'any) "") (t ""))) ;any, point, prefix.
((eq x 'point) "")))
pattern pattern
"")) ""))
...@@ -2117,6 +2124,7 @@ filter out additional entries (because TABLE migth not obey PRED)." ...@@ -2117,6 +2124,7 @@ filter out additional entries (because TABLE migth not obey PRED)."
(pointpat (or (memq 'point mergedpat) (pointpat (or (memq 'point mergedpat)
(memq 'any mergedpat) (memq 'any mergedpat)
(memq 'star mergedpat) (memq 'star mergedpat)
;; Not `prefix'.
mergedpat)) mergedpat))
;; New pos from the start. ;; New pos from the start.
(newpos (length (completion-pcm--pattern->string pointpat))) (newpos (length (completion-pcm--pattern->string pointpat)))
...@@ -2147,7 +2155,7 @@ filter out additional entries (because TABLE migth not obey PRED)." ...@@ -2147,7 +2155,7 @@ filter out additional entries (because TABLE migth not obey PRED)."
beforepoint afterpoint bounds)) beforepoint afterpoint bounds))
(pattern (if (not (stringp (car basic-pattern))) (pattern (if (not (stringp (car basic-pattern)))
basic-pattern basic-pattern
(cons 'any basic-pattern))) (cons 'prefix basic-pattern)))
(all (completion-pcm--all-completions prefix pattern table pred))) (all (completion-pcm--all-completions prefix pattern table pred)))
(list all pattern prefix suffix (car bounds)))) (list all pattern prefix suffix (car bounds))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment