From f77e628420fde1111aed58a34261d7420bd053fa Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 1 Jul 2021 11:30:01 +0200 Subject: also support #tags as link syntax --- moar.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/moar.el b/moar.el index ac593f4..58a5d6f 100644 --- a/moar.el +++ b/moar.el @@ -78,11 +78,16 @@ (defun moar-link-at-point () (let (link-start link-end) - (if (and (looking-back "\\[.*?") - (setq link-start (1+ (match-beginning 0))) - (looking-at ".*?\\]") - (setq link-end (1- (match-end 0))) - (< link-start link-end)) ; don't match empty links + (if (or (and (looking-back "\\[.*?") + (setq link-start (1+ (match-beginning 0))) + (looking-at ".*?\\]") + (setq link-end (1- (match-end 0))) + (< link-start link-end)) ; don't match empty links + (and (looking-back "#[[:word:]._-]*?") + (setq link-start (1+ (match-beginning 0))) + (looking-at "[[:word:]._-]*") + (setq link-end (match-end 0)) + (< link-start link-end))) ; don't match empty links (buffer-substring-no-properties link-start link-end)))) (defun moar-follow-link-or-newline () @@ -123,11 +128,13 @@ (save-restriction (widen) (goto-char 1) - (while (search-forward-regexp "^\C-l\n\\(.*\\)\\|\\[\\(.+?\\)\\]" + (while (search-forward-regexp "^\C-l\n\\(.*\\)\\|\\[\\(.+?\\)\\]\\|#\\([[:word:]._-]+\\)" nil t 1) (if (match-string 1) (setq current-title (match-string-no-properties 1)) - (push (cons current-title (match-string-no-properties 2)) matches) + (if (match-string 2) + (push (cons current-title (match-string-no-properties 2)) matches) + (push (cons current-title (match-string-no-properties 3)) matches)) ))))) matches)) @@ -175,7 +182,8 @@ (target (funcall read "Go to backlink: " links))) (when target (moar-visit-link target) - (when (re-search-forward (concat "\\[" (regexp-quote current-title) "\\]") + (when (re-search-forward (concat "\\[" (regexp-quote current-title) "\\]" + "\\|#" (regexp-quote current-title)) nil t) (goto-char (1+ (match-beginning 0)))) ))) -- cgit 1.4.1