[comp.emacs] Summary: Re: Writing a file through a filter

escott%deis.UCI.EDU@ROME.UCI.EDU (Scott Menter) (05/06/87)

Well, I got some help with my problem of writing a file through a
filter.  If the problem didn't interest you in the first place, I
suggest you stop reading here.  At any rate what was basically agreed
was that I should use (make-local-variable) on write-file-hooks in
those buffers that are to be written through a filter.  Here are the
replies I got, for those of you who are *really* interested in
*exactly* what everybody said.  The first message is my initial
inquiry.  Names have been deleted since nobody gave me explicit
permission to use theirs.

------- Forwarded Messages

To:  info-gnu-emacs@prep.ai.mit.edu
Date: Fri, 01 May 87 14:03:23 -0700

Subject:  Writing a file through a filter


(GNU Emacs 18.36.2 of Tue Feb 24 1987 on deis.uci.edu (berkeley-unix))

Hello.  I have a generic question:  what do you GNU Emacs Lisp
programmers think is the best way to solve this problem:

I would like certain buffers, when saved to a file, to have the output
passed through a filter first.  The filter might be, for example,
"sed" or "tr" or "rot13" (actually, in the case of my project, it's
"crypt").  I'd like auto-saves to go through the filter too.  Here's
the various ways I've thought of to do this:

(1)  Set up a function to see if a particular buffer should be
filtered before writing or auto-saving, and if so, take care of it.
The set write-file-hooks and auto-fill-hook to that function.

(2) Basically the same thing, only use (make-variable-buffer-local) so
that most files won't have any write-file-hooks to worry about,
thereby possibly speeding up saves and auto-saves in the general case.

(3) Don't associate the buffer with a file at all;  write special
functions to write and auto-save those buffers;  bind these functions
to the usual "write" keys.

Solution (1) seems like the most elegant one, to me, but I'm concerned
that the general case write, which needs no filtering, will suffer as
a result.  Solution (2) fixes that, but I wonder if it isn't bad
practice to make those variables buffer local.  Solution (3) fixes the
problems of the first two but is more work to implement, and requires
more complicated code.  Seeing as this is my first really serious Lisp
work of any kind, I'd rather avoid complications.

Any thoughts?  Reply to me, please, and if there's any interest at all
I'll summarize.  Thanks !!


+-------------------------------------------------------------------------+
 Scott Menter  UCI ICS Computing Support Group   Univ. of Calif. at Irvine
                     (714) 856 7552              Irvine, California  92717

 Internet:  escott@ics.uci.edu             UUCP:  ...!ucbvax!ucivax!escott
 Bitnet:    escott@uci               CSNet: escott%ics.uci.edu@csnet-relay
 Internet (with Name Server):  escott@deis.uci.edu
+-------------------------------------------------------------------------+


------- Message 2

To:  Scott Menter (UCI ICS Emacs Support) <escott@ICS.UCI.EDU>
Date: 02 May 87 02:55:00 -0400

Subject:  Re: Writing a file through a filter

I'd say the second solution was more elegant than the first. Besides,
the first case slows down *every* file write whereas the second only
slows down the ones you actually want to do something special with.

Also, you should use 'make-local-variable' instead of
'make-variable-buffer-local'. The first call just makes one new copy of
the variable; thats *it*. The later will cons up a new copy of the
variable every time you create a new buffer. (I generally stay way from
'make-variable-buffer-local' for this reason... Why pay for something
you don't use?).


------- Message 3

To:  escott@ICS.UCI.EDU
Date: Sat, 02 May 87 11:02:05 -0400

Subject:  Writing a file through a filter

[ Er, I decided not to share this one.  Sorry! ESM ]


------- Message 4

To:  Scott Menter (UCI ICS Emacs Support) <escott@ICS.UCI.EDU>
Date: Sat, 02 May 87 14:24:17 -0400

Subject:  Re: Writing a file through a filter 

I would definately like to see a summary of the responses you get to this
letter

[ Okay! 8^) ]


------- Message 5

To:  escott%deis.UCI.EDU@ROME.UCI.EDU
Date: Mon, 04 May 87 10:14:46 -0700

Subject:  Re: Writing a file through a filter

	I would suggest combining solutions 1 and 2.  Use the
	hooks, but make them start by testing a buffer-local
	variable.  The simplest case would be non-nil triggers
	the hook.  More complex usage might be to use the value
	to modify the selection of output filter, or the behavior
	of crypt.  Carrying this one step further, you could write
	a general output-filter package, which could be added to
	the distribution.


------- Message 6

To:  Scott Menter <escott@ICS.UCI.EDU>
Date: Tue, 05 May 87 18:30:17 -0500

Subject:  Re: Writing a file through a filter

Your solution #2 (make write-file-hooks local) seems like the way
to go.  If I were doing it, I'd make a find-file-hook which
would know how to decrypt the file when it's visited and which
would set write-file-hooks.  If there's a chance that the user
may want some hooks of their own on the list, forget about
making it local -- the extra time won't be much.  (Turn down the
auto-save frequency?)

------- Message 7

To:  Scott Menter <escott%deis.UCI.EDU@ROME.UCI.EDU>
Date: Tue, 05 May 87 19:12:35 -0500

Subject:  Re: Writing a file through a filter 

[ This was a response to my question to this person about what I
should do about the fact that there are no auto-save hooks.  I'll go
into more detail concerning this problem in a later message... ESM ]

Hmm.  You could turn off auto-saves for the crypted file's
buffer, then use the "loadst" filter or something like it
to tick away a time-based rather than keystroke-based auto-
save interval.  This way you get to write your own fuction
to do the "auto-save".

But I still like a find-file-hook that notices that the file
is encrypted.  Then there can be one for compressed files,
and so on.

------- End of Forwarded Messages