all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* process communication help
@ 2007-05-29  6:12 Yu,Gang
  0 siblings, 0 replies; 8+ messages in thread
From: Yu,Gang @ 2007-05-29  6:12 UTC (permalink / raw)
  To: help-gnu-emacs


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

Hi ,all:

   I get a problem, when I want to get sub-a process output from the buffer.

Here is the code, in my .emacs:

(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 (eval `(call-process (car check-command) nil d-buf t
,@(cdr check-command)))))
      (print `(,(buffer-modified-p) ,(buffer-size) ,(point-min) ,(point)
,(point-max)) d-buf)
      ;;(debug)
      (if (not (string-match wanted (buffer-string)))
      (progn
        (print (concat "starting command " (stringlist-to-string
start-command " ")) d-buf)
        (eval `(start-process "start up" d-buf (car start-command) ,@(cdr
start-command)))
        )
    (print
     (concat wanted " matched! no need to start " (stringlist-to-string
start-command " ")) d-buf)
    ))))

(setq system-start-up-list
      '((("sudo" "netstat" "-i") "eth0" ("sudo" "ifup" "eth0")))
    )

;;(debug-on-entry 'startup)

(mapcar (lambda (ssup-item)
      (let ((check-command (car ssup-item))
        (wanted (cadr ssup-item))
        (start-command (caddr ssup-item)))
        (startup check-command wanted start-command))
      ) system-start-up-list)

Something strange is that, I get the following in my diagnose buffer:

Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR
Flg
eth0   1500 0      3959      0      0      0     1903      0      0      0
BMRU
lo    16436 0       122      0      0      0      122      0      0      0
LRU

(nil 0 1 1 1)

"starting command sudo ifup eth0"
ifup: interface eth0 already configured

Process start up finished

It seems that , string
"
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR
Flg
eth0   1500 0      3959      0      0      0     1903      0      0      0
BMRU
lo    16436 0       122      0      0      0      122      0      0      0
LRU
" could not be read by the (buffer-string) :(

How can I solve the problem? thanks

cheers


-- 
YuGang

[-- Attachment #1.2: Type: text/html, Size: 3988 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] 8+ messages in thread

* Re: process communication help
       [not found] <mailman.1377.1180419176.32220.help-gnu-emacs@gnu.org>
@ 2007-05-29  8:00 ` Thien-Thi Nguyen
  2007-05-29  9:08   ` Yu,Gang
       [not found]   ` <mailman.1381.1180429716.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2007-05-29  8:00 UTC (permalink / raw)
  To: help-gnu-emacs

() "Yu,Gang" <wuhanyugang@gmail.com>
() Tue, 29 May 2007 14:12:46 +0800

   How can I solve the problem? thanks

determine the current buffer at the moment `(buffer-string)' is
evaluated.  if it is not as you expect, learn how to make it so.

thi

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

* Re: process communication help
  2007-05-29  8:00 ` process communication help Thien-Thi Nguyen
@ 2007-05-29  9:08   ` Yu,Gang
  2007-05-29 10:19     ` Yu,Gang
       [not found]   ` <mailman.1381.1180429716.32220.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Yu,Gang @ 2007-05-29  9:08 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: help-gnu-emacs


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

Thanks!

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

-------------------------------
(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 (eval `(call-process (car check-command) nil d-buf t
,@(cdr check-command)))))
      (switch-to-buffer d-buf)
      (print `(,(buffer-modified-p) ,(buffer-size) ,(point-min) ,(point)
,(point-max)) d-buf)
      ;;(debug)
      (if (not (string-match wanted (buffer-string)))
      (progn
        (print (concat "starting command " (stringlist-to-string
start-command " ")) d-buf)
        (eval `(start-process "start up" d-buf (car start-command) ,@(cdr
start-command)))
        )
    (print
     (concat wanted " matched! no need to start " (stringlist-to-string
start-command " ")) d-buf)
    ))))

and aux function

(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)))

On 5/29/07, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
>
> () "Yu,Gang" <wuhanyugang@gmail.com>
> () Tue, 29 May 2007 14:12:46 +0800
>
>    How can I solve the problem? thanks
>
> determine the current buffer at the moment `(buffer-string)' is
> evaluated.  if it is not as you expect, learn how to make it so.
>
> thi
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>



-- 
YuGang

[-- Attachment #1.2: Type: text/html, Size: 2967 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] 8+ messages in thread

* Re: process communication help
  2007-05-29  9:08   ` Yu,Gang
