Skip to content

Commit

Permalink
Merge pull request #808 from alphapapa/wip/extensible-follow-links
Browse files Browse the repository at this point in the history
Add extensible link-opening system
  • Loading branch information
syohex authored Oct 27, 2023
2 parents 2a0556c + c89377a commit 1cf1c1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

*Under development*

* New Features:
- Variable `markdown-follow-link-functions` extends
`markdown-follow-link-at-point` similarly to Org's
`org-open-at-point-functions`, allowing other libraries to
handle links specially. [GH-780][]

* Bug fixes:
- Don't highlight superscript/subscript in math inline/block [GH-802][]

* Improvements:
- Apply url-unescape against URL in an inline link [GH-805][]

[gh-780]: https://github.com/jrblevin/markdown-mode/issues/780
[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802
[gh-805]: https://github.com/jrblevin/markdown-mode/issues/805

Expand Down
19 changes: 13 additions & 6 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
(defvar markdown-gfm-language-history nil
"History list of languages used in the current buffer in GFM code blocks.")

(defvar markdown-follow-link-functions nil
"Functions used to follow a link.
Each function is called with one argument, the link's URL. It
should return non-nil if it followed the link, or nil if not.
Functions are called in order until one of them returns non-nil;
otherwise the default link-following function is used.")


;;; Customizable Variables ====================================================

Expand Down Expand Up @@ -7923,11 +7930,11 @@ If the link is a complete URL, open in browser with `browse-url'.
Otherwise, open with `find-file' after stripping anchor and/or query string.
Translate filenames using `markdown-filename-translate-function'."
(interactive (list last-command-event))
(save-excursion
(if event (posn-set-point (event-start event)))
(if (markdown-link-p)
(markdown--browse-url (markdown-link-url))
(user-error "Point is not at a Markdown link or URL"))))
(if event (posn-set-point (event-start event)))
(if (markdown-link-p)
(or (run-hook-with-args-until-success 'markdown-follow-link-functions (markdown-link-url))
(markdown--browse-url (markdown-link-url)))
(user-error "Point is not at a Markdown link or URL")))

(defun markdown-fontify-inline-links (last)
"Add text properties to next inline link from point to LAST."
Expand Down Expand Up @@ -8337,7 +8344,7 @@ See `markdown-follow-link-at-point' and
`markdown-follow-wiki-link-at-point'."
(interactive "P")
(cond ((markdown-link-p)
(markdown--browse-url (markdown-link-url)))
(markdown-follow-link-at-point))
((markdown-wiki-link-p)
(markdown-follow-wiki-link-at-point arg))
(t
Expand Down
20 changes: 9 additions & 11 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@
"Run BODY in a temporary buffer containing STRING in MODE."
(declare (indent 2))
`(let ((win (selected-window)))
(unwind-protect
(with-temp-buffer
(set-window-buffer win (current-buffer) t)
(erase-buffer)
(insert ,string)
(funcall ,mode)
(setq-default indent-tabs-mode nil)
(goto-char (point-min))
(font-lock-ensure)
(prog1 ,@body (kill-buffer)))
(ignore))))
(with-temp-buffer
(set-window-buffer win (current-buffer) t)
(erase-buffer)
(insert ,string)
(funcall ,mode)
(setq-default indent-tabs-mode nil)
(goto-char (point-min))
(font-lock-ensure)
,@body)))

(defmacro markdown-test-file-mode (mode file &rest body)
"Open FILE from `markdown-test-dir' in MODE and execute BODY."
Expand Down

0 comments on commit 1cf1c1b

Please sign in to comment.