Skip to content

Instantly share code, notes, and snippets.

@jmn
Last active September 12, 2023 19:36
Show Gist options
  • Save jmn/34cd4205fa30ccf83f94cb1bc0198f3f to your computer and use it in GitHub Desktop.
Save jmn/34cd4205fa30ccf83f94cb1bc0198f3f to your computer and use it in GitHub Desktop.
How to make org-mode org-insert-link (C-c C-l) automatically fill in the description from a webpage
;; How to make org-mode org-insert-link (C-c C-l) automatically fill in the description from a webpage:
(defun jmn/url-get-title (url &optional descr)
"Takes a URL and returns the value of the <title> HTML tag,
Thanks to https://frozenlock.org/tag/url-retrieve/ for documenting url-retrieve"
(let ((buffer (url-retrieve-synchronously url))
(title nil))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(search-forward-regexp "<title>\\([^<]+?\\)</title>")
(setq title (match-string 1 ) )
(kill-buffer (current-buffer)))
title))
(setq org-make-link-description-function 'jmn/url-get-title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment