[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PCM completion word boundaries
From: |
Leo |
Subject: |
Re: PCM completion word boundaries |
Date: |
Mon, 15 Aug 2011 17:56:40 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (Mac OS X 10.6.8) |
On 2011-08-13 23:18 +0800, Stefan Monnier wrote:
>> The reason I am including > is that in Scheme there are tons of
>> functions with -> in it. > is a bit slower to type and would be great if
>> I can avoid it using completion.
>
> That would make sense, yes, but it would require more changes. You may
> want to start by looking at completion-pcm--string->pattern.
So it seems completion-pcm--string->pattern needs to handle three cases:
1. <word> any <delim>
2. <delim> any <delim>
3. <delim> any-delim <word>
Case 3 is missing i.e. it should insert delim chars between delim char
and the following word.
How about something along these lines (diff against emacs-23)?
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 297cecb5..0c08eb33 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1799,7 +1799,7 @@ (defun completion-pcm--pattern-trivial-p (pattern)
(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', `any-delim', `star', `point'."
(if (and point (< point (length string)))
(let ((prefix (substring string 0 point))
(suffix (substring string point)))
@@ -1824,18 +1824,28 @@ (defun completion-pcm--string->pattern (string
&optional point)
;; This is determined by the presence of a submatch-1 which delimits
;; the prefix.
(if (match-end 1) (setq p (match-end 1)))
+ (when (and (/= p p0) (not (zerop p0)))
+ (push 'any-delim pattern))
(push (substring string p0 p) pattern)
+ (when (/= p p0)
+ (push 'any pattern))
(if (eq (aref string p) ?*)
(progn
(push 'star pattern)
(setq p0 (1+ p)))
- (push 'any pattern)
+ (when (= p p0)
+ (push 'any pattern))
+ (push (string (aref string p)) pattern)
(setq p0 p))
+ (incf p0)
(incf p))
+ (when (/= p0 (length string))
+ (push 'any-delim pattern))
+ (push (substring string p0) pattern)
;; An empty string might be erroneously added at the beginning.
;; It should be avoided properly, but it's so easy to remove it here.
- (delete "" (nreverse (cons (substring string p0) pattern))))))
+ (delete "" (nreverse pattern)))))
(defun completion-pcm--pattern->regex (pattern &optional group)
(let ((re
@@ -1846,6 +1856,10 @@ (defun completion-pcm--pattern->regex (pattern &optional
group)
((star any point)
(if (if (consp group) (memq x group) group)
"\\(.*?\\)" ".*?"))
+ (any-delim
+ (concat (and group "\\(")
+ completion-pcm--delim-wild-regex "*"
+ (and group "\\)")))
(t (regexp-quote x))))
pattern
""))))