unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Kenichi Handa <handa@etl.go.jp>
Cc: emacs-devel@gnu.org
Subject: Re: Run coding system auto-detection manually?
Date: Wed, 7 Aug 2002 17:24:55 +0900 (JST)	[thread overview]
Message-ID: <200208070824.RAA17705@etlken.m17n.org> (raw)
In-Reply-To: vafk7n4e2pj.fsf@INBOX.auto.emacs.devel.tok.lucy.cs.uni-dortmund.de

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

  reply	other threads:[~2002-08-07  8:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=200208070824.RAA17705@etlken.m17n.org \
    --to=handa@etl.go.jp \
    --cc=emacs-devel@gnu.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).