emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: emacs-orgmode@gnu.org
Subject: 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/)]
Date: Fri, 24 Sep 2021 18:14:52 -0500	[thread overview]
Message-ID: <877df5sh03.fsf@gmail.com> (raw)


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


             reply	other threads:[~2021-09-24 23:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24 23:14 Rodrigo Morales [this message]
2021-09-25 10:50 ` 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/)] Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877df5sh03.fsf@gmail.com \
    --to=moralesrodrigo1100@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).