Re: [O] custom link export and ox-md

2014-03-21 Thread Bastien
Hi Nick and Nicolas,

can we move forward on this patch?  It is good, modulo Nicolas
suggestions, which seems good to me.

 This raises an interesting question. What do we do with derived
 back-ends? E.g., what should happen if TYPE is handled in
 `org-link-protocols' for `html' but not `md'?

I'm not sure I understand the problem, but I guess it can be fixed
separately from the issue addressed by the patch.

Anyway, yes, this would go to master, as a small enhancement.

Thanks,

-- 
 Bastien



Re: [O] custom link export and ox-md

2014-02-25 Thread Nicolas Goaziou
Hello,

Nick Dokos ndo...@gmail.com writes:

 can you take a look at this patch?

Thank you for the patch. Here we go.

 If it looks OK, I can push it to maint.

Why maint? It isn't a bugfix.

 commit f820173bf514549134e8ba10a1e539cb89f6
 Author: Nick Dokos ndo...@redhat.com
 Date:   Mon Feb 24 14:31:33 2014 -0500

 Add handling of user-defined custom links to org-md-link
 
 * ox-md.el (org-md-link): Add code to handle user-defined custom links.
   Refactor raw-path calculation to simplify the code.
 
 Reported by John Peloquin 
 (http://thread.gmane.org/gmane.emacs.orgmode/82627)

 diff --git a/lisp/ox-md.el b/lisp/ox-md.el
 index 39843d5..fbc5d6f 100644
 --- a/lisp/ox-md.el
 +++ b/lisp/ox-md.el
 @@ -278,7 +278,8 @@ a communication channel.
   (if (string= .org (downcase (file-name-extension raw-path .)))
   (concat (file-name-sans-extension raw-path) .md)
 raw-path
 - (type (org-element-property :type link)))
 + (type (org-element-property :type link))
 + (raw-path (org-element-property :path link)))

