* How to overwrite completely a buffer with a file, with overwriting also the coding system ?
@ 2009-05-08 21:07 Vincent Belaïche
2009-05-09 7:01 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Vincent Belaïche @ 2009-05-08 21:07 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 3083 bytes --]
Dear emacs experts,
I am raising a question to this group: I have a problem with the emacs-template extension package used in conjunction with GNU-Emacs and with my MS-Windows-machine.
When I create a new target-file from a template, emacs-template creates a buffer for this target-file, which therefore is created with the default coding-system (iso-latin-1-dos for my machine), and then emacs-template insert into this buffer the content of the template file. Now I want that the file be created with iso-latin-1-unix coding. Even though the template file contains a -*- coding: iso-latin-1-unix -*- the target file is created with dos end-of-lines. This means that after saving and reopening the file I get all those CR at end of lines.
Christoph Wedler told me that the code of emacs-template does not have this problem with XEmacs.
I found a hack that works for me. The current mal-functionning function is the following (current buffer is the buffer for target file, and filename is the name of file containing the template):
(defun template-find-template (filename &optional replace)
(let ((file-name-buffer-file-type-alist nil)) ; Emacs on DOS/NT
(if replace
(insert-file-contents filename nil nil nil
;; 5th arg not t with empty accessible part
;; (XEmacs bug workaround: would infloop)
(> (point-max) (point-min)))
(let ((template-auto-insert nil))
(switch-to-buffer (find-file-noselect filename))))))
I replaced it as follows with use of revert-buffer, and this seems to partially solve the problem for me (actually there is still an issue with the created buffer being not marked as modified untill some editing occurs).
(let ((file-name-buffer-file-type-alist nil)) ; Emacs on DOS/NT
(if replace
(progn
(let ((buffer-file-name filename)
(buffer-file-truename (abbreviate-file-name (file-truename filename))))
(revert-buffer nil t t)
(clear-visited-file-modtime))
(set-buffer-modified-p t))
(let ((template-auto-insert nil))
(switch-to-buffer (find-file-noselect filename))))))
We both agree with Christoph that this code is hacky and is probably not very portable and future-proof. I am calling for your expertise: what would be the correct way to do this ?
I am considering another trick that would basically consist in saving the target file, reopen it, and then replace all the CR by an empty string, but I don't like it either, because in my opinion the buffer for target file shall not be saved until the user request it (although in the template creation process, the existence of the target file is already tested at this point, and the user already has accepted to overwrite it ...)
Very best regards,
Vincent.
_________________________________________________________________
Vous voulez savoir ce que vous pouvez faire avec le nouveau Windows Live ? Lancez-vous !
http://www.microsoft.com/windows/windowslive/default.aspx
[-- Attachment #2: Type: text/html, Size: 3880 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to overwrite completely a buffer with a file, with overwriting also the coding system ?
2009-05-08 21:07 How to overwrite completely a buffer with a file, with overwriting also the coding system ? Vincent Belaïche
@ 2009-05-09 7:01 ` Eli Zaretskii
2009-05-09 9:23 ` Eli Zaretskii
2009-05-09 19:04 ` Vincent Belaïche
0 siblings, 2 replies; 4+ messages in thread
From: Eli Zaretskii @ 2009-05-09 7:01 UTC (permalink / raw)
To: Vincent Belaïche; +Cc: emacs-devel
> From: =?iso-8859-1?Q?Vincent_Bela=EFche?= <vincent.b.1@hotmail.fr>
> Date: Fri, 8 May 2009 23:07:44 +0200
>
> When I create a new target-file from a template, emacs-template creates a buffer for this target-file, which therefore is created with the default coding-system (iso-latin-1-dos for my machine), and then emacs-template insert into this buffer the content of the template file. Now I want that the file be created with iso-latin-1-unix coding. Even though the template file contains a -*- coding: iso-latin-1-unix -*- the target file is created with dos end-of-lines.
What Emacs version is this? I think Emacs 23 will ask the user for
confirmation if the `coding:' cookie disagrees with the buffer's
encoding.
In any case, if you call the `find-auto-coding' function right after
inserting the template, this function will tell you what encoding
should the buffer use, taking into account the file's name and the
`coding:' cookie. You can then set the right encoding by calling
`set-buffer-file-coding-system'.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to overwrite completely a buffer with a file, with overwriting also the coding system ?
2009-05-09 7:01 ` Eli Zaretskii
@ 2009-05-09 9:23 ` Eli Zaretskii
2009-05-09 19:04 ` Vincent Belaïche
1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2009-05-09 9:23 UTC (permalink / raw)
To: vincent.b.1, emacs-devel
> Date: Sat, 09 May 2009 10:01:15 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: emacs-devel@gnu.org
>
> In any case, if you call the `find-auto-coding' function right after
> inserting the template, this function will tell you what encoding
> should the buffer use, taking into account the file's name and the
> `coding:' cookie. You can then set the right encoding by calling
> `set-buffer-file-coding-system'.
Better yet, use `set-auto-coding'. It will call `find-auto-coding'
for you, and return a coding system ready to be used.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: How to overwrite completely a buffer with a file, with overwriting also the coding system ?
2009-05-09 7:01 ` Eli Zaretskii
2009-05-09 9:23 ` Eli Zaretskii
@ 2009-05-09 19:04 ` Vincent Belaïche
1 sibling, 0 replies; 4+ messages in thread
From: Vincent Belaïche @ 2009-05-09 19:04 UTC (permalink / raw)
To: eliz; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1770 bytes --]
I have a version 23.xxx Emacs, and I do get the message about the coding that disagree with the buffer.
I will try what you propose in this message and the next one and let you know if this solves the issue.
Thanks for the information !!
Vincent.
> Date: Sat, 9 May 2009 10:01:15 +0300
> From: eliz@gnu.org
> To: vincent.b.1@hotmail.fr
> CC: emacs-devel@gnu.org
> Subject: Re: How to overwrite completely a buffer with a file, with overwriting also the coding system ?
>
> > From: =?iso-8859-1?Q?Vincent_Bela=EFche?= <vincent.b.1@hotmail.fr>
> > Date: Fri, 8 May 2009 23:07:44 +0200
> >
> > When I create a new target-file from a template, emacs-template creates a buffer for this target-file, which therefore is created with the default coding-system (iso-latin-1-dos for my machine), and then emacs-template insert into this buffer the content of the template file. Now I want that the file be created with iso-latin-1-unix coding. Even though the template file contains a -*- coding: iso-latin-1-unix -*- the target file is created with dos end-of-lines.
>
> What Emacs version is this? I think Emacs 23 will ask the user for
> confirmation if the `coding:' cookie disagrees with the buffer's
> encoding.
>
> In any case, if you call the `find-auto-coding' function right after
> inserting the template, this function will tell you what encoding
> should the buffer use, taking into account the file's name and the
> `coding:' cookie. You can then set the right encoding by calling
> `set-buffer-file-coding-system'.
>
>
_________________________________________________________________
Découvrez toutes les possibilités de communication avec vos proches
http://www.microsoft.com/windows/windowslive/default.aspx
[-- Attachment #2: Type: text/html, Size: 2089 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-09 19:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-08 21:07 How to overwrite completely a buffer with a file, with overwriting also the coding system ? Vincent Belaïche
2009-05-09 7:01 ` Eli Zaretskii
2009-05-09 9:23 ` Eli Zaretskii
2009-05-09 19:04 ` Vincent Belaïche
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).