From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Toby Cubitt Newsgroups: gmane.emacs.help 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 Message-ID: <461F4455.3080209@dr-qubit.org> References: <461F38B4.3070706@dr-qubit.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1176463802 1430 80.91.229.12 (13 Apr 2007 11:30:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 13 Apr 2007 11:30:02 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Jason Spiro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 13 13:29:55 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HcJyT-000631-Hh for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Apr 2007 13:29:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HcK2j-0001qo-Hx for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Apr 2007 07:34:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HcHZ2-000316-Am for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 04:55:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HcHZ0-0002y5-DM for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 04:55:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HcHZ0-0002xY-5P for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 04:55:26 -0400 Original-Received: from mail.geekisp.com ([216.168.135.169] helo=starfish.geekisp.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HcHUc-0005af-OK for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 04:50:56 -0400 Original-Received: (qmail 19646 invoked by uid 1003); 13 Apr 2007 08:50:28 -0000 Original-Received: from [192.168.2.102] (localhost.geekisp.com [127.0.0.1]) by localhost.geekisp.com (tmda-ofmipd) with ESMTP; Fri, 13 Apr 2007 04:50:23 -0400 (EDT) User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) In-Reply-To: X-Delivery-Agent: TMDA/1.0.3 (Seattle Slew) X-Primary-Address: t.s.cubitt.98@cantab.net X-detected-kernel: OpenBSD 3.0-3.9 X-Mailman-Approved-At: Fri, 13 Apr 2007 07:33:24 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42641 Archived-At: Jason Spiro wrote: > 2007/4/13, Toby Cubitt 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