Add xkcd find and view function

This commit is contained in:
tecosaur 2020-05-16 18:22:39 +08:00
parent 12e48b1e04
commit 9a67a30783

View file

@ -1985,7 +1985,7 @@ Saving seconds adds up after all! (but only so much)
(defun +org-xkcd-complete (&optional arg)
"Complete xkcd using `+xkcd-stored-info'"
(concat "xkcd:" (+xkcd-select)))
(format "xkcd:%d" (+xkcd-select)))
(defun +xkcd-select ()
"Prompt the user for an xkcd using `ivy-read' and `+xkcd-select-format'. Return the xkcd number or nil"
@ -1993,8 +1993,8 @@ Saving seconds adds up after all! (but only so much)
(ivy-read (format "xkcd (%s): " xkcd-latest)
(mapcar #'+xkcd-select-format
+xkcd-stored-info))))
(if (equal "" num) (number-to-string xkcd-latest)
(replace-regexp-in-string "\\([0-9]+\\).*" "\\1" num))))
(if (equal "" num) xkcd-latest
(string-to-number (replace-regexp-in-string "\\([0-9]+\\).*" "\\1" num)))))
(defun +xkcd-select-format (xkcd-info)
"Creates each ivy-read line from an xkcd info plist. Must start with the xkcd number"
@ -2025,8 +2025,14 @@ Saving seconds adds up after all! (but only so much)
"Prompt the user for an xkcd using `+xkcd-select' and copy url to clipboard"
(interactive)
(let ((num (+xkcd-select)))
(gui-select-text (format "https://xkcd.com/%s" num))
(message "xkcd.com/%s copied to clipboard" num)))
(gui-select-text (format "https://xkcd.com/%d" num))
(message "xkcd.com/%d copied to clipboard" num)))
(defun +xkcd-find-and-view ()
"Prompt the user for an xkcd using `+xkcd-select' and copy url to clipboard"
(interactive)
(xkcd-get (+xkcd-select))
(switch-to-buffer "*xkcd*"))
(defvar +xkcd-latest-max-age (* 60 60 12)
"Time after which xkcd-latest should be refreshed, in seconds")