all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why I get different results running the same exp?
@ 2007-06-07 11:25 Yu,Gang
  0 siblings, 0 replies; 4+ messages in thread
From: Yu,Gang @ 2007-06-07 11:25 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 3405 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 6552 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-06-09  4:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1721.1181215534.32220.help-gnu-emacs@gnu.org>
2007-06-07 14:05 ` Why I get different results running the same exp? Thien-Thi Nguyen
2007-06-08  2:57   ` Yu,Gang
     [not found]   ` <mailman.1761.1181271448.32220.help-gnu-emacs@gnu.org>
2007-06-09  4:08     ` Barry Margolin
2007-06-07 11:25 Yu,Gang

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.