🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.vm.bug
Article #223

Re: Suggested fix to vm-pipe-message-part

#223
From: blueman
Date: Tue, 05 Jan 2010 23:42
169 lines
8717 bytes
Uday S Reddy <uDOTsDOTreddy@cs.bham.ac.uk> writes:

> blueman wrote:
>> Uday S Reddy <uDOTsDOTreddy@cs.bham.ac.uk> writes:
>>> Sorry, JJK.  I find this rather convoluted.  
>> Personally, I think my way of doing it is "clever" ;) since:
>
> Indeed, it is.  But "cleverness" is damaging to software by entangling
> one thing with another.  If you change one thing, then everything else
> breaks.  So, the cleverest software is in fact streamlined software.

Well, the point is that my code doesn't mess anything up... but I
suppose you worry that it is dependent on the prefix numbering scheme.

>
> I was assuming that the only reason for the
> vm-pipe-messages-to-command-[start|end] variables is to provide
> separators for the vm-pipe-messages-to-command function.  If this
> function is given the stored separator lines instead, then the
> variables don't have a purpose any more and I would want to eliminate
> them.

I imagine they might still be useful if using a maildir-like format
which doesn't have a natural separator since each message is stored in a
separate file. I can also imagine many reasons for adding a unique
start/end if nothing less than for converting mail formats...

If you don't like the "cleverness" of my offset numbering scheme, I
would still recommend preserving the following portion of my solution:

  Use the notion of setting vm-pipe-messages-to-command-start to 't' as
  the way of signalling using "internal" separators in place of the ones
  specified as a string through that variable and it's cousin
  vm-pipe-messages-to-command-end

  This avoids endless proliferation of variables and helps explain the
  mutually exclusive tie between using internal separators
  vs. user-specified separators. Otherwise, you run the risk of users
  setting one variable without understanding the use of the other.

>>> I have already added yesterday a variable called
>>> `vm-message-include-separators' to alter the meaning of what a
>>> "message" means.  All that is needed now is to call
>>> vm-pipe-message-to-command after setting this variable to t.
>
> This wasn't enough, unfortunately.  There is an additional parameter
> nowait' for the plural version of the function, which seems to require
> a more complicated protocol with the process.  So, I couldn't simply
> piggy back on the singular version of the function.  When I modified
> the plural version of the function to get rid of the extra separator
> lines, it hung on the examples I tried.  So, I will have to come back
> to this later.  Meanwhile, you seem to have something that works.  So,
> please go ahead and use it, and I will make sure that you will have a
> working version of the function when you have to upgrade.

Well - nowait is broken which is part of what I submitted patches for.
>>> This will be in 8.1.1-devo version in a few minutes.
>
> Famous last words!
>
>> Thanks. Have you also included my bug fixes to:
>>      vm-pipe-command-exit-handler
>>      vm-pipe-messages-to-command
>
> I can't find them.  Did you post them to the newsgroups or Launchpad?
> Actually, Launchpad is much better for posting bug reports because we
> can keep track of things better.  But newsgroups are better for
> discussion of course.
>
I used your suggestion of using vm-submit-bug-report...but I guess you
didn't get it...

But in any case here are the 'diffs' for the 2 corrected functions:


;JJK: Fixes bug in existing routine (missing 2nd argument in defun line)
-(defun vm-pipe-command-exit-handler (process discard-output 
+(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))))

;;JJK - Changes no-wait -> ,no-wait
;;;###autoload
(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)))
+		     ,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))
      (process-send-string process vm-pipe-messages-to-command-start)
      (save-restriction
	(widen)
	(let ((region (vm-pipe-message-part m prefix-arg)))
	  (process-send-region process (nth 0 region) (nth 1 region))))
      (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: <m2tyv03yq9.fsf@consult.pretender>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.78.MISMATCH!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
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>

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!news3.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.78.MISMATCH!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: Tue, 05 Jan 2010 18:42:38 -0500
Organization: A noiseless patient Spider
Lines: 169
Message-ID: <m2tyv03yq9.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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Tue, 5 Jan 2010 23:42:40 +0000 (UTC)
Injection-Info: feeder.eternal-september.org; posting-host="o0xooYC/dlyFpPxuXQpbEw";
 logging-data="28462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZfyIyCbVDlD1LoEDB0BzHs0/uJh80l4U="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock: sha1:4Sd0V6Sm0ohQtPliE6D/up6F6P8=
 sha1:6LsRdG9Wjx5ne/TyHgWEOvDdx5c=