unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Question about the initials completion-style
@ 2010-07-15 16:00 Tassilo Horn
  2010-07-22 14:38 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Tassilo Horn @ 2010-07-15 16:00 UTC (permalink / raw)
  To: emacs-devel

Hi all,

I really like the idea of the `initials' completion style, but that
doesn't work for me.  When I do `M-x ss<TAB>' I want to call
`server-start' (or any other command with exactly 2 words separated by
some non-word-char).  I had an own mode for executing commands by giving
only initials, but I'd like to drop that for the new `completion-styles'
in recent emacsen.

Using (setq completion-styles '(basic initials partial-completion)), `M-x
ss<TAB>' will complete to "s-s", but the completion list also contains
entries with more subwords, like secrets-show-secrets.  Those are added
by the partial-completion style.

If I use (setq completion-styles '(basic initials)), `M-x ss<TAB>' will
complete to "s-s", but then no matches are found anymore, cause this
expansion requires partial-completion.

So it would be good, if there was a variant of partial-completion that
didn't consider symbols with more hyphens than are actually there.  Or
is there a way to do that right now (using a recent bzr checkout)?

Bye,
Tassilo



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

* Re: Question about the initials completion-style
  2010-07-15 16:00 Question about the initials completion-style Tassilo Horn
@ 2010-07-22 14:38 ` Stefan Monnier
  2010-07-22 15:10   ` Tassilo Horn
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2010-07-22 14:38 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

> I really like the idea of the `initials' completion style, but that
> doesn't work for me.  When I do `M-x ss<TAB>' I want to call
> `server-start' (or any other command with exactly 2 words separated by
> some non-word-char).  I had an own mode for executing commands by giving
> only initials, but I'd like to drop that for the new `completion-styles'
> in recent emacsen.
[...]
> So it would be good, if there was a variant of partial-completion that
> didn't consider symbols with more hyphens than are actually there.  Or
> is there a way to do that right now (using a recent bzr checkout)?

There is no such feature, no.  Feel free to code it up, but be warned:
there's more than one s-s match even in "emacs -Q" so you'll have to
type something more.  So you may end up discovering that you still have
to type just as much.


        Stefan



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

* Re: Question about the initials completion-style
  2010-07-22 14:38 ` Stefan Monnier
@ 2010-07-22 15:10   ` Tassilo Horn
  2010-07-22 17:27     ` Tassilo Horn
  2010-07-22 22:44     ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Tassilo Horn @ 2010-07-22 15:10 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Thursday 22 July 2010 16:38:47 Stefan Monnier wrote:

> > I really like the idea of the `initials' completion style, but that
> > doesn't work for me.  When I do `M-x ss<TAB>' I want to call
> > `server-start' (or any other command with exactly 2 words separated
> > by some non-word-char).  I had an own mode for executing commands by
> > giving only initials, but I'd like to drop that for the new
> > `completion-styles' in recent emacsen.
> [...]
> > So it would be good, if there was a variant of partial-completion
> > that didn't consider symbols with more hyphens than are actually
> > there.  Or is there a way to do that right now (using a recent bzr
> > checkout)?
> 
> There is no such feature, no.  Feel free to code it up,

Wow, that's some pretty easy, straight-forward code. ;-)

It looks to me that I could copy the `completion-pcm-all-completions'
function and add a FILTER for deleting the entries consisting of too
many words to the call to `completion-pcm--find-all-completions'.  I'll
try that as soon as I find some time...

> but be warned: there's more than one s-s match even in "emacs -Q" so
> you'll have to type something more.  So you may end up discovering
> that you still have to type just as much.

Maybe.

A related question: Is the canonical way to use different completion
styles depending on what to complete advising the relevant functions?
Currently, I use that:

--8<---------------cut here---------------start------------->8---
(setq completion-styles '(basic initials partial-completion)
      read-buffer-completion-ignore-case t)

(defadvice read-buffer (around th-read-buffer-set-substring-completion activate)
  "Enable substring completion when reading buffers."
  (let ((completion-styles '(basic substring)))
    ad-do-it))
--8<---------------cut here---------------end--------------->8---

Works good and feels like IDO, especially in combination with icomplete.
So thanks a lot for all your great work on the completion facilities. :-)

Bye,
Tassilo



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

* Re: Question about the initials completion-style
  2010-07-22 15:10   ` Tassilo Horn
@ 2010-07-22 17:27     ` Tassilo Horn
  2010-07-22 22:44     ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2010-07-22 17:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Thursday 22 July 2010 17:10:00 Tassilo Horn wrote:

Hi Stefan,

> > There is no such feature, no.  Feel free to code it up,
> 
> It looks to me that I could copy the `completion-pcm-all-completions'
> function and add a FILTER for deleting the entries consisting of too
> many words to the call to `completion-pcm--find-all-completions'.  I'll
> try that as soon as I find some time...

Ok, here's a proof-of-concept which seems to do what I want.  It lacks
some good name, relies on dynamic scoping, and is probably not the best
or even a good way to implement that feature.

--8<---------------cut here---------------start------------->8---
(defun completion-pcm--no-lengthening-filter (comps)
  (when comps
    (delq nil
          (mapcar
           (lambda (str)
             (if (= (count ?- str) cnt) str nil))
           comps))))

(defun completion-pcm-all-completions-no-lengthening (string table pred point)
  (destructuring-bind (pattern all &optional prefix suffix)
      (let ((cnt (count ?- string)))
        (completion-pcm--find-all-completions
         string table pred point
         'completion-pcm--no-lengthening-filter))
    (when all
      (nconc (completion-pcm--hilit-commonality pattern all)
             (length prefix)))))

(add-to-list 'completion-styles-alist
             '(partial-completion-no-lengthening
               completion-pcm-try-completion
               completion-pcm-all-completions-no-lengthening
               "Like the partial-completion style, but don't
complete x-y to things with more word separators (like
xoo-yee-foo)."))

;; Use it!!!
(setq completion-styles '(basic initials partial-completion-no-lengthening))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



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

* Re: Question about the initials completion-style
  2010-07-22 15:10   ` Tassilo Horn
  2010-07-22 17:27     ` Tassilo Horn
@ 2010-07-22 22:44     ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2010-07-22 22:44 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

> It looks to me that I could copy the `completion-pcm-all-completions'
> function and add a FILTER for deleting the entries consisting of too
> many words to the call to `completion-pcm--find-all-completions'.  I'll
> try that as soon as I find some time...

IIRC there's some dependency between partial-completion and initials, so
doing it right may require more work.

> A related question: Is the canonical way to use different completion
> styles depending on what to complete advising the relevant functions?

There is no such canonical way to do it, and it's one of the facilities
that we need to add, indeed.  The read-buffer case is once such glaring
example (where we should change the default to (basic substring),
actually).
If someone has an idea for what such a canonical way should look like
(and no, using `advice' is not the answer: it's only "the canonical way
to do it for lack of anything better"), I'm all ears.


        Stefan



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

end of thread, other threads:[~2010-07-22 22:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-15 16:00 Question about the initials completion-style Tassilo Horn
2010-07-22 14:38 ` Stefan Monnier
2010-07-22 15:10   ` Tassilo Horn
2010-07-22 17:27     ` Tassilo Horn
2010-07-22 22:44     ` Stefan Monnier

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