From 15ca70137ae47732fceae7bbb30f399f0d90c99e Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sun, 16 Jul 2023 09:01:24 +1000 Subject: Fix ref rendering with ref counter and help echo --- wiki-markup.el | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'wiki-markup.el') diff --git a/wiki-markup.el b/wiki-markup.el index f6543b5..dfc9cfb 100644 --- a/wiki-markup.el +++ b/wiki-markup.el @@ -103,20 +103,28 @@ This can be overriden with .dir-locals.el." 6))) (defun wiki-do-refs (limit) - (while (re-search-forward "]*\\)>" limit t) - (let ((start (match-beginning 0)) - (end (if (string-suffix-p "/" (match-string 1)) - (match-end 0) - (when (search-forward "" limit t) - (match-end 0)))) - (next-start (save-excursion - (when (re-search-forward "/]*>" limit t) - (match-beginning 0))))) - (cond ((not end) (goto-char limit)) - ((or (not next-start) (>= next-start end)) - (put-text-property start end 'display ";)") - (goto-char end)) - (t (goto-char next-start)))))) + (let ((ref-counter 0)) + (while (re-search-forward "]*\\)>" limit t) + (let ((start (match-beginning 0)) + (end (if (string-suffix-p "/" (match-string 1)) + (match-end 0) + (when (search-forward "" limit t) + (match-end 0)))) + (next-start (save-excursion + (when (re-search-forward "/]*>" limit t) + (match-beginning 0))))) + (cond ((not end) (goto-char limit)) + ((or (not next-start) (>= next-start end)) + (setq ref-counter (1+ ref-counter)) + (let ((original-text + (buffer-substring-no-properties start end))) + (put-text-property start end + 'display (format "[%d]" ref-counter)) + (put-text-property start end + 'help-echo original-text)) + (add-face-text-property start end 'org-link) + (goto-char end)) + (t (goto-char next-start))))))) (defun wiki-set-template-face (limit) "Set template faces." -- cgit v1.2.3