aboutsummaryrefslogtreecommitdiff
path: root/wiki-markup.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-09 17:17:41 +1000
committerYuchen Pei <id@ypei.org>2023-07-09 17:17:41 +1000
commit8d612cb1905ab3d989ab795e08495d9c716fb007 (patch)
treece8bb76a573549e8779b5721475f9f67854ab75d /wiki-markup.el
parent697db63180f49a3c33b440cf80eca74d39335826 (diff)
Implement wikilink following
Diffstat (limited to 'wiki-markup.el')
-rw-r--r--wiki-markup.el15
1 files changed, 12 insertions, 3 deletions
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 "<!--")
(setq-local comment-end "-->")
- ;; FIXME: this should not be necessary in outline mode
(setq-local font-lock-defaults
'(wiki-font-lock-keywords
t