@ 2007-05-29 10:19     ` Yu,Gang
  0 siblings, 0 replies; 8+ messages in thread
From: Yu,Gang @ 2007-05-29 10:19 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: help-gnu-emacs


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

Surprisely, this time, after I add

(switch-to-buffer d-buf)

it works now!!

thanks

On 5/29/07, Yu,Gang <wuhanyugang@gmail.com> wrote:
>
> Thanks!
>
> Yes, I add the statement , but result the same. So, I believe it's not the
> problem of (buffer-string)
>
> -------------------------------
> (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 (eval `(call-process (car check-command) nil d-buf
> t ,@(cdr check-command)))))
>       (switch-to-buffer d-buf)
>       (print `(,(buffer-modified-p) ,(buffer-size) ,(point-min) ,(point)
> ,(point-max)) d-buf)
>       ;;(debug)
>       (if (not (string-match wanted (buffer-string)))
>       (progn
>         (print (concat "starting command " (stringlist-to-string
> start-command " ")) d-buf)
>         (eval `(start-process "start up" d-buf (car start-command) ,@(cdr
> start-command)))
>         )
>     (print
>      (concat wanted " matched! no need to start " (stringlist-to-string
> start-command " ")) d-buf)
>     ))))
>
> and aux function
>
> (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)))
>
> On 5/29/07, Thien-Thi Nguyen < ttn@gnuvola.org> wrote:
> >
> > () "Yu,Gang" < wuhanyugang@gmail.com>
> > () Tue, 29 May 2007 14:12:46 +0800
> >
> >    How can I solve the problem? thanks
> >
> > determine the current buffer at the moment `(buffer-string)' is
> > evaluated.  if it is not as you expect, learn how to make it so.
> >
> > thi
> > _______________________________________________
> > help-gnu-emacs mailing list
> > help-gnu-emacs@gnu.org
> > http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> >
>
>
>
> --
> YuGang




-- 
YuGang

[-- Attachment #1.2: Type: text/html, Size: 3855 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] 8+ messages in thread

* Re: process communication help
       [not found]   ` <mailman.1381.1180429716.32220.help-gnu-emacs@gnu.org>
@ 2007-05-29 10:22     ` Thien-Thi Nguyen
  2007-05-29 11:57       ` Yu,Gang
       [not found]       ` <mailman.1388.1180439874.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2007-05-29 10:22 UTC (permalink / raw)
  To: help-gnu-emacs

() "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

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

* Re: process communication help
  2007-05-29 10:22     ` Thien-Thi Nguyen
@ 2007-05-29 11:57       ` Yu,Gang
       [not found]       ` <mailman.1388.1180439874.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Yu,Gang @ 2007-05-29 11:57 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: help-gnu-emacs


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

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

