From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Yu,Gang" Newsgroups: gmane.emacs.help Subject: Why I get different results running the same exp? Date: Thu, 7 Jun 2007 19:25:28 +0800 Message-ID: <48378d570706070425x65e74fbfx4bdf8468cb38532@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0457303228==" X-Trace: sea.gmane.org 1181215550 13269 80.91.229.12 (7 Jun 2007 11:25:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2007 11:25:50 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 07 13:25:49 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HwG7g-00086F-2f for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jun 2007 13:25:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HwG7f-0005Lo-7a for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jun 2007 07:25:47 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HwG7R-0005LW-2m for help-gnu-emacs@gnu.org; Thu, 07 Jun 2007 07:25:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HwG7P-0005LG-8b for help-gnu-emacs@gnu.org; Thu, 07 Jun 2007 07:25:32 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HwG7P-0005LD-5Z for help-gnu-emacs@gnu.org; Thu, 07 Jun 2007 07:25:31 -0400 Original-Received: from wa-out-1112.google.com ([209.85.146.177]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HwG7O-0004sk-Gw for help-gnu-emacs@gnu.org; Thu, 07 Jun 2007 07:25:31 -0400 Original-Received: by wa-out-1112.google.com with SMTP id k34so559116wah for ; Thu, 07 Jun 2007 04:25:28 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=PYAU8GcBuTALp/qpkWIH3Od5A1ltn5H474jT4+zprXr2d7fSttoaij7OEgWJEu4Zf3cSUR0F2U1O9nNL+yTwaNCc0w0ssYwt/RJ8eOTBsaHitj++j2apjT1KiYk2QV1hSoKplTgmRt2oQllKLQZdOdgmjIc9nVeQ9WOyxfX7g7g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=XC62A5suNdPWfWqXEEhFpmt2vuUZl28/Ufj5wcwfc1o2vBB7LzTjd6jMJzV8FTNtC3GahNGuH4/3o/tlEnS7spCYR/+WgQl1pThmKrEf2cN5dgaN+t0uooDvrWaOMXbBLPBHPLz3rISVP/nfXBimVaZelQ3LGYAUKh7KRY49Z44= Original-Received: by 10.114.66.2 with SMTP id o2mr1416567waa.1181215528293; Thu, 07 Jun 2007 04:25:28 -0700 (PDT) Original-Received: by 10.114.57.15 with HTTP; Thu, 7 Jun 2007 04:25:28 -0700 (PDT) X-detected-kernel: Linux 2.6 (newer, 2) 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:44747 Archived-At: --===============0457303228== Content-Type: multipart/alternative; boundary="----=_Part_44163_13170820.1181215528262" ------=_Part_44163_13170820.1181215528262 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, all: I'd like to search for special regexp on a directory list and collect the results to a buffer, I write the following code: (defun stringlist-to-string (list connector) "translate string list to string , cons using connector" (let ((result "")) (mapcar (lambda (string) (setq result (concat result string connector)) ) list) (substring result 0 -1))) (defun def-in-dir (dir filename-exp regexp) "find regexp in source directory" (interactive) (let ((ldir (if (not (string-equal (substring dir -1) "/")) (concat dir "/") dir)) command files) (if (file-exists-p ldir) (progn (setq default-directory ldir) (setq files (directory-files default-directory nil filename-exp)) (if files (progn (setq command (concat "egrep -nH -e '" regexp "' " (stringlist-to-string files " "))) (grep command))))))) (defun ygrep (regexp filename-exp dir-list) "search special files in the directory list for matching regexp." (interactive (let* ((regexp (read-from-minibuffer "to search (in grep format): ")) (filename-exp (read-from-minibuffer "file expression (in emacs regexp format): ")) (dir-list (read-minibuffer "directory-list: ")) ) (list regexp filename-exp (symbol-value dir-list)))) (let ((result-buffer (progn (if (get-buffer "*grep result*") (kill-buffer "*grep result*")) (get-buffer-create "*grep result*"))) (total-result 0)) (switch-to-buffer result-buffer) (compilation-mode) (if buffer-read-only (toggle-read-only)) (dolist (dir dir-list) (def-in-dir dir filename-exp regexp) (let ((grep-process (get-buffer-process (get-buffer "*grep*")))) (while (and grep-process (not (equal (process-status grep-process) 'exit))) (sleep-for 0 100))) (switch-to-buffer "*grep*") (goto-char 1) (if (not (string-match "no matches" (buffer-string))) (while (not (equal (point) (point-max))) (let ((line (buffer-substring (line-beginning-position) (line-end-position)))) (if (string-match "\\(^.*\\)\\(:[0-9]*:\\)\\(.*\\)" line) (if (file-exists-p (match-string 1 line)) (save-excursion (switch-to-buffer result-buffer) (setq total-result (+ total-result 1)) (insert (concat "\n" (if (not (string-equal (substring dir -1) "/")) (concat dir "/") dir) (match-string 1 line) (match-string 2 line) ;;(format " [%d] " total-result) //for debug (match-string 3 line))) (goto-char (point-max)) )))) (switch-to-buffer "*grep*") (forward-line))) (kill-buffer "*grep*")) (switch-to-buffer result-buffer) (goto-char 1) (insert (format "Grep search for regexp %s in file %s\n" regexp filename-exp)) (if (equal total-result 0) (insert (format "Sorry no matches found! ")) (insert (format "%d matches found! " total-result))) (toggle-read-only) )) but, everytime I run: (ygrep "(start|stop)-process" "\\.el$" load-path) in the *scratch* buffer, I get a different result. What's wrong?? Thanks -- YuGang ------=_Part_44163_13170820.1181215528262 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, all:
   
    I'd like to search for special regexp on a directory list and collect the results to a buffer, I write the following code:


(defun stringlist-to-string (list connector)
  "translate string list to string , cons using connector"
  (let ((result ""))
    (mapcar (lambda (string)
          (setq result (concat result string connector))
          ) list)
    (substring result 0 -1)))


(defun def-in-dir (dir filename-exp regexp)
  "find regexp in source directory"
  (interactive)
  (let ((ldir (if (not (string-equal (substring dir -1) "/"))
          (concat dir "/")
        dir))
    command
    files)
    (if (file-exists-p ldir)
    (progn
      (setq default-directory ldir)
      (setq files (directory-files
               default-directory
               nil filename-exp))
      (if files
          (progn
        (setq command
              (concat "egrep -nH -e '" regexp "' "  (stringlist-to-string files " ")))
        (grep command)))))))

(defun ygrep (regexp filename-exp dir-list)
  "search special files in the directory list for matching regexp."
  (interactive
   (let* ((regexp (read-from-minibuffer "to search (in grep format): "))
      (filename-exp (read-from-minibuffer "file expression (in emacs regexp format): "))
      (dir-list (read-minibuffer "directory-list: "))
      )
     (list regexp filename-exp (symbol-value dir-list))))
 
  (let ((result-buffer
     (progn
       (if (get-buffer "*grep result*")
           (kill-buffer "*grep result*"))
       (get-buffer-create "*grep result*")))
    (total-result 0))
    (switch-to-buffer result-buffer)
    (compilation-mode)
   
    (if buffer-read-only
    (toggle-read-only))
   
   
    (dolist (dir dir-list)
      (def-in-dir dir filename-exp regexp)
      (let ((grep-process (get-buffer-process (get-buffer "*grep*"))))
    (while (and
        grep-process
        (not (equal (process-status grep-process) 'exit)))
      (sleep-for 0 100)))
      (switch-to-buffer "*grep*")
      (goto-char 1)
      (if (not (string-match "no matches" (buffer-string)))
      (while (not (equal (point) (point-max)))
        (let ((line (buffer-substring (line-beginning-position) (line-end-position))))
          (if (string-match "\\(^.*\\)\\(:[0-9]*:\\)\\(.*\\)" line)
          (if (file-exists-p (match-string 1 line))
              (save-excursion
            (switch-to-buffer result-buffer)
            (setq total-result (+ total-result 1))
            (insert (concat "\n"
                    (if (not (string-equal (substring dir -1) "/"))
                        (concat dir "/")
                      dir)
                    (match-string 1 line)
                    (match-string 2 line)
                    ;;(format " [%d] " total-result) //for debug
                    (match-string 3 line)))
            (goto-char (point-max))               
        ))))
        (switch-to-buffer "*grep*")
        (forward-line)))
      (kill-buffer "*grep*"))
   
    (switch-to-buffer result-buffer)
    (goto-char 1)
    (insert (format "Grep search for regexp %s in file %s\n" regexp filename-exp))
    (if (equal total-result 0)
    (insert (format "Sorry no matches found! "))
    (insert (format "%d matches found! " total-result)))
    (toggle-read-only)
    ))

but, everytime I run:

(ygrep "(start|stop)-process" "\\.el$" load-path)

in the *scratch* buffer, I get a different result.

What's wrong??

Thanks

--
YuGang ------=_Part_44163_13170820.1181215528262-- --===============0457303228== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --===============0457303228==--