* Buffer corruption with jka-compr.el and revert-buffer
@ 2003-05-26 5:53 Martin Schwenke
2003-05-26 9:36 ` Stephen J. Turnbull
0 siblings, 1 reply; 4+ messages in thread
From: Martin Schwenke @ 2003-05-26 5:53 UTC (permalink / raw)
In GNU Emacs 21.3.2 and XEmacs 21.4.12 (and lots of earlier versions
of each, apparently, such as GNU Emacs 20.7), put the following code
into jka-compr-revert-bug.el:
--------8<---------8<-------- CUT HERE --------8<---------8<--------
(shell-command "echo 'aaa' | gzip > /tmp/aa.gz")
(shell-command "echo 'b' | gzip > /tmp/b.gz")
(auto-compression-mode 1)
(find-file "/tmp/aa.gz")
(shell-command "cp /tmp/b.gz /tmp/aa.gz")
(revert-buffer t t)
--------8<---------8<-------- CUT HERE --------8<---------8<--------
Now do:
(x)emacs -q --no-site-file -l jka-compr-revert-bug.el
You probably have a buffer that looks like
--------8<---------8<-------- CUT HERE --------8<---------8<--------
b
a
--------8<---------8<-------- CUT HERE --------8<---------8<--------
Yikes! It should just contain a 'b'!
This only seems to happen if the original file is at least 2
characters longer than the new file. The underlying file is not
changed but, when you edit and save, the corruption obviously makes
its way into the saved file.
I've had a look at revert-buffer and nothing jumps out. I've also had
a look at jka-compr.el and I've run away screaming... I suspect it
would be a lot simpler without all that coding system stuff... :-)
peace & happiness,
martin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Buffer corruption with jka-compr.el and revert-buffer
2003-05-26 5:53 Buffer corruption with jka-compr.el and revert-buffer Martin Schwenke
@ 2003-05-26 9:36 ` Stephen J. Turnbull
2003-05-26 23:50 ` Martin Schwenke
0 siblings, 1 reply; 4+ messages in thread
From: Stephen J. Turnbull @ 2003-05-26 9:36 UTC (permalink / raw)
Cc: bug-gnu-emacs, XEmacs Beta, xemacs-patches
Thanks for your report, Martin.
>>>>> "Martin" == Martin Schwenke <martin@meltin.net> writes:
Martin> I've had a look at revert-buffer and nothing jumps out.
Martin> I've also had a look at jka-compr.el and I've run away
Martin> screaming... I suspect it would be a lot simpler without
Martin> all that coding system stuff... :-)
The REPLACE semantics of j-c-insert-file-contents were simply wrong.
This fixes that, and a couple of minor bugs like the truncated
argument list and the missing docstring. It's not really ready for
prime time; see the #### comments. However, it's strictly better than
the existing code in XEmacs, and jka-compr will probably be obsolete
in XEmacs 21.5.
Caveat Emacsers. I have no idea whether this is correct for GNU Emacs.
Index: xemacs-packages/os-utils/ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/os-utils/ChangeLog,v
retrieving revision 1.38
diff -u -U0 -r1.38 ChangeLog
--- xemacs-packages/os-utils/ChangeLog 21 Mar 2003 05:51:13 -0000 1.38
+++ xemacs-packages/os-utils/ChangeLog 26 May 2003 09:24:01 -0000
@@ -0,0 +1,5 @@
+2003-05-26 Stephen J. Turnbull <stephen@xemacs.org>
+
+ * jka-compr.el (jka-compr-insert-file-contents): New docstring.
+ Implement REPLACE argument correctly.
+
Index: xemacs-packages/os-utils/jka-compr.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/os-utils/jka-compr.el,v
retrieving revision 1.8
diff -u -r1.8 jka-compr.el
--- xemacs-packages/os-utils/jka-compr.el 27 Mar 2000 13:11:15 -0000 1.8
+++ xemacs-packages/os-utils/jka-compr.el 26 May 2003 09:24:08 -0000
@@ -517,7 +517,31 @@
)))))
-(defun jka-compr-insert-file-contents (file &optional visit beg end replace)
+;; #### Should error or warn if the ignore-me arguments are supplied.
+(defun jka-compr-insert-file-contents (file &optional visit beg end replace
+ ignore-me ignore-me-too)
+ "Insert contents of FILE in current buffer after point.
+Returns list of absolute file name and length of data inserted.
+
+If second argument VISIT is non-nil, the buffer's visited filename
+and last save file modtime are set, and it is marked unmodified.
+If visiting and the file does not exist, visiting is completed
+before the error is signaled.
+
+The optional third and fourth arguments START and END
+specify what portion of the file to insert.
+If VISIT is non-nil, START and END must be nil.
+If optional fifth argument REPLACE is non-nil,
+it means replace the current buffer contents (in the accessible portion)
+with the file contents. This is better than simply deleting and inserting
+the whole thing because (1) it preserves some marker positions
+and (2) it puts less data in the undo list. (#### Is (2) true?)
+
+Coding system arguments are completely ignored (see documentation of the
+6th and 7th arguments to `insert-file-contents'). The coding system is set
+to 'undecided unless `coding-system-for-read' is bound. WARNING: That means
+this function is badly broken under Mule. Use jka-compr at your own risk
+in Mule Emacsen."
(barf-if-buffer-read-only)
(and (or beg end)
@@ -571,7 +594,7 @@
(progn
(if replace
- (goto-char (point-min)))
+ (delete-region (point-min) (point-max)))
(setq start (point))
(if (or beg end)
(jka-compr-partial-uncompress uncompress-program
@@ -595,12 +618,6 @@
t
nil
uncompress-args)))
- (setq size (- (point) start))
- (if replace
- (let* ((del-beg (point))
- (del-end (+ del-beg size)))
- (delete-region del-beg
- (min del-end (point-max)))))
(goto-char start))
(error
(if (and (eq (car error-code) 'file-error)
--
Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Buffer corruption with jka-compr.el and revert-buffer
2003-05-26 9:36 ` Stephen J. Turnbull
@ 2003-05-26 23:50 ` Martin Schwenke
2003-05-27 6:28 ` Martin Schwenke
0 siblings, 1 reply; 4+ messages in thread
From: Martin Schwenke @ 2003-05-26 23:50 UTC (permalink / raw)
Cc: XEmacs Beta
Hi Stephen,
>>>>> "Stephen" == Stephen J Turnbull <stephen@xemacs.org> writes:
Stephen> Thanks for your report, Martin.
Any time. Thanks for the fix!
Stephen> The REPLACE semantics of j-c-insert-file-contents were
Stephen> simply wrong.
Stephen> This fixes that, and a couple of minor bugs [...]
Stephen> Caveat Emacsers. I have no idea whether this is correct
Stephen> for GNU Emacs.
Party time Emacsers: it does seem to fix the problem in GNU Emacs
21.3.
peace & happiness,
martin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Buffer corruption with jka-compr.el and revert-buffer
2003-05-26 23:50 ` Martin Schwenke
@ 2003-05-27 6:28 ` Martin Schwenke
0 siblings, 0 replies; 4+ messages in thread
From: Martin Schwenke @ 2003-05-27 6:28 UTC (permalink / raw)
>>>>> "Martin" == Martin Schwenke <martin@meltin.net> writes:
Stephen> The REPLACE semantics of j-c-insert-file-contents were
Stephen> simply wrong.
Stephen> This fixes that, and a couple of minor bugs [...]
Stephen> Caveat Emacsers. I have no idea whether this is correct
Stephen> for GNU Emacs.
Martin> Party time Emacsers: it does seem to fix the problem in
Martin> GNU Emacs 21.3.
Yikes, but not when the revert-buffer happens interactively. With the
fix, even when you tell revert-buffer not to prompt (via
(revert-buffer t t) or by setting revert-without-query), it prompts
but refuses to accept 'r' as an answer.
I'll play with this and try to figure out what is happening...
peace & happiness,
martin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-05-27 6:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-26 5:53 Buffer corruption with jka-compr.el and revert-buffer Martin Schwenke
2003-05-26 9:36 ` Stephen J. Turnbull
2003-05-26 23:50 ` Martin Schwenke
2003-05-27 6:28 ` Martin Schwenke
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).