45 lines
1.6 KiB
EmacsLisp
45 lines
1.6 KiB
EmacsLisp
(defconst my/termux-p (getenv "ANDROID_ROOT"))
|
|
|
|
(defun my/clipboard-get ()
|
|
"Return the text on the system clipboard.
|
|
|
|
This function treats Termux systems differently, the clipboard is only
|
|
accessible through the termux-clipboard-get commandline interface,
|
|
part of the the termux-api package."
|
|
|
|
(if my/termux-p
|
|
(shell-command-to-string "termux-clipboard-get")
|
|
(current-kill 0)))
|
|
|
|
|
|
(defun my/get-url-title (url)
|
|
"Attempt to retrieve the title string from the given URL.
|
|
|
|
Assuming the URL points to an HTML source.
|
|
|
|
Returns nil if there is a non-200 return status or no title could
|
|
be found."
|
|
(let* ((command (format "curl --fail --silent %s" url))
|
|
(html (shell-command-to-string command))
|
|
(regexp (rx (seq "<title>"
|
|
(group (+ (not (any "<" ">"))))
|
|
"</title>")))
|
|
(matches (string-match regexp html))
|
|
(suggested-title (match-string 1 html)))
|
|
(read-string (format-prompt "Title" "") suggested-title t)))
|
|
|
|
(defun my/denote/url (url)
|
|
"Create a new Org-based note based on an URL.
|
|
|
|
Use the URL on the clipboard if there is one. Then, the title
|
|
is retrieved from the HTML source to suggest the title for the
|
|
note."
|
|
(interactive (list
|
|
(let* ((clipboard (my/clipboard-get))
|
|
(clipboard-url (when (org-url-p clipboard) clipboard)))
|
|
(read-string (format-prompt "URL" "")
|
|
clipboard-url
|
|
t))))
|
|
(denote (my/get-url-title url) (denote-keywords-prompt) 'org (denote-subdirectory-prompt))
|
|
(org-set-property "URL" url))
|