From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim McNamara Newsgroups: gmane.emacs.help Subject: elisp question Date: Wed, 30 Nov 2005 17:13:33 -0600 Organization: ipHouse - Welcome Home! Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1133392550 17430 80.91.229.2 (30 Nov 2005 23:15:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 30 Nov 2005 23:15:50 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 01 00:15:49 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EhbAb-0006UW-FD for geh-help-gnu-emacs@m.gmane.org; Thu, 01 Dec 2005 00:15:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EhbAa-0005Un-S2 for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Nov 2005 18:15:24 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!news.glorb.com!green.octanews.net!news-out.octanews.net!news-2.mpls.iphouse.net.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Cancel-Lock: sha1:LeFqhQup+xeVFAzqDB7b0TsHwD8= Original-Lines: 33 Original-NNTP-Posting-Date: 30 Nov 2005 17:13:40 CST Original-NNTP-Posting-Host: 499b82ee.newsreader.iphouse.net Original-X-Trace: DXC=I4nB046Vad58ZX7hKNUY=>Vn\Tj8`^Bb; eHS>e[L>830j_c0W7]U0a0m:@8]TdIgg5f@e7N90MVd=X1bhYXbW814 Original-X-Complaints-To: abuse@iphouse.net Original-Xref: shelby.stanford.edu gnu.emacs.help:135941 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:31548 Archived-At: 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.