diff options
author | Yuchen Pei <id@ypei.org> | 2023-07-09 17:17:41 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-07-09 17:17:41 +1000 |
commit | 8d612cb1905ab3d989ab795e08495d9c716fb007 (patch) | |
tree | ce8bb76a573549e8779b5721475f9f67854ab75d /wiki-utils.el | |
parent | 697db63180f49a3c33b440cf80eca74d39335826 (diff) |
Implement wikilink following
Diffstat (limited to 'wiki-utils.el')
-rw-r--r-- | wiki-utils.el | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/wiki-utils.el b/wiki-utils.el index 80680b7..53b7bd0 100644 --- a/wiki-utils.el +++ b/wiki-utils.el @@ -25,14 +25,21 @@ ;; wiki utility functions. ;;; Code: +(require 'url-parse) + (defvar wiki-download-dir "~/Downloads") -(defun wiki-fetch-url (url) - "Fetch url and returns the buffer." +(defun wiki-fetch-url (url &optional callback) + "Fetch URL asynchronously. + +Then calls CALLBACK which is a closure taking no argument." (interactive "sURL: ") (let ((file-name (expand-file-name (wiki-make-file-name-from-url url) - wiki-download-dir))) - (url-retrieve url 'wiki-fetch-url-save-and-switch (list file-name))) + wiki-download-dir)) + (cb (lambda (status file-name) + (wiki-fetch-url-save-and-switch status file-name) + (when callback (funcall callback))))) + (url-retrieve url cb (list file-name))) ) (defun wiki-fetch-url-save-and-switch (status file-name) @@ -41,7 +48,8 @@ (write-file file-name) (let ((coding-system-for-read 'utf-8)) (revert-buffer t t)) - (switch-to-buffer (current-buffer)))) + (switch-to-buffer (current-buffer)) + )) (defun wiki-delete-http-header () (delete-region (point-min) (progn (wiki-skip-http-header) (point)))) |