diff options
| author | Yuchen Pei <id@ypei.org> | 2025-01-04 11:51:05 +1100 | 
|---|---|---|
| committer | Yuchen Pei <id@ypei.org> | 2025-01-04 11:51:05 +1100 | 
| commit | 4bfc032aa411552271100301b341b764b5967ce1 (patch) | |
| tree | 6fef124b8109540d0be45f1ae8026ff8a61435f1 /wiki-engine.el | |
| parent | 70609bd73a36d6c590a08fa8d09b2d38959d3feb (diff) | |
Add navigation to sections and dir-local variables support
sections: foo#bar will navigate to section bar of entry foo
dir-local variable support: currently applicable to outline headings
only.
Diffstat (limited to 'wiki-engine.el')
| -rw-r--r-- | wiki-engine.el | 32 | 
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 () | 
