unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* An easy defun
@ 2007-10-07 21:51 Sven Bretfeld
  2007-10-08  0:53 ` Amy Templeton
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Bretfeld @ 2007-10-07 21:51 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 335 bytes --]

Hello to all

I'm still a complete newbie when it comes to defining own
functions. I want to define a funtion called start-mutt, which does:

- open an ansi term

- rename it to *Mutt*

- start Mutt within the ansi-term

- if the ansi-term already exists and has Mutt running, switch to that
buffer

Can anybody help me?

Thanks

Sven

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: An easy defun
  2007-10-07 21:51 An easy defun Sven Bretfeld
@ 2007-10-08  0:53 ` Amy Templeton
  2007-10-08 19:25   ` Sven Bretfeld
  0 siblings, 1 reply; 3+ messages in thread
From: Amy Templeton @ 2007-10-08  0:53 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 2156 bytes --]

Sven Bretfeld <sven.bretfeld@gmx.ch> wrote:
> I want to define a funtion called start-mutt, which does:

> - open an ansi term

> - rename it to *Mutt*

> - start Mutt within the ansi-term

> - if the ansi-term already exists and has Mutt running, switch to that
> buffer

> Can anybody help me?

Perhaps something like this? Substitute the correct path to your mutt in the
second-to-last line.

(defun start-mutt (&optional bg)
  "Start an ansi-term running the mutt mailreader, in a buffer called \"*Mutt*\"
Given an argument (assuming the buffer called \"*Mutt*\" doesn't already exist),
will start in the background"
  (interactive "P")
  (if (get-buffer "*Mutt*")
      (switch-to-buffer "*Mutt*")
    (let ((buf (current-buffer)))
      (ansi-term "/usr/bin/mutt" "Mutt")
      (if bg (switch-to-buffer buf)))))

Some useful information to know in the future:

- Press "C-h f ansi-term" to read the documentation for the function
  ansi-term (or substitute some other function you're curious about), a
  function I had never used previously but which I found out takes two
  arguments:  the program to run and the name of the buffer, to which it
  will pre-pend and append asterices.

- Most of the time you won't use (switch-to-buffer) in elisp programs (see
  its documentation, as above).

- (interactive) can be called with a wide array of arguments; see its
  documentation for more information.

- Consider checking out the Emacs Lisp Intro., which if you're running a
  recent emacs I'm pretty sure should be included.

- Try to go through this code and understand it, one step at a time.

Anyway, I hope that's helpful.

Amy

-- 
   "The History of every major Galactic Civilization tends to pass through
three distinct and recognizable phases, those of Survival, Inquiry and
Sophistication, otherwise known as the How, Why and Where phases.
   "For instance, the first phase is characterized by the question 'How can
we eat?' the second by the question 'Why do we eat?' and the third by the
question 'Where shall we have lunch?'"
                -- Hitchhiker's Guide to the Galaxy

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: An easy defun
  2007-10-08  0:53 ` Amy Templeton
@ 2007-10-08 19:25   ` Sven Bretfeld
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Bretfeld @ 2007-10-08 19:25 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1066 bytes --]

Hello list, dear Amy

I don't understand it. I wrote an answer this noon, and it still
hasn't arrived on the list.

On Sun, Oct 07, 2007 at 08:53:53PM -0400, Amy Templeton wrote:
> 
> (defun start-mutt (&optional bg)
>   "Start an ansi-term running the mutt mailreader, in a buffer called \"*Mutt*\"
> Given an argument (assuming the buffer called \"*Mutt*\" doesn't already exist),
> will start in the background"
>   (interactive "P")
>   (if (get-buffer "*Mutt*")
>       (switch-to-buffer "*Mutt*")
>     (let ((buf (current-buffer)))
>       (ansi-term "/usr/bin/mutt" "Mutt")
>       (if bg (switch-to-buffer buf)))))

This works perfectly. Thank you very much.

> - Try to go through this code and understand it, one step at a time.

That's what I did today. And I was able to write some other functions
according to your model. 
> 
> Anyway, I hope that's helpful.

Yes, you brought me a great step further to understand lisp. I know
this is quite an easy code. But, anyway, I have started to understand.

Greetings,

Sven


[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

end of thread, other threads:[~2007-10-08 19:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-07 21:51 An easy defun Sven Bretfeld
2007-10-08  0:53 ` Amy Templeton
2007-10-08 19:25   ` Sven Bretfeld

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).