emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due t


From: Ihor Radchenko
Subject: Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
Date: Tue, 25 Apr 2023 10:11:08 +0000

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>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]