* Re: completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu
@ 2007-04-12 23:16 Jason Spiro
[not found] ` <c241693f0704121619i14d16188j2cdb3e5c6baf6860@mail.gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Jason Spiro @ 2007-04-12 23:16 UTC (permalink / raw)
To: Toby Cubitt, help-gnu-emacs; +Cc: Alessandro Piras, Brad Beveridge
Hi list, hello Toby,
As you may know, I am working on vimpulse[1] which extends viper-mode
to emulate the most useful Vim keys in Emacs. I am hoping to add C-n
and C-p completion to vimpulse, and I am wondering how to do so.
I am hoping to use hippie-expand because it can complete:
- words,
- filenames, and
- entire buffer lines
among other things.[2] Dabbrev seems to basically only complete
words. I am trying to emulate Vim's completion behavior, and Vim can
complete all those things and more.[3]
> As an Elisp coder, you're not supposed to invoke *any* completion
> interface explicitly, as you've tried to do. Deciding which combination
> of user-interfaces to use is the user's business, not the package
> writer's. Maybe some users want to use menu completion, but others
> prefer to see a list in the echo area, whilst still others just want a
> tooltip to popup after a delay, etc. etc. Completion-UI offloads those
> choices onto the user, which is where they should be.
OK. I will tell vimpulse users they should set certain Completion-UI
settings themselves to get something closer to Vim completion. But
meanwhile, I still have a question about the code I am writing myself
for testing purposes.
;; Begin code {{{
(require 'completion-ui)
;; Note: This code has an additional bug in addition to the problem I
;; am asking about in this mailing list message:
;; When called with a MAXNUM of nil, this func sometimes fails. (Seems
;; to work the first time, then fail all times after, in such cases.
;; To fix, call with a normal MAXNUM.)
(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))
(defun jason-problem-demo ()
(interactive)
(setq-default completion-function
'vimpulse-try-hippie-expand-listed-functions)
(setq completion-function 'vimpulse-try-hippie-expand-listed-functions)
;; is this always necessary? Am I even ever supposed to call it?
(completion-setup-overlay 'prefix)
(completion-show-menu))
;; }}} End code
Whenever I start typing a word then run
M-x jason-problem-demo I get an empty menu. Why?
Am I using
completion-show-menu wrong? It errors on me if I don't call
completion-setup-overlay first, so I call it first. Should I?
Cheers,
Jason[5]
[1] http://www.emacswiki.org/cgi-bin/wiki/vimpulse.el
[2] Unfortunately hippie-expand can't complete multiple-word sequences
like dabbrev can when you press M-/ SPC M-/ SPC M-/. Vim can do it:
just press CTRL-X CTRL-P repeatedly. But I hope I'll eventually fix
that.
Then again, maybe I'll never have time to make that change to
hippie-expand. So maybe I should have Completion-UI call
dabbrev-expand instead.
[3] e.g. CTRL-X CTRL-T for thesaurus completion, or many other[4] things.
[4] http://ianua.initd.org/vimit/vim63/html/insert.html#ins-completion
[5] P.S. You may want to mention in the completion-ui documentation at
the top of the file that
http://www.emacswiki.org/cgi-bin/wiki/CompletionUI#toc2 has examples
of how to use completion-ui with dabbrev and etags. If I knew that
info, it would have saved me time. :-)
--
Jason Spiro: computer consulting with a smile.
I provide software development and training services to clients worldwide.
Contact me for a FREE consultation. Satisfaction guaranteed.
+1 (416) 781-5938 / Email: info@jspiro.com / MSN: jasonspiro@hotmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu
@ 2007-03-13 8:50 Jason Spiro
2007-03-14 4:36 ` Toby Cubitt
0 siblings, 1 reply; 7+ messages in thread
From: Jason Spiro @ 2007-03-13 8:50 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: toby-predictive
Hi all,
I am trying to get menu completion working for Alessandro Piras'
vimpulse.el, available on EmacsWiki. (Menu completion is an
ultra-nice feature. Instead of having to press M-/ over and over
until you get what you want, you get a drop-down menu listing the
completion options. To see what menu completion looks like in Vim,
see http://en.wikibooks.org/wiki/Learning_the_vi_editor/Vim/Useful_things_for_programmers_to_know)
If you have Toby Cubitt's predictive completion from
http://www.dr-qubit.org/emacs.php installed (incidentally, it's a very
cool package), I would appreciate if you could run this code so you
can answer my question 1 below:
;; Begin code {{{
(require 'completion-ui)
;; Note: This code has an additional bug in addition to the problem I
;; am asking about in this mailing list message:
;; When called with a MAXNUM of nil, this func sometimes fails. (Seems
;; to work the first time, then fail all times after, in such cases.
;; To fix, call with a normal MAXNUM.)
(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))
(defun vimpulse-show-completion-menu ()
(interactive)
(setq-default completion-function
'vimpulse-try-hippie-expand-listed-functions)
(setq completion-function 'vimpulse-try-hippie-expand-listed-functions)
;; is this always necessary? Am I even ever supposed to call it?
(completion-setup-overlay 'prefix)
(completion-show-menu))
;; }}} End code
1. Whenever I start typing a word then run
vimpulse-show-completion-menu I get an empty menu. Why? (Am I using
completion-show-menu wrong? It errors on me if I don't call
completion-setup-overlay first, so I call it first. Should I? In
general, what is the proper way to use completion-show-menu? It's not
perfectly documented.
2. Should menu completion really be part of vimpulse.el, or should I
try to get it into the hippie-expand source base? Or, alternatively,
would someone like to take over maintainership of my attempt to get
menu completion working in Emacs?
Thanks in advance,
Jason
P.S. I am using GNU Emacs 22.0.50.1 (i486-pc-linux-gnu, GTK+ Version
2.10.3) of 2006-09-19 on rothera, modified by Debian. That's 6 months
old. I am using predictive 0.16.2; I downloaded it today.
--
Jason Spiro: computer consulting with a smile.
I also provide training and spyware removal services for homes and businesses.
Call or email for a FREE 5-minute consultation. Satisfaction guaranteed.
+1 (416) 781-5938 / Email: info@jspiro.com / MSN: jasonspiro@hotmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu
2007-03-13 8:50 Jason Spiro
@ 2007-03-14 4:36 ` Toby Cubitt
2007-03-14 18:24 ` Jason Spiro
0 siblings, 1 reply; 7+ messages in thread
From: Toby Cubitt @ 2007-03-14 4:36 UTC (permalink / raw)
To: Jason Spiro; +Cc: help-gnu-emacs
Hi,
I'm not surprised it doesn't work, because you're using completion-UI in
completely the wrong way. (Excusable, since documentation is currently
fairly non-existent :-) Instead, set 'completion-function' to a function
that returns a list of possible completions, and leave completion-UI to
do its job.
Your comment 2. is along the right lines: menu completion shouldn't be
implemented in the vimpulse code base, or indeed in the code base of any
other completion package. It should indeed be in something like the
hippie-expand package. But that's precisely what completion-UI is! All
the hippie-expand features, plus tooltips, menu-completion,
auto-completion, hotkey completion etc. etc. Completion-UI is supposed
to supersede hippie-expand, at least for in-buffer completion. So using
completion-UI and hippie-expand at the same time is unlikely to work
very well.
As an Elisp coder, you're not supposed to invoke *any* completion
interface explicitly, as you've tried to do. Deciding which combination
of user-interfaces to use is the user's business, not the package
writer's. Maybe some users want to use menu completion, but others
prefer to see a list in the echo area, whilst still others just want a
tooltip to popup after a delay, etc. etc. Completion-UI offloads those
choices onto the user, which is where they should be.
I hope that makes things a bit clearer. I fully appreciate that using
completion-UI will be confusing until it's properly documented, although
the commentary at the beginning of completion-ui.el does tersely explain
how it should be used. (Setting 'completion-function' really is all
there is to it, I promise!)
Toby
Jason Spiro wrote:
> Hi all,
>
> I am trying to get menu completion working for Alessandro Piras'
> vimpulse.el, available on EmacsWiki. (Menu completion is an
> ultra-nice feature. Instead of having to press M-/ over and over
> until you get what you want, you get a drop-down menu listing the
> completion options. To see what menu completion looks like in Vim,
> see
> http://en.wikibooks.org/wiki/Learning_the_vi_editor/Vim/Useful_things_for_programmers_to_know)
>
>
> If you have Toby Cubitt's predictive completion from
> http://www.dr-qubit.org/emacs.php installed (incidentally, it's a very
> cool package), I would appreciate if you could run this code so you
> can answer my question 1 below:
>
> ;; Begin code {{{
>
> (require 'completion-ui)
>
> ;; Note: This code has an additional bug in addition to the problem I
> ;; am asking about in this mailing list message:
> ;; When called with a MAXNUM of nil, this func sometimes fails. (Seems
> ;; to work the first time, then fail all times after, in such cases.
> ;; To fix, call with a normal MAXNUM.)
> (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))
>
> (defun vimpulse-show-completion-menu ()
> (interactive)
> (setq-default completion-function
> 'vimpulse-try-hippie-expand-listed-functions)
> (setq completion-function 'vimpulse-try-hippie-expand-listed-functions)
> ;; is this always necessary? Am I even ever supposed to call it?
> (completion-setup-overlay 'prefix)
> (completion-show-menu))
>
> ;; }}} End code
>
> 1. Whenever I start typing a word then run
> vimpulse-show-completion-menu I get an empty menu. Why? (Am I using
> completion-show-menu wrong? It errors on me if I don't call
> completion-setup-overlay first, so I call it first. Should I? In
> general, what is the proper way to use completion-show-menu? It's not
> perfectly documented.
>
> 2. Should menu completion really be part of vimpulse.el, or should I
> try to get it into the hippie-expand source base? Or, alternatively,
> would someone like to take over maintainership of my attempt to get
> menu completion working in Emacs?
>
> Thanks in advance,
> Jason
>
> P.S. I am using GNU Emacs 22.0.50.1 (i486-pc-linux-gnu, GTK+ Version
> 2.10.3) of 2006-09-19 on rothera, modified by Debian. That's 6 months
> old. I am using predictive 0.16.2; I downloaded it today.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu
2007-03-14 4:36 ` Toby Cubitt
@ 2007-03-14 18:24 ` Jason Spiro
0 siblings, 0 replies; 7+ messages in thread
From: Jason Spiro @ 2007-03-14 18:24 UTC (permalink / raw)
To: Toby Cubitt; +Cc: help-gnu-emacs
Hi Toby,
2007/3/14, Toby Cubitt <t.s.cubitt.98-dated-1174279006.800fd7@cantab.net> wrote:
> I'm not surprised it doesn't work, because you're using completion-UI in
> completely the wrong way. (Excusable, since documentation is currently
> fairly non-existent :-) Instead, set 'completion-function' to a function
> that returns a list of possible completions, and leave completion-UI to
> do its job.
>
Will try it - thanks for the explanation.
> Your comment 2. is along the right lines: menu completion shouldn't be
> implemented in the vimpulse code base, or indeed in the code base of any
> other completion package. It should indeed be in something like the
> hippie-expand package. But that's precisely what completion-UI is! All
> the hippie-expand features, plus tooltips, menu-completion,
> auto-completion, hotkey completion etc. etc. Completion-UI is supposed
> to supersede hippie-expand, at least for in-buffer completion. So using
> completion-UI and hippie-expand at the same time is unlikely to work
> very well.
>
I decided on hippie-expand because it can complete:
- words (like dabbrev does)
- filenames
- entire buffer lines.
and more. I am trying to emulate Vim's completion behavior, and Vim
can complete all those things and more. Unfortunately it can't
complete multiple-word sequences like dabbrev can when you press M-/
SPC M-/ SPC M-/ but I hope someone else or I will add that later.
> As an Elisp coder, you're not supposed to invoke *any* completion
> interface explicitly, as you've tried to do. Deciding which combination
> of user-interfaces to use is the user's business, not the package
> writer's. Maybe some users want to use menu completion, but others
> prefer to see a list in the echo area, whilst still others just want a
> tooltip to popup after a delay, etc. etc. Completion-UI offloads those
> choices onto the user, which is where they should be.
>
I want Vimpulse to emulate Vim's completion behavior: when you press
C-n, C-p, or any of the other completion keys in Insert mode: it shows
a menu. Is there a way to programmatically change a Customize
variable's default so that my change will take effect if and only if
the user does not customize that variable themselves?
> I hope that makes things a bit clearer. I fully appreciate that using
> completion-UI will be confusing until it's properly documented, although
> the commentary at the beginning of completion-ui.el does tersely explain
> how it should be used. (Setting 'completion-function' really is all
> there is to it, I promise!)
>
I eagerly await that future day when it'll be better documented then :-)
Till then, do you know of any code examples that call completion-ui
that I could look at?
Cheers,
Jason
--
Jason Spiro: computer consulting with a smile.
I provide software development and training services to clients worldwide.
Contact me for a FREE consultation. Satisfaction guaranteed.
+1 (416) 781-5938 / Email: info@jspiro.com / MSN: jasonspiro@hotmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-04-13 8:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-12 23:16 completion-ui.el question: my vimpulse-show-completion-menu function always gives me an empty menu Jason Spiro
[not found] ` <c241693f0704121619i14d16188j2cdb3e5c6baf6860@mail.gmail.com>
2007-04-13 8:00 ` Fwd: " Toby Cubitt
2007-04-13 8:31 ` Jason Spiro
2007-04-13 8:50 ` Toby Cubitt
-- strict thread matches above, loose matches on Subject: below --
2007-03-13 8:50 Jason Spiro
2007-03-14 4:36 ` Toby Cubitt
2007-03-14 18:24 ` Jason Spiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).