emacs-devel
[Top][All Lists]
Advanced

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

Re: `completion-in-region'


From: Leo
Subject: Re: `completion-in-region'
Date: Sun, 11 Apr 2010 13:56:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

On 2010-04-09 04:05 +0100, Stefan Monnier wrote:
>> completion-in-region allows a complete customise of its behaviour
>> through completion-in-region-functions.  But minibuffer-message blocks
>> execution for minibuffer-message-timeout seconds (default to 2) unless
>> there's input from user.
>
> Yes, that's a known problem in minibuffer-message, indeed.

Thanks.

> Patches welcome.
>> For example if I define my own:
>> (defun my-completion-in-region (next-fun start end collection predicate)
>>   (when (funcall next-fun start end collection predicate)
>>   BODY))
>
>> BODY will only be executed after 2 seconds that gives a false slow user
>> experience. I can work around this problem by let-binding
>> minibuffer-message-timeout to 0. But I think some improvement can be done
>> here.
>
> 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.

>> 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 haven't used pcomplete before so I will look at it later on.

>> Another solution is to customise completion-in-region through
>> completion-in-region-functions but I need to isolate the interference
>> between functions in completion-in-region-functions.
>
> That doesn't seem like a good approach to add a terminating }
>
>> 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.

For example, with the attached package, one can define an abbrev 'li' to
expand to <li>$.</li> and when expanded it will be '<li>|</li>'. |
indicates where the point is. See `global-snippet-abbrev-mode'. When
this mode is on abbrev expansion will be processed by snippet-region.

I have added nesting snippets, better undo support and removed all known
bugs in the original snippet.el. The package is still compact and clean
with around 500 lines of code.

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.

>         Stefan

Leo

Attachment: snippet.el
Description: snippet.el


reply via email to

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