aboutsummaryrefslogtreecommitdiff
path: root/wiki-utils.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-23 17:01:24 +1000
committerYuchen Pei <id@ypei.org>2023-07-23 17:01:24 +1000
commitcd62bb147b15d052d52c5dc0f6277902efa7a61e (patch)
treedd7cad9e672c1b4605802e25ea5348cc8f9b6748 /wiki-utils.el
parentfcf126f8aab283078111f8dac0b589e51f30f0ce (diff)
Fixing copyright and flymake complaints.
Diffstat (limited to 'wiki-utils.el')
-rw-r--r--wiki-utils.el28
1 files changed, 20 insertions, 8 deletions
diff --git a/wiki-utils.el b/wiki-utils.el
index ae61d4d..257db5d 100644
--- a/wiki-utils.el
+++ b/wiki-utils.el
@@ -1,6 +1,6 @@
;;; wiki-utils.el -- wiki utility functions -*- lexical-binding: t -*-
-;; Copyright (C) 2023 Free Software Foundation.
+;; Copyright (C) 2023 Free Software Foundation, Inc.
;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "28.2"))
@@ -31,13 +31,14 @@
"Path to local directory of wiki files.")
(defvar wiki-fetch-prefer-local t
- "If non-nil, visit the local file if exists when instructed for
-fetching.")
+ "If non-nil, visit the local file if exists when fetching.")
(defun wiki-fetch-url (url dir &optional callback title)
- "Fetch URL asynchronously.
+ "Fetch URL asynchronously to a file in DIR.
-Then calls CALLBACK which is a closure taking no argument."
+Then call CALLBACK which is a closure taking no argument.
+
+A non-nil TITLE overrides title inferred from the url."
(interactive "sURL: ")
(let ((file-name (expand-file-name
(or title (wiki-make-file-name-from-url url))
@@ -49,6 +50,9 @@ Then calls CALLBACK which is a closure taking no argument."
)
(defun wiki-fetch-url-save-and-switch (status file-name)
+ "Fetch url to FILE-NAME if STATUS is ok.
+
+And switch to the corresponding buffer."
(when (plist-get status :error)
(error "Wiki fetch failed: %s" (plist-get status :error)))
(wiki-delete-http-header)
@@ -65,13 +69,20 @@ Then calls CALLBACK which is a closure taking no argument."
)
(defun wiki-delete-http-header ()
+ "Delete the http header in current buffer.
+
+Assuming the current buffer to be a `url-retrieve' response buffer."
(delete-region (point-min) (progn (wiki-skip-http-header) (point))))
(defun wiki-skip-http-header ()
+ "Skip the http header in current buffer.
+
+Assuming the current buffer to be a `url-retrieve' response buffer."
(goto-char (point-min))
(re-search-forward "\r?\n\r?\n"))
(defun wiki-make-file-name-from-url (url)
+ "Make a file name from URL."
(file-name-nondirectory
(directory-file-name
(car (url-path-and-query (url-generic-parse-url
@@ -146,9 +157,10 @@ Each item is in the form of (identifier . properties), where
identifier is a symbol, and properties is a plist of the site.
One of the sites is (local), meaning a local filesystem.")
-(defun wiki-site-fetcher (wiki-site)
- (if wiki-site
- (intern (format "wiki-%s-fetch" wiki-site))
+(defun wiki-site-fetcher (site-id)
+ "Return the fetcher function for wiki site with SITE-ID."
+ (if site-id
+ (intern (format "wiki-%s-fetch" site-id))
'wiki-find-file))
(provide 'wiki-utils)