[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: completion-ui.el question: my vimpulse-show-completion-menu fun
From: |
Toby Cubitt |
Subject: |
Re: Fwd: completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu |
Date: |
Fri, 13 Apr 2007 10:50:29 +0200 |
User-agent: |
Thunderbird 1.5.0.10 (Windows/20070221) |
Jason Spiro wrote:
2007/4/13, Toby Cubitt <tsc25@cantab.net> wrote:
>> (defun vimpulse-try-hippie-expand-listed-functions
>> (prefix &optional maxnum)
>> ; (interactive "*MString to expand:
>> ;nMaximum number of expansions, or nil for unlimited: ")
>> (setq expansions nil)
>> (with-temp-buffer
>> (insert-string prefix)
>> (hippie-expand nil)
>> (unless (string-equal (current-message) "No expansion found")
>> (while (and
>> (not (string-equal
>> (current-message)
>> "No further expansions found"))
>> (if maxnum (not (= (length expansions) maxnum))))
>> ;; Hippie-expand was designed to be run interactively. If
>> ;; this-command and last-command are equal, it assumes it's
>> ;; being called as a "repeated use" (additional call without
>> ;; moving the point) and searches for additional expansions
>> ;; with the same prefix. So, make this-command and
>> ;; last-command equal.
>> (setq this-command last-command)
>> (hippie-expand nil)
>> (add-to-list 'expansions (buffer-string))
>> (buffer-string)
>> ))
>> expansions))
> This is almost OK. Completion-UI expects the completion-function to
> return a list of completion strings *without* the prefix. So you need
> to change "expansions" in the last line to:
> (mapcar (lambda (str) (substring str 1)) expansions)
Sorry, this isn't quite correct. It should of course be:
(mapcar (lambda (str) (substring str (length prefix))) expansions)
How exactly does this multiple-word completion work? I don't follow.
For example, type: The quick brown fox jumped over the lazy dog. My
favorite foM-/ SPC M-/ SPC M-/ SPC M-/ SPC M-/ SPC M-/
It should write: The quick brown fox jumped over the lazy dog. My
favorite fox jumped over the lazy dog"
I see. This relies on the fact that the first dabbrev expansion is the
one that is closest in the buffer. If you're completion function (or
rather, hippie-expand's) returned the completions in this order, you
could get the same behaviour using completion-UI. My personal favourite
is to enable 'completion-use-dynamic', so that you don't even need to
type the M-/ equivalent (M-TAB).
Toby