[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp question
From: |
Stefan Monnier |
Subject: |
Re: elisp question |
Date: |
Thu, 01 Dec 2005 00:07:57 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
> 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...
(pop-to-buffer
(find-file-noselect (expand-file-name (number-to-string (random N))
"foo/bar/kaya")))
This assumes the file names go from 0 to N-1.
You could also do
(let ((files (directory-files "foo/bar/kaya" 'full "[^.]\\|...")))
(pop-to-buffer (find-file-noselect (nth (random (length files)) files))))
and just select any random file in the directory, without any assumption on
the file names used.
Stefan
- Re: elisp question,
Stefan Monnier <=