emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run coding system auto-detection manually?


From: Kenichi Handa
Subject: Re: Run coding system auto-detection manually?
Date: Wed, 7 Aug 2002 17:24:55 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.1.30 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

In article <address@hidden>, address@hidden (Kai Großjohann) writes:
> address@hidden (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
address@hidden


*** 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))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]