GNU bug report logs -
#1039
23.0.60; emacs forgets EOL convention after revert-buffer
Previous Next
Reported by: pdewacht <at> gmail.com (Peter De Wachter)
Date: Sat, 27 Sep 2008 21:25:03 UTC
Severity: normal
Tags: patch
Done: Chong Yidong <cyd <at> stupidchicken.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 1039 in the body.
You can then email your comments to 1039 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
pdewacht <at> gmail.com (Peter De Wachter)
:
New bug report received and forwarded. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
If you load a file with DOS line endings, and revert it with M-x
revert-buffer, emacs forgets the used EOL convention and will use
Unix line endings when writing the file.
In GNU Emacs 23.0.60.1 (x86_64-pc-linux-gnu, GTK+ Version 2.12.11)
of 2008-09-19 on elegiac, modified by Debian
(emacs-snapshot package, version 1:20080919-1)
configured using `configure '--build' 'x86_64-linux-gnu' '--host' 'x86_64-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/23.0.60/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.0.60/site-lisp:/usr/share/emacs/site-lisp' '--with-x=yes' '--with-x-toolkit=gtk' 'build_alias=x86_64-linux-gnu' 'host_alias=x86_64-linux-gnu' 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g -Wl,--as-needed' 'CPPFLAGS=''
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: nil
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: nl_BE.UTF-8
value of $XMODIFIERS: nil
locale-coding-system: utf-8-unix
default-enable-multibyte-characters: t
Major mode: Fundamental
Minor modes in effect:
tooltip-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
global-auto-composition-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Recent input:
C-x C-f f o o RET ESC x r e v e r t RET y e s RET ESC
x r e p o r t - b u g TAB RET
Recent messages:
("emacs-snapshot" "-Q")
For information about GNU Emacs and the GNU system, type C-h C-a.
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
martin rudalics <rudalics <at> gmx.at>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #10 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
[Message part 1 (text/plain, inline)]
> If you load a file with DOS line endings, and revert it with M-x
> revert-buffer, emacs forgets the used EOL convention and will use
> Unix line endings when writing the file.
The inverse scenario of this is biting me for some time already.
I'm currently using the attached patch.
martin
[revert.diff (text/plain, inline)]
*** files.el.~1.999.~ 2008-09-22 07:39:31.937500000 +0200
--- files.el 2008-09-26 13:49:18.968750000 +0200
***************
*** 4437,4442 ****
--- 4437,4443 ----
mechanism, this hook is not used.")
(defvar revert-buffer-internal-hook)
+ (defvar revert-buffer-file-coding-system)
(defun revert-buffer (&optional ignore-auto noconfirm preserve-modes)
"Replace current buffer text with the text of the visited file on disk.
***************
*** 4558,4571 ****
;; (called from insert-file-contents) to set
;; buffer-file-coding-system to a proper value.
(kill-local-variable 'buffer-file-coding-system)
!
;; Note that this preserves point in an intelligent way.
(if preserve-modes
(let ((buffer-file-format buffer-file-format))
(insert-file-contents file-name (not auto-save-p)
nil nil t))
(insert-file-contents file-name (not auto-save-p)
! nil nil t)))))
;; Recompute the truename in case changes in symlinks
;; have changed the truename.
(setq buffer-file-truename
--- 4559,4578 ----
;; (called from insert-file-contents) to set
;; buffer-file-coding-system to a proper value.
(kill-local-variable 'buffer-file-coding-system)
! ;; But in case something goes wrong there provide a
! ;; fallback coding system.
! (setq revert-buffer-file-coding-system
! (list revert-buffer-file-coding-system))
;; Note that this preserves point in an intelligent way.
(if preserve-modes
(let ((buffer-file-format buffer-file-format))
(insert-file-contents file-name (not auto-save-p)
nil nil t))
(insert-file-contents file-name (not auto-save-p)
! nil nil t))
! ;; Remember this.
! (setq revert-buffer-file-coding-system
! buffer-file-coding-system))))
;; Recompute the truename in case changes in symlinks
;; have changed the truename.
(setq buffer-file-truename
*** international/mule.el.~1.274.~ 2008-07-31 07:33:47.000000000 +0200
--- international/mule.el 2008-09-26 13:55:52.640625000 +0200
***************
*** 1146,1151 ****
--- 1146,1163 ----
(put (intern name) 'coding-system-define-form form)
(setq coding-system-alist (cons (list name) coding-system-alist)))))
+ ;;; This is nil initially, set to `buffer-file-coding-system' when the
+ ;;; latter is set, and to a list with that value as its only element
+ ;;; when the buffer shall be reverted. `after-insert-file-set-coding'
+ ;;; will use this value when `find-new-buffer-file-coding-system' does
+ ;;; not provide a useful value.
+ (defvar revert-buffer-file-coding-system nil
+ "The file coding system usable for reverting a buffer.
+ Internally used by when reverting a buffer and no other coding
+ system is provided.")
+ (make-variable-buffer-local 'revert-buffer-file-coding-system)
+ (put 'revert-buffer-file-coding-system 'permanent-local t)
+
(defun set-buffer-file-coding-system (coding-system &optional force nomodify)
"Set the file coding-system of the current buffer to CODING-SYSTEM.
This means that when you save the buffer, it will be converted
***************
*** 1169,1174 ****
--- 1181,1188 ----
(setq coding-system
(merge-coding-systems coding-system buffer-file-coding-system)))
(setq buffer-file-coding-system coding-system)
+ ;; And record its value here.
+ (setq revert-buffer-file-coding-system coding-system)
;; This is in case of an explicit call. Normally, `normal-mode' and
;; `set-buffer-major-mode-hook' take care of setting the table.
(if (fboundp 'ucs-set-table-for-input) ; don't lose when building
***************
*** 1860,1866 ****
(setq buffer-file-coding-system-explicit coding-system-for-read))
(if last-coding-system-used
(let ((coding-system
! (find-new-buffer-file-coding-system last-coding-system-used)))
(when coding-system
;; Tell set-buffer-file-coding-system not to mark the file
;; as modified; we just read it, and it's supposed to be unmodified.
--- 1874,1883 ----
(setq buffer-file-coding-system-explicit coding-system-for-read))
(if last-coding-system-used
(let ((coding-system
! (or (find-new-buffer-file-coding-system last-coding-system-used)
! ;; Use the coding system before revertin the buffer if
! ;; we have nothing newer.
! (car-safe revert-buffer-file-coding-system))))
(when coding-system
;; Tell set-buffer-file-coding-system not to mark the file
;; as modified; we just read it, and it's supposed to be unmodified.
Tags added: patch
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> emacsbugs.donarmstrong.com
.
(Tue, 30 Sep 2008 07:15:03 GMT)
Full text and
rfc822 format available.
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
Chong Yidong <cyd <at> stupidchicken.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #17 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
> The inverse scenario of this is biting me for some time already. I'm
> currently using the attached patch.
I don't understand the need for the revert-buffer-file-coding-system
variable. Why doesn't last-coding-system-used work here?
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
martin rudalics <rudalics <at> gmx.at>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #22 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
> I don't understand the need for the revert-buffer-file-coding-system
> variable. Why doesn't last-coding-system-used work here?
I suppose it's because of the intelligent point preserving behavior of
`revert-buffer'. When buffer and file don't differ (modulo decoding)
nothing gets inserted. OTOH Handa kills `buffer-file-coding-system' in
`revert-buffer' since 2002 so the old value is lost and Emacs goes for
the default value instead. I don't understand though why the problem
became virulent only lately.
In any case it would be helpful if the OP tested whether my patch works
for him ;-)
martin
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
Peter De Wachter <pdewacht <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #27 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Wed, 08 Oct 2008 20:03:09 +0200
martin rudalics <rudalics <at> gmx.at> wrote:
> In any case it would be helpful if the OP tested whether my patch
> works for him ;-)
That patch fixes the bug I reported, but it creates a new one: if you
change the EOL convention outside of emacs, revert-buffer no longer
detects this. To reproduce:
printf "hello\r\nworld\r\n" > hello
emacs -Q hello &
printf "hello\rworld\r" > hello
M-x revert-buffer
# emacs still sees DOS newlines
--
Peter De Wachter
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
martin rudalics <rudalics <at> gmx.at>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #32 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
> That patch fixes the bug I reported, but it creates a new one:
Are you sure that this worked _before_ my patch?
> if you
> change the EOL convention outside of emacs, revert-buffer no longer
> detects this.
Indeed. BTW, can you confirm that when you delete the entire buffer
text first reverting works correctly? Unfortunately, I don't understand
this part of `insert-file-contents' at all. I suppose Emacs should
redecode when it finds out that the eol-types of the buffer and the part
of the file it has already read differ. But somehow this doesn't
happen. Handa-san do you have any ideas?
martin
Information forwarded to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
Full text and
rfc822 format available.
Acknowledgement sent to
Peter De Wachter <pdewacht <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
Full text and
rfc822 format available.
Message #37 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Sun, 12 Oct 2008 20:48:45 +0200
martin rudalics <rudalics <at> gmx.at> wrote:
> > That patch fixes the bug I reported, but it creates a new one:
>
> Are you sure that this worked _before_ my patch?
Hm, I must have tried it with Emacs 22. It doesn't work in 23. Too many
versions to juggle around. Sorry for the confusion.
> > if you
> > change the EOL convention outside of emacs, revert-buffer no longer
> > detects this.
>
> Indeed. BTW, can you confirm that when you delete the entire buffer
> text first reverting works correctly? Unfortunately, I don't
Yes, it works if I clear the buffer first, both with and without your
patch.
> understand this part of `insert-file-contents' at all. I suppose
> Emacs should redecode when it finds out that the eol-types of the
> buffer and the part of the file it has already read differ. But
> somehow this doesn't happen. Handa-san do you have any ideas?
--
Peter De Wachter
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#1039
; Package
emacs
.
(Thu, 29 Jan 2009 04:30:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Kenichi Handa <handa <at> m17n.org>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 29 Jan 2009 04:30:03 GMT)
Full text and
rfc822 format available.
Message #42 received at 1039 <at> emacsbugs.donarmstrong.com (full text, mbox):
> If you load a file with DOS line endings, and revert it with M-x
> revert-buffer, emacs forgets the used EOL convention and will use
> Unix line endings when writing the file.
This problem is already fixed.
> That patch fixes the bug I reported, but it creates a new one: if you
> change the EOL convention outside of emacs, revert-buffer no longer
> detects this. To reproduce:
>
> printf "hello\r\nworld\r\n" > hello
> emacs -Q hello &
> printf "hello\rworld\r" > hello
> M-x revert-buffer
> # emacs still sees DOS newlines
This is already fixed too.
But, the problem is the case that you load "hello" by explicitly
specifying dos coding system, or you once save the file by dos coding
sytem before reverting. In this case, Emacs respects your
specification, and thus revert-buffer loads the file as dos coding
system, which results in seeing many CR charaters in the above case.
We think this behaviour is not a bug but a feature.
---
Kenichi Handa
handa <at> m17n.org
bug closed, send any further explanations to pdewacht <at> gmail.com (Peter De Wachter)
Request was from
Chong Yidong <cyd <at> stupidchicken.com>
to
control <at> emacsbugs.donarmstrong.com
.
(Thu, 29 Jan 2009 05:35:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> emacsbugs.donarmstrong.com
.
(Thu, 26 Feb 2009 15:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 16 years and 174 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.