aboutsummaryrefslogtreecommitdiff
path: root/wiki-engine.el
diff options
context:
space:
mode:
Diffstat (limited to 'wiki-engine.el')
-rw-r--r--wiki-engine.el32
1 files changed, 19 insertions, 13 deletions
diff --git a/wiki-engine.el b/wiki-engine.el
index 5cd666b..c10de6e 100644
--- a/wiki-engine.el
+++ b/wiki-engine.el
@@ -155,23 +155,26 @@ If the site has a `local' engine, \"fetch\" locally. Otherwise,
if `wiki-fetch-prefer-local' is non-nil, try fetching locally,
and if the title cannot be found locally, fetch remotely."
(when (string-empty-p title) (setq title "Main Page"))
- (let* ((engine (wiki-engine-compute-engine (alist-get site-id wiki-sites)))
- (found-local
- (when (or wiki-fetch-prefer-local (eq engine 'local))
- (wiki-find-file title (wiki-locate-dir site-id)
- (eq engine 'local))))
- (post-proc (plist-get (alist-get site-id wiki-sites) :fetch-post-proc)))
+ (pcase-let*
+ ((engine (wiki-engine-compute-engine (alist-get site-id wiki-sites)))
+ (found-local
+ (when (or wiki-fetch-prefer-local (eq engine 'local))
+ (wiki-find-file title (wiki-locate-dir site-id)
+ (eq engine 'local))))
+ (post-proc (plist-get (alist-get site-id wiki-sites) :fetch-post-proc))
+ (`(,entry ,section) (split-string title "#")))
(if found-local
(switch-to-buffer found-local)
(wiki-fetch-url
- (wiki-engine-wiki-url site-id title)
- title
+ (wiki-engine-wiki-url site-id entry)
+ entry
(wiki-locate-dir site-id)
(lambda ()
(wiki-mode)
(setq-local wiki-site site-id
wiki-title title)
- (when post-proc (funcall post-proc)))))))
+ (when post-proc (funcall post-proc))
+ (when section (wiki-goto-heading section)))))))
(defun wiki-engine-mediawiki-api-wiki (api-base-url title)
"Fetch the wikitext of TITLE using json api.
@@ -224,18 +227,21 @@ API-BASE-URL is the base url for the api request."
"Find local TITLE in DIR. Do not switch to buffer.
Return the buffer if success, and nil otherwise. If
-CREATE-IF-NOT-EXISTS is non-nil, creates the file is not found.
+CREATE-IF-NOT-EXISTS is non-nil, creates the file if not found.
DIR defaults to `default-directory'."
(interactive (list (read-file-name "Find wiki file: ")))
(unless dir (setq dir default-directory))
- (let ((file-name (expand-file-name
- (concat title wiki-extension)
- dir)))
+ (pcase-let*
+ ((`(,entry ,section) (split-string title "#"))
+ (file-name (expand-file-name
+ (concat entry wiki-extension)
+ dir)))
(when (or (file-exists-p file-name) create-if-not-exists)
(setq dir (file-name-directory file-name))
(unless (file-exists-p dir) (make-directory dir t))
(with-current-buffer (find-file-noselect file-name)
(wiki-mode)
+ (when section (wiki-goto-heading section))
(buffer-name)))))
(defmacro wiki-define-site-commands ()