[gnu.emacs.bug] Problem with reverting a buffer ...

paul@UUNET.UU.NET (Paul Hudson) (07/14/89)

I give up: after much abortive emacs lisp hackery....

This comes from attempting to change the recent sccs.el package

What happens:

the package does a delta followed by a get on a buffer. This leaves the file on the
disk with modes -r--r--r-- and the contents of the buffer are the file *before* the delta.

Problem: how do I get the contents of the buffer correct without
changing the mode of the file on the disk?

The supplied code went something like ...

	(set-buffer buffer)
	(setq buffer-file-name nil)
	(erase-buffer)
	(insert-file-contents file t)
	(setq buffer-read-only t)

For some reason this leaves the file on the disk in mode -rw-r--r--.
This won't do since a get -e will then bitch.

Revert-buffer does almost what I want but I can't make it do it quite right.

Ideas anyone?
Paul Hudson	 MAIL: Monotype ADG, Science Park, Cambridge, CB4 4FQ, UK.
		PHONE: +44 (223) 420018	  EMAIL: paul@moncam.co.uk,
	;"	  FAX: +44 (223) 420911		 ...!ukc!acorn!moncam!paul
 `"";";"        These opinions void where prohibited by law.

cks@white.toronto.edu (Chris Siebenmann) (07/17/89)

moncam!paul@UUNET.UU.NET (Paul Hudson) writes:
| Problem: how do I get the contents of the buffer correct without
| changing the mode of the file on the disk?

 This function seems to work fine; I wrote it for my (as yet unposted)
RCS package when I needed to do the same thing. It even attempts to
preserve point and mark.

;; kill and reload a buffer from a file.
(defun buf-kill-and-reload (fn)
  "Given FILE, cause the current version of that file to be loaded into a
buffer. If the file was already in a buffer already, the buffer will be
refreshed to contain the latest version of the file. If the buffer has
been modified, the file will NOT be saved.
 Makes some attempt to keep the mark and point the same if the buffer
was around before."
  (let ((buf (get-file-buffer fn)))
    (if buf
	(progn
	  (switch-to-buffer buf)
	  (let ((curp (point))
		(curm (mark)))
	    (set-buffer-modified-p nil)
	    (kill-buffer buf)
	    (find-file fn)
	    (set-mark curm)
	    (goto-char curp)))
      (find-file fn))
    ))

 If invoked with (buf-kill-and-reload (buffer-file-name)) it does what
you want.

-- 
	"I shall clasp my hands together and bow to the corners of the world."
			Number Ten Ox, "Bridge of Birds"
Chris Siebenmann		...!utgpu!{ncrcan,ontmoh!moore}!ziebmef!cks
cks@white.toronto.edu	     or ...!utgpu!{,csri!}cks