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: Re: process communication help Date: Tue, 29 May 2007 19:57:42 +0800 Message-ID: <48378d570705290457x68c645fegf56dd1f48558b5e9@mail.gmail.com> References: <878xb8kqje.fsf@ambire.localdomain> <871wh0kjzg.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0481322483==" X-Trace: sea.gmane.org 1180439889 2419 80.91.229.12 (29 May 2007 11:58:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 29 May 2007 11:58:09 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Thien-Thi Nguyen" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 29 13:58:08 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 1Ht0L2-0000bY-33 for geh-help-gnu-emacs@m.gmane.org; Tue, 29 May 2007 13:58:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ht0L1-0008Mn-KQ for geh-help-gnu-emacs@m.gmane.org; Tue, 29 May 2007 07:58:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ht0Km-0008Mh-DB for help-gnu-emacs@gnu.org; Tue, 29 May 2007 07:57:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ht0Ki-0008MR-Tl for help-gnu-emacs@gnu.org; Tue, 29 May 2007 07:57:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ht0Ki-0008MO-Nw for help-gnu-emacs@gnu.org; Tue, 29 May 2007 07:57:48 -0400 Original-Received: from wa-out-1112.google.com ([209.85.146.176]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ht0Kh-0000G9-T4 for help-gnu-emacs@gnu.org; Tue, 29 May 2007 07:57:48 -0400 Original-Received: by wa-out-1112.google.com with SMTP id j4so872279wah for ; Tue, 29 May 2007 04:57:47 -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:cc:in-reply-to:mime-version:content-type:references; b=uLhZ0NECqfp7L46b1TNZbYPaKHwiuzvwKjXJOKXlue0OF5mvwLnphvTgLWHXZqF7MK8j7eLNR6cWaWduecUDlIdJLqT61jtxUK3chUSZWKmFOCeaNU0kasxhyNYwRHvV7IV4gh/RJW6lVsrO0ZFjM8NxQxI4n/k4MHCtiEkUEus= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=j7DvzUzos9KpYZdV+DHaMgqaTgDK9l3Qo2R/dH/Xl7D7CxUfLsMQPvgNlix9WJnWFkimfIJUc5/TiEJY3pc/fS7cTfj6dALa3+BNobwww8ET53k57KfHebwGtrpdms8TC6SY69K8qzgj4J//N1tyDDy7sYILiUBY2vxy6FRd8sE= Original-Received: by 10.114.39.16 with SMTP id m16mr3377573wam.1180439867073; Tue, 29 May 2007 04:57:47 -0700 (PDT) Original-Received: by 10.114.60.1 with HTTP; Tue, 29 May 2007 04:57:42 -0700 (PDT) In-Reply-To: <871wh0kjzg.fsf@ambire.localdomain> 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:44528 Archived-At: --===============0481322483== Content-Type: multipart/alternative; boundary="----=_Part_5117_25917392.1180439862029" ------=_Part_5117_25917392.1180439862029 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Where can I get resources on elisp's idiomatic programming style? thanks How about these macros?? I rewrite the function like this, (defmacro syn-call (input buffer display command) "synchorous process call macro, using call-process" `(call-process ,(eval `(car ,command)) ,input ,buffer ,display ,@(eval `(cdr ,command)))) (defmacro asyn-call (process-name buff command) "aynchorous process call macro, using start process" `(start-process ,process-name ,buff ,(eval `(car ,command)) ,@(eval `(cdr ,command)))) (defun startup (check-command wanted start-command) "check whether the 'wanted' state satisfied, if not, launch the start-command" (interactive) (save-excursion (let* ((d-buf (get-buffer-create "diagnose")) (process-connection-type nil) (process-status (syn-call nil d-buf t check-command))) (switch-to-buffer d-buf) (if (not (string-match wanted (buffer-string))) (progn (print (concat "starting command " (stringlist-to-string start-command " ")) d-buf) (asyn-call "start up" d-buf start-command)) (print (concat wanted " matched! no need to start " (stringlist-to-string start-command " ")) d-buf) )))) On 5/29/07, Thien-Thi Nguyen wrote: > > () "Yu,Gang" > () Tue, 29 May 2007 17:08:27 +0800 > > Yes, I add the statement , but result the same. So, > I believe it's not the problem of (buffer-string) > > the problem is in your understanding of `buffer-string'. > you need to fix that first. try using `current-buffer' to > test your assumptions. btw, unrelated comment: the form: > > (eval `(func ,(car foo) ... ,@(cdr foo))) > > can be replaced by: > > (apply 'func (car foo) ... (cdr foo)) > > the latter is much more idiomatic and easier for people > like me (who wish to help you) to read. > > thi > _______________________________________________ > help-gnu-emacs mailing list > help-gnu-emacs@gnu.org > http://lists.gnu.org/mailman/listinfo/help-gnu-emacs > -- YuGang ------=_Part_5117_25917392.1180439862029 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Where can I get resources on elisp's idiomatic programming style?

thanks

How about these macros?? I rewrite the function like this,

(defmacro syn-call (input buffer display command)
   "synchorous process call macro, using call-process"
   `(call-process ,(eval `(car ,command)) ,input ,buffer ,display  ,@(eval `(cdr ,command))))

(defmacro asyn-call (process-name buff command)
  "aynchorous process call macro, using start process"
  `(start-process ,process-name ,buff ,(eval `(car ,command)) ,@(eval `(cdr ,command))))

(defun startup (check-command wanted start-command)
  "check whether the 'wanted' state satisfied, if not, launch the start-command"
  (interactive)
  (save-excursion
    (let* ((d-buf (get-buffer-create "diagnose"))
            (process-connection-type nil)
            (process-status (syn-call nil d-buf t check-command)))
      (switch-to-buffer d-buf)
      (if (not (string-match wanted (buffer-string)))
          (progn
             (print (concat "starting command " (stringlist-to-string start-command " ")) d-buf)
             (asyn-call "start up" d-buf start-command))
        (print
          (concat wanted " matched! no need to start " (stringlist-to-string start-command " ")) d-buf)
    ))))



On 5/29/07, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
() "Yu,Gang" <wuhanyugang@gmail.com>
() Tue, 29 May 2007 17:08:27 +0800

   Yes, I add the statement , but result the same. So,
   I believe it's not the problem of (buffer-string)

the problem is in your understanding of `buffer-string'.
you need to fix that first.  try using `current-buffer' to
test your assumptions.  btw, unrelated comment: the form:

  (eval `(func ,(car foo) ... ,@(cdr foo)))

can be replaced by:

  (apply 'func (car foo) ... (cdr foo))

the latter is much more idiomatic and easier for people
like me (who wish to help you) to read.

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



--
YuGang ------=_Part_5117_25917392.1180439862029-- --===============0481322483== 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 --===============0481322483==--