From: "Yu,Gang" <wuhanyugang@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Why I get different results running the same exp?
Date: Thu, 7 Jun 2007 19:25:28 +0800 [thread overview]
Message-ID: <48378d570706070425x65e74fbfx4bdf8468cb38532@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2007-06-07 11:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-07 11:25 Yu,Gang [this message]
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48378d570706070425x65e74fbfx4bdf8468cb38532@mail.gmail.com \
--to=wuhanyugang@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.