From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner Newsgroups: gmane.emacs.devel Subject: Re: How to get buffer byte length (not number of characters)? Date: Mon, 26 Aug 2024 21:48:02 -0700 Message-ID: <87h6b6bmgt.fsf@ushin.org> References: <87wmkbekjp.fsf@ushin.org> <86o75nwilg.fsf@gnu.org> <87mskz7ps2.fsf@ushin.org> <87ikvn7p7z.fsf@ushin.org> <86mskzjzpd.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9043"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Aug 27 12:51:33 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sitnP-00027W-V0 for ged-emacs-devel@m.gmane-mx.org; Tue, 27 Aug 2024 12:51:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sitmk-00063f-ST; Tue, 27 Aug 2024 06:50:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sio7s-0007r2-PQ for emacs-devel@gnu.org; Tue, 27 Aug 2024 00:48:16 -0400 Original-Received: from out-171.mta1.migadu.com ([2001:41d0:203:375::ab]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sio7q-0002j7-Pk for emacs-devel@gnu.org; Tue, 27 Aug 2024 00:48:16 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ushin.org; s=key1; t=1724734088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AXj+g5rII1GD/JVM0yb1QsiLWXD6FN8LYE8Elm3sH8E=; b=p4lFF5S1dZbaJbl7lgDRFWICsQir6E78EPyCZfWDCSTAkNmF+lVlmsMVhLrmsuTtdM3J+K 4C0Zuk2lUxVHcVzF9/6aUzfZEx9IAtP1KHo1Dzt2B36Ruol2oofZuEMcpJt3CECCaIQdZx vPgfv0H3HxDaikY9CGzFSxi8wRHDBhJAfhG/LVc0ZjLwjysJf2bFWNggp/vuogy6hcFlrE yuHiY0x/IEVtUOTM2hVZIYoSQcx6ZTf7AxdWF39WMu79YXeM3+Csp6xplVGjjeps7XimnS JUf3nDJA+h5WZe+50tkp48uOk2c1n77POpWu0h4Hj3ZTjpOplRAfB0f1dpxeGA== In-Reply-To: <86mskzjzpd.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 26 Aug 2024 14:22:38 +0300") X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::ab; envelope-from=joseph@ushin.org; helo=out-171.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 27 Aug 2024 06:50:48 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323137 Archived-At: Eli Zaretskii writes: >> From: Joseph Turner >> Cc: emacs-devel@gnu.org >> Date: Sun, 25 Aug 2024 23:49:52 -0700 >>=20 >> Joseph Turner writes: >>=20 >> > Eli Zaretskii writes: >> > >> >> you need to consider the encoding process: Emacs always encodes the >> >> buffer text on output to the external world. If this is what you >> >> want, then you need to use bufferpos-to-filepos, and make sure you >> >> pass the correct coding-system argument to it. >> > >> > Will the following code ever signal an error? >> > >> > (bufferpos-to-filepos >> > (point-max) 'exact >> > (select-safe-coding-system (point-min) (point-max))) >> > >> > The `bufferpos-to-filepos' docstring says, "It is an error to request >> > the =E2=80=98exact=E2=80=99 method when the buffer=E2=80=99s EOL forma= t is not yet decided." >> >=20=20=20=20=20 >> > IOW, does `select-safe-coding-system' always return an encoding which >> > specifies EOL conversion? >>=20 >> Let me rephrase: I would like to get the size of a buffer's text encoded >> with the return value of select-safe-coding-system, which may return an >> encoding which does not specify EOL conversion. Is there any way to >> calculate the `exact' buffer text size using bufferpos-to-filepos? >>=20 >> Or is `approximate' the only viable argument in this case? > > Unless you must deal with exotic encodings (like iso-2022 and its > derivatives), I suggest to always use 'approximate'. Thank you! I will do that.