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

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

Re: Opening a list of files in Emacs


From: Pascal Bourguignon
Subject: Re: Opening a list of files in Emacs
Date: Thu, 12 Oct 2006 04:02:56 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

venu.nayar@gmail.com writes:

> I have a file containing a list of files (full-pathname), one per line.
> How do I open this list of files from Emacs? Is there a elisp package
> to do this?

(defun text-file-contents (path)
  "Returns a list of strings, the lines in the text file at path."
  (let ((lines '()))
    (with-temp-buffer
      (insert-file-contents path)
      (goto-char 0)
      (while (< (point) (point-max))
        (push (buffer-substring-no-properties
               (progn (beginning-of-line) (point))
               (progn (end-of-line)       (point))) lines)
        (forward-line 1)))
    (nreverse lines)))


(defun find-file-of-files (filename)
  (interactive (find-file-read-args "Find file of files: " nil))
  (dolist (file (text-file-contents filename)) (find-file file)))


Perhaps:

(defun string-trim (bag string)
  (let* ((margin (format "[%s]*" (regexp-quote bag)))
         (trimer (format "\\`%s\\(\\(.\\|\n\\)*?\\)%s\\'" margin margin)))
    (replace-regexp-in-string  trimer "\\1" string)))


(defun find-file-of-files (filename)
  (interactive (find-file-read-args "Find file of files: " nil))
  (dolist (file 
          (mapcan (lambda (path) 
                    (setf path (string-trim " \t" path))
                    (if (or (string= "" path)     ; empty lines
                            (= ?# (aref path 0))) ; comments
                        '()
                        (list path)))
                   (text-file-contents "file-of-pathnames")))
    (find-file file)))
  


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.


reply via email to

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