all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* starting an external command from emacs
@ 2008-11-12 19:59 Matt Price
  2008-11-13  0:17 ` Andy Stewart
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Price @ 2008-11-12 19:59 UTC (permalink / raw)
  To: help-gnu-emacs

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!!

matt



-- 
Matt Price
matt.price@utoronto.ca




^ permalink raw reply	[flat|nested] 9+ 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 ` 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; 9+ 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] 9+ messages in thread

* Re: starting an external command from emacs
  2008-11-12 19:59 starting an external command from emacs Matt Price
@ 2008-11-13  0:17 ` Andy Stewart
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Stewart @ 2008-11-13  0:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, Matt!

I recommend you use GNUS, it's more powerful and integration closer with 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:
>
> (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!!
>
> matt





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

* Re: starting an external command from emacs
  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>
  1 sibling, 0 replies; 9+ 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] 9+ messages in thread

* 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; 9+ 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] 9+ 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 ` Dan Espen
@ 2008-11-13 15:50 ` Xah
  2008-11-14 15:33   ` Matt Price
       [not found]   ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 9+ 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] 9+ messages in thread

* Re: starting an external command from emacs
  2008-11-13 15:50 ` Xah
@ 2008-11-14 15:33   ` Matt Price
       [not found]   ` <mailman.365.1226676836.26697.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2008-11-14 20:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 19:59 starting an external command from emacs Matt Price
2008-11-13  0:17 ` Andy Stewart
     [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 13:54     ` Dan Espen
2008-11-13 15:50 ` Xah
2008-11-14 15:33   ` 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

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.