From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
Received: from mp10.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 cBBoHBDxR2QFMgEASxT56A
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 25 Apr 2023 17:26:08 +0200
Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp10.migadu.com with LMTPS
	id 2GRrGxDxR2QbOwAAG6o9tA
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 25 Apr 2023 17:26:08 +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 2DC833D46C
	for <larch@yhetil.org>; Tue, 25 Apr 2023 17:26:08 +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 1prKY3-0002cs-AU; Tue, 25 Apr 2023 11:25:43 -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 <ruijie@netyu.xyz>) id 1prKXz-0002br-C5
 for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 11:25:39 -0400
Received: from netyu.xyz ([152.44.41.246] helo=mail.netyu.xyz)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ruijie@netyu.xyz>) id 1prKXt-0001gh-4O
 for emacs-orgmode@gnu.org; Tue, 25 Apr 2023 11:25:38 -0400
Received: from fw.net.yu.netyu.xyz (<unknown> [222.248.4.98])
 by netyu.xyz (OpenSMTPD) with ESMTPSA id c05b6abd
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Tue, 25 Apr 2023 15:25:12 +0000 (UTC)
References: <D140FA73-9995-4467-963E-00D5964485C0@axelkielhorn.de>
 <sdvzg70utif.fsf@netyu.xyz> <sdvv8housn7.fsf@netyu.xyz>
 <sdvmt30um3h.fsf@netyu.xyz> <sdvedocukz1.fsf@netyu.xyz>
 <32E3D56A-9DDF-4D70-BBA6-2DB71919EC98@axelkielhorn.de>
 <sdvy1mkt0vw.fsf@netyu.xyz> <sdvh6t7tlmw.fsf@netyu.xyz>
 <37BA8B13-A49D-41A4-B752-4ED9540D5799@axelkielhorn.de>
 <sdvo7nfrs7p.fsf@netyu.xyz> <871qkau9t6.fsf@localhost>
 <sdvbkjer8c3.fsf@netyu.xyz> <874jp64oxr.fsf@localhost>
 <sdvfs8os6es.fsf@netyu.xyz>
User-agent: mu4e 1.9.22; emacs 30.0.50
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: Ihor Radchenko <yantar92@posteo.net>, Axel Kielhorn
 <org-mode@axelkielhorn.de>, emacs-orgmode@gnu.org
Subject: Re: [DRAFT PATCH v6] Decouple LANG= and testing (was: Test failure
 due to LANG)
Date: Tue, 25 Apr 2023 23:19:47 +0800
In-reply-to: <sdvfs8os6es.fsf@netyu.xyz>
Message-ID: <sdvy1mgq920.fsf@netyu.xyz>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=152.44.41.246; envelope-from=ruijie@netyu.xyz;
 helo=mail.netyu.xyz
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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>
Reply-to:  Ruijie Yu <ruijie@netyu.xyz>
From:  Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
X-Migadu-Country: US
X-Migadu-Flow: FLOW_IN
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1682436368; a=rsa-sha256; cv=none;
	b=bnxs9m/WT0NLYoykasHSJixCw4Jfdeqn86o1EW8XwGuxolKRp4rXZ4HaoCLsodPDLaw+/D
	qckdHN73Ohx8Yj2KugpkVeUyhBu0JWq27Vrr4YX1lPwfhzDFs2QE/ekDtu1d2wfsjTBSG/
	H6TR1swlE496WQIkfyPXlR34dPpa6nwKVeL1zwSyGsHh0OKmI4fpPidJP2G1OrMKsl+ksR
	H7MJWpLzKGKzKzd5sbtsOS2e7TaUFkpnTu6eEEVQmwnDQXVlt7dgi31OUFNW9kJyFpuiLs
	yuLU6pK9rmPGTi6qhb6rBnkn3MT3Zrv4xmMc7cvn7fWmFAmrHUBkH1/lrUg+fA==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=none;
	dmarc=pass (policy=none) header.from=gnu.org;
	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=1682436368;
	h=from:from:sender:sender:reply-to: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; bh=wuYggNcGgrVn1netFA0QPn8Nw5tIn2U7JuE6iKR9HZc=;
	b=a1vU+AkXkhT+yPuzBd39fE1TgndEA2kNq3Exp2yjHPC54ZE/87VUr+weQSxz6LFNLcPhdl
	q/MCEu0CTRV72Ts1xzCLyi2O84Xshp0y+ax/eTsFqpwlG260Wx1guswp9aIm4DNisRJWAl
	24rJR8zk0DBw8e6YeJXNgdksoeUZw8NTFKqT9R9hVk6TfD4PmVZigG+gwlH3Dc+IpuMuRw
	Ll+XLdjaXVZXA9MzsYNfjmNBA5FLJNCpCAS9UFn0Y8AJrLMojo8we5T7R/r6IDI1Cu8N7j
	wDgVsHYiQSWji7eMAm8qr4l/Va4UzYiWHTqgQ27hlCB+3HLmbMsEj6lQAbl95g==
