emacs-devel
[Top][All Lists]
Advanced

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

Re: `completion-in-region'


From: Stefan Monnier
Subject: Re: `completion-in-region'
Date: Sun, 11 Apr 2010 11:32:32 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>> completion-in-region-functions is indeed meant for situations where you
>> want to either completely replace the completion UI with some other one
>> (à la completion-ui.el), or where you want to let-bind some completion
>> variables.  But indeed, it hasn't been used much yet, so maybe a better
>> interface would make sense.
> BTW, some modern text editors (such as textmate) have started offering
> fuzzy completion as default.

Interesting.  Do you have any details of what is meant by "fuzzy"?
[ BTW, I expect fuzzy matching to be a completion-style rather than
  a completion-ui.  The IO part is the part that chooses which keys do
  what, where/how to display the list of completions, etc... whereas
  the completion-style controls what is the possible list of
  completions given a completion-table and a user input.  ]

>>> The above comments are based on my experience to write two
>>> completions: one for TeX: I want the completion to automatically
>>> include a 'close' string (i.e.  {} for LaTeX macros etc.), I can write
>>> a function for completion-at-point-functions which returns '(beg end
>>> completion-function) and do the adding in completion-function but it
>>> is difficult to control the position of point so that it locates
>>> between {}.
>> 
>> Could you expand on what problems you've encountered when trying to add
>> it in completion-function?  You may want to check how I used
>> completion-table-with-terminator in pcomplete.el for that same kind
>> of situation.

> I was trying to return a list of (beg end collections) and let
> completion-in-region do the job. But in the end I did something like
> this:

> (defun TeX-completion-at-point ()
>   (let ((list TeX-complete-list) entry)
>     (while list
>       (setq entry (car list)
>           list (cdr list))
>       (if (TeX-looking-at-backward (car entry) 250)
>         (setq list nil)))
>     ;; ignore the useless ispell completion
>     (when (numberp (nth 1 entry))
>       (when (looking-at "\\w")
>         (forward-word 1))
>       (TeX-complete-symbol)
>       ;; try leaving point in between parenthesis
>       (when (looking-back "\\s)" (line-beginning-position))
>         (skip-syntax-backward ")"))
>       ;; this is discouraged
>       ;; return a function that does nothing
>       'ignore)))

I don't see where this adds a terminating }.

> I haven't used pcomplete before so I will look at it later on.

My suggestion doesn't have anything to do with pcomplete.el except for
the fact that it's one place where I've used c-t-with-terminator.
I.e. I'm suggesting you use completion-table-with-terminator and the
pcomplete.el is just telling you where you can see it in use.
But "grep completion-table-with-terminator lisp/**/*.el" will show you
a few other uses (in meta-mode and make-mode, for example).

>>> Another for snippet (similar to abbrev), complete the snippet (abbrev) and
>>> then expand if completion succeeds.
>> Hmm... I do not understand the above two lines.  They seem to lack
>> context or something.

> I am re-designing snippet.el
> (http://www.emacswiki.org/emacs/SnippetMode) to tightly integrate with
> abbrev. Emacs has abbreviation feature for a very long time but it
> hasn't advanced much. 'snippet' is a substantial step forward. It was
> original introduced in textmate and becomes so popular that almost all
> text editors have it now.

There have been many Emacs packages to do such things.  Emacs itself
comes with skeleton.el, tempo.el, expand.el, and probably some more.
I'm not really interested in adding yet another such package to Emacs.
OTOH I'd be interested in consolidating them so as to try and reduce the
urge of people to reinvent them yet again.

> The completion I was talking about was for function
> `snippet-completion-at-point' which completes abbrevs and do the
> expansion if the completed string is an abbrev name; the abbrev
> expansion is then processed by snippet-region.

I see.  So what problems have you encountered in this context?
[ BTW, you may want to generalize it to abbrev-complete-at-point since
  it's likely to be easy to generalize to any abbreviation table.
  We could install this in abbrev.el.  ]


        Stefan




reply via email to

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