* 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
* Re: Why I get different results running the same exp?
[not found] <mailman.1721.1181215534.32220.help-gnu-emacs@gnu.org>
@ 2007-06-07 14:05 ` Thien-Thi Nguyen
2007-06-08 2:57 ` Yu,Gang
[not found] ` <mailman.1761.1181271448.32220.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 4+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-07 14:05 UTC (permalink / raw)
To: help-gnu-emacs
() "Yu,Gang" <wuhanyugang@gmail.com>
() Thu, 7 Jun 2007 19:25:28 +0800
but, everytime I run:
(ygrep "(start|stop)-process" "\\.el$" load-path)
in the *scratch* buffer, I get a different result.
What's wrong??
if you save the code and repeatedly load it into a freshly
started emacs, do you get consistent results each time?
if so, what does that mean?
if not, what does that mean?
thi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why I get different results running the same exp?
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>
1 sibling, 0 replies; 4+ messages in thread
From: Yu,Gang @ 2007-06-08 2:57 UTC (permalink / raw)
To: Thien-Thi Nguyen; +Cc: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 1225 bytes --]
If I understand you corrently, I restart emacs with
"emacs -q"
I copy the code to *scratch*, evaluate them
then, I repeatedly run "(ygrep "(start|stop)-process" "\\.el$" load-path)"
third times,
first result is 128 matches , and second 141, third 146.
I ediff the buffers ,find that some items are ingored by the precedent
match.
But I could not explain:-(
I suspect the problem is
"(while (and
grep-process
(not (equal (process-status grep-process) 'exit)))
(sleep-for 0 100)))"
but I am not sure, any suggestions?
thanks
On 6/7/07, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
>
> () "Yu,Gang" <wuhanyugang@gmail.com>
> () Thu, 7 Jun 2007 19:25:28 +0800
>
> but, everytime I run:
>
> (ygrep "(start|stop)-process" "\\.el$" load-path)
>
> in the *scratch* buffer, I get a different result.
>
> What's wrong??
>
> if you save the code and repeatedly load it into a freshly
> started emacs, do you get consistent results each time?
>
> if so, what does that mean?
> if not, what does that mean?
>
> thi
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
cheers
--
YuGang
[-- Attachment #1.2: Type: text/html, Size: 1984 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
* Re: Why I get different results running the same exp?
[not found] ` <mailman.1761.1181271448.32220.help-gnu-emacs@gnu.org>
@ 2007-06-09 4:08 ` Barry Margolin
0 siblings, 0 replies; 4+ messages in thread
From: Barry Margolin @ 2007-06-09 4:08 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.1761.1181271448.32220.help-gnu-emacs@gnu.org>,
"Yu,Gang" <wuhanyugang@gmail.com> wrote:
> If I understand you corrently, I restart emacs with
>
> "emacs -q"
>
> I copy the code to *scratch*, evaluate them
>
> then, I repeatedly run "(ygrep "(start|stop)-process" "\\.el$" load-path)"
> third times,
>
> first result is 128 matches , and second 141, third 146.
Works fine for me, I get 172 matches every time.
>
> I ediff the buffers ,find that some items are ingored by the precedent
> match.
>
> But I could not explain:-(
>
> I suspect the problem is
> "(while (and
> grep-process
> (not (equal (process-status grep-process) 'exit)))
> (sleep-for 0 100)))"
>
> but I am not sure, any suggestions?
That's just waiting for the grep to finish, which is fine.
I'm not sure why your function is so complicated. Instead of doing a
separate grep for each directory and then combining them, why don't you
do one big grep for everything? Append "/*.el" to each element of the
directory, concatenate them, and pass them to grep. E.g. if load-path
contains ("/path/to/dir1" "/path/to/dir2") you do
(let* ((paths (mapconcat '(lambda (dir) (concat dir "/*.el"))
load-path))
(command (sprintf "egrep -nH -e '%s' %s" regexp paths)))
(grep command))
>
> thanks
>
> On 6/7/07, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
> >
> > () "Yu,Gang" <wuhanyugang@gmail.com>
> > () Thu, 7 Jun 2007 19:25:28 +0800
> >
> > but, everytime I run:
> >
> > (ygrep "(start|stop)-process" "\\.el$" load-path)
> >
> > in the *scratch* buffer, I get a different result.
> >
> > What's wrong??
> >
> > if you save the code and repeatedly load it into a freshly
> > started emacs, do you get consistent results each time?
> >
> > if so, what does that mean?
> > if not, what does that mean?
> >
> > thi
> > _______________________________________________
> > help-gnu-emacs mailing list
> > help-gnu-emacs@gnu.org
> > http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> >
>
> cheers
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ 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.