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#56685: OBOE in string-truncate-left? Date: Fri, 22 Jul 2022 14:31:03 +0300 Message-ID: <838roll6yw.fsf@gnu.org> References: <87sfmtfnpa.fsf@gmx.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3630"; mail-complaints-to="usenet@ciao.gmane.io" Cc: stefan@marxist.se, 56685@debbugs.gnu.org To: Stephen Berman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 22 13:32:18 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 1oEqtF-0000k8-Jo for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Jul 2022 13:32:17 +0200 Original-Received: from localhost ([::1]:51176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEqtE-00033j-KP for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Jul 2022 07:32:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEqt1-00031o-1m for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2022 07:32:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oEqt0-00087q-N9 for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2022 07:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oEqt0-0008TC-B2 for bug-gnu-emacs@gnu.org; Fri, 22 Jul 2022 07:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Jul 2022 11:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56685 X-GNU-PR-Package: emacs Original-Received: via spool by 56685-submit@debbugs.gnu.org id=B56685.165848947932499 (code B ref 56685); Fri, 22 Jul 2022 11:32:02 +0000 Original-Received: (at 56685) by debbugs.gnu.org; 22 Jul 2022 11:31:19 +0000 Original-Received: from localhost ([127.0.0.1]:40295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oEqsJ-0008S7-5o for submit@debbugs.gnu.org; Fri, 22 Jul 2022 07:31:19 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oEqsF-0008Ro-7G for 56685@debbugs.gnu.org; Fri, 22 Jul 2022 07:31:18 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:59902) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEqs9-00080t-U3; Fri, 22 Jul 2022 07:31:09 -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=yKEX4NCNb1aiomuAjOkhxEzcNxe7S6zqq3Gsy/6KEyI=; b=DDk7dCqLB29J Bk6Dya5I26mtS5JXNugMIEcT5cL2Y1fZGNJASp7C4C7Cy8kVS5VmKVGnosOsZIS+z24KUIthVx+E/ 6r1sovtqqopPIUOyexbZPDux71NqNB7BXJNPCbWhLdaWhZvvpXLQMhip+6TCqbRuusVK5wgQiNTK8 HrWBMVeY1VNPaUUPwdqVfFRhRcDNTU8J2+7bPca+rQh1N9WkXnHA5BIwSOwa7v0HpxBFB9ZJCK57G BBUT8/W5Z64JLZ3mxBRZnB5Dj1nIRRvMOm9WHTAMN+6Kqq6gc4WPmWaFPvS16+Z46Yh9e4s1HJVvf 81pONJoVBitwoPBGfsu+KQ==; Original-Received: from [87.69.77.57] (port=3772 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 1oEqs8-0002HO-Kg; Fri, 22 Jul 2022 07:31:09 -0400 In-Reply-To: <87sfmtfnpa.fsf@gmx.net> (message from Stephen Berman on Fri, 22 Jul 2022 12:26:09 +0200) 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:237613 Archived-At: > Cc: 56685@debbugs.gnu.org > From: Stephen Berman > Date: Fri, 22 Jul 2022 12:26:09 +0200 > > Yes, and I also think it's counterintuitive that LENGTH includes the > length of "...". Worse, if STRING is short enough, the resulting string > (with "...") can be longer than LENGTH: > > (string-truncate-left "band" 3) > "...d" > (string-truncate-left "band" 2) > "...d" > (string-truncate-left "band" 1) > "...d" > (string-truncate-left "and" 2) > "...d" > (string-truncate-left "and" 1) > "...d" The above calls make no sense to me: since it is known up front that the function will prepend "...", what else does the caller expect from such calls? > Note that with the last two examples, the result is longer than the > original string, contradicting the meaning of truncation. The function truncates STRING, not the result it returns. So I see no contradiction here. And again, what would you do instead? Because this: > (defun string-truncate-left (string length) > - "Truncate STRING to LENGTH, replacing initial surplus with \"...\"." > + "Return STRING's last LENGTH characters prefixed with \"...\". > +If the resulting string with the prefix is not shorter than the > +original length of STRING, return STRING unchanged." again makes no sense to me: you have forcibly prevented any Lisp program from truncating STRING because you personally don't like the result in these cases. But the fact that you don't like it doesn't yet mean it isn't a valid use case. If your applications don't want truncation in those case, it is easy to provide a trivial wrapper around string-truncate-left.