From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
Received: from mp11.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms9.migadu.com with LMTPS
	id YELSNcamR2ToaQEASxT56A
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 25 Apr 2023 12:09:10 +0200
Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp11.migadu.com with LMTPS
	id +AXRNcamR2TJQQAA9RJhRA
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 25 Apr 2023 12:09:10 +0200
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by aspmx1.migadu.com (Postfix) with ESMTPS id 97E2232321
	for <larch@yhetil.org>; Tue, 25 Apr 2023 12:09:10 +0200 (CEST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-orgmode-bounces@gnu.org>)
	id 1prFb4-0003Re-1b; Tue, 25 Apr 2023 06:08:30 -0400
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 <yantar92@posteo.net>)
 id 1prFb2-0003RJ-7t
 for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 06:08:28 -0400
Received: from mout02.posteo.de ([185.67.36.66])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@posteo.net>)
 id 1prFb0-0005TV-5T
 for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 06:08:27 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id CBDC32404C4
 for <emacs-orgmode@gnu.org>; Tue, 25 Apr 2023 12:08:21 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1682417301; bh=s7gFDNWmg5gRswNX2opfndZIGgLoCxEdcIYL1Y8Lj8E=;
 h=From:To:Cc:Subject:Date:From;
 b=RqGrrYW1NS43RlIkJJPTLqtFPQdzsdRM7lRi1M56zzi6Ag9n2HGPH+9eICsDweIHz
 e9T4EfJrnuKvTdWQWw4ufVspb291NW8/cnC9gcjEtqhFn+XY5vB9lIXrxtgYp/893f
 fLtUL8W5CuLD2C7af1S9jNqwDHYWG3uGqmFFaNYeylboe+Ag1+sLMpbPlpAjorh234
 jmD5xaFe9vYY4y3R14iutpQ/vVKyhfNv9z/NUQR4uGfck74msA2L481GzS14yab0KW
 3hxovey5kMuM2fHRlmjT+DDa4NOZAmp686lQiEy8r2yjEkbsCa0g0jygxTg6zXh58T
 crDBtbeUPbung==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4Q5Hks1wcFz9rxD;
 Tue, 25 Apr 2023 12:08:21 +0200 (CEST)
From: Ihor Radchenko <yantar92@posteo.net>
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: Axel Kielhorn <org-mode@axelkielhorn.de>, emacs-orgmode@gnu.org
Subject: Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure
 due to LANG)
In-Reply-To: <sdvmt2ypqy9.fsf@netyu.xyz>
References: <D140FA73-9995-4467-963E-00D5964485C0@axelkielhorn.de>
 <sdvzg70utif.fsf@netyu.xyz> <sdvv8housn7.fsf@netyu.xyz>
 <sdvmt30um3h.fsf@netyu.xyz> <sdvedocukz1.fsf@netyu.xyz>
 <sdv7cu4ugk2.fsf@netyu.xyz> <87ildmuavp.fsf@localhost>
 <sdvjzy2rhne.fsf@netyu.xyz> <87y1misv5l.fsf@localhost>
 <sdvzg6ypsx5.fsf@netyu.xyz> <877cu24p5b.fsf@localhost>
 <sdvmt2ypqy9.fsf@netyu.xyz>
Date: Tue, 25 Apr 2023 10:11:08 +0000
Message-ID: <87v8hks24j.fsf@localhost>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net;
 helo=mout02.posteo.de
