unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* passing data to process sentinel
@ 2006-09-15 11:17 Gordon Beaton
  2006-09-15 17:01 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gordon Beaton @ 2006-09-15 11:17 UTC (permalink / raw)


I run tkdiff from emacs to compare the current buffer contents with
the corresponding saved file. tkdiff needs two filenames, so I start
by storing the buffer contents to a temporary file created by
make-temp-file.

I'd like to be able to pass the name of the temporary file to a
process sentinel so it can be cleaned up after tkdiff exits, for
example by attaching the filename to the process object itself where
it can be retrieved in the sentinel. To me this seems more elegant
than storing the filename elsewhere and looking it up.

One solution I'd like to see is something like this, but of course
neither set-process-sentinel nor the sentinel itself take the
additional argument:

  (set-process-sentinel
    (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
    'my-sentinel temp-file)

  (defun my-sentinel (process event mydata) 
    (if (file-exists-p mydata) (delete-file mydata)))
    
I was hoping that something like the following might work, but
temp-file doesn't seem to get bound in the lambda function:

  (set-process-sentinel
    (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
    (lambda (process event)
      (if (file-exists-p temp-file) (delete-file temp-file))))
  
Suggestions?

/gordon

-- 
[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

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

* Re: passing data to process sentinel
  2006-09-15 11:17 passing data to process sentinel Gordon Beaton
@ 2006-09-15 17:01 ` Kevin Rodgers
       [not found] ` <mailman.6985.1158339733.9609.help-gnu-emacs@gnu.org>
  2006-09-18 12:42 ` Johan Bockgård
  2 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2006-09-15 17:01 UTC (permalink / raw)


Gordon Beaton wrote:
> I run tkdiff from emacs to compare the current buffer contents with
> the corresponding saved file. tkdiff needs two filenames, so I start
> by storing the buffer contents to a temporary file created by
> make-temp-file.
> 
> I'd like to be able to pass the name of the temporary file to a
> process sentinel so it can be cleaned up after tkdiff exits, for
> example by attaching the filename to the process object itself where
> it can be retrieved in the sentinel. To me this seems more elegant
> than storing the filename elsewhere and looking it up.
> 
> One solution I'd like to see is something like this, but of course
> neither set-process-sentinel nor the sentinel itself take the
> additional argument:
> 
>   (set-process-sentinel
>     (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
>     'my-sentinel temp-file)
> 
>   (defun my-sentinel (process event mydata) 
>     (if (file-exists-p mydata) (delete-file mydata)))
>     
> I was hoping that something like the following might work, but
> temp-file doesn't seem to get bound in the lambda function:
> 
>   (set-process-sentinel
>     (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
>     (lambda (process event)
>       (if (file-exists-p temp-file) (delete-file temp-file))))

Backquote is your friend:

   (set-process-sentinel
     (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
     `(lambda (process event)
       (if (file-exists-p ,temp-file) (delete-file ,temp-file))))

-- 
Kevin

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

* Re: passing data to process sentinel
       [not found] ` <mailman.6985.1158339733.9609.help-gnu-emacs@gnu.org>
@ 2006-09-16  7:37   ` Gordon Beaton
  0 siblings, 0 replies; 5+ messages in thread
From: Gordon Beaton @ 2006-09-16  7:37 UTC (permalink / raw)


On Fri, 15 Sep 2006 11:01:15 -0600, Kevin Rodgers wrote:
> Backquote is your friend:
>
>    (set-process-sentinel
>      (start-process "tkdiff" nil "tkdiff" (buffer-file-name) temp-file)
>      `(lambda (process event)
>        (if (file-exists-p ,temp-file) (delete-file ,temp-file))))

Thank you! I had tried backquoting but it was the commas I didn't
think about.

I also realized after posting that I could get the file name from
(process-command process) in the sentinel, but I was more interested
in a solution like the above that works in the general case, where the
information isn't on the command line.

/gordon

-- 
[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e 

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

* Re: passing data to process sentinel
  2006-09-15 11:17 passing data to process sentinel Gordon Beaton
  2006-09-15 17:01 ` Kevin Rodgers
       [not found] ` <mailman.6985.1158339733.9609.help-gnu-emacs@gnu.org>
@ 2006-09-18 12:42 ` Johan Bockgård
  2006-09-18 13:45   ` Gordon Beaton
  2 siblings, 1 reply; 5+ messages in thread
From: Johan Bockgård @ 2006-09-18 12:42 UTC (permalink / raw)


Gordon Beaton <n.o.t@for.email> writes:

> I'd like to be able to pass the name of the temporary file to a
> process sentinel so it can be cleaned up after tkdiff exits, for
> example by attaching the filename to the process object itself where
> it can be retrieved in the sentinel. To me this seems more elegant
> than storing the filename elsewhere and looking it up.

For the record, Emacs 22 has that feature:

    *** Processes now have an associated property list where programs
    can maintain process state and other per-process related
    information.

    Use the new functions `process-get' and `process-put' to access,
    add, and modify elements on this property list. Use the new
    functions `process-plist' and `set-process-plist' to access and
    replace the entire property list of a process.

-- 
Johan Bockgård

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

* Re: passing data to process sentinel
  2006-09-18 12:42 ` Johan Bockgård
@ 2006-09-18 13:45   ` Gordon Beaton
  0 siblings, 0 replies; 5+ messages in thread
From: Gordon Beaton @ 2006-09-18 13:45 UTC (permalink / raw)


On Mon, 18 Sep 2006 14:42:10 +0200, Johan Bockgård wrote:
> For the record, Emacs 22 has that feature:
> 
>     *** Processes now have an associated property list where programs
>     can maintain process state and other per-process related
>     information.

That's good to hear. In fact I'm using a recent CVS emacs but was
referring to an older elisp manual. It didn't occur to me to check the
news file for this.

/gordon

-- 
[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

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

end of thread, other threads:[~2006-09-18 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-15 11:17 passing data to process sentinel Gordon Beaton
2006-09-15 17:01 ` Kevin Rodgers
     [not found] ` <mailman.6985.1158339733.9609.help-gnu-emacs@gnu.org>
2006-09-16  7:37   ` Gordon Beaton
2006-09-18 12:42 ` Johan Bockgård
2006-09-18 13:45   ` Gordon Beaton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).