help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: process communication help


From: Yu,Gang
Subject: Re: process communication help
Date: Tue, 29 May 2007 19:57:42 +0800

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
reply via email to

[Prev in Thread] Current Thread [Next in Thread]