0

supposing I have following ORG header

* [[http://...][Description]]

How do I extract the link and insert it as a property? My desired outcome should look like:

* Description
  :PROPERTIES:
  :URL: http://...
  :END:

Till now I only found how to remove the link from the header:

    (defun afs/org-replace-link-by-link-description ()
        "Replace an org link by its description or if empty its address"
      (interactive)
      (if (org-in-regexp org-link-bracket-re 1)
          (save-excursion
            (let ((remove (list (match-beginning 0) (match-end 0)))
                  (description
                   (if (match-end 2)
                       (org-match-string-no-properties 2)
                     (org-match-string-no-properties 1))))
              (apply 'delete-region remove)
              (insert description)))))
1

1 Answer 1

0

You need to save the URL from the match in some variable (say url) and then do (org-entry-put nil "URL" url):

(defun afs/org-replace-link-by-link-description ()
    "Replace an org link by its description or if empty its address"
  (interactive)
  (if (org-in-regexp org-link-bracket-re 1)
      (save-excursion
        (let ((remove (list (match-beginning 0) (match-end 0)))
              (description
               (if (match-end 2)
                   (org-match-string-no-properties 2)
                 (org-match-string-no-properties 1)))
              (url (org-match-string-no-properties 1)))
          (apply 'delete-region remove)
          (insert description)
          (org-entry-put nil "URL" url)))))

See the doc string of the function with C-h f org-entry-put and also see the Using the Property API section of the manual, which you can get to from inside Emacs with C-h i g(org)Using the Property API.

2
  • Thanks! That org-entry-put did the trick. Oct 6, 2021 at 6:25
  • If this answered the question to your satisfaction, please accept it.
    – NickD
    Oct 6, 2021 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.