unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Peter De Wachter <pdewacht@gmail.com>, 1039@emacsbugs.donarmstrong.com
Cc: rfrancoise@debian.org
Subject: bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer
Date: Sun, 28 Sep 2008 00:12:14 +0200	[thread overview]
Message-ID: <48DEAFBE.1080806@gmx.at> (raw)
In-Reply-To: <20080927211548.AF7DC1628122@tleilaxu>

[-- 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.

  reply	other threads:[~2008-09-27 22:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-27 21:15 bug#1039: 23.0.60; emacs forgets EOL convention after revert-buffer Peter De Wachter
2008-09-27 22:12 ` martin rudalics [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-10-08 16:15 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
2009-01-29  4:20 Kenichi Handa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48DEAFBE.1080806@gmx.at \
    --to=rudalics@gmx.at \
    --cc=1039@emacsbugs.donarmstrong.com \
    --cc=pdewacht@gmail.com \
    --cc=rfrancoise@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).