* Run coding system auto-detection manually?
@ 2002-08-04 14:22 Kai Großjohann
2002-08-05 4:48 ` Eli Zaretskii
2002-08-06 9:50 ` Kai Großjohann
0 siblings, 2 replies; 14+ messages in thread
From: Kai Großjohann @ 2002-08-04 14:22 UTC (permalink / raw)
Suppose I have a buffer and hit C-x C-s. Then Emacs figures out a
coding system to use, possibly based on the filename.
But I would like to use write-region to write the buffer contents to
another file, but I would like this call to use the same coding
system that Emacs would have used for C-x C-s.
How do I do that?
kai
PS: Background info: In the write-region handler, Tramp first writes
the region to a local temp file and then transfers this temp file to
the remote host via scp (say). So the write-region handler needs
to use the right coding system when writing the temp file.
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-04 14:22 Run coding system auto-detection manually? Kai Großjohann
@ 2002-08-05 4:48 ` Eli Zaretskii
2002-08-05 10:43 ` Kai Großjohann
2002-08-06 9:50 ` Kai Großjohann
1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2002-08-05 4:48 UTC (permalink / raw)
Cc: emacs-devel
On Sun, 4 Aug 2002 Kai.Grossjohann@CS.Uni-Dortmund.DE wrote:
> But I would like to use write-region to write the buffer contents to
> another file, but I would like this call to use the same coding
> system that Emacs would have used for C-x C-s.
Perhaps this means that the place where "C-x C-s" computes the encoding
is not the right one. Perhaps there should be a function that does that
and calls write-region, and "C-x C-s" should call that function.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-05 4:48 ` Eli Zaretskii
@ 2002-08-05 10:43 ` Kai Großjohann
2002-08-06 1:50 ` Richard Stallman
0 siblings, 1 reply; 14+ messages in thread
From: Kai Großjohann @ 2002-08-05 10:43 UTC (permalink / raw)
Cc: emacs-devel
Eli Zaretskii <eliz@is.elta.co.il> writes:
> On Sun, 4 Aug 2002 Kai.Grossjohann@CS.Uni-Dortmund.DE wrote:
>
>> But I would like to use write-region to write the buffer contents to
>> another file, but I would like this call to use the same coding
>> system that Emacs would have used for C-x C-s.
>
> Perhaps this means that the place where "C-x C-s" computes the encoding
> is not the right one. Perhaps there should be a function that does that
> and calls write-region, and "C-x C-s" should call that function.
I think I found the answer. Are the following correct?
When the file is precious, Emacs already writes to a different file
first and then renames the file. Therefore, the spot where Emacs
invokes write-region if the file is precious must already take care
of this. At that spot, (the function called from) save-buffer just
passes the real file name as the LOCKNAME argument.
Therefore it is sufficient to pass the right filename as the LOCKNAME
argument and lookup in file-coding-system-alist and so on will use
that argument.
If this is really true, the documentation for write-region should be
updated to reflect this. I can do that if you like.
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-05 10:43 ` Kai Großjohann
@ 2002-08-06 1:50 ` Richard Stallman
2002-08-06 9:48 ` Kai Großjohann
0 siblings, 1 reply; 14+ messages in thread
From: Richard Stallman @ 2002-08-06 1:50 UTC (permalink / raw)
Cc: eliz, emacs-devel
When the file is precious, Emacs already writes to a different file
first and then renames the file. Therefore, the spot where Emacs
invokes write-region if the file is precious must already take care
of this. At that spot, (the function called from) save-buffer just
passes the real file name as the LOCKNAME argument.
I don't think write-region looks at the LOCKNAME argument in
deciding which coding system to use. I think it looks only at
the FILENAME argument.
Handa, do you think it looks at LOCKNAME?
Is this a bug in the handling of coding systems for precious files?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-06 1:50 ` Richard Stallman
@ 2002-08-06 9:48 ` Kai Großjohann
2002-08-07 14:23 ` Richard Stallman
0 siblings, 1 reply; 14+ messages in thread
From: Kai Großjohann @ 2002-08-06 9:48 UTC (permalink / raw)
Cc: eliz, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> When the file is precious, Emacs already writes to a different file
> first and then renames the file. Therefore, the spot where Emacs
> invokes write-region if the file is precious must already take care
> of this. At that spot, (the function called from) save-buffer just
> passes the real file name as the LOCKNAME argument.
>
> I don't think write-region looks at the LOCKNAME argument in
> deciding which coding system to use. I think it looks only at
> the FILENAME argument.
>
> Handa, do you think it looks at LOCKNAME?
>
> Is this a bug in the handling of coding systems for precious files?
I'm sorry, I confused LOCKNAME and VISIT. After looking again in
basic-save-buffer-2, I see the following call:
(write-region (point-min) (point-max)
tempname nil realname
buffer-file-truename)
This is in the "precious" case. So you can see that the real
filename is in the VISIT argument, not in the LOCKNAME argument. I
got those two confused before.
Presumably, the intent was that write-region choose the coding system
based on realname instead of tempname.
But looking in the code for write-region, I don't find any evidence
that it looks at VISIT, only at FILENAME, for detecting the coding
system. Hm.
Maybe in the above call, tempname has been devised in such a way that
choose_write_coding_system chooses the "right" coding.
I'm somewhat confused at the moment. Can somebody clear up the
confusion? Is there a bug (regarding VISIT instead of LOCKNAME), as
Richard suggests? Or does the code work right?
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-04 14:22 Run coding system auto-detection manually? Kai Großjohann
2002-08-05 4:48 ` Eli Zaretskii
@ 2002-08-06 9:50 ` Kai Großjohann
2002-08-07 8:24 ` Kenichi Handa
1 sibling, 1 reply; 14+ messages in thread
From: Kai Großjohann @ 2002-08-06 9:50 UTC (permalink / raw)
Kai.Grossjohann@cs.uni-dortmund.de (Kai Großjohann) writes:
> Suppose I have a buffer and hit C-x C-s. Then Emacs figures out a
> coding system to use, possibly based on the filename.
>
> But I would like to use write-region to write the buffer contents to
> another file, but I would like this call to use the same coding
> system that Emacs would have used for C-x C-s.
After reading the C code, I get the impression that I can always use
find-operation-coding-system explicitly to find the right coding
system to use. Right?
So I can use that if there is no magic in write-region?
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-06 9:50 ` Kai Großjohann
@ 2002-08-07 8:24 ` Kenichi Handa
2002-08-07 15:18 ` Kai Großjohann
2002-08-08 7:01 ` Richard Stallman
0 siblings, 2 replies; 14+ messages in thread
From: Kenichi Handa @ 2002-08-07 8:24 UTC (permalink / raw)
Cc: emacs-devel
In article <vafk7n4e2pj.fsf@INBOX.auto.emacs.devel.tok.lucy.cs.uni-dortmund.de>, Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:
> Kai.Grossjohann@cs.uni-dortmund.de (Kai Großjohann) writes:
>> Suppose I have a buffer and hit C-x C-s. Then Emacs figures out a
>> coding system to use, possibly based on the filename.
>>
>> But I would like to use write-region to write the buffer contents to
>> another file, but I would like this call to use the same coding
>> system that Emacs would have used for C-x C-s.
> After reading the C code, I get the impression that I can always use
> find-operation-coding-system explicitly to find the right coding
> system to use. Right?
find-operation-coding-system does only partial task for
deciding a coding system. For your task, I think you must
simulate what choose_write_coding_system does which includes
these things:
o check the local binding of buffer-file-coding-system
o check the value of enable-multibyte-characters
o call find-operation-coding-system
o call select-safe-coding-system-function
o if end-of-line format is still undecided, use that of
default-buffer-file-coding system
> (write-region (point-min) (point-max)
> tempname nil realname
> buffer-file-truename)
> This is in the "precious" case. So you can see that the real
> filename is in the VISIT argument, not in the LOCKNAME argument. I
> got those two confused before.
> Presumably, the intent was that write-region choose the coding system
> based on realname instead of tempname.
> But looking in the code for write-region, I don't find any evidence
> that it looks at VISIT, only at FILENAME, for detecting the coding
> system. Hm.
> Maybe in the above call, tempname has been devised in such a way that
> choose_write_coding_system chooses the "right" coding.
No, I don't think so. TEMPNAME may not match a pattern that
a user specified in file-coding-system-alist for REALNAME,
or TEMPNAME may match a pattern that a user specified for
the other kind of files.
So, for the case of a precious file, I think we must check
VISIT (if that is string) instead of FILENAME in
find-operation-coding-system. What do you think about the
this patch?
---
Ken'ichi HANDA
handa@etl.go.jp
*** coding.c.~1.252.~ Mon Jul 29 13:28:42 2002
--- coding.c Wed Aug 7 17:20:00 2002
***************
*** 6878,6883 ****
--- 6878,6890 ----
if (nargs < 1 + XINT (target_idx))
error ("Too few arguments for operation: %s",
SDATA (SYMBOL_NAME (operation)));
+ /* For write-region, if the 6th argument (i.e. VISIT, the 5th
+ argument to write-region) is string, it must be treated as a
+ target file name. */
+ if (EQ (operation, Qwrite_region)
+ && nargs > 5
+ && STRINGP (args[5]))
+ target_idx = 4;
target = args[XINT (target_idx) + 1];
if (!(STRINGP (target)
|| (EQ (operation, Qopen_network_stream) && INTEGERP (target))))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-06 9:48 ` Kai Großjohann
@ 2002-08-07 14:23 ` Richard Stallman
0 siblings, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2002-08-07 14:23 UTC (permalink / raw)
Cc: eliz, emacs-devel
This is in the "precious" case. So you can see that the real
filename is in the VISIT argument, not in the LOCKNAME argument. I
got those two confused before.
As far as I can tell, the code uses only the FILENAME argument for
computing the coding system, not VISIT or LOCKNAME.
After reading the C code, I get the impression that I can always use
find-operation-coding-system explicitly to find the right coding
system to use. Right?
Yes, I think you can do that. So you can probably solve this problem.
However, we may still have a bug in the handling of precious files.
Handa, if you could examine that code and see if it can misbehave,
that would be useful.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-07 8:24 ` Kenichi Handa
@ 2002-08-07 15:18 ` Kai Großjohann
2002-08-08 1:09 ` Kenichi Handa
2002-08-08 7:01 ` Richard Stallman
1 sibling, 1 reply; 14+ messages in thread
From: Kai Großjohann @ 2002-08-07 15:18 UTC (permalink / raw)
Cc: emacs-devel
Kenichi Handa <handa@etl.go.jp> writes:
> So, for the case of a precious file, I think we must check
> VISIT (if that is string) instead of FILENAME in
> find-operation-coding-system. What do you think about the
> this patch?
>
> ---
> Ken'ichi HANDA
> handa@etl.go.jp
>
>
> *** coding.c.~1.252.~ Mon Jul 29 13:28:42 2002
> --- coding.c Wed Aug 7 17:20:00 2002
> ***************
> *** 6878,6883 ****
> --- 6878,6890 ----
> if (nargs < 1 + XINT (target_idx))
> error ("Too few arguments for operation: %s",
> SDATA (SYMBOL_NAME (operation)));
> + /* For write-region, if the 6th argument (i.e. VISIT, the 5th
> + argument to write-region) is string, it must be treated as a
> + target file name. */
> + if (EQ (operation, Qwrite_region)
> + && nargs > 5
> + && STRINGP (args[5]))
> + target_idx = 4;
> target = args[XINT (target_idx) + 1];
> if (!(STRINGP (target)
> || (EQ (operation, Qopen_network_stream) && INTEGERP (target))))
How about, instead of hard-coding the write-region operation,
find-operation-coding-system is extended so that the target-idx
property can express the rule?
If Fget (operation, Qtarget_idx) returns a cons, one could eval it and
assume that the result would be an integer to use. Then the
target-idx property for write-region could be (if (stringp visit) 5 3)
or something like that.
What do you think? (I don't mean the concrete suggestion, it might
well turn out to be rubbish. I mean the idea to make the decision in
find-operation-coding-system configurable from Lisp.)
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-07 15:18 ` Kai Großjohann
@ 2002-08-08 1:09 ` Kenichi Handa
0 siblings, 0 replies; 14+ messages in thread
From: Kenichi Handa @ 2002-08-08 1:09 UTC (permalink / raw)
Cc: emacs-devel
In article <vafhei6puib.fsf@INBOX.auto.emacs.devel.tok.lucy.cs.uni-dortmund.de>, Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Gro�johann) writes:
> How about, instead of hard-coding the write-region operation,
> find-operation-coding-system is extended so that the target-idx
> property can express the rule?
> If Fget (operation, Qtarget_idx) returns a cons, one could eval it and
> assume that the result would be an integer to use. Then the
> target-idx property for write-region could be (if (stringp visit) 5 3)
> or something like that.
> What do you think? (I don't mean the concrete suggestion, it might
> well turn out to be rubbish. I mean the idea to make the decision in
> find-operation-coding-system configurable from Lisp.)
I'm not sure it's worth making find-operation-coding-system
configurable in that way. Even if it is, I think the above
method is too indirect for the purpose of configuring
find-operation-coding-system.
If a Lisp program wants find-operation-coding-system to
choose a different target from the arguments than normal
case, it can call find-operation-coding-system just with
different arguments.
---
Ken'ichi HANDA
handa@etl.go.jp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-07 8:24 ` Kenichi Handa
2002-08-07 15:18 ` Kai Großjohann
@ 2002-08-08 7:01 ` Richard Stallman
2002-08-08 8:48 ` Kai Großjohann
2002-08-08 12:45 ` Kenichi Handa
1 sibling, 2 replies; 14+ messages in thread
From: Richard Stallman @ 2002-08-08 7:01 UTC (permalink / raw)
Cc: Kai.Grossjohann, emacs-devel
So, for the case of a precious file, I think we must check
VISIT (if that is string) instead of FILENAME in
find-operation-coding-system. What do you think about the
this patch?
It seems right to me.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-08 7:01 ` Richard Stallman
@ 2002-08-08 8:48 ` Kai Großjohann
2002-08-08 12:45 ` Kenichi Handa
1 sibling, 0 replies; 14+ messages in thread
From: Kai Großjohann @ 2002-08-08 8:48 UTC (permalink / raw)
Cc: handa, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> So, for the case of a precious file, I think we must check
> VISIT (if that is string) instead of FILENAME in
> find-operation-coding-system. What do you think about the
> this patch?
>
> It seems right to me.
Will there be a way for Tramp to decide whether the fix is in Emacs
already? If at all possible, it would be great if the same version
of Tramp worked on older Emacsen, the new Emacs, and XEmacs.
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-08 7:01 ` Richard Stallman
2002-08-08 8:48 ` Kai Großjohann
@ 2002-08-08 12:45 ` Kenichi Handa
2002-08-08 13:12 ` Kai Großjohann
1 sibling, 1 reply; 14+ messages in thread
From: Kenichi Handa @ 2002-08-08 12:45 UTC (permalink / raw)
Cc: Kai.Grossjohann, emacs-devel
In article <200208080701.g7871vx04204@wijiji.santafe.edu>, Richard Stallman <rms@gnu.org> writes:
> So, for the case of a precious file, I think we must check
> VISIT (if that is string) instead of FILENAME in
> find-operation-coding-system. What do you think about the
> this patch?
> It seems right to me.
Ok, I've just installed it for RC and HEAD.
In article <vafhei54tyf.fsf@INBOX.auto.emacs.devel.tok.lucy.cs.uni-dortmund.de>, Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Gro�johann) writes:
> Will there be a way for Tramp to decide whether the fix is in Emacs
> already? If at all possible, it would be great if the same version
> of Tramp worked on older Emacsen, the new Emacs, and XEmacs.
How about this?
(let ((file-coding-system-alist '(("test" emacs-mule))))
(find-operation-coding-system 'write-region 0 0 "" nil "test"))
If it returns non-nil, the fix is in Emacs already.
---
Ken'ichi HANDA
handa@etl.go.jp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Run coding system auto-detection manually?
2002-08-08 12:45 ` Kenichi Handa
@ 2002-08-08 13:12 ` Kai Großjohann
0 siblings, 0 replies; 14+ messages in thread
From: Kai Großjohann @ 2002-08-08 13:12 UTC (permalink / raw)
Cc: rms, emacs-devel
Kenichi Handa <handa@etl.go.jp> writes:
> How about this?
>
> (let ((file-coding-system-alist '(("test" emacs-mule))))
> (find-operation-coding-system 'write-region 0 0 "" nil "test"))
>
> If it returns non-nil, the fix is in Emacs already.
Very nice! I've included some code in Tramp, so that I can easily
use this test when I get around to it.
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2002-08-08 13:12 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-04 14:22 Run coding system auto-detection manually? Kai Großjohann
2002-08-05 4:48 ` Eli Zaretskii
2002-08-05 10:43 ` Kai Großjohann
2002-08-06 1:50 ` Richard Stallman
2002-08-06 9:48 ` Kai Großjohann
2002-08-07 14:23 ` Richard Stallman
2002-08-06 9:50 ` Kai Großjohann
2002-08-07 8:24 ` Kenichi Handa
2002-08-07 15:18 ` Kai Großjohann
2002-08-08 1:09 ` Kenichi Handa
2002-08-08 7:01 ` Richard Stallman
2002-08-08 8:48 ` Kai Großjohann
2002-08-08 12:45 ` Kenichi Handa
2002-08-08 13:12 ` Kai Großjohann
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.