help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

elisp question


From: Tim McNamara
Subject: elisp question
Date: Wed, 30 Nov 2005 17:13:33 -0600
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

I am looking to write a small program for Emacs which will create a
new buffer and read a randomly selected text file into it after
launching Emacs- rather like yow or fortune, except the files would be
Dharma snippets.  I have a very little experience with programmming
back in college and some with elisp since using Emacs, but it's
limited and so I'm stretching myself to figure this out.  Kind of fun,
actually, and it seems like a high level language like elisp ought to
make it fairly simple.

Creating the buffer works:

(add-hook 'after-init-hook
      (function
       (lambda ()
         (pop-to-buffer (get-buffer-create " *Dharma*"))

After this, I'm having trouble figuring out how to randomly select a
file in a directory and to read the file into the buffer.  

The files are in a subdirectory (called kaya), numbered 1 to whatever,
so I want to randomly pick an integer from 1 to whatever.  I thought
that (find-file) or perhaps (find-file-noselect) could be used in
conjunction with (random), but I can't figure out how to do that.
I've probably missed someting really bloody obvious in the elisp
manual...

Seems to me that there are two steps.  One is to count how many files
are in the directory, and to use that count as the limit for
(random).  Then to take the "random" number generated by (random) and
use it with find-file.

Pointers to relevant information are much appreciated!  I am probably
not even starting in the right place.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]