From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: How to get buffer byte length (not number of characters)? Date: Thu, 22 Aug 2024 21:44:04 +0300 Message-ID: <86zfp4qtxn.fsf@gnu.org> References: <87wmkbekjp.fsf@ushin.org> <86o75nwilg.fsf@gnu.org> <87bk1lhkvg.fsf@ushin.org> <86y14pu5rp.fsf@gnu.org> <871q2hfn7c.fsf@ushin.org> <86plq1td4n.fsf@gnu.org> <87ed6hdnpe.fsf@ushin.org> <865xrsu8c8.fsf@gnu.org> <87ttfcl8bn.fsf@ushin.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22823"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, schwab@suse.de, adam@alphapapa.net To: Joseph Turner Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Aug 22 20:44:56 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 1shCnn-0005nz-Ou for ged-emacs-devel@m.gmane-mx.org; Thu, 22 Aug 2024 20:44:55 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1shCn9-0007ZJ-Le; Thu, 22 Aug 2024 14:44:15 -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 1shCn5-0007Yw-7t for emacs-devel@gnu.org; Thu, 22 Aug 2024 14:44:11 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1shCn4-0002kR-1L; Thu, 22 Aug 2024 14:44:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Svjx3y1iPt5R4PPEasEZVA2KjhJ6YItvwNAB7WF76Lw=; b=kcSb7XFeMRLP eqnO3aPYBabnvoS1JQQ2LLkqRZNHWhGUGIs3RESe0IvDI6p8fFmUdU+efWvFCgZvprQ05bQA0w1TF m3A4r5aA022isRKD/qLb+cNRjl8zdiNn9yubwDquYFwdP94xntLOwu4nQpo5V8oedMtaz8Uu7sniq scWnxJfWV07SPdZA0hZKSPbNFvmSdqdjAquLENGTGLuRoKZBDZ7nD/clC29MY/8U3m39l+db6nVVE F20FMr+pb0ycp7pmjVPyAWTA6Ltqe6W6Rs3xKqcQeL3nW9evxwzoUHmlgAL+Zp/6Sm3F4XTOrZmNu eip3ezgpb6Q79vQjcvofrA==; In-Reply-To: <87ttfcl8bn.fsf@ushin.org> (message from Joseph Turner on Thu, 22 Aug 2024 11:29:48 -0700) 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:323055 Archived-At: > From: Joseph Turner > Cc: emacs-devel@gnu.org, schwab@suse.de, adam@alphapapa.net > Date: Thu, 22 Aug 2024 11:29:48 -0700 > > Eli Zaretskii writes: > > > I think it is better to use detect-coding-region instead, if > > buffer-file-coding-system is undecided. > > detect-coding-region is only useful when decoding text, right? Yes, sorry. I should have said find-coding-systems-region. > For encoding text, should we encode with buffer-file-coding-system? If you are sure it will do, yes. But what if the buffer started as all-ASCII and then the user or some Lisp program added some non-ASCII characters before saving? Then buffer-file-coding-system is no longer pertinent. > >> > By "optionally" you mean that it doesn't always happen, except if the > >> > caller requests that? If so, the caller of plz.el should decode the > >> > text manually before using it in user-facing features. > >> > >> By default, `plz' decodes response body according to the 'Content-Type' > >> charset (or utf-8 as fallback). Passing `:decode nil' stops that. > > > > Sounds correct. > > When decoding, should plz fallback to detect-coding-region instead of utf-8? If this is HTML, then I think it is okay to trust the headers about the charset and default to UTF-8. The problem with detect-coding-region is that some of it is based on guesswork, which is one reason why it could take a UTF-8 encoded text to be Latin-1. So if a more reliable source of information is available, we had better used it. > Thanks! So when decoding text in hyperdrive.el, we can use (1) > Content-Type charset, or (2) use `detect-coding-region' as a fallback. That's also possible.