emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#48148: closed (27.2; ox-ascii breaks TITLE line wrongly when 2 widt


From: GNU bug Tracking System
Subject: bug#48148: closed (27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used)
Date: Sun, 02 May 2021 15:57:02 +0000

Your message dated Sun, 02 May 2021 17:56:04 +0200
with message-id <87eeep86zv.fsf@nicolasgoaziou.fr>
and subject line Re: bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 
width char is used
has caused the debbugs.gnu.org bug report #48148,
regarding 27.2;  ox-ascii breaks TITLE line wrongly when 2 width char is used
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
48148: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=48148
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used Date: Sun, 02 May 2021 08:52:13 +0900 User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO)
Hi,

When exporting org-mode document to plain text (either ascii/unicode/utf-8)
with `org-export-dispatch', Emacs translates the document title with
`org-ascii-template--document-title'.  However, when 2 width character is
used, it detects the title line's width wrongly and breaks it even if the
width is not too long.

For example, when the title is "ABCDEF" (each character has width of
2), expected title would be like:

                     ━━━━━━━━━━━━━━━
                              ABCDEF
                     ━━━━━━━━━━━━━━━

However, the reality is:

                     ━━━━━━━━━━━━━━━
                                 ABC
                                 DEF
                     ━━━━━━━━━━━━━━━
                     
This is because it uses `length' to detects the width, which only returns the
number of characters (6 in this case) but not the actual width displayed (12
in this case), and it tries to fill the line with that half width.
`string-width' should be used instead.

Here is a potential patch.

--- ox-ascii.el.org     2021-03-26 09:28:44.000000000 +0900
+++ ox-ascii.el 2021-05-02 08:11:57.657347150 +0900
@@ -1033,7 +1033,7 @@
             ;; Format TITLE.  It may be filled if it is too wide,
             ;; that is wider than the two thirds of the total width.
             (title-len (min (apply #'max
-                                   (mapcar #'length
+                                   (mapcar #'string-width
                                            (org-split-string
                                             (concat title "\n" subtitle) 
"\n")))
                             (/ (* 2 text-width) 3)))

---
Shingo Tanaka



--- End Message ---
--- Begin Message --- Subject: Re: bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used Date: Sun, 02 May 2021 17:56:04 +0200 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Eli Zaretskii <eliz@gnu.org> writes:

>> From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
>> Cc: shingo.fg8@gmail.com,  48148@debbugs.gnu.org
>> Date: Sun, 02 May 2021 14:18:24 +0200
>> 
>> My problem is that I have some string, _which is not displayed anywhere_
>> yet. I need to obtain its real width along with the width of a single
>> character in order to compute the length argument in `make-string'.
>
> The width of any text on display is meaningless unless you also tell
> in what window will it be displayed.  That's because some of the
> factors that affect the display width depend on the window and the
> buffer shown by that window.

I understand. More than the width of the text, I'm interested in the
ratio between the width of the text and the width of an underline
character (assuming monospace).

> So assuming the string you have will eventually be displayed in some
> window -- and most strings in Emacs are of that kind -- you should use
> that window up front.  Otherwise, the value you get from other methods
> can only be an approximation, which will sometimes be close, and
> sometimes quite far from the truth.

The string may not be displayed at all. Since it is the output of an
export process, it could, e.g., be written to a file.

I applied Shingo Tanaka's suggestion using `string-width', which is the
best we can do considering our requirements.

Thank you for your answer, and to Shingo Tanaka for the report an the
patch.

Regards,



--- End Message ---

reply via email to

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