unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Matt Price <matt.price@utoronto.ca>
To: Andreas Politz <politza@fh-trier.de>
Cc: help-gnu-emacs@gnu.org, Xah <xahlee@gmail.com>
Subject: interactive function: generate tab-completion list with another function
Date: Sat, 15 Nov 2008 11:35:56 -0500	[thread overview]
Message-ID: <1226766956.4606.4915.camel@localhost> (raw)
In-Reply-To: <1226695506.850373@arno.fh-trier.de>

On Fri, 2008-11-14 at 21:43 +0100, Andreas Politz wrote:

> 
> As Xah pointed out `split-string' is the way to go. Btw `cmd-name' and `sh-output'
> will become global variables with your code. I doubt that's what you want. Better use
> let-forms.
> 
> (defun query-python-addressbook (name)
>      (interactive "s To:")
>      (let ((cmd-name "python /home/matt/evo-query.py"))
>           (split-string (shell-command-to-string (concat cmd-name " " name)) "\n" t)))
> 
> 
> In this case the variable is probably superficial anyway.
xah and andreas,

thank you both.  andreas, this does seem to be more or less exactly what
i was really trying to do.  though the answers you and Xah give to the
other part of my query suggest i have some work to do still.  

What i now want to do:  pass the user input to a function in order to
generate the tab-completion list.  the documentation for try-completion
suggests this is possible:
---------------
(try-completion string collection &optional predicate)

Return common substring of all completions of string in collection.
Test each possible completion specified by collection
to see if it begins with string.  The possible completions may be
strings or symbols.  Symbols are converted to strings before testing,
see `symbol-name'.
...
collection can also be a function to do the completion itself.
It receives three arguments: the values string, predicate and nil.
Whatever it returns becomes the value of `try-completion'.
-------------

i guess i just don't understand the syntax to use whn making
"collection" into a function.  i have the following code which doesn't
work but i think gives a sense of what i'm going for.  i now feelthat
this is possible but i'm at a loss as to how to do it:

(defun query-python-addressbook (stub)
   "interactive tab-completing query of addressbook"
   (interactive (list "s Name: " (try-completion string (do-python-query(string))
))))


(defun do-python-query (stub)
      (let ((cmd-name "python /home/matt/evo-query.py"))
          (split-string (shell-command-to-string (concat cmd-name " " stub)) "\n" t)))

the current error i'm getting is:
list: Wrong type argument: stringp, [followed by the long list of
alternatives i'm generating]

anyway i know these are stupid syntax problems that i ought to pick up
by picking the manual, but i seem to be particularly dense on this kind
of issue.  can you guys help me out?  thanks a lot!

matt




> 
> -ap
-- 
Matt Price
matt.price@utoronto.ca




  reply	other threads:[~2008-11-15 16:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.201.1226528857.26697.help-gnu-emacs@gnu.org>
2008-11-12 23:08 ` starting an external command from emacs Dan Espen
2008-11-13  3:48   ` Matt Price
     [not found]   ` <mailman.217.1226563070.26697.help-gnu-emacs@gnu.org>
2008-11-13 13:54     ` Dan Espen
2008-11-13 15:50 ` Xah
2008-11-14 13:24   ` break a chunk of text into a list of lines Matt Price
2008-11-14 15:33   ` starting an external command from emacs Matt Price
     [not found]   ` <mailman.359.1226672766.26697.help-gnu-emacs@gnu.org>
2008-11-14 19:33     ` break a chunk of text into a list of lines Xah
2008-11-14 20:43     ` Andreas Politz
2008-11-15 16:35       ` Matt Price [this message]
2008-11-16  3:42         ` syntax: anonymous vs. named functions Matt Price
2008-11-16  8:01           ` Drew Adams
2008-11-16 15:48             ` Matt Price
2008-11-17  1:06               ` Drew Adams
     [not found]               ` <mailman.552.1226883997.26697.help-gnu-emacs@gnu.org>
2008-11-17  8:08                 ` Andreas Politz
     [not found]   ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org>
2008-11-14 19:43     ` starting an external command from emacs Xah
2008-11-14 20:31     ` Andreas Politz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1226766956.4606.4915.camel@localhost \
    --to=matt.price@utoronto.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=politza@fh-trier.de \
    --cc=xahlee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).