X-Migadu-Spam-Score: -3.01
X-Spam-Score: -3.01
X-Migadu-Queue-Id: 2DC833D46C
X-Migadu-Scanner: scn0.migadu.com
Authentication-Results: aspmx1.migadu.com;
	dkim=none;
	dmarc=pass (policy=none) header.from=gnu.org;
	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-TUID: 4b/nLsiyRHeo

--=-=-=
Content-Type: text/plain


Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>>      (org-element-timestamp-interpreter timestamp nil))
>
> Thanks for the pointer.  I have made this into a macro and redid my
> changes accordingly.  Please also let me know if more work should be
> dedicated to avoid code duplication in tests (I see a lot of duplication
> in the portions I touched in testing/lisp/test-org.el).
>
> What currently still fails unexpectedly:
>
> zh_CN.UTF-8:
>     test-org-clock/clocktable/lang
>     - This test only fails in batch mode, as I mentioned up-thread.  I
>       might try to convert this into a test that expects failure
>       depending on whether Emacs is in batch mode.
>     test-org-colview/columns-width
>     - This patch did not attempt to fix it.  I posted a diff file under
>       v2 (not included in this patch), but that didn't work either.
>
> ja_JA.UTF-8:
>     test-org-colview/columns-width
>     - See above.
>
> fr_FR.UTF-8:
>     test-org-clok/org-clock-timestamps-change
>     - This is tracked in the other thread I created, and won't be fixed
>       by this patch.
>
> en_US.UTF-8 and de_DE.UTF-8:
>     No unexpected test failures.
>
> [2. text/x-patch; 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch]...
>
>
> To summarize, the remaining goal of this patchset is to fix
> `test-org-colview/columns-width', and to optionally expect-failure on
> `test-org-clock/clocktable/lang'.

Iteration v6.  Everything, other than the French test and the
batch-non-batch Chinese test, now passes.  I'll look up how to determine
whether we are in batch mode or not, and slap that onto the expect tag
for `test-org-clock/clocktable/lang'.  And the French test belongs to
its own thread, so I won't try to fix it here.

V6 has two commits: the first commit is the *exact copy* of v5, and the
second commit tries to fix the zh_CN columns-width code & test.  Hence I
only attach the patch file for the second commit.


--=-=-=
Content-Type: text/x-patch; charset=utf-8
Content-Disposition: attachment;
 filename=0002-Let-org-columns-correctly-detect-string-widths-in-co.patch
Content-Transfer-Encoding: quoted-printable

>From 59cbb93b9fc221bdc8ee708b05943a245c41ad25 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@netyu.xyz>
Date: Tue, 25 Apr 2023 22:56:02 +0800
Subject: [PATCH 2/2] Let org-columns correctly detect string-widths in code

TODO: maybe I should also make a test directly on
`org-columns-add-ellipses'.  Will do in next iteration unless
objections.

* lisp/org-colview.el (org-columns--truncate-below-width): add a
helper function that will trim off just enough data from string to
fit into expected width.
(org-columns-add-ellipses): make sure to do truncation correctly
even in CJK locales (where an ellipsis character takes two
spaces).

