emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs completion matches selection UI


From: João Távora
Subject: Re: Emacs completion matches selection UI
Date: Sat, 28 Dec 2013 15:59:19 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

John Yates <address@hidden> writes:

> Try a google search for "yasnippet autocomplete". Many folk seem to
> want to use them together. Not sure why the attempt so often leads to
> a plea for help.

Many of the search results will land you in yasnippet's issue tracker,
where I handled many such issues and admittedly never provided a
bullet-proof solution.

But I would say that 70% of the cases stem from a misunderstanding about
yasnippet. It is a abbrev expansion mechanism and not a completion
mechanism.

The fact that the key that attempts expansion is bound to TAB is a
detail. The fact that it sometimes prompts you when many expansions are
possible from a single abbreviation, and that that minibuffer prompting
*is* subject to usual emacs completion routines is also a different
issue, IMO.

So, those 70% are frequently caused by the fact that auto-complete
itself comes with a "yasnippet source", i.e. a plugin to auto-complete
that gathers possible snippets to expand at point and offers these
expansions as completion "targets". In this (completely different) use
case, auto-complete "drives" yasnippet (and yasnippet's TAB binding
should be disabled by the user). This use case is frequently broken by
reasons completely unrelated to this thread (i.e. API brea).

Anyway, the other 30% are probably legitimate cases where the user that
activated both yas-minor-mode and auto-complete-mode in a buffer
probably wants something like the following to happen:

   1. Press TAB

   2. If theres an active snippet key preceding point, expand it and
      leave

   3. Else attempt autocompletion at point, bring up a menu, whatever it
      does

   4. Else do whatever TAB is bound to

I wrote "probably" because I don't think I ever got a precise
description that clarified the desired interaction. That is, maybe some
users want 2 and 3 reversed.

Now, I'm not familiar with auto-complete to say if 3. can ever "fail"
and fall through to 4. To do that, it would probably need a fallback
mechanism similar to yasnippet's.

IIUC, it is this "attempt-command-but-maybe-fallback" mechanism that I
believe could be considered for inclusion in emacs, provided it's
designed sensibly, of course.

> Perhaps the wrinkle is yasnippet's completion model. Based on context
> preceding point yasnippet decides either that a match exists (leading
> to template expansion and return) or that no match exists causing
> responsibility to be passed to a fallback completion handler.

This is very close to the truth, but instead of "fallback completion
handler" yasnippet interactively calls whatever TAB was bound to before,
which normally is some indentation command, but can also be org-cycle as
in org-mode.

Not sure what it does if you enable yas-minor-mode in a completion-aware
minibuffer, for instance.

C-h k TAB in any buffer where yas-minor-mode is enabled should always
give you that info, btw. (I say "should" because it appears to currently
be buggy and always report "forward-button" as the fallback command).

Finally, note that autopair.el does something similar, but always runs
the fallback binding and installs its bindings in
`emulation-mode-map-alist' something that I found that is usually "on
top of everything else".

Yasnippet installs its TAB binding in a conventional minor mode map,
where IIRC it will conflict with other TAB bindings in other minor mode
maps. This used to be a common source of problems, but can be averted
with hacks like the ones described in yasnippet's faq (though these
might be out-of-date).

Hope I have helped and not unhelped with this input,
João



reply via email to

[Prev in Thread] Current Thread [Next in Thread]