all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using ido-completions in other packages
@ 2010-06-04  9:35 Andrea Crotti
  2010-06-04 10:57 ` Tassilo Horn
  2010-06-08  4:39 ` William Xu
  0 siblings, 2 replies; 12+ messages in thread
From: Andrea Crotti @ 2010-06-04  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

I was wondering if it would be possible to use the nice ido-mode
completion elsewhere.

For example senator-jump is really cool, but I always have to type the
complete name of the function/class, which is a bit annoying, while the
ido-completion like is much faster and nicer.

I've looked in the code but I don't see what I could substitute, maybe
substituting some functions or advising something else would do the
trick?

Thanks




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04  9:35 Using ido-completions in other packages Andrea Crotti
@ 2010-06-04 10:57 ` Tassilo Horn
  2010-06-04 12:06   ` Štěpán Němec
  2010-06-08  4:39 ` William Xu
  1 sibling, 1 reply; 12+ messages in thread
From: Tassilo Horn @ 2010-06-04 10:57 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

Hi Andrea,

> I've looked in the code but I don't see what I could substitute, maybe
> substituting some functions or advising something else would do the
> trick?

Basically, if you want to use ido-completion in some code, you would use
`ido-comleting-read' instead of `completing-read'.  For example, in some
home-brewn mode I have something like that:

