* Re: starting an external command from emacs [not found] <mailman.201.1226528857.26697.help-gnu-emacs@gnu.org> @ 2008-11-12 23:08 ` Dan Espen 2008-11-13 3:48 ` Matt Price [not found] ` <mailman.217.1226563070.26697.help-gnu-emacs@gnu.org> 2008-11-13 15:50 ` Xah 1 sibling, 2 replies; 16+ messages in thread From: Dan Espen @ 2008-11-12 23:08 UTC (permalink / raw) To: help-gnu-emacs Matt Price <matt.price@utoronto.ca> writes: > hi, > > i'm a not-especially-technical person who uses emacs as a > straightforward text editor; in fact i'm experimenting with living > inside emacs most of the time on my main laptop, largely to eliminate > distractions while i'm writing. however, some significant fraction of > the stuff i write is intended to be emailed away. I'd like to do two > things: > > (1) write a function that takes the contents of the current buffer and > inserts it into a message; > (2) use an external script to query an already-existing contacts > database (for me it's evolution or gmail), and pass that address on to > the to-header of the resultant message. > > (2) seemed difficult to me. so what i'm trying right now is to write a > function that invokes mutt with an address string, then, within mutt, > use emacsclient as my editor, post-mode as my mode, and insert the text > into the message body. This is what i have so far: Have you looked at VM, MH-E, rmail, GNUS? (Existing Emacs mail interfaces.) ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: starting an external command from emacs 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> 1 sibling, 0 replies; 16+ messages in thread From: Matt Price @ 2008-11-13 3:48 UTC (permalink / raw) To: Dan Espen; +Cc: help-gnu-emacs On Wed, 2008-11-12 at 18:08 -0500, Dan Espen wrote: > Matt Price <matt.price@utoronto.ca> writes: > > > hi, > > > > i'm a not-especially-technical person who uses emacs as a > > straightforward text editor; in fact i'm experimenting with living > > inside emacs most of the time on my main laptop, largely to eliminate > > distractions while i'm writing. however, some significant fraction of > > the stuff i write is intended to be emailed away. I'd like to do two > > things: > > > > (1) write a function that takes the contents of the current buffer and > > inserts it into a message; > > (2) use an external script to query an already-existing contacts > > database (for me it's evolution or gmail), and pass that address on to > > the to-header of the resultant message. > > > > (2) seemed difficult to me. so what i'm trying right now is to write a > > function that invokes mutt with an address string, then, within mutt, > > use emacsclient as my editor, post-mode as my mode, and insert the text > > into the message body. This is what i have so far: > > Have you looked at VM, MH-E, rmail, GNUS? > (Existing Emacs mail interfaces.) hi dan, i did look briefly at all of these, but two issues for me: - all of them feel a little daunting - one of my problems right now is that my contacts info is spread out in far too many places already -- mutt, evolution, and gmail, not to mention my unsyncable palm. i'd really like to be able to query these databases directly -- mutt has various scripts that let you do this, which is why i was drawn to it. these scripts generally produce a series of lines as output, one email address per line. if i could write a function that ran these ecternal scripts and took their output as a list, from which the user could choose one as a to address... then i'd certainly be willingt o use any of the already-existant emacs mail readers. the thing is, of course, that i'm really NOT looking to read my mail -- i'm trying to avoid making that any easier -- all i want to do is send my mail, and be able to use my contacts database from inside emacs. what woul you suggest i do? thanks, matt -- Matt Price matt.price@utoronto.ca ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <mailman.217.1226563070.26697.help-gnu-emacs@gnu.org>]
* Re: starting an external command from emacs [not found] ` <mailman.217.1226563070.26697.help-gnu-emacs@gnu.org> @ 2008-11-13 13:54 ` Dan Espen 0 siblings, 0 replies; 16+ messages in thread From: Dan Espen @ 2008-11-13 13:54 UTC (permalink / raw) To: help-gnu-emacs Matt Price <matt.price@utoronto.ca> writes: > On Wed, 2008-11-12 at 18:08 -0500, Dan Espen wrote: >> Matt Price <matt.price@utoronto.ca> writes: ... >> Have you looked at VM, MH-E, rmail, GNUS? >> (Existing Emacs mail interfaces.) > > hi dan, > > i did look briefly at all of these, but two issues for me: > > - all of them feel a little daunting I find MH-E to be very simple. The way mh keeps each email in a separate file is a bonus. I've configured mh-e to use lynx to convert all the HTML email I get to plain text which helps being able to copy paste plain text. VM looks to me like it's better supported with more features but I've never tried it. GNUS strays from a traditional interface (IMO) so I've never gotten comfortable with it. > - one of my problems right now is that my contacts info is spread out in > far too many places already -- mutt, evolution, and gmail, not to MH-E provides tab completion for mh aliases. If you take your database and put it in .mh_aliases in this format: user_name1: email_addr1 user_name2: email_addr2 you can start typing the user_name, hit tab and see the completions. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: starting an external command from emacs [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 15:50 ` Xah 2008-11-14 13:24 ` break a chunk of text into a list of lines Matt Price ` (3 more replies) 1 sibling, 4 replies; 16+ messages in thread From: Xah @ 2008-11-13 15:50 UTC (permalink / raw) To: help-gnu-emacs On Nov 12, 11:59 am, Matt Price <matt.pr...@utoronto.ca> wrote: > hi, > > i'm a not-especially-technical person who uses emacs as a > straightforward text editor; in fact i'm experimenting with living > inside emacs most of the time on my main laptop, largely to eliminate > distractions while i'm writing. however, some significant fraction of > the stuff i write is intended to be emailed away. I'd like to do two > things: > > (1) write a function that takes the contents of the current buffer and > inserts it into a message; > (2) use an external script to query an already-existing contacts > database (for me it's evolution or gmail), and pass that address on to > the to-header of the resultant message. > > (2) seemed difficult to me. so what i'm trying right now is to write a > function that invokes mutt with an address string, then, within mutt, > use emacsclient as my editor, post-mode as my mode, and insert the text > into the message body. This is what i have so far: > > (defun start-mutt-with-this-buffer-contents (address) > (mark-whole-buffer) > (kill-ring-save) ;; ok this needs a beginning and end but i don't know how to do that > (interactive "M") ;; i think that's right > (set-buffer (apply 'make-term "Mutt" "mutt" nil (list address))) > (switch-to-buffer "*Mutt*") > ;; need some kind of "wait for mutt to start composing" thing here > (post-goto-body) > (yank) > ) > > the problem with this right now is that the (yank) occurs too early, and > the yanked text appears in the *Mutt* window, instead of the *Composing* > window where i want it to appear. is there a way to tell emacs to wait > on mutt till the interactive command is finished, then switch tothe > composing buffer and paste the text in there? or failing that -- how > might i query an external database from within emacs? if i could do > that, then i guess i could use one of the many already-existing emacs > mail modes to actually send the message, and provide it with the the > query result as a to-address. i have, for instance, a couple of python > scripts that return a sequence of lines, one email address per line -- > these are designed for use with mutt -- i guess one could put them into > some kind of minibuffer that would then feed the appropriate choice back > to an emacs function. i just don't know how to do that kind of stuff > myself. > > Thanks in advance for your help!! Can you make your question into one specific question? if you can make just one specific question, as much as possible to your problem, it's likely to get much useful replies. from scanning several replies, here's what i think might be helpful. i used vm and rmail from about 1999 to 2000. vm was much feature rich than rmail, and i suppose it still is. I have tried gnus during the time but find it hard to learn. (i've also used mutt, unix command line mail, mh, pine, in the past 10 years, typically each i have used for a few months. I've stopped using any text based email client since about 2003.) if you want to write elisp to call some other script and process the result, it's fairly easy. If you can be specific about what command you want to call and how you want to parse the result, we can help better. The following tutorial will probably help: • Elisp Wrapper For Perl Scripts http://xahlee.org/emacs/elisp_perl_wrapper.html (you can use your existing knowledge of a scripting lang and turn them into elisp command) • Elisp Lesson: Writing image-linkify Function http://xahlee.org/emacs/elisp_image_tag.html (contains example of calling external script and process its result) Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 16+ messages in thread
* break a chunk of text into a list of lines 2008-11-13 15:50 ` Xah @ 2008-11-14 13:24 ` Matt Price 2008-11-14 15:33 ` starting an external command from emacs Matt Price ` (2 subsequent siblings) 3 siblings, 0 replies; 16+ messages in thread From: Matt Price @ 2008-11-14 13:24 UTC (permalink / raw) To: Xah; +Cc: help-gnu-emacs On Thu, 2008-11-13 at 07:50 -0800, Xah wrote: > Can you make your question into one specific question? > > if you can make just one specific question, as much as possible to > your problem, it's likely to get much useful replies. > > from scanning several replies, here's what i think might be helpful. > > if you want to write elisp to call some other script and process the > result, it's fairly easy. If you can be specific about what command > you want to call and how you want to parse the result, we can help > better. > > The following tutorial will probably help: > > • Elisp Wrapper For Perl Scripts > http://xahlee.org/emacs/elisp_perl_wrapper.html > (you can use your existing knowledge of a scripting lang and turn them > into elisp command) > > • Elisp Lesson: Writing image-linkify Function > http://xahlee.org/emacs/elisp_image_tag.html > (contains example of calling external script and process its result) > Xah, thanks for the helpful links -- also thanks to other folks who have been helping on this thread. I think i have two questions, so i'll write them in two seperate emails. I have a python script that queries my evolution database and returns a series of lines, with one address per line: matt@gont:~$ python evo-query.py matt 14 matches in 874 entries matt@mdke.org Matthew East matt.price@utoronto.ca Matt Price moptop99@gmail.com Matt Price mdz@canonical.com Matt Zimmerman Matty_fontaine@hotmail.com Matt Fontaine matt.price@utoronto.ca Matt Price mjg59@srcf.ucam.org Matthew Garrett myatesmyates@yahoo.com Matthew Yates matthias.doerries@gersulp.u-strasbg.fr Matthias Dörries matthew.flaschen@gatech.edu Matthew Flaschen mcdavey@mrao.cam.ac.uk Matt Davey matt@madhaus.cns.utoronto.ca Matt Wilks MattVermeulen@gmail.com Matthew Vermeulen matthewreedy@yahoo.com matthewreedy (note the not-so-well-maintained duplicates!) i've written a short function based on one of your examples that grabs this output -- i imagine it needs some fixing up, but here it is: (defun query-python-addressbook (name) (interactive "s To:" ) (setq cmd-name "python /home/matt/evo-query.py") (setq sh-output (shell-command-to-string (concat cmd-name " " name))) (message "%s" sh-output) ) (query-python-addressbook "matt") now returns a message with the this text. instead i'd like it to return a list of names. i'm sure someone will point me to the right info node, but i'm having some difficulty navigating the immense amounts of documentation -- is there a simple way to take each line of a text block and turn it into a list of lines? thanks much! -- second quesiton to follow... matt > Xah > ∑ http://xahlee.org/ > > ☄ -- Matt Price matt.price@utoronto.ca ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: starting an external command from emacs 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 ` Matt Price [not found] ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org> [not found] ` <mailman.359.1226672766.26697.help-gnu-emacs@gnu.org> 3 siblings, 0 replies; 16+ messages in thread From: Matt Price @ 2008-11-14 15:33 UTC (permalink / raw) To: Xah; +Cc: help-gnu-emacs On Thu, 2008-11-13 at 07:50 -0800, Xah wrote: > if you want to write elisp to call some other script and process the > result, it's fairly easy. If you can be specific about what command > you want to call and how you want to parse the result, we can help > better. here's my second question: given a list like this '( "matt@mdke.org Matthew East" "matt.price@utoronto.ca Matt Price "matthias.doerries@gersulp.u-strasbg.fr Matthias Dörries" "matthewreedy@yahoo.com matthewreedy" ) how to i tell emacs i want to use the list elements as choices for tab-completion in an interactive function? so if i have a function like this: (defun query-python-addressbook (name) (interactive "s To:" ) (setq cmd-name "python /home/matt/evo-query.py") ;; imagine sh-output generates a list -- see my last email in this thread (setq sh-output (shell-command-to-string (concat cmd-name " " name))) ) can I write another couple of lines that presents the items in the list as choices to the user, who then picks one? that'd be really great. that's about as far as i can get so far. thanks again! matt -- Matt Price matt.price@utoronto.ca ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org>]
* Re: starting an external command from emacs [not found] ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org> @ 2008-11-14 19:43 ` Xah 2008-11-14 20:31 ` Andreas Politz 1 sibling, 0 replies; 16+ messages in thread From: Xah @ 2008-11-14 19:43 UTC (permalink / raw) To: help-gnu-emacs On Nov 14, 7:33 am, Matt Price <matt.pr...@utoronto.ca> wrote: > given a list like this > '( > "m...@mdke.org Matthew East" > "matt.pr...@utoronto.ca Matt Price > "matthias.doerr...@gersulp.u-strasbg.fr Matthias Dörries" > "matthewre...@yahoo.com matthewreedy" > ) > > how to i tell emacs i want to use the list elements as choices for > tab-completion in an interactive function? i think basically you want to write a completion function. I don't know the answer. I'm currently trying to study this. You can read about try-completion. (type Alt+x elisp-index-search, then try-completion, will get you to the right manual location) The functions there are rather low level. I don't think it's easy. You can lookup existing code. Try type Ctrl+h f, then lisp-complete- symbol. Click on the source link in the result will take you to the source code on this function. Similarly, you can look at python- complete-symbol and other lang's implementation. They are about less than 100 lines of code each, but involves quite a few knowledge about buffers, emacs “windows”, etc. > can I write another couple of lines that presents the items in the list > as choices to the user, who then picks one? that'd be really great. I think you are asking for a contextual menu. Flyspell provides that when middle clicking on the highlighted word. Sorry, i haven't studied contextual menu neither. you can look at how flyspell does it by Alt+x flyspell-buffer. Then, type Ctrl+h v, then middle click on a highlighted word. Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: starting an external command from emacs [not found] ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org> 2008-11-14 19:43 ` Xah @ 2008-11-14 20:31 ` Andreas Politz 1 sibling, 0 replies; 16+ messages in thread From: Andreas Politz @ 2008-11-14 20:31 UTC (permalink / raw) To: help-gnu-emacs Matt Price wrote: > On Thu, 2008-11-13 at 07:50 -0800, Xah wrote: > >> if you want to write elisp to call some other script and process the >> result, it's fairly easy. If you can be specific about what command >> you want to call and how you want to parse the result, we can help >> better. > > here's my second question: > > given a list like this > '( > "matt@mdke.org Matthew East" > "matt.price@utoronto.ca Matt Price > "matthias.doerries@gersulp.u-strasbg.fr Matthias Dörries" > "matthewreedy@yahoo.com matthewreedy" > ) > > how to i tell emacs i want to use the list elements as choices for > tab-completion in an interactive function? so if i have a function like > this: > > > (defun query-python-addressbook (name) ;;(interactive "s To:" ) (interactive (list (completing-read "Name : " ;;or ido-completing-read '("your" "list") nil t))) > (setq cmd-name "python /home/matt/evo-query.py") > ;; imagine sh-output generates a list -- see my last email in this > thread > (setq sh-output (shell-command-to-string (concat cmd-name " " name))) > > ) > can I write another couple of lines that presents the items in the list > as choices to the user, who then picks one? that'd be really great. > > that's about as far as i can get so far. thanks again! > > matt > -ap ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <mailman.359.1226672766.26697.help-gnu-emacs@gnu.org>]
* Re: break a chunk of text into a list of lines [not found] ` <mailman.359.1226672766.26697.help-gnu-emacs@gnu.org> @ 2008-11-14 19:33 ` Xah 2008-11-14 20:43 ` Andreas Politz 1 sibling, 0 replies; 16+ messages in thread From: Xah @ 2008-11-14 19:33 UTC (permalink / raw) To: help-gnu-emacs On Nov 14, 5:24 am, Matt Price <matt.pr...@utoronto.ca> wrote: > I have a python script that queries my evolution database and returns a > series of lines, with one address per line: > > ... > > is there a simple way > to take each line of a text block and turn it into a list of lines? if your text is already a string, then you can use split-string to turn it into a list, by using “\n” as separator. You can turn a block of text into a string by using buffer-substring- no-properties. alternatively, the following i wrote in my early lisp day that does what you want. I still use it. (defun grab-lines (n) "Delete the next n lines and return a list where each element is a line." (interactive) (move-beginning-of-line 1) (let (t1 t2 cl (lines '())) (dotimes (x n) (progn (setq t1 (point)) (move-end-of-line nil) (setq t2 (point)) (setq cl (buffer-substring-no-properties t1 t2)) (delete-region t1 t2) (delete-char 1) (push cl lines) ) ) (setq lines (reverse lines)) ; (prin1 lines (current-buffer)) )) for some detail about this code, see: • Elisp Lesson: Writing a google-earth Function http://xahlee.org/emacs/google-earth.html Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: break a chunk of text into a list of lines [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 ` interactive function: generate tab-completion list with another function Matt Price 1 sibling, 1 reply; 16+ messages in thread From: Andreas Politz @ 2008-11-14 20:43 UTC (permalink / raw) To: help-gnu-emacs Matt Price wrote: > On Thu, 2008-11-13 at 07:50 -0800, Xah wrote: > >> Can you make your question into one specific question? >> >> if you can make just one specific question, as much as possible to >> your problem, it's likely to get much useful replies. >> >> from scanning several replies, here's what i think might be helpful. >> >> if you want to write elisp to call some other script and process the >> result, it's fairly easy. If you can be specific about what command >> you want to call and how you want to parse the result, we can help >> better. >> >> The following tutorial will probably help: >> >> • Elisp Wrapper For Perl Scripts >> http://xahlee.org/emacs/elisp_perl_wrapper.html >> (you can use your existing knowledge of a scripting lang and turn them >> into elisp command) >> >> • Elisp Lesson: Writing image-linkify Function >> http://xahlee.org/emacs/elisp_image_tag.html >> (contains example of calling external script and process its result) >> > > Xah, > > thanks for the helpful links -- also thanks to other folks who have been > helping on this thread. I think i have two questions, so i'll write > them in two seperate emails. > > I have a python script that queries my evolution database and returns a > series of lines, with one address per line: > > matt@gont:~$ python evo-query.py matt > 14 matches in 874 entries > matt@mdke.org Matthew East > matt.price@utoronto.ca Matt Price > moptop99@gmail.com Matt Price > mdz@canonical.com Matt Zimmerman > Matty_fontaine@hotmail.com Matt Fontaine > matt.price@utoronto.ca Matt Price > mjg59@srcf.ucam.org Matthew Garrett > myatesmyates@yahoo.com Matthew Yates > matthias.doerries@gersulp.u-strasbg.fr Matthias Dörries > matthew.flaschen@gatech.edu Matthew Flaschen > mcdavey@mrao.cam.ac.uk Matt Davey > matt@madhaus.cns.utoronto.ca Matt Wilks > MattVermeulen@gmail.com Matthew Vermeulen > matthewreedy@yahoo.com matthewreedy > > (note the not-so-well-maintained duplicates!) > > i've written a short function based on one of your examples that grabs > this output -- i imagine it needs some fixing up, but here it is: > (defun query-python-addressbook (name) > (interactive "s To:" ) > (setq cmd-name "python /home/matt/evo-query.py") > (setq sh-output (shell-command-to-string (concat cmd-name " " name))) > (message "%s" sh-output) > ) > > (query-python-addressbook "matt") now returns a message with the this > text. instead i'd like it to return a list of names. i'm sure someone > will point me to the right info node, but i'm having some difficulty > navigating the immense amounts of documentation -- is there a simple way > to take each line of a text block and turn it into a list of lines? > > thanks much! -- second quesiton to follow... > > matt > 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. -ap ^ permalink raw reply [flat|nested] 16+ messages in thread
* interactive function: generate tab-completion list with another function 2008-11-14 20:43 ` Andreas Politz @ 2008-11-15 16:35 ` Matt Price 2008-11-16 3:42 ` syntax: anonymous vs. named functions Matt Price 0 siblings, 1 reply; 16+ messages in thread From: Matt Price @ 2008-11-15 16:35 UTC (permalink / raw) To: Andreas Politz; +Cc: help-gnu-emacs, Xah 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 ^ permalink raw reply [flat|nested] 16+ messages in thread
* syntax: anonymous vs. named functions 2008-11-15 16:35 ` interactive function: generate tab-completion list with another function Matt Price @ 2008-11-16 3:42 ` Matt Price 2008-11-16 8:01 ` Drew Adams 0 siblings, 1 reply; 16+ messages in thread From: Matt Price @ 2008-11-16 3:42 UTC (permalink / raw) To: matt.price; +Cc: help-gnu-emacs I have working code for my tab-completion problem (again thanks to everyone for answering my painfully stupid questions). i don't understand, though, why attempts to write my function as an unnamed lambda fails, but the same function succeeds when named. the "lambda" line commented out in tab-complete-from-function below returns an error "test-completion: Invalid function", while the uncommented call to a different, trivial function is successful. cna anyone advise me why? thanks much! matt (defun tab-complete-from-function (stub) "very simple tab completion function" (interactive (list (completing-read "Name: " ;; (lambda (string) (split-string (shell-command-to-string (concat "/home/matt/mutt-eds-query " string)) "\n" t)) (do-completion (string)) nil t))) (message stub)) (defun do-completion (stub) "minimal function" (split-string (shell-command-to-string (concat "/home/matt/mutt-eds-query " stub)) "\n" t)) > > -ap -- Matt Price matt.price@utoronto.ca ^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: syntax: anonymous vs. named functions 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 0 siblings, 1 reply; 16+ messages in thread From: Drew Adams @ 2008-11-16 8:01 UTC (permalink / raw) To: 'Matt Price'; +Cc: help-gnu-emacs > I have working code for my tab-completion problem (again thanks to > everyone for answering my painfully stupid questions). i don't > understand, though, why attempts to write my function as an unnamed > lambda fails, but the same function succeeds when named. the "lambda" > line commented out in tab-complete-from-function below > returns an error > "test-completion: Invalid function", while the uncommented call to a > different, trivial function is successful. cna anyone advise me why? > thanks much! > > (defun tab-complete-from-function (stub) > "very simple tab completion function" > (interactive (list (completing-read "Name: " > ;; (lambda (string) > (split-string (shell-command-to-string (concat > "/home/matt/mutt-eds-query " string)) "\n" t)) > (do-completion (string)) > nil t))) > (message stub)) > > > (defun do-completion (stub) > "minimal function" > (split-string (shell-command-to-string (concat > "/home/matt/mutt-eds-query " stub)) "\n" t)) (do-completion string) is not a function. It is a function application, and its value is a list of strings. The lambda form is a function. To use a function as the `completing-read' COLLECTION argument, the function must take the right (three) arguments and return the right values. See the doc for a description of the kind of function that is needed. ^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: syntax: anonymous vs. named functions 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> 0 siblings, 2 replies; 16+ messages in thread From: Matt Price @ 2008-11-16 15:48 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs On Sun, 2008-11-16 at 00:01 -0800, Drew Adams wrote: > > I have working code for my tab-completion problem (again thanks to > > everyone for answering my painfully stupid questions). i don't > > understand, though, why attempts to write my function as an unnamed > > lambda fails, but the same function succeeds when named. the "lambda" > > line commented out in tab-complete-from-function below > > returns an error > > "test-completion: Invalid function", while the uncommented call to a > > different, trivial function is successful. cna anyone advise me why? > > thanks much! > > > > (defun tab-complete-from-function (stub) > > "very simple tab completion function" > > (interactive (list (completing-read "Name: " > > ;; (lambda (string) > > (split-string (shell-command-to-string (concat > > "/home/matt/mutt-eds-query " string)) "\n" t)) > > (do-completion (string)) > > nil t))) > > (message stub)) > > > > > > (defun do-completion (stub) > > "minimal function" > > (split-string (shell-command-to-string (concat > > "/home/matt/mutt-eds-query " stub)) "\n" t)) > > (do-completion string) is not a function. It is a function application, and its > value is a list of strings. The lambda form is a function. > > To use a function as the `completing-read' COLLECTION argument, the function > must take the right (three) arguments and return the right values. See the doc > for a description of the kind of function that is needed. > thanks for the pointer -- i had looked at the docstrings but not really read the programmed completion node of the info manual. i see this: ---------- It would be consistent and clean for completion functions to allow lambda expressions (lists that are functions) as well as function symbols as COLLECTION, but this is impossible. ---------- not sure if that's exactly what you meant but it's enough to make me stop working in that direction... thanks, matt ps, does the collection function really need to accept all three arguments (string, predicate and t/nil/lambda)? i know you say that (do-completion (string)) is a function application, but what would a function look like in this case? just like this: do-completion (that is, a simple evaluated symbol)? > -- Matt Price matt.price@utoronto.ca ^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: syntax: anonymous vs. named functions 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> 1 sibling, 0 replies; 16+ messages in thread From: Drew Adams @ 2008-11-17 1:06 UTC (permalink / raw) To: 'Matt Price'; +Cc: help-gnu-emacs > thanks for the pointer -- i had looked at the docstrings but > not really read the programmed completion node of the info manual. > i see this: > ---------- > It would be consistent and clean for completion functions to allow > lambda expressions (lists that are functions) as well as function > symbols as COLLECTION, but this is impossible. > ---------- > not sure if that's exactly what you meant but it's enough to make me > stop working in that direction... thanks, matt No, actually I had forgotten that a lambda form was not accepted as a function here. ;-) My point was that a lambda form is a function, whereas (do-completion (string)) is a list of strings - that is, it returns such a list. `completing-read' lets you provide, as the COLLECTION argument, either (1) an explicit set of completion candidates, as a list of strings, an alist, an obarray, or a hash table or (2) an implicit set of candidates: a function of three arguments that does everything. (do-completion (string)) is case #1. A lambda form is case #2 (though, as you pointed out, a lambda form is not accepted as the functional arg). The reason that a lambda form is not allowed as a functional COLLECTION argument is that although a lambda form can generally be used as a function, it _evaluates_ to a list (whose car is `lambda' etc. - that is, to itself). And since COLLECTION can also be an explicit list of candidates, it would be problematic to distinguish the intention of passing an argument whose value is a list that has the form (lambda (...) ...). This is a feature of Lisp's program=data quality. > ps, does the collection function really need to accept all three > arguments (string, predicate and t/nil/lambda)? Yes. It need not _use_ all three, or even any of them, to do its job, but it must accept three arguments. The primitive Emacs completion functions depend on it having such a signature. > i know you say that > (do-completion (string)) is a function application, but what would a > function look like in this case? just like this: do-completion (that > is, a simple evaluated symbol)? Correct. You would pass the function `do-completion' this way: (completing-read "Name: " #'do-completion nil t) ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <mailman.552.1226883997.26697.help-gnu-emacs@gnu.org>]
* Re: syntax: anonymous vs. named functions [not found] ` <mailman.552.1226883997.26697.help-gnu-emacs@gnu.org> @ 2008-11-17 8:08 ` Andreas Politz 0 siblings, 0 replies; 16+ messages in thread From: Andreas Politz @ 2008-11-17 8:08 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: [...] > > The reason that a lambda form is not allowed as a functional COLLECTION argument > is that although a lambda form can generally be used as a function, it > _evaluates_ to a list (whose car is `lambda' etc. - that is, to itself). > > And since COLLECTION can also be an explicit list of candidates, it would be > problematic to distinguish the intention of passing an argument whose value is a > list that has the form (lambda (...) ...). This is a feature of Lisp's > program=data quality. Mhh, more likely a problem of elisp. CL-USER> (functionp #'(lambda nil)) T CL-USER> (functionp '(lambda nil)) NIL In elisp both expressions evaluate as T. I like the CL feature better ;) -ap > >> ps, does the collection function really need to accept all three >> arguments (string, predicate and t/nil/lambda)? > > Yes. It need not _use_ all three, or even any of them, to do its job, but it > must accept three arguments. The primitive Emacs completion functions depend on > it having such a signature. > >> i know you say that >> (do-completion (string)) is a function application, but what would a >> function look like in this case? just like this: do-completion (that >> is, a simple evaluated symbol)? > > Correct. You would pass the function `do-completion' this way: > > (completing-read "Name: " #'do-completion nil t) > > > ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2008-11-17 8:08 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [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.365.1226676836.26697.help-gnu-emacs@gnu.org> 2008-11-14 19:43 ` Xah 2008-11-14 20:31 ` Andreas Politz [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 ` interactive function: generate tab-completion list with another function Matt Price 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
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).