I'd rather not bind RAW-PATH here, as only half the branches in the
`cond' are using it. Also, I think it is clearer to mostly do bindings
close to the areas where they are needed.

 -(let ((path (let ((raw-path (org-element-property :path link)))
 -  (if (not (file-name-absolute-p raw-path)) raw-path
 -(expand-file-name raw-path
 +(let ((path (if (not (file-name-absolute-p raw-path)) raw-path
 +(expand-file-name raw-path)))

See above.

 -(let ((ref (org-element-property :path link)))
 +(let ((ref raw-path))

If you want to go further, you could even remove REF, but, see above.

 -   (t (let* ((raw-path (org-element-property :path link))
 - (path
 +   ;; Link type is handled by a special function.
 +   ((functionp (setq protocol (nth 2 (assoc type org-link-protocols
 +(funcall protocol raw-path contents 'md))
 +

This raises an interesting question. What do we do with derived
back-ends? E.g., what should happen if TYPE is handled in
`org-link-protocols' for `html' but not `md'?

Also the blank line is not needed.


Regards,

-- 
Nicolas Goaziou



Re: [O] custom link export and ox-md

2014-02-24 Thread Nick Dokos
Nicolas,

can you take a look at this patch? If it looks OK, I can
push it to maint.

--8---cut here---start-8---
commit f820173bf514549134e8ba10a1e539cb89f6
Author: Nick Dokos ndo...@redhat.com
Date:   Mon Feb 24 14:31:33 2014 -0500

Add handling of user-defined custom links to org-md-link

* ox-md.el (org-md-link): Add code to handle user-defined custom links.
  Refactor raw-path calculation to simplify the code.

Reported by John Peloquin 
(http://thread.gmane.org/gmane.emacs.orgmode/82627)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 39843d5..fbc5d6f 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -278,7 +278,8 @@ a communication channel.
(if (string= .org (downcase (file-name-extension raw-path .)))
(concat (file-name-sans-extension raw-path) .md)
  raw-path
-   (type (org-element-property :type link)))
+   (type (org-element-property :type link))
+   (raw-path (org-element-property :path link)))
 (cond ((member type '(custom-id id))
   (let ((destination (org-export-resolve-id-link link info)))
 (if (stringp destination)  ; External file.
@@ -294,9 +295,8 @@ a communication channel.
destination info)
   .)))
  ((org-export-inline-image-p link org-html-inline-image-rules)
-  (let ((path (let ((raw-path (org-element-property :path link)))
-(if (not (file-name-absolute-p raw-path)) raw-path
-  (expand-file-name raw-path
+  (let ((path (if (not (file-name-absolute-p raw-path)) raw-path
+  (expand-file-name raw-path)))
 (caption (org-export-data
   (org-export-get-caption
(org-export-get-parent-element link)) info)))
@@ -304,7 +304,7 @@ a communication channel.
 (if (not (org-string-nw-p caption)) path
   (format %s \%s\ path caption)
  ((string= type coderef)
-  (let ((ref (org-element-property :path link)))
+  (let ((ref raw-path))
 (format (org-export-get-coderef-format ref contents)
 (org-export-resolve-coderef ref info
  ((equal type radio)
@@ -318,8 +318,11 @@ a communication channel.
   (when number
 (if (atom number) (number-to-string number)
   (mapconcat 'number-to-string number .
- (t (let* ((raw-path (org-element-property :path link))
-   (path
+ ;; Link type is handled by a special function.
+ ((functionp (setq protocol (nth 2 (assoc type org-link-protocols
+  (funcall protocol raw-path contents 'md))
+
+ (t (let* ((path
 (cond
  ((member type '(http https ftp))
   (concat type : raw-path))
--8---cut here---end---8---

Thanks,
Nick




[O] custom link export and ox-md

2014-02-23 Thread John Peloquin

Greetings,

I'm trying to define a custom link in org mode with custom export 
formatting, but I get unexpected results when exporting to markdown.



Minimal example:

`minimal-init.el`

(add-to-list 'load-path ~/.emacs.d/elpa/org-20140217)
(require 'org)
(add-to-list 'org-export-backends md)

(org-add-link-type
 cite nil
 (lambda (path desc format)
   (format [@%s] path)))


`minimal.org`

Some text [[cite:citekey]].


When I export `minimal.org` to markdown using C-c C-e m M, I get:

Some text citekey.


Whereas I expected:

Some text [@citekey].


I tried this with a clean emacs configuration (`emacs -Q -l 
minimal-init.el`).  `org-version` returns 8.2.5h, which as far as I know 
is the latest version.  `emacs-version` is 24.3.1.


I do get the expected export result if I export to latex or html, so the 
link export definition in init.el does work.  Am I doing something 
wrong?  Is this a bug in ox-md?



Best regards,

John Peloquin



Re: [O] custom link export and ox-md

2014-02-23 Thread Nick Dokos
John Peloquin john.peloq...@gmail.com writes:

 Greetings,

 I'm trying to define a custom link in org mode with custom export
 formatting, but I get unexpected results when exporting to markdown.


 Minimal example:

 `minimal-init.el`

 (add-to-list 'load-path ~/.emacs.d/elpa/org-20140217)
 (require 'org)
 (add-to-list 'org-export-backends md)

 (org-add-link-type
  cite nil
  (lambda (path desc format)
(format [@%s] path)))


 `minimal.org`

 Some text [[cite:citekey]].


 When I export `minimal.org` to markdown using C-c C-e m M, I get:

 Some text citekey.


 Whereas I expected:

 Some text [@citekey].


 I tried this with a clean emacs configuration (`emacs -Q -l 
 minimal-init.el`).  `org-version` returns 8.2.5h, which as far as I
 know is the latest version.  `emacs-version` is 24.3.1.

 I do get the expected export result if I export to latex or html, so
 the link export definition in init.el does work.  Am I doing something
 wrong? 

No.

 Is this a bug in ox-md?

Yes. There is no provision for handling user-defined link types. Try the
following patch:

--8---cut here---start-8---
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b8316dd..fa64f2d 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -340,6 +340,10 @@ a communication channel.
   (when number
 (if (atom number) (number-to-string number)
   (mapconcat 'number-to-string number .
+ ;; Link type is handled by a special function.
+ ((functionp (setq protocol (nth 2 (assoc type org-link-protocols
+  (funcall protocol (org-element-property :path link) contents 'md))
+
  (t (let* ((raw-path (org-element-property :path link))
(path
 (cond
--8---cut here---end---8---


Lightly tested with your reproducer - thanks for providing one!

-- 
Nick