* pymacs & interactivel isp functions
@ 2008-11-19 16:16 Matt Price
2008-11-19 17:37 ` Drew Adams
0 siblings, 1 reply; 8+ messages in thread
From: Matt Price @ 2008-11-19 16:16 UTC (permalink / raw)
To: help-gnu-emacs
hi,
still having trouble with my interactive query to evolution. python has
evolution bindings so i thought it would be nice to integrate python and
emacs using pymacs. i'm running into an issuethat i think is pymacs'
fault, i'm hoping someone on the list uses pymacs and can help.
i wrote this little python function, which returns a list of names and
addresses:
def return_addresslist (queryterm):
results = abook.search(queryterm)
names =[]
for record in results:
name = str(record.get_name())
print type(name)
address = str(record.get_property('email_1'))
names.append(name + " " + "<" + address +">")
for i in ["2","3"]:
if record.get_property('email_' + i):
address = record.get_property('email_' + i)
record.get_property('email_' + i)
names.append(name + ' '+ "<" + address +">")
return names
then in an elisp file, i try e.g.:
(pymacs-load "edsquery")
(setq collection (edsquery-return-addresslist "matt"))
which assigns this value to collection:
("Matt Price <matt.price@utoronto.ca>" "Matt Price <moptop99@gmail.com>" "Matthew Garrett <mjg59@srcf.ucam.org>" "Matt Zimmerman <mdz@canonical.com>" "Matt Fontaine <Matty_fontaine@hotmail.com>" "Matt Wilks <matt@madhaus.cns.utoronto.ca>" "Matthew Yates <myatesmyates@yahoo.com>" "Matthew Flaschen <matthew.flaschen@gatech.edu>" "Matthew Vermeulen <MattVermeulen@gmail.com>" "Matthew East <matt@mdke.org>" "matthewreedy <matthewreedy@yahoo.com>" "Matthias Dörries <matthias.doerries@gersulp.u-strasbg.fr>" ...)
my problem comes with a test function that triesto use the results of a
query as a collection for tab-completion:
(defun matt/external-addressbook-completion (stub)
"get a list of addresses for tab-completion in a new email"
(interactive (list (completing-read "Name: "
(edsquery-return-addresslist (string))
;; collection
nil t))))
the function works properly if i use the list "collection" generated as
above, but does not give any completion options if the python function
is called instead.
in the *Pymacs* buffer i noticesomething that seems important. when i
call the python function direction with (edsquery-python-addressbook
"matt), i have this message:
>23 eval python[1]("matt")
[]
<600 (return '("Matt Price <matt.price@utoronto.ca>" "Matt Price <moptop99@gmail.com>" "Matthew Garrett <mjg59@srcf.ucam.org>" "Matt Zimmerman <mdz@canonical.com>" "Matt Fontaine <Matty_fontaine@hotmail.com>" "Matt Wilks <matt@madhaus.cns.utoronto.ca>" "Matthew Yates <myatesmyates@yahoo.com>" "Matthew Flaschen <matthew.flaschen@gatech.edu>" "Matthew Vermeulen <MattVermeulen@gmail.com>" "Matthew East <matt@mdke.org>" "matthewreedy <matthewreedy@yahoo.com>" "Matthias D\303\266rries <matthias.doerries@gersulp.u-strasbg.fr>" "Matt Davey <mcdavey@mrao.cam.ac.uk>" "Matt Price <matt.price@utoronto.ca>"))
but when calling from completing-read, i get this instead:
>19 eval python[1]("")
[]
<14 (return 'nil)
to me it seems that the completion function isn't being sent the input
string. but i can't understand why this should be, as identical syntax
works with straight lisp functions.
--
Matt Price
matt.price@utoronto.ca
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: pymacs & interactivel isp functions
2008-11-19 16:16 pymacs & interactivel isp functions Matt Price
@ 2008-11-19 17:37 ` Drew Adams
2008-11-22 8:39 ` Matt Price
0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2008-11-19 17:37 UTC (permalink / raw)
To: 'Matt Price', 'help-gnu-emacs'
> (setq collection (edsquery-return-addresslist "matt"))
>
> which assigns this value to collection:
> ("Matt Price <matt.price@utoronto.ca>" ...)
>
> my problem comes with a test function that triesto use the
> results of a query as a collection for tab-completion:
>
> (defun matt/external-addressbook-completion (stub)
> "get a list of addresses for tab-completion in a new email"
> (interactive (list (completing-read "Name: "
> (edsquery-return-addresslist (string))
> ;; collection
> nil t))))
>
> the function works properly if i use the list "collection"
> generated as above, but does not give any completion options if
> the python functioloadf is called instead.
C-h f string
,----
| string is a built-in function in `C source code'.
|
| (string &rest CHARACTERS)
|
| Concatenate all the argument characters and make the result a string.
`----
You used (string), which calls string with an empty list of args, so it
concatenates all zero of those together into the empty string, "".
> in the *Pymacs* buffer i ... have this message:
> >23 eval python[1]("matt")
> but when calling from completing-read, i get this instead:
> >19 eval python[1]("")
Right. See above.
> to me it seems that the completion function isn't being sent the input
> string.
What input string? You're passing (string), which is "", not any input string.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: pymacs & interactivel isp functions
[not found] <mailman.747.1227111401.26697.help-gnu-emacs@gnu.org>
@ 2008-11-20 19:48 ` Greg Detre
0 siblings, 0 replies; 8+ messages in thread
From: Greg Detre @ 2008-11-20 19:48 UTC (permalink / raw)
To: help-gnu-emacs
if i understand correctly, you're saying that this works:
(setq collection (edsquery-return-addresslist "matt"))
but this doesn't
> (defun matt/external-addressbook-completion (stub)
> "get a list of addresses for tab-completion in a new email"
> (interactive (list (completing-read "Name: "
> (edsquery-return-addresslist (string))
> ;; collection
> nil t))))
is it possible that the variable you're sending in to edsquery-return-
addresslist is wrong? it looks like you're feeding in a function
(string), when presumably you mean to be feeding in some actual string
(e.g. the 'stub' input variable which you're not using).
g
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: pymacs & interactivel isp functions
2008-11-19 17:37 ` Drew Adams
@ 2008-11-22 8:39 ` Matt Price
2008-11-22 15:27 ` Kevin Rodgers
2008-11-22 15:27 ` Drew Adams
0 siblings, 2 replies; 8+ messages in thread
From: Matt Price @ 2008-11-22 8:39 UTC (permalink / raw)
To: Drew Adams; +Cc: 'help-gnu-emacs'
On Wed, 2008-11-19 at 09:37 -0800, Drew Adams wrote:
> > (setq collection (edsquery-return-addresslist "matt"))
> >
> > which assigns this value to collection:
> > ("Matt Price <matt.price@utoronto.ca>" ...)
> >
> > my problem comes with a test function that triesto use the
> > results of a query as a collection for tab-completion:
> >
> > (defun matt/external-addressbook-completion (stub)
> > "get a list of addresses for tab-completion in a new email"
> > (interactive (list (completing-read "Name: "
> > (edsquery-return-addresslist (string))
> > ;; collection
> >
> You used (string), which calls string with an empty list of args, so it
> concatenates all zero of those together into the empty string, "".
> > to me it seems that the completion function isn't being sent the input
> > string.
>
> What input string? You're passing (string), which is "", not any input string.
>
thanks drew. i don't know why i thought that similar syntax had worked
in an earlier case -- clearly it must not have. this was very helpful
and now i am very close.
i now have the following completion code:
(defun matt/external-addressbook-completion (stub)
(interactive (list (completing-read "Name: "
#'edsquery-return-addresslist
nil t))))
when called interactively, it _does_ suggest the first option in the
list that python returns, but it also gives me the following error:
ad-Orig-minibuffer-complete: Wrong type argument: number-or-marker-p,
("Matt Price <moptop99@gmail.com>" "Matthew Garrett
<mjg59@srcf.ucam.org>" "Matt Zimmerman <mdz@canonical.com>" "Matt
Fontaine <Matty_fontaine@hotmail.com>" "Matt Wilks
<matt@madhaus.cns.utoronto.ca>" "Matthew Yates <myatesmyates@yahoo.com>"
"Matthew Flaschen <matthew.flaschen@gatech.edu>" "Matthew Vermeulen
<MattVermeulen@gmail.com>" "Matthew East <matt@mdke.org>" "matthewreedy
<matthewreedy@yahoo.com>" ...)
i'm not sure, but it looks like it isn't breaking the cdr cell down into
its components before evaluating it? suggesting to me that, again,
there's something wrong with my syntax.
i appreciatethe remedial lisp lessons. sorry to just continue not
getting it... thanks again,
matt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: pymacs & interactivel isp functions
2008-11-22 8:39 ` Matt Price
@ 2008-11-22 15:27 ` Kevin Rodgers
2008-11-22 15:27 ` Drew Adams
1 sibling, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2008-11-22 15:27 UTC (permalink / raw)
To: help-gnu-emacs
Matt Price wrote:
> On Wed, 2008-11-19 at 09:37 -0800, Drew Adams wrote:
>>> (setq collection (edsquery-return-addresslist "matt"))
>>>
>>> which assigns this value to collection:
>>> ("Matt Price <matt.price@utoronto.ca>" ...)
>>>
>>> my problem comes with a test function that triesto use the
>>> results of a query as a collection for tab-completion:
>>>
>>> (defun matt/external-addressbook-completion (stub)
>>> "get a list of addresses for tab-completion in a new email"
>>> (interactive (list (completing-read "Name: "
>>> (edsquery-return-addresslist (string))
>>> ;; collection
>>>
>
>
>> You used (string), which calls string with an empty list of args, so it
>> concatenates all zero of those together into the empty string, "".
>
>>> to me it seems that the completion function isn't being sent the input
>>> string.
>> What input string? You're passing (string), which is "", not any input string.
>>
> thanks drew. i don't know why i thought that similar syntax had worked
> in an earlier case -- clearly it must not have. this was very helpful
> and now i am very close.
>
> i now have the following completion code:
>
> (defun matt/external-addressbook-completion (stub)
> (interactive (list (completing-read "Name: "
> #'edsquery-return-addresslist
> nil t))))
> when called interactively, it _does_ suggest the first option in the
> list that python returns, but it also gives me the following error:
>
> ad-Orig-minibuffer-complete: Wrong type argument: number-or-marker-p,
> ("Matt Price <moptop99@gmail.com>" "Matthew Garrett
> <mjg59@srcf.ucam.org>" "Matt Zimmerman <mdz@canonical.com>" "Matt
> Fontaine <Matty_fontaine@hotmail.com>" "Matt Wilks
> <matt@madhaus.cns.utoronto.ca>" "Matthew Yates <myatesmyates@yahoo.com>"
> "Matthew Flaschen <matthew.flaschen@gatech.edu>" "Matthew Vermeulen
> <MattVermeulen@gmail.com>" "Matthew East <matt@mdke.org>" "matthewreedy
> <matthewreedy@yahoo.com>" ...)
>
> i'm not sure, but it looks like it isn't breaking the cdr cell down into
> its components before evaluating it? suggesting to me that, again,
> there's something wrong with my syntax.
When you pass a function to completing-read, it is not used to generate
the list of canidate completions. As documented:
collection can be a list of strings, an alist, an obarray or a hash table.
collection can also be a function to do the completion itself.
predicate limits completion to a subset of collection.
See `try-completion' and `all-completions' for more details
...
collection can also be a function to do the completion itself.
It receives three arguments: the values string, predicate and nil.
I think what you want is:
(defun matt/external-addressbook-completion (stub)
(interactive (list (completing-read "Name: "
(edsquery-return-addresslist "")
nil t))))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: pymacs & interactivel isp functions
2008-11-22 8:39 ` Matt Price
2008-11-22 15:27 ` Kevin Rodgers
@ 2008-11-22 15:27 ` Drew Adams
2008-11-22 21:07 ` Matt Price
1 sibling, 1 reply; 8+ messages in thread
From: Drew Adams @ 2008-11-22 15:27 UTC (permalink / raw)
To: 'Matt Price'; +Cc: 'help-gnu-emacs'
> > You're passing (string), which is ""
>
> thanks drew. i don't know why i thought that similar syntax
> had worked in an earlier case -- clearly it must not have.
> this was very helpful and now i am very close.
>
> i now have the following completion code:
>
> (defun matt/external-addressbook-completion (stub)
> (interactive (list (completing-read "Name: "
> #'edsquery-return-addresslist
> nil t))))
>
> when called interactively, it _does_ suggest the first option in the
> list that python returns, but it also gives me the following error:
>
> ad-Orig-minibuffer-complete: Wrong type argument: number-or-marker-p,
> ("Matt Price <moptop99@gmail.com>" ...)
Dunno. Your function that does all of the completion,
`edsquery-return-addresslist' isn't shown.
The error message is saying that function `ad-Orig-minibuffer-complete' expected
a number or a marker but received the list of strings.
You also apparently advised the standard function `minibuffer-complete', and
that code isn't shown either. So it's difficult to guess what is the problem.
> i'm not sure, but it looks like it isn't breaking the cdr
> cell down into its components before evaluating it?
> suggesting to me that, again, there's something wrong with my syntax.
No comprendo. What isn't breaking what cdr cell down into what components?
FWIW, I see nothing wrong with the call to completing-read. The problem is
likely in your completion function `edsquery-return-addresslist'.
> i appreciate the remedial lisp lessons. sorry to just continue not
> getting it... thanks again,
The error message should help. Look at your advised version of
`minibuffer-complete', `ad-Orig-minibuffer-complete', and see why and where it
expects a number or marker. Look at why your function `eds...' gives it a list
of strings in that place instead. Perhaps try unadvising `minibuffer-complete',
at least for testing.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: pymacs & interactivel isp functions
2008-11-22 15:27 ` Drew Adams
@ 2008-11-22 21:07 ` Matt Price
2008-11-22 21:45 ` Drew Adams
0 siblings, 1 reply; 8+ messages in thread
From: Matt Price @ 2008-11-22 21:07 UTC (permalink / raw)
To: Drew Adams; +Cc: 'help-gnu-emacs'
On Sat, 2008-11-22 at 07:27 -0800, Drew Adams wrote:
> Dunno. Your function that does all of the completion,
> `edsquery-return-addresslist' isn't shown.
>
that code is python. here it is, but i don't think it's the problem
(see next bit below):
def return_addresslist (queryterm, predicate, buff):
results = abook.search(queryterm)
names =[]
for record in results:
name = record.get_name()
address = record.get_property('email_1')
names.append(name + " " + "<" + address +">")
for i in ["2","3"]:
if record.get_property('email_' + i):
address = record.get_property('email_' + i)
record.get_property('email_' + i)
names.append(name + ' '+ "<" + address +">")
return names
it just returns a list of strings, which is what i thought
completing-read wanted to receive.
> The error message is saying that function `ad-Orig-minibuffer-complete' expected
> a number or a marker but received the list of strings.
>
i think ad-Orig-minibuffer-complete comes from the
minibuffer-complete-cycle package; i've taken out references to it in
my .emacs for now. but my issue persists.
> You also apparently advised the standard function `minibuffer-complete', and
> that code isn't shown either. So it's difficult to guess what is the problem.
i think this came from minibuffer-complete-cycle.
> > i'm not sure, but it looks like it isn't breaking the cdr
> > cell down into its components before evaluating it?
> > suggesting to me that, again, there's something wrong with my syntax.
>
> No comprendo. What isn't breaking what cdr cell down into what components?
>
um, i'm sure i just don't know what i'm talking about...
> FWIW, I see nothing wrong with the call to completing-read. The problem is
> likely in your completion function `edsquery-return-addresslist'.
or in my understanding of completing-read, see below.
>
> > i appreciate the remedial lisp lessons. sorry to just continue not
> > getting it... thanks again,
>
> The error message should help. Look at your advised version of
> `minibuffer-complete', `ad-Orig-minibuffer-complete', and see why and where it
> expects a number or marker. Look at why your function `eds...' gives it a list
> of strings in that place instead. Perhaps try unadvising `minibuffer-complete',
> at least for testing.
hmm, i thought i wanted edsquery to give a list of strings. i have the
following trivial code which is still giving the same kind of error, and
i think probably illustrates my conceptual error, whatever it is:
( matt/external-addressbook-completion (stub)
"get a list of addresses for tab-completion in a new email"
(interactive (list (completing-read "Name: "
#'static-list
;; collection
nil t))))
(defun static-list (s p n)
'("matt1" "matt2" "matt3"))
(setq collection '("matt1" "matt2" "matt3"))
if i let 'collection' serve as the collection, the function works as
expected; but if 'static list' is called instead, i once again have a
type error:
minibuffer-complete: Wrong type argument: number-or-marker-p, ("matt2"
"matt3")
my confusion, i guess, is that I'd thought the two should evaluate to
the same list '("matt1" "matt2" "matt3"). clearly i'm misunderstanding
something but it's the kind of conceptual error i have trouble finding
an answer for in the documentation.
thanks again. you should feel free to drop me, though, drew -- i
appreciate all your efforts.
matt
--
Matt Price
matt.price@utoronto.ca
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: pymacs & interactivel isp functions
2008-11-22 21:07 ` Matt Price
@ 2008-11-22 21:45 ` Drew Adams
0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2008-11-22 21:45 UTC (permalink / raw)
To: 'Matt Price'; +Cc: 'help-gnu-emacs'
> > Dunno. Your function that does all of the completion,
> > `edsquery-return-addresslist' isn't shown.
>
> here it is, but i don't think it's the problem
<snipped>
> it just returns a list of strings, which is what i thought
> completing-read wanted to receive.
No. As Kevin mentioned, and as I explained prior to that, if you use a function
as the COLLECTION argument, then `completing-read' expects that function to do
_everything_.
It does _not_ expect that function to just return a list of possible completion
candidates, which it then uses to perform completion. It expects that COLLECTION
function to perform the completion itself. `completing-read' doesn't really do
much at all in that case - it simply prompts and then passes your function to
`try-completion', which in turn uses your function to perform completion. It's
up to your function to perform the completion you want, that is, to do
_everything_.
This is all documented in the doc strings of `completing-read' and
`try-completion', and in the Elisp manual's nodes `Minibuffer Completion' and
(especially) `Programmed Completion'. You really must read that if you want to
learn this.
I'm not sure you need programmed completion for what you want to do - I doubt
it, in fact. But if you do, then you need to read the manual about that topic.
> > The error message is saying that function
> > `ad-Orig-minibuffer-complete' expected
> > a number or a marker but received the list of strings.
>
> i think ad-Orig-minibuffer-complete comes from the
> minibuffer-complete-cycle package; i've taken out references to it in
> my .emacs for now. but my issue persists.
Always try to minimize the number of things in the big sack of unknowns you
shake to test code. If your code doesn't rely upon stuff like
`minibuffer-complete-cycle', then by all means get rid of it (for now).
This is all the more true if such extraneous code advises functions. Advising
functions makes debugging more difficult (IMO). You think you are trying to
understand `minibuffer-complete', but really you are dealing with some modified
(advised) version of it. Walk away from that jungle as fast as you can.
> > You also apparently advised the standard function `minibuffer-complete',
> > and that code isn't shown either. So it's difficult to guess
> > what is the problem.
>
> i think this came from minibuffer-complete-cycle.
>
> > > i'm not sure, but it looks like it isn't breaking the cdr
> > > cell down into its components before evaluating it?
> > > suggesting to me that, again, there's something wrong
> > > with my syntax.
> >
> > No comprendo. What isn't breaking what cdr cell down into
> > what components?
>
> um, i'm sure i just don't know what i'm talking about...
Well, that makes two of us. ;-) You will know more after you study the manual
about this.
> > FWIW, I see nothing wrong with the call to completing-read.
> > The problem is likely in your completion function
> > `edsquery-return-addresslist'.
>
> or in my understanding of completing-read, see below.
>
> > > i appreciate the remedial lisp lessons. sorry to just
> > > continue not getting it... thanks again,
It's understandable, if you didn't read the manual. It would be quite difficult
to understand this stuff if you didn't read up on it.
That's what the manual is for - it's your friend. And it is usually much better
at explaining things that we folks at help-gnu-emacs. People here are glad to
help, but you need to do a minimum of homework yourself - to help yourself.
> > The error message should help. Look at your advised version of
> > `minibuffer-complete', `ad-Orig-minibuffer-complete', and
> > see why and where it expects a number or marker. Look at why
> > your function `eds...' gives it a list of strings in that place
> > instead. Perhaps try unadvising `minibuffer-complete',
> > at least for testing.
>
> hmm, i thought i wanted edsquery to give a list of strings.
> i have the following trivial code which is still giving the
> same kind of error, and i think probably illustrates my
> conceptual error, whatever it is:
<snipped>
See above. a function as the COLLECTION argument is a special case. In that
case, `completing-read' is not expecting the function to return a set of
completion candidates; it is expecting it to perform completion - completely.
;-)
> clearly i'm misunderstanding something but it's the kind of
> conceptual error i have trouble finding an answer for in the
> documentation.
Study node `Programmed Completion' in the manual carefully. If you then have
questions, post again here.
But if you can produce the set of completion candidates you need, then you
likely do not need to worry about programmed completion (i.e. a functional
COLLECTION arg) - just provide the list of candidates. Programmed completion is
for situations where you cannot do that - where, for instance, such a list
depends on something contingent that only becomes available during the
completion process itself.
Bottom line: If you can give `completing-read' the list of candidates to use, do
so.
> thanks again. you should feel free to drop me, though, drew -- i
> appreciate all your efforts.
Don't sell yourself short. _IF_ you need programmed completion, then yes, it is
a bit confusing, but node `Programmed Completion' is your friend. _IF_ you don't
need it, that is, if you can come up with the list of completion candidates you
need explicitly, then just do that.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-11-22 21:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19 16:16 pymacs & interactivel isp functions Matt Price
2008-11-19 17:37 ` Drew Adams
2008-11-22 8:39 ` Matt Price
2008-11-22 15:27 ` Kevin Rodgers
2008-11-22 15:27 ` Drew Adams
2008-11-22 21:07 ` Matt Price
2008-11-22 21:45 ` Drew Adams
[not found] <mailman.747.1227111401.26697.help-gnu-emacs@gnu.org>
2008-11-20 19:48 ` Greg Detre
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.