Re: Bug: org-element-map doesn't consider all links in the current buffer [9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)]

2021-09-25 Thread Nicolas Goaziou
Hello,

Rodrigo Morales  writes:

> This bug report show examples where it is noticeable that
> =org-element-map=, when =link= is the value for the =TYPES= argument,
> doesn't consider all links in the current buffer.

This is not a bug, but your interpretation of the syntax differs from
Org.


There are no links in keywords or properties drawers since those are
plain key-value string pairs.

Regards,
-- 
Nicolas Goaziou



Bug: org-element-map doesn't consider all links in the current buffer [9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)]

2021-09-24 Thread Rodrigo Morales


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


* Introduction

This bug report show examples where it is noticeable that =org-element-map=, 
when =link= is the value for the =TYPES= argument, doesn't consider all links 
in the current buffer.

* Examples without errors
:PROPERTIES:
:CREATED: [2021-09-24 13:23:45 -05]
:END:

This section show examples where =org-element-map= correctly iterates through 
all links.

The following is an example.

#+begin_src elisp
(let ((lines '("|---|"
   "| [[https://link1.com]] |"
   "| [[https://link2.com]] |"
   "| [[https://link3.com]] |"
   "|---|")))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link1.com; "https://link2.com; "https://link3.com;)
#+end_example

The following is another example.

#+begin_src elisp
(let ((lines '("#+BEGIN_QUOTE"
"[[https://link1.org]];
"#+END_QUOTE")))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link1.org;)
#+end_example

The following is another example.

#+begin_src elisp
(let ((lines '("This is [[https://link1.com][a link]]"
   "#+BEGIN_SRC python"
   "print('[[https://link2.com][a link]]')"
   "#+END_SRC"
   "This is [[https://link3.com][a link]]")))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link1.com; "https://link3.com;)
#+end_example

* Examples with errors
:PROPERTIES:
:CREATED: [2021-09-24 13:24:03 -05]
:END:

This section show examples where =org-element-map= doesn't iterate through all 
links in the buffer.

The following is an example. Links in properties drawers are not considered. I 
expect those links to be considered.

#+begin_src elisp
(let ((lines '("* John Doe"
   ":PROPERTIES:"
   ":ONE: [[https://link1.com]];
   ":TWO: [[https://link2.com]];
   ":END:"
   "[[https://link3.com]];)))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link3.com;)
#+end_example


The following is another example.

The link in the =#+TITLE= line is not considered. I expect that links to be 
considered.

#+begin_src elisp
(let ((lines '("#+TITLE: A line with [[https://link1.com][a]] link"
   ""
   "[[https://link2.com]];)))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link2.com;)
#+end_example

The following is another example.

In general, links in keyword lines (i.e. those starting with =#+=) are not 
considered. I expect those links to be considered.

#+begin_src elisp
(let ((lines '("#+TITLE: A line with [[https://link1.com][a link]]"
   "#+SUBTITLE: A line with [[https://link2.com][a link]]"
   "#+AUTHOR: A line with [[https://link3.com][a link]]"
   "#+SUBAUTHOR: A line with [[https://link4.com][a link]]"
   ""
   "A simple paragraph with [[https://link5.com][a link]]")))
  (with-temp-buffer
(org-mode)
(insert (string-join lines "\n"))
(org-element-map (org-element-parse-buffer)
'link
  (lambda (link) (org-element-property :raw-link link)
#+end_src

#+RESULTS:
#+begin_example
("https://link5.com;)
#+end_example

* Personal thoughts
:PROPERTIES:
:CREATED: [2021-09-24 17:41:12 -05]
:END:

I think that links in properties drawers and keyword lines should be considered 
by =org-element-map= because there are use cases for having links at these 
locations. I will mention a use case for each context

** Links in property drawers
:PROPERTIES:
:CREATED: [2021-09-24 17:49:32 -05]
:END:

For storing contacts' information

#+BEGIN_SRC org
,* John Doe
:PROPERTIES:
:LANGUAGE_NATIVE: SPA
:LANGUAGE_FLUENT: ENG
:PERSONAL_SITE: https://www.jhondoe.com