diff options
author | Yuchen Pei <id@ypei.org> | 2023-07-23 17:26:54 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-07-23 17:26:54 +1000 |
commit | 4ca924fc02249b0ff7d9e379358a26dda10482f8 (patch) | |
tree | f40cbbf7a672438d8ad41c8222fa1f7ae6cf7504 /emacs/.emacs.d/lisp/my | |
parent | a4b7de02b0389feff60570afb9d97f0123bbbc0f (diff) |
Better my-fetch-url
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-net.el | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-net.el b/emacs/.emacs.d/lisp/my/my-net.el index 7713dba..1ffbfae 100644 --- a/emacs/.emacs.d/lisp/my/my-net.el +++ b/emacs/.emacs.d/lisp/my/my-net.el @@ -42,13 +42,22 @@ my-download-dir))) (url-retrieve url 'my-fetch-url-save-and-switch (list file-name)))) + (defun my-fetch-url-save-and-switch (status file-name) - (unless (plist-get status :error) - (my-delete-http-header) - (write-file file-name) - (let ((coding-system-for-read 'utf-8)) + (when (plist-get status :error) + (error "My fetch failed: %s" (plist-get status :error))) + (my-delete-http-header) + (let ((to-insert (buffer-string)) + (buffer (find-file-noselect file-name)) + (coding-system-for-write 'utf-8)) + (kill-buffer) + (with-current-buffer buffer + (insert to-insert) + (goto-char (point-min)) + (save-buffer) (revert-buffer t t)) - (switch-to-buffer (current-buffer)))) + (switch-to-buffer buffer)) + ) (defun my-kill-http-header () (my-skip-http-header) |