[-- Attachment #1.2: Type: text/html, Size: 3264 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] 8+ messages in thread

* Re: process communication help
       [not found]       ` <mailman.1388.1180439874.32220.help-gnu-emacs@gnu.org>
@ 2007-05-29 15:08         ` Thien-Thi Nguyen
  2007-05-30  7:53           ` Yu,Gang
  0 siblings, 1 reply; 8+ messages in thread
From: Thien-Thi Nguyen @ 2007-05-29 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

() "Yu,Gang" <wuhanyugang@gmail.com>
() Tue, 29 May 2007 19:57:42 +0800

   Where can I get resources on elisp's idiomatic programming style?

one way is to read a lot of elisp.  this is particularly easy to do
since emacs itself is distributed with a lot of elisp.

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

these are ugly.  i don't even know if they are correct, i could not
force myself to read them.

why don't you try this:

(0) make sure your emacs is properly installed, in other words, with
    full source code (for each .elc file there should be a corresponding
    .el file in the same directory).

(1) evaluate the forms:
    (require 'cl)
    (dolist (dir load-path) (ignore-errors (dired dir)))

(2) in each" dired buffer, evaluate the form:
    (grep "egrep -nH -e '(call|start)-process' *.el")

by "evaluate the form", i mean type `M-:' and then the form and then
RET.  for step (2) you can recall previous forms into the minibuffer
by typing `M-p'.

further exploration is up to you.  have fun!

thi

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

* Re: process communication help
  2007-05-29 15:08         ` Thien-Thi Nguyen
@ 2007-05-30  7:53           ` Yu,Gang
  0 siblings, 0 replies; 8+ messages in thread
From: Yu,Gang @ 2007-05-30  7:53 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: help-gnu-emacs


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

Hi, Thien-Thi :

   thanks!!

I get a lot of instances shown in *grep* buffer, just like

cd /usr/share/emacs/21.4/lisp/
egrep -nH -e '(start|call)-process' *.el /dev/null
arc-mode.el:989:      (apply 'call-process
arc-mode.el:1011:  (apply 'call-process
arc-mode.el:1122:          (let ((exitcode (apply 'call-process
arc-mode.el:1282:  (apply 'call-process
....

dired-aux.el:411:(defun dired-call-process (praogram discard &rest
arguments)
dired-aux.el:417:                 'dired-call-process)))
dired-aux.el:418:    (if handler (apply handler 'dired-call-process
dired-aux.el:420:      (apply 'call-process program nil (not discard) nil
arguments))))
dired-aux.el:438:         (apply (function dired-call-process) program nil
arguments)))
....

I try to rewrite the code like this:

(defun def-in-dir (dir regexp)
  "find regexp in elisp source directory"
  (interactive)
  (setq dir (if (not (string-equal (substring dir -1) "/"))
                  (concat dir "/")
                dir))
  (setq default-directory dir)
  (if (file-exists-p default-directory)
      (progn (setq files (directory-files default-directory nil "\\.el$"))
         (if files
            (setq command
               (concat "egrep -nH -e '" regexp "' "  (stringlist-to-string
files " ")))
           (setq command "grep -n -e"))
         (ignore-errors (grep command))
         )))

but I cant' collect all the result in the same "*grep*" buffer, everytime
only one command result can be written in this buffer, no append way?

I mean things like:

(dolist (dir load-path)
   (def-in-dir dir "(start|call)-process")


On 5/29/07, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
>
> () "Yu,Gang" <wuhanyugang@gmail.com>
> () Tue, 29 May 2007 19:57:42 +0800
>
>    Where can I get resources on elisp's idiomatic programming style?
>
> one way is to read a lot of elisp.  this is particularly easy to do
> since emacs itself is distributed with a lot of elisp.
>
>    How about these macros?? I rewrite the function like this, [...]
>
> these are ugly.  i don't even know if they are correct, i could not
> force myself to read them.
>
> why don't you try this:
>
> (0) make sure your emacs is properly installed, in other words, with
>     full source code (for each .elc file there should be a corresponding
>     .el file in the same directory).
>
> (1) evaluate the forms:
>     (require 'cl)
>     (dolist (dir load-path) (ignore-errors (dired dir)))
>
> (2) in each" dired buffer, evaluate the form:
>     (grep "egrep -nH -e '(call|start)-process' *.el")
>
> by "evaluate the form", i mean type `M-:' and then the form and then
> RET.  for step (2) you can recall previous forms into the minibuffer
> by typing `M-p'.
>
> further exploration is up to you.  have fun!
>
> thi
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>



-- 
YuGang

[-- Attachment #1.2: Type: text/html, Size: 4756 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] 8+ messages in thread

end of thread, other threads:[~2007-05-30  7:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1377.1180419176.32220.help-gnu-emacs@gnu.org>
2007-05-29  8:00 ` process communication help Thien-Thi Nguyen
2007-05-29  9:08   ` Yu,Gang
2007-05-29 10:19     ` Yu,Gang
     [not found]   ` <mailman.1381.1180429716.32220.help-gnu-emacs@gnu.org>
2007-05-29 10:22     ` Thien-Thi Nguyen
2007-05-29 11:57       ` Yu,Gang
     [not found]       ` <mailman.1388.1180439874.32220.help-gnu-emacs@gnu.org>
2007-05-29 15:08         ` Thien-Thi Nguyen
2007-05-30  7:53           ` Yu,Gang
2007-05-29  6:12 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.