changeset 108378:addaf0e91db3

* 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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 09 May 2010 18:39:36 -0400
parents 7827d5a5c826
children 203aa49071bf af5739d1d4d4
files etc/NEWS lisp/ChangeLog lisp/minibuffer.el
diffstat 3 files changed, 38 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Sun May 09 21:57:55 2010 +0200
+++ b/etc/NEWS	Sun May 09 18:39:36 2010 -0400
@@ -123,8 +123,9 @@
 The reason is that this interferes with cua-mode.
 
 ** partial-completion-mode is now obsolete.
-You can get the same behavior with
-(setq completion-styles '(partial-completion initials)).
+You can get a comparable behavior with:
+(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.
 ** Customize
--- a/lisp/ChangeLog	Sun May 09 21:57:55 2010 +0200
+++ b/lisp/ChangeLog	Sun May 09 18:39:36 2010 -0400
@@ -1,3 +1,14 @@
+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>
 
 	* net/tramp-compat.el (byte-compile-not-obsolete-vars): Define if
--- a/lisp/minibuffer.el	Sun May 09 21:57:55 2010 +0200
+++ b/lisp/minibuffer.el	Sun May 09 18:39:36 2010 -0400
@@ -1769,6 +1769,14 @@
   :group 'minibuffer
   :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)
   (and (stringp (car pattern))
        ;; It can be followed by `point' and "" and still be trivial.
@@ -1781,7 +1789,7 @@
 (defun completion-pcm--string->pattern (string &optional point)
   "Split STRING into a pattern.
 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)))
       (let ((prefix (substring string 0 point))
             (suffix (substring string point)))
@@ -1794,11 +1802,12 @@
 
       (while (and (setq p (string-match completion-pcm--delim-wild-regex
                                         string p))
-                  ;; If the char was added by minibuffer-complete-word, then
-                  ;; don't treat it as a delimiter, otherwise "M-x SPC"
-                  ;; ends up inserting a "-" rather than listing
-                  ;; all completions.
-                  (not (get-text-property p 'completion-try-word string)))
+                  (or completion-pcm-complete-word-inserts-delimiters
+                      ;; If the char was added by minibuffer-complete-word,
+                      ;; then don't treat it as a delimiter, otherwise
+                      ;; "M-x SPC" ends up inserting a "-" rather than listing
+                      ;; all completions.
+                      (not (get-text-property p 'completion-try-word string))))
         ;; Usually, completion-pcm--delim-wild-regex matches a delimiter,
         ;; meaning that something can be added *before* it, but it can also
         ;; match a prefix and postfix, in which case something can be added
@@ -1824,11 +1833,10 @@
          (concat "\\`"
                  (mapconcat
                   (lambda (x)
-                    (case x
-                      ((star any point)
-                       (if (if (consp group) (memq x group) group)
-                           "\\(.*?\\)" ".*?"))
-                      (t (regexp-quote x))))
+                    (cond
+                     ((stringp x) (regexp-quote x))
+                     ((if (consp group) (memq x group) group)
+                      "\\(.*?\\)" ".*?")))
                   pattern
                   ""))))
     ;; Avoid pathological backtracking.
@@ -2057,9 +2065,9 @@
                 ;; here any more.
                 (unless unique
                   (push elem res)
-                  (when (memq elem '(star point))
+                  (when (memq elem '(star point 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
                     ;; doesn't itself match the candidates.
                     (let ((suffix (completion--common-suffix comps)))
@@ -2074,8 +2082,7 @@
   (mapconcat (lambda (x) (cond
                      ((stringp x) x)
                      ((eq x 'star) "*")
-                     ((eq x 'any) "")
-                     ((eq x 'point) "")))
+                     (t "")))           ;any, point, prefix.
              pattern
              ""))
 
@@ -2117,6 +2124,7 @@
              (pointpat (or (memq 'point mergedpat)
                            (memq 'any   mergedpat)
                            (memq 'star  mergedpat)
+                           ;; Not `prefix'.
 			   mergedpat))
              ;; New pos from the start.
              (newpos (length (completion-pcm--pattern->string pointpat)))
@@ -2147,7 +2155,7 @@
                          beforepoint afterpoint bounds))
          (pattern (if (not (stringp (car basic-pattern)))
                       basic-pattern
-                    (cons 'any basic-pattern)))
+                    (cons 'prefix basic-pattern)))
          (all (completion-pcm--all-completions prefix pattern table pred)))
     (list all pattern prefix suffix (car bounds))))