From 8d612cb1905ab3d989ab795e08495d9c716fb007 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sun, 9 Jul 2023 17:17:41 +1000 Subject: Implement wikilink following --- wiki-markup.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'wiki-markup.el') diff --git a/wiki-markup.el b/wiki-markup.el index 0675c44..4a74974 100644 --- a/wiki-markup.el +++ b/wiki-markup.el @@ -68,8 +68,14 @@ (defvar wiki-outline-regexp "=+.*=+\ *$") +(defvar-local wiki-fetcher nil + "Buffer-local function to fetch a wiki title") +(defun wiki-follow-wikilink-action (data) + "Button action to follow a wikilink" + (funcall wiki-fetcher (alist-get 'title data))) + (defun wiki-outline-level () - (when (looking-at "\\(=+\\).*\\(=+\\)\ *$") + (when (looking-at "\\(=+\\).*[^=]\\(=+\\)\\ *$") (min (length (match-string 1)) (length (match-string 2)) 6))) @@ -83,9 +89,13 @@ (end (match-end 0)) (visible-start (or (match-beginning 2) (match-beginning 1))) (visible-end (or (match-end 2) (match-end 1))) + (title (buffer-substring-no-properties (match-beginning 1) + (match-end 1))) ) (put-text-property start visible-start 'invisible t) - (put-text-property start end 'font-lock-face 'wiki-link) + (make-text-button start end + 'action 'wiki-follow-wikilink-action + 'button-data `((title . ,title))) (put-text-property visible-end end 'invisible t) (add-text-properties (1- visible-start) visible-start '(rear-nonsticky (invisible))) @@ -105,7 +115,6 @@ (setq-local comment-start "") - ;; FIXME: this should not be necessary in outline mode (setq-local font-lock-defaults '(wiki-font-lock-keywords t -- cgit v1.2.3