aboutsummaryrefslogtreecommitdiff
path: root/wiki-utils.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-15 20:43:32 +1000
committerYuchen Pei <id@ypei.org>2023-07-15 20:43:32 +1000
commitd12b1368079d42a683bfd1098f5e16c300da3612 (patch)
tree0c9b5c46c6fc17fdc7a2d3ca293406b5b32b6db8 /wiki-utils.el
parente1665c11299257cb5bcd72a371e6043e6a019d95 (diff)
Update fetching mechanism.
Before: write process output buffer content to a file. After: open the file, insert the buffer string from the process output buffer, then save the file. This way we start with a "clean" buffer that allows undo etc.
Diffstat (limited to 'wiki-utils.el')
-rw-r--r--wiki-utils.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/wiki-utils.el b/wiki-utils.el
index 4ceeade..ae61d4d 100644
--- a/wiki-utils.el
+++ b/wiki-utils.el
@@ -52,10 +52,16 @@ Then calls CALLBACK which is a closure taking no argument."
(when (plist-get status :error)
(error "Wiki fetch failed: %s" (plist-get status :error)))
(wiki-delete-http-header)
- (write-file file-name)
- (let ((coding-system-for-read 'utf-8))
- (revert-buffer t t))
- (switch-to-buffer (current-buffer))
+ (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 buffer))
)
(defun wiki-delete-http-header ()