emacs-devel
[Top][All Lists]
Advanced

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

Re: Proposal for battery.el


From: Romain Francoise
Subject: Re: Proposal for battery.el
Date: Sat, 04 Nov 2006 19:23:31 +0100

address@hidden (Michaël Cadilhac) writes:

+ (defun battery-search-for-one-match-in-files (files regexp match-num)
+   "Search REGEXP in content of the files listed in FILES.
+ If a match occured, return the parenthesized expression numbered by
+ MATCH-NUM in the match.  Otherwise, return nil."
+   (with-temp-buffer
+     (while (and files
+               (not (or (ignore-errors
+                          (insert-file-contents (car files))
+                          (re-search-forward regexp))
+                        (erase-buffer))))
+       (setq files (cdr files)))
+     (when files
+       (match-string match-num))))

How about the following instead?  Since battery.el requires cl at
compilation time, you can safely use `dolist'...

(defun battery-search-for-one-match-in-files (files regexp match-num)
  "Search REGEXP in content of the files listed in FILES.
If a match occured, return the parenthesized expression numbered by
MATCH-NUM in the match.  Otherwise, return nil."
  (catch 'found
    (dolist (file files)
      (with-temp-buffer
        (insert-file-contents file)
        (when (re-search-forward regexp nil t)
          (throw 'found (match-string match-num)))))))

-- 
Romain Francoise <address@hidden> | The sea! the sea! the open
it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the
                                        | ever free! --Bryan W. Procter




reply via email to

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