--8<---------------cut here---------------start------------->8---
(if (and (featurep 'ido) ido-mode)
    ;; ido is available and enabled, so use it.
    (ido-completing-read "Command: " commands)
  ;; fallback to normal completion with the
  ;; most frequently used command as default.
  (completing-read
   (concat "Command (defaults to `"
           (car commands) "'): ")
   commands
   nil t nil nil (car commands)))
--8<---------------cut here---------------end--------------->8---

You could try to make `completing-read' point to `ido-completing-read':

  (fset 'completing-read 'ido-completing-read)

But that might error in some cases, cause `completing-read' has one
optional parameter more than `ido-completing-read'.  You might want to
create a function `andrea-completing-read' with the exact signature of
`completing-read' which just delegates to `ido-completing-read' and
throws away the additional parameter, and then do

  (fset 'completing-read 'andrea-completing-read)

In any case: This method is a hammer, so be warned. ;-)

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 10:57 ` Tassilo Horn
@ 2010-06-04 12:06   ` Štěpán Němec
  2010-06-04 12:12     ` Andrea Crotti
  0 siblings, 1 reply; 12+ messages in thread
From: Štěpán Němec @ 2010-06-04 12:06 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs, Andrea Crotti

Tassilo Horn <tassilo@member.fsf.org> writes:

> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> Hi Andrea,
>
>> I've looked in the code but I don't see what I could substitute, maybe
>> substituting some functions or advising something else would do the
>> trick?

What I've been successfully using for some time is this, based on the
dysfunctional (for me, anyway) tip from the Emacs Wiki:

<http://www.emacswiki.org/emacs/InteractivelyDoThings#toc12>

(defvar ido-replace-completing-read t
  "If non-nil, use `ido-completing-read' instead of `completing-read' if possible.

Set it to nil using `let' in around-advice for functions where the
original `completing-read' is required.  For example, if a function
foo absolutely must use the original `completing-read', define some
advice like this:

\(defadvice foo (around original-completing-read-only activate)
  \(let (ido-replace-completing-read) ad-do-it))")

(defvar ido-replace-completing-read-ignore-commands nil
  "List of commands to... you get the point.")

(setq ido-replace-completing-read-ignore-commands
      '(describe-function describe-variable find-function find-variable
        w3m-goto-url w3m-goto-url-new-session))

;; replace completing-read wherever possible, unless directed otherwise
(defadvice completing-read
  (around use-ido-when-possible activate)
  (if (or (not ido-replace-completing-read)
          ido-cur-list             ; Avoid infinite loop from ido calling this
          (memq this-command ido-replace-completing-read-ignore-commands))           
      ad-do-it
    (let ((allcomp (all-completions "" collection predicate)))
      (if allcomp
          (setq ad-return-value
                (ido-completing-read prompt
                                     allcomp
                                     nil require-match initial-input hist def))
        ad-do-it))))


HTH,

Štěpán

>
> Basically, if you want to use ido-completion in some code, you would use
> `ido-comleting-read' instead of `completing-read'.  For example, in some
> home-brewn mode I have something like that:
>
> (if (and (featurep 'ido) ido-mode)
>     ;; ido is available and enabled, so use it.
>     (ido-completing-read "Command: " commands)
>   ;; fallback to normal completion with the
>   ;; most frequently used command as default.
>   (completing-read
>    (concat "Command (defaults to `"
>            (car commands) "'): ")
>    commands
>    nil t nil nil (car commands)))
>
> You could try to make `completing-read' point to `ido-completing-read':
>
>   (fset 'completing-read 'ido-completing-read)
>
> But that might error in some cases, cause `completing-read' has one
> optional parameter more than `ido-completing-read'.  You might want to
> create a function `andrea-completing-read' with the exact signature of
> `completing-read' which just delegates to `ido-completing-read' and
> throws away the additional parameter, and then do
>
>   (fset 'completing-read 'andrea-completing-read)
>
> In any case: This method is a hammer, so be warned. ;-)
>
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 12:06   ` Štěpán Němec
@ 2010-06-04 12:12     ` Andrea Crotti
  2010-06-04 13:14       ` Thierry Volpiatto
  0 siblings, 1 reply; 12+ messages in thread
From: Andrea Crotti @ 2010-06-04 12:12 UTC (permalink / raw)
  To: help-gnu-emacs

Štěpán Němec <stepnem@gmail.com> writes:

> Tassilo Horn <tassilo@member.fsf.org> writes:
>

> What I've been successfully using for some time is this, based on the
> dysfunctional (for me, anyway) tip from the Emacs Wiki:
>
> <http://www.emacswiki.org/emacs/InteractivelyDoThings#toc12>

That looks very nice thanks a lot, but I tried for example with
senator-jump and it doesn't work.

I guess that maybe not all the functions will use internally
read-completion, is that correct?




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 12:12     ` Andrea Crotti
@ 2010-06-04 13:14       ` Thierry Volpiatto
  2010-06-04 14:41         ` Andrea Crotti
  0 siblings, 1 reply; 12+ messages in thread
From: Thierry Volpiatto @ 2010-06-04 13:14 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Štěpán Němec <stepnem@gmail.com> writes:
>
>> Tassilo Horn <tassilo@member.fsf.org> writes:
>>
>
>> What I've been successfully using for some time is this, based on the
>> dysfunctional (for me, anyway) tip from the Emacs Wiki:
>>
>> <http://www.emacswiki.org/emacs/InteractivelyDoThings#toc12>
>
> That looks very nice thanks a lot, but I tried for example with
> senator-jump and it doesn't work.

I don't know what is senator-jump, but i guess this function use a
simple read-string. To have completion you need a *-completing-read with a
collection as arg.

I think a better approach to enable a ido-completing-read is what DVC
does:

,----
| (defun dvc-completing-read (&rest args)
|   "Read a string in the minibuffer, with completion.
| Set `dvc-completing-read-function' to determine which function to use.
| 
| See `completing-read' for a description of ARGS."
|   ;; Initialize dvc-completing-read-function on the first invocation of dvc-completing-read
|   ;; This allows to enable ido-mode after loading DVC
|   (when (eq dvc-completing-read-function 'auto)
|     (setq dvc-completing-read-function (if (and (boundp 'ido-mode) ido-mode)
|                                            'ido-completing-read
|                                          'completing-read)))
|   (apply dvc-completing-read-function args))
`----


> I guess that maybe not all the functions will use internally
> read-completion, is that correct?
Yes like read-string.

FYI you have also an anything implementation of completing-read that is
available in anything-config.el, it is called anything-comp-read.

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 13:14       ` Thierry Volpiatto
@ 2010-06-04 14:41         ` Andrea Crotti
  2010-06-04 15:15           ` Thierry Volpiatto
  0 siblings, 1 reply; 12+ messages in thread
From: Andrea Crotti @ 2010-06-04 14:41 UTC (permalink / raw)
  To: help-gnu-emacs

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>
> I don't know what is senator-jump, but i guess this function use a
> simple read-string. To have completion you need a *-completing-read with a
> collection as arg.

Here is the part of the code that I think is in charge for showing me
the list of possibilities.
It does use completing-read, but maybe using apply it doesn't work?
(Just wild guessing).

--8<---------------cut here---------------start------------->8---
      (let*
      ...
         (completing-read-args
          (list (if (and context (car context))
                    (format "%s(default: %s) " prompt (car context))
                  prompt)
                (setq senator-jump-completion-list
                      (senator-completion-list in-context))
                nil
                require-match
                ""
                'semantic-read-symbol-history)))
    (list
     (apply #'completing-read
            (if (and context (car context))
                (append completing-read-args context)
              completing-read-args))
     in-context no-default)))
--8<---------------cut here---------------end--------------->8---



>
> ,----
> | (defun dvc-completing-read (&rest args)
> |   "Read a string in the minibuffer, with completion.
> | Set `dvc-completing-read-function' to determine which function to use.
> | 
> | See `completing-read' for a description of ARGS."
> |   ;; Initialize dvc-completing-read-function on the first invocation of dvc-completing-read
> |   ;; This allows to enable ido-mode after loading DVC
> |   (when (eq dvc-completing-read-function 'auto)
> |     (setq dvc-completing-read-function (if (and (boundp 'ido-mode) ido-mode)
> |                                            'ido-completing-read
> |                                          'completing-read)))
> |   (apply dvc-completing-read-function args))
> `----
>
>

Thanks a lot this looks alos cleaner...




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 14:41         ` Andrea Crotti
@ 2010-06-04 15:15           ` Thierry Volpiatto
  2010-06-05 14:15             ` Andrea Crotti
  0 siblings, 1 reply; 12+ messages in thread
From: Thierry Volpiatto @ 2010-06-04 15:15 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>>
>> I don't know what is senator-jump, but i guess this function use a
>> simple read-string. To have completion you need a *-completing-read with a
>> collection as arg.
>
> Here is the part of the code that I think is in charge for showing me
> the list of possibilities.
> It does use completing-read, but maybe using apply it doesn't work?
> (Just wild guessing).
>
>       (let*
>       ...
>          (completing-read-args
>           (list (if (and context (car context))
>                     (format "%s(default: %s) " prompt (car context))
>                   prompt)
>                 (setq senator-jump-completion-list
>                       (senator-completion-list in-context))
>                 nil
>                 require-match
>                 ""
>                 'semantic-read-symbol-history)))
>     (list
>      (apply #'completing-read
>             (if (and context (car context))
>                 (append completing-read-args context)
>               completing-read-args))
>      in-context no-default)))
>

Try that:

copy/paste the function senator-jump in your .emacs and replace
(apply #'completing-read
by
(apply #'ido-completing-read

That will give you ido completion, but if 
(senator-completion-list in-context) return nothing (nil)
the problem come from here.

To know that, use C-u C-M x on the function senator-jump and use it,
and then use "n" to step throught the code.

Do you have completion with the original code?(i.e using
completing-read)

--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04 15:15           ` Thierry Volpiatto
@ 2010-06-05 14:15             ` Andrea Crotti
  0 siblings, 0 replies; 12+ messages in thread
From: Andrea Crotti @ 2010-06-05 14:15 UTC (permalink / raw)
  To: help-gnu-emacs

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> Try that:
>
> copy/paste the function senator-jump in your .emacs and replace
> (apply #'completing-read
> by
> (apply #'ido-completing-read
>
> That will give you ido completion, but if 
> (senator-completion-list in-context) return nothing (nil)
> the problem come from here.
>
> To know that, use C-u C-M x on the function senator-jump and use it,
> and then use "n" to step throught the code.
>
> Do you have completion with the original code?(i.e using
> completing-read)

Great
- copy pasting
- modifying
- evaluating
and it works, even if not perfect at all I have to say...
But then I tried both the approaches you've sended me here and they
don't work, so what could be the problem?




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-04  9:35 Using ido-completions in other packages Andrea Crotti
  2010-06-04 10:57 ` Tassilo Horn
@ 2010-06-08  4:39 ` William Xu
  2010-08-16  9:27   ` Andrea Crotti
  1 sibling, 1 reply; 12+ messages in thread
From: William Xu @ 2010-06-08  4:39 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

   I was wondering if it would be possible to use the nice ido-mode
   completion elsewhere.

   For example senator-jump is really cool, but I always have to type the
   complete name of the function/class, which is a bit annoying, while the
   ido-completion like is much faster and nicer.

   I've looked in the code but I don't see what I could substitute, maybe
   substituting some functions or advising something else would do the
   trick?

I use ido-hacks.el.  Very nice.  

http://permalink.gmane.org/gmane.emacs.help/61442

-- 
William

http://xwl.appspot.com




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-06-08  4:39 ` William Xu
@ 2010-08-16  9:27   ` Andrea Crotti
  2010-08-16 11:07     ` Richard Riley
  0 siblings, 1 reply; 12+ messages in thread
From: Andrea Crotti @ 2010-08-16  9:27 UTC (permalink / raw)
  To: help-gnu-emacs

William Xu <william.xwl@gmail.com> writes:

> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
>    I was wondering if it would be possible to use the nice ido-mode
>    completion elsewhere.
>
>    For example senator-jump is really cool, but I always have to type the
>    complete name of the function/class, which is a bit annoying, while the
>    ido-completion like is much faster and nicer.
>
>    I've looked in the code but I don't see what I could substitute, maybe
>    substituting some functions or advising something else would do the
>    trick?
>
> I use ido-hacks.el.  Very nice.  
>
> http://permalink.gmane.org/gmane.emacs.help/61442

I answer a bit late sorry, just tried now ido-hacks but still semantic
doesn't care at all about it...

I guess it just doesn't work with an easy defadvice then...
Any other idea is welcome.

Now I'm too used to have flex matching that is always a pain when I
don't have it...




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-08-16  9:27   ` Andrea Crotti
@ 2010-08-16 11:07     ` Richard Riley
  2010-08-17 21:49       ` Andrea Crotti
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Riley @ 2010-08-16 11:07 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> William Xu <william.xwl@gmail.com> writes:
>
>> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>>
>>    I was wondering if it would be possible to use the nice ido-mode
>>    completion elsewhere.
>>
>>    For example senator-jump is really cool, but I always have to type the
>>    complete name of the function/class, which is a bit annoying, while the
>>    ido-completion like is much faster and nicer.
>>
>>    I've looked in the code but I don't see what I could substitute, maybe
>>    substituting some functions or advising something else would do the
>>    trick?
>>
>> I use ido-hacks.el.  Very nice.  
>>
>> http://permalink.gmane.org/gmane.emacs.help/61442
>
> I answer a bit late sorry, just tried now ido-hacks but still semantic
> doesn't care at all about it...

ido-hacks doesnt include any code for semantic afaik. Since ido-mode is
now part of emacs it might make sense to ask on the cedet mailing list
about ido integration.

>
> I guess it just doesn't work with an easy defadvice then...
> Any other idea is welcome.
>
> Now I'm too used to have flex matching that is always a pain when I
> don't have it...
>





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Using ido-completions in other packages
  2010-08-16 11:07     ` Richard Riley
@ 2010-08-17 21:49       ` Andrea Crotti
  0 siblings, 0 replies; 12+ messages in thread
From: Andrea Crotti @ 2010-08-17 21:49 UTC (permalink / raw)
  To: help-gnu-emacs

Richard Riley <rileyrg@gmail.com> writes:

> ido-hacks doesnt include any code for semantic afaik. Since ido-mode is
> now part of emacs it might make sense to ask on the cedet mailing list
> about ido integration.
>

Sure, but it advice the functions that normally every package use for
getting completion.
Also looking at the code I think it should work, but it doesn't...

Anyway I got ido working on many other things with those ido-hacks,
which is still very nice.




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-08-17 21:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-04  9:35 Using ido-completions in other packages Andrea Crotti
2010-06-04 10:57 ` Tassilo Horn
2010-06-04 12:06   ` Štěpán Němec
2010-06-04 12:12     ` Andrea Crotti
2010-06-04 13:14       ` Thierry Volpiatto
2010-06-04 14:41         ` Andrea Crotti
2010-06-04 15:15           ` Thierry Volpiatto
2010-06-05 14:15             ` Andrea Crotti
2010-06-08  4:39 ` William Xu
2010-08-16  9:27   ` Andrea Crotti
2010-08-16 11:07     ` Richard Riley
2010-08-17 21:49       ` Andrea Crotti

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.