X-Spam_score_int: -43
X-Spam_score: -4.4
X-Spam_bar: ----
X-Spam_report: (-4.4 / 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,
 RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-orgmode@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
X-Migadu-Flow: FLOW_IN
X-Migadu-Country: US
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1682417350; a=rsa-sha256; cv=none;
	b=uAsjeb9QRpHBePzMqVgrvxNkYOCHUTEs5xpJJW31rNdwM0XkLFcJ5nyb5LGP7MZGQ1oLCZ
	pAG6OBLXCRIPyRi+1YhXEajyixvsy2+bqpom84eZFbSsiYKrJp65sr58Ywe5v5wHYUf7vQ
	u0QZul0Hh3jXiQ22geSlBkrMS/txhtVLec5jT3BfNt1+qmWeq941tAoxpY+Y6NKk8fKy81
	QRoeKZZIx6PujNvaEhYeHN59pDq9i2d4dHhukRDkzuZJ1l/HtwUTP2XzduryL9w0MiDPNG
	jb3FKALSaIKs05Tli0zDtaPRTWK/vGgtooLBwD+MvBZTEesUwh8EyysHVjYiuQ==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=pass header.d=posteo.net header.s=2017 header.b=RqGrrYW1;
	dmarc=pass (policy=none) header.from=posteo.net;
	spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org;
	s=key1; t=1682417350;
	h=from:from:sender:sender:reply-to:subject:subject:date:date:
	 message-id:message-id:to:to:cc:cc:mime-version:mime-version:
	 content-type:content-type:in-reply-to:in-reply-to:
	 references:references:list-id:list-help:list-unsubscribe:
	 list-subscribe:list-post:dkim-signature;
	bh=DfilQ/HNiodCng/nWYAJh1NCuVa3By5a9Nvtx2UACj8=;
	b=XqwgCPRtK4rdWfGhpZmWgyfrU64X3lorsVKqKAB9RUbWR1i8H/vURQIjXlLEB19SmKvf/h
	i4yThz/NZDDfUNvefl0seut3Jfqoo+aRscJLA2lSJQbyK79wX/lAmGXRvMCnvsuNB3AGo1
	doWZxED6W0U9CPQ8Mc3RTKFkGm6t1Zts2LgTusH22OO8qF/SmmFKVydTgaw4okp5oAaZ+e
	hE9b9KAIYxE3sek3o9mVHHjioasMvTUs//zGs5nWChZZIvgLy1MG/HRExE0RvzhoTkwXaW
	qq5TQe/WvSSf3CQxRFVtOTEAirQsEPGr+dJOhtN+25U73Cn1u4ebq5nrn//myQ==
X-Migadu-Scanner: scn1.migadu.com
Authentication-Results: aspmx1.migadu.com;
	dkim=pass header.d=posteo.net header.s=2017 header.b=RqGrrYW1;
	dmarc=pass (policy=none) header.from=posteo.net;
	spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"
X-Migadu-Spam-Score: -4.70
X-Spam-Score: -4.70
X-Migadu-Queue-Id: 97E2232321
X-TUID: F5Q2WBllMS90

Ruijie Yu <ruijie@netyu.xyz> writes:

> Just had a try at this, fully untested code (other than starting a
> LANG=zh_CN.UTF-8 Emacs session and running this substring function to
> see its effects).

Thanks!

> +(defun org-columns--substring-below-width (string start width)
> +  "Similar to `substring', but use `string-width' to check width.

This is not really similar to `substring' as `substring' has totally
different third argument.

> +The returned value is a substring of STRING, starting at START,
> +and is the largest possible substring whose width does not exceed
> +WIDTH."
> +  (let ((end (min (+ start width) (length string))) res)
> +    (while (and end (>= end start))
> +      (let* ((curr (string-width string start end))
> +             (excess (- curr width)))
> +        (if (cl-plusp excess)

Why not simply (> excess 0)? `cl-plusp' is a bit confusing - we
generally avoid cl-lib functions unless necessary. (I've never seen
`cl-plusp' used frequently)

>  (defun org-columns-add-ellipses (string width)
>    "Truncate STRING with WIDTH characters, with ellipses."
>    (cond
> -   ((<= (length string) width) string)
> -   ((<= width (length org-columns-ellipses))
> -    (substring org-columns-ellipses 0 width))
> -   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
> -	      org-columns-ellipses))))
> +   ((<= (string-width string) width) string)
> +   ((<= width (string-width org-columns-ellipses))
> +    (org-columns--substring-below-width org-columns-ellipses 0 width))
> +   (t (concat
> +       (org-columns--substring-below-width
> +        string 0 (- width (length org-columns-ellipses)))
> +       org-columns-ellipses))))

It will be best to write dedicated tests here that will clearly indicate
issues when some non-standard LANG environment is used. The current
failure is rather difficult to debug.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>