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