unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PCM completion word boundaries
@ 2011-08-06 10:40 Leo
  2011-08-13 15:18 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Leo @ 2011-08-06 10:40 UTC (permalink / raw)
  To: emacs-devel

Hello,

1. customise (using the custom interface) completion-pcm-word-delimiters
   to include > as word boundary,

2. (defun string->symbol ())

3. In an emacs-lisp-mode buffer, type string-symbol M-TAB

It says no match. I wonder if it should match in this case. For example
minibuffer-bitset M-TAB completes to minibuffer--bitset.

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.

Thanks.

Leo




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PCM completion word boundaries
  2011-08-06 10:40 PCM completion word boundaries Leo
@ 2011-08-13 15:18 ` Stefan Monnier
  2011-08-15  9:56   ` Leo
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2011-08-13 15:18 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

> 2. (defun string->symbol ())
> 3. In an emacs-lisp-mode buffer, type string-symbol M-TAB

Right, because string->symbol does not match the "string*-symbol" glob.

> It says no match. I wonder if it should match in this case. For example
> minibuffer-bitset M-TAB completes to minibuffer--bitset.

But here "minibuffer--bitset" does match the "minibuffer*-bitset" glob.
I.e. the "-" you typed matches the second "-", not the first.

I.e. for string->symbol, you'd need to type "str>sym", at which point it
would correctly expand.

> 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.


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PCM completion word boundaries
  2011-08-13 15:18 ` Stefan Monnier
@ 2011-08-15  9:56   ` Leo
  0 siblings, 0 replies; 3+ messages in thread
From: Leo @ 2011-08-15  9:56 UTC (permalink / raw)
  To: emacs-devel

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
                   ""))))




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-15  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-06 10:40 PCM completion word boundaries Leo
2011-08-13 15:18 ` Stefan Monnier
2011-08-15  9:56   ` Leo

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).