Created
February 12, 2016 09:03
-
-
Save saidie/91f44124d71fe2583eae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun get-url-title (url) | |
(interactive) | |
(with-temp-buffer | |
(call-process "curl" nil t nil "-s" url) | |
(goto-char (point-min)) | |
(let ((case-fold-search t)) | |
(re-search-forward "<title>\\([^<]*\\)</title>" nil t) | |
(match-string 1) | |
))) | |
(defun org-set-link-title-maybe () | |
(let* ((elem (org-element-context)) | |
(type (org-element-type elem)) | |
(schema (org-element-property :type elem)) | |
(url (org-element-property :raw-link elem)) | |
(begin (org-element-property :begin elem)) | |
(end (org-element-property :end elem)) | |
(no-content (eq (org-element-property :contents-begin elem) nil)) | |
) | |
(when (and (eq type 'link) | |
(or (string= schema "http") (string= schema "https")) | |
no-content) | |
(goto-char end) | |
(insert (concat "][" (get-url-title url) "]]")) | |
(goto-char begin) | |
(insert "[[") | |
))) | |
(add-hook 'org-ctrl-c-ctrl-c-hook 'org-set-link-title-maybe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set a title of a Web page to a plain URL text