emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* 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 23:14 Rodrigo Morales
  2021-09-25 10:50 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Morales @ 2021-09-24 23:14 UTC (permalink / raw)
  To: emacs-orgmode


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
:END:
#+END_SRC

** Links in the =#+TITLE= line
:PROPERTIES:
:CREATED: [2021-09-24 17:50:04 -05]
:END:

For making a specific part of the title clickable.

#+BEGIN_SRC org
,#+TITLE: My article on [[https://www.gnu.org/software/emacs/][GNU Emacs]]
,#+AUTHOR: John Doe

,* My section

This is a paragraph.

,* My second section

This is a paragraph.
#+END_SRC

* System information

Emacs  : GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.17.4)
 of 2021-03-26
Package: Org mode version 9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)

[[[ If you see a signature in spanish below this message, please omit
it. It is automatically inserted in all my messages due to the internal
privacy policies of the organization that owns the domain of my email
address. ]]]


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

end of thread, other threads:[~2021-09-25 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-24 23:14 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/)] Rodrigo Morales
2021-09-25 10:50 ` Nicolas Goaziou

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).