From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.help Subject: Re: `write-region' writes different bytes than passed to it? Date: Tue, 11 Dec 2018 13:42:59 +0100 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1544532097 19672 195.159.176.226 (11 Dec 2018 12:41:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Dec 2018 12:41:37 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 11 13:41:33 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWhLx-00053L-BC for geh-help-gnu-emacs@m.gmane.org; Tue, 11 Dec 2018 13:41:33 +0100 Original-Received: from localhost ([::1]:37807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWhO3-0000RP-Qw for geh-help-gnu-emacs@m.gmane.org; Tue, 11 Dec 2018 07:43:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWhNZ-0000R9-Tf for help-gnu-emacs@gnu.org; Tue, 11 Dec 2018 07:43:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWhNZ-0000q5-5i for help-gnu-emacs@gnu.org; Tue, 11 Dec 2018 07:43:13 -0500 Original-Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]:40114) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWhNY-0000oY-W5 for help-gnu-emacs@gnu.org; Tue, 11 Dec 2018 07:43:13 -0500 Original-Received: by mail-ot1-x332.google.com with SMTP id s5so13834690oth.7 for ; Tue, 11 Dec 2018 04:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=LKJdrlExzghRNl+KCfb2uyGb5iKppRqzy/14xoZzThE=; b=eCmyL/weJXZ9e5RTl588JBooLYdpmIesUsmPpuOsDmf+lCBpyyNl9hGdgCCTZXZi9e kHzrcBV5cqO6S2a7yYH06rMlU9mqdeQhNRBrCW6Iu7qOwK8H1xTjDgF6R7NdaktMX7TP VF0BJHdsssT2ydtvASNHtIyW9C/8tMv5+KBE++cyz/Ygry+pc398+nlj1oO14xlV68gH I1EFlY/DP5nMSRGS2L98WrflANg65zAJzoDiGkzlsSVcwHPlRId6zE/I2d9BdNDNA+DY hCKiwN1m/X55c95T2FBMa+uGq4Uv1o8RmJNTXX+RLFPXWZ6zYxAMr7uG4qrTRI+38Axq uw2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=LKJdrlExzghRNl+KCfb2uyGb5iKppRqzy/14xoZzThE=; b=QoeisBdUbrasyHXP8RzZnsQ/2I5SRO06crog1+mbvhJmRq+mu584KXU00kT6BxftFr 51aCD+x3BYWBnFAP6TjrhCgy1md80GbAAwtj2A35P7GLhVlFKEsXeycUdMmR7KvgZyQs BVAaO1/LIERVpPrIk9SxvVAhIZh7Cc1n4XlX27Lbnd8YV2AxJmoPTBj42kXqQv+kbRfm 9AC5HZiGgWsqtw8aCMzQv7s2BeU2xFpkg7o4d6ZKA2m1mzn8nM+J/+GZgaBQ8i/boiRI IQLQ5+ZqF/+Sj82MsQ1SpE2mCgcX3HPpHK/KyLM2FntXcKyL9J+IrPNtugJmOu0vTgPd mxpg== X-Gm-Message-State: AA+aEWbQvH/SPufC+KDRII7wzuGy+K+sPNTbf6paOt0Ht3x9xYdv8qw6 jX4vSjldTZu0Xfq8dMyZ0TfsHCWGPDIwPjIdNrVBcF85 X-Google-Smtp-Source: AFSGD/UlzeMvVG72NdjuXBjsuK+MyaHw+rPw61l5U19lfW1Y7OJMi0/+1PzecWCdUPK8As3WNlj1RxEBdI5uEleCPWo= X-Received: by 2002:a9d:4549:: with SMTP id p9mr10669245oti.51.1544532191444; Tue, 11 Dec 2018 04:43:11 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::332 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118963 Archived-At: Am Di., 11. Dez. 2018 um 13:30 Uhr schrieb Philipp Stephani : > > Hi, > > usually `write-region' uses the coding system bound to > `coding-system-for-write'. However, I've found a case where this > doesn't seem to be the case: > > $ emacs -Q -batch -eval '(let ((coding-system-for-write (quote > utf-8-unix))) (write-region "\xC1\xB2" nil "/tmp/test.txt"))' && hd > /tmp/test.txt > 00000000 f2 |.| > 00000001 > > That is, instead of the byte sequence C1 B2 it writes the single byte > F2, which is an invalid UTF-8 sequence. Is that expected? I've realized that I can use either string-to-multibyte or string-as-multibyte to force writing the expected bytes. Still it seems weird that when confronted with an invalid UTF-8 sequence `write-region' occasionally writes a *different* invalid UTF-8 sequence.