Article View: gnu.emacs.vm.bug
Article #233Re: Suggested fix to vm-pipe-message-part
From: blueman
Date: Wed, 06 Jan 2010 17:42
Date: Wed, 06 Jan 2010 17:42
116 lines
6254 bytes
6254 bytes
Uday S Reddy <uDOTsDOTreddy@cs.bham.ac.uk> writes:
> blueman wrote:
>> Brief testing show it works -- indeed piping all messages in a folder to
>> an external file matches exactly the original file -- which is what I
>> think we want...
>
> It didn't work for me. I needed to make at least the following fixes.
>
> Running it on cat (on Windows Cygwin) still hangs for me. I think it
> has something to do with the asynchronous handler. But I will punt
> that issue for now.
>
> Cheers,
> Uday
>
Please try with the two patches I submitted. They really just correct
probably typos. I don't think the changes you made are necessary. But
please try my changes first...
---------------------------------------------------------------------
; Fixes missing 'command' argument in defun
(defun vm-pipe-command-exit-handler (process command discard-output
&optional exit-handler)
"Switch to output buffer of PROCESS if DISCARD-OUTPUT non-nil.
If non-nil call EXIT-HANDLER with the two arguments COMMAND and OUTPUT-BUFFER."
(let ((exit-code (process-exit-status process))
(buffer (process-buffer process))
(command (process-command process)))
(if (not (zerop exit-code))
(message "Command '%s' exit code is %d." command exit-code))
(vm-display nil nil '(vm-pipe-message-to-command)
'(vm-pipe-message-to-command))
(vm-switch-to-command-output-buffer command buffer discard-output)
(if exit-handler
(funcall exit-handler command buffer))))
;-------------------------------------------------------------------------
; Adds my new functionality and fixes unquoted ,no-wait argument
(defun vm-pipe-messages-to-command (command &optional prefix-arg
discard-output no-wait)
"Run a shell command with contents from messages as input.
Similar to `vm-pipe-message-to-command', but it will call process
just once and pipe all messages to it. For bulk operations this
is much faster than calling the command on each message. This is
more like saving to a pipe.
Before a message it will insert `vm-pipe-messages-to-command-start'
and after a message `vm-pipe-messages-to-command-end'.
Output, if any, is displayed unless DISCARD-OUTPUT is t.
If NO-WAIT is t, then do not wait for process to finish, if it is
a function then call it with the COMMAND and OUTPUT-BUFFER as
arguments after the command finished."
(interactive
;; protect value of last-command
(let ((last-command last-command)
(this-command this-command))
(vm-follow-summary-cursor)
(vm-select-folder-buffer)
(list (read-string "Pipe to command: " vm-last-pipe-command)
current-prefix-arg)))
(vm-select-folder-buffer)
(vm-check-for-killed-summary)
(vm-error-if-folder-empty)
(setq vm-last-pipe-command command)
(let ((buffer (get-buffer-create "*Shell Command Output*"))
(pop-up-windows (and pop-up-windows (eq vm-mutable-windows t)))
;; prefix arg doesn't have "normal" meaning here, so only call
;; vm-select-marked-or-prefixed-messages if we're using marks.
(mlist (if (eq last-command 'vm-next-command-uses-marks)
(vm-select-marked-or-prefixed-messages 0)
(list (car vm-message-pointer))))
m process)
(save-excursion
(set-buffer buffer)
(erase-buffer))
(setq process (start-process command buffer
(or shell-file-name "sh")
shell-command-switch command))
(set-process-sentinel
process
`(lambda (process status)
(setq status (process-status process))
(if (eq 'exit status)
(if ,no-wait
(vm-pipe-command-exit-handler
process ,command ,discard-output
(if (and ,no-wait (functionp ,no-wait))
,no-wait)))
(message "Command '%s' changed state to %s."
,command status))))
(while mlist
(setq m (vm-real-message-of (car mlist)))
(set-buffer (vm-buffer-of m))
(save-restriction
(widen)
(if (equal vm-pipe-messages-to-command-start t)
(apply 'process-send-region process (vm-start-separator-of m))
(process-send-string process vm-pipe-messages-to-command-start))
(apply 'process-send-region process (vm-pipe-message-part m prefix-arg))
(if (equal vm-pipe-messages-to-command-end t)
(apply 'process-send-region process (vm-end-separator-of m))
(process-send-string process vm-pipe-messages-to-command-end)))
(setq mlist (cdr mlist)))
(process-send-eof process)
(when (not no-wait)
(while (and (eq 'run (process-status process)))
(accept-process-output process)
(sit-for 0))
(vm-pipe-command-exit-handler process command discard-output))
buffer))
Technical Details
Message-ID:
<m2ocl7yvsr.fsf@consult.pretender>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mailReferences:
<m2d41p7sho.fsf@consult.pretender> <hht5o0$9pd$1@scotsman.ed.ac.uk> <m23a2l7myy.fsf@consult.pretender> <hhti24$9ua$1@scotsman.ed.ac.uk> <m2tyv15eaz.fsf@consult.pretender> <hhv7u9$bf4$1@scotsman.ed.ac.uk> <m2iqbg5zjg.fsf@consult.pretender> <hi0018$1gk$1@north.jnrs.ja.net> <m21vi45kxy.fsf@consult.pretender> <hi0e67$5b2$1@north.jnrs.ja.net> <m2tyv03yq9.fsf@consult.pretender> <m2pr5o3ycq.fsf@consult.pretender> <m2ljgc3xd3.fsf@consult.pretender> <hi2c72$l5i$1@north.jnrs.ja.net>Show Full Headers
Complete Article Headers
X-Google-Thread: a16957f451,747cd7667796b3e3 X-Google-Attributes: gida16957f451,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: blueman <NOSPAM@nospam.com> Newsgroups: gnu.emacs.vm.bug Subject: Re: Suggested fix to vm-pipe-message-part Date: Wed, 06 Jan 2010 12:42:28 -0500 Organization: A noiseless patient Spider Lines: 116 Message-ID: <m2ocl7yvsr.fsf@consult.pretender> References: <m2d41p7sho.fsf@consult.pretender> <hht5o0$9pd$1@scotsman.ed.ac.uk> <m23a2l7myy.fsf@consult.pretender> <hhti24$9ua$1@scotsman.ed.ac.uk> <m2tyv15eaz.fsf@consult.pretender> <hhv7u9$bf4$1@scotsman.ed.ac.uk> <m2iqbg5zjg.fsf@consult.pretender> <hi0018$1gk$1@north.jnrs.ja.net> <m21vi45kxy.fsf@consult.pretender> <hi0e67$5b2$1@north.jnrs.ja.net> <m2tyv03yq9.fsf@consult.pretender> <m2pr5o3ycq.fsf@consult.pretender> <m2ljgc3xd3.fsf@consult.pretender> <hi2c72$l5i$1@north.jnrs.ja.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 6 Jan 2010 17:42:28 +0000 (UTC) Injection-Info: news.motzarella.org; posting-host="o0xooYC/dlyFpPxuXQpbEw"; logging-data="19120"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ml9ZENrjQhdxqzAsFJL8BjoWjeV1fZ9Y=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:pJVJlZRzsz4UOnadr/Ilid+hCLY= sha1:rHx8KZd78q+NMS+YsjvsGxKIe6A=