* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
@ 2008-10-08 16:15 Chong Yidong
2008-10-08 18:03 ` martin rudalics
0 siblings, 1 reply; 8+ messages in thread
From: Chong Yidong @ 2008-10-08 16:15 UTC (permalink / raw)
To: martin rudalics; +Cc: 1039
> 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?
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
2008-10-08 16:15 bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer Chong Yidong
@ 2008-10-08 18:03 ` martin rudalics
2008-10-11 22:10 ` Peter De Wachter
0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2008-10-08 18:03 UTC (permalink / raw)
To: Chong Yidong; +Cc: 1039, Peter De Wachter
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
2008-10-08 18:03 ` martin rudalics
@ 2008-10-11 22:10 ` Peter De Wachter
2008-10-12 18:48 ` martin rudalics
0 siblings, 1 reply; 8+ messages in thread
From: Peter De Wachter @ 2008-10-11 22:10 UTC (permalink / raw)
To: martin rudalics; +Cc: Chong Yidong, 1039
On Wed, 08 Oct 2008 20:03:09 +0200
martin rudalics <rudalics@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
2008-10-11 22:10 ` Peter De Wachter
@ 2008-10-12 18:48 ` martin rudalics
2008-10-13 19:53 ` Peter De Wachter
0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2008-10-12 18:48 UTC (permalink / raw)
To: Peter De Wachter; +Cc: Chong Yidong, 1039, Kenichi Handa
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
2008-10-12 18:48 ` martin rudalics
@ 2008-10-13 19:53 ` Peter De Wachter
0 siblings, 0 replies; 8+ messages in thread
From: Peter De Wachter @ 2008-10-13 19:53 UTC (permalink / raw)
To: martin rudalics, Chong Yidong, 1039
On Sun, 12 Oct 2008 20:48:45 +0200
martin rudalics <rudalics@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
@ 2009-01-29 4:20 Kenichi Handa
0 siblings, 0 replies; 8+ messages in thread
From: Kenichi Handa @ 2009-01-29 4:20 UTC (permalink / raw)
To: 1039; +Cc: cyd, rfrancoise, pdewacht, handa
> 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@m17n.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
@ 2008-09-27 21:15 Peter De Wachter
2008-09-27 22:12 ` martin rudalics
0 siblings, 1 reply; 8+ messages in thread
From: Peter De Wachter @ 2008-09-27 21:15 UTC (permalink / raw)
To: emacs-pretest-bug; +Cc: rfrancoise
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
2008-09-27 21:15 Peter De Wachter
@ 2008-09-27 22:12 ` martin rudalics
0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2008-09-27 22:12 UTC (permalink / raw)
To: Peter De Wachter, 1039; +Cc: rfrancoise
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
> 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
[-- Attachment #2: revert.diff --]
[-- Type: text/plain, Size: 4649 bytes --]
*** 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-01-29 4:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-08 16:15 bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer Chong Yidong
2008-10-08 18:03 ` martin rudalics
2008-10-11 22:10 ` Peter De Wachter
2008-10-12 18:48 ` martin rudalics
2008-10-13 19:53 ` Peter De Wachter
-- strict thread matches above, loose matches on Subject: below --
2009-01-29 4:20 Kenichi Handa
2008-09-27 21:15 Peter De Wachter
2008-09-27 22:12 ` martin rudalics
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).