emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [bug, ox-ascii][PATCH] description list and long links
@ 2015-01-28  0:30 Rasmus
  2015-01-28 12:58 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2015-01-28  0:30 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

Hi,

Consider the following example:

--8<---------------cut here---------------start------------->8---
(with-temp-buffer 
  (require 'ox-ascii)
  (insert
   "- [[http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html][A label with a long link]] :: Lorem ipsum dolor sit amet, consectetur adipiscing elit\n")
  (org-ascii-export-as-ascii nil nil nil t))  
--8<---------------cut here---------------end--------------->8---

With output:

--8<---------------cut here---------------start------------->8---
[A label with a long link]: Lorem
                            ipsum
                            dolor
                            sit
                            amet,
                            consectetur
                            adipiscing
                            elit


[A label with a long link]
http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html
--8<---------------cut here---------------end--------------->8---

The reason for the wrong formatting is that org-ascii--current-text-width
takes that there's is like -28 characters left for lorem ipsum...  It does
that because it counts link and label.

The patch fixes this by only counting the length of the label.

I'm not really familiar with the ascii backend, so let me know if there's
any obvious deficits that I have overlooked.

Otherwise I push it.

—Rasmus


-- 
Evidence suggests Snowden used a powerful tool called monospaced fonts

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-ascii.el-Bug-in-description-list-formatting.patch --]
[-- Type: text/x-diff, Size: 1124 bytes --]

From 7b6a8730de6f5ec57f5d45af57c3c9f90f389fef Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Wed, 28 Jan 2015 01:10:56 +0100
Subject: [PATCH] ox-ascii.el: Bug in description-list formatting

* ox-ascii.el (org-ascii--current-text-width): Consider length of
  label for links.
---
 lisp/ox-ascii.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index e294fab..cd239f9 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -624,8 +624,11 @@ INFO is a plist used as a communication channel."
 		      (string-width (or (org-ascii--checkbox parent-item info)
 					""))
 		      (string-width
-		       (or (org-list-get-tag beg-item struct)
-			   (org-list-get-bullet beg-item struct)))))))))))))
+		       (let ((tag (or (org-list-get-tag beg-item struct)
+				      (org-list-get-bullet beg-item struct))))
+			 (if (string-match org-bracket-link-analytic-regexp tag)
+			     (match-string 4 tag)
+			   tag)))))))))))))
 
 (defun org-ascii--current-justification (element)
   "Return expected justification for ELEMENT's contents.
-- 
2.2.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [bug, ox-ascii][PATCH] description list and long links
  2015-01-28  0:30 [bug, ox-ascii][PATCH] description list and long links Rasmus
@ 2015-01-28 12:58 ` Nicolas Goaziou
  2015-01-28 13:48   ` Rasmus
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2015-01-28 12:58 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> Consider the following example:
>
> (with-temp-buffer 
>   (require 'ox-ascii)
>   (insert
>    "- [[http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html][A label with a long link]] :: Lorem ipsum dolor sit amet, consectetur adipiscing elit\n")
>   (org-ascii-export-as-ascii nil nil nil t))  
>
> With output:
>
> [A label with a long link]: Lorem
>                             ipsum
>                             dolor
>                             sit
>                             amet,
>                             consectetur
>                             adipiscing
>                             elit
>
>
> [A label with a long link]
> http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html
>
> The reason for the wrong formatting is that org-ascii--current-text-width
> takes that there's is like -28 characters left for lorem ipsum...  It does
> that because it counts link and label.
>
> The patch fixes this by only counting the length of the label.

Thank you. I have applied a slightly different patch.

The formatting is still not optimal, however, as you can end up with
something like

  [http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html]: Lorem
                                                                                    ipsum
                                                                                    dolor
                                                                                    sit
                                                                                    amet,
                                                                                    consectetur
                                                                                    adipisicing
                                                                                    elit

A proper formatting would be, for example,

  [http://www.npr.org/blogs/monkeysee/2009/03/a_very_long_url_makes_a_very_s.html]:

        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
        eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
        enimad minim veniam, quis nostrud exercitation ullamco laboris


I guess a threshold would then be needed, though, as the following is
still nice and probably desirable

  lorem: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
         do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
         enimad minim veniam, quis nostrud exercitation ullamco laboris nisi

But I'm not sure if it is common to have such long tags in description
lists.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [bug, ox-ascii][PATCH] description list and long links
  2015-01-28 12:58 ` Nicolas Goaziou
@ 2015-01-28 13:48   ` Rasmus
  0 siblings, 0 replies; 3+ messages in thread
From: Rasmus @ 2015-01-28 13:48 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Thank you. I have applied a slightly different patch.

Thanks! 

> The formatting is still not optimal, however, as you can end up with
> something like
> [...]
> I guess a threshold would then be needed, though, as the following is
> still nice and probably desirable
>
>   lorem: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
>          do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
>          enimad minim veniam, quis nostrud exercitation ullamco laboris nisi
>
> But I'm not sure if it is common to have such long tags in description
> lists.

I don't know.  If it is, maybe someone will complain.

—Rasmus

-- 
Me gusta la noche, me gustas tú

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-28 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-28  0:30 [bug, ox-ascii][PATCH] description list and long links Rasmus
2015-01-28 12:58 ` Nicolas Goaziou
2015-01-28 13:48   ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).