* testing/lisp/test-org-colview.el
(test-org-colview/substring-below-width): add test to make sure
helper function is correct.
(test-org-colview/columns-width): fix incorrect expectations for
CJK locales about ellipses.
---
 lisp/org-colview.el              | 26 +++++++++++++++++++++-----
 testing/lisp/test-org-colview.el | 19 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 92a3b473d..6311a9274 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -452,14 +452,30 @@ DATELINE is non-nil when the face used should be
 	    "Type \\<org-columns-map>`\\[org-columns-edit-value]' \
 to edit property")))))))
=20
+(defun org-columns--truncate-below-width (string width)
+  "Return a substring of STRING no wider than WIDTH.
+This substring must start at 0, and must be the longest possible
+substring whose `string-width' does not exceed WIDTH."
+  (declare (side-effect-free t))
+  (let ((end (min width (length string))) res)
+    (while (and end (>=3D end 0))
+      (let* ((curr (string-width string 0 end))
+             (excess (- curr width)))
+        (if (> excess 0)
+            (cl-decf end (max 1 (/ excess 2)))
+          (setq res (substring string 0 end) end nil))))
+    res))
+
 (defun org-columns-add-ellipses (string width)
   "Truncate STRING with WIDTH characters, with ellipses."
   (cond
-   ((<=3D (length string) width) string)
-   ((<=3D width (length org-columns-ellipses))
-    (substring org-columns-ellipses 0 width))
-   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
-	      org-columns-ellipses))))
+   ((<=3D (string-width string) width) string)
+   ((<=3D width (string-width org-columns-ellipses))
+    (org-columns--truncate-below-width org-columns-ellipses width))
+   (t (concat
+       (org-columns--truncate-below-width
+        string (- width (string-width org-columns-ellipses)))
+       org-columns-ellipses))))
=20
 (defvar org-columns-full-header-line-format nil
   "The full header line format, will be shifted by horizontal scrolling." )
diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colvi=
ew.el
index 9daec18e2..b421fdc41 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -26,6 +26,23 @@
 (require 'org-duration)
 (require 'org-inlinetask)
=20
+(ert-deftest test-org-colview/substring-below-width ()
+  "Test `org-columns--truncate-below-width'."
+  (cl-flet ((check (string width expect)
+              (string=3D expect (org-columns--truncate-below-width
+                               string width))))
+    (if (=3D (char-width ?=E2=80=A6) 2)
+        (progn (should (check "12=E2=80=A6" 3 "12"))
+               (should (check "1=E2=80=A62" 1 "1"))
+               (should (check "1=E2=80=A62" 2 "1"))
+               (should (check "1=E2=80=A62" 3 "1=E2=80=A6"))
+               (should (check "=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=
=A6=E2=80=A6=E2=80=A6=E2=80=A6" 7 "=E2=80=A6=E2=80=A6=E2=80=A6")))
+      (progn (should (check "12=E2=80=A6" 4 "12=E2=80=A6"))
+             (should (check "1=E2=80=A62" 1 "1"))
+             (should (check "1=E2=80=A62" 2 "1=E2=80=A6"))
+             (should (check "1=E2=80=A62" 3 "1=E2=80=A62"))
+             (should (check "=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=
=E2=80=A6=E2=80=A6=E2=80=A6" 7 "=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=
=A6=E2=80=A6=E2=80=A6"))))))
+
 (ert-deftest test-org-colview/get-format ()
   "Test `org-columns-get-format' specifications."
   ;; Without any clue, use `org-columns-default-format'.
@@ -160,7 +177,7 @@
 	      (org-columns))
 	    (org-trim (get-char-property (point) 'display)))))
   (should
-   (equal "1234=E2=80=A6 |"
+   (equal (if (=3D 1 (char-width ?=E2=80=A6)) "1234=E2=80=A6 |" "123=E2=80=
=A6 |")
 	  (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
 	    (let ((org-columns-default-format "%5P")
 		  (org-columns-ellipses "=E2=80=A6"))
--=20
2.40.0


--=-=-=
Content-Type: text/plain


Comments welcome, thanks.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]

--=-=-=--