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.bugs Subject: bug#55801: [PATCH] Fix documentation of `aset' on strings, `store-substring' Date: Sun, 05 Jun 2022 11:30:00 +0300 Message-ID: <83tu8za4xj.fsf@gnu.org> References: <1d60b9cc-c6a5-e42b-7ed0-5ded2dcbab65@rhansen.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13751"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 55801@debbugs.gnu.org To: Richard Hansen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 05 10:31:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nxlfF-0003RG-3C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jun 2022 10:31:13 +0200 Original-Received: from localhost ([::1]:41706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxlfD-0000cT-HT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jun 2022 04:31:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxlf4-0000c3-84 for bug-gnu-emacs@gnu.org; Sun, 05 Jun 2022 04:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxlf3-00011q-Ua for bug-gnu-emacs@gnu.org; Sun, 05 Jun 2022 04:31:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nxlf3-0005kJ-QE for bug-gnu-emacs@gnu.org; Sun, 05 Jun 2022 04:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jun 2022 08:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55801 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 55801-submit@debbugs.gnu.org id=B55801.165441784822067 (code B ref 55801); Sun, 05 Jun 2022 08:31:01 +0000 Original-Received: (at 55801) by debbugs.gnu.org; 5 Jun 2022 08:30:48 +0000 Original-Received: from localhost ([127.0.0.1]:60012 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxlep-0005jr-Id for submit@debbugs.gnu.org; Sun, 05 Jun 2022 04:30:47 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:33794) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxlem-0005jc-JP for 55801@debbugs.gnu.org; Sun, 05 Jun 2022 04:30:46 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxlef-0000wQ-CH; Sun, 05 Jun 2022 04:30:38 -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=KIUoLD4sBTHwX3XFy7Oe4+i9bT7UyAyo2Si8Fw7Zb70=; b=nITyKKPp0cVy iap5/8I0rtJfYqknkGvJ/P+r/dn6zAKRGuKUkrbMttPHHGpiFfwlx9c0k3TKEltKpO+nGQxd8YPNk 6nRj/FxiryGqxk9dc4GO81bYwoNH9/w3/Jijw3g3WTFk5QrWEUQqvM0JlzkB6jEIvRmKWU/J0sv9b Uy535g6EvWtlKqRx2kV8IYey/ZyMjkIrZscRpOA1da0DlqWMyQoVuAFYF7kaXFr7MFZLnLEJ9l4CE aqQieqLswPJT46z+6cjMfSDQleQc31pL6K6ZrjeOaf/11KVUDZIKNYVa/E5s+xZ1CbrHDOS27CmER x1u+xy2oQo2/1qh71Kz0Lg==; Original-Received: from [87.69.77.57] (port=3161 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxleK-0002Rq-Au; Sun, 05 Jun 2022 04:30:31 -0400 In-Reply-To: <1d60b9cc-c6a5-e42b-7ed0-5ded2dcbab65@rhansen.org> (message from Richard Hansen on Sat, 4 Jun 2022 23:30:29 -0400) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:233695 Archived-At: > Date: Sat, 4 Jun 2022 23:30:29 -0400 > From: Richard Hansen > > See attached patch: > > * doc/lispref/strings.texi (Modifying Strings): `aref` and > `store-substring` automatically convert the string to multibyte if > necessary, and support characters with different sized encodings. Thanks. I installed the following modified version, which I think is more accurate (e.g., "length" and "index" can be ambiguous when talking about Lisp strings), and also includes some practical advice that can avoid some unibyte-vs-multibyte pitfalls and surprises with these functions: The most basic way to alter the contents of an existing string is with @code{aset} (@pxref{Array Functions}). @w{@code{(aset @var{string} @var{idx} @var{char})}} stores @var{char} into @var{string} at character index @var{idx}. It will automatically convert a pure-@acronym{ASCII} @var{string} to a multibyte string (@pxref{Text Representations}) if needed, but we recommend to always make sure @var{string} is multibyte, (e.g., by using @code{string-to-multibyte}, @pxref{Converting Representations}), if @var{char} is a non-@acronym{ASCII} character, not a raw byte. A more powerful function is @code{store-substring}: @defun store-substring string idx obj This function alters part of the contents of the specified @var{string}, by storing @var{obj} starting at character index @var{idx}. The argument @var{obj} may be either a character (in which case the function behaves exactly as @code{aset}) or a (smaller) string. If @var{obj} is a multibyte string, we recommend to make sure @var{string} is also multibyte, even if it's pure-@acronym{ASCII}. Since it is impossible to change the number of characters in an existing string, it is en error if @var{obj} consists of more characters than would fit in @var{string} starting at character index @var{idx}. @end defun