diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-07-01 11:30:01 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-07-01 11:30:01 +0200 |
commit | f77e628420fde1111aed58a34261d7420bd053fa (patch) | |
tree | b36caaf8c358af4408dd20756e9a582d2b2737d9 | |
parent | 8cac65a8566876da21eeeb8e691052759b4c87a4 (diff) | |
download | moar-f77e628420fde1111aed58a34261d7420bd053fa.tar.gz moar-f77e628420fde1111aed58a34261d7420bd053fa.tar.xz moar-f77e628420fde1111aed58a34261d7420bd053fa.zip |
also support #tags as link syntax
-rw-r--r-- | moar.el | 24 |
1 files 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)))) ))) |